|
6 | 6 |
|
7 | 7 | #include "Arduino.h" |
8 | 8 |
|
| 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 | + */ |
9 | 16 | void pinMode(pin_size_t pinNumber, PinMode pinMode) { |
10 | 17 | if (pinMode == INPUT || pinMode == INPUT_PULLDOWN) { // input mode |
11 | 18 | gpio_pin_configure_dt(arduino_pins[pinNumber], |
12 | | - GPIO_INPUT | GPIO_ACTIVE_LOW); |
| 19 | + GPIO_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH); |
13 | 20 | } 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); |
15 | 23 | } |
16 | 24 | } |
17 | 25 |
|
18 | 26 | 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); |
24 | 28 | } |
25 | 29 |
|
26 | 30 | 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 | | - } |
31 | 31 | return (gpio_pin_get_dt(arduino_pins[pinNumber]) == 1) ? HIGH : LOW; |
32 | 32 | } |
33 | 33 |
|
|
0 commit comments