Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions cores/arduino/wiring_analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ namespace {

#ifdef CONFIG_PWM

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

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

size_t pwm_pin_index(pin_size_t pinNumber) {
for (size_t i = 0; i < ARRAY_SIZE(arduino_pwm_pins); i++) {
if (arduino_pwm_pins[i] == pinNumber) {
Expand All @@ -55,13 +48,6 @@ size_t pwm_pin_index(pin_size_t pinNumber) {

#ifdef CONFIG_ADC

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

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

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

Expand Down
32 changes: 32 additions & 0 deletions cores/arduino/wiring_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
} \
} while (0)

#define ZARD_PWM_DT_SPEC(n, p, i) PWM_DT_SPEC_GET_BY_IDX(n, i),
#define ZARD_PWM_PINS(n, p, i) \
DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),

#define ZARD_ADC_DT_SPEC(n, p, i) ADC_DT_SPEC_GET_BY_IDX(n, i),
#define ZARD_ADC_PINS(n, p, i) \
DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),

#ifdef __cplusplus

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

#ifdef CONFIG_PWM

constexpr struct pwm_dt_spec arduino_pwm[] = {
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwms, ZARD_PWM_DT_SPEC)};

/* pwm-pins node provides a mapping digital pin numbers to pwm channels */
constexpr pin_size_t arduino_pwm_pins[] = {
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwm_pin_gpios, ZARD_PWM_PINS)};

#endif

#ifdef CONFIG_ADC

constexpr struct adc_dt_spec arduino_adc[] = {
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ZARD_ADC_DT_SPEC)};

/* io-channel-pins node provides a mapping digital pin numbers to adc channels */
constexpr pin_size_t arduino_analog_pins[] = {
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), adc_pin_gpios, ZARD_ADC_PINS)};

#endif

/*
* Calculate GPIO ports/pins number statically from devicetree configuration
*/
Expand Down
Loading