8000 esp32/machine_pin: Add mode and pull in machine_pin_print(). · micropython/micropython@3598998 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3598998

Browse files
committed
esp32/machine_pin: Add mode and pull in machine_pin_print().
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
1 parent 611d8f9 commit 3598998

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

ports/esp32/machine_pin.c

100644100755
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,29 @@ gpio_num_t machine_pin_get_id(mp_obj_t pin_in) {
129129

130130
static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
131131
machine_pin_obj_t *self = self_in;
132-
mp_printf(print, "Pin(%u)", PIN_OBJ_PTR_INDEX(self));
132+
gpio_num_t gpio_num = PIN_OBJ_PTR_INDEX(self);
133+
134+
bool pu, pd, ie, oe, od, slp_sel;
135+
uint32_t drv, fun_sel, sig_out;
136+
gpio_get_io_config(gpio_num, &pu, &pd, &ie, &oe, &od, &drv, &fun_sel, &sig_out, &slp_sel);
137+
138+
mp_printf(print, "Pin(%u", gpio_num);
139+
if (oe) {
140+
mp_printf(print, ", mode=Pin.OUT");
141+
} else if (od) {
142+
mp_printf(print, ", mode=Pin.OPEN_DRAIN");
143+
} else if (ie) {
144+
mp_printf(print, ", mode=Pin.IN");
145+
}
146+
if (pu) {
147+
mp_printf(print, ", pull=Pin.PULL_UP");
148+
} else if (pd) {
149+
mp_printf(print, ", pull=Pin.PULL_DOWN");
150+
}
151+
if (drv != GPIO_DRIVE_CAP_2) {
152+
mp_printf(print, ", drive=Pin.DRIVE_%u", drv);
153+
}
154+
mp_printf(print, ")");
133155
}
134156

135157
// pin.init(mode=None, pull=-1, *, value, drive, hold)

0 commit comments

Comments
 (0)
0