Skip to content

Commit

Permalink
Expose the additional APIs on EspThread too
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Sep 19, 2024
1 parent ef7bfb8 commit a18a43b
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const BAUD_RATE: u32 = 115200;

macro_rules! ot_esp {
($err:expr) => {{
esp!(match $err {
esp!(match $err as _ {
otError_OT_ERROR_NONE => ESP_OK,
otError_OT_ERROR_FAILED => ESP_FAIL,
_ => ESP_FAIL, // For now
Expand Down Expand Up @@ -334,6 +334,10 @@ impl<'d> ThreadDriver<'d, Host> {
}
}

extern "C" {
fn otAppNcpInit(instance: *mut otInstance);
}

#[cfg(esp_idf_soc_ieee802154_supported)]
impl<'d> ThreadDriver<'d, RCP> {
/// Create a new Thread RCP driver instance utilizing an SPI connection
Expand Down Expand Up @@ -404,6 +408,10 @@ impl<'d> ThreadDriver<'d, RCP> {

Self::init(&cfg, false)?;

unsafe {
otAppNcpInit(esp_openthread_get_instance());
}

Ok(Self {
mode: RCP,
_mounted_event_fs: mounted_event_fs,
Expand Down Expand Up @@ -483,6 +491,10 @@ impl<'d> ThreadDriver<'d, RCP> {

Self::init(&cfg, false)?;

unsafe {
otAppNcpInit(esp_openthread_get_instance());
}

Ok(Self {
mode: RCP,
_mounted_event_fs: mounted_event_fs,
Expand Down Expand Up @@ -729,6 +741,45 @@ impl<'d> EspThread<'d> {
&mut self.netif
}

/// Retrieve the active TOD (Thread Operational Dataset) in the user-supplied buffer
///
/// Return the size of the TOD data written to the buffer
///
/// The TOD is in Thread TLV format.
pub fn tod(&self, buf: &mut [u8]) -> Result<usize, EspError> {
self.driver().tod(buf)
}

/// Retrieve the pending TOD (Thread Operational Dataset) in the user-supplied buffer
///
/// Return the size of the TOD data written to the buffer
///
/// The TOD is in Thread TLV format.
pub fn pending_tod(&self, buf: &mut [u8]) -> Result<usize, EspError> {
self.driver().pending_tod(buf)
}

/// Set the active TOD (Thread Operational Dataset) to the provided data
///
/// The TOD data should be in Thread TLV format.
pub fn set_tod(&self, tod: &[u8]) -> Result<(), EspError> {
self.driver().set_tod(tod)
}

/// Set the pending TOD (Thread Operational Dataset) to the provided data
///
/// The TOD data should be in Thread TLV format.
pub fn set_pending_tod(&self, tod: &[u8]) -> Result<(), EspError> {
self.driver().set_pending_tod(tod)
}

/// Set the active TOD (Thread Operational Dataset) according to the
/// `CONFIG_OPENTHREAD_` TOD-related parameters compiled into the app
/// during build (via `sdkconfig*)
pub fn set_active_tod_from_cfg(&self) -> Result<(), EspError> {
ot_esp!(unsafe { esp_openthread_auto_start(core::ptr::null_mut()) })
}

/// Run the Thread stack
///
/// The current thread would block while the stack is running
Expand Down

0 comments on commit a18a43b

Please sign in to comment.