Skip to content

Add SPI frame format config method #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- LSB/MSB bit format selection for `SPI`

## [v0.7.0]- 2020-10-17

### Breaking changes
Expand Down
17 changes: 17 additions & 0 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ pub struct Spi<SPI, REMAP, PINS, FRAMESIZE> {
_framesize: PhantomData<FRAMESIZE>,
}

/// The bit format to send the data in
#[derive(Debug, Clone, Copy)]
pub enum SpiBitFormat {
/// Least significant bit first
LsbFirst,
/// Most significant bit first
MsbFirst,
}

/// A filler type for when the SCK pin is unnecessary
pub struct NoSck;
/// A filler type for when the Miso pin is unnecessary
Expand Down Expand Up @@ -309,6 +318,14 @@ where
pub fn release(self) -> (SPI, PINS) {
(self.spi, self.pins)
}

/// Select which frame format is used for data transfers
pub fn bit_format(&mut self, format: SpiBitFormat) {
match format {
SpiBitFormat::LsbFirst => self.spi.cr1.modify(|_, w| w.lsbfirst().set_bit()),
SpiBitFormat::MsbFirst => self.spi.cr1.modify(|_, w| w.lsbfirst().clear_bit()),
}
}
}

impl<SPI, REMAP, PINS> Spi<SPI, REMAP, PINS, u8>
Expand Down