stm32-rs / stm32f4xx-hal

A Rust embedded-hal HAL for all MCUs in the STM32 F4 family

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Erase PWM channel

kossnikita opened this issue · comments

I have the similar problem as #499. But in addition to this, I would like to use channels without binding to timers and their channels.
Is there any way to erase the timer and channel? To use a channel in an array for example.

    let pins = (Channel1::new(gpioa.pa0), Channel2::new(gpioa.pa1));
    let mut pwm = dp.TIM5.pwm_hz(pins, 1.kHz(), &clocks).split();

    let mut channels = [pwm.0, pwm.1];
|                              ^^^^^ expected `0`, found `1`
|
= note: expected struct `PwmChannel<_, 0, _>`
          found struct `PwmChannel<_, 1, _>`

Or like this

use hal::{
    prelude::*,
    timer::{Channel1, Channel2, PwmChannel, Instance, WithPwm},
|                                                      ^^^^^^^ private trait
};

struct CommonChannel<TIM, const C: u8> {
    pwm: PwmChannel<TIM, C>,
}

impl<TIM: Instance + WithPwm, const C: u8> CommonChannel<TIM, C> {
    pub fn enable(&self) {
        self.pwm.enable();
    }
}

Is there any way to erase the timer and channel? To use a channel in an array for example.

This is reasonable. Could you make PR with ErasedPwmChannel?