Skip to content

Commit 41a61cb

Browse files
committed
e-h-async: document fixes and inline hints.
Signed-off-by: Zhouqi Jiang <[email protected]>
1 parent a0e1f49 commit 41a61cb

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

embedded-hal-async/src/delay.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Delays
1+
//! Delays.
22
3-
/// Microsecond delay
3+
/// Microsecond delay.
44
pub trait DelayUs {
55
/// Pauses execution for at minimum `us` microseconds. Pause can be longer
66
/// if the implementation requires it due to precision/timing issues.
@@ -15,10 +15,12 @@ impl<T> DelayUs for &mut T
1515
where
1616
T: DelayUs + ?Sized,
1717
{
18+
#[inline]
1819
async fn delay_us(&mut self, us: u32) {
1920
T::delay_us(self, us).await
2021
}
2122

23+
#[inline]
2224
async fn delay_ms(&mut self, ms: u32) {
2325
T::delay_ms(self, ms).await
2426
}

embedded-hal-async/src/digital.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Asynchronous digital I/O
1+
//! Asynchronous digital I/O.
22
//!
33
//! # Example
44
//!
@@ -49,22 +49,27 @@ pub trait Wait: embedded_hal::digital::ErrorType {
4949
}
5050

5151
impl<T: Wait + ?Sized> Wait for &mut T {
52+
#[inline]
5253
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
5354
T::wait_for_high(self).await
5455
}
5556

57+
#[inline]
5658
async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
5759
T::wait_for_low(self).await
5860
}
5961

62+
#[inline]
6063
async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
6164
T::wait_for_rising_edge(self).await
6265
}
6366

67+
#[inline]
6468
async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
6569
T::wait_for_falling_edge(self).await
6670
}
6771

72+
#[inline]
6873
async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
6974
T::wait_for_any_edge(self).await
7075
}

embedded-hal-async/src/i2c.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Async I2C API
1+
//! Async I2C API.
22
//!
33
//! This API supports 7-bit and 10-bit addresses. Traits feature an `AddressMode`
44
//! marker type parameter. Two implementation of the `AddressMode` exist:
@@ -21,9 +21,9 @@ pub use embedded_hal::i2c::{
2121
AddressMode, Error, ErrorKind, ErrorType, NoAcknowledgeSource, SevenBitAddress, TenBitAddress,
2222
};
2323

24-
/// Async i2c
24+
/// Async I2c.
2525
pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
26-
/// Reads enough bytes from slave with `address` to fill `buffer`
26+
/// Reads enough bytes from slave with `address` to fill `buffer`.
2727
///
2828
/// # I2C Events (contract)
2929
///
@@ -41,12 +41,13 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
4141
/// - `MAK` = master acknowledge
4242
/// - `NMAK` = master no acknowledge
4343
/// - `SP` = stop condition
44+
#[inline]
4445
async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error> {
4546
self.transaction(address, &mut [Operation::Read(read)])
4647
.await
4748
}
4849

49-
/// Writes bytes to slave with address `address`
50+
/// Writes bytes to slave with address `address`.
5051
///
5152
/// # I2C Events (contract)
5253
///
@@ -62,6 +63,7 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
6263
/// - `SAK` = slave acknowledge
6364
/// - `Bi` = ith byte of data
6465
/// - `SP` = stop condition
66+
#[inline]
6567
async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error> {
6668
self.transaction(address, &mut [Operation::Write(write)])
6769
.await
@@ -89,6 +91,7 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
8991
/// - `MAK` = master acknowledge
9092
/// - `NMAK` = master no acknowledge
9193
/// - `SP` = stop condition
94+
#[inline]
9295
async fn write_read(
9396
&mut self,
9497
address: A,
@@ -123,14 +126,17 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
123126
}
124127

125128
impl<A: AddressMode, T: I2c<A> + ?Sized> I2c<A> for &mut T {
129+
#[inline]
126130
async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error> {
127131
T::read(self, address, read).await
128132
}
129133

134+
#[inline]
130135
async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error> {
131136
T::write(self, address, write).await
132137
}
133138

139+
#[inline]
134140
async fn write_read(
135141
&mut self,
136142
address: A,
@@ -140,6 +146,7 @@ impl<A: AddressMode, T: I2c<A> + ?Sized> I2c<A> for &mut T {
140146
T::write_read(self, address, write, read).await
141147
}
142148

149+
#[inline]
143150
async fn transaction(
144151
&mut self,
145152
address: A,

embedded-hal-async/src/spi.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use embedded_hal::spi::{
44
Error, ErrorKind, ErrorType, Mode, Operation, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3,
55
};
66

7-
/// SPI device trait
7+
/// SPI device trait.
88
///
99
/// `SpiDevice` represents ownership over a single SPI device on a (possibly shared) bus, selected
1010
/// with a CS (Chip Select) pin.
@@ -36,6 +36,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
3636
/// This is a convenience method equivalent to `device.read_transaction(&mut [buf])`.
3737
///
3838
/// See also: [`SpiDevice::transaction`], [`SpiDevice::read`]
39+
#[inline]
3940
async fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
4041
self.transaction(&mut [Operation::Read(buf)]).await
4142
}
@@ -45,6 +46,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
4546
/// This is a convenience method equivalent to `device.write_transaction(&mut [buf])`.
4647
///
4748
/// See also: [`SpiDevice::transaction`], [`SpiDevice::write`]
49+
#[inline]
4850
async fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error> {
4951
self.transaction(&mut [Operation::Write(buf)]).await
5052
}
@@ -54,6 +56,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
5456
/// This is a convenience method equivalent to `device.transaction(|bus| bus.transfer(read, write))`.
5557
///
5658
/// See also: [`SpiDevice::transaction`], [`SpiBus::transfer`]
59+
#[inline]
5760
async fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error> {
5861
self.transaction(&mut [Operation::Transfer(read, write)])
5962
.await
@@ -64,38 +67,44 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
6467
/// This is a convenience method equivalent to `device.transaction(|bus| bus.transfer_in_place(buf))`.
6568
///
6669
/// See also: [`SpiDevice::transaction`], [`SpiBus::transfer_in_place`]
70+
#[inline]
6771
async fn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
6872
self.transaction(&mut [Operation::TransferInPlace(buf)])
6973
.await
7074
}
7175
}
7276

7377
impl<Word: Copy + 'static, T: SpiDevice<Word> + ?Sized> SpiDevice<Word> for &mut T {
78+
#[inline]
7479
async fn transaction(
7580
&mut self,
7681
operations: &mut [Operation<'_, Word>],
7782
) -> Result<(), Self::Error> {
7883
T::transaction(self, operations).await
7984
}
8085

86+
#[inline]
8187
async fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
8288
T::read(self, buf).await
8389
}
8490

91+
#[inline]
8592
async fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error> {
8693
T::write(self, buf).await
8794
}
8895

96+
#[inline]
8997
async fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error> {
9098
T::transfer(self, read, write).await
9199
}
92100

101+
#[inline]
93102
async fn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
94103
T::transfer_in_place(self, buf).await
95104
}
96105
}
97106

98-
/// SPI bus
107+
/// SPI bus.
99108
///
100109
/// `SpiBus` represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
101110
///
@@ -110,7 +119,7 @@ pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
110119
/// complete. See (the docs on embedded-hal)[embedded_hal::spi] for details on flushing.
111120
async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error>;
112121

113-
/// Write `words` to the slave, ignoring all the incoming words
122+
/// Write `words` to the slave, ignoring all the incoming words.
114123
///
115124
/// Implementations are allowed to return before the operation is
116125
/// complete. See (the docs on embedded-hal)[embedded_hal::spi] for details on flushing.
@@ -144,22 +153,27 @@ pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
144153
}
145154

146155
impl<T: SpiBus<Word> + ?Sized, Word: 'static + Copy> SpiBus<Word> for &mut T {
156+
#[inline]
147157
async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error> {
148158
T::read(self, words).await
149159
}
150160

161+
#[inline]
151162
async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error> {
152163
T::write(self, words).await
153164
}
154165

166+
#[inline]
155167
async fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error> {
156168
T::transfer(self, read, write).await
157169
}
158170

171+
#[inline]
159172
async fn transfer_in_place(&mut self, words: &mut [Word]) -> Result<(), Self::Error> {
160173
T::transfer_in_place(self, words).await
161174
}
162175

176+
#[inline]
163177
async fn flush(&mut self) -> Result<(), Self::Error> {
164178
T::flush(self).await
165179
}

0 commit comments

Comments
 (0)