Skip to content

Commit 5d4148d

Browse files
committed
Use native u32 as PWM Duty type
1 parent 12b9310 commit 5d4148d

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/pwm.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ macro_rules! hal {
166166
}
167167

168168
impl hal::PwmPin for Pwm<$TIMX, C1> {
169-
type Duty = u16;
169+
type Duty = u32;
170170

171171
fn disable(&mut self) {
172172
unsafe { bb::clear(&(*$TIMX::ptr()).ccer, 0) }
@@ -176,21 +176,21 @@ macro_rules! hal {
176176
unsafe { bb::set(&(*$TIMX::ptr()).ccer, 0) }
177177
}
178178

179-
fn get_duty(&self) -> u16 {
180-
unsafe { u16((*$TIMX::ptr()).ccr1.read().ccr1().bits()).unwrap() }
179+
fn get_duty(&self) -> Self::Duty {
180+
unsafe { (*$TIMX::ptr()).ccr1.read().ccr1().bits() }
181181
}
182182

183-
fn get_max_duty(&self) -> u16 {
184-
unsafe { u16((*$TIMX::ptr()).arr.read().arr().bits()).unwrap() }
183+
fn get_max_duty(&self) -> Self::Duty {
184+
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
185185
}
186186

187-
fn set_duty(&mut self, duty: u16) {
188-
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr1().bits(u32(duty))) }
187+
fn set_duty(&mut self, duty: Self::Duty) {
188+
unsafe { (*$TIMX::ptr()).ccr1.write(|w| w.ccr1().bits(duty)) }
189189
}
190190
}
191191

192192
impl hal::PwmPin for Pwm<$TIMX, C2> {
193-
type Duty = u16;
193+
type Duty = u32;
194194

195195
fn disable(&mut self) {
196196
unsafe { bb::clear(&(*$TIMX::ptr()).ccer, 4) }
@@ -200,21 +200,21 @@ macro_rules! hal {
200200
unsafe { bb::set(&(*$TIMX::ptr()).ccer, 4) }
201201
}
202202

203-
fn get_duty(&self) -> u16 {
204-
unsafe { u16((*$TIMX::ptr()).ccr2.read().ccr2().bits()).unwrap() }
203+
fn get_duty(&self) -> Self::Duty {
204+
unsafe { (*$TIMX::ptr()).ccr2.read().ccr2().bits() }
205205
}
206206

207-
fn get_max_duty(&self) -> u16 {
208-
unsafe { u16((*$TIMX::ptr()).arr.read().arr().bits()).unwrap() }
207+
fn get_max_duty(&self) -> Self::Duty {
208+
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
209209
}
210210

211-
fn set_duty(&mut self, duty: u16) {
212-
unsafe { (*$TIMX::ptr()).ccr2.write(|w| w.ccr2().bits(u32(duty))) }
211+
fn set_duty(&mut self, duty: Self::Duty) {
212+
unsafe { (*$TIMX::ptr()).ccr2.write(|w| w.ccr2().bits(duty)) }
213213
}
214214
}
215215

216216
impl hal::PwmPin for Pwm<$TIMX, C3> {
217-
type Duty = u16;
217+
type Duty = u32;
218218

219219
fn disable(&mut self) {
220220
unsafe { bb::clear(&(*$TIMX::ptr()).ccer, 8) }
@@ -224,21 +224,21 @@ macro_rules! hal {
224224
unsafe { bb::set(&(*$TIMX::ptr()).ccer, 8) }
225225
}
226226

227-
fn get_duty(&self) -> u16 {
228-
unsafe { u16((*$TIMX::ptr()).ccr3.read().ccr3().bits()).unwrap() }
227+
fn get_duty(&self) -> Self::Duty {
228+
unsafe { (*$TIMX::ptr()).ccr3.read().ccr3().bits() }
229229
}
230230

231-
fn get_max_duty(&self) -> u16 {
232-
unsafe { u16((*$TIMX::ptr()).arr.read().arr().bits()).unwrap() }
231+
fn get_max_duty(&self) -> Self::Duty {
232+
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
233233
}
234234

235-
fn set_duty(&mut self, duty: u16) {
236-
unsafe { (*$TIMX::ptr()).ccr3.write(|w| w.ccr3().bits(u32(duty))) }
235+
fn set_duty(&mut self, duty: Self::Duty) {
236+
unsafe { (*$TIMX::ptr()).ccr3.write(|w| w.ccr3().bits(duty)) }
237237
}
238238
}
239239

240240
impl hal::PwmPin for Pwm<$TIMX, C4> {
241-
type Duty = u16;
241+
type Duty = u32;
242242

243243
fn disable(&mut self) {
244244
unsafe { bb::clear(&(*$TIMX::ptr()).ccer, 12) }
@@ -248,16 +248,16 @@ macro_rules! hal {
248248
unsafe { bb::set(&(*$TIMX::ptr()).ccer, 12) }
249249
}
250250

251-
fn get_duty(&self) -> u16 {
252-
unsafe { u16((*$TIMX::ptr()).ccr4.read().ccr4().bits()).unwrap() }
251+
fn get_duty(&self) -> Self::Duty {
252+
unsafe { (*$TIMX::ptr()).ccr4.read().ccr4().bits() }
253253
}
254254

255-
fn get_max_duty(&self) -> u16 {
256-
unsafe { u16((*$TIMX::ptr()).arr.read().arr().bits()).unwrap() }
255+
fn get_max_duty(&self) -> Self::Duty {
256+
unsafe { (*$TIMX::ptr()).arr.read().arr().bits() }
257257
}
258258

259-
fn set_duty(&mut self, duty: u16) {
260-
unsafe { (*$TIMX::ptr()).ccr4.write(|w| w.ccr4().bits(u32(duty))) }
259+
fn set_duty(&mut self, duty: Self::Duty) {
260+
unsafe { (*$TIMX::ptr()).ccr4.write(|w| w.ccr4().bits(duty)) }
261261
}
262262
}
263263
)+

0 commit comments

Comments
 (0)