Skip to content

Commit c23fd78

Browse files
authored
Merge pull request #55 from nickray/v0.7.0-pac
Use 0.7.0 PAC and fix PWM
2 parents 82fd75b + 86d3a65 commit c23fd78

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ edition = "2018"
2323
[dependencies]
2424
cortex-m = "0.5.8"
2525
nb = "0.1.1"
26-
stm32l4 = "0.6.0"
26+
stm32l4 = "0.7.0"
2727
as-slice = "0.1"
2828

2929
[dependencies.cast]

src/gpio.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ macro_rules! gpio {
112112
use crate::rcc::AHB2;
113113
use super::{
114114
Alternate,
115-
AF1, AF4, AF5, AF6, AF7, AF8, AF9,
115+
AF1, AF4, AF5, AF6, AF7, AF8, AF9, AF10,
116116
Floating, GpioExt, Input, OpenDrain, Output,
117117
PullDown, PullUp, PushPull, State,
118118
};
@@ -402,6 +402,30 @@ macro_rules! gpio {
402402
$PXi { _mode: PhantomData }
403403
}
404404

405+
/// Configures the pin to serve as alternate function 10 (AF10)
406+
pub fn into_af10(
407+
self,
408+
moder: &mut MODER,
409+
afr: &mut $AFR,
410+
) -> $PXi<Alternate<AF10, MODE>> {
411+
let offset = 2 * $i;
412+
413+
// alternate function mode
414+
let mode = 0b10;
415+
moder.moder().modify(|r, w| unsafe {
416+
w.bits((r.bits() & !(0b11 << offset)) | (mode << offset))
417+
});
418+
419+
let af = 10;
420+
let offset = 4 * ($i % 8);
421+
422+
afr.afr().modify(|r, w| unsafe {
423+
w.bits((r.bits() & !(0b1111 << offset)) | (af << offset))
424+
});
425+
426+
$PXi { _mode: PhantomData }
427+
}
428+
405429
/// Configures the pin to operate as a floating input pin
406430
pub fn into_floating_input(
407431
self,

src/pwm.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ macro_rules! hal {
192192
}
193193

194194
fn get_duty(&self) -> Self::Duty {
195-
unsafe { (*$TIMX::ptr()).ccr1.read().ccr1().bits() }
195+
unsafe { (*$TIMX::ptr()).ccr1.read().ccr().bits() }
196196
}
197197

198198
fn get_max_duty(&self) -> Self::Duty {
199199
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
200200
}
201201

202202
fn set_duty(&mut self, duty: Self::Duty) {
203-
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr1().bits(duty)) }
203+
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr().bits(duty)) }
204204
}
205205
}
206206

@@ -216,15 +216,15 @@ macro_rules! hal {
216216
}
217217

218218
fn get_duty(&self) -> Self::Duty {
219-
unsafe { (*$TIMX::ptr()).ccr2.read().ccr2().bits() }
219+
unsafe { (*$TIMX::ptr()).ccr2.read().ccr().bits() }
220220
}
221221

222222
fn get_max_duty(&self) -> Self::Duty {
223223
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
224224
}
225225

226226
fn set_duty(&mut self, duty: Self::Duty) {
227-
unsafe { (*$TIMX::ptr()).ccr2.write(|w| w.ccr2().bits(duty)) }
227+
unsafe { (*$TIMX::ptr()).ccr2.write(|w| w.ccr().bits(duty)) }
228228
}
229229
}
230230

@@ -240,15 +240,15 @@ macro_rules! hal {
240240
}
241241

242242
fn get_duty(&self) -> Self::Duty {
243-
unsafe { (*$TIMX::ptr()).ccr3.read().ccr3().bits() }
243+
unsafe { (*$TIMX::ptr()).ccr3.read().ccr().bits() }
244244
}
245245

246246
fn get_max_duty(&self) -> Self::Duty {
247247
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
248248
}
249249

250250
fn set_duty(&mut self, duty: Self::Duty) {
251-
unsafe { (*$TIMX::ptr()).ccr3.write(|w| w.ccr3().bits(duty)) }
251+
unsafe { (*$TIMX::ptr()).ccr3.write(|w| w.ccr().bits(duty)) }
252252
}
253253
}
254254

@@ -264,15 +264,15 @@ macro_rules! hal {
264264
}
265265

266266
fn get_duty(&self) -> Self::Duty {
267-
unsafe { (*$TIMX::ptr()).ccr4.read().ccr4().bits() }
267+
unsafe { (*$TIMX::ptr()).ccr4.read().ccr().bits() }
268268
}
269269

270270
fn get_max_duty(&self) -> Self::Duty {
271271
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
272272
}
273273

274274
fn set_duty(&mut self, duty: Self::Duty) {
275-
unsafe { (*$TIMX::ptr()).ccr4.write(|w| w.ccr4().bits(duty)) }
275+
unsafe { (*$TIMX::ptr()).ccr4.write(|w| w.ccr().bits(duty)) }
276276
}
277277
}
278278
)+

0 commit comments

Comments
 (0)