pub enum Mode {
Mode0,
Mode1,
Mode2,
Mode3,
}Expand description
An SPI clock mode: the (CPOL, CPHA) pair a controller and peripheral must share.
The mode number is (CPOL << 1) | CPHA, so the four modes are:
| Mode | CPOL | CPHA | Clock idles | Data sampled on |
|---|---|---|---|---|
| 0 | 0 | 0 | low | leading edge (rising) |
| 1 | 0 | 1 | low | trailing edge (falling) |
| 2 | 1 | 0 | high | leading edge (falling) |
| 3 | 1 | 1 | high | trailing edge (rising) |
§Examples
use pamoja_gpio::spi::Mode;
// An SD card and most LoRa radios use mode 0.
assert_eq!(Mode::Mode0.number(), 0);
assert_eq!(Mode::Mode0.cpol_cpha(), (false, false));
assert_eq!(Mode::from_number(3), Some(Mode::Mode3));
assert_eq!(Mode::from_cpol_cpha(true, false), Mode::Mode2);Variants§
Mode0
CPOL 0, CPHA 0: clock idles low, data sampled on the rising (leading) edge.
Mode1
CPOL 0, CPHA 1: clock idles low, data sampled on the falling (trailing) edge.
Mode2
CPOL 1, CPHA 0: clock idles high, data sampled on the falling (leading) edge.
Mode3
CPOL 1, CPHA 1: clock idles high, data sampled on the rising (trailing) edge.
Implementations§
Source§impl Mode
impl Mode
Sourcepub fn from_number(number: u8) -> Option<Mode>
pub fn from_number(number: u8) -> Option<Mode>
Sourcepub fn cpol_cpha(self) -> (bool, bool)
pub fn cpol_cpha(self) -> (bool, bool)
Returns the (CPOL, CPHA) pair for this mode.
§Returns
(clock idles high, data sampled on the trailing edge).
Sourcepub fn from_cpol_cpha(cpol: bool, cpha: bool) -> Mode
pub fn from_cpol_cpha(cpol: bool, cpha: bool) -> Mode
Sourcepub fn clock_idles_high(self) -> bool
pub fn clock_idles_high(self) -> bool
Returns true if the clock idles high (CPOL = 1), which is modes 2 and 3.
Sourcepub fn samples_on_trailing_edge(self) -> bool
pub fn samples_on_trailing_edge(self) -> bool
Returns true if data is sampled on the trailing clock edge (CPHA = 1), which is
modes 1 and 3.
Trait Implementations§
impl Copy for Mode
impl Eq for Mode
impl StructuralPartialEq for Mode
Auto Trait Implementations§
impl Freeze for Mode
impl RefUnwindSafe for Mode
impl Send for Mode
impl Sync for Mode
impl Unpin for Mode
impl UnsafeUnpin for Mode
impl UnwindSafe for Mode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more