Skip to content

Commit 62b177c

Browse files
committed
spi: Small doc fixes
1 parent ad66fa9 commit 62b177c

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

embedded-hal-async/src/spi.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use embedded_hal::{digital::blocking::OutputPin, spi::blocking};
99

1010
/// SPI device trait
1111
///
12-
/// SpiDevice represents ownership over a single SPI device on a (possibly shared) bus, selected
13-
/// with a CS pin.
12+
/// `SpiDevice` represents ownership over a single SPI device on a (possibly shared) bus, selected
13+
/// with a CS (Chip Select) pin.
1414
///
1515
/// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for important information on SPI Bus vs Device traits.
1616
pub trait SpiDevice: ErrorType {
@@ -30,17 +30,18 @@ pub trait SpiDevice: ErrorType {
3030
),
3131
> + 'a;
3232

33-
/// Start a transaction against the device.
33+
/// Perform a transaction against the device.
3434
///
3535
/// - Locks the bus
3636
/// - Asserts the CS (Chip Select) pin.
3737
/// - Calls `f` with an exclusive reference to the bus, which can then be used to do transfers against the device.
38+
/// - [Flushes](SpiBusFlush::flush) the bus.
3839
/// - Deasserts the CS pin.
39-
/// - Unlocks the bus,
40+
/// - Unlocks the bus.
4041
///
41-
/// The lock mechanism is implementation-defined. The only requirement is it must prevent two
42+
/// The locking mechanism is implementation-defined. The only requirement is it must prevent two
4243
/// transactions from executing concurrently against the same bus. Examples of implementations are:
43-
/// critical sections, blocking mutexes, async mutexes, or returning an error or panicking if the bus is already busy.
44+
/// critical sections, blocking mutexes, async mutexes, returning an error or panicking if the bus is already busy.
4445
fn transaction<'a, R, F, Fut>(&'a mut self, f: F) -> Self::TransactionFuture<'a, R, F, Fut>
4546
where
4647
F: FnOnce(&'a mut Self::Bus) -> Fut + 'a,
@@ -74,14 +75,16 @@ impl<T: SpiDevice> SpiDevice for &mut T {
7475
}
7576
}
7677

77-
/// Flush for SPI bus
78+
/// Flush support for SPI bus
7879
pub trait SpiBusFlush: ErrorType {
7980
/// Future returned by the `flush` method.
8081
type FlushFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
8182
where
8283
Self: 'a;
8384

84-
/// Flush
85+
/// Wait until all operations have completed and the bus is idle.
86+
///
87+
/// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for information on flushing.
8588
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a>;
8689
}
8790

@@ -104,6 +107,9 @@ pub trait SpiBusRead<Word: 'static + Copy = u8>: SpiBusFlush {
104107
///
105108
/// The word value sent on MOSI during reading is implementation-defined,
106109
/// typically `0x00`, `0xFF`, or configurable.
110+
///
111+
/// Implementations are allowed to return before the operation is
112+
/// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
107113
fn read<'a>(&'a mut self, words: &'a mut [Word]) -> Self::ReadFuture<'a>;
108114
}
109115

@@ -123,6 +129,9 @@ pub trait SpiBusWrite<Word: 'static + Copy = u8>: SpiBusFlush {
123129
Self: 'a;
124130

125131
/// Write `words` to the slave, ignoring all the incoming words
132+
///
133+
/// Implementations are allowed to return before the operation is
134+
/// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
126135
fn write<'a>(&'a mut self, words: &'a [Word]) -> Self::WriteFuture<'a>;
127136
}
128137

@@ -136,7 +145,7 @@ impl<T: SpiBusWrite<Word>, Word: 'static + Copy> SpiBusWrite<Word> for &mut T {
136145

137146
/// Read-write SPI bus
138147
///
139-
/// SpiBus represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
148+
/// `SpiBus` represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
140149
///
141150
/// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for important information on SPI Bus vs Device traits.
142151
pub trait SpiBus<Word: 'static + Copy = u8>: SpiBusRead<Word> + SpiBusWrite<Word> {
@@ -153,6 +162,9 @@ pub trait SpiBus<Word: 'static + Copy = u8>: SpiBusRead<Word> + SpiBusWrite<Word
153162
/// incoming words after `read` has been filled will be discarded. If `write` is shorter,
154163
/// the value of words sent in MOSI after all `write` has been sent is implementation-defined,
155164
/// typically `0x00`, `0xFF`, or configurable.
165+
///
166+
/// Implementations are allowed to return before the operation is
167+
/// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
156168
fn transfer<'a>(
157169
&'a mut self,
158170
read: &'a mut [Word],
@@ -167,6 +179,9 @@ pub trait SpiBus<Word: 'static + Copy = u8>: SpiBusRead<Word> + SpiBusWrite<Word
167179
/// Write and read simultaneously. The contents of `words` are
168180
/// written to the slave, and the received words are stored into the same
169181
/// `words` buffer, overwriting it.
182+
///
183+
/// Implementations are allowed to return before the operation is
184+
/// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
170185
fn transfer_in_place<'a>(
171186
&'a mut self,
172187
words: &'a mut [Word],

src/spi/blocking.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ use super::{Error, ErrorKind};
175175

176176
/// SPI device trait
177177
///
178-
/// SpiDevice represents ownership over a single SPI device on a (possibly shared) bus, selected
179-
/// with a CS pin.
178+
/// `SpiDevice` represents ownership over a single SPI device on a (possibly shared) bus, selected
179+
/// with a CS (Chip Select) pin.
180180
///
181181
/// See the [module-level documentation](self) for important usage information.
182182
pub trait SpiDevice: ErrorType {
@@ -192,9 +192,9 @@ pub trait SpiDevice: ErrorType {
192192
/// - Deasserts the CS pin.
193193
/// - Unlocks the bus.
194194
///
195-
/// The lock mechanism is implementation-defined. The only requirement is it must prevent two
195+
/// The locking mechanism is implementation-defined. The only requirement is it must prevent two
196196
/// transactions from executing concurrently against the same bus. Examples of implementations are:
197-
/// critical sections, blocking mutexes, or returning an error or panicking if the bus is already busy.
197+
/// critical sections, blocking mutexes, returning an error or panicking if the bus is already busy.
198198
fn transaction<R>(
199199
&mut self,
200200
f: impl FnOnce(&mut Self::Bus) -> Result<R, <Self::Bus as ErrorType>::Error>,
@@ -265,7 +265,7 @@ impl<T: SpiDevice> SpiDevice for &mut T {
265265

266266
/// Flush support for SPI bus
267267
pub trait SpiBusFlush: ErrorType {
268-
/// Blocks until all operations have completed and the bus is idle.
268+
/// Wait until all operations have completed and the bus is idle.
269269
///
270270
/// See the [module-level documentation](self) for important usage information.
271271
fn flush(&mut self) -> Result<(), Self::Error>;
@@ -279,7 +279,7 @@ impl<T: SpiBusFlush> SpiBusFlush for &mut T {
279279

280280
/// Read-only SPI bus
281281
pub trait SpiBusRead<Word: Copy = u8>: SpiBusFlush {
282-
/// Reads `words` from the slave.
282+
/// Read `words` from the slave.
283283
///
284284
/// The word value sent on MOSI during reading is implementation-defined,
285285
/// typically `0x00`, `0xFF`, or configurable.
@@ -297,7 +297,7 @@ impl<T: SpiBusRead<Word>, Word: Copy> SpiBusRead<Word> for &mut T {
297297

298298
/// Write-only SPI bus
299299
pub trait SpiBusWrite<Word: Copy = u8>: SpiBusFlush {
300-
/// Writes `words` to the slave, ignoring all the incoming words
300+
/// Write `words` to the slave, ignoring all the incoming words
301301
///
302302
/// Implementations are allowed to return before the operation is
303303
/// complete. See the [module-level documentation](self) for details.
@@ -312,11 +312,11 @@ impl<T: SpiBusWrite<Word>, Word: Copy> SpiBusWrite<Word> for &mut T {
312312

313313
/// Read-write SPI bus
314314
///
315-
/// SpiBus represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
315+
/// `SpiBus` represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
316316
///
317317
/// See the [module-level documentation](self) for important information on SPI Bus vs Device traits.
318318
pub trait SpiBus<Word: Copy = u8>: SpiBusRead<Word> + SpiBusWrite<Word> {
319-
/// Writes and reads simultaneously. `write` is written to the slave on MOSI and
319+
/// Write and read simultaneously. `write` is written to the slave on MOSI and
320320
/// words received on MISO are stored in `read`.
321321
///
322322
/// It is allowed for `read` and `write` to have different lengths, even zero length.
@@ -329,7 +329,7 @@ pub trait SpiBus<Word: Copy = u8>: SpiBusRead<Word> + SpiBusWrite<Word> {
329329
/// complete. See the [module-level documentation](self) for details.
330330
fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error>;
331331

332-
/// Writes and reads simultaneously. The contents of `words` are
332+
/// Write and read simultaneously. The contents of `words` are
333333
/// written to the slave, and the received words are stored into the same
334334
/// `words` buffer, overwriting it.
335335
///
@@ -388,7 +388,7 @@ impl<BUS, CS> ExclusiveDevice<BUS, CS> {
388388

389389
impl<BUS, CS> ErrorType for ExclusiveDevice<BUS, CS>
390390
where
391-
BUS: SpiBusFlush,
391+
BUS: ErrorType,
392392
CS: OutputPin,
393393
{
394394
type Error = ExclusiveDeviceError<BUS::Error, CS::Error>;

0 commit comments

Comments
 (0)