Skip to content

Commit

Permalink
feat(vendor HAL command): add Set Radio Activity Mask command
Browse files Browse the repository at this point in the history
  • Loading branch information
OueslatiGhaith committed Jan 4, 2024
1 parent 7bac2f2 commit 59c054d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/vendor/command/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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<T: Controller> HalCommands for T {
Expand Down Expand Up @@ -201,6 +219,13 @@ impl<T: Controller> 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.
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/vendor/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/vendor/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 59c054d

Please sign in to comment.