Struct gd32vf103xx_hal::pwm::PwmTimer [−][src]
pub struct PwmTimer<TIMER, REMAP> { /* fields omitted */ }
Expand description
PWM TIMER configuration.
To create a new PWM TIMER you should choose a timer and a REMAP mode from
NoRemap
, PartialRemap1
, PartialRemap2
or FullRemap
.
The tuple provided should contains only the pins you will use.
use gd32vf103xx_hal as hal;
use hal::pac::{Peripherals, TIMER0};
use hal::gpio::GpioExt;
use hal::rcu::RcuExt;
use hal::afio::AfioExt;
use hal::pwm::{PwmTimer, Channel, NoRemap};
use embedded_hal::Pwm;
// ...
let dp = Peripherals::take().unwrap();
let mut rcu = dp.RCU.configure().freeze();
let gpioa = dp.GPIOA.split(&mut rcu);
let pa9 = gpioa.pa9.into_alternate_push_pull();
let pa10 = gpioa.pa10.into_alternate_push_pull();
let mut afio = dp.AFIO.constrain(&mut rcu);
let timer0 = dp.TIMER0;
let mut pwm_t0 = PwmTimer::<TIMER0, NoRemap>::new(
timer0, (None, Some(&pa9), Some(&pa10), None), &mut rcu, &mut afio);
let max = pwm_t0.get_max_duty();
pwm_t0.set_period(100.hz());
pwm_t0.set_duty(Channel::CH0, max / 4); // 25% duty cycle
pwm_t0.enable(Channel::CH0);
Implementations
Trait Implementations
Returns the current PWM period
Returns the maximum duty cycle value
Sets a new PWM period
Returns the current PWM period
Returns the maximum duty cycle value
Sets a new PWM period
Returns the current PWM period
Returns the maximum duty cycle value
Sets a new PWM period
Returns the current PWM period
Returns the maximum duty cycle value
Sets a new PWM period
Returns the current PWM period
Returns the maximum duty cycle value
Sets a new PWM period