From 76ff01452b4b6bac7ce0024574ce7a3482deef47 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 28 Sep 2023 16:22:10 -0400 Subject: [PATCH] Trinket M0 comes up; still very much wip --- extmod/vfs_fat.c | 4 +- ports/atmel-samd/Makefile | 2 +- ports/atmel-samd/common-hal/busio/SPI.h | 24 --------- .../common-hal/i2ctarget/I2CTarget.h | 21 -------- .../espressif/bindings/espnow/ESPNowPacket.c | 18 +------ ports/espressif/mphalport.h | 27 ---------- ports/mimxrt10xx/boards/imxrt1010_evk/board.c | 34 ------------ .../mimxrt10xx/common-hal/audiobusio/I2SOut.h | 15 ------ ports/raspberrypi/bindings/cyw43/__init__.c | 3 +- ports/raspberrypi/common-hal/wifi/Monitor.c | 52 ------------------- py/circuitpy_defns.mk | 1 + py/circuitpy_mpconfig.h | 17 +----- py/gc.c | 11 +++- py/mpconfig.h | 5 ++ py/nlrmips.c | 2 +- py/obj.h | 6 +++ py/objfloat.c | 20 +++++++ py/objstr.c | 16 ++++++ py/objstr.h | 4 ++ py/runtime.c | 2 +- py/vm.c | 2 +- shared-bindings/_pew/__init__.c | 2 + shared-bindings/busio/UART.c | 33 +++++++++--- shared-bindings/digitalio/DriveMode.c | 2 +- shared-bindings/digitalio/Pull.c | 2 +- shared-bindings/displayio/TileGrid.c | 5 +- shared-bindings/fontio/Glyph.c | 20 +------ shared-bindings/pwmio/PWMOut.c | 2 +- shared-bindings/rtc/__init__.c | 2 + shared-bindings/time/__init__.c | 22 ++------ shared-bindings/usb_cdc/Serial.c | 3 +- shared-bindings/usb_midi/PortOut.c | 3 +- shared-module/board/__init__.c | 3 ++ shared-module/keypad/__init__.c | 2 + supervisor/shared/memory.c | 2 + 35 files changed, 119 insertions(+), 270 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 02910f24de..9c0da3cda6 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -104,7 +104,7 @@ STATIC void verify_fs_writable(fs_user_mount_t *vfs) { } } -#if _FS_REENTRANT +#if FF_FS_REENTRANT STATIC mp_obj_t fat_vfs_del(mp_obj_t self_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(self_in); // f_umount only needs to be called to release the sync object @@ -508,7 +508,7 @@ STATIC const mp_obj_property_t fat_vfs_label_obj = { #endif STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { - #if _FS_REENTRANT + #if FF_FS_REENTRANT { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&fat_vfs_del_obj) }, #endif { MP_ROM_QSTR(MP_QSTR_mkfs), MP_ROM_PTR(&fat_vfs_mkfs_obj) }, diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 0f01c789c6..f5cb5edf99 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -362,7 +362,7 @@ OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/candata.h $(HEADER_BUILD)/candata.h: tools/mkcandata.py | $(HEADER_BUILD) $(Q)$(PYTHON) $< > $@ -SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) +SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) $(SRC_CIRCUITPY_COMMON) # Sources that only hold QSTRs after pre-processing. SRC_QSTR_PREPROCESSOR += peripherals/samd/$(PERIPHERALS_CHIP_FAMILY)/clocks.c diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 45a81e9651..2fced6d642 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -3,11 +3,7 @@ * * The MIT License (MIT) * -<<<<<<<< HEAD:ports/atmel-samd/common-hal/busio/SPI.h * Copyright (c) 2016 Scott Shawcroft -======== - * Copyright (c) 2022 Blake W. Felt & Angus Gratton ->>>>>>>> v1.20.0:shared/tinyusb/mp_usbd.c * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +24,6 @@ * THE SOFTWARE. */ -<<<<<<<< HEAD:ports/atmel-samd/common-hal/busio/SPI.h #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H @@ -48,22 +43,3 @@ typedef struct { } busio_spi_obj_t; #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H -======== -#include - -#include "py/mpconfig.h" - -#if MICROPY_HW_ENABLE_USBDEV - -#ifndef NO_QSTR -#include "tusb.h" // TinyUSB is not avaiable when running the string preprocessor -#include "device/usbd.h" -#include "device/usbd_pvt.h" -#endif - -void usbd_task(void) { - tud_task_ext(0, false); -} - -#endif ->>>>>>>> v1.20.0:shared/tinyusb/mp_usbd.c diff --git a/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h b/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h index 20426e61cc..471abbb0bf 100644 --- a/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h +++ b/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h @@ -3,11 +3,7 @@ * * The MIT License (MIT) * -<<<<<<<< HEAD:ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h * Copyright (c) 2018 Noralf Trønnes -======== - * Copyright (c) 2013, 2014 Damien P. George ->>>>>>>> v1.20.0:ports/samd/pendsv.h * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,7 +26,6 @@ #ifndef MICROPY_INCLUDED_SAMD_PENDSV_H #define MICROPY_INCLUDED_SAMD_PENDSV_H -<<<<<<<< HEAD:ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H @@ -50,19 +45,3 @@ typedef struct { } i2ctarget_i2c_target_obj_t; #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H -======== -enum { - PENDSV_DISPATCH_SOFT_TIMER, // For later & for having at least one entry - MICROPY_BOARD_PENDSV_ENTRIES - PENDSV_DISPATCH_MAX -}; - -#define PENDSV_DISPATCH_NUM_SLOTS PENDSV_DISPATCH_MAX - -typedef void (*pendsv_dispatch_t)(void); - -void pendsv_init(void); -void pendsv_schedule_dispatch(size_t slot, pendsv_dispatch_t f); - -#endif // MICROPY_INCLUDED_SAMD_PENDSV_H ->>>>>>>> v1.20.0:ports/samd/pendsv.h diff --git a/ports/espressif/bindings/espnow/ESPNowPacket.c b/ports/espressif/bindings/espnow/ESPNowPacket.c index f8bc8e8418..cefdb1e9e8 100644 --- a/ports/espressif/bindings/espnow/ESPNowPacket.c +++ b/ports/espressif/bindings/espnow/ESPNowPacket.c @@ -43,23 +43,7 @@ //| const mp_obj_namedtuple_type_t espnow_packet_type_obj = { - .base = { - .base = { - .type = &mp_type_type - }, - .flags = MP_TYPE_FLAG_EXTENDED, - .name = MP_QSTR_ESPNowPacket, - .print = namedtuple_print, - .parent = &mp_type_tuple, - .make_new = namedtuple_make_new, - .attr = namedtuple_attr, - MP_TYPE_EXTENDED_FIELDS( - .unary_op = mp_obj_tuple_unary_op, - .binary_op = mp_obj_tuple_binary_op, - .subscr = mp_obj_tuple_subscr, - .getiter = mp_obj_tuple_getiter, - ), - }, + NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ESPNowPacket), .n_fields = 4, .fields = { MP_QSTR_mac, diff --git a/ports/espressif/mphalport.h b/ports/espressif/mphalport.h index 96b8268dc3..7ff8129903 100644 --- a/ports/espressif/mphalport.h +++ b/ports/espressif/mphalport.h @@ -38,31 +38,4 @@ bool mp_hal_stdin_any(void); -<<<<<<<< HEAD:ports/espressif/mphalport.h #endif // MICROPY_INCLUDED_ESPRESSIF_MPHAL_H -======== -int mp_hal_get_interrupt_char(void); - -#if MICROPY_VFS_POSIX - -#include - -// This macro is used to implement PEP 475 to retry specified syscalls on EINTR -#define MP_HAL_RETRY_SYSCALL(ret, syscall, raise) \ - { \ - for (;;) { \ - ret = syscall; \ - if (ret == -1) { \ - int err = errno; \ - if (err == EINTR) { \ - mp_handle_pending(true); \ - continue; \ - } \ - raise; \ - } \ - break; \ - } \ - } - -#endif ->>>>>>>> v1.20.0:ports/webassembly/mphalport.h diff --git a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c index 83162d40e5..9c7f4a256f 100644 --- a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c @@ -3,12 +3,8 @@ * * The MIT License (MIT) * -<<<<<<<< HEAD:ports/mimxrt10xx/boards/imxrt1010_evk/board.c * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries * Copyright (c) 2019 Artur Pacholec -======== - * Copyright (c) 2022 Damien P. George ->>>>>>>> v1.20.0:ports/raspberrypi/pendsv.h * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,10 +24,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_RP2_PENDSV_H -#define MICROPY_INCLUDED_RP2_PENDSV_H -<<<<<<<< HEAD:ports/mimxrt10xx/boards/imxrt1010_evk/board.c #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" @@ -52,30 +45,3 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { }; // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. -======== -#include - -enum { - #if MICROPY_PY_LWIP - PENDSV_DISPATCH_LWIP, - #endif - #if MICROPY_PY_NETWORK_CYW43 - PENDSV_DISPATCH_CYW43, - #endif - #if MICROPY_PY_NETWORK_WIZNET5K - PENDSV_DISPATCH_WIZNET, - #endif - MICROPY_BOARD_PENDSV_ENTRIES - PENDSV_DISPATCH_MAX -}; - -#define PENDSV_DISPATCH_NUM_SLOTS PENDSV_DISPATCH_MAX - -typedef void (*pendsv_dispatch_t)(void); - -void pendsv_suspend(void); -void pendsv_resume(void); -void pendsv_schedule_dispatch(size_t slot, pendsv_dispatch_t f); - -#endif // MICROPY_INCLUDED_RP2_PENDSV_H ->>>>>>>> v1.20.0:ports/raspberrypi/pendsv.h diff --git a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h index 0c2568e481..319e52c159 100644 --- a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h +++ b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h @@ -1,15 +1,9 @@ /* * This file is part of the MicroPython project, http://micropython.org/ * - * This file provides functions for configuring the clocks. - * * The MIT License (MIT) * -<<<<<<<< HEAD:ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h * Copyright (c) 2020 Jeff Epler for Adafruit Industries -======== - * Copyright (c) 2022 Robert Hammelrath ->>>>>>>> v1.20.0:ports/samd/clock_config.h * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,7 +24,6 @@ * THE SOFTWARE. */ -<<<<<<<< HEAD:ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h #pragma once // Some boards don't implement I2SOut, so suppress any routines from here. @@ -49,11 +42,3 @@ typedef struct { } audiobusio_i2sout_obj_t; #endif -======== -void init_clocks(uint32_t cpu_freq); -void set_cpu_freq(uint32_t cpu_freq); -uint32_t get_cpu_freq(void); -uint32_t get_peripheral_freq(void); -void check_usb_recovery_mode(void); -void enable_sercom_clock(int id); ->>>>>>>> v1.20.0:ports/samd/clock_config.h diff --git a/ports/raspberrypi/bindings/cyw43/__init__.c b/ports/raspberrypi/bindings/cyw43/__init__.c index 0df67f5bda..9c28686b13 100644 --- a/ports/raspberrypi/bindings/cyw43/__init__.c +++ b/ports/raspberrypi/bindings/cyw43/__init__.c @@ -54,9 +54,8 @@ void bindings_cyw43_wifi_enforce_pm() { //| MP_DEFINE_CONST_OBJ_TYPE( cyw43_pin_type, - MP_TYPE_FLAG_EXTENDED, + MP_QSTR_CywPin, MP_TYPE_FLAG_NONE, - name, MP_QSTR_CywPin, print, shared_bindings_microcontroller_pin_print, unary_op, mp_generic_unary_op, ); diff --git a/ports/raspberrypi/common-hal/wifi/Monitor.c b/ports/raspberrypi/common-hal/wifi/Monitor.c index a69dc34f02..f288cd1ea1 100644 --- a/ports/raspberrypi/common-hal/wifi/Monitor.c +++ b/ports/raspberrypi/common-hal/wifi/Monitor.c @@ -3,11 +3,7 @@ * * The MIT License (MIT) * -<<<<<<<< HEAD:ports/raspberrypi/common-hal/wifi/Monitor.c * Copyright (c) 2021 microDev -======== - * Copyright (c) 2013, 2014 Damien P. George ->>>>>>>> v1.20.0:ports/samd/pendsv.c * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +24,6 @@ * THE SOFTWARE. */ -<<<<<<<< HEAD:ports/raspberrypi/common-hal/wifi/Monitor.c #include #include "py/mpstate.h" @@ -77,50 +72,3 @@ mp_obj_t common_hal_wifi_monitor_get_queued(wifi_monitor_obj_t *self) { mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self) { return mp_const_none; } -======== -#include - -#include "py/runtime.h" -#include "shared/runtime/interrupt_char.h" -#include "sam.h" -#include "pendsv.h" - - -#if defined(PENDSV_DISPATCH_NUM_SLOTS) -uint32_t pendsv_dispatch_active; -pendsv_dispatch_t pendsv_dispatch_table[PENDSV_DISPATCH_NUM_SLOTS]; -#endif - -void pendsv_init(void) { - #if defined(PENDSV_DISPATCH_NUM_SLOTS) - pendsv_dispatch_active = false; - #endif - - // set PendSV interrupt at lowest priority - NVIC_SetPriority(PendSV_IRQn, IRQ_PRI_PENDSV); -} - -#if defined(PENDSV_DISPATCH_NUM_SLOTS) -void pendsv_schedule_dispatch(size_t slot, pendsv_dispatch_t f) { - pendsv_dispatch_table[slot] = f; - pendsv_dispatch_active = true; - SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; -} - -void pendsv_dispatch_handler(void) { - for (size_t i = 0; i < PENDSV_DISPATCH_NUM_SLOTS; ++i) { - if (pendsv_dispatch_table[i] != NULL) { - pendsv_dispatch_t f = pendsv_dispatch_table[i]; - pendsv_dispatch_table[i] = NULL; - f(); - } - } -} - -void PendSV_Handler(void) { - if (pendsv_dispatch_active) { - pendsv_dispatch_handler(); - } -} -#endif ->>>>>>>> v1.20.0:ports/samd/pendsv.c diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 8186d24b2a..392b047133 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -787,6 +787,7 @@ endif $(patsubst %.c,$(BUILD)/%.o,$(SRC_LIBM)): CFLAGS += -Wno-missing-prototypes endif +# Sources used in all ports except unix. SRC_CIRCUITPY_COMMON = \ shared/libc/string0.c \ shared/readline/readline.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 8ee5b2c9ec..f19b5ac6bb 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -316,15 +316,12 @@ typedef long mp_off_t; #if defined(DEFAULT_UART_BUS_TX) && defined(DEFAULT_UART_BUS_RX) #define CIRCUITPY_BOARD_UART (1) #define CIRCUITPY_BOARD_UART_PIN {{.tx = DEFAULT_UART_BUS_TX, .rx = DEFAULT_UART_BUS_RX}} -#define BOARD_UART_ROOT_POINTER mp_obj_t board_uart_bus; #else #define CIRCUITPY_BOARD_UART (0) -#define BOARD_UART_ROOT_POINTER #endif -#else -#define BOARD_UART_ROOT_POINTER mp_obj_t board_uart_bus; #endif + #if MICROPY_PY_ASYNC_AWAIT && !CIRCUITPY_TRACEBACK #error CIRCUITPY_ASYNCIO requires CIRCUITPY_TRACEBACK #endif @@ -359,12 +356,6 @@ typedef long mp_off_t; #define CIRCUITPY_DISPLAY_AREA_BUFFER_SIZE (0) #endif -#if CIRCUITPY_KEYPAD -#define KEYPAD_ROOT_POINTERS mp_obj_t keypad_scanners_linked_list; -#else -#define KEYPAD_ROOT_POINTERS -#endif - #if CIRCUITPY_MEMORYMONITOR #define MEMORYMONITOR_ROOT_POINTERS mp_obj_t active_allocationsizes; \ mp_obj_t active_allocationalarms; @@ -438,15 +429,9 @@ struct _supervisor_allocation_node; #define CIRCUITPY_COMMON_ROOT_POINTERS \ FLASH_ROOT_POINTERS \ - KEYPAD_ROOT_POINTERS \ - BOARD_UART_ROOT_POINTER \ WIFI_MONITOR_ROOT_POINTERS \ MEMORYMONITOR_ROOT_POINTERS \ vstr_t *repl_line; \ - mp_obj_t pew_singleton; \ - mp_obj_t rtc_time_source; \ - const char *readline_hist[MICROPY_READLINE_HISTORY_SIZE]; \ - struct _supervisor_allocation_node *first_embedded_allocation; \ void background_callback_run_all(void); #define RUN_BACKGROUND_TASKS (background_callback_run_all()) diff --git a/py/gc.c b/py/gc.c index ac0acfcc10..acb7edf873 100644 --- a/py/gc.c +++ b/py/gc.c @@ -482,13 +482,19 @@ void gc_collect_start(void) { #endif } +// CIRCUITPY +void gc_collect_ptr(void *ptr) { + void *ptrs[1] = { ptr }; + gc_collect_root(ptrs, 1); +} + // Address sanitizer needs to know that the access to ptrs[i] must always be // considered OK, even if it's a load from an address that would normally be // prohibited (due to being undefined, in a red zone, etc). #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) __attribute__((no_sanitize_address)) #endif -static void *gc_get_ptr(void **ptrs, int i) { +static void *MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_get_ptr)(void **ptrs, int i) { #if MICROPY_DEBUG_VALGRIND if (!VALGRIND_CHECK_MEM_IS_ADDRESSABLE(&ptrs[i], sizeof(*ptrs))) { return NULL; @@ -1167,7 +1173,10 @@ void gc_dump_alloc_table(const mp_print_t *print) { */ /* this prints the uPy object type of the head block */ case AT_HEAD: { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" void **ptr = (void **)(area->gc_pool_start + bl * BYTES_PER_BLOCK); + #pragma GCC diagnostic pop if (*ptr == &mp_type_tuple) { c = 'T'; } else if (*ptr == &mp_type_list) { diff --git a/py/mpconfig.h b/py/mpconfig.h index 8398562cf2..0ce5d50b57 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1745,6 +1745,11 @@ typedef double mp_float_t; #define MICROPY_PY_ONEWIRE (0) #endif +// Whether to provide the "platform" module +#ifndef MICROPY_PY_UPLATFORM +#define MICROPY_PY_UPLATFORM (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#endif + /*****************************************************************************/ /* Hooks for a port to add builtins */ diff --git a/py/nlrmips.c b/py/nlrmips.c index bd5d73b6f7..b75d06cda6 100644 --- a/py/nlrmips.c +++ b/py/nlrmips.c @@ -26,7 +26,7 @@ #include "py/mpstate.h" -#if MICROPY_NLR_MIPS +#if defined(MICROPY_NLR_MIPS) && MICROPY_NLR_MIPS __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr); diff --git a/py/obj.h b/py/obj.h index 000903c105..bb55ea3351 100644 --- a/py/obj.h +++ b/py/obj.h @@ -995,12 +995,18 @@ mp_obj_t mp_obj_new_str_from_utf8_vstr(vstr_t *vstr); // input data must be vali #endif mp_obj_t mp_obj_new_bytes_from_vstr(vstr_t *vstr); mp_obj_t mp_obj_new_bytes(const byte *data, size_t len); +// CIRCUITPY +mp_obj_t mp_obj_new_bytes_of_zeros(size_t len); mp_obj_t mp_obj_new_bytearray(size_t n, const void *items); mp_obj_t mp_obj_new_bytearray_of_zeros(size_t n); // CIRCUITPY mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items); #if MICROPY_PY_BUILTINS_FLOAT mp_obj_t mp_obj_new_int_from_float(mp_float_t val); mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag); + +// CIRCUITPY: our own conversion routines that don't bring double routines +extern mp_float_t uint64_to_float(uint64_t ui64); +extern uint64_t float_to_uint64(float f); #endif mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type); mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args); diff --git a/py/objfloat.c b/py/objfloat.c index 14c4140e51..90aeef648b 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -346,4 +346,24 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t return mp_obj_new_float(lhs_val); } +// CIRCUITPY +// Convert a uint64_t to a 32-bit float without invoking the double-precision math routines, +// which are large. +mp_float_t uint64_to_float(uint64_t ui64) { + // 4294967296 = 2^32 + return (mp_float_t)((uint32_t)(ui64 >> 32) * 4294967296.0f + (uint32_t)(ui64 & 0xffffffff)); +} + +// CIRCUITPY +// Convert a uint64_t to a 32-bit float to a uint64_t without invoking extra math routines. +// which are large. +// Assume f >= 0. +uint64_t float_to_uint64(float f) { + // 4294967296 = 2^32 + const uint32_t upper_half = (uint32_t)(f / 4294967296.0f); + const uint32_t lower_half = (uint32_t)f; + return (((uint64_t)upper_half) << 32) + lower_half; +} +#pragma GCC diagnostic pop + #endif // MICROPY_PY_BUILTINS_FLOAT diff --git a/py/objstr.c b/py/objstr.c index 818da8c109..994194540f 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -34,6 +34,13 @@ #include "py/runtime.h" #include "py/stackctrl.h" +// CIRCUITPY +const char nibble_to_hex_upper[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F'}; + +const char nibble_to_hex_lower[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f'}; + #if MICROPY_PY_BUILTINS_STR_OP_MODULO STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); #endif @@ -2323,6 +2330,15 @@ mp_obj_t mp_obj_new_bytes(const byte *data, size_t len) { return mp_obj_new_str_copy(&mp_type_bytes, data, len); } +// CIRCUITPY +mp_obj_t mp_obj_new_bytes_of_zeros(size_t len) { + vstr_t vstr; + vstr_init_len(&vstr, len); + memset(vstr.buf, 0, len); + return mp_obj_new_bytes_from_vstr(&vstr); +} + + bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { if (mp_obj_is_qstr(s1) && mp_obj_is_qstr(s2)) { return s1 == s2; diff --git a/py/objstr.h b/py/objstr.h index 604f6d7886..810742a97f 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -29,6 +29,10 @@ #include "py/obj.h" #include "py/objarray.h" +// CIRCUITPY +extern const char nibble_to_hex_upper[16]; +extern const char nibble_to_hex_lower[16]; + typedef struct _mp_obj_str_t { mp_obj_base_t base; size_t hash; diff --git a/py/runtime.c b/py/runtime.c index 8bf7505727..d83e624be1 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -44,6 +44,7 @@ #include "py/runtime.h" #include "py/builtin.h" #include "py/stackctrl.h" +#include "py/stream.h" #include "py/gc.h" #if MICROPY_DEBUG_VERBOSE // print debugging info @@ -1371,7 +1372,6 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { STATIC mp_fun_1_t type_get_iternext(const mp_obj_type_t *type) { if ((type->flags & MP_TYPE_FLAG_ITER_IS_STREAM) == MP_TYPE_FLAG_ITER_IS_STREAM) { - mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self); return mp_stream_unbuffered_iter; } else if (type->flags & MP_TYPE_FLAG_ITER_IS_ITERNEXT) { return (mp_fun_1_t)MP_OBJ_TYPE_GET_SLOT(type, iter); diff --git a/py/vm.c b/py/vm.c index 42134f5a4a..0e6c1c249d 100644 --- a/py/vm.c +++ b/py/vm.c @@ -326,7 +326,7 @@ outer_dispatch_loop: for (;;) { dispatch_loop: #if MICROPY_OPT_COMPUTED_GOTO - DISPATCH(); + ONE_TRUE_DISPATCH(); #else TRACE(ip); MARK_EXC_IP_GLOBAL(); diff --git a/shared-bindings/_pew/__init__.c b/shared-bindings/_pew/__init__.c index 435f50151a..9a0620ebab 100644 --- a/shared-bindings/_pew/__init__.c +++ b/shared-bindings/_pew/__init__.c @@ -62,3 +62,5 @@ const mp_obj_module_t pew_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&pew_module_globals, }; + +MP_REGISTER_ROOT_POINTER(mp_obj_t pew_singleton); diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 66f15b1bb8..3bb9d6eb78 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -43,7 +43,22 @@ // #define STREAM_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) //| class UART: -//| """A bidirectional serial protocol""" +//| """A bidirectional serial protocol +//| +//| .. raw:: html +//| +//|

+//|

+//| Available on these boards +//|
    +//| {% for board in support_matrix_reverse["busio.UART"] %} +//|
  • {{ board }} +//| {% endfor %} +//|
+//|
+//|

+//| +//| """ //| //| def __init__( //| self, @@ -402,12 +417,13 @@ STATIC void busio_uart_parity_print(const mp_print_t *print, mp_obj_t self_in, m mp_printf(print, "%q.%q.%q.%q", MP_QSTR_busio, MP_QSTR_UART, MP_QSTR_Parity, parity); } -const mp_obj_type_t busio_uart_parity_type = { - { &mp_type_type }, - .name = MP_QSTR_Parity, - .print = busio_uart_parity_print, - .locals_dict = (mp_obj_dict_t *)&busio_uart_parity_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + busio_uart_parity_type, + MP_QSTR_Parity, + MP_TYPE_FLAG_NONE, + print, busio_uart_parity_print, + locals_dict, &busio_uart_parity_locals_dict + ); STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = { #if CIRCUITPY_BUSIO_UART @@ -452,7 +468,8 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_ITER_IS_ITERNEXT, make_new, busio_uart_make_new, locals_dict, &busio_uart_locals_dict, - iter, mp_stream_unbuffered_iter + iter, mp_stream_unbuffered_iter, + protocol, &uart_stream_p ); #else MP_DEFINE_CONST_OBJ_TYPE( diff --git a/shared-bindings/digitalio/DriveMode.c b/shared-bindings/digitalio/DriveMode.c index 4a582d8a81..c7cde494c8 100644 --- a/shared-bindings/digitalio/DriveMode.c +++ b/shared-bindings/digitalio/DriveMode.c @@ -66,7 +66,7 @@ STATIC void digitalio_drive_mode_print(const mp_print_t *print, mp_obj_t self_in MP_DEFINE_CONST_OBJ_TYPE( digitalio_drive_mode_type, - name, MP_QSTR_DriveMode, + MP_QSTR_DriveMode, MP_TYPE_FLAG_NONE, print, digitalio_drive_mode_print, locals_dict, &digitalio_drive_mode_locals_dict diff --git a/shared-bindings/digitalio/Pull.c b/shared-bindings/digitalio/Pull.c index 58ae4fb529..3be38ef78c 100644 --- a/shared-bindings/digitalio/Pull.c +++ b/shared-bindings/digitalio/Pull.c @@ -68,8 +68,8 @@ STATIC void digitalio_pull_print(const mp_print_t *print, mp_obj_t self_in, mp_p MP_DEFINE_CONST_OBJ_TYPE( digitalio_pull_type, + MP_QSTR_Pull, MP_TYPE_FLAG_NONE, - name, MP_QSTR_Pull, print, digitalio_pull_print, locals_dict, &digitalio_pull_locals_dict ); diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 65ec3d4814..d8fa60abb0 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -505,10 +505,9 @@ STATIC MP_DEFINE_CONST_DICT(displayio_tilegrid_locals_dict, displayio_tilegrid_l MP_DEFINE_CONST_OBJ_TYPE( displayio_tilegrid_type, - MP_TYPE_FLAG_EXTENDED, + MP_QSTR_TileGrid, MP_TYPE_FLAG_NONE, - name, MP_QSTR_TileGrid, make_new, displayio_tilegrid_make_new, locals_dict, &displayio_tilegrid_locals_dict, - .subscr, tilegrid_subscr + subscr, tilegrid_subscr ); diff --git a/shared-bindings/fontio/Glyph.c b/shared-bindings/fontio/Glyph.c index 9fd49cfb1a..0568048026 100644 --- a/shared-bindings/fontio/Glyph.c +++ b/shared-bindings/fontio/Glyph.c @@ -7,7 +7,7 @@ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights + * in the Software without restriction, including witho>ut limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: @@ -55,23 +55,7 @@ //| ... //| const mp_obj_namedtuple_type_t fontio_glyph_type = { - .base = { - .base = { - .type = &mp_type_type - }, - .name = MP_QSTR_Glyph, - .flags = MP_TYPE_FLAG_EXTENDED, - .print = namedtuple_print, - .make_new = namedtuple_make_new, - .parent = &mp_type_tuple, - .attr = namedtuple_attr, - MP_TYPE_EXTENDED_FIELDS( - .unary_op = mp_obj_tuple_unary_op, - .binary_op = mp_obj_tuple_binary_op, - .subscr = mp_obj_tuple_subscr, - .getiter = mp_obj_tuple_getiter, - ), - }, + NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_Glyph), .n_fields = 8, .fields = { MP_QSTR_bitmap, diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index 94bf34b8ee..5ec03d1c28 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -302,6 +302,6 @@ MP_DEFINE_CONST_OBJ_TYPE( pwmio_pwmout_type, MP_QSTR_PWMOut, MP_TYPE_FLAG_NONE, - .make_new, pwmio_pwmout_make_new, + make_new, pwmio_pwmout_make_new, locals_dict, &pwmio_pwmout_locals_dict ); diff --git a/shared-bindings/rtc/__init__.c b/shared-bindings/rtc/__init__.c index e1220841eb..908b324071 100644 --- a/shared-bindings/rtc/__init__.c +++ b/shared-bindings/rtc/__init__.c @@ -87,4 +87,6 @@ const mp_obj_module_t rtc_module = { .globals = (mp_obj_dict_t *)&rtc_module_globals, }; +MP_REGISTER_ROOT_POINTER(mp_obj_t rtc_time_source); + MP_REGISTER_MODULE(MP_QSTR_rtc, rtc_module); diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index 66a3267264..4bd501667a 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -118,23 +118,7 @@ STATIC mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, s //| ... //| const mp_obj_namedtuple_type_t struct_time_type_obj = { - .base = { - .base = { - .type = &mp_type_type - }, - .flags = MP_TYPE_FLAG_EXTENDED, - .name = MP_QSTR_struct_time, - .print = namedtuple_print, - .parent = &mp_type_tuple, - .make_new = struct_time_make_new, - .attr = namedtuple_attr, - MP_TYPE_EXTENDED_FIELDS( - .unary_op = mp_obj_tuple_unary_op, - .binary_op = mp_obj_tuple_binary_op, - .subscr = mp_obj_tuple_subscr, - .getiter = mp_obj_tuple_getiter, - ), - }, + NAMEDTUPLE_TYPE_BASE_AND_SLOTS_MAKE_NEW(MP_QSTR_struct_time, struct_time_make_new), .n_fields = 9, .fields = { MP_QSTR_tm_year, @@ -176,7 +160,7 @@ void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) { mp_obj_t *elems; size_t len; - if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, &struct_time_type_obj.base)) { + if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, (mp_obj_type_t *)&struct_time_type_obj.base)) { mp_raise_TypeError(translate("Tuple or struct_time argument required")); } @@ -290,7 +274,7 @@ STATIC mp_obj_t time_mktime(mp_obj_t t) { mp_obj_t *elem; size_t len; - if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, &struct_time_type_obj.base)) { + if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, (mp_obj_type_t *)&struct_time_type_obj.base)) { mp_raise_TypeError(translate("Tuple or struct_time argument required")); } diff --git a/shared-bindings/usb_cdc/Serial.c b/shared-bindings/usb_cdc/Serial.c index 7d9fd251ce..52bc3d7295 100644 --- a/shared-bindings/usb_cdc/Serial.c +++ b/shared-bindings/usb_cdc/Serial.c @@ -279,10 +279,9 @@ STATIC const mp_stream_p_t usb_cdc_serial_stream_p = { MP_DEFINE_CONST_OBJ_TYPE( usb_cdc_serial_type, - .name = MP_QSTR_Serial, + MP_QSTR_Serial, MP_TYPE_FLAG_ITER_IS_ITERNEXT, locals_dict, &usb_cdc_serial_locals_dict, - getiter, mp_identity_getiter, iter, mp_stream_unbuffered_iter, protocol, &usb_cdc_serial_stream_p ); diff --git a/shared-bindings/usb_midi/PortOut.c b/shared-bindings/usb_midi/PortOut.c index 2d2c2fa281..2f35a5baa5 100644 --- a/shared-bindings/usb_midi/PortOut.c +++ b/shared-bindings/usb_midi/PortOut.c @@ -95,7 +95,6 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_QSTR_PortOut, MP_TYPE_FLAG_ITER_IS_ITERNEXT, locals_dict, &usb_midi_portout_locals_dict, - getiter, mp_identity_getiter, - iternext, mp_stream_unbuffered_iter, + iter, mp_stream_unbuffered_iter, protocol, &usb_midi_portout_stream_p ); diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 372f014239..4c096a25a6 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -139,6 +139,9 @@ mp_obj_t common_hal_board_create_spi(const mp_int_t instance) { #if CIRCUITPY_BOARD_UART + +MP_REGISTER_ROOT_POINTER(mp_obj_t board_uart_bus); + typedef struct { const mcu_pin_obj_t *tx; const mcu_pin_obj_t *rx; diff --git a/shared-module/keypad/__init__.c b/shared-module/keypad/__init__.c index 68cde559fb..5d0905e420 100644 --- a/shared-module/keypad/__init__.c +++ b/shared-module/keypad/__init__.c @@ -154,3 +154,5 @@ mp_obj_t common_hal_keypad_generic_get_events(void *self_in) { keypad_scanner_obj_t *self = self_in; return self->events; } + +MP_REGISTER_ROOT_POINTER(mp_obj_t keypad_scanners_linked_list); diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index 7420b2b0b8..badc35b55e 100644 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -346,3 +346,5 @@ void supervisor_move_memory(void) { // Add calls to further clients here. old_allocations = NULL; } + +MP_REGISTER_ROOT_POINTER(struct _supervisor_allocation_node *first_embedded_allocation);