Skip to content

Commit a9be75f

Browse files
geomatsiTeXitoi
authored andcommitted
pwm: fix examples for custom Pins trait (#74)
Fix copy-paste errors and implement Pins trait properly for TIM3 PWM, where PC8 and PC9 pins are configured as its two channel channels.
1 parent 5687091 commit a9be75f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/pwm.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
The second example selects PC8 and PC9 channels for TIM3 PWM output:
7070
7171
```
72-
struct MyChannels(PB5<Alternate<PushPull>>);
72+
struct MyChannels(PC8<Alternate<PushPull>>, PC9<Alternate<PushPull>>);
7373
7474
impl Pins<TIM3> for MyChannels {
7575
const REMAP: u8 = 0b11; // use TIM3 AFIO remapping for PC6, PC7, PC8, PC9 pins
@@ -115,18 +115,21 @@
115115
116116
let device: pac::Peripherals = ..;
117117
118-
let (c1, c2) = device.TIM3.pwm(
118+
let (mut c1, mut c2) = device.TIM3.pwm(
119119
MyChannels(p1, p2),
120120
&mut afio.mapr,
121121
100.hz(),
122122
clocks,
123123
&mut rcc.apb1
124124
);
125125
126-
// Set the duty cycle of channel 0 to 50%
126+
// Set the duty cycle of channels C1 and C2 to 50% and 25% respectively
127127
c1.set_duty(c1.get_max_duty() / 2);
128+
c2.set_duty(c2.get_max_duty() / 4);
129+
128130
// PWM outputs are disabled by default
129131
c1.enable()
132+
c2.enable()
130133
131134
```
132135
*/

0 commit comments

Comments
 (0)