Skip to content

Commit d81f7b8

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

File tree

8 files changed

+44
-10
lines changed

8 files changed

+44
-10
lines changed

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,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ pub struct CriticalSectionDevice<'a, BUS, CS, D> {
2323
}
2424

2525
impl<'a, BUS, CS, D> CriticalSectionDevice<'a, BUS, CS, D> {
26-
/// Create a new ExclusiveDevice
26+
/// Create a new ExclusiveDevice.
27+
#[inline]
2728
pub fn new(bus: &'a Mutex<RefCell<BUS>>, cs: CS, delay: D) -> Self {
2829
Self { bus, cs, delay }
2930
}
@@ -36,6 +37,7 @@ impl<'a, BUS, CS> CriticalSectionDevice<'a, BUS, CS, super::NoDelay> {
3637
///
3738
/// The returned device will panic if you try to execute a transaction
3839
/// that contains any operations of type `Operation::DelayUs`.
40+
#[inline]
3941
pub fn new_no_delay(bus: &'a Mutex<RefCell<BUS>>, cs: CS) -> Self {
4042
Self {
4143
bus,
@@ -59,6 +61,7 @@ where
5961
CS: OutputPin,
6062
D: DelayUs,
6163
{
64+
#[inline]
6265
fn transaction(&mut self, operations: &mut [Operation<'_, Word>]) -> Result<(), Self::Error> {
6366
critical_section::with(|cs| {
6467
let bus = &mut *self.bus.borrow_ref_mut(cs);

embedded-hal-bus/src/spi/exclusive.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ pub struct ExclusiveDevice<BUS, CS, D> {
2222
}
2323

2424
impl<BUS, CS, D> ExclusiveDevice<BUS, CS, D> {
25-
/// Create a new ExclusiveDevice
25+
/// Create a new ExclusiveDevice.
26+
#[inline]
2627
pub fn new(bus: BUS, cs: CS, delay: D) -> Self {
2728
Self { bus, cs, delay }
2829
}
2930

3031
/// Returns a reference to the underlying bus object.
32+
#[inline]
3133
pub fn bus(&self) -> &BUS {
3234
&self.bus
3335
}
3436

3537
/// Returns a mutable reference to the underlying bus object.
38+
#[inline]
3639
pub fn bus_mut(&mut self) -> &mut BUS {
3740
&mut self.bus
3841
}
@@ -45,6 +48,7 @@ impl<BUS, CS> ExclusiveDevice<BUS, CS, super::NoDelay> {
4548
///
4649
/// The returned device will panic if you try to execute a transaction
4750
/// that contains any operations of type `Operation::DelayUs`.
51+
#[inline]
4852
pub fn new_no_delay(bus: BUS, cs: CS) -> Self {
4953
Self {
5054
bus,
@@ -68,6 +72,7 @@ where
6872
CS: OutputPin,
6973
D: DelayUs,
7074
{
75+
#[inline]
7176
fn transaction(&mut self, operations: &mut [Operation<'_, Word>]) -> Result<(), Self::Error> {
7277
self.cs.set_low().map_err(DeviceError::Cs)?;
7378

@@ -103,6 +108,7 @@ where
103108
CS: OutputPin,
104109
D: AsyncDelayUs,
105110
{
111+
#[inline]
106112
async fn transaction(
107113
&mut self,
108114
operations: &mut [Operation<'_, Word>],

embedded-hal-bus/src/spi/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use crate::defmt;
2121
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
2222
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
2323
pub enum DeviceError<BUS, CS> {
24-
/// An inner SPI bus operation failed
24+
/// An inner SPI bus operation failed.
2525
Spi(BUS),
26-
/// Asserting or deasserting CS failed
26+
/// Asserting or deasserting CS failed.
2727
Cs(CS),
2828
}
2929

@@ -32,6 +32,7 @@ where
3232
BUS: Error + Debug,
3333
CS: Debug,
3434
{
35+
#[inline]
3536
fn kind(&self) -> ErrorKind {
3637
match self {
3738
Self::Spi(e) => e.kind(),
@@ -51,6 +52,7 @@ fn no_delay_panic() {
5152
}
5253

5354
impl embedded_hal::delay::DelayUs for NoDelay {
55+
#[inline]
5456
fn delay_us(&mut self, _us: u32) {
5557
no_delay_panic();
5658
}
@@ -59,11 +61,13 @@ impl embedded_hal::delay::DelayUs for NoDelay {
5961
#[cfg(feature = "async")]
6062
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
6163
impl embedded_hal_async::delay::DelayUs for NoDelay {
64+
#[inline]
6265
async fn delay_us(&mut self, _us: u32) {
6366
no_delay_panic();
6467
}
6568

66-
async fn delay_ms(&mut self, _us: u32) {
69+
#[inline]
70+
async fn delay_ms(&mut self, _ms: u32) {
6771
no_delay_panic();
6872
}
6973
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub struct MutexDevice<'a, BUS, CS, D> {
2121
}
2222

2323
impl<'a, BUS, CS, D> MutexDevice<'a, BUS, CS, D> {
24-
/// Create a new ExclusiveDevice
24+
/// Create a new MutexDevice.
25+
#[inline]
2526
pub fn new(bus: &'a Mutex<BUS>, cs: CS, delay: D) -> Self {
2627
Self { bus, cs, delay }
2728
}
@@ -34,6 +35,7 @@ impl<'a, BUS, CS> MutexDevice<'a, BUS, CS, super::NoDelay> {
3435
///
3536
/// The returned device will panic if you try to execute a transaction
3637
/// that contains any operations of type `Operation::DelayUs`.
38+
#[inline]
3739
pub fn new_no_delay(bus: &'a Mutex<BUS>, cs: CS) -> Self {
3840
Self {
3941
bus,
@@ -57,6 +59,7 @@ where
5759
CS: OutputPin,
5860
D: DelayUs,
5961
{
62+
#[inline]
6063
fn transaction(&mut self, operations: &mut [Operation<'_, Word>]) -> Result<(), Self::Error> {
6164
let bus = &mut *self.bus.lock().unwrap();
6265

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub struct RefCellDevice<'a, BUS, CS, D> {
2020
}
2121

2222
impl<'a, BUS, CS, D> RefCellDevice<'a, BUS, CS, D> {
23-
/// Create a new ExclusiveDevice
23+
/// Create a new RefCellDevice.
24+
#[inline]
2425
pub fn new(bus: &'a RefCell<BUS>, cs: CS, delay: D) -> Self {
2526
Self { bus, cs, delay }
2627
}
@@ -33,6 +34,7 @@ impl<'a, BUS, CS> RefCellDevice<'a, BUS, CS, super::NoDelay> {
3334
///
3435
/// The returned device will panic if you try to execute a transaction
3536
/// that contains any operations of type `Operation::DelayUs`.
37+
#[inline]
3638
pub fn new_no_delay(bus: &'a RefCell<BUS>, cs: CS) -> Self {
3739
Self {
3840
bus,
@@ -56,6 +58,7 @@ where
5658
CS: OutputPin,
5759
D: DelayUs,
5860
{
61+
#[inline]
5962
fn transaction(&mut self, operations: &mut [Operation<'_, Word>]) -> Result<(), Self::Error> {
6063
let bus = &mut *self.bus.borrow_mut();
6164

0 commit comments

Comments
 (0)