@@ -19,9 +19,7 @@ use embassy_time::{Duration, Instant};
1919use mode:: { Master , MasterMode } ;
2020
2121use crate :: dma:: ChannelAndRequest ;
22- #[ cfg( gpio_v2) ]
23- use crate :: gpio:: Pull ;
24- use crate :: gpio:: { AfType , AnyPin , OutputType , SealedPin as _, Speed } ;
22+ use crate :: gpio:: { AnyPin , SealedPin as _} ;
2523use crate :: interrupt:: typelevel:: Interrupt ;
2624use crate :: mode:: { Async , Blocking , Mode } ;
2725use crate :: rcc:: { RccInfo , SealedRccPeripheral } ;
@@ -48,70 +46,6 @@ pub enum Error {
4846 ZeroLengthTransfer ,
4947}
5048
51- /// I2C config
52- #[ non_exhaustive]
53- #[ derive( Copy , Clone ) ]
54- pub struct Config {
55- /// Enable internal pullup on SDA.
56- ///
57- /// Using external pullup resistors is recommended for I2C. If you do
58- /// have external pullups you should not enable this.
59- #[ cfg( gpio_v2) ]
60- pub sda_pullup : bool ,
61- /// Enable internal pullup on SCL.
62- ///
63- /// Using external pullup resistors is recommended for I2C. If you do
64- /// have external pullups you should not enable this.
65- #[ cfg( gpio_v2) ]
66- pub scl_pullup : bool ,
67- /// Timeout.
68- #[ cfg( feature = "time" ) ]
69- pub timeout : embassy_time:: Duration ,
70- }
71-
72- impl Default for Config {
73- fn default ( ) -> Self {
74- Self {
75- #[ cfg( gpio_v2) ]
76- sda_pullup : false ,
77- #[ cfg( gpio_v2) ]
78- scl_pullup : false ,
79- #[ cfg( feature = "time" ) ]
80- timeout : embassy_time:: Duration :: from_millis ( 1000 ) ,
81- }
82- }
83- }
84-
85- impl Config {
86- fn scl_af ( & self ) -> AfType {
87- #[ cfg( gpio_v1) ]
88- return AfType :: output ( OutputType :: OpenDrain , Speed :: Medium ) ;
89- #[ cfg( gpio_v2) ]
90- return AfType :: output_pull (
91- OutputType :: OpenDrain ,
92- Speed :: Medium ,
93- match self . scl_pullup {
94- true => Pull :: Up ,
95- false => Pull :: Down ,
96- } ,
97- ) ;
98- }
99-
100- fn sda_af ( & self ) -> AfType {
101- #[ cfg( gpio_v1) ]
102- return AfType :: output ( OutputType :: OpenDrain , Speed :: Medium ) ;
103- #[ cfg( gpio_v2) ]
104- return AfType :: output_pull (
105- OutputType :: OpenDrain ,
106- Speed :: Medium ,
107- match self . sda_pullup {
108- true => Pull :: Up ,
109- false => Pull :: Down ,
110- } ,
111- ) ;
112- }
113- }
114-
11549/// I2C modes
11650pub mod mode {
11751 trait SealedMode { }
@@ -169,8 +103,12 @@ struct I2CDropGuard<'d> {
169103}
170104impl < ' d > Drop for I2CDropGuard < ' d > {
171105 fn drop ( & mut self ) {
172- self . scl . as_ref ( ) . map ( |x| x. set_as_disconnected ( ) ) ;
173- self . sda . as_ref ( ) . map ( |x| x. set_as_disconnected ( ) ) ;
106+ if let Some ( x) = self . scl . as_ref ( ) {
107+ x. set_as_disconnected ( )
108+ }
109+ if let Some ( x) = self . sda . as_ref ( ) {
110+ x. set_as_disconnected ( )
111+ }
174112
175113 self . info . rcc . disable ( ) ;
176114 }
@@ -187,7 +125,7 @@ pub struct I2c<'d, M: Mode, IM: MasterMode> {
187125 timeout : Duration ,
188126 _phantom : PhantomData < M > ,
189127 _phantom2 : PhantomData < IM > ,
190- drop_guard : I2CDropGuard < ' d > ,
128+ _drop_guard : I2CDropGuard < ' d > ,
191129}
192130
193131impl < ' d > I2c < ' d , Async , Master > {
@@ -261,7 +199,7 @@ impl<'d, M: Mode> I2c<'d, M, Master> {
261199 timeout : config. timeout ,
262200 _phantom : PhantomData ,
263201 _phantom2 : PhantomData ,
264- drop_guard : I2CDropGuard {
202+ _drop_guard : I2CDropGuard {
265203 info : T :: info ( ) ,
266204 scl,
267205 sda,
@@ -509,9 +447,7 @@ fn operation_frames<'a, 'b: 'a>(
509447 let mut next_first_frame = true ;
510448
511449 Ok ( iter:: from_fn ( move || {
512- let Some ( op) = operations. next ( ) else {
513- return None ;
514- } ;
450+ let op = operations. next ( ) ?;
515451
516452 // Is `op` first frame of its type?
517453 let first_frame = next_first_frame;
0 commit comments