Skip to content

Commit 7422deb

Browse files
committed
core: PWM/ADC constants make into constexpr
Move the constant array derived from devicetree to wiring_private.h and convert it to constexpr. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent c1f29ad commit 7422deb

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

cores/arduino/wiring_analog.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ namespace {
3535

3636
#ifdef CONFIG_PWM
3737

38-
const struct pwm_dt_spec arduino_pwm[] = {
39-
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwms, PWM_DT_SPEC)};
40-
41-
/* pwm-pins node provides a mapping digital pin numbers to pwm channels */
42-
const pin_size_t arduino_pwm_pins[] = {
43-
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwm_pin_gpios, PWM_PINS)};
44-
4538
size_t pwm_pin_index(pin_size_t pinNumber) {
4639
for (size_t i = 0; i < ARRAY_SIZE(arduino_pwm_pins); i++) {
4740
if (arduino_pwm_pins[i] == pinNumber) {
@@ -55,13 +48,6 @@ size_t pwm_pin_index(pin_size_t pinNumber) {
5548

5649
#ifdef CONFIG_ADC
5750

58-
const struct adc_dt_spec arduino_adc[] = {
59-
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_DT_SPEC)};
60-
61-
/* io-channel-pins node provides a mapping digital pin numbers to adc channels */
62-
const pin_size_t arduino_analog_pins[] = {
63-
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), adc_pin_gpios, ADC_PINS)};
64-
6551
struct adc_channel_cfg channel_cfg[] = {
6652
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_CH_CFG)};
6753

cores/arduino/wiring_private.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
} \
1616
} while (0)
1717

18+
#define ZARD_PWM_DT_SPEC(n, p, i) PWM_DT_SPEC_GET_BY_IDX(n, i),
19+
#define ZARD_PWM_PINS(n, p, i) \
20+
DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
21+
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
22+
23+
#define ZARD_ADC_DT_SPEC(n, p, i) ADC_DT_SPEC_GET_BY_IDX(n, i),
24+
#define ZARD_ADC_PINS(n, p, i) \
25+
DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
26+
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
27+
1828
#ifdef __cplusplus
1929

2030
namespace zephyr {
@@ -24,6 +34,28 @@ constexpr struct gpio_dt_spec arduino_pins[] = {
2434
DT_FOREACH_PROP_ELEM_SEP(
2535
DT_PATH(zephyr_user), digital_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, ))};
2636

37+
#ifdef CONFIG_PWM
38+
39+
constexpr struct pwm_dt_spec arduino_pwm[] = {
40+
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwms, ZARD_PWM_DT_SPEC)};
41+
42+
/* pwm-pins node provides a mapping digital pin numbers to pwm channels */
43+
constexpr pin_size_t arduino_pwm_pins[] = {
44+
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwm_pin_gpios, ZARD_PWM_PINS)};
45+
46+
#endif
47+
48+
#ifdef CONFIG_ADC
49+
50+
constexpr struct adc_dt_spec arduino_adc[] = {
51+
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ZARD_ADC_DT_SPEC)};
52+
53+
/* io-channel-pins node provides a mapping digital pin numbers to adc channels */
54+
constexpr pin_size_t arduino_analog_pins[] = {
55+
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), adc_pin_gpios, ZARD_ADC_PINS)};
56+
57+
#endif
58+
2759
/*
2860
* Calculate GPIO ports/pins number statically from devicetree configuration
2961
*/

0 commit comments

Comments
 (0)