PebbleOS v4.47.0
Loading...
Searching...
No Matches
pwm.h File Reference
#include <stdint.h>
#include <pbl/device.h>
#include <pbl/util/bits.h>
#include <pbl/util/units.h>

Data Structures

struct  pbl_pwm_state
 Output state. More...
 
struct  pbl_pwm
 A channel, as used by a consumer. More...
 
struct  pbl_pwm_controller_ops
 PWM controller driver operations. More...
 
struct  pbl_pwm_controller
 A PWM controller. More...
 

Macros

#define PBL_PWM_USEC(us)   ((us) * (uint32_t)PBL_NSEC_PER_USEC)
 us microseconds, in nanoseconds.
 
#define PBL_PWM_MSEC(ms)   ((ms) * (uint32_t)PBL_NSEC_PER_MSEC)
 ms milliseconds, in nanoseconds.
 
#define PBL_PWM_HZ(hz)   ((uint32_t)PBL_NSEC_PER_SEC / (hz))
 Period of a hz Hz output, in nanoseconds.
 
#define PBL_PWM_POLARITY_INVERTED   PBL_BIT(0)
 Spec flag: the output is inverted.
 
#define PBL_PWM(_ctrl, _channel, _period, _flags)    {.ctrl = (_ctrl), .channel = (_channel), .period = (_period), .flags = (_flags)}
 Initializer for a struct pbl_pwm.
 
#define PBL_PWM_CONTROLLER_STATE_DEFINE(sym, _num_channels)
 Define the class state of PWM controller sym, for the driver's define macro.
 
#define PBL_PWM_CONTROLLER_INIT(sym, _name, _init, _deps, _ops)
 Initializer for the struct pbl_pwm_controller of controller sym.
 

Enumerations

enum  pbl_pwm_polarity { PBL_PWM_POLARITY_NORMAL , PBL_PWM_POLARITY_INVERSED }
 Output polarity. More...
 

Functions

void pbl_pwm_get_state (const struct pbl_pwm *pwm, struct pbl_pwm_state *state)
 Read the last applied state of a channel; disabled before the first one.
 
void pbl_pwm_init_state (const struct pbl_pwm *pwm, struct pbl_pwm_state *state)
 Prepare a state from the channel's spec.
 
int pbl_pwm_set_relative_duty_cycle (struct pbl_pwm_state *state, uint32_t duty, uint32_t scale)
 Set the duty cycle of a state to duty / scale of its period.
 
int pbl_pwm_apply (const struct pbl_pwm *pwm, const struct pbl_pwm_state *state)
 Apply a state to a channel.
 
int pbl_pwm_disable (const struct pbl_pwm *pwm)
 Disable a channel, keeping the rest of its state.
 

Variables

const struct pbl_device_class pbl_pwm_class
 Class of the PWM controllers.