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 | ) |
|
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 4 of file pwm.c.
◆ pwm_get_duty_cycle()
uint32_t pwm_get_duty_cycle |
( |
const int |
pwm | ) |
|
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 8 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 7 of file pwm.c.
◆ pwm_get_steps()
uint32_t pwm_get_steps |
( |
const int |
pwm | ) |
|
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 10 of file pwm.c.
◆ pwm_init()
void pwm_init |
( |
const int |
pwm, |
|
|
const uint32_t |
period |
|
) |
| |
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 3 of file pwm.c.
◆ pwm_initialized()
bool pwm_initialized |
( |
const int |
pwm | ) |
|
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 2 of file pwm.c.
◆ pwm_set_duty_cycle()
void pwm_set_duty_cycle |
( |
const int |
pwm, |
|
|
const uint32_t |
duty |
|
) |
| |
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 5 of file pwm.c.
◆ pwm_set_period()
void pwm_set_period |
( |
const int |
pwm, |
|
|
const uint32_t |
period |
|
) |
| |
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 6 of file pwm.c.
◆ pwm_set_steps()
void pwm_set_steps |
( |
const int |
pwm, |
|
|
const uint32_t |
steps |
|
) |
| |
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 9 of file pwm.c.