Skip to content

Commit

Permalink
embedded-hal: 1.0.0-alpha.10 -> 1.0.0-alpha.11
Browse files Browse the repository at this point in the history
  • Loading branch information
newAM committed Jul 6, 2023
1 parent 6cb008a commit 2523d1a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 109 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.16.0] - 2023-06-05
### Changed
- Updated the alpha release of `embedded-hal` from `1.0.0-alpha.10` to `1.0.0-alpha.11`.

## [0.15.1] - 2023-05-13
### Fixed
- Changed the `Error` and `ErrorKind` types from private to public.
Expand Down Expand Up @@ -139,7 +143,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.1.0] - 2020-09-12
- Initial release

[Unreleased]: https://github.com/ftdi-rs/ftdi-embedded-hal/compare/v0.15.1...HEAD
[Unreleased]: https://github.com/ftdi-rs/ftdi-embedded-hal/compare/v0.16.0...HEAD
[0.16.0]: https://github.com/ftdi-rs/ftdi-embedded-hal/compare/v0.15.1...v0.16.0
[0.15.1]: https://github.com/ftdi-rs/ftdi-embedded-hal/compare/v0.15.0...v0.15.1
[0.15.0]: https://github.com/ftdi-rs/ftdi-embedded-hal/compare/v0.14.0...v0.15.0
[0.14.0]: https://github.com/ftdi-rs/ftdi-embedded-hal/compare/v0.13.0...v0.14.0
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ftdi-embedded-hal"
version = "0.15.1"
version = "0.16.0"
authors = ["Alex Martens <[email protected]>"]
description = "embedded-hal implementation for FTDI USB devices."
keywords = ["ftdi", "usb", "io", "hal"]
Expand All @@ -17,8 +17,8 @@ default = []

[dependencies]
eh0 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
eh1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
ehnb1 = { package = "embedded-hal-nb", version = "=1.0.0-alpha.2" }
eh1 = { package = "embedded-hal", version = "=1.0.0-alpha.11" }
ehnb1 = { package = "embedded-hal-nb", version = "=1.0.0-alpha.3" }
ftdi = { version = "0.1.3", optional = true }
ftdi-mpsse = "0.1"
libftd2xx = { version = "0.32", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ FTDI device into the [embedded-hal] traits.

```toml
[dependencies.ftdi-embedded-hal]
version = "0.15.1"
version = "0.16.0"
features = ["libftd2xx", "libftd2xx-static"]
```

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//!
//! ```toml
//! [dependencies.ftdi-embedded-hal]
//! version = "0.15.1"
//! version = "0.16.0"
//! features = ["libftd2xx", "libftd2xx-static"]
//! ```
//!
Expand Down
125 changes: 22 additions & 103 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,61 +223,40 @@ where
type Error = Error<E>;
}

impl<Device, E> eh1::spi::SpiBusFlush for Spi<Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}

impl<Device, E> eh1::spi::SpiBusWrite<u8> for Spi<Device>
impl<Device, E> eh1::spi::SpiBus<u8> for Spi<Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn write(&mut self, words: &[u8]) -> Result<(), Error<E>> {
fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> {
let data_out: Vec<u8> = vec![0; words.len()];
let cmd: MpsseCmdBuilder = MpsseCmdBuilder::new()
.clock_data_out(self.pol.clk_out, words)
.clock_data(self.pol.clk, &data_out)
.send_immediate();

let mut lock = self.mtx.lock().expect("Failed to aquire FTDI mutex");
lock.ft.send(cmd.as_slice())?;
lock.ft.recv(words)?;

Ok(())
}
}

impl<Device, E> eh1::spi::SpiBusRead<u8> for Spi<Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> {
let data_out: Vec<u8> = vec![0; words.len()];
fn write(&mut self, words: &[u8]) -> Result<(), Error<E>> {
let cmd: MpsseCmdBuilder = MpsseCmdBuilder::new()
.clock_data(self.pol.clk, &data_out)
.clock_data_out(self.pol.clk_out, words)
.send_immediate();

let mut lock = self.mtx.lock().expect("Failed to aquire FTDI mutex");
lock.ft.send(cmd.as_slice())?;
lock.ft.recv(words)?;

Ok(())
}
}

impl<Device, E> eh1::spi::SpiBus<u8> for Spi<Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}

fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Error<E>> {
let cmd: MpsseCmdBuilder = MpsseCmdBuilder::new()
.clock_data(self.pol.clk, words)
Expand Down Expand Up @@ -350,18 +329,7 @@ where
type Error = Error<E>;
}

impl<'a, Device, E> eh1::spi::SpiBusFlush for SpiDeviceBus<'a, Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}

impl<'a, Device, E> eh1::spi::SpiBusRead<u8> for SpiDeviceBus<'a, Device>
impl<'a, Device, E> eh1::spi::SpiBus<u8> for SpiDeviceBus<'a, Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Expand All @@ -377,14 +345,7 @@ where
)?;
Ok(())
}
}

impl<'a, Device, E> eh1::spi::SpiBusWrite<u8> for SpiDeviceBus<'a, Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
self.lock.ft.send(
MpsseCmdBuilder::new()
Expand All @@ -394,14 +355,11 @@ where
)?;
Ok(())
}
}

impl<'a, Device, E> eh1::spi::SpiBus<u8> for SpiDeviceBus<'a, Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}

fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> {
self.lock.ft.xfer(
MpsseCmdBuilder::new()
Expand Down Expand Up @@ -519,48 +477,6 @@ where
type Error = Error<E>;
}

impl<'a, Device, E> eh1::spi::SpiDeviceRead for &'a SpiDevice<Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn read_transaction(&mut self, operations: &mut [&mut [u8]]) -> Result<(), Self::Error> {
// lock the bus
let lock: MutexGuard<FtInner<Device>> =
self.mtx.lock().expect("Failed to aquire FTDI mutex");
let mut bus: SpiDeviceBus<'a, Device> = SpiDeviceBus {
lock,
pol: self.pol,
};
for op in operations {
eh1::spi::SpiBusRead::read(&mut bus, op)?;
}
Ok(())
}
}

impl<'a, Device, E> eh1::spi::SpiDeviceWrite for &'a SpiDevice<Device>
where
Device: MpsseCmdExecutor<Error = E>,
E: std::error::Error,
Error<E>: From<E>,
{
fn write_transaction(&mut self, operations: &[&[u8]]) -> Result<(), Self::Error> {
// lock the bus
let lock: MutexGuard<FtInner<Device>> =
self.mtx.lock().expect("Failed to aquire FTDI mutex");
let mut bus: SpiDeviceBus<'a, Device> = SpiDeviceBus {
lock,
pol: self.pol,
};
for op in operations {
eh1::spi::SpiBusWrite::write(&mut bus, op)?;
}
Ok(())
}
}

impl<'a, Device, E> eh1::spi::SpiDevice for &'a SpiDevice<Device>
where
Device: MpsseCmdExecutor<Error = E>,
Expand Down Expand Up @@ -593,23 +509,26 @@ where
for op in operations {
match op {
eh1::spi::Operation::Read(buffer) => {
eh1::spi::SpiBusRead::read(&mut bus, buffer)?;
eh1::spi::SpiBus::read(&mut bus, buffer)?;
}
eh1::spi::Operation::Write(buffer) => {
eh1::spi::SpiBusWrite::write(&mut bus, buffer)?;
eh1::spi::SpiBus::write(&mut bus, buffer)?;
}
eh1::spi::Operation::Transfer(read, write) => {
eh1::spi::SpiBus::transfer(&mut bus, read, write)?;
}
eh1::spi::Operation::TransferInPlace(buffer) => {
eh1::spi::SpiBus::transfer_in_place(&mut bus, buffer)?;
}
eh1::spi::Operation::DelayUs(micros) => {
std::thread::sleep(std::time::Duration::from_micros((*micros).into()));
}
}
}

// flush the bus
{
use eh1::spi::SpiBusFlush;
use eh1::spi::SpiBus;
bus.flush()?;
}

Expand Down

0 comments on commit 2523d1a

Please sign in to comment.