8000 esp32/machine_pin: Add mode and pull in machine_pin_print() as repr() function. by IhorNehrutsa · Pull Request #12293 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

esp32/machine_pin: Add mode and pull in machine_pin_print() as repr() function. #12293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion ports/esp32/machine_pin.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,31 @@ gpio_num_t machine_pin_get_id(mp_obj_t pin_in) {

static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_pin_obj_t *self = self_in;
mp_printf(print, "Pin(%u)", PIN_OBJ_PTR_INDEX(self));
gpio_num_t gpio_num = PIN_OBJ_PTR_INDEX(self);

mp_printf(print, "Pin(%u", gpio_num);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
bool pu, pd, ie, oe, od, slp_sel;
uint32_t drv, fun_sel, sig_out;
gpio_get_io_config(gpio_num, &pu, &pd, &ie, &oe, &od, &drv, &fun_sel, &sig_out, &slp_sel);

if (oe) {
mp_printf(print, ", mode=Pin.OUT");
} else if (od) {
mp_printf(print, ", mode=Pin.OPEN_DRAIN");
} else if (ie) {
mp_printf(print, ", mode=Pin.IN");
}
if (pu) {
mp_printf(print, ", pull=Pin.PULL_UP");
} else if (pd) {
mp_printf(print, ", pull=Pin.PULL_DOWN");
}
if (drv != GPIO_DRIVE_CAP_2) {
mp_printf(print, ", drive=Pin.DRIVE_%u", drv);
}
#endif
mp_printf(print, ")");
}

// pin.init(mode=None, pull=-1, *, value, drive, hold)
Expand Down
Loading
0