Functions to use Pulse Width Modulation (PWM).
Each of the 6 PWM channels (numbered 0..NUM_PWMS-1) can be linked to any mappable pin (e.g. green or color LEDs, buttons).
PWM can also be used through GPIO (see gpio.h and pinmap.h). Note that GPIO numbering (SWB_PWM0..SWB_PWM5) is then used instead of 0..NUM_PWMS-1 (PWM0..PWM5).
◆ pwm_index_t
Enum of PWM channels.
All functions use a PWM channel from 0..NUM_PWMS-1. Alternatively, you can use PWMi instead of just i if you find that clearer.
Enumerator |
---|
PWM0 | |
PWM1 | |
PWM2 | |
PWM3 | |
PWM4 | |
PWM5 | |
NUM_PWMS | |
Definition at line 47 of file pwm.h.
◆ pwm_destroy()
void pwm_destroy |
( |
const int |
pwm | ) |
|
|
extern |
Removes the instantiated shared memory system of the PWM channel.
- Parameters
-
pwm | The PWM channel to destroy. |
- Warning
- Fails with program exit if pwm is outside valid range.
Definition at line 72 of file pwm.c.
◆ pwm_get_duty_cycle()
uint32_t pwm_get_duty_cycle |
( |
const int |
pwm | ) |
|
|
extern |
Gets the duty cycle of the specified PWM channel.
- Parameters
-
- Returns
- The duty cycle of the specified PWM channel.
- Warning
- Fails with program exit if pwm is outside valid range or if pwm has not been initialized.
Definition at line 78 of file pwm.c.
◆ pwm_get_period()
uint32_t pwm_get_period |
( |
const int |
pwm | ) |
|
Returns the period of a certain PWM channel.
- Parameters
-
- Returns
- The period of the specified PWM channel as an uint32_t.
- Warning
- Fails with program exit if pwm is outside valid range or if pwm has not been initialized.
Definition at line 83 of file pwm.c.
◆ pwm_get_steps()
uint32_t pwm_get_steps |
( |
const int |
pwm | ) |
|
|
extern |
Get the number of steps a certain channel has taken so far.
- Parameters
-
- Returns
- The number of steps that have been taken; 0 is off and -1 is continous.
- Warning
- Fails with program exit if pwm is outside valid range or if pwm has not been initialized.
Definition at line 98 of file pwm.c.
◆ pwm_init()
void pwm_init |
( |
const int |
pwm, |
|
|
const uint32_t |
period |
|
) |
| |
|
extern |
Initializes the PWM channel with the specified period.
- Parameters
-
pwm | the PWM channel to initialize. |
period | The period to set for the PWM channel. |
- Warning
- Fails with program exit if pwm is outside valid range.
Definition at line 61 of file pwm.c.
◆ pwm_initialized()
bool pwm_initialized |
( |
const int |
pwm | ) |
|
|
extern |
Checks if the channel index is initialized.
- Parameters
-
- Returns
- True if initialized, false if not
- Warning
- Fails with program exit if pwm is outside valid range.
Definition at line 38 of file pwm.c.
◆ pwm_set_duty_cycle()
void pwm_set_duty_cycle |
( |
const int |
pwm, |
|
|
const uint32_t |
duty |
|
) |
| |
|
extern |
Sets the duty cycle for the specified PWM channel.
- Parameters
-
pwm | The PWM channel. |
duty | The duty cycle to set for the PWM channel. |
- Warning
- Fails with program exit if pwm is outside valid range or if pwm has not been initialized.
Definition at line 93 of file pwm.c.
◆ pwm_set_period()
void pwm_set_period |
( |
const int |
pwm, |
|
|
const uint32_t |
period |
|
) |
| |
|
extern |
Sets the period for the specified PWM channel.
- Parameters
-
pwm | The PWM channel. |
period | The period to set for the PWM channel. |
- Warning
- Fails with program exit if pwm is outside valid range or if pwm has not been initialized.
Definition at line 88 of file pwm.c.
◆ pwm_set_steps()
void pwm_set_steps |
( |
const int |
pwm, |
|
|
const uint32_t |
steps |
|
) |
| |
|
extern |
Generates steps steps on the PWM channel.
- Parameters
-
pwm | The PWM channel. |
steps | The number of steps to cycle, 0 to turn off and -1 to run continously. |
- Warning
- Fails with program exit if pwm is outside valid range or if pwm has not been initialized.
Definition at line 103 of file pwm.c.