![]() |
nrfx 4.5.0
|
Pulse Width Modulation (PWM) peripheral driver. More...
Topics | |
| PWM peripheral driver configuration | |
Data Structures | |
| struct | nrfx_pwm_config_t |
| PWM driver configuration structure. More... | |
| struct | nrfx_pwm_t |
| PWM driver instance data structure. More... | |
Macros | |
| #define | NRFX_PWM_DEFAULT_CONFIG(_out_0, _out_1, _out_2, _out_3) |
| PWM driver default configuration. | |
| #define | NRFX_PWM_INSTANCE(reg) |
| Macro for creating a PWM driver instance. | |
Typedefs | |
| typedef void(* | nrfx_pwm_event_handler_t) (nrfx_pwm_event_type_t event_type, void *p_context) |
| PWM event handler type for user-defined callback function. | |
Enumerations | |
| enum | nrfx_pwm_flag_t { NRFX_PWM_FLAG_STOP = 0x01 , NRFX_PWM_FLAG_LOOP = 0x02 , NRFX_PWM_FLAG_SIGNAL_END_SEQ0 = 0x04 , NRFX_PWM_FLAG_SIGNAL_END_SEQ1 = 0x08 , NRFX_PWM_FLAG_NO_EVT_FINISHED = 0x10 , NRFX_PWM_FLAG_START_VIA_TASK = 0x80 } |
| PWM flags providing additional playback options. More... | |
| enum | nrfx_pwm_event_type_t { NRFX_PWM_EVENT_FINISHED , NRFX_PWM_EVENT_END_SEQ0 , NRFX_PWM_EVENT_END_SEQ1 , NRFX_PWM_EVENT_STOPPED } |
| PWM driver event type. More... | |
Functions | |
| int | nrfx_pwm_init (nrfx_pwm_t *p_instance, nrfx_pwm_config_t const *p_config, nrfx_pwm_event_handler_t handler, void *p_context) |
| Function for initializing the PWM driver. | |
| int | nrfx_pwm_reconfigure (nrfx_pwm_t const *p_instance, nrfx_pwm_config_t const *p_config) |
| Function for reconfiguring the PWM driver. | |
| void | nrfx_pwm_uninit (nrfx_pwm_t *p_instance) |
| Function for uninitializing the PWM driver. | |
| bool | nrfx_pwm_init_check (nrfx_pwm_t const *p_instance) |
| Function for checking if the PWM driver instance is initialized. | |
| uint32_t | nrfx_pwm_simple_playback (nrfx_pwm_t *p_instance, nrf_pwm_sequence_t const *p_sequence, uint16_t playback_count, uint32_t flags) |
| Function for starting a single sequence playback. | |
| uint32_t | nrfx_pwm_complex_playback (nrfx_pwm_t *p_instance, nrf_pwm_sequence_t const *p_sequence_0, nrf_pwm_sequence_t const *p_sequence_1, uint16_t playback_count, uint32_t flags) |
| Function for starting a two-sequence playback. | |
| NRFX_STATIC_INLINE void | nrfx_pwm_step (nrfx_pwm_t const *p_instance) |
| Function for advancing the active sequence. | |
| bool | nrfx_pwm_stop (nrfx_pwm_t *p_instance, bool wait_until_stopped) |
| Function for stopping the sequence playback. | |
| bool | nrfx_pwm_stopped_check (nrfx_pwm_t *p_instance) |
| Function for checking the status of the PWM peripheral. | |
| void | nrfx_pwm_irq_handler (nrfx_pwm_t *p_instance) |
| Driver interrupt handler. | |
| NRFX_STATIC_INLINE void | nrfx_pwm_sequence_update (nrfx_pwm_t const *p_instance, uint8_t seq_id, nrf_pwm_sequence_t const *p_sequence) |
| Function for updating the sequence data during playback. | |
| NRFX_STATIC_INLINE uint32_t | nrfx_pwm_task_address_get (nrfx_pwm_t const *p_instance, nrf_pwm_task_t task) |
| Function for returning the address of a specified PWM task that can be used in PPI module. | |
| NRFX_STATIC_INLINE uint32_t | nrfx_pwm_event_address_get (nrfx_pwm_t const *p_instance, nrf_pwm_event_t event) |
| Function for returning the address of a specified PWM event that can be used in PPI module. | |
Pulse Width Modulation (PWM) peripheral driver.
| #define NRFX_PWM_DEFAULT_CONFIG | ( | _out_0, | |
| _out_1, | |||
| _out_2, | |||
| _out_3 ) |
PWM driver default configuration.
This configuration sets up PWM with the following options:
| [in] | _out_0 | PWM output 0 pin. |
| [in] | _out_1 | PWM output 1 pin. |
| [in] | _out_2 | PWM output 2 pin. |
| [in] | _out_3 | PWM output 3 pin. |
| #define NRFX_PWM_INSTANCE | ( | reg | ) |
Macro for creating a PWM driver instance.
PWM driver event type.
| enum nrfx_pwm_flag_t |
PWM flags providing additional playback options.
| Enumerator | |
|---|---|
| NRFX_PWM_FLAG_STOP | When the requested playback is finished, the peripheral will be stopped.
|
| NRFX_PWM_FLAG_LOOP | When the requested playback is finished, it will be started from the beginning. This flag is ignored if used together with NRFX_PWM_FLAG_STOP.
|
| NRFX_PWM_FLAG_SIGNAL_END_SEQ0 | The event handler is to be called when the last value from sequence 0 is loaded. |
| NRFX_PWM_FLAG_SIGNAL_END_SEQ1 | The event handler is to be called when the last value from sequence 1 is loaded. |
| NRFX_PWM_FLAG_NO_EVT_FINISHED | The playback finished event (enabled by default) is to be suppressed. |
| NRFX_PWM_FLAG_START_VIA_TASK | The playback must not be started directly by the called function. Instead, the function must only prepare it and return the address of the task to be triggered to start the playback. |
| uint32_t nrfx_pwm_complex_playback | ( | nrfx_pwm_t * | p_instance, |
| nrf_pwm_sequence_t const * | p_sequence_0, | ||
| nrf_pwm_sequence_t const * | p_sequence_1, | ||
| uint16_t | playback_count, | ||
| uint32_t | flags ) |
Function for starting a two-sequence playback.
Use the NRFX_PWM_FLAG_START_VIA_TASK flag if you want the playback to be only prepared by this function, and you want to start it later by triggering a task (using PPI for instance). The function will then return the address of the task to be triggered.
| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | p_sequence_0 | First sequence to be played back. |
| [in] | p_sequence_1 | Second sequence to be played back. |
| [in] | playback_count | Number of playbacks to be performed (must not be 0). |
| [in] | flags | Additional options. Pass any combination of playback flags, or 0 for default settings. |
| NRFX_STATIC_INLINE uint32_t nrfx_pwm_event_address_get | ( | nrfx_pwm_t const * | p_instance, |
| nrf_pwm_event_t | event ) |
Function for returning the address of a specified PWM event that can be used in PPI module.
| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | event | Requested event. |
| int nrfx_pwm_init | ( | nrfx_pwm_t * | p_instance, |
| nrfx_pwm_config_t const * | p_config, | ||
| nrfx_pwm_event_handler_t | handler, | ||
| void * | p_context ) |
Function for initializing the PWM driver.
| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | p_config | Pointer to the structure with the initial configuration. NULL if configuration is to be skipped and will be done later using nrfx_pwm_reconfigure. |
| [in] | handler | Event handler provided by the user. If NULL is passed instead, event notifications are not done and PWM interrupts are disabled. |
| [in] | p_context | Context passed to the event handler. |
| 0 | Initialization was successful. |
| -EALREADY | The driver is already initialized. |
| bool nrfx_pwm_init_check | ( | nrfx_pwm_t const * | p_instance | ) |
Function for checking if the PWM driver instance is initialized.
| [in] | p_instance | Pointer to the driver instance structure. |
| true | Instance is already initialized. |
| false | Instance is not initialized. |
| void nrfx_pwm_irq_handler | ( | nrfx_pwm_t * | p_instance | ) |
Driver interrupt handler.
| [in] | p_instance | Pointer to the driver instance structure. |
| int nrfx_pwm_reconfigure | ( | nrfx_pwm_t const * | p_instance, |
| nrfx_pwm_config_t const * | p_config ) |
Function for reconfiguring the PWM driver.
| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | p_config | Pointer to the structure with the configuration. |
| 0 | Reconfiguration was successful. |
| -EBUSY | The driver is during playback. |
| -EINPROGRESS | The driver is uninitialized. |
| NRFX_STATIC_INLINE void nrfx_pwm_sequence_update | ( | nrfx_pwm_t const * | p_instance, |
| uint8_t | seq_id, | ||
| nrf_pwm_sequence_t const * | p_sequence ) |
Function for updating the sequence data during playback.
| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | seq_id | Identifier of the sequence (0 or 1). |
| [in] | p_sequence | Pointer to the new sequence definition. |
| uint32_t nrfx_pwm_simple_playback | ( | nrfx_pwm_t * | p_instance, |
| nrf_pwm_sequence_t const * | p_sequence, | ||
| uint16_t | playback_count, | ||
| uint32_t | flags ) |
Function for starting a single sequence playback.
To take advantage of the looping mechanism in the PWM peripheral, both sequences must be used (single sequence can be played back only once by the peripheral). Therefore, the provided sequence is internally set and played back as both sequence 0 and sequence 1. Consequently, if the end of sequence notifications are required, events for both sequences must be used (that is, both the NRFX_PWM_FLAG_SIGNAL_END_SEQ0 flag and the NRFX_PWM_FLAG_SIGNAL_END_SEQ1 flag must be specified, and the NRFX_PWM_EVENT_END_SEQ0 event and the NRFX_PWM_EVENT_END_SEQ1 event must be handled in the same way).
Use the NRFX_PWM_FLAG_START_VIA_TASK flag if you want the playback to be only prepared by this function, and you want to start it later by triggering a task (for example, by using PPI). The function will then return the address of the task to be triggered.
| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | p_sequence | Sequence to be played back. |
| [in] | playback_count | Number of playbacks to be performed (must not be 0). |
| [in] | flags | Additional options. Pass any combination of playback flags, or 0 for default settings. |
| NRFX_STATIC_INLINE void nrfx_pwm_step | ( | nrfx_pwm_t const * | p_instance | ) |
Function for advancing the active sequence.
This function only applies to NRF_PWM_STEP_TRIGGERED mode.
| [in] | p_instance | Pointer to the driver instance structure. |
| bool nrfx_pwm_stop | ( | nrfx_pwm_t * | p_instance, |
| bool | wait_until_stopped ) |
Function for stopping the sequence playback.
The playback is stopped at the end of the current PWM period. This means that if the active sequence is configured to repeat each duty cycle value for a certain number of PWM periods, the last played value might appear on the output less times than requested.
wait_until_stopped to true). Depending on the length of the PMW period, this might take a significant amount of time. Alternatively, the nrfx_pwm_stopped_check function can be used to poll the status, or the NRFX_PWM_EVENT_STOPPED event can be used to get the notification when the playback is stopped, provided the event handler is defined.| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | wait_until_stopped | If true, the function will not return until the playback is stopped. |
| true | The PWM peripheral is stopped. |
| false | The PWM peripheral is not stopped. |
| bool nrfx_pwm_stopped_check | ( | nrfx_pwm_t * | p_instance | ) |
Function for checking the status of the PWM peripheral.
| [in] | p_instance | Pointer to the driver instance structure. |
| true | The PWM peripheral is stopped. |
| false | The PWM peripheral is not stopped. |
| NRFX_STATIC_INLINE uint32_t nrfx_pwm_task_address_get | ( | nrfx_pwm_t const * | p_instance, |
| nrf_pwm_task_t | task ) |
Function for returning the address of a specified PWM task that can be used in PPI module.
| [in] | p_instance | Pointer to the driver instance structure. |
| [in] | task | Requested task. |
| void nrfx_pwm_uninit | ( | nrfx_pwm_t * | p_instance | ) |
Function for uninitializing the PWM driver.
If any sequence playback is in progress, it is stopped immediately.
| [in] | p_instance | Pointer to the driver instance structure. |