Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `i2s-audio-out` example updated and now use pcm5102 dac module instead one from discovery board.
- extend visibility of gpio/marker to crate since i2s module require it.
- Bump `synopsys-usb-otg` to `0.3.0`
- Bump `embedded-hal` to `1.0.0-alpha.8`

### Added
- example of using i2s in out with rtic and interrupt.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ version = "0.3"
default-features = false

[dependencies.embedded-hal-one]
version = "=1.0.0-alpha.7"
version = "=1.0.0-alpha.8"
package = "embedded-hal"

[dependencies.stm32_i2s_v12x]
Expand Down
16 changes: 0 additions & 16 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ macro_rules! adc_pins {
type ID = u8;
fn channel() -> u8 { $chan }
}

impl embedded_hal_one::adc::nb::Channel<pac::$adc> for $pin {
type ID = u8;
fn channel(&self) -> u8 { $chan }
}
)+
};
}
Expand Down Expand Up @@ -1075,17 +1070,6 @@ macro_rules! adc {
}
}

impl<PIN> embedded_hal_one::adc::nb::OneShot<pac::$adc_type, u16, PIN> for Adc<pac::$adc_type>
where
PIN: embedded_hal::adc::Channel<pac::$adc_type, ID=u8> + embedded_hal_one::adc::nb::Channel<pac::$adc_type, ID=u8>,
{
type Error = ();

fn read(&mut self, pin: &mut PIN) -> nb::Result<u16, Self::Error> {
self.read::<PIN>(pin)
}
}

unsafe impl PeriAddress for Adc<pac::$adc_type> {
#[inline(always)]
fn address(&self) -> u32 {
Expand Down
77 changes: 12 additions & 65 deletions src/spi/hal_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,25 @@ mod nb {
mod blocking {
use super::super::{Error, Instance, Spi, TransferModeBidi, TransferModeNormal};
use embedded_hal_one::spi::{
blocking::{Operation, Read, Transactional, Transfer, TransferInplace, Write, WriteIter},
blocking::{SpiBus, SpiBusFlush, SpiBusRead, SpiBusWrite},
nb::FullDuplex,
};

impl<SPI, PINS, TRANSFER_MODE, W: Copy + 'static> TransferInplace<W>
impl<SPI, PINS, TRANSFER_MODE, W: Copy + Default + 'static> SpiBus<W>
for Spi<SPI, PINS, TRANSFER_MODE>
where
Self: FullDuplex<W, Error = Error>,
Self: FullDuplex<W, Error = Error> + SpiBusWrite<W>,
SPI: Instance,
{
fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
for word in words.iter_mut() {
nb::block!(<Self as FullDuplex<W>>::write(self, *word))?;
*word = nb::block!(<Self as FullDuplex<W>>::read(self))?;
}

Ok(())
}
}

impl<SPI, PINS, TRANSFER_MODE, W: Copy + 'static> Transfer<W> for Spi<SPI, PINS, TRANSFER_MODE>
where
Self: FullDuplex<W, Error = Error>,
SPI: Instance,
{
fn transfer(&mut self, buff: &mut [W], data: &[W]) -> Result<(), Self::Error> {
assert_eq!(data.len(), buff.len());

Expand All @@ -114,71 +108,45 @@ mod blocking {
}
}

impl<SPI, PINS, W: Copy + 'static> Write<W> for Spi<SPI, PINS, TransferModeNormal>
impl<SPI, PINS, TRANSFER_MODE> SpiBusFlush for Spi<SPI, PINS, TRANSFER_MODE>
where
Self: FullDuplex<W, Error = Error>,
SPI: Instance,
{
fn write(&mut self, words: &[W]) -> Result<(), Self::Error> {
for word in words {
nb::block!(<Self as FullDuplex<W>>::write(self, *word))?;
nb::block!(<Self as FullDuplex<W>>::read(self))?;
}

fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}

impl<SPI, PINS, W: Copy + 'static> Write<W> for Spi<SPI, PINS, TransferModeBidi>
impl<SPI, PINS, W: Copy + 'static> SpiBusWrite<W> for Spi<SPI, PINS, TransferModeNormal>
where
Self: FullDuplex<W, Error = Error>,
SPI: Instance,
{
fn write(&mut self, words: &[W]) -> Result<(), Self::Error> {
for word in words {
nb::block!(<Self as FullDuplex<W>>::write(self, *word))?;
}

Ok(())
}
}

impl<SPI, PINS, W: Copy + 'static> WriteIter<W> for Spi<SPI, PINS, TransferModeNormal>
where
Self: FullDuplex<W, Error = Error>,
SPI: Instance,
{
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
where
WI: IntoIterator<Item = W>,
{
for word in words.into_iter() {
nb::block!(<Self as FullDuplex<W>>::write(self, word))?;
nb::block!(<Self as FullDuplex<W>>::read(self))?;
}

Ok(())
}
}

impl<SPI, PINS, W: Copy + 'static> WriteIter<W> for Spi<SPI, PINS, TransferModeBidi>
impl<SPI, PINS, W: Copy + 'static> SpiBusWrite<W> for Spi<SPI, PINS, TransferModeBidi>
where
Self: FullDuplex<W, Error = Error>,
SPI: Instance,
{
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
where
WI: IntoIterator<Item = W>,
{
for word in words.into_iter() {
nb::block!(<Self as FullDuplex<W>>::write(self, word))?;
fn write(&mut self, words: &[W]) -> Result<(), Self::Error> {
for word in words {
nb::block!(<Self as FullDuplex<W>>::write(self, *word))?;
}

Ok(())
}
}

impl<SPI, PINS, TRANSFER_MODE, W: Copy + Default + 'static> Read<W>
impl<SPI, PINS, TRANSFER_MODE, W: Copy + Default + 'static> SpiBusRead<W>
for Spi<SPI, PINS, TRANSFER_MODE>
where
Self: FullDuplex<W, Error = Error>,
Expand All @@ -193,25 +161,4 @@ mod blocking {
Ok(())
}
}

impl<SPI, PINS, TRANSFER_MODE, W: Copy + 'static> Transactional<W> for Spi<SPI, PINS, TRANSFER_MODE>
where
Self: Write<W, Error = Error>
+ Read<W, Error = Error>
+ TransferInplace<W, Error = Error>
+ Transfer<W, Error = Error>,
{
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Error> {
for op in operations {
match op {
Operation::Write(w) => self.write(w)?,
Operation::TransferInplace(t) => self.transfer_inplace(t)?,
Operation::Read(r) => self.read(r)?,
Operation::Transfer(w, r) => self.transfer(w, r)?,
}
}

Ok(())
}
}
}