Skip to content

Create common digital pin definition #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2022
Merged
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
12 changes: 6 additions & 6 deletions cores/arduino/zephyrCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ void yield(void) {
*/
void pinMode(pin_size_t pinNumber, PinMode pinMode) {
if (pinMode == INPUT) { // input mode
gpio_pin_configure_dt(arduino_pins[pinNumber],
gpio_pin_configure_dt(&arduino_pins[pinNumber],
GPIO_INPUT | GPIO_ACTIVE_HIGH);
} else if (pinMode == INPUT_PULLUP) { // input with internal pull-up
gpio_pin_configure_dt(arduino_pins[pinNumber],
gpio_pin_configure_dt(&arduino_pins[pinNumber],
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_HIGH);
} else if (pinMode == INPUT_PULLDOWN) { // input with internal pull-down
gpio_pin_configure_dt(arduino_pins[pinNumber],
gpio_pin_configure_dt(&arduino_pins[pinNumber],
GPIO_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH);
} else if (pinMode == OUTPUT) { // output mode
gpio_pin_configure_dt(arduino_pins[pinNumber],
gpio_pin_configure_dt(&arduino_pins[pinNumber],
GPIO_OUTPUT_LOW | GPIO_ACTIVE_HIGH);
}
}

void digitalWrite(pin_size_t pinNumber, PinStatus status) {
gpio_pin_set_dt(arduino_pins[pinNumber], status);
gpio_pin_set_dt(&arduino_pins[pinNumber], status);
}

PinStatus digitalRead(pin_size_t pinNumber) {
return (gpio_pin_get_dt(arduino_pins[pinNumber]) == 1) ? HIGH : LOW;
return (gpio_pin_get_dt(&arduino_pins[pinNumber]) == 1) ? HIGH : LOW;
}

void delay(unsigned long ms) { k_sleep(K_MSEC(ms)); }
Expand Down
78 changes: 0 additions & 78 deletions variants/arduino_mkrzero/arduino_mkrzero_pinmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,5 @@
#include <zephyr/drivers/i2c.h>

#define LED_BUILTIN 22
#define LED0_NODE DT_ALIAS(led0)

static struct gpio_dt_spec d0 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
static struct gpio_dt_spec d1 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
static struct gpio_dt_spec d2 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
static struct gpio_dt_spec d3 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
static struct gpio_dt_spec d4 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
static struct gpio_dt_spec d5 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
static struct gpio_dt_spec d6 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
static struct gpio_dt_spec d7 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
static struct gpio_dt_spec d8 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
static struct gpio_dt_spec d9 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
static struct gpio_dt_spec d10 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
static struct gpio_dt_spec d11 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
static struct gpio_dt_spec d12 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
static struct gpio_dt_spec d13 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d14 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d15 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
static struct gpio_dt_spec d16 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
static struct gpio_dt_spec d17 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
static struct gpio_dt_spec d18 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
static struct gpio_dt_spec d19 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
static struct gpio_dt_spec d20 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
static struct gpio_dt_spec d21 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);
static struct gpio_dt_spec led_builtin = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

static struct gpio_dt_spec *arduino_pins[23] = {
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7,
&d8, &d9, &d10, &d11, &d12, &d13, &d14, &d15,
&d16, &d17, &d18, &d19, &d20, &d21, &led_builtin};

enum digitalPins {
D0,
D1,
D2,
D3,
D4,
D5,
D6,
D7,
D8,
D9,
D10,
D11,
D12,
D13,
D14,
D15,
D16,
D17,
D18,
D19,
D20,
D21,
LED
};

const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(sercom0));
70 changes: 0 additions & 70 deletions variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,4 @@

#define LED_BUILTIN 13

static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
static struct gpio_dt_spec d1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
static struct gpio_dt_spec d2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
static struct gpio_dt_spec d3 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
static struct gpio_dt_spec d4 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
static struct gpio_dt_spec d5 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
static struct gpio_dt_spec d6 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
static struct gpio_dt_spec d7 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
static struct gpio_dt_spec d8 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
static struct gpio_dt_spec d9 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
static struct gpio_dt_spec d10 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
static struct gpio_dt_spec d11 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
static struct gpio_dt_spec d12 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
static struct gpio_dt_spec d13 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d14 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d15 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
static struct gpio_dt_spec d16 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
static struct gpio_dt_spec d17 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
static struct gpio_dt_spec d18 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
static struct gpio_dt_spec d19 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
static struct gpio_dt_spec d20 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
static struct gpio_dt_spec d21 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);

static struct gpio_dt_spec *arduino_pins[22] = {
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, &d9, &d10,
&d11, &d12, &d13, &d14, &d15, &d16, &d17, &d18, &d19, &d20, &d21};

enum digitalPins {
D0,
D1,
D2,
D3,
D4,
D5,
D6,
D7,
D8,
D9,
D10,
D11,
D12,
D13,
D14,
D15,
D16,
D17,
D18,
D19,
D20,
D21
};

const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,4 @@

#define LED_BUILTIN 13

static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
static struct gpio_dt_spec d1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
static struct gpio_dt_spec d2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
static struct gpio_dt_spec d3 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
static struct gpio_dt_spec d4 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
static struct gpio_dt_spec d5 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
static struct gpio_dt_spec d6 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
static struct gpio_dt_spec d7 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
static struct gpio_dt_spec d8 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
static struct gpio_dt_spec d9 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
static struct gpio_dt_spec d10 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
static struct gpio_dt_spec d11 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
static struct gpio_dt_spec d12 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
static struct gpio_dt_spec d13 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d14 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d15 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
static struct gpio_dt_spec d16 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
static struct gpio_dt_spec d17 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
static struct gpio_dt_spec d18 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
static struct gpio_dt_spec d19 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
static struct gpio_dt_spec d20 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
static struct gpio_dt_spec d21 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);

static struct gpio_dt_spec *arduino_pins[22] = {
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, &d9, &d10,
&d11, &d12, &d13, &d14, &d15, &d16, &d17, &d18, &d19, &d20, &d21};

enum digitalPins {
D0,
D1,
D2,
D3,
D4,
D5,
D6,
D7,
D8,
D9,
D10,
D11,
D12,
D13,
D14,
D15,
D16,
D17,
D18,
D19,
D20,
D21
};

const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));
70 changes: 0 additions & 70 deletions variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,5 @@

#define LED_BUILTIN 13

static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
static struct gpio_dt_spec d1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
static struct gpio_dt_spec d2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
static struct gpio_dt_spec d3 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
static struct gpio_dt_spec d4 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
static struct gpio_dt_spec d5 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
static struct gpio_dt_spec d6 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
static struct gpio_dt_spec d7 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
static struct gpio_dt_spec d8 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
static struct gpio_dt_spec d9 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
static struct gpio_dt_spec d10 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
static struct gpio_dt_spec d11 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
static struct gpio_dt_spec d12 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
static struct gpio_dt_spec d13 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d14 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
static struct gpio_dt_spec d15 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
static struct gpio_dt_spec d16 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
static struct gpio_dt_spec d17 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
static struct gpio_dt_spec d18 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
static struct gpio_dt_spec d19 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
static struct gpio_dt_spec d20 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
static struct gpio_dt_spec d21 =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);

static struct gpio_dt_spec *arduino_pins[22] = {
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, &d9, &d10,
&d11, &d12, &d13, &d14, &d15, &d16, &d17, &d18, &d19, &d20, &d21};

enum digitalPins {
D0,
D1,
D2,
D3,
D4,
D5,
D6,
D7,
D8,
D9,
D10,
D11,
D12,
D13,
D14,
D15,
D16,
D17,
D18,
D19,
D20,
D21
};

const static struct device *i2c_dev =
DEVICE_DT_GET(DT_NODELABEL(arduino_nano_i2c));
Loading