Skip to content
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 @@ pub struct I2cBB<SCL, SDA, CLK>
where
SCL: OutputPin,
SDA: OutputPin + InputPin,
CLK: CountDown + Periodic,
CLK: DelayNs,
{
scl: SCL,
sda: SDA,
Expand All @@ -82,7 +81,7 @@ impl<SCL, SDA, CLK, E> I2cBB<SCL, SDA, CLK>
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 @@ -258,7 +257,7 @@ impl<SCL, SDA, CLK, E> Write for I2cBB<SCL, SDA, CLK>
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 @@ -281,7 +280,7 @@ impl<SCL, SDA, CLK, E> Read for I2cBB<SCL, SDA, CLK>
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 @@ -308,7 +307,7 @@ impl<SCL, SDA, CLK, E> WriteRead for I2cBB<SCL, SDA, CLK>
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 @@ pub struct Serial<TX, RX, Timer>
where
TX: OutputPin,
RX: InputPin,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
tx: TX,
rx: RX,
Expand All @@ -36,7 +37,7 @@ impl<TX, RX, Timer, E> Serial<TX, RX, Timer>
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 @@ -53,7 +54,7 @@ impl<TX, RX, Timer, E> serial::Write<u8> for Serial<TX, RX, Timer>
where
TX: OutputPin<Error = E>,
RX: InputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
type Error = crate::serial::Error<E>;

Expand Down Expand Up @@ -84,7 +85,7 @@ impl<TX, RX, Timer, E> serial::Read<u8> for Serial<TX, RX, Timer>
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};
use embedded_hal::timer::{CountDown, Periodic};
use nb::block;

/// Error type
#[derive(Debug)]
Expand Down Expand Up @@ -52,7 +51,7 @@ where
Miso: InputPin,
Mosi: OutputPin,
Sck: OutputPin,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
mode: Mode,
miso: Miso,
Expand All @@ -68,7 +67,7 @@ where
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 @@ -156,7 +155,7 @@ where
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 @@ where
}
}

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>
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>
for SPI<Miso, Mosi, Sck, Timer>
where
Miso: InputPin<Error = E>,
Mosi: OutputPin<Error = E>,
Sck: OutputPin<Error = E>,
Timer: CountDown + Periodic,
Timer: DelayNs,
{
}