diff --git a/.github/workflows/checkpatch.yml b/.github/workflows/checkpatch.yml index f2a407a1..c3cba500 100644 --- a/.github/workflows/checkpatch.yml +++ b/.github/workflows/checkpatch.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CI +name: checkpatch review # Controls when the workflow will run on: @@ -15,15 +15,16 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on + my_review: + name: checkpatch review runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - name: checkpatch.pl PR review - uses: webispy/checkpatch-action@v8 + - name: 'Calculate PR commits + 1' + run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: ${{ env.PR_FETCH_DEPTH }} + - name: Run checkpatch review + uses: webispy/checkpatch-action@v9 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1931cfc2..c185b827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ if (CONFIG_ARDUINO_API) add_subdirectory(cores) -add_subdirectory(variants) add_subdirectory(libraries) +zephyr_include_directories(variants/${BOARD}) endif() diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..1a54cd03 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,5 @@ +# CODEOWNERS for autoreview assigning in github + +# https://help.github.com/en/articles/about-code-owners#codeowners-syntax + +/* @DhruvaG2000 @szczys @beriberikix @soburi diff --git a/Kconfig b/Kconfig index 4fcf7746..64ccf3a8 100644 --- a/Kconfig +++ b/Kconfig @@ -6,9 +6,8 @@ config ARDUINO_API bool "ARDUINO_API" - imply CPLUSPLUS + imply CPP imply GPIO - imply CPLUSPLUS imply I2C imply NEWLIB_LIBC_FLOAT_PRINTF imply CBPRINTF_FP_SUPPORT diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 4ef58eaf..f75c50f6 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -4,12 +4,101 @@ * SPDX-License-Identifier: Apache-2.0 */ +#pragma once + #include "api/ArduinoAPI.h" +#include #include #include #include -#include +#include + +#define DIGITAL_PIN_EXISTS(n, p, i, dev, num) \ + (((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && \ + (num == DT_PHA_BY_IDX(n, p, i, pin))) \ + ? 1 \ + : 0) + +/* Check all pins are defined only once */ +#define DIGITAL_PIN_CHECK_UNIQUE(i, _) \ + ((DT_FOREACH_PROP_ELEM_SEP_VARGS( \ + DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \ + DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \ + DT_PHA_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i, pin))) == 1) + +#if !LISTIFY(DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios), DIGITAL_PIN_CHECK_UNIQUE, (&&)) +#error "digital_pin_gpios has duplicate definition" +#endif + +#undef DIGITAL_PIN_CHECK_UNIQUE + +#ifndef LED_BUILTIN + +/* Return the index of it if matched, oterwise return 0 */ +#define LED_BUILTIN_INDEX_BY_REG_AND_PINNUM(n, p, i, dev, num) \ + (DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0) + +/* Only matched pin returns non-zero value, so the sum is matched pin's index */ +#define DIGITAL_PIN_GPIOS_FIND_PIN(dev, pin) \ + DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \ + LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin) + +#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \ + (DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0) + +#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \ + DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \ + DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \ + DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0) +#warning "pin not found in digital_pin_gpios" +#else +#define LED_BUILTIN \ + DIGITAL_PIN_GPIOS_FIND_PIN( \ + DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \ + DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) +#endif + +/* If digital-pin-gpios is not defined, tries to use the led0 alias */ +#elif DT_NODE_EXISTS(DT_ALIAS(led0)) + +#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \ + (+), DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \ + DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) > 0) +#warning "pin not found in digital_pin_gpios" +#else +#define LED_BUILTIN \ + DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \ + DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) +#endif + +#endif // builtin_led_gpios + +#endif // LED_BUILTIN + +#define DN_ENUMS(n, p, i) D##i = i + +/* + * expand as + * enum digitalPins { D0, D1, ... LED... NUM_OF_DIGITAL_PINS }; + */ +enum digitalPins { + DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, DN_ENUMS, (, )), + NUM_OF_DIGITAL_PINS +}; + +const 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_ADC + +#define AN_ENUMS(n, p, i) A ## 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)), +enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), + adc_pin_gpios, AN_ENUMS) }; + +#endif #include #include diff --git a/documentation/variants.md b/documentation/variants.md index 38a10012..5f26571e 100644 --- a/documentation/variants.md +++ b/documentation/variants.md @@ -9,6 +9,7 @@ Once completed, continue here by adding a variant for your custom board. - [X] Arduino Nano ble sense 33 - [X] Arduino Nano ble 33 - [X] Arduino Nano 33 iot +- [X] Beagleconnect Freedom ## Planned Support: (TODO) - [ ] Particle Xenon diff --git a/variants/CMakeLists.txt b/variants/CMakeLists.txt deleted file mode 100644 index c217a8c9..00000000 --- a/variants/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -zephyr_include_directories(.) -zephyr_include_directories(${BOARD}) diff --git a/variants/arduino_mkrzero/arduino_mkrzero_pinmap.h b/variants/arduino_mkrzero/arduino_mkrzero_pinmap.h deleted file mode 100644 index 1ad579e4..00000000 --- a/variants/arduino_mkrzero/arduino_mkrzero_pinmap.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2022 Dhruva Gole - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once -#include -#include -#include - diff --git a/variants/arduino_mkrzero/variants.h b/variants/arduino_mkrzero/variants.h new file mode 100644 index 00000000..06cab2da --- /dev/null +++ b/variants/arduino_mkrzero/variants.h @@ -0,0 +1,5 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ diff --git a/variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h b/variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h deleted file mode 100644 index 48517b4d..00000000 --- a/variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2022 Dhruva Gole - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* All the pins that are 100 + x are gpio1 pins and < 100 are in gpio0 */ -#pragma once -#include -#include -#include -#include - diff --git a/variants/arduino_nano_33_ble/variants.h b/variants/arduino_nano_33_ble/variants.h new file mode 100644 index 00000000..06cab2da --- /dev/null +++ b/variants/arduino_nano_33_ble/variants.h @@ -0,0 +1,5 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ diff --git a/variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense_pinmap.h b/variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense_pinmap.h deleted file mode 100644 index 48517b4d..00000000 --- a/variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense_pinmap.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2022 Dhruva Gole - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* All the pins that are 100 + x are gpio1 pins and < 100 are in gpio0 */ -#pragma once -#include -#include -#include -#include - diff --git a/variants/arduino_nano_33_ble_sense/variants.h b/variants/arduino_nano_33_ble_sense/variants.h new file mode 100644 index 00000000..06cab2da --- /dev/null +++ b/variants/arduino_nano_33_ble_sense/variants.h @@ -0,0 +1,5 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ diff --git a/variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h b/variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h deleted file mode 100644 index 48517b4d..00000000 --- a/variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2022 Dhruva Gole - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* All the pins that are 100 + x are gpio1 pins and < 100 are in gpio0 */ -#pragma once -#include -#include -#include -#include - diff --git a/variants/arduino_nano_33_iot/variants.h b/variants/arduino_nano_33_iot/variants.h new file mode 100644 index 00000000..06cab2da --- /dev/null +++ b/variants/arduino_nano_33_iot/variants.h @@ -0,0 +1,5 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ diff --git a/variants/beagleconnect_freedom/beagleconnect_freedom.overlay b/variants/beagleconnect_freedom/beagleconnect_freedom.overlay new file mode 100644 index 00000000..47901fab --- /dev/null +++ b/variants/beagleconnect_freedom/beagleconnect_freedom.overlay @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Ayush Singh + * + * SPDX-License-Identifier: Apache-2.0 + */ + + / { + zephyr,user { + digital-pin-gpios = + <&gpio0 16 GPIO_ACTIVE_HIGH>, /* D0 - MB1 INT */ + <&gpio0 20 GPIO_ACTIVE_HIGH>, /* D1 - MB2 INT */ + <&gpio0 17 GPIO_ACTIVE_HIGH>, /* D2 - MB1 PWM */ + <&gpio0 28 GPIO_ACTIVE_HIGH>, /* D3 - MB1 CS - A5 */ + <&gpio0 21 GPIO_ACTIVE_HIGH>, /* D4 - MB2 UART1 RX */ + <&gpio0 22 GPIO_ACTIVE_HIGH>, /* D5 - MB2 UART1 TX */ + <&gpio0 19 GPIO_ACTIVE_HIGH>, /* D6 - MB2 PWM */ + <&gpio0 27 GPIO_ACTIVE_HIGH>, /* D7 - MB2 CS - A4 */ + <&gpio0 9 GPIO_ACTIVE_HIGH>, /* D8 - MB1/2 PICO */ + <&gpio0 10 GPIO_ACTIVE_HIGH>, /* D9 - MB1/2 SCK */ + <&gpio0 11 GPIO_ACTIVE_HIGH>, /* D10 - MB1/2 POCI */ + <&gpio0 26 GPIO_ACTIVE_HIGH>, /* D11 - MB1/2 SDA - A2 */ + <&gpio0 25 GPIO_ACTIVE_HIGH>, /* D12 - MB1/2 SCL - A3 */ + <&gpio0 12 GPIO_ACTIVE_HIGH>, /* D13 - MB1 UART0 RX */ + <&gpio0 13 GPIO_ACTIVE_HIGH>, /* D14 - MB1 UART0 TX */ + <&gpio0 23 GPIO_ACTIVE_HIGH>, /* D15 - MB1 AN - A0 */ + <&gpio0 24 GPIO_ACTIVE_HIGH>, /* D16 - MB2 AN - A1 */ + <&gpio0 5 GPIO_ACTIVE_HIGH>, /* D17 - MB2 RST */ + <&gpio0 6 GPIO_ACTIVE_HIGH>, /* D18 - MB1 RST */ + <&gpio0 7 GPIO_ACTIVE_HIGH>, /* D19 - on-board sensor INT */ + <&gpio0 8 GPIO_ACTIVE_HIGH>, /* D20 - flash CS */ + <&gpio0 14 GPIO_ACTIVE_HIGH>, /* D21 - on-board sensor I2C enable */ + <&gpio0 15 GPIO_ACTIVE_HIGH>, /* D22 - BOOT button */ + <&gpio0 18 GPIO_ACTIVE_HIGH>; /* D23 - LINK LED */ + + pwm-pin-gpios = + <&gpio0 17 GPIO_ACTIVE_HIGH>, /* D2 - MB1 PWM */ + <&gpio0 3 GPIO_ACTIVE_HIGH>; /* D6 - MB2 PWM */ + + adc-pin-gpios = + <&gpio0 23 GPIO_ACTIVE_HIGH>, /* D15 - MB1 AN - A0 */ + <&gpio0 24 GPIO_ACTIVE_HIGH>, /* D16 - MB2 AN - A1 */ + <&gpio0 26 GPIO_ACTIVE_HIGH>, /* D11 - MB1/2 SDA - A2 */ + <&gpio0 25 GPIO_ACTIVE_HIGH>, /* D12 - MB1/2 SCL - A3 */ + <&gpio0 27 GPIO_ACTIVE_HIGH>, /* D7 - MB2 CS - A4 */ + <&gpio0 28 GPIO_ACTIVE_HIGH>; /* D3 - MB1 CS - A5 */ + + builtin-led-gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>; /* 2.4GHz TX/RX */ + serials = <&uart0 &uart1>; + i2cs = <&i2c0>; + }; + }; diff --git a/variants/beagleconnect_freedom/variants.h b/variants/beagleconnect_freedom/variants.h new file mode 100644 index 00000000..efd90537 --- /dev/null +++ b/variants/beagleconnect_freedom/variants.h @@ -0,0 +1,6 @@ +/* + * Copyright (c) 2024 Ayush Singh + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once diff --git a/variants/cc3220sf_launchxl/cc3220sf_launchxl_pinmap.h b/variants/cc3220sf_launchxl/variants.h similarity index 68% rename from variants/cc3220sf_launchxl/cc3220sf_launchxl_pinmap.h rename to variants/cc3220sf_launchxl/variants.h index 5eac76e0..0be70fc9 100644 --- a/variants/cc3220sf_launchxl/cc3220sf_launchxl_pinmap.h +++ b/variants/cc3220sf_launchxl/variants.h @@ -6,10 +6,6 @@ /* All the pins that are 100 + x are gpio1 pins and < 100 are in gpio0 */ #pragma once -#include -#include -#include -#include #define LED_BUILTIN 4 #define YELLOW_LED 3 diff --git a/variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840_pinmap.h b/variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840_pinmap.h deleted file mode 100644 index 976d3241..00000000 --- a/variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840_pinmap.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2022 Mike Szczys - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __NRF52840DK_NRF52840_PINMAP_H__ -#define __NRF52840DK_NRF52840_PINMAP_H__ - -#include -#include -#include - -#endif diff --git a/variants/nrf52840dk_nrf52840/variants.h b/variants/nrf52840dk_nrf52840/variants.h new file mode 100644 index 00000000..dd35da07 --- /dev/null +++ b/variants/nrf52840dk_nrf52840/variants.h @@ -0,0 +1,5 @@ +/* + * Copyright (c) 2022 Mike Szczys + * + * SPDX-License-Identifier: Apache-2.0 + */ diff --git a/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160_pinmap.h b/variants/nrf9160dk_nrf9160/variants.h similarity index 86% rename from variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160_pinmap.h rename to variants/nrf9160dk_nrf9160/variants.h index e4a1fbcc..1da36b9b 100644 --- a/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160_pinmap.h +++ b/variants/nrf9160dk_nrf9160/variants.h @@ -7,10 +7,6 @@ #ifndef INCLUDE_NRF1960DK_NRF1960_PINMAP_H #define INCLUDE_NRF1960DK_NRF1960_PINMAP_H -#include -#include -#include - #define NRF9160DK_LED_1 D2 // P0.02 #define NRF9160DK_LED_2 D3 // P0.03 #define NRF9160DK_LED_3 D4 // P0.04 diff --git a/variants/variants.h b/variants/variants.h deleted file mode 100644 index 9b7bc7dc..00000000 --- a/variants/variants.h +++ /dev/null @@ -1,111 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -#pragma once - -#ifdef CONFIG_BOARD_ARDUINO_NANO_33_BLE -#include -#endif // CONFIG_BOARD_ARDUINO_NANO_33_BLE -#ifdef CONFIG_BOARD_ARDUINO_NANO_33_BLE_SENSE -#include -#endif // CONFIG_BOARD_ARDUINO_NANO_33_BLE_SENSE -#ifdef CONFIG_BOARD_ARDUINO_NANO_33_IOT -#include -#endif /* CONFIG_BOARD_ARDUINO_NANO_33_IOT */ -#ifdef CONFIG_BOARD_NRF52840DK_NRF52840 -#include "nrf52840dk_nrf52840_pinmap.h" -#endif /* CONFIG_BOARD_NRF52840DK_NRF52840 */ -#ifdef CONFIG_BOARD_NRF9160DK_NRF9160 -#include "nrf9160dk_nrf9160_pinmap.h" -#endif /* CONFIG_BOARD_NRF9160DK_NRF9160 */ -#ifdef CONFIG_BOARD_ARDUINO_MKRZERO -#include "arduino_mkrzero_pinmap.h" -#endif // CONFIG_BOARD_ARDUINO_MKRZERO -#ifdef CONFIG_BOARD_CC3220SF_LAUNCHXL -#include "cc3220sf_launchxl_pinmap.h" -#endif // CONFIG_BOARD_CC3220SF_LAUNCHXL - -#define DIGITAL_PIN_EXISTS(n, p, i, dev, num) \ - (((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && \ - (num == DT_PHA_BY_IDX(n, p, i, pin))) \ - ? 1 \ - : 0) - -/* Check all pins are defined only once */ -#define DIGITAL_PIN_CHECK_UNIQUE(i, _) \ - ((DT_FOREACH_PROP_ELEM_SEP_VARGS( \ - DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \ - DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \ - DT_PHA_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i, pin))) == 1) - -#if !LISTIFY(DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios), DIGITAL_PIN_CHECK_UNIQUE, (&&)) -#error "digital_pin_gpios has duplicate definition" -#endif - -#undef DIGITAL_PIN_CHECK_UNIQUE - -#ifndef LED_BUILTIN - -/* Return the index of it if matched, oterwise return 0 */ -#define LED_BUILTIN_INDEX_BY_REG_AND_PINNUM(n, p, i, dev, num) \ - (DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0) - -/* Only matched pin returns non-zero value, so the sum is matched pin's index */ -#define DIGITAL_PIN_GPIOS_FIND_PIN(dev, pin) \ - DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \ - LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin) - -#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \ - (DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0) - -#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \ - DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \ - DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \ - DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0) -#warning "pin not found in digital_pin_gpios" -#else -#define LED_BUILTIN \ - DIGITAL_PIN_GPIOS_FIND_PIN( \ - DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \ - DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) -#endif - -/* If digital-pin-gpios is not defined, tries to use the led0 alias */ -#elif DT_NODE_EXISTS(DT_ALIAS(led0)) - -#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \ - (+), DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \ - DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) > 0) -#warning "pin not found in digital_pin_gpios" -#else -#define LED_BUILTIN \ - DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \ - DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) -#endif - -#endif // builtin_led_gpios - -#endif // LED_BUILTIN - -#define DN_ENUMS(n, p, i) D##i = i - -/* - * expand as - * enum digitalPins { D0, D1, ... LED... NUM_OF_DIGITAL_PINS }; - */ -enum digitalPins { - DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, DN_ENUMS, (, )), - NUM_OF_DIGITAL_PINS -}; - -const 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_ADC - -#define AN_ENUMS(n, p, i) A ## 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)), -enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), - adc_pin_gpios, AN_ENUMS) }; - -#endif