diff options
author | Aaron Massey <aaronmassey@google.com> | 2022-10-07 16:48:35 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-10 23:53:16 +0000 |
commit | 5a0519d8018e9a3280d486a4ff3985b5492ee9e8 (patch) | |
tree | f3fe07c27c524444d0e00d5847deac17a97c8822 | |
parent | 6045f083da62a46cbb0d37f30893eb877a9b7b62 (diff) | |
download | chrome-ec-5a0519d8018e9a3280d486a4ff3985b5492ee9e8.tar.gz |
pwm: Factor out PWM_RAW/PERCENT_TO_PERCENT/RAW()
The shim and common pwm code both define the exact same macros to
convert to PWM raw and percentage values.
Factor these macros out as a single macro included in the pwm.h header
that is already included by both the shim and common code. This has the
other side-effect of exposing these macros for testing purposes.
BRANCH=none
BUG=b:236132469
BUG=b:236132199
TEST=zmake build -a
TEST=make runhosttests
TEST=CQ
Signed-off-by: Aaron Massey <aaronmassey@google.com>
Change-Id: I8a8c19242b0122a1a18c26bba3eda08a0613d824
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3939620
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r-- | common/pwm.c | 3 | ||||
-rw-r--r-- | include/pwm.h | 5 | ||||
-rw-r--r-- | zephyr/shim/src/pwm_hc.c | 3 |
3 files changed, 5 insertions, 6 deletions
diff --git a/common/pwm.c b/common/pwm.c index 9019a329b4..e630ddd58e 100644 --- a/common/pwm.c +++ b/common/pwm.c @@ -13,9 +13,6 @@ #ifdef CONFIG_PWM -#define PWM_RAW_TO_PERCENT(v) DIV_ROUND_NEAREST((uint32_t)(v)*100, UINT16_MAX) -#define PWM_PERCENT_TO_RAW(v) ((uint32_t)(v)*UINT16_MAX / 100) - /* * Get target channel based on type / index host command parameters. * Returns 0 if a valid channel is selected, -1 on error. diff --git a/include/pwm.h b/include/pwm.h index 2ac46b3812..03e424ee05 100644 --- a/include/pwm.h +++ b/include/pwm.h @@ -6,6 +6,11 @@ #ifndef __CROS_EC_PWM_H #define __CROS_EC_PWM_H +#include <inttypes.h> + +#define PWM_RAW_TO_PERCENT(v) DIV_ROUND_NEAREST((uint32_t)(v)*100, UINT16_MAX) +#define PWM_PERCENT_TO_RAW(v) ((uint32_t)(v)*UINT16_MAX / 100) + /* The values are defined in board.h */ enum pwm_channel; diff --git a/zephyr/shim/src/pwm_hc.c b/zephyr/shim/src/pwm_hc.c index 3b1a98f651..c0350c733f 100644 --- a/zephyr/shim/src/pwm_hc.c +++ b/zephyr/shim/src/pwm_hc.c @@ -19,9 +19,6 @@ LOG_MODULE_REGISTER(pwm_shim, LOG_LEVEL_ERR); -#define PWM_RAW_TO_PERCENT(v) DIV_ROUND_NEAREST((uint32_t)(v)*100, UINT16_MAX) -#define PWM_PERCENT_TO_RAW(v) ((uint32_t)(v)*UINT16_MAX / 100) - #define HAS_PWM_GENERIC_CHANNEL(compat) \ DT_NODE_HAS_PROP(DT_COMPAT_GET_ANY_STATUS_OKAY(compat), \ generic_pwm_channel) |