From 7ca763cef1fbd0800364ca70c07caa06b70a35a0 Mon Sep 17 00:00:00 2001 From: Mike Szczys Date: Sun, 31 Jul 2022 11:27:50 -0500 Subject: [PATCH 1/3] pinMode: Set pull-up/pull-down from user code * Enable internal pull-up/down based on user code * Test for OUTPUT keyword Signed-off-by: Mike Szczys --- cores/arduino/zephyrCommon.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index da32a5201..c07723165 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -7,17 +7,21 @@ #include "Arduino.h" /* - * We have initialised all pins by default to pull down - * inorder to not have random floating voltages in pins * The ACTIVE_HIGH flag is set so that A low physical * level on the pin will be interpreted as value 0. * A high physical level will be interpreted as value 1 */ void pinMode(pin_size_t pinNumber, PinMode pinMode) { - if (pinMode == INPUT || pinMode == INPUT_PULLDOWN) { // input mode + if (pinMode == INPUT) { // input mode + 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_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_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH); - } else { // output mode + } else if (pinMode == OUTPUT) { // output mode gpio_pin_configure_dt(arduino_pins[pinNumber], GPIO_OUTPUT_LOW | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH); } From 187fd5c23ec61b377c5386bbaa15164cc4722888 Mon Sep 17 00:00:00 2001 From: Mike Szczys Date: Sun, 31 Jul 2022 11:30:33 -0500 Subject: [PATCH 2/3] README: clarify path differences and bug workaround * Explain where to look for path setting in sample code folders * Explain where to find file for the WCharacter.h workaround Signed-off-by: Mike Szczys --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77f596268..cfc9830e4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Arduino Core API module for zephyr leverages the power of Zephyr under an Arduin ## Adding Arduino Core API to Zephyr -* **Pre requisites:** It is assumed that you have zephyrproject configured and installed on your system as per the official [Get Started Guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html). The recommended path to install is `~/zephyrproject` as specified in the guide. You may face path issues if you have zephyr installed in a custom path. +* **Pre requisites:** It is assumed that you have zephyrproject configured and installed on your system as per the official [Get Started Guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html). The recommended path to install is `~/zephyrproject` as specified in the guide. If you have zephyr installed in a custom path you may need to make changes to the CMakeLists.txt file in the sample code directory when building these samples. * Add following entry to `west.yml` file in `manifest/projects` subtree of Zephyr: ``` @@ -32,7 +32,7 @@ $ ln -s ///ArduinoCore-API/api cores/arduino/. ``` **Known Bug(s):** -* While compiling with the ArduinoCore-API `WCharacter.h` produces many errors. It needs to be deleted from ArduinoAPI.h (it is unused in this port.) We are looking into resolving the issue. +* 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**: - [beriberikix](https://github.com/beriberikix) From 6cf40cb21e14621c8d62b363652f7038d8cc082b Mon Sep 17 00:00:00 2001 From: Mike Szczys Date: Sun, 31 Jul 2022 11:37:16 -0500 Subject: [PATCH 3/3] pinMode: pull-down not needed for outputs Outputs will be driven so a pull-down is not needed. Signed-off-by: Mike Szczys --- cores/arduino/zephyrCommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index c07723165..a9c053b1e 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -23,7 +23,7 @@ void pinMode(pin_size_t pinNumber, PinMode pinMode) { GPIO_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH); } else if (pinMode == OUTPUT) { // output mode gpio_pin_configure_dt(arduino_pins[pinNumber], - GPIO_OUTPUT_LOW | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH); + GPIO_OUTPUT_LOW | GPIO_ACTIVE_HIGH); } }