mp_obj_t mod_citrus_ptmsysm_configure_new3ds_cpu(mp_obj_t enable_highspeed, mp_obj_t enable_cache) { int cpu = mp_obj_is_true(enable_highspeed) ? 1 : 0; int l2 = mp_obj_is_true(enable_cache) ? (1 << 1) : 0; u8 val = cpu | l2; return mp_obj_new_int(PTMSYSM_ConfigureNew3DSCPU(val)); }
// config_cursor method mp_obj_t pyb_lcd_config_cursor(mp_obj_t self_in,mp_obj_t cursorOnOffObj,mp_obj_t blinkOnOffObj) { uint8_t cursorOnOff=0; if(mp_obj_is_true(cursorOnOffObj)) cursorOnOff=1; uint8_t blinkOnOff=0; if(mp_obj_is_true(blinkOnOffObj)) blinkOnOff=1; mp_hal_configCursorLCD(cursorOnOff,blinkOnOff); return mp_const_none; }
/// \classmethod debug([state]) /// Get or set the debugging state (`True` or `False` for on or off). STATIC mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) { if (n_args > 1) { pin_class_debug = mp_obj_is_true(args[1]); return mp_const_none; } return mp_obj_new_bool(pin_class_debug); }
// method socket.setblocking(flag) STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) { if (mp_obj_is_true(blocking)) { return socket_settimeout(self_in, mp_const_none); } else { return socket_settimeout(self_in, MP_OBJ_NEW_SMALL_INT(0)); } }
STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t is800k) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); esp_neopixel_write(mp_obj_get_pin_obj(pin)->phys_port, (uint8_t*)bufinfo.buf, bufinfo.len, mp_obj_is_true(is800k)); return mp_const_none; }
STATIC mp_obj_t mod_citrus_gfx_set_double_buffering(mp_obj_t which, mp_obj_t enabled) { int screen = _mod_citrus_gfx_get_gfx_screen(which); gfxSetDoubleBuffering(screen, mp_obj_is_true(enabled)); return mp_const_none; }
STATIC mp_obj_t mod_citrus_gfx_config_screen(mp_obj_t which, mp_obj_t immediate) { int screen = _mod_citrus_gfx_get_gfx_screen(which); gfxConfigScreen(screen, mp_obj_is_true(immediate)); return mp_const_none; }
/// \classmethod debug([state]) /// Get or set the debugging state (`True` or `False` for on or off). STATIC mp_obj_t pin_debug(uint n_args, mp_obj_t *args) { if (n_args > 1) { pin_class_debug = mp_obj_is_true(args[1]); return mp_const_none; } return MP_BOOL(pin_class_debug); }
mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self) { mp_obj_t l_in = stream_unbuffered_readline(1, &self); if (mp_obj_is_true(l_in)) { return l_in; } return MP_OBJ_STOP_ITERATION; }
STATIC mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); wifi_mode_t mode; if (!wifi_started) { mode = WIFI_MODE_NULL; } else { ESP_EXCEPTIONS(esp_wifi_get_mode(&mode)); } int bit = (self->if_id == WIFI_IF_STA) ? WIFI_MODE_STA : WIFI_MODE_AP; if (n_args > 1) { bool active = mp_obj_is_true(args[1]); mode = active ? (mode | bit) : (mode & ~bit); if (mode == WIFI_MODE_NULL) { if (wifi_started) { ESP_EXCEPTIONS(esp_wifi_stop()); wifi_started = false; } } else { ESP_EXCEPTIONS(esp_wifi_set_mode(mode)); if (!wifi_started) { ESP_EXCEPTIONS(esp_wifi_start()); wifi_started = true; } } } return (mode & bit) ? mp_const_true : mp_const_false; }
void mp_arg_parse_all(mp_uint_t n_pos, const mp_obj_t *pos, mp_map_t *kws, mp_uint_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals) { mp_uint_t pos_found = 0, kws_found = 0; for (mp_uint_t i = 0; i < n_allowed; i++) { mp_obj_t given_arg; if (i < n_pos) { if (allowed[i].flags & MP_ARG_KW_ONLY) { goto extra_positional; } pos_found++; given_arg = pos[i]; } else { mp_map_elem_t *kw = mp_map_lookup(kws, MP_OBJ_NEW_QSTR(allowed[i].qst), MP_MAP_LOOKUP); if (kw == NULL) { if (allowed[i].flags & MP_ARG_REQUIRED) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { mp_arg_error_terse_mismatch(); } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' argument required", qstr_str(allowed[i].qst))); } } out_vals[i] = allowed[i].defval; continue; } else { kws_found++; given_arg = kw->value; } } if ((allowed[i].flags & MP_ARG_KIND_MASK) == MP_ARG_BOOL) { out_vals[i].u_bool = mp_obj_is_true(given_arg); } else if ((allowed[i].flags & MP_ARG_KIND_MASK) == MP_ARG_INT) { out_vals[i].u_int = mp_obj_get_int(given_arg); } else if ((allowed[i].flags & MP_ARG_KIND_MASK) == MP_ARG_OBJ) { out_vals[i].u_obj = given_arg; } else { assert(0); } } if (pos_found < n_pos) { extra_positional: if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { mp_arg_error_terse_mismatch(); } else { // TODO better error message nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "extra positional arguments given")); } } if (kws_found < kws->used) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { mp_arg_error_terse_mismatch(); } else { // TODO better error message nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "extra keyword arguments given")); } } }
STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); if (!mp_obj_is_true(binary_form)) { mp_raise_NotImplementedError(NULL); } const mbedtls_x509_crt* peer_cert = mbedtls_ssl_get_peer_cert(&o->ssl); return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len); }
STATIC mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) { if (n_args) { mperror_enable_heartbeat (mp_obj_is_true(args[0])); return mp_const_none; } else { return mp_obj_new_bool(mperror_is_heartbeat_enabled()); } }
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { // Currently supports only blocking mode (void)self_in; if (!mp_obj_is_true(flag_in)) { mp_not_implemented(""); } return mp_const_none; }
static mp_obj_t pin_map_obj_debug(uint n_args, mp_obj_t *args) { pin_map_obj_t *self = args[0]; if (n_args > 1) { self->debug = mp_obj_is_true(args[1]); return mp_const_none; } return MP_BOOL(self->debug); }
STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[pin_INIT_NUM_ARGS]; mp_arg_parse_all(n_args, pos_args, kw_args, pin_INIT_NUM_ARGS, pin_init_args, args); // get the io mode uint mode = args[0].u_int; pin_validate_mode(mode); // get the pull type uint pull; if (args[1].u_obj == mp_const_none) { pull = PIN_TYPE_STD; } else { pull = mp_obj_get_int(args[1].u_obj); pin_validate_pull (pull); } // get the value int value = -1; if (args[2].u_obj != MP_OBJ_NULL) { if (mp_obj_is_true(args[2].u_obj)) { value = 1; } else { value = 0; } } // get the strenght uint strength = args[3].u_int; pin_validate_drive(strength); // get the alternate function int af = args[4].u_int; if (mode != GPIO_DIR_MODE_ALT && mode != GPIO_DIR_MODE_ALT_OD) { if (af == -1) { af = 0; } else { goto invalid_args; } } else if (af < -1 || af > 15) { goto invalid_args; } // check for a valid af and then free it from any other pins if (af > PIN_MODE_0) { uint8_t fn, unit, type; pin_validate_af (self, af, &fn, &unit, &type); pin_free_af_from_pins(fn, unit, type); } pin_config (self, af, mode, pull, value, strength); return mp_const_none; invalid_args: nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); }
STATIC mp_obj_t lwip_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { lwip_socket_obj_t *socket = self_in; bool val = mp_obj_is_true(flag_in); if (val) { socket->timeout = -1; } else { socket->timeout = 0; } return mp_const_none; }
STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); if (n_args == 0) { return mp_const_false; } else { return mp_obj_new_bool(mp_obj_is_true(args[0])); } }
STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) { mp_obj_t iterable = mp_getiter(o_in); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) { if (!mp_obj_is_true(item)) { return mp_const_false; } } return mp_const_true; }
STATIC mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) { if (machine_rtc_config.ext0_pin != -1) { mp_raise_ValueError("no resources"); } //nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "touchpad wakeup not available for this version of ESP-IDF")); machine_rtc_config.wake_on_touch = mp_obj_is_true(wake); return mp_const_none; }
STATIC mp_obj_t mod_citrus_gfx_init(mp_obj_t top_format, mp_obj_t bottom_format, mp_obj_t vram_buffers) { INIT_ONCE(_mod_citrus_gfx_is_init); int top = _mod_citrus_gsp_get_framebuffer_format(top_format); int bot = _mod_citrus_gsp_get_framebuffer_format(bottom_format); gfxInit(top, bot, mp_obj_is_true(vram_buffers)); return mp_const_none; }
STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) { mp_obj_t iterable = mp_getiter(o_in); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (mp_obj_is_true(item)) { return mp_const_true; } } return mp_const_false; }
static mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { bool result; if (mp_obj_is_true(state)) { result = sdcard_power_on(); } else { sdcard_power_off(); result = true; } return MP_BOOL(result); }
STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { bool result; if (mp_obj_is_true(state)) { result = sdcard_power_on(); } else { sdcard_power_off(); result = true; } return mp_obj_new_bool(result); }
STATIC mp_obj_t bool_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); switch (n_args) { case 0: return mp_const_false; case 1: default: // must be 0 or 1 if (mp_obj_is_true(args[0])) { return mp_const_true; } else { return mp_const_false; } } }
// TODO take an optional extra argument (what does it do exactly?) STATIC mp_obj_t stream_unbuffered_readlines(mp_obj_t self) { mp_obj_t lines = mp_obj_new_list(0, NULL); for (;;) { mp_obj_t line = stream_unbuffered_readline(1, &self); if (!mp_obj_is_true(line)) { break; } mp_obj_list_append(lines, line); } return lines; }
// fast method for getting/setting pin value STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (n_args == 0) { // get pin return MP_OBJ_NEW_SMALL_INT(mp_hal_pin_read(self)); } else { // set pin mp_hal_pin_write(self, mp_obj_is_true(args[0])); return mp_const_none; } }
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); int val = mp_obj_is_true(flag_in); int flags = fcntl(self->fd, F_GETFL, 0); RAISE_ERRNO(flags, errno); if (val) { flags &= ~O_NONBLOCK; } else { flags |= O_NONBLOCK; } flags = fcntl(self->fd, F_SETFL, flags); RAISE_ERRNO(flags, errno); return mp_const_none; }
/// \method value([value]) /// Get or set the digital logic level of the pin: /// /// - With no arguments, return 0 or 1 depending on the logic level of the pin. /// - With `value` given, set the logic level of the pin. `value` can be /// anything that converts to a boolean. If it converts to `True`, the pin /// is set high, otherwise it is set low. STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { // get the pin value return MP_OBJ_NEW_SMALL_INT(MAP_GPIOPinRead(self->port, self->bit) ? 1 : 0); } else { // set the pin value if (mp_obj_is_true(args[1])) { MAP_GPIOPinWrite(self->port, self->bit, self->bit); } else { MAP_GPIOPinWrite(self->port, self->bit, 0); } return mp_const_none; } }
/// \method value([value]) /// Get or set the digital logic level of the pin: /// /// - With no argument, return 0 or 1 depending on the logic level of the pin. /// - With `value` given, set the logic level of the pin. `value` can be /// anything that converts to a boolean. If it converts to `True`, the pin /// is set high, otherwise it is set low. STATIC mp_obj_t pin_value(uint n_args, mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { // get pin return MP_OBJ_NEW_SMALL_INT(GPIO_read_pin(self->gpio, self->pin)); } else { // set pin if (mp_obj_is_true(args[1])) { GPIO_set_pin(self->gpio, self->pin_mask); } else { GPIO_clear_pin(self->gpio, self->pin_mask); } return mp_const_none; } }