PWM controller class.
More...
|
| #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, _parent, _ops) |
| | Initializer for the struct pbl_pwm_controller of controller sym.
|
| |
PWM controller class.
A PWM controller is a struct pbl_pwm_controller device with numbered channels. A consumer holds a struct pbl_pwm, what a devicetree pwms entry describes: controller, channel, period and flags. As in Linux, the output is set by applying a whole state at once:
state.enabled = true;
A channel, as used by a consumer.
Definition pwm.h:77
Output state.
Definition pwm.h:65
#define PBL_PWM_HZ(hz)
Period of a hz Hz output, in nanoseconds.
Definition pwm.h:51
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_apply(const struct pbl_pwm *pwm, const struct pbl_pwm_state *state)
Apply a state to a channel.
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.
#define PBL_PWM(_ctrl, _channel, _period, _flags)
Initializer for a struct pbl_pwm.
Definition pwm.h:96
Times are in nanoseconds. Controllers round the period and the duty cycle down to what they can generate. A disabled output stays at its inactive level, low for the normal polarity. A channel belongs to one consumer; calls are made from task context.
◆ pbl_pwm_state
| Data Fields |
|
uint32_t |
duty_cycle |
Active time per period, in nanoseconds, up to period. |
|
bool |
enabled |
Whether the output runs; when false the output is inactive. |
|
uint32_t |
period |
Period, in nanoseconds. |
|
enum pbl_pwm_polarity |
polarity |
Polarity. |
◆ pbl_pwm
A channel, as used by a consumer.
◆ pbl_pwm_controller
| struct pbl_pwm_controller |
◆ PBL_PWM
| #define PBL_PWM |
( |
|
_ctrl, |
|
|
|
_channel, |
|
|
|
_period, |
|
|
|
_flags |
|
) |
| {.ctrl = (_ctrl), .channel = (_channel), .period = (_period), .flags = (_flags)} |
Initializer for a struct pbl_pwm.
- Parameters
-
◆ PBL_PWM_CONTROLLER_INIT
| #define PBL_PWM_CONTROLLER_INIT |
( |
|
sym, |
|
|
|
_name, |
|
|
|
_init, |
|
|
|
_parent, |
|
|
|
_ops |
|
) |
| |
Value: { \
.ops = (_ops), \
.states = sym##_pwm_states, \
.num_channels = sizeof(sym##_pwm_states) / sizeof(sym##_pwm_states[0]), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153
const struct pbl_device_class pbl_pwm_class
Class of the PWM controllers.
Initializer for the struct pbl_pwm_controller of controller sym.
- Parameters
-
| sym | Symbol of the controller instance, with its state defined by PBL_PWM_CONTROLLER_STATE_DEFINE(). |
| _name | Name. |
| _init | Device init function, or NULL. |
| _parent | Parent device, or NULL. |
| _ops | Driver operations. |
◆ PBL_PWM_CONTROLLER_STATE_DEFINE
| #define PBL_PWM_CONTROLLER_STATE_DEFINE |
( |
|
sym, |
|
|
|
_num_channels |
|
) |
| |
Value:
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132
Define the class state of PWM controller sym, for the driver's define macro.
- Parameters
-
| sym | Symbol of the controller instance. |
| _num_channels | Number of channels. |
◆ PBL_PWM_HZ
Period of a hz Hz output, in nanoseconds.
◆ PBL_PWM_MSEC
ms milliseconds, in nanoseconds.
◆ PBL_PWM_POLARITY_INVERTED
| #define PBL_PWM_POLARITY_INVERTED PBL_BIT(0) |
Spec flag: the output is inverted.
◆ PBL_PWM_USEC
us microseconds, in nanoseconds.
◆ pbl_pwm_polarity
Output polarity.
| Enumerator |
|---|
| PBL_PWM_POLARITY_NORMAL | High for the duty cycle, then low.
|
| PBL_PWM_POLARITY_INVERSED | Low for the duty cycle, then high.
|
◆ pbl_pwm_apply()
Apply a state to a channel.
- Parameters
-
- Returns
- 0,
-EINVAL for a state the controller cannot generate, or another negative errno.
◆ pbl_pwm_disable()
| int pbl_pwm_disable |
( |
const struct pbl_pwm * |
pwm | ) |
|
Disable a channel, keeping the rest of its state.
- Parameters
-
- Returns
- 0 or a negative errno.
◆ pbl_pwm_get_state()
Read the last applied state of a channel; disabled before the first one.
- Parameters
-
| pwm | Channel. |
| [out] | state | State. |
◆ pbl_pwm_init_state()
Prepare a state from the channel's spec.
Takes the last applied state, with the period and polarity of the spec and no duty cycle.
- Parameters
-
| pwm | Channel. |
| [out] | state | State. |
◆ pbl_pwm_set_relative_duty_cycle()
| 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.
- Parameters
-
| state | State, with its period set. |
| duty | Duty cycle, up to scale. |
| scale | Scale. |
- Returns
- 0, or
-EINVAL if scale is 0 or duty is above it.
◆ pbl_pwm_class
Class of the PWM controllers.