diff options
author | alexmoon <alex.r.moon@gmail.com> | 2022-03-26 12:59:20 -0400 |
---|---|---|
committer | alexmoon <alex.r.moon@gmail.com> | 2022-03-26 12:59:20 -0400 |
commit | 4f283a4555736715cfb1ae0d21e062a6f5e28919 (patch) | |
tree | 6aa851719dae645428cc0f644c5b979918c878b4 | |
parent | a9af20b6ce1276addd04f8a7681a84b3d569d3e7 (diff) | |
download | nrf-softdevice-4f283a4555736715cfb1ae0d21e062a6f5e28919.zip |
Remove flash events from SocEvent and add docs.
-rw-r--r-- | nrf-softdevice/src/events.rs | 22 | ||||
-rw-r--r-- | nrf-softdevice/src/softdevice.rs | 7 |
2 files changed, 16 insertions, 13 deletions
diff --git a/nrf-softdevice/src/events.rs b/nrf-softdevice/src/events.rs index f45538e..5df73f1 100644 --- a/nrf-softdevice/src/events.rs +++ b/nrf-softdevice/src/events.rs @@ -11,6 +11,7 @@ use crate::RawError; static SWI2_WAKER: AtomicWaker = AtomicWaker::new(); +/// SoC events reported by the softdevice. #[rustfmt::skip] #[repr(u32)] #[derive(Debug, PartialEq, Eq, Clone, Copy, IntoPrimitive, TryFromPrimitive)] @@ -18,8 +19,6 @@ static SWI2_WAKER: AtomicWaker = AtomicWaker::new(); pub enum SocEvent { Hfclkstarted = raw::NRF_SOC_EVTS_NRF_EVT_HFCLKSTARTED, PowerFailureWarning = raw::NRF_SOC_EVTS_NRF_EVT_POWER_FAILURE_WARNING, - FlashOperationSuccess = raw::NRF_SOC_EVTS_NRF_EVT_FLASH_OPERATION_SUCCESS, - FlashOperationError = raw::NRF_SOC_EVTS_NRF_EVT_FLASH_OPERATION_ERROR, RadioBlocked = raw::NRF_SOC_EVTS_NRF_EVT_RADIO_BLOCKED, RadioCanceled = raw::NRF_SOC_EVTS_NRF_EVT_RADIO_CANCELED, RadioSignalCallbackInvalidReturn = raw::NRF_SOC_EVTS_NRF_EVT_RADIO_SIGNAL_CALLBACK_INVALID_RETURN, @@ -34,16 +33,19 @@ pub enum SocEvent { } fn on_soc_evt<F: FnMut(SocEvent)>(evt: u32, evt_handler: &mut F) { - let evt = match SocEvent::try_from(evt) { - Ok(evt) => evt, - Err(_) => panic!("Unknown soc evt {:?}", evt), - }; - info!("soc evt {:?}", evt); + match evt { - SocEvent::FlashOperationError => crate::flash::on_flash_error(), - SocEvent::FlashOperationSuccess => crate::flash::on_flash_success(), - _ => evt_handler(evt), + raw::NRF_SOC_EVTS_NRF_EVT_FLASH_OPERATION_ERROR => crate::flash::on_flash_error(), + raw::NRF_SOC_EVTS_NRF_EVT_FLASH_OPERATION_SUCCESS => crate::flash::on_flash_success(), + _ => { + let evt = match SocEvent::try_from(evt) { + Ok(evt) => evt, + Err(_) => panic!("Unknown soc evt {:?}", evt), + }; + + evt_handler(evt) + } } } diff --git a/nrf-softdevice/src/softdevice.rs b/nrf-softdevice/src/softdevice.rs index af8a0b4..d697cbe 100644 --- a/nrf-softdevice/src/softdevice.rs +++ b/nrf-softdevice/src/softdevice.rs @@ -323,10 +323,11 @@ impl Softdevice { self.run_with_callback(|_| {}).await } - /// Runs the softdevice event handling loop. + /// Runs the softdevice event handling loop with a callback for [`SocEvent`]s. /// - /// It must be called in its own async task after enabling the softdevice - /// and before doing any operation. Failure to doing so will cause async operations to never finish. + /// It must be called under the same conditions as [`Softdevice::run()`]. This + /// version allows the application to provide a callback to receive SoC events + /// from the softdevice (other than flash events which are handled by [`Flash`](crate::flash::Flash)). pub async fn run_with_callback<F: FnMut(SocEvent)>(&self, f: F) -> ! { crate::events::run(f).await } |