|
34 | 34 | //! and change their polarity with `set_polarity` and `set_complementary_polarity`.
|
35 | 35 |
|
36 | 36 | use super::{
|
37 |
| - compute_arr_presc, Advanced, Channel, FTimer, Instance, Ocm, Polarity, Timer, WithPwm, |
| 37 | + compute_arr_presc, Advanced, Channel, FTimer, Instance, Ocm, Polarity, Timer, WithPwm, IdleState, |
38 | 38 | };
|
39 | 39 | use crate::rcc::Clocks;
|
40 | 40 | use core::marker::PhantomData;
|
@@ -263,6 +263,16 @@ impl<TIM: Instance + WithPwm + Advanced, const C: u8> PwmChannel<TIM, C, true> {
|
263 | 263 | pub fn enable_complementary(&mut self) {
|
264 | 264 | TIM::enable_nchannel(C, true);
|
265 | 265 | }
|
| 266 | + |
| 267 | + #[inline] |
| 268 | + pub fn set_idle_state(&mut self, s: IdleState) { |
| 269 | + TIM::idle_state(C, false, s); |
| 270 | + } |
| 271 | + |
| 272 | + #[inline] |
| 273 | + pub fn set_complementary_idle_state(&mut self, s: IdleState) { |
| 274 | + TIM::idle_state(C, true, s); |
| 275 | + } |
266 | 276 | }
|
267 | 277 |
|
268 | 278 | pub struct PwmHz<TIM, P, PINS>
|
@@ -412,22 +422,36 @@ where
|
412 | 422 | TIM: Instance + WithPwm + Advanced,
|
413 | 423 | PINS: Pins<TIM, P>,
|
414 | 424 | {
|
| 425 | + #[inline] |
415 | 426 | pub fn enable_complementary(&mut self, channel: Channel) {
|
416 | 427 | TIM::enable_nchannel(PINS::check_complementary_used(channel) as u8, true)
|
417 | 428 | }
|
418 | 429 |
|
| 430 | + #[inline] |
419 | 431 | pub fn disable_complementary(&mut self, channel: Channel) {
|
420 | 432 | TIM::enable_nchannel(PINS::check_complementary_used(channel) as u8, false)
|
421 | 433 | }
|
422 | 434 |
|
| 435 | + #[inline] |
423 | 436 | pub fn set_dead_time(&mut self, dts_ticks: u16) {
|
424 | 437 | let bits = pack_ceil_dead_time(dts_ticks);
|
425 | 438 | TIM::set_dtg_value(bits);
|
426 | 439 | }
|
427 | 440 |
|
| 441 | + #[inline] |
428 | 442 | pub fn get_dead_time(&self) -> u16 {
|
429 | 443 | unpack_dead_time(TIM::read_dtg_value())
|
430 | 444 | }
|
| 445 | + |
| 446 | + #[inline] |
| 447 | + pub fn set_idle_state(&mut self, channel: Channel, s: IdleState) { |
| 448 | + TIM::idle_state(PINS::check_used(channel) as u8, false, s); |
| 449 | + } |
| 450 | + |
| 451 | + #[inline] |
| 452 | + pub fn set_complementary_idle_state(&mut self, channel: Channel, s: IdleState) { |
| 453 | + TIM::idle_state(PINS::check_complementary_used(channel) as u8, true, s); |
| 454 | + } |
431 | 455 | }
|
432 | 456 |
|
433 | 457 | pub struct Pwm<TIM, P, PINS, const FREQ: u32>
|
@@ -578,22 +602,36 @@ where
|
578 | 602 | TIM: Instance + WithPwm + Advanced,
|
579 | 603 | PINS: Pins<TIM, P>,
|
580 | 604 | {
|
| 605 | + #[inline] |
581 | 606 | pub fn enable_complementary(&mut self, channel: Channel) {
|
582 | 607 | TIM::enable_nchannel(PINS::check_complementary_used(channel) as u8, true)
|
583 | 608 | }
|
584 | 609 |
|
| 610 | + #[inline] |
585 | 611 | pub fn disable_complementary(&mut self, channel: Channel) {
|
586 | 612 | TIM::enable_nchannel(PINS::check_complementary_used(channel) as u8, false)
|
587 | 613 | }
|
588 | 614 |
|
| 615 | + #[inline] |
589 | 616 | pub fn set_dead_time(&mut self, dts_ticks: u16) {
|
590 | 617 | let bits = pack_ceil_dead_time(dts_ticks);
|
591 | 618 | TIM::set_dtg_value(bits);
|
592 | 619 | }
|
593 | 620 |
|
| 621 | + #[inline] |
594 | 622 | pub fn get_dead_time(&self) -> u16 {
|
595 | 623 | unpack_dead_time(TIM::read_dtg_value())
|
596 | 624 | }
|
| 625 | + |
| 626 | + #[inline] |
| 627 | + pub fn set_idle_state(&mut self, channel: Channel, s: IdleState) { |
| 628 | + TIM::idle_state(PINS::check_used(channel) as u8, false, s); |
| 629 | + } |
| 630 | + |
| 631 | + #[inline] |
| 632 | + pub fn set_complementary_idle_state(&mut self, channel: Channel, s: IdleState) { |
| 633 | + TIM::idle_state(PINS::check_complementary_used(channel) as u8, true, s); |
| 634 | + } |
597 | 635 | }
|
598 | 636 |
|
599 | 637 | const fn pack_ceil_dead_time(dts_ticks: u16) -> u8 {
|
|
0 commit comments