Added Settings app to disable Config Mode (#1781)

This commit is contained in:
Mark Thompson 2024-01-16 23:59:35 -06:00 committed by GitHub
parent e7af85ffba
commit 99bbd8805c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 101 additions and 17 deletions

View file

@ -145,7 +145,7 @@ struct misc_config_t {
bool disable_speaker : 1;
bool config_disable_external_tcxo : 1;
bool config_sdcard_high_speed_io : 1;
bool UNUSED_4 : 1;
bool config_disable_config_mode : 1;
bool UNUSED_5 : 1;
bool UNUSED_6 : 1;
bool UNUSED_7 : 1;
@ -156,6 +156,8 @@ struct misc_config_t {
};
static_assert(sizeof(misc_config_t) == sizeof(uint32_t));
#define MC_CONFIG_DISABLE_CONFIG_MODE 0x00000010 // config_disable_config_mode bit in struct above
/* IMPORTANT: Update dump_persistent_memory (below) when changing data_t. */
/* Struct must pack the same way on M4 and M0 cores.
@ -386,6 +388,7 @@ namespace cache {
void defaults() {
cached_backup_ram = backup_ram_t();
// If the desired default is 0/false, then no need to set it here (buffer is initialized to 0)
set_config_backlight_timer(backlight_config_t{});
set_config_splash(true);
set_config_disable_external_tcxo(false);
@ -416,8 +419,8 @@ void init() {
const auto switches_state = get_switches_state();
// ignore for valid check
auto config_mode_backup = config_mode_storage();
set_config_mode_storage(CONFIG_MODE_NORMAL_VALUE);
auto config_mode_backup = config_mode_storage_direct();
set_config_mode_storage_direct(CONFIG_MODE_NORMAL_VALUE);
if (!(switches_state[(size_t)ui::KeyEvent::Left] && switches_state[(size_t)ui::KeyEvent::Right]) && backup_ram->is_valid()) {
// Copy valid persistent data into cache.
@ -434,7 +437,7 @@ void init() {
// Copy defaults into cache.
defaults();
}
set_config_mode_storage(config_mode_backup);
set_config_mode_storage_direct(config_mode_backup);
}
void persist() {
@ -598,6 +601,10 @@ bool config_disable_external_tcxo() {
return data->misc_config.config_disable_external_tcxo;
}
bool config_disable_config_mode() {
return data->misc_config.config_disable_config_mode;
}
bool config_sdcard_high_speed_io() {
return data->misc_config.config_sdcard_high_speed_io;
}
@ -667,6 +674,10 @@ void set_config_disable_external_tcxo(bool v) {
data->misc_config.config_disable_external_tcxo = v;
}
void set_config_disable_config_mode(bool v) {
data->misc_config.config_disable_config_mode = v;
}
void set_config_sdcard_high_speed_io(bool v, bool save) {
if (v) {
/* 200MHz / (2 * 2) = 50MHz */
@ -948,12 +959,18 @@ void set_encoder_dial_sensitivity(uint8_t v) {
// Recovery mode magic value storage
static data_t* data_direct_access = reinterpret_cast<data_t*>(memory::map::backup_ram.base());
uint32_t config_mode_storage() {
uint32_t config_mode_storage_direct() {
return data_direct_access->config_mode_storage;
}
void set_config_mode_storage(uint32_t v) {
void set_config_mode_storage_direct(uint32_t v) {
data_direct_access->config_mode_storage = v;
}
bool config_disable_config_mode_direct() {
// "return data_direct_access->misc_config.config_disable_config_mode"
// Casting as U32 as workaround for misaligned memory access
uint32_t misc_config_u32 = *(uint32_t*)&data_direct_access->misc_config;
return ((misc_config_u32 & MC_CONFIG_DISABLE_CONFIG_MODE) != 0);
}
// PMem to sdcard settings
@ -1088,8 +1105,9 @@ bool debug_dump() {
// misc_config bits
pmem_dump_file.write_line("misc_config config_audio_mute: " + to_string_dec_int(config_audio_mute()));
pmem_dump_file.write_line("misc_config config_speaker_disable: " + to_string_dec_int(config_speaker_disable()));
pmem_dump_file.write_line("ui_config config_disable_external_tcxo: " + to_string_dec_uint(config_disable_external_tcxo()));
pmem_dump_file.write_line("ui_config config_sdcard_high_speed_io: " + to_string_dec_uint(config_sdcard_high_speed_io()));
pmem_dump_file.write_line("misc_config config_disable_external_tcxo: " + to_string_dec_uint(config_disable_external_tcxo()));
pmem_dump_file.write_line("misc_config config_sdcard_high_speed_io: " + to_string_dec_uint(config_sdcard_high_speed_io()));
pmem_dump_file.write_line("misc_config config_disable_config_mode: " + to_string_dec_uint(config_disable_config_mode()));
// receiver_model
pmem_dump_file.write_line("\n[Receiver Model]");