Skip to content

Commit 122c11e

Browse files
committed
Add the half-duplex use case and update the behaviours accordingly
1 parent 6f96afb commit 122c11e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

hal/rfcs/0000-spi-overhaul.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ In order to provide a meaningful API, this RFC will consider the following use c
5757
- SPI Slave block transfer : Not supported in current API
5858

5959
The asynchronous API is particularly important when dealing with multiple interfaces. Indeed, handling simultaneously two SPI transfers would require two thread with a blocking API while only one is required by the asynchronous API saving kilobytes of RAM.
60-
60+
- Half-duplex mode:
61+
The [LPS22HB](https://www.st.com/en/mems-and-sensors/lps22hb.html) product family can be controlled through a half-duplex SPI interface (called 3 wire mode in the data sheet).
6162

6263
## API Changes
6364

@@ -144,6 +145,7 @@ void spi_free(spi_t *obj);
144145
- The shortest part of the duty cycle must not be shorter than 50% of the expected period.
145146
- `spi_init()` initializes the pins leaving the configuration registers unchanged.
146147
- `spi_init()` ignores the `SS` pin if `is_slave` is false.
148+
- if `miso` (exclusive) or `mosi` is missing in any function that expects pins, the bus is assumed to be half-duplex.
147149
- `spi_free()` resets the pins to their default state.
148150
- `spi_free()` disables the peripheral clock.
149151
- `spi_format()` sets :
@@ -162,9 +164,13 @@ void spi_free(spi_t *obj);
162164
- `spi_transfer()` :
163165
- writes `tx_len` symbols to the bus.
164166
- reads `rx_len` symbols from the bus.
165-
- if `rx_len` > `tx_len` then it sends `(rx_len-tx_len)` additional `fill_symbol` to the bus.
166167
- if `rx` is NULL then inputs are discarded.
167168
- if `tx` is NULL then `fill_symbol` is used instead.
169+
- In Full-duplex mode :
170+
- if `rx_len` > `tx_len` then it sends `(rx_len-tx_len)` additional `fill_symbol` to the bus.
171+
- In Half-duplex mode :
172+
- as master, `spi_transfer()` sends `tx_len` symbols and then reads `rx_len` symbols.
173+
- as slave, `spi_transfer()` receives `rx_len` symbols and then sends `tx_len` symbols.
168174
- `spi_transter_async()` schedules a transfer to be process the same way ̀`spi_transfer()` would have but asynchronously.
169175
- `spi_transter_async()` returns immediately with a boolean indicating whether the transfer was successfully scheduled or not.
170176
- The callback given to `spi_transfer_async()` is invoked when the transfer completes (with a success or an error).
@@ -186,6 +192,7 @@ void spi_free(spi_t *obj);
186192
- Passing an invalid pointer as `fill_symbol` to `spi_transfer` and `spi_transfer_async` while they would be required by the transfer (`rx_len != tx_len` or `tx==NULL`).
187193
- Passing an invalid pointer as `handler` to `spi_transfer_async`.
188194
- Calling `spi_transfer_async_abort()` while no async transfer is being processed (no transfer or a synchronous transfer).
195+
- In half-duplex mode, any mechanism (if any is present) to detect or prevent collision is implementation defined.
189196
190197
### Updated flow
191198
The IRQ flow has slightly changed. In the new API the flow is as follow :

0 commit comments

Comments
 (0)