Skip to content

Commit

Permalink
Merge pull request #437 from quartiq/feature/sequential-storage-updates
Browse files Browse the repository at this point in the history
Updating sequential-storage implementation
  • Loading branch information
jordens authored Aug 29, 2024
2 parents 1096a71 + b7747f2 commit 8d783a6
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 204 deletions.
9 changes: 6 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enc424j600 = "0.4"
embedded-hal = "1"
smoltcp-nal = { version = "0.5", features=["shared-stack"] }

serial-settings = {git = "https://github.com/quartiq/stabilizer", rev = "5452272931e1ad70547b578052ffbb186fb72514"}
serial-settings = "0.1"
stm32f4xx-hal = {version = "0.21.0", features = ["stm32f407", "usb_fs"] }

postcard = "1"
Expand Down
6 changes: 4 additions & 2 deletions src/hardware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ pub enum Mac {
Enc424j600(enc424j600::Enc424j600<SpiDevice>),
}

pub type SerialTerminal =
serial_settings::Runner<'static, crate::settings::flash::SerialSettingsPlatform, 5>;
pub type SerialSettingsPlatform =
crate::settings::flash::SerialSettingsPlatform<crate::settings::Settings, 5>;

pub type SerialTerminal = serial_settings::Runner<'static, SerialSettingsPlatform, 5>;

pub type NetworkStack = smoltcp_nal::NetworkStack<'static, Mac, SystemTimer>;

Expand Down
3 changes: 2 additions & 1 deletion src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub fn setup(
// values stored in flash. This helps preserve backwards compatibility with older Booster
// firmware versions that didn't store settings in flash. We no longer persist settings to
// EEPROM, so flash will have the latest and greatest settings data.
crate::settings::flash::load_from_flash(&mut settings, &mut flash);
crate::settings::flash::SerialSettingsPlatform::load(&mut settings, &mut flash);

let mut mac = {
let mut spi = {
Expand Down Expand Up @@ -548,6 +548,7 @@ pub fn setup(
serial_settings::Runner::new(
crate::settings::flash::SerialSettingsPlatform {
metadata,
_settings_marker: core::marker::PhantomData,
interface: serial_settings::BestEffortInterface::new(usb_serial),
storage: flash,
},
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ mod app {
.lock(|watchdog| watchdog.check_in(WatchdogClient::Usb));

(&mut c.shared.usb_terminal, &mut c.shared.settings).lock(|terminal, settings| {
// Handle the USB serial terminal.
c.local.usb.process(terminal);
if terminal.process(settings).unwrap() {
update_settings::spawn().unwrap();
if terminal.poll(settings).unwrap() {
update_settings::spawn().unwrap()
}

// Process any log output.
LOGGER.process(terminal);
});
Expand Down
8 changes: 6 additions & 2 deletions src/net/mqtt_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ use core::fmt::Write;
use heapless::{String, Vec};
use serde::Serialize;

use crate::settings::{flash::SerialSettingsPlatform, Settings};
use crate::hardware::SerialSettingsPlatform;
use crate::settings::Settings;
use miniconf::{IntoKeys, Keys, Path, Postcard, TreeKey};
use serial_settings::Platform;

/// Default metadata message if formatting errors occur.
const DEFAULT_METADATA: &str = "{\"message\":\"Truncated: See USB terminal\"}";
Expand Down Expand Up @@ -266,7 +268,9 @@ pub fn save_settings_to_flash(
.len();
data.truncate(len);

settings_platform.save_item(&mut buf[..], channel_path.0, data);
settings_platform
.store(&mut buf[..], channel_path.0.as_bytes(), &data)
.map_err(|_| "Failed to save to flash")?;
}

Ok(0)
Expand Down
Loading

0 comments on commit 8d783a6

Please sign in to comment.