Fixed no audio issue v2 (#567)

* Fixed no audio issue v2 (#567)
This commit is contained in:
jLynx 2022-04-12 09:28:36 +12:00 committed by GitHub
parent 5d9a2e560b
commit 178528ef96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,24 +212,53 @@ int read_file(std::string name) {
} }
static int load_config(){ static int load_config(){
static Optional<int> config_value;
if(!config_value.is_valid()){
int8_t value = portapack::persistent_memory::config_cpld(); int8_t value = portapack::persistent_memory::config_cpld();
if(value == 0 && sd_card::status() == sd_card::Status::Mounted){ if((value <= 0 || value >= 4) && sd_card::status() == sd_card::Status::Mounted){
int data = read_file("/hardware/settings.txt"); int data = read_file("/hardware/settings.txt");
if(data != -1) { if(data != -1) {
return data; config_value = data;
}
} else {
config_value = value;
} }
} }
return value; return config_value.value();
} }
static PortaPackModel portapack_model() { static PortaPackModel portapack_model() {
static Optional<PortaPackModel> model; static Optional<PortaPackModel> model;
if( !model.is_valid() ) { if( !model.is_valid() ) {
const auto switches_state = get_switches_state();
if (switches_state[(size_t)ui::KeyEvent::Up]){
save_config(1);
model = PortaPackModel::R2_20170522;
}
else if (switches_state[(size_t)ui::KeyEvent::Down]){
save_config(2);
model = PortaPackModel::R1_20150901;
}
else if (switches_state[(size_t)ui::KeyEvent::Left]){
save_config(3);
}
else if (switches_state[(size_t)ui::KeyEvent::Select]){
save_config(0);
}
if (load_config() == 1) {
model = PortaPackModel::R2_20170522;
} else if (load_config() == 2) {
model = PortaPackModel::R1_20150901;
} else {
if( audio_codec_wm8731.detected() ) { if( audio_codec_wm8731.detected() ) {
model = PortaPackModel::R1_20150901; // H1R1 model = PortaPackModel::R1_20150901; // H1R1
} else { } else {
model = PortaPackModel::R2_20170522; // H1R2, H2+ model = PortaPackModel::R2_20170522; // H1R2, H2, H2+
}
} }
} }
@ -248,28 +277,6 @@ static audio::Codec* portapack_audio_codec() {
} }
static const portapack::cpld::Config& portapack_cpld_config() { static const portapack::cpld::Config& portapack_cpld_config() {
const auto switches_state = get_switches_state();
if (switches_state[(size_t)ui::KeyEvent::Up]){
save_config(1);
return portapack::cpld::rev_20170522::config;
}
if (switches_state[(size_t)ui::KeyEvent::Down]){
save_config(2);
return portapack::cpld::rev_20150901::config;
}
if (switches_state[(size_t)ui::KeyEvent::Left]){
save_config(3);
}
if (switches_state[(size_t)ui::KeyEvent::Select]){
save_config(0);
}
if (load_config() == 1) {
return portapack::cpld::rev_20170522::config;
} else if (load_config() == 2) {
return portapack::cpld::rev_20150901::config;
}
return (portapack_model() == PortaPackModel::R2_20170522) return (portapack_model() == PortaPackModel::R2_20170522)
? portapack::cpld::rev_20170522::config ? portapack::cpld::rev_20170522::config
: portapack::cpld::rev_20150901::config; : portapack::cpld::rev_20150901::config;
@ -456,18 +463,14 @@ bool init() {
radio::init(); radio::init();
sdcStart(&SDCD1, nullptr); sdcStart(&SDCD1, nullptr);
sd_card::poll_inserted(); sd_card::poll_inserted();
chThdSleepMilliseconds(1);
if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) {
chThdSleepMilliseconds(1);
// If using a "2021/12 QFP100", press and hold the left button while booting. Should only need to do once. // If using a "2021/12 QFP100", press and hold the left button while booting. Should only need to do once.
const auto switches_state = get_switches_state(); if (load_config() != 3){
/*
* The LEFT key held check seems redundant as its in the portapack_cpld_config().
* But for some reason the persistent_memory check fails on some devices if we dont have the extra check in....
* So dont ask me why that is, but we have to keep this redundant check in for the persistent_memory check to work.
*/
if (!switches_state[(size_t)ui::KeyEvent::Left] && load_config() != 3){
shutdown_base(); shutdown_base();
return false; return false;
} }
@ -477,6 +480,8 @@ bool init() {
chSysHalt(); chSysHalt();
} }
chThdSleepMilliseconds(1); // This delay seems to solve white noise audio issues
LPC_CREG->DMAMUX = portapack::gpdma_mux; LPC_CREG->DMAMUX = portapack::gpdma_mux;
gpdma::controller.enable(); gpdma::controller.enable();