PWM (Pulse-width modulation) API for Soletta.
More...
PWM (Pulse-width modulation) API for Soletta.
Alignment determines how the pulse is aligned within the PWM period.
No API for this on Linux (and other OSes), so we simply ignore it there
Enumerator |
---|
SOL_PWM_ALIGNMENT_LEFT |
The pulse is aligned to the leading-edge (left) of the PWM period.
|
SOL_PWM_ALIGNMENT_RIGHT |
The pulse is aligned to the trailing-edge (right) of the PWM period.
|
SOL_PWM_ALIGNMENT_CENTER |
The pulse is aligned to the center of the PWM period.
Also known as phase-correct.
|
Polarity is whether the output is active-high or active-low.
In the paired and complementary configurations, the polarity of the secondary PWM output is determined by the polarity of the primary PWM channel.
This is ignored on RIOT (no API there) and not always supported on Linux.
Enumerator |
---|
SOL_PWM_POLARITY_NORMAL |
|
SOL_PWM_POLARITY_INVERSED |
|
Converts a string PWM alignment to sol_pwm_alignment.
This function converts a string PWM alignment to enumeration sol_pwm_alignment.
- See Also
- sol_pwm_alignment_to_str().
- Parameters
-
pwm_alignment | Valid values are "left", "center", "right". |
- Returns
- enumeration sol_pwm_alignment
Converts sol_pwm_alignment to a string name.
This function converts sol_pwm_alignment enumeration to a string PWM alignment.
- See Also
- sol_pwm_alignment_from_str().
- Parameters
-
pwm_alignment | sol_pwm_alignment |
- Returns
- String representation of the sol_pwm_alignment
void sol_pwm_close |
( |
struct sol_pwm * |
pwm | ) |
|
int32_t sol_pwm_get_duty_cycle |
( |
const struct sol_pwm * |
pwm | ) |
|
Get PWM duty cycle in nanoseconds.
- See Also
- sol_pwm_set_duty_cycle() for more details.
- Parameters
-
pwm | PWM pin to get property. |
- Returns
- Duty cycle in nanoseconds. It may be a negative value on error.
int32_t sol_pwm_get_period |
( |
const struct sol_pwm * |
pwm | ) |
|
Get PWM period in nanoseconds.
- See Also
- sol_pwm_set_period() for more details.
- Parameters
-
pwm | PWM pin to get property. |
- Returns
- Period in nanoseconds. It may be a negative value on error.
bool sol_pwm_is_enabled |
( |
const struct sol_pwm * |
pwm | ) |
|
Check wheter a pmw pin is enabled or disabled.
- Parameters
-
pwm | PWM pin to get property. |
- Returns
true
if enabled or false
if disabled or on error.
Opens a given pin as pwm.
A pin (defined by device and channel) should be opened just once, calling this function more than once for the same pin results in undefined behaviour - per platform basis.
- See Also
- sol_pwm_open_raw(), sol_pwm_close().
The difference between sol_pwm_open_raw() and sol_pwm_open() is that the last will setup pin mux, if enabled.
- Parameters
-
device | The device controlling the pin to be opened. |
channel | The channel used to communicate with the pin to be opened. |
config | Contains the pin configuration. |
- Returns
- A new
sol_pwm
instance on success, NULL
otherwise.
Opens a given pin by its board label as pwm.
This function only works when the board was successfully detected by Soletta and a corresponding pin multiplexer module was found.
A pin should be opened just once, calling this function more than once for the same pin results in undefined behavior - per platform basis.
- See Also
- sol_pwm_open_raw(), sol_pwm_close().
- Parameters
-
label | The pin to be opened. |
config | Contains the pin configuration. |
- Returns
- A new
sol_pwm
instance on success, NULL
otherwise.
Opens a given pin as pwm.
A pin (defined by device and channel) should be opened just once, calling this function more than once for the same pin results in undefined behaviour - per platform basis.
- See Also
- sol_pwm_open(), sol_pwm_close().
- Parameters
-
device | The device controlling the pin to be opened. |
channel | The channel used to communicate with the pin to be opened. |
config | Contains the pin configuration. |
- Returns
- A new
sol_pwm
instance on success, NULL
otherwise.
Converts a string PWM polarity to sol_pwm_polarity.
This function converts a string PWM polarity to enumeration sol_pwm_polarity.
- See Also
- sol_pwm_polarity_to_str().
- Parameters
-
pwm_polarity | Valid values are "normal", "inversed". |
- Returns
- enumeration sol_pwm_polarity
Converts sol_pwm_polarity to a string name.
This function converts sol_pwm_polarity enumeration to a string PWM polarity.
- See Also
- sol_pwm_polarity_from_str().
- Parameters
-
pwm_polarity | sol_pwm_polarity |
- Returns
- String representation of the sol_pwm_polarity
int sol_pwm_set_duty_cycle |
( |
struct sol_pwm * |
pwm, |
|
|
uint32_t |
duty_cycle_ns |
|
) |
| |
Set PWM duty cycle in nanoseconds.
Duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time.
A low duty cycle corresponds to low power, because the power is off for most of the time.
- Parameters
-
pwm | PWM pin to be modified. |
duty_cycle_ns | Duty cycle in nanoseconds. |
- Returns
0
on success or a negative number on error.
int sol_pwm_set_enabled |
( |
struct sol_pwm * |
pwm, |
|
|
bool |
enable |
|
) |
| |
Enable or disable a given pwm pin.
- Parameters
-
pwm | PWM pin to be modified. |
enable | If true pwm is enabled and if false it's disabled. |
- Returns
0
on success or a negative number on error.
int sol_pwm_set_period |
( |
struct sol_pwm * |
pwm, |
|
|
uint32_t |
period_ns |
|
) |
| |
Set PWM period in nanoseconds.
Period is the amount of time that a cycle (on / off state) takes. It's the inverse of the frequency of the waveform.
- Parameters
-
pwm | PWM pin to be modified. |
period_ns | Period in nanoseconds. |
- Returns
0
on success or a
negative number on error.