Skip to content
Draft
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
4 changes: 2 additions & 2 deletions cyw43/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/embassy-rs/embassy"
documentation = "https://docs.embassy.dev/cyw43"

[features]
defmt = ["dep:defmt", "heapless/defmt-03", "embassy-time/defmt", "bt-hci?/defmt", "embedded-io-async?/defmt-03"]
defmt = ["dep:defmt", "heapless/defmt-03", "embassy-time/defmt", "bt-hci?/defmt", "embedded-io-async?/defmt"]
log = ["dep:log"]
bluetooth = ["dep:bt-hci", "dep:embedded-io-async"]

Expand All @@ -35,7 +35,7 @@ num_enum = { version = "0.5.7", default-features = false }
heapless = "0.8.0"

# Bluetooth deps
embedded-io-async = { version = "0.6.0", optional = true }
embedded-io-async = { version = "0.7.0", optional = true }
bt-hci = { version = "0.6.0", optional = true }

[package.metadata.embassy]
Expand Down
8 changes: 8 additions & 0 deletions cyw43/src/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,14 @@ impl From<FromHciBytesError> for Error {
}
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(self, f)
}
}

impl core::error::Error for Error {}

impl<'d> embedded_io_async::ErrorType for BtDriver<'d> {
type Error = Error;
}
Expand Down
4 changes: 2 additions & 2 deletions embassy-imxrt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ cfg-if = "1.0.0"
cortex-m-rt = ">=0.7.3,<0.8"
cortex-m = "0.7.6"
critical-section = "1.1"
embedded-io = { version = "0.6.1" }
embedded-io-async = { version = "0.6.1" }
embedded-io = { version = "0.7.1" }
embedded-io-async = { version = "0.7.0" }
fixed = "1.23.1"

rand-core-06 = { package = "rand_core", version = "0.6" }
Expand Down
4 changes: 2 additions & 2 deletions embassy-mspm0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["un
embedded-hal = { version = "1.0" }
embedded-hal-nb = { version = "1.0" }
embedded-hal-async = { version = "1.0" }
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
embedded-io = { version = "0.7.1" }
embedded-io-async = { version = "0.7.0" }

defmt = { version = "1.0.1", optional = true }
fixed = "1.29"
Expand Down
4 changes: 4 additions & 0 deletions embassy-mspm0/src/uart/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ impl embedded_io_async::Write for BufferedUart<'_> {
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.tx.write_inner(buf).await
}

async fn flush(&mut self) -> Result<(), Self::Error> {
self.tx.flush_inner().await
}
}

impl embedded_io_async::Write for BufferedUartTx<'_> {
Expand Down
2 changes: 1 addition & 1 deletion embassy-net-nrf91/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ embassy-futures = { version = "0.1.2", path = "../embassy-futures" }
embassy-net-driver-channel = { version = "0.3.2", path = "../embassy-net-driver-channel" }

heapless = "0.8"
embedded-io = "0.6.1"
embedded-io = { version = "0.7.1" }
at-commands = "0.5.4"

[package.metadata.embassy]
Expand Down
2 changes: 1 addition & 1 deletion embassy-net-ppp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ log = ["dep:log", "ppproto/log"]
defmt = { version = "1.0.1", optional = true }
log = { version = "0.4.14", optional = true }

embedded-io-async = { version = "0.6.1" }
embedded-io-async = { version = "0.7.0" }
embassy-net-driver-channel = { version = "0.3.2", path = "../embassy-net-driver-channel" }
embassy-futures = { version = "0.1.2", path = "../embassy-futures" }
ppproto = { version = "0.2.1"}
Expand Down
4 changes: 2 additions & 2 deletions embassy-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ smoltcp = { version = "0.12.0", default-features = false, features = [
embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" }
embassy-time = { version = "0.5.0", path = "../embassy-time" }
embassy-sync = { version = "0.7.2", path = "../embassy-sync" }
embedded-io-async = { version = "0.6.1" }
embedded-io-async = { version = "0.7.0" }

managed = { version = "0.8.0", default-features = false, features = [ "map" ] }
heapless = { version = "0.8", default-features = false }
embedded-nal-async = "0.8.0"
embedded-nal-async = "0.9.0"
document-features = "0.2.7"
16 changes: 16 additions & 0 deletions embassy-net/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,13 @@ impl<'d> TcpIo<'d> {
mod embedded_io_impls {
use super::*;

impl core::fmt::Display for ConnectError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("ConnectError")
}
}
impl core::error::Error for ConnectError {}

impl embedded_io_async::Error for ConnectError {
fn kind(&self) -> embedded_io_async::ErrorKind {
match self {
Expand All @@ -667,6 +674,15 @@ mod embedded_io_impls {
}
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::ConnectionReset => f.write_str("ConnectionReset"),
}
}
}
impl core::error::Error for Error {}

impl embedded_io_async::Error for Error {
fn kind(&self) -> embedded_io_async::ErrorKind {
match self {
Expand Down
4 changes: 2 additions & 2 deletions embassy-nrf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ embassy-futures = { version = "0.1.2", path = "../embassy-futures", optional = t
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
embedded-hal-async = { version = "1.0" }
embedded-io = { version = "0.6.0" }
embedded-io-async = { version = "0.6.1" }
embedded-io = { version = "0.7.1" }
embedded-io-async = { version = "0.7.0" }

rand-core-06 = { package = "rand_core", version = "0.6" }
rand-core-09 = { package = "rand_core", version = "0.9" }
Expand Down
7 changes: 7 additions & 0 deletions embassy-nrf/src/buffered_uarte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,13 @@ impl<'a> Drop for BufferedUarteRx<'a> {
}
}

impl core::fmt::Display for Error {
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {}
}
}
impl core::error::Error for Error {}

mod _embedded_io {
use super::*;

Expand Down
20 changes: 20 additions & 0 deletions embassy-nrf/src/uarte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,20 @@ mod eh02 {
}
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
Self::BufferTooLong => f.write_str("BufferTooLong"),
Self::BufferNotInRAM => f.write_str("BufferNotInRAM"),
Self::Framing => f.write_str("Framing"),
Self::Parity => f.write_str("Parity"),
Self::Overrun => f.write_str("Overrun"),
Self::Break => f.write_str("Break"),
}
}
}
impl core::error::Error for Error {}

mod _embedded_io {
use super::*;

Expand Down Expand Up @@ -1085,12 +1099,18 @@ mod _embedded_io {
self.write(buf).await?;
Ok(buf.len())
}
async fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}

impl<'d> embedded_io_async::Write for UarteTx<'d> {
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.write(buf).await?;
Ok(buf.len())
}
async fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
}
2 changes: 1 addition & 1 deletion embassy-nxp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ log = { version = "0.4.27", optional = true }
embassy-time = { version = "0.5.0", path = "../embassy-time", optional = true }
embassy-time-driver = { version = "0.2.1", path = "../embassy-time-driver", optional = true }
embassy-time-queue-utils = { version = "0.3.0", path = "../embassy-time-queue-utils", optional = true }
embedded-io = "0.6.1"
embedded-io = { version = "0.7.1" }
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
## Chip dependencies
nxp-pac = { version = "0.1.0", optional = true, git = "https://github.com/i509VCB/nxp-pac", rev = "b736e3038254d593024aaa1a5a7b1f95a5728538"}
Expand Down
9 changes: 9 additions & 0 deletions embassy-nxp/src/usart/lpc55.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ impl embedded_io::Error for Error {
}
}
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(self, f)
}
}

impl core::error::Error for Error {}

/// Word length.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DataBits {
Expand Down
4 changes: 2 additions & 2 deletions embassy-rp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ cortex-m-rt = ">=0.6.15,<0.8"
cortex-m = "0.7.6"
critical-section = "1.2.0"
chrono = { version = "0.4", default-features = false, optional = true }
embedded-io = { version = "0.6.1" }
embedded-io-async = { version = "0.6.1" }
embedded-io = { version = "0.7.1" }
embedded-io-async = { version = "0.7.0" }
embedded-storage = { version = "0.3" }
embedded-storage-async = { version = "0.4.1" }
fixed = "1.28.0"
Expand Down
4 changes: 4 additions & 0 deletions embassy-rp/src/pio_programs/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl<PIO: Instance, const SM: usize> Write for PioUartTx<'_, PIO, SM> {
}
Ok(buf.len())
}

async fn flush(&mut self) -> Result<(), Infallible> {
Ok(())
}
}

/// This struct represents a Uart Rx program loaded into pio instruction memory.
Expand Down
8 changes: 8 additions & 0 deletions embassy-rp/src/uart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ pub enum Error {
Framing,
}

impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(self, f)
}
}

impl core::error::Error for Error {}

/// Read To Break error
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand Down
6 changes: 3 additions & 3 deletions embassy-stm32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ vcell = "0.1.3"
nb = "1.0.0"
stm32-fmc = "0.3.0"
cfg-if = "1.0.0"
embedded-io = { version = "0.6.0" }
embedded-io-async = { version = "0.6.1" }
embedded-io = { version = "0.7.1" }
embedded-io-async = { version = "0.7.0" }
chrono = { version = "^0.4", default-features = false, optional = true }
bit_field = "0.10.2"
document-features = "0.2.7"
Expand Down Expand Up @@ -222,7 +222,7 @@ defmt = [
"embassy-sync/defmt",
"embassy-embedded-hal/defmt",
"embassy-hal-internal/defmt",
"embedded-io-async/defmt-03",
"embedded-io-async/defmt",
"embassy-usb-driver/defmt",
"embassy-net-driver/defmt",
"embassy-time?/defmt",
Expand Down
2 changes: 1 addition & 1 deletion embassy-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ futures-core = { version = "0.3.31", default-features = false }
critical-section = "1.1"
heapless = "0.8"
cfg-if = "1.0.0"
embedded-io-async = { version = "0.6.1" }
embedded-io-async = { version = "0.7.0" }

[dev-dependencies]
futures-executor = { version = "0.3.17", features = [ "thread-pool" ] }
Expand Down
1 change: 1 addition & 0 deletions embassy-usb-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ target = "thumbv7em-none-eabi"
features = ["defmt"]

[dependencies]
# TODO: remove before releasing embassy-usb-driver v0.3
embedded-io-async = "0.6.1"
defmt = { version = "1", optional = true }

Expand Down
1 change: 1 addition & 0 deletions embassy-usb-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ pub enum EndpointError {
Disabled,
}

// TODO: remove before releasing embassy-usb-driver v0.3
impl embedded_io_async::Error for EndpointError {
fn kind(&self) -> embedded_io_async::ErrorKind {
match self {
Expand Down
2 changes: 1 addition & 1 deletion embassy-usb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ embassy-net-driver-channel = { version = "0.3.2", path = "../embassy-net-driver-
defmt = { version = "1", optional = true }
log = { version = "0.4.14", optional = true }
heapless = "0.8"
embedded-io-async = "0.6.1"
embedded-io-async = { version = "0.7.0" }

# for HID
usbd-hid = { version = "0.8.1", optional = true }
Expand Down
52 changes: 46 additions & 6 deletions embassy-usb/src/class/cdc_acm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ const REQ_SET_LINE_CODING: u8 = 0x20;
const REQ_GET_LINE_CODING: u8 = 0x21;
const REQ_SET_CONTROL_LINE_STATE: u8 = 0x22;

/// CDC ACM error.
#[derive(Clone, Debug)]
pub enum CdcAcmError {
/// USB is not connected.
NotConnected,
}

impl core::fmt::Display for CdcAcmError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
Self::NotConnected => f.write_str("NotConnected"),
}
}
}

impl core::error::Error for CdcAcmError {}
impl embedded_io_async::Error for CdcAcmError {
fn kind(&self) -> embedded_io_async::ErrorKind {
match *self {
Self::NotConnected => embedded_io_async::ErrorKind::NotConnected,
}
}
}

/// Internal state for CDC-ACM
pub struct State<'a> {
control: MaybeUninit<Control<'a>>,
Expand Down Expand Up @@ -411,14 +435,21 @@ impl<'d, D: Driver<'d>> Sender<'d, D> {
}

impl<'d, D: Driver<'d>> embedded_io_async::ErrorType for Sender<'d, D> {
type Error = EndpointError;
type Error = CdcAcmError;
}

impl<'d, D: Driver<'d>> embedded_io_async::Write for Sender<'d, D> {
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
let len = core::cmp::min(buf.len(), self.max_packet_size() as usize);
self.write_packet(&buf[..len]).await?;
Ok(len)
match self.write_packet(&buf[..len]).await {
Ok(()) => Ok(len),
Err(EndpointError::BufferOverflow) => unreachable!(),
Err(EndpointError::Disabled) => Err(CdcAcmError::NotConnected),
}
}

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

Expand Down Expand Up @@ -529,7 +560,7 @@ impl<'d, D: Driver<'d>> BufferedReceiver<'d, D> {
}

impl<'d, D: Driver<'d>> embedded_io_async::ErrorType for BufferedReceiver<'d, D> {
type Error = EndpointError;
type Error = CdcAcmError;
}

impl<'d, D: Driver<'d>> embedded_io_async::Read for BufferedReceiver<'d, D> {
Expand All @@ -542,12 +573,21 @@ impl<'d, D: Driver<'d>> embedded_io_async::Read for BufferedReceiver<'d, D> {
// If the caller's buffer is large enough to contain an entire packet, read directly into
// that instead of buffering the packet internally.
if buf.len() > self.receiver.max_packet_size() as usize {
return self.receiver.read_packet(buf).await;
return match self.receiver.read_packet(buf).await {
Ok(n) => Ok(n),
Err(EndpointError::BufferOverflow) => unreachable!(),
Err(EndpointError::Disabled) => Err(CdcAcmError::NotConnected),
};
}

// Otherwise read a packet into the internal buffer, and return some of it to the caller
self.start = 0;
self.end = self.receiver.read_packet(&mut self.buffer).await?;
self.end = 0;
match self.receiver.read_packet(&mut self.buffer).await {
Ok(n) => self.end = n,
Err(EndpointError::BufferOverflow) => unreachable!(),
Err(EndpointError::Disabled) => return Err(CdcAcmError::NotConnected),
}
return Ok(self.read_from_buffer(buf));
}
}
Expand Down
Loading
Loading