Skip to content

Commit

Permalink
SPI: Add initializer based on bus number
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Oct 12, 2023
1 parent 904f848 commit 0fbf769
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use riot_sys::{
spi_transfer_bytes,
};

pub struct SPIDevice(pub spi_t);
pub struct SPIDevice(#[deprecated(note = "Use constructor instead")] pub spi_t);

pub struct AcquiredSPI<'a> {
device: &'a mut SPIDevice,
Expand All @@ -24,6 +24,17 @@ impl<'a> Drop for AcquiredSPI<'a> {
}

impl SPIDevice {
/// Create an SPI device from an `spi_t`
pub fn from_c(bus: spi_t) -> Self {
Self(bus)
}

/// Create an SPI device from the number it is assigned on the board
pub fn from_number(bus: u32) -> Self {
let bus = unsafe { riot_sys::macro_SPI_DEV(bus) };
Self::from_c(bus)
}

pub fn acquire<'a>(
&'a mut self,
cs: spi_cs_t,
Expand Down

0 comments on commit 0fbf769

Please sign in to comment.