mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-25 07:19:28 -05:00
Consolidate peripheral declarations.
This commit is contained in:
parent
8af8941687
commit
1d16cd8aac
@ -124,6 +124,7 @@ CPPSRC = main.cpp \
|
|||||||
event.cpp \
|
event.cpp \
|
||||||
message_queue.cpp \
|
message_queue.cpp \
|
||||||
hackrf_hal.cpp \
|
hackrf_hal.cpp \
|
||||||
|
portapack.cpp \
|
||||||
portapack_shared_memory.cpp \
|
portapack_shared_memory.cpp \
|
||||||
portapack_io.cpp \
|
portapack_io.cpp \
|
||||||
i2c_pp.cpp \
|
i2c_pp.cpp \
|
||||||
|
@ -22,42 +22,27 @@
|
|||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
#include "hackrf_hal.hpp"
|
#include "lpc43xx_cpp.hpp"
|
||||||
#include "hackrf_gpio.hpp"
|
using namespace lpc43xx;
|
||||||
using namespace hackrf::one;
|
|
||||||
|
|
||||||
|
#include "portapack.hpp"
|
||||||
#include "portapack_shared_memory.hpp"
|
#include "portapack_shared_memory.hpp"
|
||||||
#include "portapack_hal.hpp"
|
|
||||||
#include "portapack_io.hpp"
|
|
||||||
|
|
||||||
#include "cpld_update.hpp"
|
#include "cpld_update.hpp"
|
||||||
|
|
||||||
#include "message_queue.hpp"
|
#include "message_queue.hpp"
|
||||||
|
|
||||||
#include "si5351.hpp"
|
|
||||||
#include "clock_manager.hpp"
|
|
||||||
|
|
||||||
#include "wm8731.hpp"
|
|
||||||
#include "radio.hpp"
|
|
||||||
#include "touch.hpp"
|
|
||||||
#include "touch_adc.hpp"
|
|
||||||
|
|
||||||
#include "ui.hpp"
|
#include "ui.hpp"
|
||||||
#include "ui_widget.hpp"
|
#include "ui_widget.hpp"
|
||||||
#include "ui_painter.hpp"
|
#include "ui_painter.hpp"
|
||||||
#include "ui_navigation.hpp"
|
#include "ui_navigation.hpp"
|
||||||
|
|
||||||
#include "receiver_model.hpp"
|
|
||||||
|
|
||||||
#include "irq_ipc.hpp"
|
#include "irq_ipc.hpp"
|
||||||
#include "irq_lcd_frame.hpp"
|
#include "irq_lcd_frame.hpp"
|
||||||
#include "irq_controls.hpp"
|
#include "irq_controls.hpp"
|
||||||
|
|
||||||
#include "event.hpp"
|
#include "event.hpp"
|
||||||
|
|
||||||
#include "i2c_pp.hpp"
|
|
||||||
#include "spi_pp.hpp"
|
|
||||||
|
|
||||||
#include "m4_startup.hpp"
|
#include "m4_startup.hpp"
|
||||||
#include "spi_image.hpp"
|
#include "spi_image.hpp"
|
||||||
|
|
||||||
@ -68,12 +53,6 @@ using namespace hackrf::one;
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
I2C i2c0(&I2CD0);
|
|
||||||
SPI ssp0(&SPID1);
|
|
||||||
SPI ssp1(&SPID2);
|
|
||||||
|
|
||||||
wolfson::wm8731::WM8731 audio_codec { i2c0, portapack::wm8731_i2c_address };
|
|
||||||
|
|
||||||
/* From ChibiOS crt0.c:
|
/* From ChibiOS crt0.c:
|
||||||
* Two stacks available for Cortex-M, main stack or process stack.
|
* Two stacks available for Cortex-M, main stack or process stack.
|
||||||
*
|
*
|
||||||
@ -147,112 +126,6 @@ static spi_bus_t ssp0 = {
|
|||||||
* _default_exit() (default is infinite loop)
|
* _default_exit() (default is infinite loop)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
si5351::Si5351 clock_generator {
|
|
||||||
i2c0, si5351_i2c_address
|
|
||||||
};
|
|
||||||
|
|
||||||
ClockManager clock_manager {
|
|
||||||
i2c0, clock_generator
|
|
||||||
};
|
|
||||||
|
|
||||||
ReceiverModel receiver_model {
|
|
||||||
clock_manager
|
|
||||||
};
|
|
||||||
|
|
||||||
class Power {
|
|
||||||
public:
|
|
||||||
void init() {
|
|
||||||
/* VAA powers:
|
|
||||||
* MAX5864 analog section.
|
|
||||||
* MAX2837 registers and other functions.
|
|
||||||
* RFFC5072 analog section.
|
|
||||||
*
|
|
||||||
* Beware that power applied to pins of the MAX2837 may
|
|
||||||
* show up on VAA and start powering other components on the
|
|
||||||
* VAA net. So turn on VAA before driving pins from MCU to
|
|
||||||
* MAX2837.
|
|
||||||
*/
|
|
||||||
/* Turn on VAA */
|
|
||||||
gpio_vaa_disable.clear();
|
|
||||||
gpio_vaa_disable.output();
|
|
||||||
|
|
||||||
/* 1V8 powers CPLD internals.
|
|
||||||
*/
|
|
||||||
/* Turn on 1V8 */
|
|
||||||
gpio_1v8_enable.set();
|
|
||||||
gpio_1v8_enable.output();
|
|
||||||
|
|
||||||
/* Set VREGMODE for switching regulator on HackRF One */
|
|
||||||
gpio_vregmode.set();
|
|
||||||
gpio_vregmode.output();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
static Power power;
|
|
||||||
|
|
||||||
static void init() {
|
|
||||||
for(const auto& pin : pins) {
|
|
||||||
pin.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Configure other pins */
|
|
||||||
LPC_SCU->SFSI2C0 =
|
|
||||||
(1U << 3)
|
|
||||||
| (1U << 11)
|
|
||||||
;
|
|
||||||
|
|
||||||
power.init();
|
|
||||||
|
|
||||||
gpio_max5864_select.set();
|
|
||||||
gpio_max5864_select.output();
|
|
||||||
|
|
||||||
gpio_max2837_select.set();
|
|
||||||
gpio_max2837_select.output();
|
|
||||||
|
|
||||||
led_usb.setup();
|
|
||||||
led_rx.setup();
|
|
||||||
led_tx.setup();
|
|
||||||
|
|
||||||
clock_manager.init();
|
|
||||||
clock_manager.run_at_full_speed();
|
|
||||||
|
|
||||||
clock_manager.start_audio_pll();
|
|
||||||
audio_codec.init();
|
|
||||||
|
|
||||||
clock_manager.enable_first_if_clock();
|
|
||||||
clock_manager.enable_second_if_clock();
|
|
||||||
clock_manager.enable_codec_clocks();
|
|
||||||
radio::init();
|
|
||||||
|
|
||||||
touch::adc::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
void __late_init(void) {
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* System initializations.
|
|
||||||
* - HAL initialization, this also initializes the configured device drivers
|
|
||||||
* and performs the board-specific initializations.
|
|
||||||
* - Kernel initialization, the main() function becomes a thread and the
|
|
||||||
* RTOS is active.
|
|
||||||
*/
|
|
||||||
halInit();
|
|
||||||
|
|
||||||
/* After this call, scheduler, systick, heap, etc. are available. */
|
|
||||||
/* By doing chSysInit() here, it runs before C++ constructors, which may
|
|
||||||
* require the heap.
|
|
||||||
*/
|
|
||||||
chSysInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
CH_IRQ_HANDLER(RTC_IRQHandler) {
|
CH_IRQ_HANDLER(RTC_IRQHandler) {
|
||||||
@ -601,18 +474,8 @@ message_handlers[Message::ID::TestResults] = [&system_view](const Message* const
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
portapack::IO portapack::io {
|
|
||||||
portapack::gpio_dir,
|
|
||||||
portapack::gpio_lcd_rd,
|
|
||||||
portapack::gpio_lcd_wr,
|
|
||||||
portapack::gpio_io_stbx,
|
|
||||||
portapack::gpio_addr,
|
|
||||||
portapack::gpio_lcd_te,
|
|
||||||
portapack::gpio_unused,
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
init();
|
portapack::init();
|
||||||
|
|
||||||
if( !cpld_update_if_necessary() ) {
|
if( !cpld_update_if_necessary() ) {
|
||||||
chSysHalt();
|
chSysHalt();
|
||||||
@ -646,7 +509,6 @@ int main(void) {
|
|||||||
context.message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
context.message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
||||||
const auto message = static_cast<const FSKPacketMessage*>(p);
|
const auto message = static_cast<const FSKPacketMessage*>(p);
|
||||||
(void)message;
|
(void)message;
|
||||||
led_usb.toggle();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
m4txevent_interrupt_enable();
|
m4txevent_interrupt_enable();
|
||||||
|
187
firmware/application/portapack.cpp
Normal file
187
firmware/application/portapack.cpp
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||||
|
*
|
||||||
|
* This file is part of PortaPack.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "portapack.hpp"
|
||||||
|
#include "portapack_hal.hpp"
|
||||||
|
|
||||||
|
#include "hackrf_hal.hpp"
|
||||||
|
#include "hackrf_gpio.hpp"
|
||||||
|
using namespace hackrf::one;
|
||||||
|
|
||||||
|
#include "si5351.hpp"
|
||||||
|
#include "clock_manager.hpp"
|
||||||
|
|
||||||
|
#include "i2c_pp.hpp"
|
||||||
|
|
||||||
|
#include "touch_adc.hpp"
|
||||||
|
|
||||||
|
#include "m4_startup.hpp"
|
||||||
|
#include "spi_image.hpp"
|
||||||
|
|
||||||
|
namespace portapack {
|
||||||
|
|
||||||
|
portapack::IO io {
|
||||||
|
portapack::gpio_dir,
|
||||||
|
portapack::gpio_lcd_rd,
|
||||||
|
portapack::gpio_lcd_wr,
|
||||||
|
portapack::gpio_io_stbx,
|
||||||
|
portapack::gpio_addr,
|
||||||
|
portapack::gpio_lcd_te,
|
||||||
|
portapack::gpio_unused,
|
||||||
|
};
|
||||||
|
|
||||||
|
I2C i2c0(&I2CD0);
|
||||||
|
SPI ssp0(&SPID1);
|
||||||
|
SPI ssp1(&SPID2);
|
||||||
|
|
||||||
|
wolfson::wm8731::WM8731 audio_codec { i2c0, portapack::wm8731_i2c_address };
|
||||||
|
|
||||||
|
si5351::Si5351 clock_generator {
|
||||||
|
i2c0, hackrf::one::si5351_i2c_address
|
||||||
|
};
|
||||||
|
|
||||||
|
ClockManager clock_manager {
|
||||||
|
i2c0, clock_generator
|
||||||
|
};
|
||||||
|
|
||||||
|
ReceiverModel receiver_model {
|
||||||
|
clock_manager
|
||||||
|
};
|
||||||
|
|
||||||
|
class Power {
|
||||||
|
public:
|
||||||
|
void init() {
|
||||||
|
/* VAA powers:
|
||||||
|
* MAX5864 analog section.
|
||||||
|
* MAX2837 registers and other functions.
|
||||||
|
* RFFC5072 analog section.
|
||||||
|
*
|
||||||
|
* Beware that power applied to pins of the MAX2837 may
|
||||||
|
* show up on VAA and start powering other components on the
|
||||||
|
* VAA net. So turn on VAA before driving pins from MCU to
|
||||||
|
* MAX2837.
|
||||||
|
*/
|
||||||
|
/* Turn on VAA */
|
||||||
|
gpio_vaa_disable.clear();
|
||||||
|
gpio_vaa_disable.output();
|
||||||
|
|
||||||
|
/* 1V8 powers CPLD internals.
|
||||||
|
*/
|
||||||
|
/* Turn on 1V8 */
|
||||||
|
gpio_1v8_enable.set();
|
||||||
|
gpio_1v8_enable.output();
|
||||||
|
|
||||||
|
/* Set VREGMODE for switching regulator on HackRF One */
|
||||||
|
gpio_vregmode.set();
|
||||||
|
gpio_vregmode.output();
|
||||||
|
}
|
||||||
|
|
||||||
|
void shutdown() {
|
||||||
|
gpio_1v8_enable.clear();
|
||||||
|
gpio_vaa_disable.set();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
static Power power;
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
for(const auto& pin : pins) {
|
||||||
|
pin.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Configure other pins */
|
||||||
|
LPC_SCU->SFSI2C0 =
|
||||||
|
(1U << 3)
|
||||||
|
| (1U << 11)
|
||||||
|
;
|
||||||
|
|
||||||
|
power.init();
|
||||||
|
|
||||||
|
gpio_max5864_select.set();
|
||||||
|
gpio_max5864_select.output();
|
||||||
|
|
||||||
|
gpio_max2837_select.set();
|
||||||
|
gpio_max2837_select.output();
|
||||||
|
|
||||||
|
led_usb.setup();
|
||||||
|
led_rx.setup();
|
||||||
|
led_tx.setup();
|
||||||
|
|
||||||
|
clock_manager.init();
|
||||||
|
clock_manager.run_at_full_speed();
|
||||||
|
|
||||||
|
clock_manager.start_audio_pll();
|
||||||
|
audio_codec.init();
|
||||||
|
|
||||||
|
clock_manager.enable_first_if_clock();
|
||||||
|
clock_manager.enable_second_if_clock();
|
||||||
|
clock_manager.enable_codec_clocks();
|
||||||
|
radio::init();
|
||||||
|
|
||||||
|
touch::adc::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void shutdown() {
|
||||||
|
sdcStop(&SDCD1);
|
||||||
|
|
||||||
|
radio::disable();
|
||||||
|
audio_codec.reset();
|
||||||
|
clock_manager.shutdown();
|
||||||
|
|
||||||
|
power.shutdown();
|
||||||
|
// TODO: Wait a bit for supplies to discharge?
|
||||||
|
|
||||||
|
chSysDisable();
|
||||||
|
hackrf::one::reset();
|
||||||
|
m4_init(portapack::spi_flash::hackrf, reinterpret_cast<void*>(0x10000000));
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
__WFE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void __late_init(void) {
|
||||||
|
|
||||||
|
reset();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* System initializations.
|
||||||
|
* - HAL initialization, this also initializes the configured device drivers
|
||||||
|
* and performs the board-specific initializations.
|
||||||
|
* - Kernel initialization, the main() function becomes a thread and the
|
||||||
|
* RTOS is active.
|
||||||
|
*/
|
||||||
|
halInit();
|
||||||
|
|
||||||
|
/* After this call, scheduler, systick, heap, etc. are available. */
|
||||||
|
/* By doing chSysInit() here, it runs before C++ constructors, which may
|
||||||
|
* require the heap.
|
||||||
|
*/
|
||||||
|
chSysInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace portapack */
|
45
firmware/application/portapack.hpp
Normal file
45
firmware/application/portapack.hpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||||
|
*
|
||||||
|
* This file is part of PortaPack.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "portapack_io.hpp"
|
||||||
|
|
||||||
|
#include "receiver_model.hpp"
|
||||||
|
|
||||||
|
#include "spi_pp.hpp"
|
||||||
|
#include "wm8731.hpp"
|
||||||
|
|
||||||
|
#include "radio.hpp"
|
||||||
|
|
||||||
|
namespace portapack {
|
||||||
|
|
||||||
|
extern portapack::IO io;
|
||||||
|
|
||||||
|
extern SPI ssp0;
|
||||||
|
extern SPI ssp1;
|
||||||
|
|
||||||
|
extern wolfson::wm8731::WM8731 audio_codec;
|
||||||
|
|
||||||
|
extern ReceiverModel receiver_model;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
} /* namespace portapack */
|
@ -36,8 +36,7 @@
|
|||||||
#include "hackrf_gpio.hpp"
|
#include "hackrf_gpio.hpp"
|
||||||
using namespace hackrf::one;
|
using namespace hackrf::one;
|
||||||
|
|
||||||
#include "spi_pp.hpp"
|
#include "portapack.hpp"
|
||||||
extern SPI ssp1;
|
|
||||||
|
|
||||||
namespace radio {
|
namespace radio {
|
||||||
|
|
||||||
@ -75,7 +74,7 @@ static constexpr SPIConfig ssp_config_max5864 = {
|
|||||||
.cpsr = ssp1_cpsr,
|
.cpsr = ssp1_cpsr,
|
||||||
};
|
};
|
||||||
|
|
||||||
static spi::arbiter::Arbiter ssp1_arbiter(ssp1);
|
static spi::arbiter::Arbiter ssp1_arbiter(portapack::ssp1);
|
||||||
|
|
||||||
static spi::arbiter::Target ssp1_target_max2837 {
|
static spi::arbiter::Target ssp1_target_max2837 {
|
||||||
ssp1_arbiter,
|
ssp1_arbiter,
|
||||||
|
@ -22,13 +22,8 @@
|
|||||||
#include "receiver_model.hpp"
|
#include "receiver_model.hpp"
|
||||||
|
|
||||||
#include "portapack_shared_memory.hpp"
|
#include "portapack_shared_memory.hpp"
|
||||||
#include "radio.hpp"
|
#include "portapack.hpp"
|
||||||
#include "wm8731.hpp"
|
using namespace portapack;
|
||||||
|
|
||||||
// TODO: Nasty. Put this in an #include somewhere, or a shared system state
|
|
||||||
// object?
|
|
||||||
|
|
||||||
extern wolfson::wm8731::WM8731 audio_codec;
|
|
||||||
|
|
||||||
rf::Frequency ReceiverModel::tuning_frequency() const {
|
rf::Frequency ReceiverModel::tuning_frequency() const {
|
||||||
return tuning_frequency_;
|
return tuning_frequency_;
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "ui_debug.hpp"
|
#include "ui_debug.hpp"
|
||||||
#include "ui_receiver.hpp"
|
#include "ui_receiver.hpp"
|
||||||
|
|
||||||
extern ReceiverModel receiver_model;
|
#include "portapack.hpp"
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
@ -21,11 +21,8 @@
|
|||||||
|
|
||||||
#include "ui_receiver.hpp"
|
#include "ui_receiver.hpp"
|
||||||
|
|
||||||
// TODO: Nasty. Put this in an #include somewhere, or a shared system state
|
#include "portapack.hpp"
|
||||||
// object?
|
using namespace portapack;
|
||||||
|
|
||||||
#include "wm8731.hpp"
|
|
||||||
extern wolfson::wm8731::WM8731 audio_codec;
|
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user