@@ -19,9 +19,7 @@ use embassy_time::{Duration, Instant};
19
19
use mode:: { Master , MasterMode } ;
20
20
21
21
use 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 _} ;
25
23
use crate :: interrupt:: typelevel:: Interrupt ;
26
24
use crate :: mode:: { Async , Blocking , Mode } ;
27
25
use crate :: rcc:: { RccInfo , SealedRccPeripheral } ;
@@ -48,70 +46,6 @@ pub enum Error {
48
46
ZeroLengthTransfer ,
49
47
}
50
48
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
-
115
49
/// I2C modes
116
50
pub mod mode {
117
51
trait SealedMode { }
@@ -169,8 +103,12 @@ struct I2CDropGuard<'d> {
169
103
}
170
104
impl < ' d > Drop for I2CDropGuard < ' d > {
171
105
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
+ }
174
112
175
113
self . info . rcc . disable ( ) ;
176
114
}
@@ -187,7 +125,7 @@ pub struct I2c<'d, M: Mode, IM: MasterMode> {
187
125
timeout : Duration ,
188
126
_phantom : PhantomData < M > ,
189
127
_phantom2 : PhantomData < IM > ,
190
- drop_guard : I2CDropGuard < ' d > ,
128
+ _drop_guard : I2CDropGuard < ' d > ,
191
129
}
192
130
193
131
impl < ' d > I2c < ' d , Async , Master > {
@@ -261,7 +199,7 @@ impl<'d, M: Mode> I2c<'d, M, Master> {
261
199
timeout : config. timeout ,
262
200
_phantom : PhantomData ,
263
201
_phantom2 : PhantomData ,
264
- drop_guard : I2CDropGuard {
202
+ _drop_guard : I2CDropGuard {
265
203
info : T :: info ( ) ,
266
204
scl,
267
205
sda,
@@ -509,9 +447,7 @@ fn operation_frames<'a, 'b: 'a>(
509
447
let mut next_first_frame = true ;
510
448
511
449
Ok ( iter:: from_fn ( move || {
512
- let Some ( op) = operations. next ( ) else {
513
- return None ;
514
- } ;
450
+ let op = operations. next ( ) ?;
515
451
516
452
// Is `op` first frame of its type?
517
453
let first_frame = next_first_frame;
0 commit comments