Name

pwm_init_state — prepare a new state to be applied with pwm_apply_state

Synopsis

void pwm_init_state (const struct pwm_device * pwm,
 struct pwm_state * state);
 

Arguments

pwm

PWM device

state

state to fill with the prepared PWM state

Description

This functions prepares a state that can later be tweaked and applied to the PWM device with pwm_apply_state. This is a convenient function that first retrieves the current PWM state and the replaces the period and polarity fields with the reference values defined in pwm->args. Once the function returns, you can adjust the ->enabled and ->duty_cycle fields according to your needs before calling pwm_apply_state.

->duty_cycle is initially set to zero to avoid cases where the current ->duty_cycle value exceed the pwm_args->period one, which would trigger an error if the user calls pwm_apply_state without adjusting ->duty_cycle first.