Skip to content

Commit b9a5b1b

Browse files
Deomid Ryabkovcesantabot
authored andcommitted
Add mgos_gpio_setup_{input,output}
These serve as shortcuts and mgos_gpio_setup_output also takes care of avoiding spurious transitions by configuring level first and the mode. Previously it was impossible on platforms that need port to be enabled before mgos_gpio_write will work. CL: Add mgos_gpio_setup_{input,output} PUBLISHED_FROM=e50035368bff1100307283c760ddcbb0b2eb6f7c
1 parent b15d4fb commit b9a5b1b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

fs/api_gpio.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ let GPIO = {
66
MODE_INPUT: 0,
77
MODE_OUTPUT: 1,
88

9-
// ## **`GPIO.set_pull(pin, type)`**
9+
// ## **`GPIO.set_pull(pin, pull_type)`**
1010
// Set GPIO pin pull type.
11-
// `type` can be either `GPIO.PULL_NONE`, `GPIO.PULL_UP`, or `GPIO.PULL_DOWN`.
11+
// `pull_type` can be either `GPIO.PULL_NONE`, `GPIO.PULL_UP`, or `GPIO.PULL_DOWN`.
1212
set_pull: ffi('int mgos_gpio_set_pull(int,int)'),
1313
PULL_NONE: 0,
1414
PULL_UP: 1,
1515
PULL_DOWN: 2,
1616

17+
// ## **`GPIO.setup_input(pin, pull_type)`**
18+
// Setup pin as input and configure pull type.
19+
// `pull_type` can be either `GPIO.PULL_NONE`, `GPIO.PULL_UP`, or `GPIO.PULL_DOWN`.
20+
setup_input: ffi('int mgos_gpio_setup_input(int,int)'),
21+
22+
// ## **`GPIO.setup_output(pin, level)`**
23+
// Setup pin as output and set initial level, 0 or 1.
24+
// Avoids spurious transitions: applies level first, then sets mode.
25+
setup_output: ffi('int mgos_gpio_setup_output(int,int)'),
26+
1727
// ## **`GPIO.toggle(pin)`**
1828
// Toggle the level of certain GPIO pin.
1929
// Return value: 0 or 1, indicating the resulting pin level.

0 commit comments

Comments
 (0)