samples: blink_led: add support for PWM flags

Pass PWM flags set in the device tree, if any, to the
pwm_pin_set_usec() functions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2019-11-26 09:45:12 +01:00 committed by Carles Cufí
commit edd891adfd

View file

@ -19,6 +19,11 @@
/* get the defines from dt (based on alias 'pwm-led0') */ /* get the defines from dt (based on alias 'pwm-led0') */
#define PWM_DRIVER DT_ALIAS_PWM_LED0_PWMS_CONTROLLER #define PWM_DRIVER DT_ALIAS_PWM_LED0_PWMS_CONTROLLER
#define PWM_CHANNEL DT_ALIAS_PWM_LED0_PWMS_CHANNEL #define PWM_CHANNEL DT_ALIAS_PWM_LED0_PWMS_CHANNEL
#ifdef DT_ALIAS_PWM_LED0_PWMS_FLAGS
#define PWM_FLAGS DT_ALIAS_PWM_LED0_PWMS_FLAGS
#else
#define PWM_FLAGS 0
#endif
#else #else
#error "Choose supported PWM driver" #error "Choose supported PWM driver"
#endif #endif
@ -51,7 +56,7 @@ void main(void)
*/ */
max_period = MAX_PERIOD; max_period = MAX_PERIOD;
while (pwm_pin_set_usec(pwm_dev, PWM_CHANNEL, while (pwm_pin_set_usec(pwm_dev, PWM_CHANNEL,
max_period, max_period / 2U, 0)) { max_period, max_period / 2U, PWM_FLAGS)) {
max_period /= 2U; max_period /= 2U;
if (max_period < (4U * MIN_PERIOD)) { if (max_period < (4U * MIN_PERIOD)) {
printk("This sample needs to set a period that is " printk("This sample needs to set a period that is "
@ -63,7 +68,7 @@ void main(void)
period = max_period; period = max_period;
while (1) { while (1) {
if (pwm_pin_set_usec(pwm_dev, PWM_CHANNEL, if (pwm_pin_set_usec(pwm_dev, PWM_CHANNEL,
period, period / 2U, 0)) { period, period / 2U, PWM_FLAGS)) {
printk("pwm pin set fails\n"); printk("pwm pin set fails\n");
return; return;
} }