void pin_config (pin_obj_t *self, uint af, uint mode, uint type, uint strength) { // configure the pin in analog mode self->af = af, self->mode = mode, self->type = type, self->strength = strength; pin_obj_configure ((const pin_obj_t *)self); // mark the pin as used self->isused = true; // register it with the sleep module pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure); }
STATIC mp_obj_t pin_drive(mp_uint_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_int(self->strength); } else { uint32_t strength = mp_obj_get_int(args[1]); pin_validate_drive (strength); self->strength = strength; pin_obj_configure(self); return mp_const_none; } }
STATIC mp_obj_t pin_mode(mp_uint_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_int(self->mode); } else { uint32_t mode = mp_obj_get_int(args[1]); pin_validate_mode (mode); self->mode = mode; pin_obj_configure(self); return mp_const_none; } }
void pin_config (pin_obj_t *self, int af, uint mode, uint pull, int value, uint strength) { self->mode = mode, self->pull = pull, self->strength = strength; // if af is -1, then we want to keep it as it is if (af != -1) { self->af = af; } // if value is -1, then we want to keep it as it is if (value != -1) { self->value = value; } // mark the pin as used self->used = true; pin_obj_configure ((const pin_obj_t *)self); // register it with the sleep module pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure); }
STATIC mp_obj_t pin_pull(mp_uint_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { if (self->pull == PIN_TYPE_STD) { return mp_const_none; } return mp_obj_new_int(self->pull); } else { uint32_t pull; if (args[1] == mp_const_none) { pull = PIN_TYPE_STD; } else { pull = mp_obj_get_int(args[1]); pin_validate_pull (pull); } self->pull = pull; pin_obj_configure(self); return mp_const_none; } }
STATIC mp_obj_t pin_type_fun(mp_uint_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { if (self->type == GPIO_PIN_TYPE_STD) { return mp_const_none; } return mp_obj_new_int(self->type); } else { uint32_t type; if (args[1] == mp_const_none) { type = GPIO_PIN_TYPE_STD; } else { type = mp_obj_get_int(args[1]); pin_validate_type (type); } self->type = type; pin_obj_configure(self); return mp_const_none; } }