pins: enable pwm pins

pull/20/head
Astro 2020-09-12 00:35:58 +02:00
parent 8cddbc5173
commit 4a1ce342a0
1 changed files with 13 additions and 3 deletions

View File

@ -1,6 +1,6 @@
use stm32f4xx_hal::{ use stm32f4xx_hal::{
adc::Adc, adc::Adc,
hal::{blocking::spi::Transfer, digital::v2::OutputPin}, hal::{self, blocking::spi::Transfer, digital::v2::OutputPin},
gpio::{ gpio::{
AF5, Alternate, Analog, Floating, Input, AF5, Alternate, Analog, Floating, Input,
gpioa::*, gpioa::*,
@ -287,11 +287,17 @@ impl PwmPins {
) -> PwmPins { ) -> PwmPins {
let freq = 20u32.khz(); let freq = 20u32.khz();
fn init_pwm_pin<P: hal::PwmPin<Duty=u16>>(pin: &mut P) {
pin.set_duty(0);
pin.enable();
}
let channels = ( let channels = (
max_v0.into_alternate_af2(), max_v0.into_alternate_af2(),
max_v1.into_alternate_af2(), max_v1.into_alternate_af2(),
); );
let (max_v0, max_v1) = pwm::tim3(tim3, channels, clocks, freq); let (mut max_v0, mut max_v1) = pwm::tim3(tim3, channels, clocks, freq);
init_pwm_pin(&mut max_v0);
init_pwm_pin(&mut max_v1);
let channels = ( let channels = (
max_i_pos0.into_alternate_af1(), max_i_pos0.into_alternate_af1(),
@ -299,8 +305,12 @@ impl PwmPins {
max_i_neg0.into_alternate_af1(), max_i_neg0.into_alternate_af1(),
max_i_neg1.into_alternate_af1(), max_i_neg1.into_alternate_af1(),
); );
let (max_i_pos0, max_i_pos1, max_i_neg0, max_i_neg1) = let (mut max_i_pos0, mut max_i_pos1, mut max_i_neg0, mut max_i_neg1) =
pwm::tim1(tim1, channels, clocks, freq); pwm::tim1(tim1, channels, clocks, freq);
init_pwm_pin(&mut max_i_pos0);
init_pwm_pin(&mut max_i_neg0);
init_pwm_pin(&mut max_i_pos1);
init_pwm_pin(&mut max_i_neg1);
PwmPins { PwmPins {
max_v0, max_v1, max_v0, max_v1,