From 4a1ce342a0b8ed12762805b6d2d5839e98213807 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 12 Sep 2020 00:35:58 +0200 Subject: [PATCH] pins: enable pwm pins --- src/pins.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pins.rs b/src/pins.rs index 3628aae..b12813e 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -1,6 +1,6 @@ use stm32f4xx_hal::{ adc::Adc, - hal::{blocking::spi::Transfer, digital::v2::OutputPin}, + hal::{self, blocking::spi::Transfer, digital::v2::OutputPin}, gpio::{ AF5, Alternate, Analog, Floating, Input, gpioa::*, @@ -287,11 +287,17 @@ impl PwmPins { ) -> PwmPins { let freq = 20u32.khz(); + fn init_pwm_pin>(pin: &mut P) { + pin.set_duty(0); + pin.enable(); + } let channels = ( max_v0.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 = ( max_i_pos0.into_alternate_af1(), @@ -299,8 +305,12 @@ impl PwmPins { max_i_neg0.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); + 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 { max_v0, max_v1,