Skip to content

Commit b64af5a

Browse files
committed
Add INPUT_PULLUP
1 parent 24b6a74 commit b64af5a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/gpio.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#include "driver/gpio.h"
55

6+
#define GPIO_MODE_DEF_PULLUP (BIT3)
7+
#define GPIO_MODE_INPUT_PULLUP ((GPIO_MODE_INPUT)|(GPIO_MODE_DEF_PULLUP))
8+
69
static mrb_value
710
mrb_esp32_gpio_pin_mode(mrb_state *mrb, mrb_value self) {
811
mrb_value pin, dir;
@@ -13,7 +16,12 @@ mrb_esp32_gpio_pin_mode(mrb_state *mrb, mrb_value self) {
1316
return mrb_nil_value();
1417
}
1518

16-
gpio_set_direction(mrb_fixnum(pin), mrb_fixnum(dir));
19+
gpio_pad_select_gpio(mrb_fixnum(pin));
20+
gpio_set_direction(mrb_fixnum(pin), mrb_fixnum(dir) & ~GPIO_MODE_DEF_PULLUP);
21+
22+
if (mrb_fixnum(dir) & GPIO_MODE_DEF_PULLUP) {
23+
gpio_set_pull_mode(mrb_fixnum(pin), GPIO_PULLUP_ONLY);
24+
}
1725

1826
return self;
1927
}
@@ -108,6 +116,7 @@ mrb_mruby_esp32_gpio_gem_init(mrb_state* mrb)
108116
mrb_define_const(mrb, constants, "HIGH", mrb_fixnum_value(1));
109117

110118
mrb_define_const(mrb, constants, "INPUT", mrb_fixnum_value(GPIO_MODE_INPUT));
119+
mrb_define_const(mrb, constants, "INPUT_PULLUP", mrb_fixnum_value(GPIO_MODE_INPUT_PULLUP));
111120
mrb_define_const(mrb, constants, "OUTPUT", mrb_fixnum_value(GPIO_MODE_OUTPUT));
112121
}
113122

0 commit comments

Comments
 (0)