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 c4f03855..15b9d5c2 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,18 +181,19 @@ 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 { - model = PortaPackModel::R2_20170522; - //} + if( audio_codec_wm8731.detected() ) { + model = PortaPackModel::R1_20150901; // H1R1 + } else { + model = PortaPackModel::R2_20170522; // H1R2, H2+ + } } return model.value(); } +//audio_codec_wm8731 = H1R1 & H2+ +//audio_codec_ak4951 = H1R2 + static audio::Codec* portapack_audio_codec() { /* I2C ready OK, Automatic recognition of audio chip */ return (audio_codec_wm8731.detected()) @@ -200,16 +203,34 @@ 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]){ + 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() { 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 +339,15 @@ bool init() { i2c0.start(i2c_config_boot_clock); - if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { - shutdown_base(); - return false; - } + // Keeping this here for now incase we need to revert + // 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(); @@ -377,20 +399,30 @@ bool init() { i2c0.start(i2c_config_fast_clock); - clock_manager.set_reference_ppb(persistent_memory::correction_ppb()); + touch::adc::init(); + controls_init(); - audio::init(portapack_audio_codec()); - + 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(); - - touch::adc::init(); + 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; + } + + if( !hackrf::cpld::load_sram() ) { + chSysHalt(); + } + return true; } diff --git a/firmware/common/ak4951.cpp b/firmware/common/ak4951.cpp index d94bbb0b..1f88a3d6 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 ea394966..3b1f9e1a 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; diff --git a/firmware/common/portapack_persistent_memory.cpp b/firmware/common/portapack_persistent_memory.cpp index 2bee6470..0fdada7d 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 11643bab..d04b1239 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();