Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Enumerations | Functions
PWM

PWM (Pulse-width modulation) API for Soletta. More...

Data Structures

struct  sol_pwm_config
 PWM configuration struct. More...
 

Typedefs

typedef struct sol_pwm sol_pwm
 A handle to a PWM. More...
 
typedef struct sol_pwm_config sol_pwm_config
 PWM configuration struct. More...
 

Enumerations

enum  sol_pwm_alignment { SOL_PWM_ALIGNMENT_LEFT, SOL_PWM_ALIGNMENT_RIGHT, SOL_PWM_ALIGNMENT_CENTER }
 Alignment determines how the pulse is aligned within the PWM period. More...
 
enum  sol_pwm_polarity { SOL_PWM_POLARITY_NORMAL, SOL_PWM_POLARITY_INVERSED }
 Polarity is whether the output is active-high or active-low. More...
 

Functions

enum sol_pwm_alignment sol_pwm_alignment_from_str (const char *pwm_alignment)
 Converts a string PWM alignment to sol_pwm_alignment. More...
 
const char * sol_pwm_alignment_to_str (enum sol_pwm_alignment pwm_alignment)
 Converts sol_pwm_alignment to a string name. More...
 
void sol_pwm_close (struct sol_pwm *pwm)
 Closes a given PWM pin. More...
 
int32_t sol_pwm_get_duty_cycle (const struct sol_pwm *pwm)
 Get PWM duty cycle in nanoseconds. More...
 
int32_t sol_pwm_get_period (const struct sol_pwm *pwm)
 Get PWM period in nanoseconds. More...
 
bool sol_pwm_is_enabled (const struct sol_pwm *pwm)
 Check wheter a pmw pin is enabled or disabled. More...
 
struct sol_pwmsol_pwm_open (int device, int channel, const struct sol_pwm_config *config)
 Opens a given pin as pwm. More...
 
struct sol_pwmsol_pwm_open_by_label (const char *label, const struct sol_pwm_config *config)
 Opens a given pin by its board label as pwm. More...
 
struct sol_pwmsol_pwm_open_raw (int device, int channel, const struct sol_pwm_config *config)
 Opens a given pin as pwm. More...
 
enum sol_pwm_polarity sol_pwm_polarity_from_str (const char *pwm_polarity)
 Converts a string PWM polarity to sol_pwm_polarity. More...
 
const char * sol_pwm_polarity_to_str (enum sol_pwm_polarity pwm_polarity)
 Converts sol_pwm_polarity to a string name. More...
 
int sol_pwm_set_duty_cycle (struct sol_pwm *pwm, uint32_t duty_cycle_ns)
 Set PWM duty cycle in nanoseconds. More...
 
int sol_pwm_set_enabled (struct sol_pwm *pwm, bool enable)
 Enable or disable a given pwm pin. More...
 
int sol_pwm_set_period (struct sol_pwm *pwm, uint32_t period_ns)
 Set PWM period in nanoseconds. More...
 

Detailed Description

PWM (Pulse-width modulation) API for Soletta.

Typedef Documentation

PWM configuration struct.

See Also
sol_pwm_open_by_label()
sol_pwm_open()
sol_pwm_open_raw()

Enumeration Type Documentation

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 

Function Documentation

enum sol_pwm_alignment sol_pwm_alignment_from_str ( const char *  pwm_alignment)

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_alignmentValid values are "left", "center", "right".
Returns
enumeration sol_pwm_alignment
const char* sol_pwm_alignment_to_str ( enum sol_pwm_alignment  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_alignmentsol_pwm_alignment
Returns
String representation of the sol_pwm_alignment
void sol_pwm_close ( struct sol_pwm pwm)

Closes a given PWM pin.

See Also
sol_pwm_open(), sol_pwm_open_raw().
Parameters
pwmThe open sol_pwm representing the pin to be closed.
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
pwmPWM 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
pwmPWM 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
pwmPWM pin to get property.
Returns
true if enabled or false if disabled or on error.
struct sol_pwm* sol_pwm_open ( int  device,
int  channel,
const struct sol_pwm_config config 
)

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
deviceThe device controlling the pin to be opened.
channelThe channel used to communicate with the pin to be opened.
configContains the pin configuration.
Returns
A new sol_pwm instance on success, NULL otherwise.
struct sol_pwm* sol_pwm_open_by_label ( const char *  label,
const struct sol_pwm_config config 
)

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
labelThe pin to be opened.
configContains the pin configuration.
Returns
A new sol_pwm instance on success, NULL otherwise.
struct sol_pwm* sol_pwm_open_raw ( int  device,
int  channel,
const struct sol_pwm_config config 
)

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
deviceThe device controlling the pin to be opened.
channelThe channel used to communicate with the pin to be opened.
configContains the pin configuration.
Returns
A new sol_pwm instance on success, NULL otherwise.
enum sol_pwm_polarity sol_pwm_polarity_from_str ( const char *  pwm_polarity)

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_polarityValid values are "normal", "inversed".
Returns
enumeration sol_pwm_polarity
const char* sol_pwm_polarity_to_str ( enum sol_pwm_polarity  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_polaritysol_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
pwmPWM pin to be modified.
duty_cycle_nsDuty 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
pwmPWM pin to be modified.
enableIf 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
pwmPWM pin to be modified.
period_nsPeriod in nanoseconds.
Returns
0 on success or a negative number on error.