Skip to content

Commit

Permalink
Switch puzzle-fw to use RTIC as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpallant committed Dec 12, 2024
1 parent 20f464e commit f27c694
Show file tree
Hide file tree
Showing 4 changed files with 650 additions and 457 deletions.
45 changes: 0 additions & 45 deletions nrf52-code/boards/dongle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,51 +230,6 @@ impl core::fmt::Write for &Ringbuffer {
}
}

/// The global type for sharing things with an interrupt handler
pub struct GlobalIrqState<T> {
inner: critical_section::Mutex<core::cell::RefCell<Option<T>>>,
}

impl<T> GlobalIrqState<T> {
/// Create a new, empty, object
pub const fn new() -> GlobalIrqState<T> {
GlobalIrqState {
inner: critical_section::Mutex::new(core::cell::RefCell::new(None)),
}
}

/// Load a value into the global
///
/// Returns the old value, if any
pub fn load(&self, value: T) -> Option<T> {
critical_section::with(|cs| self.inner.borrow(cs).replace(Some(value)))
}
}

/// The local type for sharing things with an interrupt handler
pub struct LocalIrqState<T> {
inner: Option<T>,
}

impl<T> LocalIrqState<T> {
/// Create a new, empty, object
pub const fn new() -> LocalIrqState<T> {
LocalIrqState { inner: None }
}

/// Grab a mutable reference to the contents.
///
/// If the value is empty, the contents are taken from a mutex-locked global
/// variable. That global must have been initialised before calling this
/// function. If not, this function panics.
pub fn get_or_init_with(&mut self, global: &GlobalIrqState<T>) -> &mut T {
let result = self.inner.get_or_insert_with(|| {
critical_section::with(|cs| global.inner.borrow(cs).replace(None).unwrap())
});
result
}
}

/// The ways that initialisation can fail
#[derive(Debug, Copy, Clone, defmt::Format)]
pub enum Error {
Expand Down
176 changes: 168 additions & 8 deletions nrf52-code/puzzle-fw/Cargo.lock

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

35 changes: 8 additions & 27 deletions nrf52-code/puzzle-fw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,15 @@ version = "0.0.0"

[dependencies]
consts = { path = "../consts" }
cortex-m = {version = "0.7.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7.5"
critical-section = "1.2.0"
defmt = "0.3.10"
defmt-rtt = "0.4.1"
dongle = { path = "../boards/dongle" }
embedded-hal = "1.0"
heapless = "0.8"
usb-device = "0.3"
usbd-hid = "0.8"
usbd-serial = "0.2"
heapless = { version = "0.8.0", features = ["defmt-03"] }
rtic = { version = "2.1.2", features = ["thumbv7-backend"] }
rtic-monotonics = { version = "2.0.3", features = ["cortex-m-systick"] }
usb-device = { version = "0.3.2", features = ["defmt"] }
usbd-hid = { version = "0.8.2", features = ["defmt"] }
usbd-serial = "0.2.2"

[build-dependencies]
rand = "0.8.5"

# optimize code in both profiles
[profile.dev]
codegen-units = 1
debug = 2
debug-assertions = true # !
incremental = false
lto = "fat"
opt-level = 'z' # !
overflow-checks = false

[profile.release]
codegen-units = 1
debug = 2
debug-assertions = false
incremental = false
lto = "fat"
opt-level = 3
overflow-checks = false
Loading

0 comments on commit f27c694

Please sign in to comment.