Compare commits
No commits in common. "b3e9a1b6360ff4764a3455558df0acd19913abda" and "8d70c03520e1cc221e40232cad3f4beb4fec5199" have entirely different histories.
b3e9a1b636
...
8d70c03520
|
@ -51,39 +51,12 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
/// apply loaded config to system
|
||||
pub fn apply(&self, channels: &mut Channels) {
|
||||
for i in 0..CHANNELS {
|
||||
self.channels[i].apply(channels, i);
|
||||
}
|
||||
pub fn encode<'a>(&self, buffer: &'a mut [u8]) -> Result<&'a mut [u8], postcard::Error> {
|
||||
to_slice(self, buffer)
|
||||
}
|
||||
|
||||
pub fn load(eeprom: &mut pins::Eeprom) -> Result<Self, Error> {
|
||||
let mut buffer = [0; EEPROM_SIZE];
|
||||
eeprom.read_data(0, &mut buffer)?;
|
||||
log::info!("load: {:?}", buffer);
|
||||
let config = from_bytes(&mut buffer)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub fn save(&self, eeprom: &mut pins::Eeprom) -> Result<(), Error> {
|
||||
let mut buffer = [0; EEPROM_SIZE];
|
||||
let config_buffer = to_slice(self, &mut buffer)?;
|
||||
log::info!("save: {:?}", config_buffer);
|
||||
|
||||
let mut addr = 0;
|
||||
for chunk in config_buffer.chunks(EEPROM_PAGE_SIZE) {
|
||||
'write_retry: loop {
|
||||
match eeprom.write_page(addr, chunk) {
|
||||
Ok(()) => break 'write_retry,
|
||||
Err(eeprom24x::Error::I2C(i2c::Error::NACK)) => {},
|
||||
Err(e) => Err(e)?,
|
||||
}
|
||||
}
|
||||
addr += chunk.len() as u32;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
pub fn decode(buffer: &[u8]) -> Result<Self, postcard::Error> {
|
||||
from_bytes(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::usb;
|
||||
|
||||
#[cfg(not(feature = "semihosting"))]
|
||||
static USB_LOGGER: usb::Logger = usb::Logger;
|
||||
|
||||
#[cfg(not(feature = "semihosting"))]
|
||||
pub fn init_log() {
|
||||
static USB_LOGGER: usb::Logger = usb::Logger;
|
||||
let _ = log::set_logger(&USB_LOGGER);
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
}
|
||||
|
||||
#[cfg(feature = "semihosting")]
|
||||
|
|
|
@ -124,9 +124,6 @@ fn main() -> ! {
|
|||
usb::State::setup(usb);
|
||||
|
||||
let mut channels = Channels::new(pins);
|
||||
let _ = Config::load(&mut eeprom)
|
||||
.map(|config| config.apply(&mut channels))
|
||||
.map_err(|e| warn!("error loading config: {:?}", e));
|
||||
|
||||
// EEPROM ships with a read-only EUI-48 identifier
|
||||
let mut eui48 = [0; 6];
|
||||
|
|
Loading…
Reference in New Issue