High level interface for interacting with the Cypress PWM.
This block is able to create arbitrary square waves based off of an input clock. It can also be used to control the brightness of an LED by manipulating the duty cycle.
|
| enum | cyhal_pwm_event_t { CYHAL_PWM_IRQ_NONE = 0,
CYHAL_PWM_IRQ_TERMINAL_COUNT = 1 << 0,
CYHAL_PWM_IRQ_CAPTURE_COMPARE = 1 << 1,
CYHAL_PWM_IRQ_ALL = (1 << 2) - 1
} |
| |
|
| cy_rslt_t | cyhal_pwm_init (cyhal_pwm_t *obj, cyhal_gpio_t pin, const cyhal_clock_divider_t *clk) |
| |
| void | cyhal_pwm_free (cyhal_pwm_t *obj) |
| |
| cy_rslt_t | cyhal_pwm_set_period (cyhal_pwm_t *obj, uint32_t period_us, uint32_t pulse_width_us) |
| |
| cy_rslt_t | cyhal_pwm_set_duty_cycle (cyhal_pwm_t *obj, float duty_cycle, uint32_t frequencyhal_hz) |
| |
| cy_rslt_t | cyhal_pwm_start (cyhal_pwm_t *obj) |
| |
| cy_rslt_t | cyhal_pwm_stop (cyhal_pwm_t *obj) |
| |
| void | cyhal_pwm_register_callback (cyhal_pwm_t *obj, cyhal_pwm_event_callback_t callback, void *callback_arg) |
| |
| void | cyhal_pwm_enable_event (cyhal_pwm_t *obj, cyhal_pwm_event_t event, uint8_t intrPriority, bool enable) |
| |
◆ CYHAL_PWM_RSLT_BAD_ARGUMENT
◆ CYHAL_PWM_RSLT_FAILED_CLOCK_INIT
Failed to initialize PWM clock
◆ CYHAL_PWM_RSLT_FAILED_INIT
◆ cyhal_pwm_event_callback_t
| typedef void(* cyhal_pwm_event_callback_t) (void *callback_arg, cyhal_pwm_event_t event) |
Handler for PWM interrupts
◆ cyhal_pwm_event_t
◆ cyhal_pwm_init()
Initialize the PWM out peripheral and configure the pin
- Parameters
-
| [out] | obj | The PWM object to initialize |
| [in] | pin | The PWM pin to initialize |
| [in] | clk | The clock to use can be shared, if not provided a new clock will be allocated |
- Returns
- The status of the init request
◆ cyhal_pwm_free()
Deinitialize the PWM object
- Parameters
-
| [in,out] | obj | The PWM object |
◆ cyhal_pwm_set_period()
Set the number of microseconds for the PWM period & pulse width
- Parameters
-
| [in] | obj | The PWM object |
| [in] | period_us | The period in microseconds |
| [in] | pulse_width_us | The pulse width in microseconds |
- Returns
- The status of the period request
◆ cyhal_pwm_set_duty_cycle()
| cy_rslt_t cyhal_pwm_set_duty_cycle |
( |
cyhal_pwm_t * |
obj, |
|
|
float |
duty_cycle, |
|
|
uint32_t |
frequencyhal_hz |
|
) |
| |
Set the PWM pulsewidth specified in microseconds, keeping the period the same.
- Parameters
-
| [in] | obj | The PWM object |
| [in] | duty_cycle | The percentage of time the output is high |
| [in] | frequencyhal_hz | The frequency of the PWM |
- Returns
- The status of the pulsewidth request
◆ cyhal_pwm_start()
Starts the PWM with the provided period and pulsewidth
- Parameters
-
- Returns
- The status of the start request
◆ cyhal_pwm_stop()
Stops the PWM from running
- Parameters
-
- Returns
- The status of the stop request
◆ cyhal_pwm_register_callback()
The PWM interrupt handler registration
- Parameters
-
| [in] | obj | The PWM object |
| [in] | callback | The callback handler which will be invoked when the event occurs |
| [in] | callback_arg | Generic argument that will be provided to the callback when called |
◆ cyhal_pwm_enable_event()
Configure PWM event enablement.
- Parameters
-
| [in] | obj | The PWM object |
| [in] | event | The PWM event type |
| [in] | intrPriority | The priority for NVIC interrupt events |
| [in] | enable | True to turn on events, False to turn off |