pwm.h File Reference
#include "pico.h"
#include "hardware/structs/pwm.h"
#include "hardware/regs/dreq.h"
Include dependency graph for pwm.h:

Go to the source code of this file.

Data Structures

struct  pwm_config
 

Macros

#define PARAM_ASSERTIONS_ENABLED_PWM   0
 

Enumerations

enum  pwm_clkdiv_mode { PWM_DIV_FREE_RUNNING = 0, PWM_DIV_B_HIGH = 1, PWM_DIV_B_RISING = 2, PWM_DIV_B_FALLING = 3 }
 PWM Divider mode settings. More...
 
enum  pwm_chan { PWM_CHAN_A = 0, PWM_CHAN_B = 1 }
 

Functions

static void check_slice_num_param (__unused uint slice_num)
 
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 PWM clock divider in a PWM configuration. More...
 
static void pwm_config_set_clkdiv_int_frac (pwm_config *c, uint8_t integer, uint8_t fract)
 Set PWM clock divider in a PWM configuration using an 8:4 fractional value. 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...