diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2021-10-05 19:14:32 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-06 00:04:59 +0000 |
commit | aabb0eb2685f011fd50b41ba3df0b2b562d1fa83 (patch) | |
tree | d9d566f7f85df92f3df3459d2e18b9ddf2be907f /zephyr/shim/src/pwm_led.c | |
parent | 1441ad312c7bca9f301f51494df8641a597cfe47 (diff) | |
download | chrome-ec-aabb0eb2685f011fd50b41ba3df0b2b562d1fa83.tar.gz |
zephyr: shim: support optional pwm led channels
This changes the PWM_CHANNEL_BY_IDX macro to correctly handle pwm-leds
entries with less than 3 phandles, defaulting the corresponding channels
to PWM_LED_NO_CHANNEL.
This is necessary for devices with only two LED channels.
BRANCH=none
BUG=b:200974848
TEST=build only, compared the resulting pwm_leds structure
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: I719ebfb085e60cc2ef27c3508c2b73ae85d3f7ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3205318
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr/shim/src/pwm_led.c')
-rw-r--r-- | zephyr/shim/src/pwm_led.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c index 48565d2e56..2646f09c43 100644 --- a/zephyr/shim/src/pwm_led.c +++ b/zephyr/shim/src/pwm_led.c @@ -22,11 +22,17 @@ BUILD_ASSERT(DT_INST_PROP_LEN(0, leds) <= 2, PWM_CHANNEL(DT_PWMS_CTLR_BY_IDX( \ DT_PHANDLE_BY_IDX(node_id, prop, idx), led_ch)) +#define PWM_CHANNEL_BY_IDX_COND(node_id, prop, idx, led_ch) \ + COND_CODE_1(DT_PROP_HAS_IDX( \ + DT_PHANDLE_BY_IDX(node_id, prop, idx), pwms, led_ch), \ + (PWM_CHANNEL_BY_IDX(node_id, prop, idx, led_ch)), \ + (PWM_LED_NO_CHANNEL)) + #define PWM_LED_INIT(node_id, prop, idx) \ [PWM_LED##idx] = { \ - .ch0 = PWM_CHANNEL_BY_IDX(node_id, prop, idx, 0), \ - .ch1 = PWM_CHANNEL_BY_IDX(node_id, prop, idx, 1), \ - .ch2 = PWM_CHANNEL_BY_IDX(node_id, prop, idx, 2), \ + .ch0 = PWM_CHANNEL_BY_IDX_COND(node_id, prop, idx, 0), \ + .ch1 = PWM_CHANNEL_BY_IDX_COND(node_id, prop, idx, 1), \ + .ch2 = PWM_CHANNEL_BY_IDX_COND(node_id, prop, idx, 2), \ .enable = &pwm_enable, \ .set_duty = &pwm_set_duty, \ }, |