Skip to content

Commit a6dde78

Browse files
repnopTheZoq2
authored andcommitted
Add SPI frame format config method
Fixes #279
1 parent 0e614f3 commit a6dde78

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- LSB/MSB bit format selection for `SPI`
13+
1014
## [v0.7.0]- 2020-10-17
1115

1216
### Breaking changes

src/spi.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ pub struct Spi<SPI, REMAP, PINS, FRAMESIZE> {
116116
_framesize: PhantomData<FRAMESIZE>,
117117
}
118118

119+
/// The bit format to send the data in
120+
#[derive(Debug, Clone, Copy)]
121+
pub enum SpiBitFormat {
122+
/// Least significant bit first
123+
LsbFirst,
124+
/// Most significant bit first
125+
MsbFirst,
126+
}
127+
119128
/// A filler type for when the SCK pin is unnecessary
120129
pub struct NoSck;
121130
/// A filler type for when the Miso pin is unnecessary
@@ -309,6 +318,14 @@ where
309318
pub fn release(self) -> (SPI, PINS) {
310319
(self.spi, self.pins)
311320
}
321+
322+
/// Select which frame format is used for data transfers
323+
pub fn bit_format(&mut self, format: SpiBitFormat) {
324+
match format {
325+
SpiBitFormat::LsbFirst => self.spi.cr1.modify(|_, w| w.lsbfirst().set_bit()),
326+
SpiBitFormat::MsbFirst => self.spi.cr1.modify(|_, w| w.lsbfirst().clear_bit()),
327+
}
328+
}
312329
}
313330

314331
impl<SPI, REMAP, PINS> Spi<SPI, REMAP, PINS, u8>

0 commit comments

Comments
 (0)