From 6fabfbd19445c06b738e9366e2157b602834c488 Mon Sep 17 00:00:00 2001 From: Dhruva Gole Date: Sun, 27 Nov 2022 09:30:15 +0530 Subject: [PATCH 01/11] create west.yml This file can be used to directly pull and use this module. Main use case at the moment is to easily pull this module in a docker container and then run a simple sample build test to see if code compiles without errors. Signed-off-by: Dhruva Gole --- west.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 west.yml diff --git a/west.yml b/west.yml new file mode 100644 index 000000000..9f3b2a499 --- /dev/null +++ b/west.yml @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Dhruva Gole +# SPDX-License-Identifier: Apache-2.0 + +# NOTE: This is created to be used for CI/CD workflow. So use it only +# if you are in the zephyrproject directory or else things may break. + +manifest: + self: + path: modules/lib/Arduino-Zephyr-API + + remotes: + - name: zephyrproject-rtos + url-base: https://github.com/zephyrproject-rtos + + projects: + - name: zephyr + remote: zephyrproject-rtos + revision: main + import: true From 1b7727c297ae9f8f0e6c97b359722445a9b35102 Mon Sep 17 00:00:00 2001 From: Dhruva Gole Date: Wed, 30 Nov 2022 18:46:15 +0530 Subject: [PATCH 02/11] create build.yml for CI CD This creates a CI CD build workflow to check if project builds successfully for a basic fade led and i2c samples Signed-off-by: Dhruva Gole --- .github/workflows/build.yml | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..3d30661ce --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: Build + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + container: zephyrprojectrtos/ci:latest + env: + CMAKE_PREFIX_PATH: /opt/toolchains + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + path: Arduino-Zephyr-API + + - name: Initialize + working-directory: Arduino-Zephyr-API + run: | + west init -m https://github.com/zephyrproject-rtos/gsoc-2022-arduino-core.git + west update + git clone https://github.com/arduino/ArduinoCore-API.git ArduinoCore-API + sed '/WCharacter.h/ s/./\/\/ &/' ArduinoCore-API/api/ArduinoAPI.h > ArduinoCore-API/api/tmpArduinoAPI.h + mv ArduinoCore-API/api/tmpArduinoAPI.h ArduinoCore-API/api/ArduinoAPI.h + cp -r ArduinoCore-API/api modules/lib/Arduino-Zephyr-API/cores/arduino/. + + - name: Build fade + working-directory: Arduino-Zephyr-API + run: | + west build -p -b arduino_nano_33_ble_sense samples/fade + + - name: Build i2cdemo + working-directory: Arduino-Zephyr-API + run: | + west build -p -b arduino_nano_33_ble_sense samples/i2cdemo + + - name: Archive firmware + uses: actions/upload-artifact@v2 + with: + name: firmware + path: Arduino-Zephyr-API/build/zephyr/zephyr.* From e08deb1936cd8a8e7e84e1fd9a45a9b4f71c1cd4 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 20 Nov 2022 06:49:16 +0900 Subject: [PATCH 03/11] variant: Rename LED_BUILTIN_FIND_DIGITAL_PIN for generally purpuse Signed-off-by: TOKITA Hiroshi --- variants/variants.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/variants/variants.h b/variants/variants.h index 1fdea12a8..1983e405a 100644 --- a/variants/variants.h +++ b/variants/variants.h @@ -44,7 +44,7 @@ (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 LED_BUILTIN_FIND_DIGITAL_PIN(dev, pin) \ +#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) @@ -58,7 +58,7 @@ #warning "pin not found in digital_pin_gpios" #else #define LED_BUILTIN \ - LED_BUILTIN_FIND_DIGITAL_PIN( \ + 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 @@ -72,7 +72,7 @@ #warning "pin not found in digital_pin_gpios" #else #define LED_BUILTIN \ - LED_BUILTIN_FIND_DIGITAL_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \ + 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 From 453d857b1047a38b936c9f6c5395191383bc31d0 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 20 Nov 2022 06:49:47 +0900 Subject: [PATCH 04/11] 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 --- cores/arduino/zephyrCommon.cpp | 14 ++++++++++---- variants/variants.h | 6 ++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 9eda0bd17..219d3cdaf 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -113,14 +113,17 @@ void handleGpioCallback(const struct device *port, struct gpio_callback *cb, uin #ifdef CONFIG_PWM #define PWM_DT_SPEC(n,p,i) PWM_DT_SPEC_GET_BY_IDX(n, i), -#define PWM_PINS(n,p,i) DT_PROP_BY_IDX(n, p, i), +#define 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)), 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_pins, 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 Date: Sun, 20 Nov 2022 06:48:59 +0900 Subject: [PATCH 05/11] variants: Apply GPIO cell based PWM and ADC node configuration Signed-off-by: TOKITA Hiroshi --- .../arduino_mkrzero/arduino_mkrzero.overlay | 13 +++++++++-- .../arduino_nano_33_ble.overlay | 23 +++++++++++++++---- .../arduino_nano_33_ble_sense.overlay | 23 +++++++++++++++---- .../arduino_nano_33_iot.overlay | 20 ++++++++++++++-- .../nrf52840dk_nrf52840.overlay | 17 ++++++++++++-- 5 files changed, 82 insertions(+), 14 deletions(-) diff --git a/variants/arduino_mkrzero/arduino_mkrzero.overlay b/variants/arduino_mkrzero/arduino_mkrzero.overlay index a5505b486..4e69fbc92 100644 --- a/variants/arduino_mkrzero/arduino_mkrzero.overlay +++ b/variants/arduino_mkrzero/arduino_mkrzero.overlay @@ -32,9 +32,19 @@ <&arduino_mkr_header 21 0>, <&portb 8 0>; + pwm-pin-gpios = <&arduino_mkr_header 2 0>, + <&arduino_mkr_header 3 0>; + + adc-pin-gpios = <&arduino_mkr_header 15 0>, + <&arduino_mkr_header 16 0>, + <&arduino_mkr_header 17 0>, + <&arduino_mkr_header 18 0>, + <&arduino_mkr_header 19 0>, + <&arduino_mkr_header 20 0>, + <&arduino_mkr_header 21 0>; + pwms = <&tcc0 2 255>, <&tcc0 3 255>; - pwm-pins = <2 3>; io-channels = <&adc 0>, <&adc 10>, @@ -43,7 +53,6 @@ <&adc 5>, <&adc 6>, <&adc 7>; - io-channel-pins = <15 16 17 18 19 20 21>; serials = <&sercom5>; i2cs = <&sercom0>; diff --git a/variants/arduino_nano_33_ble/arduino_nano_33_ble.overlay b/variants/arduino_nano_33_ble/arduino_nano_33_ble.overlay index 6f8d0bed3..6c8f9754d 100644 --- a/variants/arduino_nano_33_ble/arduino_nano_33_ble.overlay +++ b/variants/arduino_nano_33_ble/arduino_nano_33_ble.overlay @@ -23,6 +23,25 @@ <&arduino_nano_header 20 0>, <&arduino_nano_header 21 0>; + pwm-pin-gpios = <&arduino_nano_header 3 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 6 0>, + <&arduino_nano_header 13 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>, + <&arduino_nano_header 11 0>; + + adc-pin-gpios = <&arduino_nano_header 14 0>, + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, + <&arduino_nano_header 19 0>, + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + builtin-led-gpios = <&arduino_nano_header 13 0>; + pwms = <&pwm1 1 255 PWM_POLARITY_NORMAL>, <&pwm1 2 255 PWM_POLARITY_NORMAL>, <&pwm1 3 255 PWM_POLARITY_NORMAL>, @@ -30,7 +49,6 @@ <&pwm2 1 255 PWM_POLARITY_NORMAL>, <&pwm2 2 255 PWM_POLARITY_NORMAL>, <&pwm2 3 255 PWM_POLARITY_NORMAL>; - pwm-pins = <3 5 6 13 9 10 11>; io-channels = <&adc 2>, <&adc 3>, @@ -40,12 +58,9 @@ <&adc 0>, <&adc 4>, <&adc 1>; - io-channel-pins = <14 15 16 17 18 19 20 21>; serials = <&uart0>; i2cs = <&arduino_nano_i2c>; - - builtin-led-gpios = <&arduino_nano_header 13 0>; }; }; diff --git a/variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense.overlay b/variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense.overlay index 6f8d0bed3..6c8f9754d 100644 --- a/variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense.overlay +++ b/variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense.overlay @@ -23,6 +23,25 @@ <&arduino_nano_header 20 0>, <&arduino_nano_header 21 0>; + pwm-pin-gpios = <&arduino_nano_header 3 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 6 0>, + <&arduino_nano_header 13 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>, + <&arduino_nano_header 11 0>; + + adc-pin-gpios = <&arduino_nano_header 14 0>, + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, + <&arduino_nano_header 19 0>, + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + builtin-led-gpios = <&arduino_nano_header 13 0>; + pwms = <&pwm1 1 255 PWM_POLARITY_NORMAL>, <&pwm1 2 255 PWM_POLARITY_NORMAL>, <&pwm1 3 255 PWM_POLARITY_NORMAL>, @@ -30,7 +49,6 @@ <&pwm2 1 255 PWM_POLARITY_NORMAL>, <&pwm2 2 255 PWM_POLARITY_NORMAL>, <&pwm2 3 255 PWM_POLARITY_NORMAL>; - pwm-pins = <3 5 6 13 9 10 11>; io-channels = <&adc 2>, <&adc 3>, @@ -40,12 +58,9 @@ <&adc 0>, <&adc 4>, <&adc 1>; - io-channel-pins = <14 15 16 17 18 19 20 21>; serials = <&uart0>; i2cs = <&arduino_nano_i2c>; - - builtin-led-gpios = <&arduino_nano_header 13 0>; }; }; diff --git a/variants/arduino_nano_33_iot/arduino_nano_33_iot.overlay b/variants/arduino_nano_33_iot/arduino_nano_33_iot.overlay index 899fcb53c..d99109799 100644 --- a/variants/arduino_nano_33_iot/arduino_nano_33_iot.overlay +++ b/variants/arduino_nano_33_iot/arduino_nano_33_iot.overlay @@ -25,6 +25,24 @@ <&arduino_nano_header 20 0>, <&arduino_nano_header 21 0>; + pwm-pin-gpios = <&arduino_nano_header 6 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 12 0>, + <&arduino_nano_header 2 0>, + <&arduino_nano_header 3 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>; + + adc-pin-gpios = <&arduino_nano_header 14 0>, + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, + <&arduino_nano_header 19 0>, + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + pwms = <&tcc0 0 255>, <&tcc0 1 255>, <&tcc0 2 255>, @@ -33,7 +51,6 @@ <&tcc0 5 255>, <&tcc0 6 255>, <&tcc0 7 255>; - pwm-pins = <6 5 17 12 2 3 9 10>; io-channels = <&adc 0>, <&adc 10>, @@ -42,7 +59,6 @@ <&adc 5>, <&adc 6>, <&adc 7>; - io-channel-pins = <14 15 16 17 18 19 20 21>; serials = <&sercom5>; i2cs = <&arduino_nano_i2c>; diff --git a/variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840.overlay b/variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840.overlay index c648749f2..220208215 100644 --- a/variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840.overlay +++ b/variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840.overlay @@ -24,13 +24,27 @@ <&arduino_header 5 0>, <&gpio0 13 GPIO_ACTIVE_LOW>; + pwm-pin-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>, + <&arduino_header 9 0>, + <&arduino_header 11 0>, + <&arduino_header 12 0>, + <&arduino_header 15 0>, + <&arduino_header 16 0>, + <&arduino_header 17 0>; + + adc-pin-gpios = <&arduino_header 0 0>, + <&arduino_header 1 0>, + <&arduino_header 2 0>, + <&arduino_header 3 0>, + <&arduino_header 4 0>, + <&arduino_header 5 0>; + pwms = <&pwm0 1 255 PWM_POLARITY_NORMAL>, <&pwm0 2 255 PWM_POLARITY_NORMAL>, <&pwm0 3 255 PWM_POLARITY_NORMAL>, <&pwm1 0 255 PWM_POLARITY_NORMAL>, <&pwm1 1 255 PWM_POLARITY_NORMAL>, <&pwm1 2 255 PWM_POLARITY_NORMAL>; - pwm-pins = <22 3 5 6 9 10 11>; io-channels = <&arduino_adc 0>, <&arduino_adc 1>, @@ -38,7 +52,6 @@ <&arduino_adc 3>, <&arduino_adc 4>, <&arduino_adc 5>; - io-channel-pins = <16 17 18 19 20 21>; }; }; From 0bae8e1b65e6917e8777017819420eca1e76b22b Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 20 Nov 2022 09:34:14 +0900 Subject: [PATCH 06/11] documentation: Update document about pin mapping nodes Update the document about `digital-pin-gpios` and add description for `pwm-pin-gpios` and `adc-pin-gpios` Signed-off-by: TOKITA Hiroshi --- documentation/variants.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/documentation/variants.md b/documentation/variants.md index 79e98a79d..38a100126 100644 --- a/documentation/variants.md +++ b/documentation/variants.md @@ -49,10 +49,15 @@ variants/ ### DeviceTree Overlay files for Arduino boards -This module requires that your Arduino header pins be mapped in the DeviceTree -to 'digital-pin-gpios' array that child of a `zephyr,user` node. Follow the -examples in the variants directory to create an overlay file and a header file -for your board. +The Arduino API requires pin mapping definitions to use Arduino-style pin numbers +(pin numbers printed on the board, not GPIO numbers). +The pin-mapping node is under the `zephyr,user` node of DTS. +`digital-pin-gpios` defines digital input/output pins that is D0, D1, .., +`adc-pin-gpios` defines analog input pins that is A0, A1, ... . +`pwm-pin-gpios` defines PWM pins. +Each pin specifies in the form of a GPIO cell. +Usually, it is in the form of `<[port] [pin-number] [flag]>`. +You can also use the Arduino header node definition here. ### Overlays using previously-defined Arduino headers From e43e671fc8d278bb9ccb635acd02043600efc69c Mon Sep 17 00:00:00 2001 From: Dhruva Gole Date: Sat, 15 Apr 2023 10:30:42 +0530 Subject: [PATCH 07/11] variants: Add cc3220sf Add support for the TI CC3220SF LaunchXL platform in arduino core API for zephyr. Signed-off-by: Dhruva Gole --- .../cc3220sf_launchxl.overlay | 36 +++++++++++++++++++ .../cc3220sf_launchxl_pinmap.h | 18 ++++++++++ variants/variants.h | 3 ++ 3 files changed, 57 insertions(+) create mode 100644 variants/cc3220sf_launchxl/cc3220sf_launchxl.overlay create mode 100644 variants/cc3220sf_launchxl/cc3220sf_launchxl_pinmap.h diff --git a/variants/cc3220sf_launchxl/cc3220sf_launchxl.overlay b/variants/cc3220sf_launchxl/cc3220sf_launchxl.overlay new file mode 100644 index 000000000..f1c91f6d2 --- /dev/null +++ b/variants/cc3220sf_launchxl/cc3220sf_launchxl.overlay @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ + + / { + zephyr,user { + digital-pin-gpios = <&boosterpack_header 4 0>, /* GPIO_12 */ + <&boosterpack_header 5 0>, /* GPIO_06 */ + <&boosterpack_header 7 0>, /* GPIO_14 */ + <&boosterpack_header 9 0>, /* I2C_SCL | YELLOW_LED */ + <&boosterpack_header 10 0>, /* I2C_SDA | GREEN_LED */ + <&boosterpack_header 11 0>, /* GPIO_22 */ + <&boosterpack_header 12 0>, /* GPIO_01 */ + <&boosterpack_header 13 0>, /* GPIO_25 */ + <&boosterpack_header 14 0>, /* GPIO_15 */ + <&boosterpack_header 15 0>, /* GPIO_16 */ + <&boosterpack_header 17 0>, /* GPIO_31 */ + <&boosterpack_header 18 0>, /* GPIO_17 */ + <&boosterpack_header 19 0>, /* GPIO_28 */ + <&boosterpack_header 23 0>, /* GPIO_02 | AIN0 */ + <&boosterpack_header 24 0>, /* GPIO_05 | AIN3 */ + <&boosterpack_header 25 0>, /* GPIO_03 | AIN1 */ + <&boosterpack_header 26 0>, /* GPIO_04 | AIN2 */ + <&boosterpack_header 27 0>, /* GPIO_08 */ + <&boosterpack_header 28 0>, /* GPIO_30 */ + <&boosterpack_header 29 0>, /* GPIO_09 | RED_LED | I2S_DOUT*/ + <&boosterpack_header 30 0>, /* GPIO_00 */ + <&boosterpack_header 31 0>, /* GPIO_24 */ + <&boosterpack_header 32 0>; /* GPIO_23 */ + builtin-led-gpios = <&boosterpack_header 10 0>; /* GREEN_LED */ + serials = <&boosterpack_serial>; + i2cs = <&boosterpack_i2c>; + }; + }; diff --git a/variants/cc3220sf_launchxl/cc3220sf_launchxl_pinmap.h b/variants/cc3220sf_launchxl/cc3220sf_launchxl_pinmap.h new file mode 100644 index 000000000..5eac76e0f --- /dev/null +++ b/variants/cc3220sf_launchxl/cc3220sf_launchxl_pinmap.h @@ -0,0 +1,18 @@ +/* + * 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 + +#define LED_BUILTIN 4 +#define YELLOW_LED 3 +#define GREEN_LED 4 +#define RED_LED 19 + diff --git a/variants/variants.h b/variants/variants.h index e3bf7806e..e662dab37 100644 --- a/variants/variants.h +++ b/variants/variants.h @@ -17,6 +17,9 @@ #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))) && \ From 39f7c3518ead4336314e95e0e52eb97020ffad56 Mon Sep 17 00:00:00 2001 From: Dhruva Gole Date: Sun, 23 Apr 2023 16:44:15 +0530 Subject: [PATCH 08/11] README: Update heading and also maintainers * New maintainers - Dhruva and Tokita, Hiroshi have been added. * The title has been updated to specify what the project does at the top of the README. Acked-by: Mike Szczys Acked-by: Jonathan Beri Signed-off-by: Dhruva Gole --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d941f847f..15271ee47 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ -# GSoC 2022 Project +# GSoC 2022 Project: Arduino Core API module for Zephyr ![](https://dhruvag2000.github.io/Blog-GSoC22/assets/images/website_header.png) -## Arduino Core API module for zephyr - -Arduino Core API module for zephyr leverages the power of Zephyr under an Arduino-C++ style abtraction layer thus helping zephyr new-comers to start using it without worrying about learning about new APIs and libraries. See the project documentation folder for detailed documentation on these topics: +The **Arduino Core API** module for zephyr leverages the power of Zephyr under an Arduino-C++ style abtraction layer thus helping zephyr new-comers to start using it without worrying about learning about new APIs and libraries. See the project documentation folder for detailed documentation on these topics: * [Using external Arduino Libraries](/documentation/arduino_libs.md) * [Adding custom boards/ variants](/documentation/variants.md) @@ -45,12 +43,12 @@ __NOTE:__ You can skip this step as well if you ran ``install.sh``. * While compiling with the ArduinoCore-API `WCharacter.h` produces many errors. The include of that file needs to be deleted from `cores/arduino/api/ArduinoAPI.h` (it is unused in this port.) We are looking into resolving the issue. **Maintainers**: +- [DhruvaG2000](https://github.com/DhruvaG2000) +- [soburi](https://github.com/soburi) - [szczys](https://github.com/szczys) -- [beriberikix](https://github.com/beriberikix) +- [beriberikix](https://github.com/beriberikix) - [alvarowolfx](https://github.com/alvarowolfx) -**Contributor**: [DhruvaG2000](https://github.com/DhruvaG2000) - ## License Please note that the current license is Apache 2. Previously it was LGPL 2.1 but after careful review it was determined that no LGPL code or derivates was used and the more permissive license was chosen. From 6772aff3b87759ea5aa859d748830c198a49fd2c Mon Sep 17 00:00:00 2001 From: dejan Date: Wed, 2 Aug 2023 03:04:49 +1000 Subject: [PATCH 09/11] variants: Add support for nRF9160 Add support for Nordic nRF9160 DK (Demo Kit) board. More information at https://www.nordicsemi.com/Products/Development-hardware/nRF9160-DK/GetStarte Signed-off-by: Dejan Deletic --- .../nrf9160dk_nrf9160.overlay | 192 ++++++++++++++++++ .../nrf9160dk_nrf9160_pinmap.h | 24 +++ variants/variants.h | 3 + 3 files changed, 219 insertions(+) create mode 100644 variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160.overlay create mode 100644 variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160_pinmap.h diff --git a/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160.overlay b/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160.overlay new file mode 100644 index 000000000..d69fdcb5f --- /dev/null +++ b/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160.overlay @@ -0,0 +1,192 @@ +/ { + zephyr,user { + digital-pin-gpios = + <&arduino_header 6 0>, /* Digital */ + <&arduino_header 7 0>, + <&arduino_header 8 0>, + <&arduino_header 9 0>, + <&arduino_header 10 0>, + <&arduino_header 11 0>, + <&arduino_header 12 0>, + <&arduino_header 13 0>, + <&arduino_header 14 0>, + <&arduino_header 15 0>, + <&arduino_header 16 0>, + <&arduino_header 17 0>, + <&arduino_header 18 0>, + <&arduino_header 19 0>, + <&arduino_header 20 0>, + <&arduino_header 21 0>, + <&arduino_header 0 0>, /* Analog */ + <&arduino_header 1 0>, + <&arduino_header 2 0>, + <&arduino_header 3 0>, + <&arduino_header 4 0>, + <&arduino_header 5 0>, + <&gpio0 13 GPIO_ACTIVE_LOW>; + + pwm-pin-gpios = + <&gpio0 13 GPIO_ACTIVE_LOW>, + <&arduino_header 9 0>, + <&arduino_header 11 0>, + <&arduino_header 12 0>, + <&arduino_header 15 0>, + <&arduino_header 16 0>, + <&arduino_header 17 0>; + + adc-pin-gpios = + <&arduino_header 0 0>, + <&arduino_header 1 0>, + <&arduino_header 2 0>, + <&arduino_header 3 0>, + <&arduino_header 4 0>, + <&arduino_header 5 0>; + + pwms = + <&pwm0 1 255 PWM_POLARITY_NORMAL>, + <&pwm0 2 255 PWM_POLARITY_NORMAL>, + <&pwm0 3 255 PWM_POLARITY_NORMAL>, + <&pwm1 0 255 PWM_POLARITY_NORMAL>, + <&pwm1 1 255 PWM_POLARITY_NORMAL>, + <&pwm1 2 255 PWM_POLARITY_NORMAL>; + + io-channels = + <&arduino_adc 0>, + <&arduino_adc 1>, + <&arduino_adc 2>, + <&arduino_adc 3>, + <&arduino_adc 4>, + <&arduino_adc 5>; + }; +}; + +&adc { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.02 */ + zephyr,resolution = <10>; + }; + + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.03 */ + zephyr,resolution = <10>; + }; + + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.04 */ + zephyr,resolution = <10>; + }; + + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.05 */ + zephyr,resolution = <10>; + }; + + channel@4 { + reg = <4>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.28 */ + zephyr,resolution = <10>; + }; + + channel@5 { + reg = <5>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.29 */ + zephyr,resolution = <10>; + }; + + channel@6 { + reg = <6>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.30 */ + zephyr,resolution = <10>; + }; + + channel@7 { + reg = <7>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.31 */ + zephyr,resolution = <10>; + }; +}; + +&pinctrl { + pwm0_default: pwm0_default { + group1 { + psels = , /* keep original config */ + , + , + ; + nordic,invert; + }; + }; + + pwm0_sleep: pwm0_sleep { + group1 { + psels = , /* keep original config */ + , + , + ; + low-power-enable; + }; + }; + + pwm1_default: pwm1_default { + group1 { + psels = , + , + ; + nordic,invert; + }; + }; + + pwm1_sleep: pwm1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default>; + pinctrl-1 = <&pwm1_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160_pinmap.h b/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160_pinmap.h new file mode 100644 index 000000000..e4a1fbcca --- /dev/null +++ b/variants/nrf9160dk_nrf9160/nrf9160dk_nrf9160_pinmap.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Dejan Deletic + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#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 +#define NRF9160DK_LED_4 D5 // P0.05 + +#define NRF9160DK_SWITCH_1 D6 // P0.08 +#define NRF9160DK_SWITCH_2 D7 // P0.09 +#define NRF9160DK_BUTTON_1 D8 // P0.06 +#define NRF9160DK_BUTTON_2 D9 // P0.07 + +#endif diff --git a/variants/variants.h b/variants/variants.h index e662dab37..9b7bc7dc0 100644 --- a/variants/variants.h +++ b/variants/variants.h @@ -14,6 +14,9 @@ #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 From b252469073c9ecf52c01e3747ea94029ee5459e3 Mon Sep 17 00:00:00 2001 From: dejan Date: Wed, 2 Aug 2023 03:05:46 +1000 Subject: [PATCH 10/11] samples: Fix paths to overlay files given to cmake on Windows When building samples on Windows, path to overlay file must be given in the form that cmake can understand. Which means paths must not have single backslash (\) character in them. However $ENV(ZEPHYR_BASE) contains exactly that (e.g. C:\Users\...). We fix this by passing $ENV(ZEPHYR_BASE) through cmake_path(). Signed-off-by: Dejan Deletic --- samples/analog_input/CMakeLists.txt | 3 ++- samples/attach_interrupt/CMakeLists.txt | 3 ++- samples/blinky_arduino/CMakeLists.txt | 3 ++- samples/button_press_led/CMakeLists.txt | 3 ++- samples/fade/CMakeLists.txt | 3 ++- samples/hello_arduino/CMakeLists.txt | 3 ++- samples/i2cdemo/CMakeLists.txt | 3 ++- samples/serial_event/CMakeLists.txt | 3 ++- samples/threads_arduino/CMakeLists.txt | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/samples/analog_input/CMakeLists.txt b/samples/analog_input/CMakeLists.txt index d18e0e2cc..83ac0d6bd 100644 --- a/samples/analog_input/CMakeLists.txt +++ b/samples/analog_input/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(analog_input) diff --git a/samples/attach_interrupt/CMakeLists.txt b/samples/attach_interrupt/CMakeLists.txt index 84dffa81b..711b9673b 100644 --- a/samples/attach_interrupt/CMakeLists.txt +++ b/samples/attach_interrupt/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(attach_interrupt) diff --git a/samples/blinky_arduino/CMakeLists.txt b/samples/blinky_arduino/CMakeLists.txt index 58cf0b3b0..e5c58ee33 100644 --- a/samples/blinky_arduino/CMakeLists.txt +++ b/samples/blinky_arduino/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(blinky) diff --git a/samples/button_press_led/CMakeLists.txt b/samples/button_press_led/CMakeLists.txt index 58cf0b3b0..e5c58ee33 100644 --- a/samples/button_press_led/CMakeLists.txt +++ b/samples/button_press_led/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(blinky) diff --git a/samples/fade/CMakeLists.txt b/samples/fade/CMakeLists.txt index a1142a948..6f3c4cffa 100644 --- a/samples/fade/CMakeLists.txt +++ b/samples/fade/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(fade) diff --git a/samples/hello_arduino/CMakeLists.txt b/samples/hello_arduino/CMakeLists.txt index 72fb07439..0675b10d1 100644 --- a/samples/hello_arduino/CMakeLists.txt +++ b/samples/hello_arduino/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(hello_world) diff --git a/samples/i2cdemo/CMakeLists.txt b/samples/i2cdemo/CMakeLists.txt index 664bc247c..e79ab241b 100644 --- a/samples/i2cdemo/CMakeLists.txt +++ b/samples/i2cdemo/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(blinky) diff --git a/samples/serial_event/CMakeLists.txt b/samples/serial_event/CMakeLists.txt index 4053955ba..a275e3cc2 100644 --- a/samples/serial_event/CMakeLists.txt +++ b/samples/serial_event/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(serial_event) diff --git a/samples/threads_arduino/CMakeLists.txt b/samples/threads_arduino/CMakeLists.txt index 3e97b7b23..f9aea636e 100644 --- a/samples/threads_arduino/CMakeLists.txt +++ b/samples/threads_arduino/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.20.0) -set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(threads) From aa2150b05e7589501c5f05692f802106b97cbe9b Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Mon, 21 Aug 2023 20:15:38 +0900 Subject: [PATCH 11/11] zephyrSerial: Fix misdetection arduino_serial1 DT_NODE_EXISTS value is true even if the status is disabled, so it caused misdetection. Use DT_NODE_HAS_STATUS to detect the status of the arduino_serial1 node is ok. Signed-off-by: TOKITA Hiroshi --- cores/arduino/zephyrSerial.cpp | 2 +- cores/arduino/zephyrSerial.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/zephyrSerial.cpp b/cores/arduino/zephyrSerial.cpp index f9d79f1c4..d25682679 100644 --- a/cores/arduino/zephyrSerial.cpp +++ b/cores/arduino/zephyrSerial.cpp @@ -186,7 +186,7 @@ arduino::ZephyrSerial Serial(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), serials, DECLARE_SERIAL_N) #endif // PROP_LEN(serials) > 1 -#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_serial)) +#elif DT_NODE_HAS_STATUS(DT_NODELABEL(arduino_serial), okay) /* If serials node is not defined, tries to use arduino_serial */ arduino::ZephyrSerial Serial(DEVICE_DT_GET(DT_NODELABEL(arduino_serial))); #else diff --git a/cores/arduino/zephyrSerial.h b/cores/arduino/zephyrSerial.h index 72703504c..b62e54f64 100644 --- a/cores/arduino/zephyrSerial.h +++ b/cores/arduino/zephyrSerial.h @@ -92,7 +92,7 @@ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), serials, DECLARE_EXTERN_SERIAL_N) #undef EXTERN_SERIAL_N #undef SERIAL_DEFINED_0 #endif -#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_serial)) +#elif DT_NODE_HAS_STATUS(DT_NODELABEL(arduino_serial), okay) extern arduino::ZephyrSerial Serial; #else extern arduino::ZephyrSerialStub Serial;