Trinket M0 comes up; still very much wip

This commit is contained in:
Dan Halbert 2023-09-28 16:22:10 -04:00
parent 171aa42168
commit 76ff01452b
35 changed files with 119 additions and 270 deletions

View File

@ -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) { STATIC mp_obj_t fat_vfs_del(mp_obj_t self_in) {
mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(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 // 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 #endif
STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { 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) }, { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&fat_vfs_del_obj) },
#endif #endif
{ MP_ROM_QSTR(MP_QSTR_mkfs), MP_ROM_PTR(&fat_vfs_mkfs_obj) }, { MP_ROM_QSTR(MP_QSTR_mkfs), MP_ROM_PTR(&fat_vfs_mkfs_obj) },

View File

@ -362,7 +362,7 @@ OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/candata.h
$(HEADER_BUILD)/candata.h: tools/mkcandata.py | $(HEADER_BUILD) $(HEADER_BUILD)/candata.h: tools/mkcandata.py | $(HEADER_BUILD)
$(Q)$(PYTHON) $< > $@ $(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. # Sources that only hold QSTRs after pre-processing.
SRC_QSTR_PREPROCESSOR += peripherals/samd/$(PERIPHERALS_CHIP_FAMILY)/clocks.c SRC_QSTR_PREPROCESSOR += peripherals/samd/$(PERIPHERALS_CHIP_FAMILY)/clocks.c

View File

@ -3,11 +3,7 @@
* *
* The MIT License (MIT) * The MIT License (MIT)
* *
<<<<<<<< HEAD:ports/atmel-samd/common-hal/busio/SPI.h
* Copyright (c) 2016 Scott Shawcroft * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -28,7 +24,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
<<<<<<<< HEAD:ports/atmel-samd/common-hal/busio/SPI.h
#ifndef MICROPY_INCLUDED_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 #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H
@ -48,22 +43,3 @@ typedef struct {
} busio_spi_obj_t; } busio_spi_obj_t;
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H
========
#include <stdlib.h>
#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

View File

@ -3,11 +3,7 @@
* *
* The MIT License (MIT) * The MIT License (MIT)
* *
<<<<<<<< HEAD:ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h
* Copyright (c) 2018 Noralf Trønnes * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -30,7 +26,6 @@
#ifndef MICROPY_INCLUDED_SAMD_PENDSV_H #ifndef MICROPY_INCLUDED_SAMD_PENDSV_H
#define 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 #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H
#define 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; } i2ctarget_i2c_target_obj_t;
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H #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

View File

@ -43,23 +43,7 @@
//| //|
const mp_obj_namedtuple_type_t espnow_packet_type_obj = { const mp_obj_namedtuple_type_t espnow_packet_type_obj = {
.base = { NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ESPNowPacket),
.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,
),
},
.n_fields = 4, .n_fields = 4,
.fields = { .fields = {
MP_QSTR_mac, MP_QSTR_mac,

View File

@ -38,31 +38,4 @@
bool mp_hal_stdin_any(void); bool mp_hal_stdin_any(void);
<<<<<<<< HEAD:ports/espressif/mphalport.h
#endif // MICROPY_INCLUDED_ESPRESSIF_MPHAL_H #endif // MICROPY_INCLUDED_ESPRESSIF_MPHAL_H
========
int mp_hal_get_interrupt_char(void);
#if MICROPY_VFS_POSIX
#include <errno.h>
// 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

View File

@ -3,12 +3,8 @@
* *
* The MIT License (MIT) * The MIT License (MIT)
* *
<<<<<<<< HEAD:ports/mimxrt10xx/boards/imxrt1010_evk/board.c
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2019 Artur Pacholec * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * 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 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * 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 "supervisor/board.h"
#include "shared-bindings/microcontroller/Pin.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. // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
========
#include <stddef.h>
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

View File

@ -1,15 +1,9 @@
/* /*
* This file is part of the MicroPython project, http://micropython.org/ * This file is part of the MicroPython project, http://micropython.org/
* *
* This file provides functions for configuring the clocks.
*
* The MIT License (MIT) * The MIT License (MIT)
* *
<<<<<<<< HEAD:ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h
* Copyright (c) 2020 Jeff Epler for Adafruit Industries * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -30,7 +24,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
<<<<<<<< HEAD:ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h
#pragma once #pragma once
// Some boards don't implement I2SOut, so suppress any routines from here. // Some boards don't implement I2SOut, so suppress any routines from here.
@ -49,11 +42,3 @@ typedef struct {
} audiobusio_i2sout_obj_t; } audiobusio_i2sout_obj_t;
#endif #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

View File

@ -54,9 +54,8 @@ void bindings_cyw43_wifi_enforce_pm() {
//| //|
MP_DEFINE_CONST_OBJ_TYPE( MP_DEFINE_CONST_OBJ_TYPE(
cyw43_pin_type, cyw43_pin_type,
MP_TYPE_FLAG_EXTENDED, MP_QSTR_CywPin,
MP_TYPE_FLAG_NONE, MP_TYPE_FLAG_NONE,
name, MP_QSTR_CywPin,
print, shared_bindings_microcontroller_pin_print, print, shared_bindings_microcontroller_pin_print,
unary_op, mp_generic_unary_op, unary_op, mp_generic_unary_op,
); );

View File

@ -3,11 +3,7 @@
* *
* The MIT License (MIT) * The MIT License (MIT)
* *
<<<<<<<< HEAD:ports/raspberrypi/common-hal/wifi/Monitor.c
* Copyright (c) 2021 microDev * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -28,7 +24,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
<<<<<<<< HEAD:ports/raspberrypi/common-hal/wifi/Monitor.c
#include <string.h> #include <string.h>
#include "py/mpstate.h" #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) { mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self) {
return mp_const_none; return mp_const_none;
} }
========
#include <stdlib.h>
#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

View File

@ -787,6 +787,7 @@ endif
$(patsubst %.c,$(BUILD)/%.o,$(SRC_LIBM)): CFLAGS += -Wno-missing-prototypes $(patsubst %.c,$(BUILD)/%.o,$(SRC_LIBM)): CFLAGS += -Wno-missing-prototypes
endif endif
# Sources used in all ports except unix.
SRC_CIRCUITPY_COMMON = \ SRC_CIRCUITPY_COMMON = \
shared/libc/string0.c \ shared/libc/string0.c \
shared/readline/readline.c \ shared/readline/readline.c \

View File

@ -316,15 +316,12 @@ typedef long mp_off_t;
#if defined(DEFAULT_UART_BUS_TX) && defined(DEFAULT_UART_BUS_RX) #if defined(DEFAULT_UART_BUS_TX) && defined(DEFAULT_UART_BUS_RX)
#define CIRCUITPY_BOARD_UART (1) #define CIRCUITPY_BOARD_UART (1)
#define CIRCUITPY_BOARD_UART_PIN {{.tx = DEFAULT_UART_BUS_TX, .rx = DEFAULT_UART_BUS_RX}} #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 #else
#define CIRCUITPY_BOARD_UART (0) #define CIRCUITPY_BOARD_UART (0)
#define BOARD_UART_ROOT_POINTER
#endif #endif
#else
#define BOARD_UART_ROOT_POINTER mp_obj_t board_uart_bus;
#endif #endif
#if MICROPY_PY_ASYNC_AWAIT && !CIRCUITPY_TRACEBACK #if MICROPY_PY_ASYNC_AWAIT && !CIRCUITPY_TRACEBACK
#error CIRCUITPY_ASYNCIO requires CIRCUITPY_TRACEBACK #error CIRCUITPY_ASYNCIO requires CIRCUITPY_TRACEBACK
#endif #endif
@ -359,12 +356,6 @@ typedef long mp_off_t;
#define CIRCUITPY_DISPLAY_AREA_BUFFER_SIZE (0) #define CIRCUITPY_DISPLAY_AREA_BUFFER_SIZE (0)
#endif #endif
#if CIRCUITPY_KEYPAD
#define KEYPAD_ROOT_POINTERS mp_obj_t keypad_scanners_linked_list;
#else
#define KEYPAD_ROOT_POINTERS
#endif
#if CIRCUITPY_MEMORYMONITOR #if CIRCUITPY_MEMORYMONITOR
#define MEMORYMONITOR_ROOT_POINTERS mp_obj_t active_allocationsizes; \ #define MEMORYMONITOR_ROOT_POINTERS mp_obj_t active_allocationsizes; \
mp_obj_t active_allocationalarms; mp_obj_t active_allocationalarms;
@ -438,15 +429,9 @@ struct _supervisor_allocation_node;
#define CIRCUITPY_COMMON_ROOT_POINTERS \ #define CIRCUITPY_COMMON_ROOT_POINTERS \
FLASH_ROOT_POINTERS \ FLASH_ROOT_POINTERS \
KEYPAD_ROOT_POINTERS \
BOARD_UART_ROOT_POINTER \
WIFI_MONITOR_ROOT_POINTERS \ WIFI_MONITOR_ROOT_POINTERS \
MEMORYMONITOR_ROOT_POINTERS \ MEMORYMONITOR_ROOT_POINTERS \
vstr_t *repl_line; \ 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); void background_callback_run_all(void);
#define RUN_BACKGROUND_TASKS (background_callback_run_all()) #define RUN_BACKGROUND_TASKS (background_callback_run_all())

11
py/gc.c
View File

@ -482,13 +482,19 @@ void gc_collect_start(void) {
#endif #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 // 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 // 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). // prohibited (due to being undefined, in a red zone, etc).
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
__attribute__((no_sanitize_address)) __attribute__((no_sanitize_address))
#endif #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 MICROPY_DEBUG_VALGRIND
if (!VALGRIND_CHECK_MEM_IS_ADDRESSABLE(&ptrs[i], sizeof(*ptrs))) { if (!VALGRIND_CHECK_MEM_IS_ADDRESSABLE(&ptrs[i], sizeof(*ptrs))) {
return NULL; 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 */ /* this prints the uPy object type of the head block */
case AT_HEAD: { case AT_HEAD: {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
void **ptr = (void **)(area->gc_pool_start + bl * BYTES_PER_BLOCK); void **ptr = (void **)(area->gc_pool_start + bl * BYTES_PER_BLOCK);
#pragma GCC diagnostic pop
if (*ptr == &mp_type_tuple) { if (*ptr == &mp_type_tuple) {
c = 'T'; c = 'T';
} else if (*ptr == &mp_type_list) { } else if (*ptr == &mp_type_list) {

View File

@ -1745,6 +1745,11 @@ typedef double mp_float_t;
#define MICROPY_PY_ONEWIRE (0) #define MICROPY_PY_ONEWIRE (0)
#endif #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 */ /* Hooks for a port to add builtins */

View File

@ -26,7 +26,7 @@
#include "py/mpstate.h" #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); __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr);

View File

@ -995,12 +995,18 @@ mp_obj_t mp_obj_new_str_from_utf8_vstr(vstr_t *vstr); // input data must be vali
#endif #endif
mp_obj_t mp_obj_new_bytes_from_vstr(vstr_t *vstr); 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); 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(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_of_zeros(size_t n); // CIRCUITPY
mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items); mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items);
#if MICROPY_PY_BUILTINS_FLOAT #if MICROPY_PY_BUILTINS_FLOAT
mp_obj_t mp_obj_new_int_from_float(mp_float_t val); 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); 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 #endif
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type); 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); mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args);

View File

@ -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); 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 #endif // MICROPY_PY_BUILTINS_FLOAT

View File

@ -34,6 +34,13 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/stackctrl.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 #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); 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 #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); 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) { bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) {
if (mp_obj_is_qstr(s1) && mp_obj_is_qstr(s2)) { if (mp_obj_is_qstr(s1) && mp_obj_is_qstr(s2)) {
return s1 == s2; return s1 == s2;

View File

@ -29,6 +29,10 @@
#include "py/obj.h" #include "py/obj.h"
#include "py/objarray.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 { typedef struct _mp_obj_str_t {
mp_obj_base_t base; mp_obj_base_t base;
size_t hash; size_t hash;

View File

@ -44,6 +44,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/builtin.h" #include "py/builtin.h"
#include "py/stackctrl.h" #include "py/stackctrl.h"
#include "py/stream.h"
#include "py/gc.h" #include "py/gc.h"
#if MICROPY_DEBUG_VERBOSE // print debugging info #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) { 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) { 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; return mp_stream_unbuffered_iter;
} else if (type->flags & MP_TYPE_FLAG_ITER_IS_ITERNEXT) { } else if (type->flags & MP_TYPE_FLAG_ITER_IS_ITERNEXT) {
return (mp_fun_1_t)MP_OBJ_TYPE_GET_SLOT(type, iter); return (mp_fun_1_t)MP_OBJ_TYPE_GET_SLOT(type, iter);

View File

@ -326,7 +326,7 @@ outer_dispatch_loop:
for (;;) { for (;;) {
dispatch_loop: dispatch_loop:
#if MICROPY_OPT_COMPUTED_GOTO #if MICROPY_OPT_COMPUTED_GOTO
DISPATCH(); ONE_TRUE_DISPATCH();
#else #else
TRACE(ip); TRACE(ip);
MARK_EXC_IP_GLOBAL(); MARK_EXC_IP_GLOBAL();

View File

@ -62,3 +62,5 @@ const mp_obj_module_t pew_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&pew_module_globals, .globals = (mp_obj_dict_t *)&pew_module_globals,
}; };
MP_REGISTER_ROOT_POINTER(mp_obj_t pew_singleton);

View File

@ -43,7 +43,22 @@
// #define STREAM_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) // #define STREAM_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
//| class UART: //| class UART:
//| """A bidirectional serial protocol""" //| """A bidirectional serial protocol
//|
//| .. raw:: html
//|
//| <p>
//| <details>
//| <summary>Available on these boards</summary>
//| <ul>
//| {% for board in support_matrix_reverse["busio.UART"] %}
//| <li> {{ board }}
//| {% endfor %}
//| </ul>
//| </details>
//| </p>
//|
//| """
//| //|
//| def __init__( //| def __init__(
//| self, //| 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); 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_DEFINE_CONST_OBJ_TYPE(
{ &mp_type_type }, busio_uart_parity_type,
.name = MP_QSTR_Parity, MP_QSTR_Parity,
.print = busio_uart_parity_print, MP_TYPE_FLAG_NONE,
.locals_dict = (mp_obj_dict_t *)&busio_uart_parity_locals_dict, print, busio_uart_parity_print,
}; locals_dict, &busio_uart_parity_locals_dict
);
STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = { STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = {
#if CIRCUITPY_BUSIO_UART #if CIRCUITPY_BUSIO_UART
@ -452,7 +468,8 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_TYPE_FLAG_ITER_IS_ITERNEXT, MP_TYPE_FLAG_ITER_IS_ITERNEXT,
make_new, busio_uart_make_new, make_new, busio_uart_make_new,
locals_dict, &busio_uart_locals_dict, locals_dict, &busio_uart_locals_dict,
iter, mp_stream_unbuffered_iter iter, mp_stream_unbuffered_iter,
protocol, &uart_stream_p
); );
#else #else
MP_DEFINE_CONST_OBJ_TYPE( MP_DEFINE_CONST_OBJ_TYPE(

View File

@ -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( MP_DEFINE_CONST_OBJ_TYPE(
digitalio_drive_mode_type, digitalio_drive_mode_type,
name, MP_QSTR_DriveMode, MP_QSTR_DriveMode,
MP_TYPE_FLAG_NONE, MP_TYPE_FLAG_NONE,
print, digitalio_drive_mode_print, print, digitalio_drive_mode_print,
locals_dict, &digitalio_drive_mode_locals_dict locals_dict, &digitalio_drive_mode_locals_dict

View File

@ -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( MP_DEFINE_CONST_OBJ_TYPE(
digitalio_pull_type, digitalio_pull_type,
MP_QSTR_Pull,
MP_TYPE_FLAG_NONE, MP_TYPE_FLAG_NONE,
name, MP_QSTR_Pull,
print, digitalio_pull_print, print, digitalio_pull_print,
locals_dict, &digitalio_pull_locals_dict locals_dict, &digitalio_pull_locals_dict
); );

View File

@ -505,10 +505,9 @@ STATIC MP_DEFINE_CONST_DICT(displayio_tilegrid_locals_dict, displayio_tilegrid_l
MP_DEFINE_CONST_OBJ_TYPE( MP_DEFINE_CONST_OBJ_TYPE(
displayio_tilegrid_type, displayio_tilegrid_type,
MP_TYPE_FLAG_EXTENDED, MP_QSTR_TileGrid,
MP_TYPE_FLAG_NONE, MP_TYPE_FLAG_NONE,
name, MP_QSTR_TileGrid,
make_new, displayio_tilegrid_make_new, make_new, displayio_tilegrid_make_new,
locals_dict, &displayio_tilegrid_locals_dict, locals_dict, &displayio_tilegrid_locals_dict,
.subscr, tilegrid_subscr subscr, tilegrid_subscr
); );

View File

@ -7,7 +7,7 @@
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * 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 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
@ -55,23 +55,7 @@
//| ... //| ...
//| //|
const mp_obj_namedtuple_type_t fontio_glyph_type = { const mp_obj_namedtuple_type_t fontio_glyph_type = {
.base = { NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_Glyph),
.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,
),
},
.n_fields = 8, .n_fields = 8,
.fields = { .fields = {
MP_QSTR_bitmap, MP_QSTR_bitmap,

View File

@ -302,6 +302,6 @@ MP_DEFINE_CONST_OBJ_TYPE(
pwmio_pwmout_type, pwmio_pwmout_type,
MP_QSTR_PWMOut, MP_QSTR_PWMOut,
MP_TYPE_FLAG_NONE, MP_TYPE_FLAG_NONE,
.make_new, pwmio_pwmout_make_new, make_new, pwmio_pwmout_make_new,
locals_dict, &pwmio_pwmout_locals_dict locals_dict, &pwmio_pwmout_locals_dict
); );

View File

@ -87,4 +87,6 @@ const mp_obj_module_t rtc_module = {
.globals = (mp_obj_dict_t *)&rtc_module_globals, .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); MP_REGISTER_MODULE(MP_QSTR_rtc, rtc_module);

View File

@ -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 = { const mp_obj_namedtuple_type_t struct_time_type_obj = {
.base = { NAMEDTUPLE_TYPE_BASE_AND_SLOTS_MAKE_NEW(MP_QSTR_struct_time, struct_time_make_new),
.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,
),
},
.n_fields = 9, .n_fields = 9,
.fields = { .fields = {
MP_QSTR_tm_year, 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; mp_obj_t *elems;
size_t len; 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")); 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; mp_obj_t *elem;
size_t len; 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")); mp_raise_TypeError(translate("Tuple or struct_time argument required"));
} }

View File

@ -279,10 +279,9 @@ STATIC const mp_stream_p_t usb_cdc_serial_stream_p = {
MP_DEFINE_CONST_OBJ_TYPE( MP_DEFINE_CONST_OBJ_TYPE(
usb_cdc_serial_type, usb_cdc_serial_type,
.name = MP_QSTR_Serial, MP_QSTR_Serial,
MP_TYPE_FLAG_ITER_IS_ITERNEXT, MP_TYPE_FLAG_ITER_IS_ITERNEXT,
locals_dict, &usb_cdc_serial_locals_dict, locals_dict, &usb_cdc_serial_locals_dict,
getiter, mp_identity_getiter,
iter, mp_stream_unbuffered_iter, iter, mp_stream_unbuffered_iter,
protocol, &usb_cdc_serial_stream_p protocol, &usb_cdc_serial_stream_p
); );

View File

@ -95,7 +95,6 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_QSTR_PortOut, MP_QSTR_PortOut,
MP_TYPE_FLAG_ITER_IS_ITERNEXT, MP_TYPE_FLAG_ITER_IS_ITERNEXT,
locals_dict, &usb_midi_portout_locals_dict, locals_dict, &usb_midi_portout_locals_dict,
getiter, mp_identity_getiter, iter, mp_stream_unbuffered_iter,
iternext, mp_stream_unbuffered_iter,
protocol, &usb_midi_portout_stream_p protocol, &usb_midi_portout_stream_p
); );

View File

@ -139,6 +139,9 @@ mp_obj_t common_hal_board_create_spi(const mp_int_t instance) {
#if CIRCUITPY_BOARD_UART #if CIRCUITPY_BOARD_UART
MP_REGISTER_ROOT_POINTER(mp_obj_t board_uart_bus);
typedef struct { typedef struct {
const mcu_pin_obj_t *tx; const mcu_pin_obj_t *tx;
const mcu_pin_obj_t *rx; const mcu_pin_obj_t *rx;

View File

@ -154,3 +154,5 @@ mp_obj_t common_hal_keypad_generic_get_events(void *self_in) {
keypad_scanner_obj_t *self = self_in; keypad_scanner_obj_t *self = self_in;
return self->events; return self->events;
} }
MP_REGISTER_ROOT_POINTER(mp_obj_t keypad_scanners_linked_list);

View File

@ -346,3 +346,5 @@ void supervisor_move_memory(void) {
// Add calls to further clients here. // Add calls to further clients here.
old_allocations = NULL; old_allocations = NULL;
} }
MP_REGISTER_ROOT_POINTER(struct _supervisor_allocation_node *first_embedded_allocation);