Skip to content

Commit adfa670

Browse files
committed
BitFormat
1 parent 84d3336 commit adfa670

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/spi.rs

+17
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ impl FrameSize for u16 {
143143
const DFF: bool = true;
144144
}
145145

146+
/// The bit format to send the data in
147+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
148+
pub enum BitFormat {
149+
/// Least significant bit first
150+
LsbFirst,
151+
/// Most significant bit first
152+
MsbFirst,
153+
}
154+
146155
#[derive(Debug)]
147156
pub struct Spi<SPI, PINS, const BIDI: bool = false, W = u8, OPERATION = Master> {
148157
spi: SPI,
@@ -520,6 +529,14 @@ impl<SPI: Instance, PINS, const BIDI: bool, W, OPERATION> Spi<SPI, PINS, BIDI, W
520529
self
521530
}
522531

532+
/// Select which frame format is used for data transfers
533+
pub fn bit_format(&mut self, format: BitFormat) {
534+
match format {
535+
BitFormat::LsbFirst => self.spi.cr1.modify(|_, w| w.lsbfirst().set_bit()),
536+
BitFormat::MsbFirst => self.spi.cr1.modify(|_, w| w.lsbfirst().clear_bit()),
537+
}
538+
}
539+
523540
/// Enable interrupts for the given `event`:
524541
/// - Received data ready to be read (RXNE)
525542
/// - Transmit data register empty (TXE)

0 commit comments

Comments
 (0)