diff --git a/src/vendor/command/hal.rs b/src/vendor/command/hal.rs index 935a00b..3de4262 100644 --- a/src/vendor/command/hal.rs +++ b/src/vendor/command/hal.rs @@ -127,6 +127,14 @@ pub trait HalCommands { /// The controller will generate a [command complete](crate::event::command::CommandComplete) event. async fn get_link_status(&mut self); + /// This command sets the bitmask associated to + /// [End of Radio Activity](crate::vendor::event::VendorEvent::EndOfRadioActivity) event. + /// + /// Only the radio activities enabled in the mask will be reported to the application by the + /// [End of Radio Activity](crate::vendor::event::VendorEvent::EndOfRadioActivity) event. + // TODO: add EndOfRadioActivity event + async fn set_radio_activity_mask(&mut self, mask: RadioActivityMask); + /// This command is intended to retrieve information about the current Anchor Interval and /// allocable timing slots. /// @@ -138,6 +146,16 @@ pub trait HalCommands { /// /// The controller will generate a [command complete](crate::event::command::CommandComplete) event. async fn get_anchor_period(&mut self); + + // TODO: set_event_mask + // TODO: get_pm_debug_info + // TODO: set_peripheral_latency + // TODO: read_rssi + // TODO: read_radio_reg + // TODO: read_raw_rssi + // TODO: rx_start + // TODO: rx_stop + // TODO: stack_reset } impl HalCommands for T { @@ -201,6 +219,13 @@ impl HalCommands for T { self.controller_write(crate::vendor::opcode::HAL_GET_ANCHOR_PERIOD, &[]) .await } + + async fn set_radio_activity_mask(&mut self, mask: RadioActivityMask) { + let mut payload = [0; 2]; + LittleEndian::write_u16(&mut payload, mask.bits()); + self.controller_write(crate::vendor::opcode::HAL_SET_RADIO_ACTIVITY_MASK, &payload) + .await; + } } /// Potential errors from parameter validation. @@ -669,3 +694,44 @@ pub enum PowerLevel { /// 6 dBm. Plus6dBm = 0x1F, } + +#[cfg(not(feature = "defmt"))] +bitflags::bitflags! { + #[derive(Debug, Clone, Copy)] + pub struct RadioActivityMask: u16 { + /// Idle + const IDLE = 0x0001; + /// Advertising + const ADVERTISING = 0x0002; + /// Peripheral connection + const PERIPHERAL_CONN = 0x0004; + /// Scanning + const SCANNING = 0x0008; + /// Central connection + const CENTRAL_CONN = 0x0020; + /// Tx test mode + const TX_TEST = 0x0040; + /// Rx test mode + const RX_TEST = 0x0080; + } +} + +#[cfg(feature = "defmt")] +defmt::bitflags! { + pub struct RadioActivityMask: u16 { + /// Idle + const IDLE = 0x0001; + /// Advertising + const ADVERTISING = 0x0002; + /// Peripheral connection + const PERIPHERAL_CONN = 0x0004; + /// Scanning + const SCANNING = 0x0008; + /// Central connection + const CENTRAL_CONN = 0x0020; + /// Tx test mode + const TX_TEST = 0x0040; + /// Rx test mode + const RX_TEST = 0x0080; + } +} diff --git a/src/vendor/event/mod.rs b/src/vendor/event/mod.rs index b57a425..03a1b4a 100644 --- a/src/vendor/event/mod.rs +++ b/src/vendor/event/mod.rs @@ -21,6 +21,7 @@ pub use crate::{BdAddr, BdAddrType, ConnectionHandle}; #[allow(clippy::large_enum_variant)] #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +// TODO: add missing events pub enum VendorEvent { /// When the radio coprocessor firmware is started normally, it gives this event to the user to /// indicate the system has started. diff --git a/src/vendor/opcode.rs b/src/vendor/opcode.rs index dcdfc16..c96f9d9 100644 --- a/src/vendor/opcode.rs +++ b/src/vendor/opcode.rs @@ -33,6 +33,7 @@ vendor_opcodes! { pub const HAL_START_TONE = 0x15; pub const HAL_STOP_TONE = 0x16; pub const HAL_GET_LINK_STATUS = 0x17; + pub const HAL_SET_RADIO_ACTIVITY_MASK = 0x18; // The documentation says the OCF is 0xF8 (0b1111_1000), but that does not fit the OCF // length (7 bits). The C source code has 0x19, which is valid.