PWM Device Interface Functions More...
Go to the source code of this file.
Data Structures | |
struct | dif_pwm_config |
Runtime configuration for PWM. More... | |
struct | dif_pwm_channel_config |
Runtime configuration for a specific PWM channel. More... | |
Macros | |
#define | DIF_PWM_CHANNEL_LIST(X) |
Helper X macro for defining enums and case statements related to PWM channels. More... | |
#define | PWM_CHANNEL_ENUM_INIT_(channel_) kDifPwmChannel##channel_ = 1U << channel_, |
Helper macro for defining a dif_pwm_channel_t enumeration constant. More... | |
Typedefs | |
typedef enum dif_pwm_channel | dif_pwm_channel_t |
A PWM channel. | |
typedef struct dif_pwm_config | dif_pwm_config_t |
Runtime configuration for PWM. More... | |
typedef enum dif_pwm_mode | dif_pwm_mode_t |
A PWM channel mode. | |
typedef enum dif_pwm_polarity | dif_pwm_polarity_t |
A PWM channel polarity. | |
typedef struct dif_pwm_channel_config | dif_pwm_channel_config_t |
Runtime configuration for a specific PWM channel. More... | |
Enumerations | |
enum | dif_pwm_channel |
A PWM channel. | |
enum | dif_pwm_mode { kDifPwmModeFirmware = 0 , kDifPwmModeHeartbeat = 1 , kDifPwmModeBlink = 2 } |
A PWM channel mode. More... | |
enum | dif_pwm_polarity { kDifPwmPolarityActiveHigh = 0 , kDifPwmPolarityActiveLow = 1 } |
A PWM channel polarity. More... | |
Functions | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_configure (const dif_pwm_t *pwm, dif_pwm_config_t config) |
Configures "phase cycle" and "beat" durations of all PWM channels. More... | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_configure_channel (const dif_pwm_t *pwm, dif_pwm_channel_t channel, dif_pwm_channel_config_t config) |
Configures a single PWM channel. More... | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_phase_cntr_set_enabled (const dif_pwm_t *pwm, dif_toggle_t enabled) |
Sets the enablement state of the PWM phase counter, which controls the enablement of all PWM channels. More... | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_phase_cntr_get_enabled (const dif_pwm_t *pwm, dif_toggle_t *is_enabled) |
Gets the enablement state of the PWM phase counter, which controls the enablement of all PWM channels. More... | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_channel_set_enabled (const dif_pwm_t *pwm, uint32_t channels, dif_toggle_t enabled) |
Sets the enablement states of one or more PWM channels. More... | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_channel_get_enabled (const dif_pwm_t *pwm, dif_pwm_channel_t channel, dif_toggle_t *is_enabled) |
Gets the enablement state of one PWM channel. More... | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_lock (const dif_pwm_t *pwm) |
Locks PWM configurations. More... | |
OT_WARN_UNUSED_RESULT dif_result_t | dif_pwm_is_locked (const dif_pwm_t *pwm, bool *is_locked) |
Checks whether PWM configurations are locked. More... | |
PWM Device Interface Functions
The PWM block contains a 16-bit "phase counter" that controls each channel's output signal. The "phase counter" acts as a point of reference for a single PWM "pulse cycle", that is further broken into "beats", depending on the beats_per_cycle
parameter. Specifically, a "pulse cycle" may contain [2, 2^16] "beats". Within a "pulse cycle", users can configure the duty cycle in number of "beats". Additionally, the duration of a single "beat", is computed by dividing the core clock frequency by clock_divisor + 1
.
PWM "pulse cycle" defined by 16-bit phase counter
| | v v |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| ... |-|-|-|-|
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| ... |-|-|-|-| min beat size = 1 phase counter tick --> 2^16 "beats" / "pulse cycle"
|-------------------------------------------— ... | ... –| max beat size = 2^15 phase counter ticks --> 2 "beats" / "pulse cycle"
Definition in file dif_pwm.h.
struct dif_pwm_config |
Runtime configuration for PWM.
This struct describes runtime configuration for one-time configuration of the PWM "pulse cycle" and "beat" durations that impact all PWM channels.
struct dif_pwm_channel_config |
Runtime configuration for a specific PWM channel.
This struct describes runtime configuration for one-time configuration of a specific PWM channel.
Data Fields | ||
---|---|---|
uint16_t | blink_parameter_x |
One of two blink parameters that only impact the "Heartbeat" and "Blink" operation modes. The meaning of this parameter is different based on the operation mode:
|
uint16_t | blink_parameter_y |
One of two blink parameters that only impact the "Heartbeat" and "Blink" operation modes. The meaning of this parameter is different based on the operation mode:
Note: the raw value written to the |
uint16_t | duty_cycle_a |
Primary duty cycle, in number of "beats" / "pulse cycle". Valid range: [0, beats_per_pulse_cycle) Note: the raw value written to the |
uint16_t | duty_cycle_b |
Secondary duty cycle, in number of "beats" / "pulse cycle", that is only relevant in heartbeat and blink modes. Valid range: [0, beats_per_pulse_cycle) Note: above notes for |
dif_pwm_mode_t | mode |
The operation mode to configure the channel in, see dif_pwm_mode_t . |
uint16_t | phase_delay |
Phase delay at the beginning of a "pulse cycle" to delay the active duty cycle "beats" for, in number of "beats". Valid range: [0, beats_per_pulse_cycle) |
dif_pwm_polarity_t | polarity |
The polarity to configure the channel in, see dif_pwm_polarity_t . |
#define DIF_PWM_CHANNEL_LIST | ( | X | ) |
#define PWM_CHANNEL_ENUM_INIT_ | ( | channel_ | ) | kDifPwmChannel##channel_ = 1U << channel_, |
typedef struct dif_pwm_channel_config dif_pwm_channel_config_t |
Runtime configuration for a specific PWM channel.
This struct describes runtime configuration for one-time configuration of a specific PWM channel.
typedef struct dif_pwm_config dif_pwm_config_t |
Runtime configuration for PWM.
This struct describes runtime configuration for one-time configuration of the PWM "pulse cycle" and "beat" durations that impact all PWM channels.
enum dif_pwm_mode |
A PWM channel mode.
enum dif_pwm_polarity |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_channel_get_enabled | ( | const dif_pwm_t * | pwm, |
dif_pwm_channel_t | channel, | ||
dif_toggle_t * | is_enabled | ||
) |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_channel_set_enabled | ( | const dif_pwm_t * | pwm, |
uint32_t | channels, | ||
dif_toggle_t | enabled | ||
) |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_configure | ( | const dif_pwm_t * | pwm, |
dif_pwm_config_t | config | ||
) |
Configures "phase cycle" and "beat" durations of all PWM channels.
Since changes to CLK_DIV
and DC_RESN
are only allowed when the PWM is disabled, this function has the side effect of temporarily disabling all PWM channels while configurations are updated, before restoring the original enablement state.
This function should only need to be called once for the lifetime of handle
.
pwm | A PWM handle. |
config | Runtime configuration parameters. |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_configure_channel | ( | const dif_pwm_t * | pwm, |
dif_pwm_channel_t | channel, | ||
dif_pwm_channel_config_t | config | ||
) |
Configures a single PWM channel.
This function should only need to be called once for each PWM channel that will be used.
pwm | A PWM handle. |
channel | A PWM channel to configure. |
config | Runtime configuration parameters for the channel. |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_is_locked | ( | const dif_pwm_t * | pwm, |
bool * | is_locked | ||
) |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_lock | ( | const dif_pwm_t * | pwm | ) |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_phase_cntr_get_enabled | ( | const dif_pwm_t * | pwm, |
dif_toggle_t * | is_enabled | ||
) |
OT_WARN_UNUSED_RESULT dif_result_t dif_pwm_phase_cntr_set_enabled | ( | const dif_pwm_t * | pwm, |
dif_toggle_t | enabled | ||
) |