chore(config): streamline flash interactions
All checks were successful
Publish nightly release / build (push) Successful in 1m16s
All checks were successful
Publish nightly release / build (push) Successful in 1m16s
This commit is contained in:
parent
8073328405
commit
ac1d6e08a2
1 changed files with 9 additions and 11 deletions
|
@ -554,7 +554,7 @@ impl ControllerConfig {
|
||||||
pub fn from_flash_memory(
|
pub fn from_flash_memory(
|
||||||
mut flash: &mut Flash<'static, FLASH, Async, FLASH_SIZE>,
|
mut flash: &mut Flash<'static, FLASH, Async, FLASH_SIZE>,
|
||||||
) -> Result<Self, embassy_rp::flash::Error> {
|
) -> Result<Self, embassy_rp::flash::Error> {
|
||||||
let mut controller_config_packed: <ControllerConfig as packed_struct::PackedStruct>::ByteArray = [0u8; 659]; // ControllerConfig byte size
|
let mut controller_config_packed: <ControllerConfig as packed_struct::PackedStruct>::ByteArray = ControllerConfig::default().pack().unwrap();
|
||||||
|
|
||||||
let r = flash.blocking_read(ADDR_OFFSET, &mut controller_config_packed);
|
let r = flash.blocking_read(ADDR_OFFSET, &mut controller_config_packed);
|
||||||
|
|
||||||
|
@ -569,23 +569,21 @@ impl ControllerConfig {
|
||||||
Ok(cfg) => match cfg {
|
Ok(cfg) => match cfg {
|
||||||
a if a.config_revision == CONTROLLER_CONFIG_REVISION => {
|
a if a.config_revision == CONTROLLER_CONFIG_REVISION => {
|
||||||
info!("Controller config loaded from flash: {}", a);
|
info!("Controller config loaded from flash: {}", a);
|
||||||
Ok(a)
|
return Ok(a);
|
||||||
}
|
}
|
||||||
a => {
|
a => {
|
||||||
warn!("Outdated controller config detected ({:02X}), or controller config was never present, using default.", a.config_revision);
|
warn!("Outdated controller config detected ({:02X}), or controller config was never present, using default.", a.config_revision);
|
||||||
let cfg = ControllerConfig::default();
|
|
||||||
info!("Going to save default controller config.");
|
|
||||||
cfg.write_to_flash(&mut flash)?;
|
|
||||||
Ok(cfg)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let cfg = ControllerConfig::default();
|
warn!("Controller config corrupted or flash uninitialized, using default.");
|
||||||
info!("Going to save default controller config.");
|
|
||||||
cfg.write_to_flash(&mut flash)?;
|
|
||||||
Ok(cfg)
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let cfg = ControllerConfig::default();
|
||||||
|
info!("Going to save default controller config.");
|
||||||
|
cfg.write_to_flash(&mut flash)?;
|
||||||
|
Ok(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_flash(
|
pub fn write_to_flash(
|
||||||
|
|
Loading…
Reference in a new issue