|
static uint | pwm_gpio_to_slice_num (uint gpio) |
| Determine the PWM slice that is attached to the specified GPIO. More...
|
|
static uint | pwm_gpio_to_channel (uint gpio) |
| Determine the PWM channel that is attached to the specified GPIO. More...
|
|
static void | pwm_config_set_phase_correct (pwm_config *c, bool phase_correct) |
| Set phase correction in a PWM configuration. More...
|
|
static void | pwm_config_set_clkdiv (pwm_config *c, float div) |
| Set clock divider in a PWM configuration. More...
|
|
static void | pwm_config_set_clkdiv_int (pwm_config *c, uint div) |
| Set PWM clock divider in a PWM configuration. More...
|
|
static void | pwm_config_set_clkdiv_mode (pwm_config *c, enum pwm_clkdiv_mode mode) |
| Set PWM counting mode in a PWM configuration. More...
|
|
static void | pwm_config_set_output_polarity (pwm_config *c, bool a, bool b) |
| Set output polarity in a PWM configuration. More...
|
|
static void | pwm_config_set_wrap (pwm_config *c, uint16_t wrap) |
| Set PWM counter wrap value in a PWM configuration. More...
|
|
static void | pwm_init (uint slice_num, pwm_config *c, bool start) |
| Initialise a PWM with settings from a configuration object. More...
|
|
static pwm_config | pwm_get_default_config (void) |
| Get a set of default values for PWM configuration. More...
|
|
static void | pwm_set_wrap (uint slice_num, uint16_t wrap) |
| Set the current PWM counter wrap value. More...
|
|
static void | pwm_set_chan_level (uint slice_num, uint chan, uint16_t level) |
| Set the current PWM counter compare value for one channel. More...
|
|
static void | pwm_set_both_levels (uint slice_num, uint16_t level_a, uint16_t level_b) |
| Set PWM counter compare values. More...
|
|
static void | pwm_set_gpio_level (uint gpio, uint16_t level) |
| Helper function to set the PWM level for the slice and channel associated with a GPIO. More...
|
|
static uint16_t | pwm_get_counter (uint slice_num) |
| Get PWM counter. More...
|
|
static void | pwm_set_counter (uint slice_num, uint16_t c) |
| Set PWM counter. More...
|
|
static void | pwm_advance_count (uint slice_num) |
| Advance PWM count. More...
|
|
static void | pwm_retard_count (uint slice_num) |
| Retard PWM count. More...
|
|
static void | pwm_set_clkdiv_int_frac (uint slice_num, uint8_t integer, uint8_t fract) |
| Set PWM clock divider using an 8:4 fractional value. More...
|
|
static void | pwm_set_clkdiv (uint slice_num, float divider) |
| Set PWM clock divider. More...
|
|
static void | pwm_set_output_polarity (uint slice_num, bool a, bool b) |
| Set PWM output polarity. More...
|
|
static void | pwm_set_clkdiv_mode (uint slice_num, enum pwm_clkdiv_mode mode) |
| Set PWM divider mode. More...
|
|
static void | pwm_set_phase_correct (uint slice_num, bool phase_correct) |
| Set PWM phase correct on/off. More...
|
|
static void | pwm_set_enabled (uint slice_num, bool enabled) |
| Enable/Disable PWM. More...
|
|
static void | pwm_set_mask_enabled (uint32_t mask) |
| Enable/Disable multiple PWM slices simultaneously. More...
|
|
static void | pwm_set_irq_enabled (uint slice_num, bool enabled) |
| Enable PWM instance interrupt. More...
|
|
static void | pwm_set_irq_mask_enabled (uint32_t slice_mask, bool enabled) |
| Enable multiple PWM instance interrupts. More...
|
|
static void | pwm_clear_irq (uint slice_num) |
| Clear a single PWM channel interrupt. More...
|
|
static uint32_t | pwm_get_irq_status_mask (void) |
| Get PWM interrupt status, raw. More...
|
|
static void | pwm_force_irq (uint slice_num) |
| Force PWM interrupt. More...
|
|
static uint | pwm_get_dreq (uint slice_num) |
| Return the DREQ to use for pacing transfers to a particular PWM slice. More...
|
|
Hardware Pulse Width Modulation (PWM) API.
The RP2040 PWM block has 8 identical slices. Each slice can drive two PWM output signals, or measure the frequency or duty cycle of an input signal. This gives a total of up to 16 controllable PWM outputs. All 30 GPIOs can be driven by the PWM block.
The PWM hardware functions by continuously comparing the input value to a free-running counter. This produces a toggling output where the amount of time spent at the high output level is proportional to the input value. The fraction of time spent at the high signal level is known as the duty cycle of the signal.
int main() {
}
void gpio_set_function(uint gpio, enum gpio_function fn)
Select GPIO function.
Definition: gpio.c:10
static void pwm_set_chan_level(uint slice_num, uint chan, uint16_t level)
Set the current PWM counter compare value for one channel.
Definition: pwm.h:255
static void pwm_set_enabled(uint slice_num, bool enabled)
Enable/Disable PWM.
Definition: pwm.h:468
static void pwm_set_wrap(uint slice_num, uint16_t wrap)
Set the current PWM counter wrap value.
Definition: pwm.h:235
static uint pwm_gpio_to_slice_num(uint gpio)
Determine the PWM slice that is attached to the specified GPIO.
Definition: pwm.h:78
static void pwm_set_both_levels |
( |
uint |
slice_num, |
|
|
uint16_t |
level_a, |
|
|
uint16_t |
level_b |
|
) |
| |
|
inlinestatic |
Set PWM counter compare values.
Set the value of the PWM counter compare values, A and B.
The counter compare register is double-buffered in hardware. This means that, when the PWM is running, a write to the counter compare values does not take effect until the next time the PWM slice wraps (or, in phase-correct mode, the next time the slice reaches 0). If the PWM is not running, the write is latched in immediately.
- Parameters
-
slice_num | PWM slice number |
level_a | Value to set compare A to. When the counter reaches this value the A output is deasserted |
level_b | Value to set compare B to. When the counter reaches this value the B output is deasserted |
static void pwm_set_chan_level |
( |
uint |
slice_num, |
|
|
uint |
chan, |
|
|
uint16_t |
level |
|
) |
| |
|
inlinestatic |
Set the current PWM counter compare value for one channel.
Set the value of the PWM counter compare value, for either channel A or channel B.
The counter compare register is double-buffered in hardware. This means that, when the PWM is running, a write to the counter compare values does not take effect until the next time the PWM slice wraps (or, in phase-correct mode, the next time the slice reaches 0). If the PWM is not running, the write is latched in immediately.
- Parameters
-
slice_num | PWM slice number |
chan | Which channel to update. 0 for A, 1 for B. |
level | new level for the selected output |
static void pwm_set_gpio_level |
( |
uint |
gpio, |
|
|
uint16_t |
level |
|
) |
| |
|
inlinestatic |
Helper function to set the PWM level for the slice and channel associated with a GPIO.
Look up the correct slice (0 to 7) and channel (A or B) for a given GPIO, and update the corresponding counter compare field.
This PWM slice should already have been configured and set running. Also be careful of multiple GPIOs mapping to the same slice and channel (if GPIOs have a difference of 16).
The counter compare register is double-buffered in hardware. This means that, when the PWM is running, a write to the counter compare values does not take effect until the next time the PWM slice wraps (or, in phase-correct mode, the next time the slice reaches 0). If the PWM is not running, the write is latched in immediately.
- Parameters
-
gpio | GPIO to set level of |
level | PWM level for this GPIO |