ariel_os_rp/spi/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Provides support for the SPI communication bus.

#[doc(alias = "master")]
pub mod main;

use ariel_os_embassy_common::spi::Mode;
use embassy_rp::spi::{Phase, Polarity};

fn from_mode(mode: Mode) -> (Polarity, Phase) {
    match mode {
        Mode::Mode0 => (Polarity::IdleLow, Phase::CaptureOnFirstTransition),
        Mode::Mode1 => (Polarity::IdleLow, Phase::CaptureOnSecondTransition),
        Mode::Mode2 => (Polarity::IdleHigh, Phase::CaptureOnFirstTransition),
        Mode::Mode3 => (Polarity::IdleHigh, Phase::CaptureOnSecondTransition),
    }
}

#[doc(hidden)]
pub fn init(peripherals: &mut crate::OptionalPeripherals) {
    // Take all SPI peripherals and do nothing with them.
    cfg_if::cfg_if! {
        if #[cfg(context = "rp2040")] {
            let _ = peripherals.SPI0.take().unwrap();
            let _ = peripherals.SPI1.take().unwrap();
        } else {
            compile_error!("this RP chip is not supported");
        }
    }
}