From 50821bab55e1a64a707b4a7f267d37cc54a27300 Mon Sep 17 00:00:00 2001 From: jLynx Date: Wed, 6 Apr 2022 08:16:57 +1200 Subject: [PATCH] Added button on boot detection --- firmware/application/main.cpp | 2 +- firmware/application/portapack.cpp | 46 ++++++++++++++++++------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index 59ef942c..185a905d 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -169,7 +169,7 @@ int main(void) { sdcStart(&SDCD1, nullptr); - controls_init(); + // controls_init(); // Commented out as now happens in portapack.cpp lcd_frame_sync_configure(); rtc_interrupt_enable(); diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 409efaa6..d9308c6d 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -29,6 +29,7 @@ #include "hackrf_gpio.hpp" using namespace hackrf::one; + #include "clock_manager.hpp" #include "event_m0.hpp" @@ -45,6 +46,7 @@ using asahi_kasei::ak4951::AK4951; #include "cpld_update.hpp" #include "optional.hpp" +#include "irq_controls.hpp" namespace portapack { @@ -179,12 +181,10 @@ static PortaPackModel portapack_model() { static Optional model; if( !model.is_valid() ) { - if( audio_codec_wm8731.detected() && audio_codec_ak4951.detected()) { - model = PortaPackModel::R2_20170522; // H2+ - } else if( audio_codec_wm8731.detected() ) { + if( audio_codec_wm8731.detected() ) { model = PortaPackModel::R1_20150901; // H1R1 } else { - model = PortaPackModel::R2_20170522; // H1R2 + model = PortaPackModel::R2_20170522; // H1R2, H2+ } } @@ -203,6 +203,15 @@ static audio::Codec* portapack_audio_codec() { } static const portapack::cpld::Config& portapack_cpld_config() { + + const auto switches_state = get_switches_state(); + if (switches_state[(size_t)ui::KeyEvent::Up]){ + return portapack::cpld::rev_20150901::config; + } + if (switches_state[(size_t)ui::KeyEvent::Down]){ + return portapack::cpld::rev_20170522::config; + } + return (portapack_model() == PortaPackModel::R2_20170522) ? portapack::cpld::rev_20170522::config : portapack::cpld::rev_20150901::config @@ -381,6 +390,21 @@ bool init() { i2c0.start(i2c_config_fast_clock); + touch::adc::init(); + controls_init(); + + clock_manager.set_reference_ppb(persistent_memory::correction_ppb()); + clock_manager.enable_first_if_clock(); + clock_manager.enable_second_if_clock(); + clock_manager.enable_codec_clocks(); + radio::init(); + + + LPC_CREG->DMAMUX = portapack::gpdma_mux; + gpdma::controller.enable(); + + audio::init(portapack_audio_codec()); + if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { shutdown_base(); return false; @@ -390,20 +414,6 @@ bool init() { chSysHalt(); } - clock_manager.set_reference_ppb(persistent_memory::correction_ppb()); - - audio::init(portapack_audio_codec()); - - clock_manager.enable_first_if_clock(); - clock_manager.enable_second_if_clock(); - clock_manager.enable_codec_clocks(); - radio::init(); - - touch::adc::init(); - - LPC_CREG->DMAMUX = portapack::gpdma_mux; - gpdma::controller.enable(); - return true; }