From 43e9ce47049372c3fbe049d899542770df9bb609 Mon Sep 17 00:00:00 2001 From: jLynx Date: Tue, 5 Apr 2022 10:52:42 +1200 Subject: [PATCH 1/7] Fixed R1_20150901 vs R2_20170522 boot & detection issues --- firmware/application/portapack.cpp | 48 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index c4f038556..f0c2022de 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -181,17 +181,24 @@ static PortaPackModel portapack_model() { if( !model.is_valid() ) { /*For the time being, it is impossible to distinguish the hardware of R1 and R2 from the software level*/ /*At this point, I2c is not ready.*/ - //if( audio_codec_wm8731.detected() ) { - // model = PortaPackModel::R1_20150901; - //} else { + if( audio_codec_wm8731.detected() ) { + model = PortaPackModel::R1_20150901; + } else { model = PortaPackModel::R2_20170522; - //} + } + + // model = PortaPackModel::R1_20150901; + + // ToDo: Do validation here to check if R2_20170522 or R1_20150901 (Gen1) } return model.value(); } static audio::Codec* portapack_audio_codec() { + + // Maybe we c ould change the model here + /* I2C ready OK, Automatic recognition of audio chip */ return (audio_codec_wm8731.detected()) ? static_cast(&audio_codec_wm8731) @@ -200,6 +207,9 @@ static audio::Codec* portapack_audio_codec() { } static const portapack::cpld::Config& portapack_cpld_config() { + // This function here is teh decider if the device boots or not. + + // return portapack::cpld::rev_20150901::config; // R1_20150901 return (portapack_model() == PortaPackModel::R2_20170522) ? portapack::cpld::rev_20170522::config : portapack::cpld::rev_20150901::config @@ -207,9 +217,10 @@ static const portapack::cpld::Config& portapack_cpld_config() { } Backlight* backlight() { + // return static_cast(&backlight_on_off); // This should work for R1_20150901 return (portapack_model() == PortaPackModel::R2_20170522) - ? static_cast(&backlight_cat4004) - : static_cast(&backlight_on_off); + ? static_cast(&backlight_cat4004) // R2_20170522 + : static_cast(&backlight_on_off); // R1_20150901 } #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) @@ -318,14 +329,14 @@ bool init() { i2c0.start(i2c_config_boot_clock); - if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { - shutdown_base(); - return false; - } + // if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { + // shutdown_base(); + // return false; + // } - if( !hackrf::cpld::load_sram() ) { - chSysHalt(); - } + // if( !hackrf::cpld::load_sram() ) { + // chSysHalt(); + // } configure_pins_portapack(); @@ -338,7 +349,7 @@ bool init() { set_clock_config(clock_config_irc); cgu::pll1::disable(); - + /* Incantation from LPC43xx UM10503 section 12.2.1.1, to bring the M4 * core clock speed to the 110 - 204MHz range. */ @@ -377,6 +388,15 @@ bool init() { i2c0.start(i2c_config_fast_clock); + if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { + shutdown_base(); + return false; + } + + if( !hackrf::cpld::load_sram() ) { + chSysHalt(); + } + clock_manager.set_reference_ppb(persistent_memory::correction_ppb()); audio::init(portapack_audio_codec()); From b4a6b958e50536712014441ffa580c963630d966 Mon Sep 17 00:00:00 2001 From: jLynx Date: Tue, 5 Apr 2022 10:53:52 +1200 Subject: [PATCH 2/7] Fixed R1_20150901 vs R2_20170522 boot & detection issues --- firmware/application/portapack.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index f0c2022de..b574597d9 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -186,19 +186,12 @@ static PortaPackModel portapack_model() { } else { model = PortaPackModel::R2_20170522; } - - // model = PortaPackModel::R1_20150901; - - // ToDo: Do validation here to check if R2_20170522 or R1_20150901 (Gen1) } return model.value(); } static audio::Codec* portapack_audio_codec() { - - // Maybe we c ould change the model here - /* I2C ready OK, Automatic recognition of audio chip */ return (audio_codec_wm8731.detected()) ? static_cast(&audio_codec_wm8731) @@ -207,9 +200,6 @@ static audio::Codec* portapack_audio_codec() { } static const portapack::cpld::Config& portapack_cpld_config() { - // This function here is teh decider if the device boots or not. - - // return portapack::cpld::rev_20150901::config; // R1_20150901 return (portapack_model() == PortaPackModel::R2_20170522) ? portapack::cpld::rev_20170522::config : portapack::cpld::rev_20150901::config @@ -217,7 +207,6 @@ static const portapack::cpld::Config& portapack_cpld_config() { } Backlight* backlight() { - // return static_cast(&backlight_on_off); // This should work for R1_20150901 return (portapack_model() == PortaPackModel::R2_20170522) ? static_cast(&backlight_cat4004) // R2_20170522 : static_cast(&backlight_on_off); // R1_20150901 @@ -329,6 +318,7 @@ bool init() { i2c0.start(i2c_config_boot_clock); + // Keeping this here for now incase we need to revert // if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { // shutdown_base(); // return false; @@ -349,7 +339,7 @@ bool init() { set_clock_config(clock_config_irc); cgu::pll1::disable(); - + /* Incantation from LPC43xx UM10503 section 12.2.1.1, to bring the M4 * core clock speed to the 110 - 204MHz range. */ From f6c496d1d30c89ab758db07bbfa8fcdf8c71e0f3 Mon Sep 17 00:00:00 2001 From: jLynx Date: Tue, 5 Apr 2022 10:56:09 +1200 Subject: [PATCH 3/7] removed comments --- firmware/application/portapack.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index b574597d9..0f9c8b480 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -179,8 +179,6 @@ static PortaPackModel portapack_model() { static Optional model; if( !model.is_valid() ) { - /*For the time being, it is impossible to distinguish the hardware of R1 and R2 from the software level*/ - /*At this point, I2c is not ready.*/ if( audio_codec_wm8731.detected() ) { model = PortaPackModel::R1_20150901; } else { From fd8bc177ad2762ef00a9cbce72dbe8e794f362ea Mon Sep 17 00:00:00 2001 From: jLynx Date: Tue, 5 Apr 2022 14:41:12 +1200 Subject: [PATCH 4/7] Added support for H2+ --- firmware/application/portapack.cpp | 12 +++++++++--- firmware/common/ak4951.cpp | 4 ++++ firmware/common/ak4951.hpp | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 0f9c8b480..b4c6ec2df 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -179,18 +179,24 @@ static PortaPackModel portapack_model() { static Optional model; if( !model.is_valid() ) { - if( audio_codec_wm8731.detected() ) { - model = PortaPackModel::R1_20150901; + if( audio_codec_wm8731.detected() && audio_codec_ak4951.detected()) { + model = PortaPackModel::R2_20170522; // H2+ + } else if( audio_codec_wm8731.detected() ) { + model = PortaPackModel::R1_20150901; // H1R1 } else { - model = PortaPackModel::R2_20170522; + model = PortaPackModel::R2_20170522; // H1R2 } } return model.value(); } +//audio_codec_wm8731 = H1R1 & H2 +//audio_codec_ak4951 = H1R2 (China/mine) + static audio::Codec* portapack_audio_codec() { /* I2C ready OK, Automatic recognition of audio chip */ + // return static_cast(&audio_codec_wm8731); return (audio_codec_wm8731.detected()) ? static_cast(&audio_codec_wm8731) : static_cast(&audio_codec_ak4951) diff --git a/firmware/common/ak4951.cpp b/firmware/common/ak4951.cpp index d94bbb0bb..1f88a3d6e 100644 --- a/firmware/common/ak4951.cpp +++ b/firmware/common/ak4951.cpp @@ -115,6 +115,10 @@ void AK4951::init() { // update(Register::DigitalFilterMode); } +bool AK4951::detected() { + return reset(); +} + bool AK4951::reset() { io.audio_reset_state(true); diff --git a/firmware/common/ak4951.hpp b/firmware/common/ak4951.hpp index ea394966a..3b1f9e1aa 100644 --- a/firmware/common/ak4951.hpp +++ b/firmware/common/ak4951.hpp @@ -823,6 +823,8 @@ public: std::string name() const override { return "AK4951"; } + + bool detected(); void init() override; bool reset() override; From 796d9ca854301addfa2e938017053f739c15086f Mon Sep 17 00:00:00 2001 From: jLynx Date: Tue, 5 Apr 2022 14:44:32 +1200 Subject: [PATCH 5/7] Updated comments --- firmware/application/portapack.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index b4c6ec2df..409efaa60 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -191,12 +191,11 @@ static PortaPackModel portapack_model() { return model.value(); } -//audio_codec_wm8731 = H1R1 & H2 -//audio_codec_ak4951 = H1R2 (China/mine) +//audio_codec_wm8731 = H1R1 & H2+ +//audio_codec_ak4951 = H1R2 static audio::Codec* portapack_audio_codec() { /* I2C ready OK, Automatic recognition of audio chip */ - // return static_cast(&audio_codec_wm8731); return (audio_codec_wm8731.detected()) ? static_cast(&audio_codec_wm8731) : static_cast(&audio_codec_ak4951) From 50821bab55e1a64a707b4a7f267d37cc54a27300 Mon Sep 17 00:00:00 2001 From: jLynx Date: Wed, 6 Apr 2022 08:16:57 +1200 Subject: [PATCH 6/7] 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 59ef942c6..185a905d0 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 409efaa60..d9308c6d7 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; } From 0c0d47b0d21ce524d6f58686efbd1f365d9bd0af Mon Sep 17 00:00:00 2001 From: jLynx Date: Wed, 6 Apr 2022 13:28:10 +1200 Subject: [PATCH 7/7] Added persistent memory of save state --- firmware/application/portapack.cpp | 23 +++++++++++++------ .../common/portapack_persistent_memory.cpp | 11 +++++++++ .../common/portapack_persistent_memory.hpp | 3 +++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index d9308c6d7..15b9d5c2b 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -203,19 +203,28 @@ 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]){ + persistent_memory::set_config_cpld(1); return portapack::cpld::rev_20170522::config; } + if (switches_state[(size_t)ui::KeyEvent::Down]){ + persistent_memory::set_config_cpld(2); + return portapack::cpld::rev_20150901::config; + } + if (switches_state[(size_t)ui::KeyEvent::Select]){ + persistent_memory::set_config_cpld(0); + } + + if (portapack::persistent_memory::config_cpld() == 1) { + return portapack::cpld::rev_20170522::config; + } else if (portapack::persistent_memory::config_cpld() == 2) { + return portapack::cpld::rev_20150901::config; + } return (portapack_model() == PortaPackModel::R2_20170522) - ? portapack::cpld::rev_20170522::config - : portapack::cpld::rev_20150901::config - ; + ? portapack::cpld::rev_20170522::config + : portapack::cpld::rev_20150901::config; } Backlight* backlight() { diff --git a/firmware/common/portapack_persistent_memory.cpp b/firmware/common/portapack_persistent_memory.cpp index 2bee6470e..0fdada7df 100644 --- a/firmware/common/portapack_persistent_memory.cpp +++ b/firmware/common/portapack_persistent_memory.cpp @@ -82,6 +82,9 @@ struct data_t { int32_t afsk_space_freq; int32_t modem_baudrate; int32_t modem_repeat; + + // Hardware + uint32_t hardware_config; // Play dead unlock uint32_t playdead_magic; @@ -254,6 +257,10 @@ bool config_splash() { return data->ui_config & (1 << 31); } +uint8_t config_cpld() { + return data->hardware_config; +} + uint32_t config_backlight_timer() { const uint32_t timer_seconds[8] = { 0, 5, 15, 30, 60, 180, 300, 600 }; return timer_seconds[data->ui_config & 7]; //first three bits, 8 possible values @@ -287,6 +294,10 @@ void set_config_splash(bool v) { data->ui_config = (data->ui_config & ~(1 << 31)) | (v << 31); } +void set_config_cpld(uint8_t i) { + data->hardware_config = i; +} + void set_config_backlight_timer(uint32_t i) { data->ui_config = (data->ui_config & ~7) | (i & 7); } diff --git a/firmware/common/portapack_persistent_memory.hpp b/firmware/common/portapack_persistent_memory.hpp index 11643bab3..d04b12395 100644 --- a/firmware/common/portapack_persistent_memory.hpp +++ b/firmware/common/portapack_persistent_memory.hpp @@ -74,6 +74,9 @@ void set_playdead_sequence(const uint32_t new_value); bool stealth_mode(); void set_stealth_mode(const bool v); +uint8_t config_cpld(); +void set_config_cpld(uint8_t i); + bool config_splash(); bool hide_clock(); bool clock_with_date();