Skip to main content

ariel_os_nrf/spi/
mod.rs

1//! Provides support for the SPI communication bus.
2
3#[doc(alias = "master")]
4pub mod main;
5
6use ariel_os_embassy_common::spi::{BitOrder, Mode};
7
8fn from_mode(mode: Mode) -> embassy_nrf::spim::Mode {
9    match mode {
10        Mode::Mode0 => embassy_nrf::spim::MODE_0,
11        Mode::Mode1 => embassy_nrf::spim::MODE_1,
12        Mode::Mode2 => embassy_nrf::spim::MODE_2,
13        Mode::Mode3 => embassy_nrf::spim::MODE_3,
14    }
15}
16
17fn from_bit_order(bit_order: BitOrder) -> embassy_nrf::spim::BitOrder {
18    match bit_order {
19        BitOrder::MsbFirst => embassy_nrf::spim::BitOrder::MSB_FIRST,
20        BitOrder::LsbFirst => embassy_nrf::spim::BitOrder::LSB_FIRST,
21    }
22}
23
24#[doc(hidden)]
25pub fn init(peripherals: &mut crate::OptionalPeripherals) {
26    // Take all SPI peripherals and do nothing with them.
27    cfg_select! {
28        context = "nrf52833" => {
29            let _ = peripherals.SPI3.take().unwrap();
30        }
31        context = "nrf52840" => {
32            let _ = peripherals.SPI2.take().unwrap();
33            let _ = peripherals.SPI3.take().unwrap();
34        }
35        context = "nrf5340-app" => {
36            let _ = peripherals.SERIAL2.take().unwrap();
37            // Used by UART
38            // let _ = peripherals.SERIAL3.take().unwrap();
39        }
40        context = "nrf91" => {
41            let _ = peripherals.SERIAL2.take().unwrap();
42            // Used by UART
43            // let _ = peripherals.SERIAL3.take().unwrap();
44        }
45        _ => {
46            compile_error!("this nRF chip is not supported");
47        }
48    }
49}