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

Enumeration of channels that can be used with this Pwm interface Read more

A time unit that can be converted into a human time unit (e.g. seconds)

Type for the duty methods Read more

Disables a PWM channel

Enables a PWM channel

Returns the current PWM period

Returns the current duty cycle

Returns the maximum duty cycle value

Sets a new duty cycle

Sets a new PWM period

Enumeration of channels that can be used with this Pwm interface Read more

A time unit that can be converted into a human time unit (e.g. seconds)

Type for the duty methods Read more

Disables a PWM channel

Enables a PWM channel

Returns the current PWM period

Returns the current duty cycle

Returns the maximum duty cycle value

Sets a new duty cycle

Sets a new PWM period

Enumeration of channels that can be used with this Pwm interface Read more

A time unit that can be converted into a human time unit (e.g. seconds)

Type for the duty methods Read more

Disables a PWM channel

Enables a PWM channel

Returns the current PWM period

Returns the current duty cycle

Returns the maximum duty cycle value

Sets a new duty cycle

Sets a new PWM period

Enumeration of channels that can be used with this Pwm interface Read more

A time unit that can be converted into a human time unit (e.g. seconds)

Type for the duty methods Read more

Disables a PWM channel

Enables a PWM channel

Returns the current PWM period

Returns the current duty cycle

Returns the maximum duty cycle value

Sets a new duty cycle

Sets a new PWM period

Enumeration of channels that can be used with this Pwm interface Read more

A time unit that can be converted into a human time unit (e.g. seconds)

Type for the duty methods Read more

Disables a PWM channel

Enables a PWM channel

Returns the current PWM period

Returns the current duty cycle

Returns the maximum duty cycle value

Sets a new duty cycle

Sets a new PWM period

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.