Skip to content
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

WIP e-h 1.0 and edition 2021 #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
File renamed without changes.
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ readme = "README.md"
keywords = ["no_std", "embedded", "bitbang", "embedded-hal", "hal"]
categories = ["embedded", "no-std"]

[dependencies]
nb = "1"
[dependencies.embedded-hal-nb]
version = "1"

[dependencies.embedded-hal]
version = "0.2.7"
features = ["unproven"]
version = "1"

[dev-dependencies.stm32f1xx-hal]
version = "0.9"
version = "0.10.0"
features = ["stm32f103", "rt", "medium"]

[dev-dependencies]
cortex-m = "0.7"
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
eeprom24x = "0.5.0"
lm75 = "0.2"
eeprom24x = "0.7.1"
lm75 = "1"
4 changes: 2 additions & 2 deletions examples/i2c-eeprom24x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ fn main() -> ! {
for addr in addrs.iter() {
eeprom.write_byte(*addr, byte).unwrap();
// need to wait before next write
block!(delay.wait()).ok();
block!(delay.try_wait()).ok();
}

loop {
for addr in addrs.iter() {
let _ = eeprom.read_byte(*addr).unwrap();
block!(delay.wait()).ok();
block!(delay.try_wait()).ok();
}
}
}
2 changes: 1 addition & 1 deletion examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() -> ! {

loop {
for byte in b"Hello, World!\r\n" {
block!(serial.write(*byte)).unwrap();
block!(serial.try_write(*byte)).unwrap();
}

delay.delay_ms(1000u16);
Expand Down
17 changes: 8 additions & 9 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
```
*/

use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
use embedded_hal::digital::v2::{InputPin, OutputPin};
use embedded_hal::timer::{CountDown, Periodic};
use nb::block;
use embedded_hal::delay::DelayNs;
use embedded_hal::digital::{InputPin, OutputPin};
use embedded_hal_nb::nb::block;

/// I2C error
#[derive(Debug, Eq, PartialEq)]
Expand All @@ -71,7 +70,7 @@
where
SCL: OutputPin,
SDA: OutputPin + InputPin,
CLK: CountDown + Periodic,
CLK: DelayNs,
{
scl: SCL,
sda: SDA,
Expand All @@ -82,7 +81,7 @@
where
SCL: OutputPin<Error = E>,
SDA: OutputPin<Error = E> + InputPin<Error = E>,
CLK: CountDown + Periodic,
CLK: DelayNs,
{
/// Create instance
pub fn new(scl: SCL, sda: SDA, clk: CLK) -> Self {
Expand Down Expand Up @@ -254,11 +253,11 @@
}
}

impl<SCL, SDA, CLK, E> Write for I2cBB<SCL, SDA, CLK>

Check failure on line 256 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / docs

cannot find trait `Write` in this scope

Check failure on line 256 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / build

cannot find trait `Write` in this scope

Check failure on line 256 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / examples

cannot find trait `Write` in this scope

Check failure on line 256 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / doctest

cannot find trait `Write` in this scope
where
SCL: OutputPin<Error = E>,
SDA: OutputPin<Error = E> + InputPin<Error = E>,
CLK: CountDown + Periodic,
CLK: DelayNs,
{
type Error = crate::i2c::Error<E>;

Expand All @@ -277,11 +276,11 @@
}
}

impl<SCL, SDA, CLK, E> Read for I2cBB<SCL, SDA, CLK>

Check failure on line 279 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / docs

cannot find trait `Read` in this scope

Check failure on line 279 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / build

cannot find trait `Read` in this scope

Check failure on line 279 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / examples

cannot find trait `Read` in this scope

Check failure on line 279 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / doctest

cannot find trait `Read` in this scope
where
SCL: OutputPin<Error = E>,
SDA: OutputPin<Error = E> + InputPin<Error = E>,
CLK: CountDown + Periodic,
CLK: DelayNs,
{
type Error = crate::i2c::Error<E>;

Expand All @@ -304,11 +303,11 @@
}
}

impl<SCL, SDA, CLK, E> WriteRead for I2cBB<SCL, SDA, CLK>

Check failure on line 306 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / docs

cannot find trait `WriteRead` in this scope

Check failure on line 306 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / build

cannot find trait `WriteRead` in this scope

Check failure on line 306 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / examples

cannot find trait `WriteRead` in this scope

Check failure on line 306 in src/i2c.rs

View workflow job for this annotation

GitHub Actions / doctest

cannot find trait `WriteRead` in this scope
where
SCL: OutputPin<Error = E>,
SDA: OutputPin<Error = E> + InputPin<Error = E>,
CLK: CountDown + Periodic,
CLK: DelayNs,
{
type Error = crate::i2c::Error<E>;

Expand Down
17 changes: 9 additions & 8 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
//! The timer must be configured to twice the desired communication frequency.
//!

use embedded_hal::digital::v2::{InputPin, OutputPin};
use embedded_hal::serial;
use embedded_hal::timer::{CountDown, Periodic};
use nb::block;
use embedded_hal::{
delay::DelayNs,
digital::{InputPin, OutputPin},
};
use embedded_hal_nb::nb::block;

/// Serial communication error type
#[derive(Debug)]
Expand All @@ -25,7 +26,7 @@
where
TX: OutputPin,
RX: InputPin,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
tx: TX,
rx: RX,
Expand All @@ -36,7 +37,7 @@
where
TX: OutputPin<Error = E>,
RX: InputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
/// Create instance
pub fn new(tx: TX, rx: RX, timer: Timer) -> Self {
Expand All @@ -49,15 +50,15 @@
}
}

impl<TX, RX, Timer, E> serial::Write<u8> for Serial<TX, RX, Timer>

Check failure on line 53 in src/serial.rs

View workflow job for this annotation

GitHub Actions / docs

failed to resolve: use of undeclared crate or module `serial`

Check failure on line 53 in src/serial.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: use of undeclared crate or module `serial`

Check failure on line 53 in src/serial.rs

View workflow job for this annotation

GitHub Actions / examples

failed to resolve: use of undeclared crate or module `serial`

Check failure on line 53 in src/serial.rs

View workflow job for this annotation

GitHub Actions / doctest

failed to resolve: use of undeclared crate or module `serial`
where
TX: OutputPin<Error = E>,
RX: InputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
type Error = crate::serial::Error<E>;

fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> {

Check failure on line 61 in src/serial.rs

View workflow job for this annotation

GitHub Actions / docs

failed to resolve: use of undeclared crate or module `nb`

Check failure on line 61 in src/serial.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: use of undeclared crate or module `nb`

Check failure on line 61 in src/serial.rs

View workflow job for this annotation

GitHub Actions / examples

failed to resolve: use of undeclared crate or module `nb`

Check failure on line 61 in src/serial.rs

View workflow job for this annotation

GitHub Actions / doctest

failed to resolve: use of undeclared crate or module `nb`
let mut data_out = byte;
self.tx.set_low().map_err(Error::Bus)?; // start bit
self.wait_for_timer();
Expand All @@ -75,7 +76,7 @@
Ok(())
}

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

Check failure on line 79 in src/serial.rs

View workflow job for this annotation

GitHub Actions / docs

failed to resolve: use of undeclared crate or module `nb`

Check failure on line 79 in src/serial.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: use of undeclared crate or module `nb`

Check failure on line 79 in src/serial.rs

View workflow job for this annotation

GitHub Actions / examples

failed to resolve: use of undeclared crate or module `nb`

Check failure on line 79 in src/serial.rs

View workflow job for this annotation

GitHub Actions / doctest

failed to resolve: use of undeclared crate or module `nb`
Ok(())
}
}
Expand All @@ -84,7 +85,7 @@
where
TX: OutputPin<Error = E>,
RX: InputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
type Error = crate::serial::Error<E>;

Expand Down
19 changes: 9 additions & 10 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
//! MSB-first and LSB-first bit orders are supported.
//!

use embedded_hal::delay::DelayNs;
pub use embedded_hal::spi::{MODE_0, MODE_1, MODE_2, MODE_3};

use embedded_hal::digital::v2::{InputPin, OutputPin};
use embedded_hal::digital::{InputPin, OutputPin};
use embedded_hal::spi::{FullDuplex, Mode, Polarity};

Check failure on line 20 in src/spi.rs

View workflow job for this annotation

GitHub Actions / docs

unresolved import `embedded_hal::spi::FullDuplex`

Check failure on line 20 in src/spi.rs

View workflow job for this annotation

GitHub Actions / build

unresolved import `embedded_hal::spi::FullDuplex`

Check failure on line 20 in src/spi.rs

View workflow job for this annotation

GitHub Actions / examples

unresolved import `embedded_hal::spi::FullDuplex`

Check failure on line 20 in src/spi.rs

View workflow job for this annotation

GitHub Actions / doctest

unresolved import `embedded_hal::spi::FullDuplex`
use embedded_hal::timer::{CountDown, Periodic};
use nb::block;

/// Error type
#[derive(Debug)]
Expand Down Expand Up @@ -52,7 +51,7 @@
Miso: InputPin,
Mosi: OutputPin,
Sck: OutputPin,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
mode: Mode,
miso: Miso,
Expand All @@ -68,7 +67,7 @@
Miso: InputPin<Error = E>,
Mosi: OutputPin<Error = E>,
Sck: OutputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
/// Create instance
pub fn new(mode: Mode, miso: Miso, mosi: Mosi, sck: Sck, timer: Timer) -> Self {
Expand Down Expand Up @@ -147,7 +146,7 @@

#[inline]
fn wait_for_timer(&mut self) {
block!(self.timer.wait()).ok();

Check failure on line 149 in src/spi.rs

View workflow job for this annotation

GitHub Actions / docs

cannot find macro `block` in this scope

Check failure on line 149 in src/spi.rs

View workflow job for this annotation

GitHub Actions / build

cannot find macro `block` in this scope

Check failure on line 149 in src/spi.rs

View workflow job for this annotation

GitHub Actions / examples

cannot find macro `block` in this scope

Check failure on line 149 in src/spi.rs

View workflow job for this annotation

GitHub Actions / doctest

cannot find macro `block` in this scope
}
}

Expand All @@ -156,7 +155,7 @@
Miso: InputPin<Error = E>,
Mosi: OutputPin<Error = E>,
Sck: OutputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
type Error = crate::spi::Error<E>;

Expand Down Expand Up @@ -217,22 +216,22 @@
}
}

impl<Miso, Mosi, Sck, Timer, E> embedded_hal::blocking::spi::transfer::Default<u8>
impl<Miso, Mosi, Sck, Timer, E> embedded_hal::spi::transfer::Default<u8>

Check failure on line 219 in src/spi.rs

View workflow job for this annotation

GitHub Actions / docs

failed to resolve: could not find `transfer` in `spi`

Check failure on line 219 in src/spi.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: could not find `transfer` in `spi`

Check failure on line 219 in src/spi.rs

View workflow job for this annotation

GitHub Actions / examples

failed to resolve: could not find `transfer` in `spi`

Check failure on line 219 in src/spi.rs

View workflow job for this annotation

GitHub Actions / doctest

failed to resolve: could not find `transfer` in `spi`
for SPI<Miso, Mosi, Sck, Timer>
where
Miso: InputPin<Error = E>,
Mosi: OutputPin<Error = E>,
Sck: OutputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
}

impl<Miso, Mosi, Sck, Timer, E> embedded_hal::blocking::spi::write::Default<u8>
impl<Miso, Mosi, Sck, Timer, E> embedded_hal::spi::write::Default<u8>

Check failure on line 229 in src/spi.rs

View workflow job for this annotation

GitHub Actions / docs

failed to resolve: could not find `write` in `spi`

Check failure on line 229 in src/spi.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: could not find `write` in `spi`

Check failure on line 229 in src/spi.rs

View workflow job for this annotation

GitHub Actions / examples

failed to resolve: could not find `write` in `spi`

Check failure on line 229 in src/spi.rs

View workflow job for this annotation

GitHub Actions / doctest

failed to resolve: could not find `write` in `spi`
for SPI<Miso, Mosi, Sck, Timer>
where
Miso: InputPin<Error = E>,
Mosi: OutputPin<Error = E>,
Sck: OutputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
}
Loading