Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit 3679a9d

Browse files
DhruvaG2000beriberikix
authored andcommitted
refactor/gpio: improve config of pins
* The pins are pulled down now by default. * set to active high so they interpret phy HIGH as a 1 and vice versa * rm redundant code Signed-off-by: Dhruva Gole <goledhruva@gmail.com>
1 parent 553dfc7 commit 3679a9d

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66

77
#include "Arduino.h"
88

9+
/*
10+
* We have initialised all pins by default to pull down
11+
* inorder to not have random floating voltages in pins
12+
* The ACTIVE_HIGH flag is set so that A low physical
13+
* level on the pin will be interpreted as value 0.
14+
* A high physical level will be interpreted as value 1
15+
*/
916
void pinMode(pin_size_t pinNumber, PinMode pinMode) {
1017
if (pinMode == INPUT || pinMode == INPUT_PULLDOWN) { // input mode
1118
gpio_pin_configure_dt(arduino_pins[pinNumber],
12-
GPIO_INPUT | GPIO_ACTIVE_LOW);
19+
GPIO_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH);
1320
} else { // output mode
14-
gpio_pin_configure_dt(arduino_pins[pinNumber], GPIO_OUTPUT);
21+
gpio_pin_configure_dt(arduino_pins[pinNumber],
22+
GPIO_OUTPUT_LOW | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH);
1523
}
1624
}
1725

1826
void digitalWrite(pin_size_t pinNumber, PinStatus status) {
19-
if (status == HIGH) {
20-
gpio_pin_set_dt(arduino_pins[pinNumber], GPIO_ACTIVE_HIGH);
21-
} else if (status == LOW) {
22-
gpio_pin_set_dt(arduino_pins[pinNumber], GPIO_ACTIVE_LOW);
23-
}
27+
gpio_pin_set_dt(arduino_pins[pinNumber], status);
2428
}
2529

2630
PinStatus digitalRead(pin_size_t pinNumber) {
27-
if (pinNumber >= 100) {
28-
pinNumber -= 100;
29-
return (gpio_pin_get_dt(arduino_pins[pinNumber]) == 1) ? HIGH : LOW;
30-
}
3131
return (gpio_pin_get_dt(arduino_pins[pinNumber]) == 1) ? HIGH : LOW;
3232
}
3333

variants/ARDUINO_NANO33BLE/arduino_nano_ble_sense_pinmap.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
1515
static struct gpio_dt_spec d1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
1616
static struct gpio_dt_spec d2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
17-
static struct gpio_dt_spec d3 =
18-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
17+
static struct gpio_dt_spec d3 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
1918
static struct gpio_dt_spec d4 =
2019
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
2120
static struct gpio_dt_spec d5 =

0 commit comments

Comments
 (0)