Skip to content

Commit 15f2298

Browse files
Merge #598
598: BREAKING CHANGE: Ability to use 1 DMA channel for TX or RX only for I2C dma implementation r=burrbull a=SpeedCrash100 # Short description This PR closes #590 * Adds two methods to the blocking I2c implementation: `use_dma_tx`, `use_dma_rx` to create I2CMasterDma that use only one of Tx/Rx channels. * Clients can only use `write_dma` and all blocking methods if using Tx only I2c DMA. * Clients can only use `read_dma` and all blocking methods if using Rx only I2c DMA. # What has changed for clients * An `I2CMasterDma` signature now has 3 generic parameters: 1. I2C instance 2. `TxDMA` with same I2C instance, DMA stream and channel number or `NoDMA` if Tx is not used 3. `RxDMA` with same I2C instance, DMA stream and channel number or `NoDMA` if Rx is not used * The client must import `I2CMasterHandleIT` from `stm32f4xx_hal::i2c::dma` for access interrupt handling methods or just use `stm32f4xx_hal::prelude::*` * The client must also import `TxDMA`, `RxDMA`, `NoDMA` from same module Co-authored-by: SpeedCrash100 <[email protected]>
2 parents b626dcb + 36d80e7 commit 15f2298

File tree

4 files changed

+390
-118
lines changed

4 files changed

+390
-118
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Add advanced timer dead time insertion example [#585]
1414
- Cleanups [#595]
1515
- Fix comlementary for independent channels [#599]
16+
- I2c dma can now use single DMA channel for TX or RX only [#598]
1617

1718
## [v0.15.0] - 2023-03-13
1819

examples/stopwatch-with-ssd1306-and-interrupts-and-dma-i2c.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use panic_semihosting as _; // logs messages to the host stderr; requires a debu
2222
use stm32f4xx_hal as hal;
2323

2424
use crate::hal::{
25-
dma::{Stream0, Stream1, StreamsTuple},
25+
dma::{Stream1, StreamsTuple},
2626
gpio::*,
27-
i2c::dma::{I2CMasterDma, I2CMasterWriteDMA},
27+
i2c::dma::{I2CMasterDma, NoDMA, TxDMA},
2828
i2c::I2c,
2929
interrupt, pac,
3030
pac::{DMA1, I2C1},
@@ -52,11 +52,9 @@ use heapless::String;
5252
use ssd1306::{prelude::*, Ssd1306};
5353

5454
pub type I2c1Handle = I2CMasterDma<
55-
I2C1, // Instance of I2C
56-
Stream1<DMA1>, // Stream used for Tx
57-
0, // Channel for Tx
58-
Stream0<DMA1>, // Stream used for Rx (Not used in example)
59-
1, // Channel for Rx (Not used in example)
55+
I2C1, // Instance of I2C
56+
TxDMA<I2C1, Stream1<DMA1>, 0>, // Stream and channel used for Tx. First parameter must be same Instance as first generic parameter of I2CMasterDma
57+
NoDMA, // This example don't need Rx
6058
>;
6159

6260
// Set up global state. It's all mutexed up for concurrency safety.
@@ -177,7 +175,7 @@ fn main() -> ! {
177175

178176
// Then convert it to DMA
179177
let streams = StreamsTuple::new(dp.DMA1);
180-
let i2c_dma: I2c1Handle = i2c.use_dma(streams.1, streams.0);
178+
let i2c_dma: I2c1Handle = i2c.use_dma_tx(streams.1);
181179
free(|cs| {
182180
I2C1.borrow(cs).replace(Some(i2c_dma));
183181
});

0 commit comments

Comments
 (0)