Skip to content

Commit 1dd5ccc

Browse files
committed
Split nb and can traits to separate crates.
1 parent 1f87498 commit 1dd5ccc

File tree

25 files changed

+965
-861
lines changed

25 files changed

+965
-861
lines changed

Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,3 @@ name = "embedded-hal"
1414
readme = "README.md"
1515
repository = "https://github.com/rust-embedded/embedded-hal"
1616
version = "1.0.0-alpha.8"
17-
18-
[dependencies]
19-
nb = "1"
20-
21-
[dev-dependencies.stm32f1]
22-
version = "0.14"
23-
features = ["stm32f103", "rt"]

embedded-can/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "embedded-can"
3+
version = "0.4.0"
4+
edition = "2018"
5+
6+
description = "HAL traits for Controller Area Netowrk (CAN) devices."
7+
categories = ["embedded", "hardware-support", "no-std"]
8+
documentation = "https://docs.rs/embedded-hal-can"
9+
keywords = ["hal", "IO"]
10+
license = "MIT OR Apache-2.0"
11+
readme = "README.md"
12+
repository = "https://github.com/rust-embedded/embedded-hal"
13+
14+
[dependencies]
15+
embedded-hal = { version = "=1.0.0-alpha.8", path = ".." }
16+
nb = "1"

embedded-can/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[![crates.io](https://img.shields.io/crates/d/embedded-hal-nb.svg)](https://crates.io/crates/embedded-hal-nb)
2+
[![crates.io](https://img.shields.io/crates/v/embedded-hal-nb.svg)](https://crates.io/crates/embedded-hal-nb)
3+
[![Documentation](https://docs.rs/embedded-hal-nb/badge.svg)](https://docs.rs/embedded-hal-nb)
4+
![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.54+-blue.svg)
5+
6+
# `embedded-hal-nb`
7+
8+
A non-blocking Hardware Abstraction Layer (HAL) for embedded systems, using the `nb` crate.
9+
10+
This crate contains versions of some [`embedded-hal`] traits using `nb`, and shares its scope and [design goals].
11+
12+
This project is developed and maintained by the [HAL team][team].
13+
14+
## [API reference]
15+
16+
[API reference]: https://docs.rs/embedded-hal-nb
17+
18+
## Minimum Supported Rust Version (MSRV)
19+
20+
This crate is guaranteed to compile on stable Rust 1.54 and up. It *might*
21+
compile with older versions but that may change in any new patch release.
22+
23+
See [here](docs/msrv.md) for details on how the MSRV may be upgraded.
24+
25+
## License
26+
27+
Licensed under either of
28+
29+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
30+
http://www.apache.org/licenses/LICENSE-2.0)
31+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
32+
33+
at your option.
34+
35+
### Contribution
36+
37+
Unless you explicitly state otherwise, any contribution intentionally submitted
38+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
39+
dual licensed as above, without any additional terms or conditions.
40+
41+
## Code of Conduct
42+
43+
Contribution to this crate is organized under the terms of the [Rust Code of
44+
Conduct][CoC], the maintainer of this crate, the [HAL team][team], promises
45+
to intervene to uphold that code of conduct.
46+
47+
[CoC]: ../CODE_OF_CONDUCT.md
48+
[team]: https://github.com/rust-embedded/wg#the-hal-team
49+
[`embedded-hal`]: https://crates.io/crates/embedded-hal
50+
[design goals]: https://docs.rs/embedded-hal/latest/embedded_hal/#design-goals

src/can/blocking.rs renamed to embedded-can/src/blocking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/// A blocking CAN interface that is able to transmit and receive frames.
44
pub trait Can {
55
/// Associated frame type.
6-
type Frame: crate::can::Frame;
6+
type Frame: crate::Frame;
77

88
/// Associated error type.
9-
type Error: crate::can::Error;
9+
type Error: crate::Error;
1010

1111
/// Puts a frame in the transmit buffer. Blocks until space is available in
1212
/// the transmit buffer.
File renamed without changes.

src/can/mod.rs renamed to embedded-can/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
//! Controller Area Network
1+
//! Controller Area Network (CAN) traits
2+
3+
#![warn(missing_docs)]
4+
#![no_std]
25

36
pub mod blocking;
47
pub mod nb;

src/can/nb.rs renamed to embedded-can/src/nb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/// A CAN interface that is able to transmit and receive frames.
44
pub trait Can {
55
/// Associated frame type.
6-
type Frame: crate::can::Frame;
6+
type Frame: crate::Frame;
77

88
/// Associated error type.
9-
type Error: crate::can::Error;
9+
type Error: crate::Error;
1010

1111
/// Puts a frame in the transmit buffer to be sent on the bus.
1212
///

embedded-hal-async/src/i2c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! `SevenBitAddress` has been set as default mode and thus can be omitted if desired.
1818
1919
use core::future::Future;
20-
pub use embedded_hal::i2c::blocking::Operation;
20+
pub use embedded_hal::i2c::Operation;
2121
pub use embedded_hal::i2c::{
2222
AddressMode, Error, ErrorKind, ErrorType, NoAcknowledgeSource, SevenBitAddress, TenBitAddress,
2323
};

embedded-hal-async/src/spi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
33
use core::{fmt::Debug, future::Future};
44

5+
use embedded_hal::digital::OutputPin;
6+
use embedded_hal::spi as blocking;
57
pub use embedded_hal::spi::{
68
Error, ErrorKind, ErrorType, Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3,
79
};
8-
use embedded_hal::{digital::blocking::OutputPin, spi::blocking};
910

1011
type ReadFuture<'a, T, Word>
1112
where

embedded-hal-bus/src/spi.rs

Lines changed: 60 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,78 @@
11
//! SPI bus sharing mechanisms.
22
3-
/// SPI bus sharing with blocking traits
4-
pub mod blocking {
5-
use core::fmt::Debug;
6-
use embedded_hal::{
7-
digital::blocking::OutputPin,
8-
spi::{
9-
blocking::{SpiBusFlush, SpiDevice},
10-
Error, ErrorKind, ErrorType,
11-
},
12-
};
3+
use core::fmt::Debug;
4+
use embedded_hal::digital::OutputPin;
5+
use embedded_hal::spi::{Error, ErrorKind, ErrorType, SpiBusFlush, SpiDevice};
136

14-
/// Error type for [`ExclusiveDevice`] operations.
15-
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
16-
pub enum ExclusiveDeviceError<BUS, CS> {
17-
/// An inner SPI bus operation failed
18-
Spi(BUS),
19-
/// Asserting or deasserting CS failed
20-
Cs(CS),
21-
}
7+
/// Error type for [`ExclusiveDevice`] operations.
8+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
9+
pub enum ExclusiveDeviceError<BUS, CS> {
10+
/// An inner SPI bus operation failed
11+
Spi(BUS),
12+
/// Asserting or deasserting CS failed
13+
Cs(CS),
14+
}
2215

23-
impl<BUS, CS> Error for ExclusiveDeviceError<BUS, CS>
24-
where
25-
BUS: Error + Debug,
26-
CS: Debug,
27-
{
28-
fn kind(&self) -> ErrorKind {
29-
match self {
30-
Self::Spi(e) => e.kind(),
31-
Self::Cs(_) => ErrorKind::ChipSelectFault,
32-
}
16+
impl<BUS, CS> Error for ExclusiveDeviceError<BUS, CS>
17+
where
18+
BUS: Error + Debug,
19+
CS: Debug,
20+
{
21+
fn kind(&self) -> ErrorKind {
22+
match self {
23+
Self::Spi(e) => e.kind(),
24+
Self::Cs(_) => ErrorKind::ChipSelectFault,
3325
}
3426
}
27+
}
3528

36-
/// [`SpiDevice`] implementation with exclusive access to the bus (not shared).
37-
///
38-
/// This is the most straightforward way of obtaining an [`SpiDevice`] from an [`SpiBus`],
39-
/// ideal for when no sharing is required (only one SPI device is present on the bus).
40-
pub struct ExclusiveDevice<BUS, CS> {
41-
bus: BUS,
42-
cs: CS,
43-
}
29+
/// [`SpiDevice`] implementation with exclusive access to the bus (not shared).
30+
///
31+
/// This is the most straightforward way of obtaining an [`SpiDevice`] from an [`SpiBus`],
32+
/// ideal for when no sharing is required (only one SPI device is present on the bus).
33+
pub struct ExclusiveDevice<BUS, CS> {
34+
bus: BUS,
35+
cs: CS,
36+
}
4437

45-
impl<BUS, CS> ExclusiveDevice<BUS, CS> {
46-
/// Create a new ExclusiveDevice
47-
pub fn new(bus: BUS, cs: CS) -> Self {
48-
Self { bus, cs }
49-
}
38+
impl<BUS, CS> ExclusiveDevice<BUS, CS> {
39+
/// Create a new ExclusiveDevice
40+
pub fn new(bus: BUS, cs: CS) -> Self {
41+
Self { bus, cs }
5042
}
43+
}
5144

52-
impl<BUS, CS> ErrorType for ExclusiveDevice<BUS, CS>
53-
where
54-
BUS: ErrorType,
55-
CS: OutputPin,
56-
{
57-
type Error = ExclusiveDeviceError<BUS::Error, CS::Error>;
58-
}
45+
impl<BUS, CS> ErrorType for ExclusiveDevice<BUS, CS>
46+
where
47+
BUS: ErrorType,
48+
CS: OutputPin,
49+
{
50+
type Error = ExclusiveDeviceError<BUS::Error, CS::Error>;
51+
}
5952

60-
impl<BUS, CS> SpiDevice for ExclusiveDevice<BUS, CS>
61-
where
62-
BUS: SpiBusFlush,
63-
CS: OutputPin,
64-
{
65-
type Bus = BUS;
53+
impl<BUS, CS> SpiDevice for ExclusiveDevice<BUS, CS>
54+
where
55+
BUS: SpiBusFlush,
56+
CS: OutputPin,
57+
{
58+
type Bus = BUS;
6659

67-
fn transaction<R>(
68-
&mut self,
69-
f: impl FnOnce(&mut Self::Bus) -> Result<R, <Self::Bus as ErrorType>::Error>,
70-
) -> Result<R, Self::Error> {
71-
self.cs.set_low().map_err(ExclusiveDeviceError::Cs)?;
60+
fn transaction<R>(
61+
&mut self,
62+
f: impl FnOnce(&mut Self::Bus) -> Result<R, <Self::Bus as ErrorType>::Error>,
63+
) -> Result<R, Self::Error> {
64+
self.cs.set_low().map_err(ExclusiveDeviceError::Cs)?;
7265

73-
let f_res = f(&mut self.bus);
66+
let f_res = f(&mut self.bus);
7467

75-
// On failure, it's important to still flush and deassert CS.
76-
let flush_res = self.bus.flush();
77-
let cs_res = self.cs.set_high();
68+
// On failure, it's important to still flush and deassert CS.
69+
let flush_res = self.bus.flush();
70+
let cs_res = self.cs.set_high();
7871

79-
let f_res = f_res.map_err(ExclusiveDeviceError::Spi)?;
80-
flush_res.map_err(ExclusiveDeviceError::Spi)?;
81-
cs_res.map_err(ExclusiveDeviceError::Cs)?;
72+
let f_res = f_res.map_err(ExclusiveDeviceError::Spi)?;
73+
flush_res.map_err(ExclusiveDeviceError::Spi)?;
74+
cs_res.map_err(ExclusiveDeviceError::Cs)?;
8275

83-
Ok(f_res)
84-
}
76+
Ok(f_res)
8577
}
8678
}

embedded-hal-nb/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "embedded-hal-nb"
3+
version = "1.0.0-alpha.1"
4+
edition = "2018"
5+
6+
categories = ["embedded", "hardware-support", "no-std"]
7+
description = "Non-blocking Hardware Abstraction Layer (HAL) for embedded systems using the `nb` crate."
8+
documentation = "https://docs.rs/embedded-hal-nb"
9+
keywords = ["hal", "IO"]
10+
license = "MIT OR Apache-2.0"
11+
readme = "README.md"
12+
repository = "https://github.com/rust-embedded/embedded-hal"
13+
14+
[dependencies]
15+
embedded-hal = { version = "=1.0.0-alpha.8", path = ".." }
16+
nb = "1"
17+
18+
[dev-dependencies.stm32f1]
19+
version = "0.14"
20+
features = ["stm32f103", "rt"]

embedded-hal-nb/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[![crates.io](https://img.shields.io/crates/d/embedded-hal-nb.svg)](https://crates.io/crates/embedded-hal-nb)
2+
[![crates.io](https://img.shields.io/crates/v/embedded-hal-nb.svg)](https://crates.io/crates/embedded-hal-nb)
3+
[![Documentation](https://docs.rs/embedded-hal-nb/badge.svg)](https://docs.rs/embedded-hal-nb)
4+
![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.54+-blue.svg)
5+
6+
# `embedded-hal-nb`
7+
8+
A non-blocking Hardware Abstraction Layer (HAL) for embedded systems, using the `nb` crate.
9+
10+
This crate contains versions of some [`embedded-hal`] traits using `nb`, and shares its scope and [design goals].
11+
12+
This project is developed and maintained by the [HAL team][team].
13+
14+
## [API reference]
15+
16+
[API reference]: https://docs.rs/embedded-hal-nb
17+
18+
## Minimum Supported Rust Version (MSRV)
19+
20+
This crate is guaranteed to compile on stable Rust 1.54 and up. It *might*
21+
compile with older versions but that may change in any new patch release.
22+
23+
See [here](docs/msrv.md) for details on how the MSRV may be upgraded.
24+
25+
## License
26+
27+
Licensed under either of
28+
29+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
30+
http://www.apache.org/licenses/LICENSE-2.0)
31+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
32+
33+
at your option.
34+
35+
### Contribution
36+
37+
Unless you explicitly state otherwise, any contribution intentionally submitted
38+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
39+
dual licensed as above, without any additional terms or conditions.
40+
41+
## Code of Conduct
42+
43+
Contribution to this crate is organized under the terms of the [Rust Code of
44+
Conduct][CoC], the maintainer of this crate, the [HAL team][team], promises
45+
to intervene to uphold that code of conduct.
46+
47+
[CoC]: ../CODE_OF_CONDUCT.md
48+
[team]: https://github.com/rust-embedded/wg#the-hal-team
49+
[`embedded-hal`]: https://crates.io/crates/embedded-hal
50+
[design goals]: https://docs.rs/embedded-hal/latest/embedded_hal/#design-goals

0 commit comments

Comments
 (0)