RKTK API Docs RKTK Home Repo

rktk_drivers_nrf/
system.rs

1use embassy_nrf::gpio::{Level, Output};
2use rktk::{drivers::interface::system::SystemDriver, utils::Mutex};
3
4pub struct NrfSystemDriver<'d> {
5    vcc_cutoff: Option<Mutex<(Output<'d>, Level)>>,
6}
7
8impl<'d> NrfSystemDriver<'d> {
9    pub fn new(vcc_cutoff: Option<(Output<'d>, Level)>) -> Self {
10        Self {
11            vcc_cutoff: vcc_cutoff.map(|(pin, level)| Mutex::new((pin, level))),
12        }
13    }
14}
15
16impl SystemDriver for NrfSystemDriver<'_> {
17    #[cfg(feature = "power")]
18    async fn power_off(&self) {
19        {
20            if let Some(vcc_cutoff) = &self.vcc_cutoff {
21                let mut out = vcc_cutoff.lock().await;
22                let level = out.1;
23                out.0.set_level(level);
24                embassy_time::Timer::after_millis(50).await;
25            }
26        }
27
28        embassy_nrf::power::set_system_off();
29        cortex_m::asm::udf();
30    }
31}