1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::output::PwmPrescaler;
#[derive(Debug, PartialEq, Eq, Default, Clone, Copy)]
pub enum PwmConfig {
/// PWM is deactivated
#[default]
Deactivated,
Servo {
channel_a: bool,
channel_b: bool,
},
/// A duty cycle group can set individual duty cycles for channel A and B, but they share the
/// same frequency.
/// It can be configured with a prescaler and a frequency. The
/// prescaler determines the base frequency of the PWM signal, the frequency then sets the
/// fine-grained frequency of the PWM signal with the following formula:
/// `frequency = prescaler / 2 / frequency`
///
/// # Example
/// Target frequency: `1 Hz`
/// 1 Hz = PwmPrescaler::Prescale62_5kHz / 2 / 31250
DutyCycle {
prescaler: PwmPrescaler,
frequency: u16,
channel_a: bool,
channel_b: bool,
},
/// A universal group can only configure frequency and duty cycle of channel A, while channel B
/// always has 50% duty cycle and half the frequency of channel A.
/// It can be configured with a prescaler and a frequency. The
/// prescaler determines the base frequency of the PWM signal, the frequency then sets the
/// fine-grained frequency of the PWM signal with the following formula:
/// `frequency = prescaler / 2 / frequency`
///
/// # Example
/// Target frequency channel A: `1 Hz`
/// 1 Hz = PwmPrescaler::Prescale62_5kHz / 2 / 31250
/// => Channel B frequency: 0.5 Hz
Universal {
prescaler: PwmPrescaler,
frequency: u16,
duty_cycle: u16,
channel_a: bool,
channel_b: bool,
},
/// A frequency group can set individual frequencies for channel A and B, but they both have a
/// duty cycle of 50%. The prescaler determines the base frequency of the PWM signal. The
/// maximum frequency that can be set for the individual channels after the configuration is `20kHz`.
Frequency {
prescaler: PwmPrescaler,
channel_a: bool,
channel_b: bool,
},
}