Skip to content

Commit c11058d

Browse files
committed
Add I2C support to the DMA API
This can't be used yet, as the I2C API itself doesn't support DMA yet.
1 parent 5f02350 commit c11058d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/dma.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ use core::{
2727
use as_slice::AsSlice;
2828

2929
use crate::{
30+
i2c,
3031
pac::{
3132
self,
3233
dma1::ccr1,
34+
I2C1,
35+
I2C2,
36+
I2C3,
3337
USART1,
3438
USART2,
3539
},
@@ -476,16 +480,35 @@ macro_rules! impl_target {
476480
}
477481
}
478482

483+
// See STM32L0x2 Reference Manual, table 51 (page 267).
479484
impl_target!(
485+
// USART1
480486
serial::Tx<USART1>, Channel2, 3;
481487
serial::Tx<USART1>, Channel4, 3;
482488
serial::Rx<USART1>, Channel3, 3;
483489
serial::Rx<USART1>, Channel5, 3;
484490

491+
// USART2
485492
serial::Tx<USART2>, Channel4, 4;
486493
serial::Tx<USART2>, Channel7, 4;
487494
serial::Rx<USART2>, Channel5, 4;
488495
serial::Rx<USART2>, Channel6, 4;
496+
497+
// I2C1
498+
i2c::Tx<I2C1>, Channel2, 6;
499+
i2c::Rx<I2C1>, Channel3, 6;
500+
i2c::Tx<I2C1>, Channel6, 6;
501+
i2c::Rx<I2C1>, Channel7, 6;
502+
503+
// I2C2
504+
i2c::Tx<I2C2>, Channel4, 7;
505+
i2c::Rx<I2C2>, Channel5, 7;
506+
507+
// I2C3
508+
i2c::Tx<I2C3>, Channel2, 14;
509+
i2c::Rx<I2C3>, Channel3, 14;
510+
i2c::Tx<I2C3>, Channel4, 14;
511+
i2c::Rx<I2C3>, Channel5, 14;
489512
);
490513

491514
// See STM32L0x2 Reference Manual, table 51 (page 267).

src/i2c.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! I2C
22
3-
use core::ops::Deref;
3+
use core::{
4+
marker::PhantomData,
5+
ops::Deref,
6+
};
47

58
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
69

@@ -382,3 +385,16 @@ i2c!(
382385
(PC0<Output<OpenDrain>>, AltMode::AF7),
383386
],
384387
);
388+
389+
390+
/// Token used for DMA transfers
391+
///
392+
/// This is an implementation detail. The user doesn't have to deal with this
393+
/// directly.
394+
pub struct Tx<I>(PhantomData<I>);
395+
396+
/// Token used for DMA transfers
397+
///
398+
/// This is an implementation detail. The user doesn't have to deal with this
399+
/// directly.
400+
pub struct Rx<I>(PhantomData<I>);

0 commit comments

Comments
 (0)