Skip to content

Commit 453d857

Browse files
soburiDhruvaG2000
authored andcommitted
zephyrCommon: GPIO cells use to PWM and ADC pin assigning
Change to use GPIO cells to assign PWM and ADC pins. This change makes it easier to manage because unifying the notation with `digital-pin-gpios`. Deleting `pwm-pins` and `io-channel-pins` nodes, and create `pwm-pin-gpios` and `adc-pins-gpios`. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent e08deb1 commit 453d857

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

cores/arduino/zephyrCommon.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,17 @@ void handleGpioCallback(const struct device *port, struct gpio_callback *cb, uin
113113
#ifdef CONFIG_PWM
114114

115115
#define PWM_DT_SPEC(n,p,i) PWM_DT_SPEC_GET_BY_IDX(n, i),
116-
#define PWM_PINS(n,p,i) DT_PROP_BY_IDX(n, p, i),
116+
#define PWM_PINS(n, p, i) \
117+
DIGITAL_PIN_GPIOS_FIND_PIN( \
118+
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
119+
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
117120

118121
const struct pwm_dt_spec arduino_pwm[] =
119122
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwms, PWM_DT_SPEC) };
120123

121124
/* pwm-pins node provides a mapping digital pin numbers to pwm channels */
122125
const pin_size_t arduino_pwm_pins[] =
123-
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwm_pins, PWM_PINS) };
126+
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwm_pin_gpios, PWM_PINS) };
124127

125128
size_t pwm_pin_index(pin_size_t pinNumber) {
126129
for(size_t i=0; i<ARRAY_SIZE(arduino_pwm_pins); i++) {
@@ -136,15 +139,18 @@ size_t pwm_pin_index(pin_size_t pinNumber) {
136139
#ifdef CONFIG_ADC
137140

138141
#define ADC_DT_SPEC(n,p,i) ADC_DT_SPEC_GET_BY_IDX(n, i),
139-
#define ADC_PINS(n,p,i) DT_PROP_BY_IDX(n, p, i),
142+
#define ADC_PINS(n, p, i) \
143+
DIGITAL_PIN_GPIOS_FIND_PIN( \
144+
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
145+
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
140146
#define ADC_CH_CFG(n,p,i) arduino_adc[i].channel_cfg,
141147

142148
const struct adc_dt_spec arduino_adc[] =
143149
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_DT_SPEC) };
144150

145151
/* io-channel-pins node provides a mapping digital pin numbers to adc channels */
146152
const pin_size_t arduino_analog_pins[] =
147-
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channel_pins, ADC_PINS) };
153+
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), adc_pin_gpios, ADC_PINS) };
148154

149155
struct adc_channel_cfg channel_cfg[ARRAY_SIZE(arduino_analog_pins)] =
150156
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_CH_CFG) };

variants/variants.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ const struct gpio_dt_spec arduino_pins[] = {DT_FOREACH_PROP_ELEM_SEP(
9696

9797
#ifdef CONFIG_ADC
9898

99-
#define AN_ENUMS(n, p, i) A ## i = DT_PROP_BY_IDX(n, p, i),
99+
#define AN_ENUMS(n, p, i) A ## i = DIGITAL_PIN_GPIOS_FIND_PIN( \
100+
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
101+
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
100102
enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user),
101-
io_channel_pins, AN_ENUMS) };
103+
adc_pin_gpios, AN_ENUMS) };
102104

103105
#endif

0 commit comments

Comments
 (0)