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

Commit 5009acc

Browse files
committed
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 <mike@golioth.io>
1 parent 529f77d commit 5009acc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
#include "Arduino.h"
88

99
/*
10-
* We have initialised all pins by default to pull down
11-
* inorder to not have random floating voltages in pins
1210
* The ACTIVE_HIGH flag is set so that A low physical
1311
* level on the pin will be interpreted as value 0.
1412
* A high physical level will be interpreted as value 1
1513
*/
1614
void pinMode(pin_size_t pinNumber, PinMode pinMode) {
17-
if (pinMode == INPUT || pinMode == INPUT_PULLDOWN) { // input mode
15+
if (pinMode == INPUT) { // input mode
16+
gpio_pin_configure_dt(arduino_pins[pinNumber],
17+
GPIO_INPUT | GPIO_ACTIVE_HIGH);
18+
} else if (pinMode == INPUT_PULLUP) { // input with internal pull-up
19+
gpio_pin_configure_dt(arduino_pins[pinNumber],
20+
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_HIGH);
21+
} else if (pinMode == INPUT_PULLDOWN) { // input with internal pull-down
1822
gpio_pin_configure_dt(arduino_pins[pinNumber],
1923
GPIO_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH);
20-
} else { // output mode
24+
} else if (pinMode == OUTPUT) { // output mode
2125
gpio_pin_configure_dt(arduino_pins[pinNumber],
2226
GPIO_OUTPUT_LOW | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH);
2327
}

0 commit comments

Comments
 (0)