Skip to content

Commit c1d6b81

Browse files
committed
pin release flow
1 parent 1355bc8 commit c1d6b81

File tree

7 files changed

+60
-10
lines changed

7 files changed

+60
-10
lines changed

src/analog/comparator.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ impl ComparatorSplit for COMP {
521521

522522
pub trait OutputPin<COMP> {
523523
fn setup(&self);
524+
fn release(self) -> Self;
524525
}
525526

526527
macro_rules! output_pin {
@@ -529,6 +530,10 @@ macro_rules! output_pin {
529530
fn setup(&self) {
530531
self.set_alt_mode(AltFunction::AF7)
531532
}
533+
534+
fn release(self) -> Self {
535+
self.into()
536+
}
532537
}
533538
};
534539
}

src/i2c.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ pub struct I2c<I2C, SDA, SCL> {
8282
// I2C SDA pin
8383
pub trait SDAPin<I2C> {
8484
fn setup(&self);
85+
fn release(self) -> Self;
8586
}
8687

8788
// I2C SCL pin
8889
pub trait SCLPin<I2C> {
8990
fn setup(&self);
91+
fn release(self) -> Self;
9092
}
9193

9294
// I2C error
@@ -155,6 +157,10 @@ macro_rules! i2c {
155157
fn setup(&self) {
156158
self.set_alt_mode(AltFunction::AF6)
157159
}
160+
161+
fn release(self) -> Self {
162+
self.into()
163+
}
158164
}
159165
)+
160166

@@ -163,6 +169,10 @@ macro_rules! i2c {
163169
fn setup(&self) {
164170
self.set_alt_mode(AltFunction::AF6)
165171
}
172+
173+
fn release(self) -> Self {
174+
self.into()
175+
}
166176
}
167177
)+
168178

@@ -182,7 +192,10 @@ macro_rules! i2c {
182192
}
183193
}
184194

185-
impl<SDA, SCL> I2c<$I2CX, SDA, SCL> {
195+
impl<SDA, SCL> I2c<$I2CX, SDA, SCL> where
196+
SDA: SDAPin<$I2CX>,
197+
SCL: SCLPin<$I2CX>
198+
{
186199
pub fn $i2cx(i2c: $I2CX, sda: SDA, scl: SCL, config: Config, rcc: &mut Rcc) -> Self
187200
where
188201
SDA: SDAPin<$I2CX>,
@@ -220,7 +233,7 @@ macro_rules! i2c {
220233
}
221234

222235
pub fn release(self) -> ($I2CX, SDA, SCL) {
223-
(self.i2c, self.sda, self.scl)
236+
(self.i2c, self.sda.release(), self.scl.release())
224237
}
225238
}
226239

src/rcc/clockout.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Lsco {
2020
}
2121

2222
pub fn release(self) -> LscoPin {
23-
self.pin
23+
self.pin.into()
2424
}
2525
}
2626

@@ -52,7 +52,10 @@ pub struct Mco<PIN> {
5252
src_bits: u8,
5353
}
5454

55-
impl<PIN> Mco<PIN> {
55+
impl<PIN> Mco<PIN>
56+
where
57+
PIN: MCOExt<PIN>,
58+
{
5659
pub fn enable(&self) {
5760
let rcc = unsafe { &(*RCC::ptr()) };
5861
rcc.cfgr
@@ -65,12 +68,13 @@ impl<PIN> Mco<PIN> {
6568
}
6669

6770
pub fn release(self) -> PIN {
68-
self.pin
71+
self.pin.release()
6972
}
7073
}
7174

7275
pub trait MCOExt<PIN> {
7376
fn mco(self, src: MCOSrc, psc: Prescaler, rcc: &mut Rcc) -> Mco<PIN>;
77+
fn release(self) -> PIN;
7478
}
7579

7680
macro_rules! mco {
@@ -117,6 +121,10 @@ macro_rules! mco {
117121
self.set_alt_mode(AltFunction::AF0);
118122
Mco { src_bits, pin: self }
119123
}
124+
125+
fn release(self) -> $PIN {
126+
self.into()
127+
}
120128
}
121129
)+
122130
};

src/serial/usart.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ pub struct Serial<USART, Config> {
9595
// Serial TX pin
9696
pub trait TxPin<USART> {
9797
fn setup(&self);
98+
fn release(self) -> Self;
9899
}
99100

100101
// Serial RX pin
101102
pub trait RxPin<USART> {
102103
fn setup(&self);
104+
fn release(self) -> Self;
103105
}
104106

105107
pub trait SerialExt<USART, Config> {
@@ -140,12 +142,15 @@ macro_rules! uart_shared {
140142
tx: [ $(($PTX:ident, $TAF:expr),)+ ],
141143
rx: [ $(($PRX:ident, $RAF:expr),)+ ]) => {
142144

143-
144145
$(
145146
impl<MODE> TxPin<$USARTX> for $PTX<MODE> {
146147
fn setup(&self) {
147148
self.set_alt_mode($TAF)
148149
}
150+
151+
fn release(self) -> Self {
152+
self.into()
153+
}
149154
}
150155
)+
151156

@@ -154,6 +159,10 @@ macro_rules! uart_shared {
154159
fn setup(&self) {
155160
self.set_alt_mode($RAF)
156161
}
162+
163+
fn release(self) -> Self {
164+
self.into()
165+
}
157166
}
158167
)+
159168

@@ -640,6 +649,7 @@ rx: [
640649
(PB7, AltFunction::AF0),
641650
(PC5, AltFunction::AF1),
642651
]);
652+
643653
uart_shared!(USART2, USART2_RX, USART2_TX,
644654
tx: [
645655
(PA2, AltFunction::AF1),

src/spi.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct NoMosi;
2525

2626
pub trait Pins<SPI> {
2727
fn setup(&self);
28+
fn release(self) -> Self;
2829
}
2930

3031
pub trait PinSck<SPI> {
@@ -50,6 +51,10 @@ where
5051
self.1.setup();
5152
self.2.setup();
5253
}
54+
55+
fn release(self) -> Self {
56+
(self.0.into(), self.1.into(), self.2.into())
57+
}
5358
}
5459

5560
#[derive(Debug)]
@@ -105,7 +110,7 @@ macro_rules! spi {
105110
}
106111
)*
107112

108-
impl<PINS> Spi<$SPIX, PINS> {
113+
impl<PINS: Pins<$SPIX>> Spi<$SPIX, PINS> {
109114
pub fn $spiX<T>(
110115
spi: $SPIX,
111116
pins: PINS,
@@ -114,7 +119,6 @@ macro_rules! spi {
114119
rcc: &mut Rcc
115120
) -> Self
116121
where
117-
PINS: Pins<$SPIX>,
118122
T: Into<Hertz>
119123
{
120124
// Enable clock for SPI
@@ -177,7 +181,7 @@ macro_rules! spi {
177181
}
178182

179183
pub fn release(self) -> ($SPIX, PINS) {
180-
(self.spi, self.pins)
184+
(self.spi, self.pins.release())
181185
}
182186
}
183187

src/timer/pins.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub trait TimerPin<TIM> {
1111
type Channel;
1212

1313
fn setup(&self);
14+
fn release(self) -> Self;
1415
}
1516

1617
macro_rules! timer_pins {
@@ -22,6 +23,10 @@ macro_rules! timer_pins {
2223
fn setup(&self) {
2324
self.set_alt_mode($af_mode);
2425
}
26+
27+
fn release(self) -> Self {
28+
self.into()
29+
}
2530
}
2631
)+
2732
};

src/timer/qei.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct Qei<TIM, PINS> {
1717

1818
pub trait QeiPins<TIM> {
1919
fn setup(&self);
20+
fn release(self) -> Self;
2021
}
2122

2223
impl<TIM, P1, P2> QeiPins<TIM> for (P1, P2)
@@ -28,6 +29,10 @@ where
2829
self.0.setup();
2930
self.1.setup();
3031
}
32+
33+
fn release(self) -> Self {
34+
(self.0.release(), self.1.release())
35+
}
3136
}
3237

3338
pub trait QeiExt<TIM, PINS>
@@ -78,7 +83,7 @@ macro_rules! qei {
7883
}
7984

8085
pub fn release(self) -> ($TIMX, PINS) {
81-
(self.tim, self.pins)
86+
(self.tim, self.pins.release())
8287
}
8388
}
8489

0 commit comments

Comments
 (0)