Skip to content

Commit 35e6012

Browse files
authored
Merge pull request #488 from luojia65/luojia65/1.0.0-fixes
lib: amend documents to add periods (.), add inline hints when necessary
2 parents 9228fb2 + d2f099e commit 35e6012

File tree

23 files changed

+235
-104
lines changed

23 files changed

+235
-104
lines changed

embedded-hal-async/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Minor document fixes.
11+
- Add #[inline] hints to most of `embedded-hal-async` functions.
12+
1013
## [v1.0.0-rc.1] - 2023-08-15
1114

1215
- Updated `embedded-hal` to version `1.0.0-rc.1`.

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
}

embedded-hal-bus/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Minor document fixes.
11+
- Add #[inline] hints to most of `embedded-hal-bus` functions.
12+
1013
## [v0.1.0-rc.1] - 2023-08-15
1114

1215
- Updated `embedded-hal`, `embedded-hal-async` to version `1.0.0-rc.1`.

embedded-hal-bus/src/i2c/critical_section.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub struct CriticalSectionDevice<'a, T> {
1414
}
1515

1616
impl<'a, T> CriticalSectionDevice<'a, T> {
17-
/// Create a new `CriticalSectionDevice`
17+
/// Create a new `CriticalSectionDevice`.
18+
#[inline]
1819
pub fn new(bus: &'a Mutex<RefCell<T>>) -> Self {
1920
Self { bus }
2021
}
@@ -31,20 +32,23 @@ impl<'a, T> I2c for CriticalSectionDevice<'a, T>
3132
where
3233
T: I2c,
3334
{
35+
#[inline]
3436
fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> {
3537
critical_section::with(|cs| {
3638
let bus = &mut *self.bus.borrow_ref_mut(cs);
3739
bus.read(address, read)
3840
})
3941
}
4042

43+
#[inline]
4144
fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> {
4245
critical_section::with(|cs| {
4346
let bus = &mut *self.bus.borrow_ref_mut(cs);
4447
bus.write(address, write)
4548
})
4649
}
4750

51+
#[inline]
4852
fn write_read(
4953
&mut self,
5054
address: u8,
@@ -57,6 +61,7 @@ where
5761
})
5862
}
5963

64+
#[inline]
6065
fn transaction(
6166
&mut self,
6267
address: u8,

embedded-hal-bus/src/i2c/mutex.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pub struct MutexDevice<'a, T> {
1212
}
1313

1414
impl<'a, T> MutexDevice<'a, T> {
15-
/// Create a new `MutexDevice`
15+
/// Create a new `MutexDevice`.
16+
#[inline]
1617
pub fn new(bus: &'a Mutex<T>) -> Self {
1718
Self { bus }
1819
}
@@ -29,16 +30,19 @@ impl<'a, T> I2c for MutexDevice<'a, T>
2930
where
3031
T: I2c,
3132
{
33+
#[inline]
3234
fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> {
3335
let bus = &mut *self.bus.lock().unwrap();
3436
bus.read(address, read)
3537
}
3638

39+
#[inline]
3740
fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> {
3841
let bus = &mut *self.bus.lock().unwrap();
3942
bus.write(address, write)
4043
}
4144

45+
#[inline]
4246
fn write_read(
4347
&mut self,
4448
address: u8,
@@ -49,6 +53,7 @@ where
4953
bus.write_read(address, write, read)
5054
}
5155

56+
#[inline]
5257
fn transaction(
5358
&mut self,
5459
address: u8,

embedded-hal-bus/src/i2c/refcell.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ pub struct RefCellDevice<'a, T> {
6868
}
6969

7070
impl<'a, T> RefCellDevice<'a, T> {
71-
/// Create a new `RefCellDevice`
71+
/// Create a new `RefCellDevice`.
72+
#[inline]
7273
pub fn new(bus: &'a RefCell<T>) -> Self {
7374
Self { bus }
7475
}
@@ -85,16 +86,19 @@ impl<'a, T> I2c for RefCellDevice<'a, T>
8586
where
8687
T: I2c,
8788
{
89+
#[inline]
8890
fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> {
8991
let bus = &mut *self.bus.borrow_mut();
9092
bus.read(address, read)
9193
}
9294

95+
#[inline]
9396
fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> {
9497
let bus = &mut *self.bus.borrow_mut();
9598
bus.write(address, write)
9699
}
97100

101+
#[inline]
98102
fn write_read(
99103
&mut self,
100104
address: u8,
@@ -105,6 +109,7 @@ where
105109
bus.write_read(address, write, read)
106110
}
107111

112+
#[inline]
108113
fn transaction(
109114
&mut self,
110115
address: u8,

0 commit comments

Comments
 (0)