From b7a2d4f259ee3d02b33b52932aea015af57e5eb7 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Mon, 2 Nov 2020 16:35:21 -0500 Subject: [PATCH] Add SPI frame format config method Fixes #279 --- CHANGELOG.md | 4 ++++ src/spi.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1d087e9..d3824727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/spi.rs b/src/spi.rs index 234316a0..2fa14cca 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -116,6 +116,15 @@ pub struct Spi { _framesize: PhantomData, } +/// 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 @@ -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