3
3
//! as of 2021-02-25.
4
4
5
5
use crate :: hal:: blocking:: i2c:: { Read , Write , WriteRead } ;
6
- use crate :: pac:: { i2c1, I2C1 , I2C2 } ;
6
+ use crate :: pac:: { i2c1, I2C1 , I2C2 , I2C3 , I2C4 } ;
7
7
use crate :: rcc:: { Clocks , APB1R1 } ;
8
- #[ cfg( any( feature = "stm32l4x5" , feature = "stm32l4x6" ) ) ]
9
- use crate :: stm32:: I2C3 ;
10
8
use crate :: time:: Hertz ;
11
9
use cast:: { u16, u8} ;
12
10
use core:: ops:: Deref ;
@@ -121,7 +119,7 @@ impl State {
121
119
}
122
120
123
121
macro_rules! hal {
124
- ( $i2c_type: ident, $i2cX: ident, $i2cXen: ident, $i2cXrst: ident) => {
122
+ ( $i2c_type: ident, $enr : ident , $rstr : ident , $ i2cX: ident, $i2cXen: ident, $i2cXrst: ident) => {
125
123
impl <SCL , SDA > I2c <$i2c_type, ( SCL , SDA ) > {
126
124
pub fn $i2cX<F >(
127
125
i2c: $i2c_type,
@@ -135,20 +133,25 @@ macro_rules! hal {
135
133
SCL : SclPin <$i2c_type>,
136
134
SDA : SdaPin <$i2c_type>,
137
135
{
138
- apb1. enr( ) . modify( |_, w| w. $i2cXen( ) . set_bit( ) ) ;
139
- apb1. rstr( ) . modify( |_, w| w. $i2cXrst( ) . set_bit( ) ) ;
140
- apb1. rstr( ) . modify( |_, w| w. $i2cXrst( ) . clear_bit( ) ) ;
136
+ apb1. $ enr( ) . modify( |_, w| w. $i2cXen( ) . set_bit( ) ) ;
137
+ apb1. $ rstr( ) . modify( |_, w| w. $i2cXrst( ) . set_bit( ) ) ;
138
+ apb1. $ rstr( ) . modify( |_, w| w. $i2cXrst( ) . clear_bit( ) ) ;
141
139
Self :: new( i2c, pins, freq, clocks)
142
140
}
143
141
}
144
142
} ;
145
143
}
146
144
147
- hal ! ( I2C1 , i2c1, i2c1en, i2c1rst) ;
148
- hal ! ( I2C2 , i2c2, i2c2en, i2c2rst) ;
145
+ hal ! ( I2C1 , enr, rstr, i2c1, i2c1en, i2c1rst) ;
146
+ hal ! ( I2C2 , enr, rstr, i2c2, i2c2en, i2c2rst) ;
147
+
148
+ #[ cfg( any( feature = "stm32l4x3" , feature = "stm32l4x5" , feature = "stm32l4x6" ) ) ]
149
+ hal ! ( I2C3 , enr, rstr, i2c3, i2c3en, i2c3rst) ;
149
150
151
+ // Warning: available on stm32l4x5 according to reference manual,
152
+ // but stm32l475rc (only one available) does not have this peripheral listed,
150
153
#[ cfg( any( feature = "stm32l4x5" , feature = "stm32l4x6" ) ) ]
151
- hal ! ( I2C3 , i2c3 , i2c3en , i2c3rst ) ;
154
+ hal ! ( I2C4 , enr2 , rstr2 , i2c4 , i2c4en , i2c4rst ) ;
152
155
153
156
impl < SCL , SDA , I2C > I2c < I2C , ( SCL , SDA ) >
154
157
where
@@ -472,8 +475,8 @@ where
472
475
}
473
476
}
474
477
475
- // All parts have I2C1 on alternate function 4 of
476
- // pins PA9/PB6 as SCL and PA10/PB7 as SDA, etc.
478
+ /// **Warning**: A9 and A10 in AF4 don't have this function on stm32l471qe,
479
+ /// but do on stm32l431cb and stm32l451cc
477
480
mod i2c_pins_default {
478
481
use super :: { I2C1 , I2C2 } ;
479
482
use crate :: gpio:: gpioa:: { PA10 , PA9 } ;
@@ -489,23 +492,20 @@ mod i2c_pins_default {
489
492
490
493
#[ cfg( any( feature = "stm32l4x1" , feature = "stm32l4x2" , feature = "stm32l4x6" ) ) ]
491
494
mod i2c_pins_pb8_pb9 {
492
- use super :: I2C1 ;
493
- use crate :: gpio:: gpiob:: { PB8 , PB9 } ;
495
+ use super :: { I2C1 , I2C2 } ;
496
+ use crate :: gpio:: gpiob:: { PB13 , PB14 , PB8 , PB9 } ;
494
497
use crate :: gpio:: { Alternate , OpenDrain , Output , AF4 } ;
495
498
496
499
pins ! ( I2C1 , AF4 , SCL : [ PB8 ] , SDA : [ PB9 ] ) ;
497
- }
498
-
499
- #[ cfg( any( feature = "stm32l4x1" , feature = "stm32l4x6" ) ) ]
500
- mod i2c_pins_pb13_pb14 {
501
- use super :: I2C2 ;
502
- use crate :: gpio:: gpiob:: { PB13 , PB14 } ;
503
- use crate :: gpio:: { Alternate , OpenDrain , Output , AF4 } ;
504
-
505
500
pins ! ( I2C2 , AF4 , SCL : [ PB13 ] , SDA : [ PB14 ] ) ;
506
501
}
507
502
508
- #[ cfg( any( feature = "stm32l4x3" , feature = "stm32l4x5" , feature = "stm32l4x6" ) ) ]
503
+ #[ cfg( any(
504
+ feature = "stm32l4x1" ,
505
+ feature = "stm32l4x3" ,
506
+ feature = "stm32l4x5" ,
507
+ feature = "stm32l4x6"
508
+ ) ) ]
509
509
mod i2c_pins_pbc0_pc1 {
510
510
use super :: I2C3 ;
511
511
use crate :: gpio:: gpioc:: { PC0 , PC1 } ;
@@ -514,7 +514,17 @@ mod i2c_pins_pbc0_pc1 {
514
514
pins ! ( I2C3 , AF4 , SCL : [ PC0 ] , SDA : [ PC1 ] ) ;
515
515
}
516
516
517
- #[ cfg( feature = "stm32l4x3" ) ]
517
+ /// **Warning**: PA7 and PB4 don't have this function on stm32l486jg and stm32l476je,
518
+ /// but do on stm32l496ae and stm32l4a6ag
519
+ ///
520
+ /// **Warning**: PA7 and PB4 don't have this function on stm32l471qe and stm32l475rc,
521
+ /// but do on stm32l431cb and stm32l451cc
522
+ #[ cfg( any(
523
+ feature = "stm32l4x1" ,
524
+ feature = "stm32l4x2" ,
525
+ feature = "stm32l4x3" ,
526
+ feature = "stm32l4x6"
527
+ ) ) ]
518
528
mod i2c_pins_pa7_pb4 {
519
529
use super :: I2C3 ;
520
530
use crate :: gpio:: gpioa:: PA7 ;
@@ -524,3 +534,19 @@ mod i2c_pins_pa7_pb4 {
524
534
// These pins aren't as nicely consistent
525
535
pins ! ( I2C3 , AF4 , SCL : [ PA7 ] , SDA : [ PB4 ] ) ;
526
536
}
537
+
538
+ /// **Warning**: these pins don't have this function on stm32l486jg and stm32l476je,
539
+ /// but do on stm32l496ae and stm32l4a6ag
540
+ #[ cfg( feature = "stm32l4x6" ) ]
541
+ mod i2c_pins_pd12_pd13_pf0_pf1_pf14_pf15 {
542
+ use super :: { I2C2 , I2C4 } ;
543
+ use crate :: gpio:: gpiod:: { PD12 , PD13 } ;
544
+ use crate :: gpio:: gpiof:: { PF0 , PF1 , PF14 , PF15 } ;
545
+ use crate :: gpio:: { Alternate , OpenDrain , Output , AF4 } ;
546
+
547
+ // SCL and SDA are "reversed", correct according to reference manual
548
+ pins ! ( I2C2 , AF4 , SCL : [ PF1 ] , SDA : [ PF0 ] ) ;
549
+
550
+ pins ! ( I2C4 , AF4 , SCL : [ PD12 ] , SDA : [ PD13 ] ) ;
551
+ pins ! ( I2C4 , AF4 , SCL : [ PF14 ] , SDA : [ PF15 ] ) ;
552
+ }
0 commit comments