Skip to main content
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 { vcc_cutoff: vcc_cutoff.map(|(pin, level)| Mutex::new((pin, level))) }
11    }
12}
13
14impl SystemDriver for NrfSystemDriver<'_> {
15    #[cfg(feature = "power")]
16    async fn power_off(&self) {
17        {
18            if let Some(vcc_cutoff) = &self.vcc_cutoff {
19                let mut out = vcc_cutoff.lock().await;
20                let level = out.1;
21                out.0.set_level(level);
22                embassy_time::Timer::after_millis(50).await;
23            }
24        }
25
26        embassy_nrf::power::set_system_off();
27        cortex_m::asm::udf();
28    }
29}