Skip to content

Commit daeefdd

Browse files
committed
fix ci
1 parent fc21739 commit daeefdd

File tree

3 files changed

+41
-85
lines changed

3 files changed

+41
-85
lines changed

embassy-stm32/src/i2c/config.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#[cfg(gpio_v2)]
12
use crate::gpio::Pull;
3+
use crate::gpio::{AfType, OutputType, Speed};
24

35
#[repr(u8)]
46
#[derive(Copy, Clone)]
@@ -111,11 +113,13 @@ pub struct Config {
111113
///
112114
/// Using external pullup resistors is recommended for I2C. If you do
113115
/// have external pullups you should not enable this.
116+
#[cfg(gpio_v2)]
114117
pub sda_pullup: bool,
115118
/// Enable internal pullup on SCL.
116119
///
117120
/// Using external pullup resistors is recommended for I2C. If you do
118121
/// have external pullups you should not enable this.
122+
#[cfg(gpio_v2)]
119123
pub scl_pullup: bool,
120124
/// Timeout.
121125
#[cfg(feature = "time")]
@@ -125,7 +129,9 @@ pub struct Config {
125129
impl Default for Config {
126130
fn default() -> Self {
127131
Self {
132+
#[cfg(gpio_v2)]
128133
sda_pullup: false,
134+
#[cfg(gpio_v2)]
129135
scl_pullup: false,
130136
#[cfg(feature = "time")]
131137
timeout: embassy_time::Duration::from_millis(1000),
@@ -134,17 +140,31 @@ impl Default for Config {
134140
}
135141

136142
impl Config {
137-
pub(super) fn scl_pull_mode(&self) -> Pull {
138-
match self.scl_pullup {
139-
true => Pull::Up,
140-
false => Pull::Down,
141-
}
143+
pub(super) fn scl_af(&self) -> AfType {
144+
#[cfg(gpio_v1)]
145+
return AfType::output(OutputType::OpenDrain, Speed::Medium);
146+
#[cfg(gpio_v2)]
147+
return AfType::output_pull(
148+
OutputType::OpenDrain,
149+
Speed::Medium,
150+
match self.scl_pullup {
151+
true => Pull::Up,
152+
false => Pull::Down,
153+
},
154+
);
142155
}
143156

144-
pub(super) fn sda_pull_mode(&self) -> Pull {
145-
match self.sda_pullup {
146-
true => Pull::Up,
147-
false => Pull::Down,
148-
}
157+
pub(super) fn sda_af(&self) -> AfType {
158+
#[cfg(gpio_v1)]
159+
return AfType::output(OutputType::OpenDrain, Speed::Medium);
160+
#[cfg(gpio_v2)]
161+
return AfType::output_pull(
162+
OutputType::OpenDrain,
163+
Speed::Medium,
164+
match self.sda_pullup {
165+
true => Pull::Up,
166+
false => Pull::Down,
167+
},
168+
);
149169
}
150170
}

embassy-stm32/src/i2c/mod.rs

Lines changed: 10 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use embassy_time::{Duration, Instant};
1919
use mode::{Master, MasterMode};
2020

2121
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 _};
2523
use crate::interrupt::typelevel::Interrupt;
2624
use crate::mode::{Async, Blocking, Mode};
2725
use 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
11650
pub mod mode {
11751
trait SealedMode {}
@@ -169,8 +103,12 @@ struct I2CDropGuard<'d> {
169103
}
170104
impl<'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

193131
impl<'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;

embassy-stm32/src/i2c/v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ impl<'d, M: Mode> I2c<'d, M, Master> {
728728
timeout: self.timeout,
729729
_phantom: PhantomData,
730730
_phantom2: PhantomData,
731-
drop_guard: self.drop_guard,
731+
_drop_guard: self._drop_guard,
732732
};
733733
slave.init_slave(slave_addr_config);
734734
slave

0 commit comments

Comments
 (0)