Merge pull request #536 from jLynx/gen1

Fixed R1_20150901 vs R2_20170522 boot & detection issues. Read up about it here https://github.com/eried/portapack-mayhem/wiki/Won't-boot
This commit is contained in:
jLynx 2022-04-06 13:52:00 +12:00 committed by GitHub
commit e26d026216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 26 deletions

View File

@ -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();

View File

@ -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<PortaPackModel> 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_20150901::config;
}
Backlight* backlight() {
return (portapack_model() == PortaPackModel::R2_20170522)
? static_cast<portapack::Backlight*>(&backlight_cat4004)
: static_cast<portapack::Backlight*>(&backlight_on_off);
? static_cast<portapack::Backlight*>(&backlight_cat4004) // R2_20170522
: static_cast<portapack::Backlight*>(&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);
touch::adc::init();
controls_init();
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();
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;
}

View File

@ -115,6 +115,10 @@ void AK4951::init() {
// update(Register::DigitalFilterMode);
}
bool AK4951::detected() {
return reset();
}
bool AK4951::reset() {
io.audio_reset_state(true);

View File

@ -824,6 +824,8 @@ public:
return "AK4951";
}
bool detected();
void init() override;
bool reset() override;

View File

@ -83,6 +83,9 @@ struct data_t {
int32_t modem_baudrate;
int32_t modem_repeat;
// Hardware
uint32_t hardware_config;
// Play dead unlock
uint32_t playdead_magic;
uint32_t playing_dead;
@ -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);
}

View File

@ -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();