From 398eb459292ae9759875d2dd13c0c12112a8713a Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Fri, 6 Dec 2024 09:12:50 -0600 Subject: [PATCH 01/15] Always update `echo_buffer_len` during `recalculate_delay` when `freq_shift=False` to avoid `echo_buffer_len=0` when `delay_ms` is invalid within constructor. --- shared-module/audiodelays/Echo.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index e4eeff48f4c33..2c499d1ac40fb 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -132,23 +132,8 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { self->echo_buffer_rate = (uint32_t)MAX(self->max_delay_ms / f_delay_ms * MICROPY_FLOAT_CONST(256.0), MICROPY_FLOAT_CONST(1.0)); self->echo_buffer_len = self->max_echo_buffer_len; } else { - // Calculate the current echo buffer length in bytes - uint32_t new_echo_buffer_len = (uint32_t)(self->sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * (self->channel_count * sizeof(uint16_t)); - - // Check if our new echo is too long for our maximum buffer - if (new_echo_buffer_len > self->max_echo_buffer_len) { - return; - } else if (new_echo_buffer_len < 0.0) { // or too short! - return; - } - - // If the echo buffer is larger then our audio buffer weird things happen - if (new_echo_buffer_len < self->buffer_len) { - return; - } - - self->echo_buffer_len = new_echo_buffer_len; - + // Calculate the current echo buffer length in bytes and limit to valid range + self->echo_buffer_len = (uint32_t)MIN(MAX((self->sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * (self->channel_count * sizeof(uint16_t)), self->channel_count * sizeof(uint16_t)), self->max_echo_buffer_len); // Clear the now unused part of the buffer or some weird artifacts appear memset(self->echo_buffer + self->echo_buffer_len, 0, self->max_echo_buffer_len - self->echo_buffer_len); } From cf6086ddcba602f3387426b57a9e331e4a975a94 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Fri, 6 Dec 2024 10:02:31 -0600 Subject: [PATCH 02/15] Fix casting error in buffer length calculation. --- shared-module/audiodelays/Echo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 2c499d1ac40fb..d8f0b85ceb143 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -133,7 +133,8 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { self->echo_buffer_len = self->max_echo_buffer_len; } else { // Calculate the current echo buffer length in bytes and limit to valid range - self->echo_buffer_len = (uint32_t)MIN(MAX((self->sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * (self->channel_count * sizeof(uint16_t)), self->channel_count * sizeof(uint16_t)), self->max_echo_buffer_len); + self->echo_buffer_len = MIN(MAX((uint32_t)(self->sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * (self->channel_count * sizeof(uint16_t)), self->channel_count * sizeof(uint16_t)), self->max_echo_buffer_len); + // Clear the now unused part of the buffer or some weird artifacts appear memset(self->echo_buffer + self->echo_buffer_len, 0, self->max_echo_buffer_len - self->echo_buffer_len); } From 83fce94b3b61c5dc9fb7eb3468c5850e1839fa0f Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Fri, 6 Dec 2024 10:04:55 -0600 Subject: [PATCH 03/15] Fix handling of echo buffer when `freq_shift=True` and `channel_count=2` and remove unnecessary position variables. --- shared-module/audiodelays/Echo.c | 94 +++++++++++++------------------- shared-module/audiodelays/Echo.h | 5 +- 2 files changed, 40 insertions(+), 59 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index d8f0b85ceb143..ac77691c9f6ad 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -91,11 +91,9 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // read is where we read previous echo from delay_ms ago to play back now // write is where the store the latest playing sample to echo back later - self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); - self->echo_buffer_write_pos = 0; - - // where we read the previous echo from delay_ms ago to play back now (for freq shift) - self->echo_buffer_left_pos = self->echo_buffer_right_pos = 0; + self->echo_buffer_pos = 0; + // use a separate buffer position for the right channel when using freq_shift + self->echo_buffer_right_pos = 0; } bool common_hal_audiodelays_echo_deinited(audiodelays_echo_obj_t *self) { @@ -130,7 +128,8 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { if (self->freq_shift) { // Calculate the rate of iteration over the echo buffer with 8 sub-bits self->echo_buffer_rate = (uint32_t)MAX(self->max_delay_ms / f_delay_ms * MICROPY_FLOAT_CONST(256.0), MICROPY_FLOAT_CONST(1.0)); - self->echo_buffer_len = self->max_echo_buffer_len; + // Only use half of the buffer per channel if stereo + self->echo_buffer_len = self->max_echo_buffer_len >> (self->channel_count - 1); } else { // Calculate the current echo buffer length in bytes and limit to valid range self->echo_buffer_len = MIN(MAX((uint32_t)(self->sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * (self->channel_count * sizeof(uint16_t)), self->channel_count * sizeof(uint16_t)), self->max_echo_buffer_len); @@ -290,14 +289,9 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // The echo buffer is always stored as a 16-bit value internally int16_t *echo_buffer = (int16_t *)self->echo_buffer; uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t); - - // Set our echo buffer position accounting for stereo - uint32_t echo_buffer_pos = 0; - if (self->freq_shift) { - echo_buffer_pos = self->echo_buffer_left_pos; - if (channel == 1) { - echo_buffer_pos = self->echo_buffer_right_pos; - } + uint32_t echo_buf_pos = self->echo_buffer_pos; + if (self->freq_shift && channel == 1) { + echo_buf_pos = self->echo_buffer_right_pos; } // Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample @@ -341,19 +335,20 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * for (uint32_t i = 0; i < length; i++) { int16_t echo, word = 0; uint32_t next_buffer_pos = 0; + bool echo_buf_offset = self->freq_shift && (channel == 1 || i % self->channel_count == 1); if (self->freq_shift) { - echo = echo_buffer[echo_buffer_pos >> 8]; - next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; + echo = echo_buffer[(echo_buf_pos >> 8) + echo_buf_len * echo_buf_offset]; + next_buffer_pos = echo_buf_pos + self->echo_buffer_rate; word = (int16_t)(echo * decay); - for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { - echo_buffer[j % echo_buf_len] = word; + for (uint32_t j = echo_buf_pos >> 8; j < next_buffer_pos >> 8; j++) { + echo_buffer[(j % echo_buf_len) + echo_buf_len * echo_buf_offset] = word; } } else { - echo = echo_buffer[self->echo_buffer_read_pos++]; + echo = echo_buffer[echo_buf_pos]; word = (int16_t)(echo * decay); - echo_buffer[self->echo_buffer_write_pos++] = word; + echo_buffer[echo_buf_pos++] = word; } word = (int16_t)(echo * mix); @@ -370,15 +365,10 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } - if (self->freq_shift) { - echo_buffer_pos = next_buffer_pos % (echo_buf_len << 8); - } else { - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } + if (self->freq_shift && (single_channel_output || echo_buf_offset)) { + echo_buf_pos = next_buffer_pos % (echo_buf_len << 8); + } else if (!self->freq_shift && echo_buf_pos >= echo_buf_len) { + echo_buf_pos = 0; } } } @@ -416,23 +406,23 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * int32_t echo, word = 0; uint32_t next_buffer_pos = 0; + bool echo_buf_offset = self->freq_shift && (channel == 1 || i % self->channel_count == 1); if (self->freq_shift) { - echo = echo_buffer[echo_buffer_pos >> 8]; - next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; - word = (int32_t)(echo * decay + sample_word); + echo = echo_buffer[(echo_buf_pos >> 8) + echo_buf_len * echo_buf_offset]; + next_buffer_pos = echo_buf_pos + self->echo_buffer_rate; } else { - echo = echo_buffer[self->echo_buffer_read_pos++]; - word = (int32_t)(echo * decay + sample_word); + echo = echo_buffer[echo_buf_pos]; } + word = (int32_t)(echo * decay + sample_word); if (MP_LIKELY(self->bits_per_sample == 16)) { word = mix_down_sample(word); if (self->freq_shift) { - for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { - echo_buffer[j % echo_buf_len] = (int16_t)word; + for (uint32_t j = echo_buf_pos >> 8; j < next_buffer_pos >> 8; j++) { + echo_buffer[(j % echo_buf_len) + echo_buf_len * echo_buf_offset] = (int16_t)word; } } else { - echo_buffer[self->echo_buffer_write_pos++] = (int16_t)word; + echo_buffer[echo_buf_pos++] = (int16_t)word; } } else { // Do not have mix_down for 8 bit so just hard cap samples into 1 byte @@ -442,11 +432,11 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * word = -128; } if (self->freq_shift) { - for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { - echo_buffer[j % echo_buf_len] = (int8_t)word; + for (uint32_t j = echo_buf_pos >> 8; j < next_buffer_pos >> 8; j++) { + echo_buffer[(j % echo_buf_len) + echo_buf_offset] = (int8_t)word; } } else { - echo_buffer[self->echo_buffer_write_pos++] = (int8_t)word; + echo_buffer[echo_buf_pos++] = (int8_t)word; } } @@ -466,15 +456,10 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } - if (self->freq_shift) { - echo_buffer_pos = next_buffer_pos % (echo_buf_len << 8); - } else { - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } + if (self->freq_shift && (single_channel_output || echo_buf_offset)) { + echo_buf_pos = next_buffer_pos % (echo_buf_len << 8); + } else if (!self->freq_shift && echo_buf_pos >= echo_buf_len) { + echo_buf_pos = 0; } } } @@ -488,12 +473,11 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } - if (self->freq_shift) { - if (channel == 0) { - self->echo_buffer_left_pos = echo_buffer_pos; - } else if (channel == 1) { - self->echo_buffer_right_pos = echo_buffer_pos; - } + // Update buffer position + if (self->freq_shift && channel == 1) { + self->echo_buffer_right_pos = echo_buf_pos; + } else { + self->echo_buffer_pos = echo_buf_pos; } // Finally pass our buffer and length to the calling audio function diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index 8742f83898a75..17aaec20a9333 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -40,11 +40,8 @@ typedef struct { uint32_t echo_buffer_len; // bytes uint32_t max_echo_buffer_len; // bytes - uint32_t echo_buffer_read_pos; // words - uint32_t echo_buffer_write_pos; // words - + uint32_t echo_buffer_pos; // words (<< 8 when freq_shift=True) uint32_t echo_buffer_rate; // words << 8 - uint32_t echo_buffer_left_pos; // words << 8 uint32_t echo_buffer_right_pos; // words << 8 mp_obj_t sample; From 9e36143416c08b1c91d673ad5dc825b6391166fb Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Fri, 6 Dec 2024 10:05:11 -0600 Subject: [PATCH 04/15] Reset buffer if changing `freq_shift` modes. --- shared-module/audiodelays/Echo.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index ac77691c9f6ad..6a56c59db4d5b 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -162,6 +162,12 @@ bool common_hal_audiodelays_echo_get_freq_shift(audiodelays_echo_obj_t *self) { } void common_hal_audiodelays_echo_set_freq_shift(audiodelays_echo_obj_t *self, bool freq_shift) { + // Clear the echo buffer and reset buffer position if changing freq_shift modes + if (self->freq_shift != freq_shift) { + memset(self->echo_buffer, 0, self->max_echo_buffer_len); + self->echo_buffer_pos = 0; + self->echo_buffer_right_pos = 0; + } self->freq_shift = freq_shift; uint32_t delay_ms = (uint32_t)synthio_block_slot_get(&self->delay_ms); recalculate_delay(self, delay_ms); From b3afaea488755ca3d884d34d34f2f50b8a412778 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 7 Mar 2025 17:57:43 -0600 Subject: [PATCH 05/15] implement ColoConverter for TilePaletteMapper --- .../tilepalettemapper/TilePaletteMapper.c | 26 ++++++----- .../tilepalettemapper/TilePaletteMapper.h | 2 +- .../tilepalettemapper/TilePaletteMapper.c | 46 ++++++++++++++----- .../tilepalettemapper/TilePaletteMapper.h | 4 +- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/shared-bindings/tilepalettemapper/TilePaletteMapper.c b/shared-bindings/tilepalettemapper/TilePaletteMapper.c index ee1475d16b50f..f30977ee6e527 100644 --- a/shared-bindings/tilepalettemapper/TilePaletteMapper.c +++ b/shared-bindings/tilepalettemapper/TilePaletteMapper.c @@ -11,6 +11,7 @@ #include "py/runtime.h" #include "shared-bindings/util.h" #include "shared-bindings/displayio/Palette.h" +#include "shared-bindings/displayio/ColorConverter.h" #include "shared-bindings/tilepalettemapper/TilePaletteMapper.h" //| class TilePaletteMapper: @@ -24,28 +25,29 @@ //| ) -> None: //| """Create a TilePaletteMApper object to store a set of color mappings for tiles. //| -//| :param displayio.Palette palette: The palette to get mapped colors from. +//| :param Union[displayio.Palette, displayio.ColorConverter] pixel_shader: +//| The palette or ColorConverter to get mapped colors from. //| :param int input_color_count: The number of colors in in the input bitmap. //| :param int width: The width of the grid in tiles. //| :param int height: The height of the grid in tiles.""" //| static mp_obj_t tilepalettemapper_tilepalettemapper_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_palette, ARG_input_color_count, ARG_width, ARG_height }; + enum { ARG_pixel_shader, ARG_input_color_count, ARG_width, ARG_height }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_palette, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_input_color_count, MP_ARG_INT | MP_ARG_REQUIRED }, { MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED }, { MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_obj_t palette = args[ARG_palette].u_obj; - if (!mp_obj_is_type(palette, &displayio_palette_type)) { + mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; + if (!mp_obj_is_type(pixel_shader, &displayio_palette_type) && !mp_obj_is_type(pixel_shader, &displayio_colorconverter_type)) { mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported %q type"), MP_QSTR_pixel_shader); } tilepalettemapper_tilepalettemapper_t *self = mp_obj_malloc(tilepalettemapper_tilepalettemapper_t, &tilepalettemapper_tilepalettemapper_type); - common_hal_tilepalettemapper_tilepalettemapper_construct(self, palette, args[ARG_input_color_count].u_int, args[ARG_width].u_int, args[ARG_height].u_int); + common_hal_tilepalettemapper_tilepalettemapper_construct(self, pixel_shader, args[ARG_input_color_count].u_int, args[ARG_width].u_int, args[ARG_height].u_int); return MP_OBJ_FROM_PTR(self); } @@ -73,17 +75,17 @@ MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_height_obj, (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_height_obj); -//| palette: displayio.Palette -//| """The palette that the mapper uses.""" +//| palette: Union[displayio.Palette, displayio.ColorConverter] +//| """The palette or ColorConverter that the mapper uses.""" //| -static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_palette(mp_obj_t self_in) { +static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_pixel_shader(mp_obj_t self_in) { tilepalettemapper_tilepalettemapper_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_tilepalettemapper_tilepalettemapper_get_palette(self); + return common_hal_tilepalettemapper_tilepalettemapper_get_pixel_shader(self); } -MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_palette_obj, tilepalettemapper_tilepalettemapper_obj_get_palette); +MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_pixel_shader_obj, tilepalettemapper_tilepalettemapper_obj_get_pixel_shader); MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_palette_obj, - (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_palette_obj); + (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_pixel_shader_obj); //| def __getitem__(self, index: Union[Tuple[int, int], int]) -> Tuple[int]: diff --git a/shared-bindings/tilepalettemapper/TilePaletteMapper.h b/shared-bindings/tilepalettemapper/TilePaletteMapper.h index 0e4eced23b7c3..3fa1ab1e3a5cc 100644 --- a/shared-bindings/tilepalettemapper/TilePaletteMapper.h +++ b/shared-bindings/tilepalettemapper/TilePaletteMapper.h @@ -13,6 +13,6 @@ void common_hal_tilepalettemapper_tilepalettemapper_construct(tilepalettemapper_ uint16_t common_hal_tilepalettemapper_tilepalettemapper_get_width(tilepalettemapper_tilepalettemapper_t *self); uint16_t common_hal_tilepalettemapper_tilepalettemapper_get_height(tilepalettemapper_tilepalettemapper_t *self); -mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_palette(tilepalettemapper_tilepalettemapper_t *self); +mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_pixel_shader(tilepalettemapper_tilepalettemapper_t *self); mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y); void common_hal_tilepalettemapper_tilepalettemapper_set_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y, size_t len, mp_obj_t *items); diff --git a/shared-module/tilepalettemapper/TilePaletteMapper.c b/shared-module/tilepalettemapper/TilePaletteMapper.c index c988e908ab00b..f27c507fdca49 100644 --- a/shared-module/tilepalettemapper/TilePaletteMapper.c +++ b/shared-module/tilepalettemapper/TilePaletteMapper.c @@ -7,21 +7,28 @@ #include "py/runtime.h" #include "shared-bindings/tilepalettemapper/TilePaletteMapper.h" #include "shared-bindings/displayio/Palette.h" +#include "shared-bindings/displayio/ColorConverter.h" void common_hal_tilepalettemapper_tilepalettemapper_construct(tilepalettemapper_tilepalettemapper_t *self, - mp_obj_t palette, uint16_t input_color_count, uint16_t width, uint16_t height) { + mp_obj_t pixel_shader, uint16_t input_color_count, uint16_t width, uint16_t height) { - self->palette = palette; + self->pixel_shader = pixel_shader; self->width_in_tiles = width; self->height_in_tiles = height; self->input_color_count = input_color_count; self->needs_refresh = false; int mappings_len = width * height; - self->tile_mappings = (uint16_t **)m_malloc(mappings_len * sizeof(uint16_t *)); + self->tile_mappings = (uint32_t **)m_malloc(mappings_len * sizeof(uint32_t *)); for (int i = 0; i < mappings_len; i++) { - self->tile_mappings[i] = (uint16_t *)m_malloc(input_color_count * sizeof(uint16_t)); - for (uint16_t j = 0; j < input_color_count; j++) { - self->tile_mappings[i][j] = j; + self->tile_mappings[i] = (uint32_t *)m_malloc(input_color_count * sizeof(uint32_t)); + if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { + for (uint16_t j = 0; j < input_color_count; j++) { + self->tile_mappings[i][j] = j; + } + } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { + for (uint16_t j = 0; j < input_color_count; j++) { + self->tile_mappings[i][j] = 0; + } } } } @@ -34,8 +41,8 @@ uint16_t common_hal_tilepalettemapper_tilepalettemapper_get_height(tilepalettema return self->height_in_tiles; } -mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_palette(tilepalettemapper_tilepalettemapper_t *self) { - return self->palette; +mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_pixel_shader(tilepalettemapper_tilepalettemapper_t *self) { + return self->pixel_shader; } mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y) { @@ -48,10 +55,16 @@ mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_mapping(tilepalettem } void common_hal_tilepalettemapper_tilepalettemapper_set_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y, size_t len, mp_obj_t *items) { - uint32_t palette_len = common_hal_displayio_palette_get_len(self->palette); + uint32_t palette_max; + if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { + palette_max = common_hal_displayio_palette_get_len(self->pixel_shader) - 1; + } else { // colorconverter type + palette_max = 0xFFFFFF; + } + for (uint16_t i = 0; i < MIN(len, self->input_color_count); i++) { int mapping_val = mp_arg_validate_type_int(items[i], MP_QSTR_mapping_value); - mp_arg_validate_int_range(mapping_val, 0, palette_len - 1, MP_QSTR_mapping_value); + mp_arg_validate_int_range(mapping_val, 0, palette_max, MP_QSTR_mapping_value); self->tile_mappings[y * self->width_in_tiles + x][i] = mapping_val; } self->needs_refresh = true; @@ -59,14 +72,23 @@ void common_hal_tilepalettemapper_tilepalettemapper_set_mapping(tilepalettemappe void tilepalettemapper_tilepalettemapper_get_color(tilepalettemapper_tilepalettemapper_t *self, const _displayio_colorspace_t *colorspace, displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color, uint16_t x_tile_index, uint16_t y_tile_index) { if (x_tile_index >= self->width_in_tiles || y_tile_index >= self->height_in_tiles) { - displayio_palette_get_color(self->palette, colorspace, input_pixel, output_color); + if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { + displayio_palette_get_color(self->pixel_shader, colorspace, input_pixel, output_color); + } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { + displayio_colorconverter_convert(self->pixel_shader, colorspace, input_pixel, output_color); + } return; } uint16_t tile_index = y_tile_index * self->width_in_tiles + x_tile_index; uint32_t mapped_index = self->tile_mappings[tile_index][input_pixel->pixel]; displayio_input_pixel_t tmp_pixel; tmp_pixel.pixel = mapped_index; - displayio_palette_get_color(self->palette, colorspace, &tmp_pixel, output_color); + if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { + displayio_palette_get_color(self->pixel_shader, colorspace, &tmp_pixel, output_color); + } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { + displayio_colorconverter_convert(self->pixel_shader, colorspace, &tmp_pixel, output_color); + } + } bool tilepalettemapper_tilepalettemapper_needs_refresh(tilepalettemapper_tilepalettemapper_t *self) { diff --git a/shared-module/tilepalettemapper/TilePaletteMapper.h b/shared-module/tilepalettemapper/TilePaletteMapper.h index 8502d4bf53601..98226ae7e04fa 100644 --- a/shared-module/tilepalettemapper/TilePaletteMapper.h +++ b/shared-module/tilepalettemapper/TilePaletteMapper.h @@ -15,11 +15,11 @@ typedef struct { mp_obj_base_t base; - mp_obj_t palette; + mp_obj_t pixel_shader; uint16_t width_in_tiles; uint16_t height_in_tiles; uint16_t input_color_count; - uint16_t **tile_mappings; + uint32_t **tile_mappings; bool needs_refresh; } tilepalettemapper_tilepalettemapper_t; From 2f4cd7497de9b06f505df53d7f818f6fa9f242f2 Mon Sep 17 00:00:00 2001 From: eightycc Date: Tue, 18 Mar 2025 06:32:32 -0700 Subject: [PATCH 06/15] Use MICROPY_HW_MCU_NAME for sysname and nodename for all ports. --- ports/analog/common-hal/os/__init__.c | 4 ++-- ports/atmel-samd/common-hal/os/__init__.c | 10 ++-------- ports/cxd56/common-hal/os/__init__.c | 4 ++-- ports/litex/common-hal/os/__init__.c | 4 ++-- ports/mimxrt10xx/common-hal/os/__init__.c | 4 ++-- ports/nordic/common-hal/os/__init__.c | 4 ++-- ports/renode/common-hal/os/__init__.c | 4 ++-- ports/silabs/common-hal/os/__init__.c | 4 ++-- ports/stm/common-hal/os/__init__.c | 4 ++-- ports/zephyr-cp/common-hal/os/__init__.c | 4 ++-- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c index 1f89300c4c182..a32947cb8b054 100644 --- a/ports/analog/common-hal/os/__init__.c +++ b/ports/analog/common-hal/os/__init__.c @@ -19,8 +19,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "max32"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "max32"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); diff --git a/ports/atmel-samd/common-hal/os/__init__.c b/ports/atmel-samd/common-hal/os/__init__.c index 2c1de431c6635..1926fdc73e3d8 100644 --- a/ports/atmel-samd/common-hal/os/__init__.c +++ b/ports/atmel-samd/common-hal/os/__init__.c @@ -20,14 +20,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -#ifdef SAMD21 -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "samd21"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "samd21"); -#endif -#ifdef SAM_D5X_E5X -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "samd51"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "samd51"); -#endif +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); diff --git a/ports/cxd56/common-hal/os/__init__.c b/ports/cxd56/common-hal/os/__init__.c index 7d211b3a79d06..3d06d524fd36b 100644 --- a/ports/cxd56/common-hal/os/__init__.c +++ b/ports/cxd56/common-hal/os/__init__.c @@ -15,8 +15,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "spresense"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "spresense"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); diff --git a/ports/litex/common-hal/os/__init__.c b/ports/litex/common-hal/os/__init__.c index e6da1904da522..4595ae4804bfb 100644 --- a/ports/litex/common-hal/os/__init__.c +++ b/ports/litex/common-hal/os/__init__.c @@ -16,8 +16,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "litex"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "litex"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); diff --git a/ports/mimxrt10xx/common-hal/os/__init__.c b/ports/mimxrt10xx/common-hal/os/__init__.c index 79ae228dc4240..6c19ff997967e 100644 --- a/ports/mimxrt10xx/common-hal/os/__init__.c +++ b/ports/mimxrt10xx/common-hal/os/__init__.c @@ -21,8 +21,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "mimxrt10xx"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "mimxrt10xx"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); diff --git a/ports/nordic/common-hal/os/__init__.c b/ports/nordic/common-hal/os/__init__.c index 78aa1e040cf8e..a835be1504fa8 100644 --- a/ports/nordic/common-hal/os/__init__.c +++ b/ports/nordic/common-hal/os/__init__.c @@ -21,8 +21,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "nrf52"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "nrf52"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); diff --git a/ports/renode/common-hal/os/__init__.c b/ports/renode/common-hal/os/__init__.c index 334742bb594e3..e9f555d7d561c 100644 --- a/ports/renode/common-hal/os/__init__.c +++ b/ports/renode/common-hal/os/__init__.c @@ -16,8 +16,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "renode"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "renode"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); diff --git a/ports/silabs/common-hal/os/__init__.c b/ports/silabs/common-hal/os/__init__.c index 42036536e4ff6..d7a54429f4bde 100644 --- a/ports/silabs/common-hal/os/__init__.c +++ b/ports/silabs/common-hal/os/__init__.c @@ -39,8 +39,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, EFR32_SERIES_LOWER); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, EFR32_SERIES_LOWER); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); diff --git a/ports/stm/common-hal/os/__init__.c b/ports/stm/common-hal/os/__init__.c index b3d9e67d98893..beeb66f7cd556 100644 --- a/ports/stm/common-hal/os/__init__.c +++ b/ports/stm/common-hal/os/__init__.c @@ -19,8 +19,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, STM32_SERIES_LOWER); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, STM32_SERIES_LOWER); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); diff --git a/ports/zephyr-cp/common-hal/os/__init__.c b/ports/zephyr-cp/common-hal/os/__init__.c index 58e6674cb1157..d173f43312355 100644 --- a/ports/zephyr-cp/common-hal/os/__init__.c +++ b/ports/zephyr-cp/common-hal/os/__init__.c @@ -17,8 +17,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "nrf52"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "nrf52"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); From 9b3731c694cedbb86eb9ae2d8a98d43b1f118d09 Mon Sep 17 00:00:00 2001 From: eightycc Date: Wed, 19 Mar 2025 09:10:10 -0700 Subject: [PATCH 07/15] Remove watchdog.deinit() for 10.0.0. --- shared-bindings/watchdog/WatchDogTimer.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/shared-bindings/watchdog/WatchDogTimer.c b/shared-bindings/watchdog/WatchDogTimer.c index 19e931d0dcc4d..dbb91311345f2 100644 --- a/shared-bindings/watchdog/WatchDogTimer.c +++ b/shared-bindings/watchdog/WatchDogTimer.c @@ -48,24 +48,6 @@ static mp_obj_t watchdog_watchdogtimer_feed(mp_obj_t self_in) { } static MP_DEFINE_CONST_FUN_OBJ_1(watchdog_watchdogtimer_feed_obj, watchdog_watchdogtimer_feed); -//| def deinit(self) -> None: -//| """Stop the watchdog timer. -//| -//| :raises RuntimeError: if the watchdog timer cannot be disabled on this platform. -//| -//| .. note:: This is deprecated in ``9.0.0`` and will be removed in ``10.0.0``. -//| Set watchdog `mode` to `None` instead. -//| -//| """ -//| ... -//| -static mp_obj_t watchdog_watchdogtimer_deinit(mp_obj_t self_in) { - watchdog_watchdogtimer_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_watchdog_deinit(self); - return mp_const_none; -} -static MP_DEFINE_CONST_FUN_OBJ_1(watchdog_watchdogtimer_deinit_obj, watchdog_watchdogtimer_deinit); - //| timeout: float //| """The maximum number of seconds that can elapse between calls //| to `feed()`. Setting the timeout will also feed the watchdog.""" @@ -126,7 +108,6 @@ MP_PROPERTY_GETSET(watchdog_watchdogtimer_mode_obj, static const mp_rom_map_elem_t watchdog_watchdogtimer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_feed), MP_ROM_PTR(&watchdog_watchdogtimer_feed_obj) }, - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&watchdog_watchdogtimer_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_timeout), MP_ROM_PTR(&watchdog_watchdogtimer_timeout_obj) }, { MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&watchdog_watchdogtimer_mode_obj) }, }; From 9b89ee83606e2792ac77ff60ee4276df68ff8243 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 19 Mar 2025 15:55:00 -0500 Subject: [PATCH 08/15] update docstring to new name --- shared-bindings/tilepalettemapper/TilePaletteMapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/tilepalettemapper/TilePaletteMapper.c b/shared-bindings/tilepalettemapper/TilePaletteMapper.c index f30977ee6e527..88189de549dbb 100644 --- a/shared-bindings/tilepalettemapper/TilePaletteMapper.c +++ b/shared-bindings/tilepalettemapper/TilePaletteMapper.c @@ -75,7 +75,7 @@ MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_height_obj, (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_height_obj); -//| palette: Union[displayio.Palette, displayio.ColorConverter] +//| pixel_shader: Union[displayio.Palette, displayio.ColorConverter] //| """The palette or ColorConverter that the mapper uses.""" //| static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_pixel_shader(mp_obj_t self_in) { From 8afdccc2cffcf7c95a4c77520fb690c366b8f0e9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 19 Mar 2025 15:59:32 -0500 Subject: [PATCH 09/15] check if pins exist before using --- tests/circuitpython-manual/usb/device_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/circuitpython-manual/usb/device_info.py b/tests/circuitpython-manual/usb/device_info.py index 7b8631a8f865a..3481707055507 100644 --- a/tests/circuitpython-manual/usb/device_info.py +++ b/tests/circuitpython-manual/usb/device_info.py @@ -9,7 +9,8 @@ d.switch_to_output(value=True) print("USB power on") -h = usb_host.Port(board.USB_HOST_DP, board.USB_HOST_DM) +if hasattr(board, "USB_HOST_DP") and hasattr(board, "USB_HOST_DM"): + h = usb_host.Port(board.USB_HOST_DP, board.USB_HOST_DM) while True: for device in usb.core.find(find_all=True): From 7c0fa46cf8e8bef94606c0f894e0beb38c27d3cd Mon Sep 17 00:00:00 2001 From: page200 <69221289+page200@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:47:34 +0100 Subject: [PATCH 10/15] Suspected typo: last "S" in "STM32F412xGS" Because https://www.st.com/resource/en/data_brief/32f412gdiscovery.pdf says "STM32F412ZGT6" --- ports/stm/boards/stm32f412zg_discovery/mpconfigboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm/boards/stm32f412zg_discovery/mpconfigboard.h b/ports/stm/boards/stm32f412zg_discovery/mpconfigboard.h index e771532437f6b..b068b8e2d517c 100644 --- a/ports/stm/boards/stm32f412zg_discovery/mpconfigboard.h +++ b/ports/stm/boards/stm32f412zg_discovery/mpconfigboard.h @@ -9,7 +9,7 @@ // Micropython setup #define MICROPY_HW_BOARD_NAME "STM32F412G_DISCO" -#define MICROPY_HW_MCU_NAME "STM32F412xGS" +#define MICROPY_HW_MCU_NAME "STM32F412xG" #define FLASH_SIZE (0x100000) #define FLASH_PAGE_SIZE (0x4000) From df3327179d1516dfc6e38792bcc847aa20a9c649 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 19 Mar 2025 20:45:35 -0400 Subject: [PATCH 11/15] CIRCUITPY_FULL_BUILD now controls a few more features --- ports/analog/mpconfigport.h | 3 --- ports/atmel-samd/mpconfigport.h | 3 +-- ports/broadcom/mpconfigport.h | 4 +--- ports/cxd56/boards/spresense/mpconfigboard.h | 2 -- ports/cxd56/mpconfigport.h | 3 --- ports/espressif/mpconfigport.h | 3 --- ports/litex/mpconfigport.h | 2 -- ports/mimxrt10xx/mpconfigport.h | 4 ---- ports/nordic/mpconfigport.h | 2 -- ports/raspberrypi/mpconfigport.h | 3 --- ports/renode/mpconfigport.h | 3 --- ports/silabs/mpconfigport.h | 3 --- ports/stm/mpconfigport.h | 3 --- py/circuitpy_mpconfig.h | 22 ++++++++++++++++++++ 14 files changed, 24 insertions(+), 36 deletions(-) diff --git a/ports/analog/mpconfigport.h b/ports/analog/mpconfigport.h index cadfbddbc55bb..c4b3ee031cacf 100644 --- a/ports/analog/mpconfigport.h +++ b/ports/analog/mpconfigport.h @@ -9,9 +9,6 @@ #include -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - // 24KiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index f02f3d595d9b4..eca28dbd9be00 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -68,8 +68,7 @@ #define MICROPY_PY_SYS_PLATFORM "MicroChip SAME54" #endif #define SPI_FLASH_MAX_BAUDRATE 24000000 -#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) -#define MICROPY_PY_FUNCTION_ATTRS (1) + // MICROPY_PY_ERRNO_LIST - Use the default #endif // SAM_D5X_E5X diff --git a/ports/broadcom/mpconfigport.h b/ports/broadcom/mpconfigport.h index 648259720f800..8b749ca03100a 100644 --- a/ports/broadcom/mpconfigport.h +++ b/ports/broadcom/mpconfigport.h @@ -13,9 +13,7 @@ #define CIRCUITPY_MCU_FAMILY broadcom #define MICROPY_PY_SYS_PLATFORM "BROADCOM" -#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + #if BCM_VERSION == 2837 || BCM_VERSION == 2711 #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A) #elif BCM_VERSION == 2835 diff --git a/ports/cxd56/boards/spresense/mpconfigboard.h b/ports/cxd56/boards/spresense/mpconfigboard.h index 2d334ef29b301..c9510771b1855 100644 --- a/ports/cxd56/boards/spresense/mpconfigboard.h +++ b/ports/cxd56/boards/spresense/mpconfigboard.h @@ -18,5 +18,3 @@ #define DEFAULT_UART_BUS_RX (&pin_UART2_RXD) #define DEFAULT_UART_BUS_TX (&pin_UART2_TXD) - -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) diff --git a/ports/cxd56/mpconfigport.h b/ports/cxd56/mpconfigport.h index b779b521ddaf9..3bcb252868786 100644 --- a/ports/cxd56/mpconfigport.h +++ b/ports/cxd56/mpconfigport.h @@ -8,9 +8,6 @@ #define MICROPY_PY_SYS_PLATFORM "CXD56" -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - // 64kiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE (0x10000) diff --git a/ports/espressif/mpconfigport.h b/ports/espressif/mpconfigport.h index 443a59b0474bd..98c1986240b73 100644 --- a/ports/espressif/mpconfigport.h +++ b/ports/espressif/mpconfigport.h @@ -17,9 +17,6 @@ #define CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY (1) -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - #include "py/circuitpy_mpconfig.h" #define MICROPY_NLR_SETJMP (1) diff --git a/ports/litex/mpconfigport.h b/ports/litex/mpconfigport.h index 50986d16026c2..7ac34a44336cf 100644 --- a/ports/litex/mpconfigport.h +++ b/ports/litex/mpconfigport.h @@ -9,8 +9,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE (0) #define MICROPY_NLR_THUMB (0) -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) #include "py/circuitpy_mpconfig.h" diff --git a/ports/mimxrt10xx/mpconfigport.h b/ports/mimxrt10xx/mpconfigport.h index 4f9acd7a9fd30..4d5e4e59700bd 100644 --- a/ports/mimxrt10xx/mpconfigport.h +++ b/ports/mimxrt10xx/mpconfigport.h @@ -17,10 +17,6 @@ extern uint8_t _ld_filesystem_end; extern uint8_t _ld_default_stack_size; #define CIRCUITPY_DEFAULT_STACK_SIZE ((uint32_t)&_ld_default_stack_size) -#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0) -#define MICROPY_PY_FUNCTION_ATTRS (0) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR ((uint32_t)&_ld_filesystem_start) #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE ((uint32_t)(&_ld_filesystem_end - &_ld_filesystem_start)) diff --git a/ports/nordic/mpconfigport.h b/ports/nordic/mpconfigport.h index ed6c2827000ca..33fcfa371e0bd 100644 --- a/ports/nordic/mpconfigport.h +++ b/ports/nordic/mpconfigport.h @@ -13,8 +13,6 @@ #include "nrf_sdm.h" // for SD_FLASH_SIZE #include "peripherals/nrf/nvm.h" // for FLASH_PAGE_SIZE -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) #define MICROPY_PY_SYS_STDIO_BUFFER (1) // 24kiB stack diff --git a/ports/raspberrypi/mpconfigport.h b/ports/raspberrypi/mpconfigport.h index 00dcafe10fe11..1181517fdf9a0 100644 --- a/ports/raspberrypi/mpconfigport.h +++ b/ports/raspberrypi/mpconfigport.h @@ -16,9 +16,6 @@ #define MICROPY_PY_SYS_PLATFORM "RP2350" #endif -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - // Setting a non-default value also requires a non-default link.ld #ifndef CIRCUITPY_FIRMWARE_SIZE #define CIRCUITPY_FIRMWARE_SIZE (1020 * 1024) diff --git a/ports/renode/mpconfigport.h b/ports/renode/mpconfigport.h index 19937d749d47b..185a884ed313e 100644 --- a/ports/renode/mpconfigport.h +++ b/ports/renode/mpconfigport.h @@ -8,9 +8,6 @@ #define MICROPY_PY_SYS_PLATFORM "Renode" -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - #define MICROPY_USE_INTERNAL_PRINTF (1) // This also includes mpconfigboard.h. diff --git a/ports/silabs/mpconfigport.h b/ports/silabs/mpconfigport.h index ce7739cccaea4..26fe7dfc2f0b5 100644 --- a/ports/silabs/mpconfigport.h +++ b/ports/silabs/mpconfigport.h @@ -29,9 +29,6 @@ #include -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - // 24kiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 diff --git a/ports/stm/mpconfigport.h b/ports/stm/mpconfigport.h index ed36b49ffb92f..afa9aa3685c9a 100644 --- a/ports/stm/mpconfigport.h +++ b/ports/stm/mpconfigport.h @@ -9,9 +9,6 @@ #include -#define MICROPY_PY_FUNCTION_ATTRS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - extern uint8_t _ld_default_stack_size; // 24kiB stack diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 0121144f8ced6..0168b0f4d8254 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -93,6 +93,7 @@ extern void common_hal_mcu_enable_interrupts(void); #define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE) #define MICROPY_OPT_LOAD_ATTR_FAST_PATH (CIRCUITPY_OPT_LOAD_ATTR_FAST_PATH) #define MICROPY_OPT_MAP_LOOKUP_CACHE (CIRCUITPY_OPT_MAP_LOOKUP_CACHE) +#define MICROPY_OPT_MPZ_BITWISE (0) #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (CIRCUITPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) #define MICROPY_PERSISTENT_CODE_LOAD (1) @@ -224,31 +225,52 @@ typedef long mp_off_t; // Turning off FULL_BUILD removes some functionality to reduce flash size on tiny SAMD21s #define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (CIRCUITPY_FULL_BUILD) + #ifndef MICROPY_CPYTHON_COMPAT #define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD) #endif + #ifndef MICROPY_CPYTHON_EXCEPTION_CHAIN #define MICROPY_CPYTHON_EXCEPTION_CHAIN (CIRCUITPY_FULL_BUILD) #endif + #define MICROPY_PY_BUILTINS_POW3 (CIRCUITPY_BUILTINS_POW3) #define MICROPY_PY_FSTRINGS (1) #define MICROPY_MODULE_WEAK_LINKS (0) #define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD) + #ifndef MICROPY_PY_BUILTINS_COMPLEX #define MICROPY_PY_BUILTINS_COMPLEX (CIRCUITPY_FULL_BUILD) #endif + #define MICROPY_PY_BUILTINS_FROZENSET (CIRCUITPY_FULL_BUILD) + +#ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED +#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (CIRCUITPY_FULL_BUILD) +#endif + #define MICROPY_PY_BUILTINS_STR_CENTER (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_BUILTINS_STR_PARTITION (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_BUILTINS_STR_SPLITLINES (CIRCUITPY_FULL_BUILD) + #ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (CIRCUITPY_FULL_BUILD) #endif + #ifndef MICROPY_PY_COLLECTIONS_DEQUE #define MICROPY_PY_COLLECTIONS_DEQUE (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_COLLECTIONS_DEQUE_ITER (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR (CIRCUITPY_FULL_BUILD) #endif + +#ifndef MICROPY_PY_FUNCTION_ATTRS +#define MICROPY_PY_FUNCTION_ATTRS (CIRCUITPY_FULL_BUILD) +#endif + +#ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD) +#endif + #define MICROPY_PY_RE_MATCH_GROUPS (CIRCUITPY_RE) #define MICROPY_PY_RE_MATCH_SPAN_START_END (CIRCUITPY_RE) #define MICROPY_PY_RE_SUB (CIRCUITPY_RE) From 214c2f6dd8278118d19eba8c5e41ee0e57db6e40 Mon Sep 17 00:00:00 2001 From: eightycc Date: Thu, 20 Mar 2025 06:25:46 -0700 Subject: [PATCH 12/15] Factor common_hal_os_uname into os_uname() and remove common_hal_os_uname. --- ports/analog/common-hal/os/__init__.c | 26 --------------------- ports/atmel-samd/common-hal/os/__init__.c | 26 --------------------- ports/broadcom/common-hal/os/__init__.c | 27 ---------------------- ports/cxd56/common-hal/os/__init__.c | 26 --------------------- ports/espressif/common-hal/os/__init__.c | 26 --------------------- ports/litex/common-hal/os/__init__.c | 26 --------------------- ports/mimxrt10xx/common-hal/os/__init__.c | 25 -------------------- ports/nordic/common-hal/os/__init__.c | 26 --------------------- ports/raspberrypi/common-hal/os/__init__.c | 26 --------------------- ports/renode/common-hal/os/__init__.c | 26 --------------------- ports/silabs/common-hal/os/__init__.c | 25 -------------------- ports/stm/common-hal/os/__init__.c | 26 --------------------- ports/zephyr-cp/common-hal/os/__init__.c | 26 --------------------- shared-bindings/os/__init__.c | 24 ++++++++++++++++++- shared-bindings/os/__init__.h | 3 --- shared-module/os/__init__.c | 2 +- 16 files changed, 24 insertions(+), 342 deletions(-) diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c index a32947cb8b054..7b607cf6b3c4b 100644 --- a/ports/analog/common-hal/os/__init__.c +++ b/ports/analog/common-hal/os/__init__.c @@ -15,32 +15,6 @@ // #include "peripherals/periph.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); - -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { #if (HAS_TRNG) // todo (low prior): implement diff --git a/ports/atmel-samd/common-hal/os/__init__.c b/ports/atmel-samd/common-hal/os/__init__.c index 1926fdc73e3d8..89b5e85135d87 100644 --- a/ports/atmel-samd/common-hal/os/__init__.c +++ b/ports/atmel-samd/common-hal/os/__init__.c @@ -16,32 +16,6 @@ #include "hal/include/hal_rand_sync.h" #endif -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #ifdef SAM_D5X_E5X hri_mclk_set_APBCMASK_TRNG_bit(MCLK); diff --git a/ports/broadcom/common-hal/os/__init__.c b/ports/broadcom/common-hal/os/__init__.c index 72a9a07e9077e..c1c50234451ef 100644 --- a/ports/broadcom/common-hal/os/__init__.c +++ b/ports/broadcom/common-hal/os/__init__.c @@ -10,33 +10,6 @@ #include "py/objtuple.h" #include "py/qstr.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; - -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { return false; } diff --git a/ports/cxd56/common-hal/os/__init__.c b/ports/cxd56/common-hal/os/__init__.c index 3d06d524fd36b..e1024108b07dc 100644 --- a/ports/cxd56/common-hal/os/__init__.c +++ b/ports/cxd56/common-hal/os/__init__.c @@ -10,32 +10,6 @@ #include "py/objstr.h" #include "py/objtuple.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; - -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { uint32_t i = 0; diff --git a/ports/espressif/common-hal/os/__init__.c b/ports/espressif/common-hal/os/__init__.c index 4063090fe1f96..fff89c8476d8d 100644 --- a/ports/espressif/common-hal/os/__init__.c +++ b/ports/espressif/common-hal/os/__init__.c @@ -15,32 +15,6 @@ #include "esp_system.h" #include "esp_random.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { uint32_t i = 0; while (i < length) { diff --git a/ports/litex/common-hal/os/__init__.c b/ports/litex/common-hal/os/__init__.c index 4595ae4804bfb..659411187fafb 100644 --- a/ports/litex/common-hal/os/__init__.c +++ b/ports/litex/common-hal/os/__init__.c @@ -12,32 +12,6 @@ #include "shared-bindings/os/__init__.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { return false; } diff --git a/ports/mimxrt10xx/common-hal/os/__init__.c b/ports/mimxrt10xx/common-hal/os/__init__.c index 6c19ff997967e..ac168f2ed09b3 100644 --- a/ports/mimxrt10xx/common-hal/os/__init__.c +++ b/ports/mimxrt10xx/common-hal/os/__init__.c @@ -17,31 +17,6 @@ #include "sdk/drivers/trng/fsl_trng.h" #endif -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #if CIRCUITPY_RANDOM trng_config_t trngConfig; diff --git a/ports/nordic/common-hal/os/__init__.c b/ports/nordic/common-hal/os/__init__.c index a835be1504fa8..54b8ad026a7de 100644 --- a/ports/nordic/common-hal/os/__init__.c +++ b/ports/nordic/common-hal/os/__init__.c @@ -17,32 +17,6 @@ #include "nrf_rng.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); - -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #ifdef BLUETOOTH_SD uint8_t sd_en = 0; diff --git a/ports/raspberrypi/common-hal/os/__init__.c b/ports/raspberrypi/common-hal/os/__init__.c index d9ad1c238ff34..616bb8d8c7929 100644 --- a/ports/raspberrypi/common-hal/os/__init__.c +++ b/ports/raspberrypi/common-hal/os/__init__.c @@ -18,32 +18,6 @@ #include -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - // NIST Special Publication 800-90B (draft) recommends several extractors, // including the SHA hash family and states that if the amount of entropy input // is twice the number of bits output from them, that output can be considered diff --git a/ports/renode/common-hal/os/__init__.c b/ports/renode/common-hal/os/__init__.c index e9f555d7d561c..14e22960469fa 100644 --- a/ports/renode/common-hal/os/__init__.c +++ b/ports/renode/common-hal/os/__init__.c @@ -12,32 +12,6 @@ #include "shared-bindings/os/__init__.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { return false; } diff --git a/ports/silabs/common-hal/os/__init__.c b/ports/silabs/common-hal/os/__init__.c index d7a54429f4bde..79e79875fd541 100644 --- a/ports/silabs/common-hal/os/__init__.c +++ b/ports/silabs/common-hal/os/__init__.c @@ -35,31 +35,6 @@ #include "peripherals/periph.h" #define RNG_TIMEOUT 5 -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); - -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { return false; diff --git a/ports/stm/common-hal/os/__init__.c b/ports/stm/common-hal/os/__init__.c index beeb66f7cd556..d654f844b1767 100644 --- a/ports/stm/common-hal/os/__init__.c +++ b/ports/stm/common-hal/os/__init__.c @@ -15,32 +15,6 @@ #include STM32_HAL_H #include "peripherals/periph.h" -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); - -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - #define RNG_TIMEOUT 5 bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { diff --git a/ports/zephyr-cp/common-hal/os/__init__.c b/ports/zephyr-cp/common-hal/os/__init__.c index d173f43312355..2f37ba40f47a6 100644 --- a/ports/zephyr-cp/common-hal/os/__init__.c +++ b/ports/zephyr-cp/common-hal/os/__init__.c @@ -13,32 +13,6 @@ #include -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); - -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - -mp_obj_t common_hal_os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; -} - bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #if !DT_HAS_CHOSEN(zephyr_entropy) return false; diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index e6f6d4896dc3d..5e28c02452d05 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -44,8 +44,30 @@ //| machine: str //| //| +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + static mp_obj_t os_uname(void) { - return common_hal_os_uname(); + return (mp_obj_t)&os_uname_info_obj; } static MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); diff --git a/shared-bindings/os/__init__.h b/shared-bindings/os/__init__.h index f273708cf4ed9..56b643e2edfbe 100644 --- a/shared-bindings/os/__init__.h +++ b/shared-bindings/os/__init__.h @@ -11,9 +11,6 @@ #include "py/objtuple.h" -extern const mp_rom_obj_tuple_t common_hal_os_uname_info_obj; - -mp_obj_t common_hal_os_uname(void); void common_hal_os_chdir(const char *path); mp_obj_t common_hal_os_getcwd(void); mp_obj_t common_hal_os_getenv(const char *key, mp_obj_t default_); diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c index 81296db854cd3..6afe64dd62d5b 100644 --- a/shared-module/os/__init__.c +++ b/shared-module/os/__init__.c @@ -17,7 +17,7 @@ #include "shared-bindings/os/__init__.h" // This provides all VFS related OS functions so that ports can share the code -// as needed. It does not provide uname. +// as needed. // Version of mp_vfs_lookup_path that takes and returns uPy string objects. static mp_vfs_mount_t *lookup_path(const char *path, mp_obj_t *path_out) { From 1876c7179faed51ccc628537c8be12e9d756e041 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 28 Mar 2025 13:12:58 -0400 Subject: [PATCH 13/15] Convert completely to new displayio bindings; remove warnings --- py/circuitpy_mpconfig.h | 6 ------ py/objmodule.c | 27 --------------------------- shared-bindings/displayio/__init__.c | 15 +-------------- 3 files changed, 1 insertion(+), 47 deletions(-) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 0168b0f4d8254..42e6f1841a445 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -17,12 +17,6 @@ // Always 1: defined in circuitpy_mpconfig.mk // #define CIRCUITPY (1) -// Can be removed once CircuitPython 10 is released. -// Print warnings or not about deprecated names. See objmodule.c. -#ifndef CIRCUITPY_9_10_WARNINGS -#define CIRCUITPY_9_10_WARNINGS (1) -#endif - // REPR_C encodes qstrs, 31-bit ints, and 30-bit floats in a single 32-bit word. #ifndef MICROPY_OBJ_REPR #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C) diff --git a/py/objmodule.c b/py/objmodule.c index b6513907e5551..3ccd31b23af22 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -67,33 +67,6 @@ static void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *de static void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { - // CIRCUITPY-CHANGE - #if CIRCUITPY_9_10_WARNINGS && CIRCUITPY_DISPLAYIO && CIRCUITPY_WARNINGS - if (self == &displayio_module) { - #if CIRCUITPY_BUSDISPLAY - if (attr == MP_QSTR_Display) { - warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_Display, MP_QSTR_displayio, MP_QSTR_busdisplay); - warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q renamed %q"), MP_QSTR_Display, MP_QSTR_BusDisplay); - } - #endif - #if CIRCUITPY_EPAPERDISPLAY - if (attr == MP_QSTR_EPaperDisplay) { - warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_EPaperDisplay, MP_QSTR_displayio, MP_QSTR_epaperdisplay); - } - #endif - #if CIRCUITPY_FOURWIRE - if (attr == MP_QSTR_FourWire) { - warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_FourWire, MP_QSTR_displayio, MP_QSTR_fourwire); - } - #endif - #if CIRCUITPY_I2CDISPLAYBUS - if (attr == MP_QSTR_I2CDisplay) { - warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_I2CDisplay, MP_QSTR_displayio, MP_QSTR_i2cdisplaybus); - warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q renamed %q"), MP_QSTR_I2CDisplay, MP_QSTR_I2CDisplayBus); - } - #endif - } - #endif // load attribute mp_map_elem_t *elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); if (elem != NULL) { diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 136f380f3d33d..e0c35d3bce47d 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -100,21 +100,8 @@ static const mp_rom_map_elem_t displayio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) }, { MP_ROM_QSTR(MP_QSTR_TileGrid), MP_ROM_PTR(&displayio_tilegrid_type) }, - // Remove these in CircuitPython 10 - #if CIRCUITPY_BUSDISPLAY - { MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&busdisplay_busdisplay_type) }, - #endif - #if CIRCUITPY_EPAPERDISPLAY - { MP_ROM_QSTR(MP_QSTR_EPaperDisplay), MP_ROM_PTR(&epaperdisplay_epaperdisplay_type) }, - #endif - #if CIRCUITPY_FOURWIRE - { MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&fourwire_fourwire_type) }, - #endif - #if CIRCUITPY_I2CDISPLAYBUS - { MP_ROM_QSTR(MP_QSTR_I2CDisplay), MP_ROM_PTR(&i2cdisplaybus_i2cdisplaybus_type) }, - #endif - { MP_ROM_QSTR(MP_QSTR_release_displays), MP_ROM_PTR(&displayio_release_displays_obj) }, + { MP_ROM_QSTR(MP_QSTR_CIRCUITPYTHON_TERMINAL), MP_ROM_PTR(&circuitpython_splash) }, }; static MP_DEFINE_CONST_DICT(displayio_module_globals, displayio_module_globals_table); From ca063ae563adb48b62f25b25b93ad421c18f7391 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Mar 2025 11:18:51 -0700 Subject: [PATCH 14/15] Update TinyUSB and close device endpoints --- lib/tinyusb | 2 +- ports/raspberrypi/lib/Pico-PIO-USB | 2 +- shared-bindings/usb/core/Device.c | 22 ++++++++++++++++++++++ shared-bindings/usb/core/Device.h | 1 + shared-module/usb/core/Device.c | 18 +++++++++++++++--- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 6bba41045a422..8c1802e41d37c 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 6bba41045a4224abb68256dcf2fce893da47a743 +Subproject commit 8c1802e41d37c915334a19b859b24cb2a1b48ee5 diff --git a/ports/raspberrypi/lib/Pico-PIO-USB b/ports/raspberrypi/lib/Pico-PIO-USB index 1862cc008e026..e0aba546813d8 160000 --- a/ports/raspberrypi/lib/Pico-PIO-USB +++ b/ports/raspberrypi/lib/Pico-PIO-USB @@ -1 +1 @@ -Subproject commit 1862cc008e026cbd07b97b28e29eafb5f38b35fb +Subproject commit e0aba546813d89cb7f321bef3363bfba5f282e14 diff --git a/shared-bindings/usb/core/Device.c b/shared-bindings/usb/core/Device.c index 28d178b748eae..683115a842102 100644 --- a/shared-bindings/usb/core/Device.c +++ b/shared-bindings/usb/core/Device.c @@ -39,6 +39,7 @@ #include "py/objproperty.h" #include "shared-bindings/usb/core/Device.h" +#include "shared-bindings/util.h" #include "py/runtime.h" //| class Device: @@ -49,6 +50,12 @@ //| ... //| +static void check_for_deinit(usb_core_device_obj_t *self) { + if (common_hal_usb_core_device_deinited(self)) { + raise_deinited_error(); + } +} + //| def __del__(self) -> None: //| """Closes any resources used for this device.""" //| ... @@ -64,6 +71,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_deinit_obj, usb_core_device_dei //| """The USB vendor ID of the device""" static mp_obj_t usb_core_device_obj_get_idVendor(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_idVendor(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_idVendor_obj, usb_core_device_obj_get_idVendor); @@ -75,6 +83,7 @@ MP_PROPERTY_GETTER(usb_core_device_idVendor_obj, //| """The USB product ID of the device""" static mp_obj_t usb_core_device_obj_get_idProduct(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_idProduct(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_idProduct_obj, usb_core_device_obj_get_idProduct); @@ -86,6 +95,7 @@ MP_PROPERTY_GETTER(usb_core_device_idProduct_obj, //| """The USB device's serial number string.""" static mp_obj_t usb_core_device_obj_get_serial_number(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return common_hal_usb_core_device_get_serial_number(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_serial_number_obj, usb_core_device_obj_get_serial_number); @@ -97,6 +107,7 @@ MP_PROPERTY_GETTER(usb_core_device_serial_number_obj, //| """The USB device's product string.""" static mp_obj_t usb_core_device_obj_get_product(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return common_hal_usb_core_device_get_product(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_product_obj, usb_core_device_obj_get_product); @@ -109,6 +120,7 @@ MP_PROPERTY_GETTER(usb_core_device_product_obj, //| static mp_obj_t usb_core_device_obj_get_manufacturer(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return common_hal_usb_core_device_get_manufacturer(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_manufacturer_obj, usb_core_device_obj_get_manufacturer); @@ -121,6 +133,7 @@ MP_PROPERTY_GETTER(usb_core_device_manufacturer_obj, //| static mp_obj_t usb_core_device_obj_get_bus(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_bus(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_bus_obj, usb_core_device_obj_get_bus); @@ -134,6 +147,7 @@ MP_PROPERTY_GETTER(usb_core_device_bus_obj, //| static mp_obj_t usb_core_device_obj_get_port_numbers(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return common_hal_usb_core_device_get_port_numbers(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_port_numbers_obj, usb_core_device_obj_get_port_numbers); @@ -147,6 +161,7 @@ MP_PROPERTY_GETTER(usb_core_device_port_numbers_obj, //| static mp_obj_t usb_core_device_obj_get_speed(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_speed(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_speed_obj, usb_core_device_obj_get_speed); @@ -171,6 +186,7 @@ static mp_obj_t usb_core_device_set_configuration(size_t n_args, const mp_obj_t { MP_QSTR_configuration, MP_ARG_INT, {.u_int = 1} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -197,6 +213,7 @@ static mp_obj_t usb_core_device_write(size_t n_args, const mp_obj_t *pos_args, m { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 0} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -228,6 +245,7 @@ static mp_obj_t usb_core_device_read(size_t n_args, const mp_obj_t *pos_args, mp { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 0} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -277,6 +295,7 @@ static mp_obj_t usb_core_device_ctrl_transfer(size_t n_args, const mp_obj_t *pos { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 0} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -310,6 +329,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(usb_core_device_ctrl_transfer_obj, 2, usb_core_device //| static mp_obj_t usb_core_device_is_kernel_driver_active(mp_obj_t self_in, mp_obj_t interface_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); mp_int_t interface = mp_obj_get_int(interface_in); bool active = common_hal_usb_core_device_is_kernel_driver_active(self, interface); return mp_obj_new_bool(active); @@ -327,6 +347,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(usb_core_device_is_kernel_driver_active_obj, usb_core_ //| static mp_obj_t usb_core_device_detach_kernel_driver(mp_obj_t self_in, mp_obj_t interface_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); mp_int_t interface = mp_obj_get_int(interface_in); common_hal_usb_core_device_detach_kernel_driver(self, interface); return mp_const_none; @@ -343,6 +364,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(usb_core_device_detach_kernel_driver_obj, usb_core_dev //| static mp_obj_t usb_core_device_attach_kernel_driver(mp_obj_t self_in, mp_obj_t interface_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); mp_int_t interface = mp_obj_get_int(interface_in); common_hal_usb_core_device_attach_kernel_driver(self, interface); return mp_const_none; diff --git a/shared-bindings/usb/core/Device.h b/shared-bindings/usb/core/Device.h index 7278ca297ede3..28c2cfbe19860 100644 --- a/shared-bindings/usb/core/Device.h +++ b/shared-bindings/usb/core/Device.h @@ -13,6 +13,7 @@ extern const mp_obj_type_t usb_core_device_type; bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t device_number); +bool common_hal_usb_core_device_deinited(usb_core_device_obj_t *self); void common_hal_usb_core_device_deinit(usb_core_device_obj_t *self); uint16_t common_hal_usb_core_device_get_idVendor(usb_core_device_obj_t *self); uint16_t common_hal_usb_core_device_get_idProduct(usb_core_device_obj_t *self); diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 10fdf63b1ed6f..0a52b925facf1 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -49,10 +49,22 @@ bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t d return true; } +bool common_hal_usb_core_device_deinited(usb_core_device_obj_t *self) { + return self->device_address == 0; +} + void common_hal_usb_core_device_deinit(usb_core_device_obj_t *self) { - // TODO: Close all of the endpoints we've opened. Some drivers store state - // for each open endpoint. If we don't close them, then we'll leak memory. - // Waiting for TinyUSB to add this. + if (common_hal_usb_core_device_deinited(self)) { + return; + } + size_t open_size = sizeof(self->open_endpoints); + for (size_t i = 0; i < open_size; i++) { + if (self->open_endpoints[i] != 0) { + tuh_edpt_close(self->device_address, self->open_endpoints[i]); + self->open_endpoints[i] = 0; + } + } + self->device_address = 0; } uint16_t common_hal_usb_core_device_get_idVendor(usb_core_device_obj_t *self) { From 232c7ff9d0909aa2d1e8d09137542f81bccb37fa Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Sat, 29 Mar 2025 10:25:45 -0500 Subject: [PATCH 15/15] Revert "Merge branch 'adafruit:main' into audiodelays_stereo_freq_shift_fix" This reverts commit db3a47d065e5ddb83515791e0d006a5ad2ee0cbd, reversing changes made to b4698a5135f0d8b2275ef99d85c5842042b2c914. --- .github/pull_request_template.md | 10 -- .pre-commit-config.yaml | 5 +- docs/library/errno.rst | 2 +- lib/tinyusb | 2 +- main.c | 6 +- ports/analog/common-hal/os/__init__.c | 26 +++++ ports/analog/mpconfigport.h | 3 + .../atmel-samd/common-hal/audioio/AudioOut.c | 7 +- ports/atmel-samd/common-hal/os/__init__.c | 32 +++++++ ports/atmel-samd/mpconfigport.h | 3 +- ports/broadcom/common-hal/os/__init__.c | 27 ++++++ ports/broadcom/mpconfigport.h | 4 +- ports/cxd56/boards/spresense/mpconfigboard.h | 2 + ports/cxd56/common-hal/os/__init__.c | 26 +++++ ports/cxd56/mpconfigport.h | 3 + .../mpconfigboard.mk | 1 + .../boards/waveshare_esp32_s3_geek/board.c | 9 ++ .../waveshare_esp32_s3_geek/mpconfigboard.h | 6 +- .../boards/waveshare_esp32_s3_geek/pins.c | 15 ++- .../waveshare_esp32_s3_touch_lcd_2/board.c | 78 --------------- .../mpconfigboard.h | 19 ---- .../mpconfigboard.mk | 14 --- .../waveshare_esp32_s3_touch_lcd_2/pins.c | 94 ------------------- .../waveshare_esp32_s3_touch_lcd_2/sdkconfig | 0 ports/espressif/common-hal/audioio/AudioOut.c | 76 ++++++++------- ports/espressif/common-hal/os/__init__.c | 26 +++++ ports/espressif/common-hal/pulseio/PulseIn.c | 3 - ports/espressif/common-hal/pulseio/PulseOut.c | 3 - ports/espressif/mpconfigport.h | 3 + ports/litex/common-hal/os/__init__.c | 26 +++++ ports/litex/mpconfigport.h | 2 + ports/mimxrt10xx/common-hal/os/__init__.c | 25 +++++ ports/mimxrt10xx/mpconfigport.h | 4 + ports/nordic/common-hal/os/__init__.c | 26 +++++ ports/nordic/mpconfigport.h | 2 + ports/raspberrypi/Makefile | 9 +- ports/raspberrypi/audio_dma.c | 2 +- ports/raspberrypi/audio_dma.h | 2 +- ports/raspberrypi/bindings/cyw43/__init__.c | 2 +- .../boards/adafruit_fruit_jam/pins.c | 7 +- .../boards/adafruit_macropad_rp2040/board.c | 2 +- .../boards/adafruit_qt2040_trinkey/board.c | 2 +- .../boards/boardsource_blok/board.c | 2 +- .../bradanlanestudio_explorer_rp2040/board.c | 4 +- .../jpconstantineau_encoderpad_rp2040/board.c | 2 +- .../boards/jpconstantineau_pykey18/board.c | 2 +- .../boards/jpconstantineau_pykey44/board.c | 2 +- .../boards/jpconstantineau_pykey60/board.c | 2 +- .../boards/jpconstantineau_pykey87/board.c | 2 +- ports/raspberrypi/boards/ugame22/board.c | 2 +- ports/raspberrypi/boards/wk-50/board.c | 2 +- .../boards/zrichard_rp2.65-f/board.c | 2 +- ports/raspberrypi/boot_stage2/RP2040.c.jinja | 8 +- .../common-hal/analogbufio/BufferedIn.c | 6 +- .../common-hal/analogbufio/BufferedIn.h | 2 +- .../common-hal/analogio/AnalogIn.c | 2 +- .../common-hal/audiopwmio/PWMAudioOut.c | 4 +- ports/raspberrypi/common-hal/busio/I2C.c | 2 +- ports/raspberrypi/common-hal/busio/I2C.h | 2 +- ports/raspberrypi/common-hal/busio/SPI.c | 4 +- ports/raspberrypi/common-hal/busio/SPI.h | 2 +- ports/raspberrypi/common-hal/busio/UART.c | 4 +- ports/raspberrypi/common-hal/busio/UART.h | 2 +- .../raspberrypi/common-hal/countio/Counter.c | 6 +- .../common-hal/digitalio/DigitalInOut.c | 2 +- .../common-hal/i2ctarget/I2CTarget.c | 2 +- .../common-hal/i2ctarget/I2CTarget.h | 2 +- .../imagecapture/ParallelImageCapture.c | 4 +- .../common-hal/max3421e/Max3421E.c | 2 +- .../common-hal/microcontroller/Pin.c | 2 +- .../common-hal/microcontroller/Processor.c | 25 +++-- .../common-hal/microcontroller/Processor.h | 2 +- .../common-hal/microcontroller/__init__.c | 6 +- .../common-hal/microcontroller/__init__.h | 2 +- ports/raspberrypi/common-hal/nvm/ByteArray.c | 2 +- ports/raspberrypi/common-hal/os/__init__.c | 26 +++++ .../common-hal/picodvi/Framebuffer_RP2040.c | 14 +-- .../common-hal/picodvi/Framebuffer_RP2350.c | 10 +- .../raspberrypi/common-hal/pulseio/PulseIn.c | 2 +- .../raspberrypi/common-hal/pulseio/PulseIn.h | 2 +- .../raspberrypi/common-hal/pulseio/PulseOut.c | 6 +- .../raspberrypi/common-hal/pulseio/PulseOut.h | 2 +- ports/raspberrypi/common-hal/pwmio/PWMOut.c | 8 +- .../common-hal/rgbmatrix/RGBMatrix.c | 4 +- .../common-hal/rp2pio/StateMachine.c | 22 ++--- .../common-hal/rp2pio/StateMachine.h | 2 +- ports/raspberrypi/common-hal/rtc/RTC.c | 4 +- .../common-hal/socketpool/Socket.c | 2 +- ports/raspberrypi/common-hal/usb_host/Port.c | 18 ++-- ports/raspberrypi/cyw43_configport.h | 2 +- ports/raspberrypi/lib/Pico-PIO-USB | 2 +- ports/raspberrypi/lwip_inc/lwipopts.h | 1 - ports/raspberrypi/mpconfigport.h | 3 + ports/raspberrypi/mphalport.c | 2 +- ports/raspberrypi/supervisor/internal_flash.c | 8 +- ports/raspberrypi/supervisor/port.c | 24 ++--- ports/raspberrypi/supervisor/usb.c | 4 +- ports/renode/common-hal/os/__init__.c | 26 +++++ ports/renode/mpconfigport.h | 3 + ports/silabs/common-hal/os/__init__.c | 25 +++++ ports/silabs/mpconfigport.h | 3 + ports/stm/common-hal/os/__init__.c | 26 +++++ ports/stm/mpconfigport.h | 3 + ports/zephyr-cp/common-hal/os/__init__.c | 26 +++++ py/circuitpy_defns.mk | 2 +- py/circuitpy_mpconfig.h | 28 ++---- py/objmodule.c | 27 ++++++ shared-bindings/_stage/__init__.c | 4 +- shared-bindings/aesio/aes.c | 6 +- shared-bindings/alarm/time/TimeAlarm.c | 6 -- shared-bindings/analogio/AnalogOut.c | 3 - shared-bindings/audioio/AudioOut.c | 15 +-- shared-bindings/busio/I2C.c | 3 - shared-bindings/busio/SPI.c | 4 +- shared-bindings/displayio/TileGrid.c | 2 +- shared-bindings/displayio/__init__.c | 15 ++- shared-bindings/epaperdisplay/EPaperDisplay.c | 3 +- shared-bindings/fourwire/FourWire.c | 6 +- shared-bindings/i2cdisplaybus/I2CDisplayBus.c | 6 +- shared-bindings/index.rst | 6 -- shared-bindings/keypad/EventQueue.c | 5 +- shared-bindings/os/__init__.c | 24 +---- shared-bindings/os/__init__.h | 3 + .../paralleldisplaybus/ParallelBus.c | 6 +- shared-bindings/rotaryio/IncrementalEncoder.c | 8 +- shared-bindings/socketpool/SocketPool.c | 4 + shared-bindings/synthio/LFO.c | 2 +- .../tilepalettemapper/TilePaletteMapper.c | 26 +++-- .../tilepalettemapper/TilePaletteMapper.h | 2 +- shared-bindings/usb/core/Device.c | 22 ----- shared-bindings/usb/core/Device.h | 1 - shared-module/audiomp3/MP3Decoder.c | 2 +- shared-module/keypad/EventQueue.c | 6 +- shared-module/os/__init__.c | 2 +- .../tilepalettemapper/TilePaletteMapper.c | 46 +++------ .../tilepalettemapper/TilePaletteMapper.h | 4 +- shared-module/usb/core/Device.c | 18 +--- shared-module/usb_cdc/Serial.c | 8 +- supervisor/shared/serial.c | 2 +- supervisor/shared/usb/usb_msc_flash.c | 6 +- tests/circuitpython-manual/usb/device_info.py | 3 +- tests/circuitpython/issue9705.py | 12 ++- tests/circuitpython/issue9705.py.exp | 20 ++-- 143 files changed, 725 insertions(+), 656 deletions(-) delete mode 100644 .github/pull_request_template.md delete mode 100644 ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/board.c delete mode 100644 ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.h delete mode 100644 ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.mk delete mode 100644 ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/pins.c delete mode 100644 ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/sdkconfig diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 21f1e4e630ae2..0000000000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,10 +0,0 @@ -Thanks for submitting a pull request to CircuitPython! Remove these instructions before submitting. - - See https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github for detailed instructions. - -- Consider whether to submit this PR against `main` or against (if it exists) the branch for the current stable release or an upcoming minor release. The branch will be named `i.j.x`, for example, `9.2.x`. Bug fixes and minor enhancements can be submitted against the stable release branch, and will be merged to `main` regularly. -- Create your own fork of `circuitpython` and create a branch for your changes. -- Use `pre-commit` to check your commits before submitting. See https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github/check-your-code. -- Test your changes and tell us how you tested. - ---- diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95bc80657212c..0fa10f2043042 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,9 +10,9 @@ repos: hooks: - id: check-yaml - id: end-of-file-fixer - exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|ports/mimxrt10xx/sdk|ports/raspberrypi/sdk|lib/tinyusb)' + exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|ports/raspberrypi/sdk|lib/tinyusb)' - id: trailing-whitespace - exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|lib/mbedtls_errors/generate_errors.diff|ports/raspberrypi/sdk|ports/mimxrt10xx/sdk|lib/tinyusb)' + exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|lib/mbedtls_errors/generate_errors.diff|ports/raspberrypi/sdk|lib/tinyusb)' - repo: https://github.com/codespell-project/codespell rev: v2.2.4 hooks: @@ -59,4 +59,3 @@ repos: rev: "v2.5.0" hooks: - id: pyproject-fmt - exclude: '^(ports/mimxrt10xx/sdk)' diff --git a/docs/library/errno.rst b/docs/library/errno.rst index 10ecd4d2c791d..61970291df57a 100644 --- a/docs/library/errno.rst +++ b/docs/library/errno.rst @@ -7,7 +7,7 @@ |see_cpython_module| :mod:`python:errno`. This module provides access to symbolic error codes for `OSError` exception. -Some codes are not available on the smallest CircuitPython builds, such as SAMD21, for space reasons. +The codes available may vary per CircuitPython build. Constants --------- diff --git a/lib/tinyusb b/lib/tinyusb index 8c1802e41d37c..6bba41045a422 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 8c1802e41d37c915334a19b859b24cb2a1b48ee5 +Subproject commit 6bba41045a4224abb68256dcf2fce893da47a743 diff --git a/main.c b/main.c index 0ea389635f40f..c9c7acb11f7ba 100644 --- a/main.c +++ b/main.c @@ -131,9 +131,9 @@ static uint8_t *_allocate_memory(safe_mode_t safe_mode, const char *env_key, siz *final_size = default_size; #if CIRCUITPY_OS_GETENV if (safe_mode == SAFE_MODE_NONE) { - mp_int_t size; - if (common_hal_os_getenv_int(env_key, &size) == GETENV_OK && size > 0) { - *final_size = size; + (void)common_hal_os_getenv_int(env_key, (mp_int_t *)final_size); + if (*final_size < 0) { + *final_size = default_size; } } #endif diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c index 7b607cf6b3c4b..1f89300c4c182 100644 --- a/ports/analog/common-hal/os/__init__.c +++ b/ports/analog/common-hal/os/__init__.c @@ -15,6 +15,32 @@ // #include "peripherals/periph.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "max32"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "max32"); + +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { #if (HAS_TRNG) // todo (low prior): implement diff --git a/ports/analog/mpconfigport.h b/ports/analog/mpconfigport.h index c4b3ee031cacf..cadfbddbc55bb 100644 --- a/ports/analog/mpconfigport.h +++ b/ports/analog/mpconfigport.h @@ -9,6 +9,9 @@ #include +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + // 24KiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index f7af5e292a719..d9078a7470902 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -79,9 +79,6 @@ static void ramp_value(uint16_t start, uint16_t end) { // Caller validates that pins are free. void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, const mcu_pin_obj_t *left_channel, const mcu_pin_obj_t *right_channel, uint16_t quiescent_value) { - - // The case of left_channel == right_channel is already disallowed in shared-bindings. - #ifdef SAM_D5X_E5X bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK); #endif @@ -110,6 +107,10 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, if (right_channel != NULL && right_channel != &pin_PA02 && right_channel != &pin_PA05) { raise_ValueError_invalid_pin_name(MP_QSTR_right_channel); } + if (right_channel == left_channel) { + mp_raise_ValueError_varg(MP_ERROR_TEXT("%q and %q must be different"), + MP_QSTR_left_channel, MP_QSTR_right_channel); + } claim_pin(left_channel); if (right_channel != NULL) { claim_pin(right_channel); diff --git a/ports/atmel-samd/common-hal/os/__init__.c b/ports/atmel-samd/common-hal/os/__init__.c index 89b5e85135d87..2c1de431c6635 100644 --- a/ports/atmel-samd/common-hal/os/__init__.c +++ b/ports/atmel-samd/common-hal/os/__init__.c @@ -16,6 +16,38 @@ #include "hal/include/hal_rand_sync.h" #endif +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +#ifdef SAMD21 +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "samd21"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "samd21"); +#endif +#ifdef SAM_D5X_E5X +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "samd51"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "samd51"); +#endif +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #ifdef SAM_D5X_E5X hri_mclk_set_APBCMASK_TRNG_bit(MCLK); diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index eca28dbd9be00..f02f3d595d9b4 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -68,7 +68,8 @@ #define MICROPY_PY_SYS_PLATFORM "MicroChip SAME54" #endif #define SPI_FLASH_MAX_BAUDRATE 24000000 - +#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) +#define MICROPY_PY_FUNCTION_ATTRS (1) // MICROPY_PY_ERRNO_LIST - Use the default #endif // SAM_D5X_E5X diff --git a/ports/broadcom/common-hal/os/__init__.c b/ports/broadcom/common-hal/os/__init__.c index c1c50234451ef..72a9a07e9077e 100644 --- a/ports/broadcom/common-hal/os/__init__.c +++ b/ports/broadcom/common-hal/os/__init__.c @@ -10,6 +10,33 @@ #include "py/objtuple.h" #include "py/qstr.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; + +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { return false; } diff --git a/ports/broadcom/mpconfigport.h b/ports/broadcom/mpconfigport.h index 8b749ca03100a..648259720f800 100644 --- a/ports/broadcom/mpconfigport.h +++ b/ports/broadcom/mpconfigport.h @@ -13,7 +13,9 @@ #define CIRCUITPY_MCU_FAMILY broadcom #define MICROPY_PY_SYS_PLATFORM "BROADCOM" - +#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) #if BCM_VERSION == 2837 || BCM_VERSION == 2711 #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A) #elif BCM_VERSION == 2835 diff --git a/ports/cxd56/boards/spresense/mpconfigboard.h b/ports/cxd56/boards/spresense/mpconfigboard.h index c9510771b1855..2d334ef29b301 100644 --- a/ports/cxd56/boards/spresense/mpconfigboard.h +++ b/ports/cxd56/boards/spresense/mpconfigboard.h @@ -18,3 +18,5 @@ #define DEFAULT_UART_BUS_RX (&pin_UART2_RXD) #define DEFAULT_UART_BUS_TX (&pin_UART2_TXD) + +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) diff --git a/ports/cxd56/common-hal/os/__init__.c b/ports/cxd56/common-hal/os/__init__.c index e1024108b07dc..7d211b3a79d06 100644 --- a/ports/cxd56/common-hal/os/__init__.c +++ b/ports/cxd56/common-hal/os/__init__.c @@ -10,6 +10,32 @@ #include "py/objstr.h" #include "py/objtuple.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; + +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "spresense"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "spresense"); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { uint32_t i = 0; diff --git a/ports/cxd56/mpconfigport.h b/ports/cxd56/mpconfigport.h index 3bcb252868786..b779b521ddaf9 100644 --- a/ports/cxd56/mpconfigport.h +++ b/ports/cxd56/mpconfigport.h @@ -8,6 +8,9 @@ #define MICROPY_PY_SYS_PLATFORM "CXD56" +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + // 64kiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE (0x10000) diff --git a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk index 383961a832798..633cca09823dc 100644 --- a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk +++ b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk @@ -26,3 +26,4 @@ CIRCUITPY_DISPLAYIO = 1 FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Shapes FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_RFM9x diff --git a/ports/espressif/boards/waveshare_esp32_s3_geek/board.c b/ports/espressif/boards/waveshare_esp32_s3_geek/board.c index 414188fb46a52..71f742b51f423 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_geek/board.c +++ b/ports/espressif/boards/waveshare_esp32_s3_geek/board.c @@ -30,9 +30,18 @@ uint8_t display_init_sequence[] = { }; static void display_init(void) { + busio_spi_obj_t *spi = common_hal_board_create_spi(0); fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + common_hal_busio_spi_construct( + spi, + &pin_GPIO12, // CLK + &pin_GPIO11, // MOSI + NULL, // MISO not connected + false); // Not half-duplex + + bus->base.type = &fourwire_fourwire_type; common_hal_fourwire_fourwire_construct( diff --git a/ports/espressif/boards/waveshare_esp32_s3_geek/mpconfigboard.h b/ports/espressif/boards/waveshare_esp32_s3_geek/mpconfigboard.h index 87ac391f5a0bf..2da021447e39f 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_geek/mpconfigboard.h +++ b/ports/espressif/boards/waveshare_esp32_s3_geek/mpconfigboard.h @@ -17,6 +17,6 @@ #define DEFAULT_I2C_BUS_SCL (&pin_GPIO17) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO16) -#define CIRCUITPY_BOARD_SPI (2) -#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO12, .mosi = &pin_GPIO11}, \ - {.clock = &pin_GPIO36, .mosi = &pin_GPIO35, .miso = &pin_GPIO37}} +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO37) diff --git a/ports/espressif/boards/waveshare_esp32_s3_geek/pins.c b/ports/espressif/boards/waveshare_esp32_s3_geek/pins.c index 65d391ec9ea88..01c3baf8c9f8f 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_geek/pins.c +++ b/ports/espressif/boards/waveshare_esp32_s3_geek/pins.c @@ -5,10 +5,8 @@ // SPDX-License-Identifier: MIT #include "shared-bindings/board/__init__.h" -#include "shared-module/displayio/__init__.h" - -CIRCUITPY_BOARD_BUS_SINGLETON(sd_spi, spi, 1) +#include "shared-module/displayio/__init__.h" static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS @@ -66,11 +64,11 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, // SD Card - { MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO36) }, - { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO35) }, - { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO37) }, - { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO34) }, - { MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_sd_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO36)}, + { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO35)}, + { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO37)}, + { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO34)}, + { MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_spi_obj) }, // Pin 38 is for the SDIO interface, and therefore not included in the SPI object // LCD @@ -80,7 +78,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO9) }, { MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) }, }; diff --git a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/board.c b/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/board.c deleted file mode 100644 index e7a6b86440ee5..0000000000000 --- a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/board.c +++ /dev/null @@ -1,78 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries -// -// SPDX-License-Identifier: MIT - -#include "supervisor/board.h" -#include "mpconfigboard.h" -#include "shared-bindings/busio/SPI.h" -#include "shared-bindings/fourwire/FourWire.h" -#include "shared-bindings/microcontroller/Pin.h" -#include "shared-module/displayio/__init__.h" -#include "shared-module/displayio/mipi_constants.h" -#include "shared-bindings/board/__init__.h" - -#define DELAY 0x80 - -// display init sequence according to LilyGO example app -uint8_t display_init_sequence[] = { - 0x01, DELAY, 0x96, // _SWRESET and Delay 150ms - 0x11, DELAY, 0xFF, // _SLPOUT and Delay 500ms - 0x3A, DELAY | 1, 0x55, 0x0A, // _COLMOD and Delay 10ms - 0x21, DELAY, 0x0A, // _INVON Hack and Delay 10ms - 0x13, DELAY, 0x0A, // _NORON and Delay 10ms - 0x36, 0x01, 0x60, // _MADCTL - 0x29, DELAY, 0xFF, // _DISPON and Delay 500ms -}; - -void board_init(void) { - busio_spi_obj_t *spi = common_hal_board_create_spi(0); - fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; - bus->base.type = &fourwire_fourwire_type; - - common_hal_fourwire_fourwire_construct( - bus, - spi, - &pin_GPIO42, // DC - &pin_GPIO45, // CS - &pin_GPIO0, // RST - // 24000000, - 40000000, // baudrate - 0, // polarity - 0 // phase - ); - busdisplay_busdisplay_obj_t *display = &allocate_display()->display; - display->base.type = &busdisplay_busdisplay_type; - - common_hal_busdisplay_busdisplay_construct( - display, - bus, - 320, // width (after rotation) - 240, // height (after rotation) - 0, // column start - 0, // row start - 0, // rotation - 16, // color depth - false, // grayscale - false, // pixels in a byte share a row. Only valid for depths < 8 - 1, // bytes per cell. Only valid for depths < 8 - false, // reverse_pixels_in_byte. Only valid for depths < 8 - true, // reverse_pixels_in_word - MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command - MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command - MIPI_COMMAND_WRITE_MEMORY_START, // write memory command - display_init_sequence, - sizeof(display_init_sequence), - &pin_GPIO1, // backlight pin - NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness - false, // single_byte_bounds - false, // data_as_commands - true, // auto_refresh - 60, // native_frames_per_second - true, // backlight_on_high - false, // SH1107_addressing - 50000 // backlight pwm frequency - ); -} diff --git a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.h b/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.h deleted file mode 100644 index b4009fdfd7f6b..0000000000000 --- a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.h +++ /dev/null @@ -1,19 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2025 Neradoc -// -// SPDX-License-Identifier: MIT - -#pragma once - -#define MICROPY_HW_BOARD_NAME "Waveshare ESP32S3 Touch LCD 2" -#define MICROPY_HW_MCU_NAME "ESP32S3" - -#define CIRCUITPY_BOARD_I2C (1) -#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO47, .sda = &pin_GPIO48}} - -#define CIRCUITPY_BOARD_SPI (1) -#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO39, .mosi = &pin_GPIO38, .miso = &pin_GPIO40}} - -#define DEFAULT_UART_BUS_RX (&pin_GPIO44) -#define DEFAULT_UART_BUS_TX (&pin_GPIO43) diff --git a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.mk b/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.mk deleted file mode 100644 index a6c719bf50feb..0000000000000 --- a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/mpconfigboard.mk +++ /dev/null @@ -1,14 +0,0 @@ -USB_VID = 0x303A -USB_PID = 0x82CE -USB_MANUFACTURER = "Waveshare Electronics" -USB_PRODUCT = "ESP32S3 Touch LCD 2" - -IDF_TARGET = esp32s3 - -CIRCUITPY_ESP_FLASH_MODE = qio -CIRCUITPY_ESP_FLASH_FREQ = 80m -CIRCUITPY_ESP_FLASH_SIZE = 16MB - -CIRCUITPY_ESP_PSRAM_SIZE = 8MB -CIRCUITPY_ESP_PSRAM_MODE = opi -CIRCUITPY_ESP_PSRAM_FREQ = 80m diff --git a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/pins.c b/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/pins.c deleted file mode 100644 index 015a7a33952f0..0000000000000 --- a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/pins.c +++ /dev/null @@ -1,94 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries -// -// SPDX-License-Identifier: MIT - -#include "shared-bindings/board/__init__.h" -#include "shared-module/displayio/__init__.h" - -static const mp_rom_map_elem_t board_module_globals_table[] = { - CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - - // User accessible GPIO - { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, - { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, - { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, - { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, - { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, - { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, - { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, - { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, - { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, - { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, - { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, - { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, - { MP_ROM_QSTR(MP_QSTR_IO47), MP_ROM_PTR(&pin_GPIO47) }, - { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, - { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, - { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, - { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, - { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, - - // User button - { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_BUTTON0), MP_ROM_PTR(&pin_GPIO0) }, - - // Battery ADC - {MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO5)}, - - // I2C - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO47) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO48) }, - - // CST816D Touch - { MP_ROM_QSTR(MP_QSTR_TOUCH_INT), MP_ROM_PTR(&pin_GPIO46) }, - - // QMI8658 IMU - { MP_ROM_QSTR(MP_QSTR_IMU_INT), MP_ROM_PTR(&pin_GPIO3) }, - - // SPI - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO39) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO38) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO40) }, - - // LCD - { MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO42) }, - { MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO45) }, - { MP_ROM_QSTR(MP_QSTR_LCD_RESET), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO1) }, - - // SD Card slot - { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO41) }, - - // Camera connector - { MP_ROM_QSTR(MP_QSTR_CAM_HREF), MP_ROM_PTR(&pin_GPIO4) }, - { MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_GPIO6) }, - { MP_ROM_QSTR(MP_QSTR_CAM_XCLK), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_CAM_PCLK), MP_ROM_PTR(&pin_GPIO9) }, - { MP_ROM_QSTR(MP_QSTR_CAM_PWDN), MP_ROM_PTR(&pin_GPIO17) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D0), MP_ROM_PTR(&pin_GPIO12) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D1), MP_ROM_PTR(&pin_GPIO13) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D2), MP_ROM_PTR(&pin_GPIO15) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D3), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D4), MP_ROM_PTR(&pin_GPIO14) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D5), MP_ROM_PTR(&pin_GPIO10) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D6), MP_ROM_PTR(&pin_GPIO7) }, - { MP_ROM_QSTR(MP_QSTR_CAM_D7), MP_ROM_PTR(&pin_GPIO2) }, - { MP_ROM_QSTR(MP_QSTR_TWI_CLK), MP_ROM_PTR(&pin_GPIO16) }, - { MP_ROM_QSTR(MP_QSTR_TWI_SDA), MP_ROM_PTR(&pin_GPIO21) }, - - // UART - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, - - // Objects - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, - { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}, -}; -MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_touch_lcd_2/sdkconfig deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/ports/espressif/common-hal/audioio/AudioOut.c b/ports/espressif/common-hal/audioio/AudioOut.c index 6d829228e1555..8322bc3799850 100644 --- a/ports/espressif/common-hal/audioio/AudioOut.c +++ b/ports/espressif/common-hal/audioio/AudioOut.c @@ -11,6 +11,7 @@ #include "driver/dac_continuous.h" + #if defined(CONFIG_IDF_TARGET_ESP32) #define pin_CHANNEL_0 pin_GPIO25 #define pin_CHANNEL_1 pin_GPIO26 @@ -303,32 +304,6 @@ static audioout_sample_convert_func_t audioout_get_samples_convert_func( } } -static void audioio_audioout_start(audioio_audioout_obj_t *self) { - esp_err_t ret; - - self->playing = true; - self->paused = false; - - ret = dac_continuous_start_async_writing(self->handle); - if (ret != ESP_OK) { - mp_raise_RuntimeError(MP_ERROR_TEXT("Failed to start async audio")); - } -} - -static void audioio_audioout_stop(audioio_audioout_obj_t *self, bool full_stop) { - dac_continuous_stop_async_writing(self->handle); - if (full_stop) { - self->get_buffer_index = 0; - self->put_buffer_index = 0; - self->sample_buffer = NULL; - self->sample = NULL; - self->playing = false; - self->paused = false; - } else { - self->paused = true; - } -} - static bool audioout_fill_buffer(audioio_audioout_obj_t *self) { if (!self->playing) { return false; @@ -367,7 +342,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) { &raw_sample_buf, &raw_sample_buf_size); if (get_buffer_result == GET_BUFFER_ERROR) { - audioio_audioout_stop(self, true); + common_hal_audioio_audioout_stop(self); return false; } @@ -415,7 +390,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) { } else { // TODO: figure out if it is ok to call this here or do we need // to somehow wait for all of the samples to be flushed - audioio_audioout_stop(self, true); + common_hal_audioio_audioout_stop(self); return false; } } @@ -517,8 +492,11 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, self->paused = false; self->freq_hz = DEFAULT_SAMPLE_RATE; - // The case of left_channel == right_channel is already disallowed in shared-bindings. - + /* espressif has two dac channels and it can support true stereo or + * outputting the same signal to both channels (dual mono). + * if different pins are supplied for left and right then use true stereo. + * if the same pin is supplied for left and right then use dual mono. + */ if ((left_channel_pin == &pin_CHANNEL_0 && right_channel_pin == &pin_CHANNEL_1) || (left_channel_pin == &pin_CHANNEL_1 && @@ -526,6 +504,12 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, self->channel_mask = DAC_CHANNEL_MASK_ALL; self->num_channels = 2; self->channel_mode = DAC_CHANNEL_MODE_ALTER; + } else if ((left_channel_pin == &pin_CHANNEL_0 || + left_channel_pin == &pin_CHANNEL_1) && + right_channel_pin == left_channel_pin) { + self->channel_mask = DAC_CHANNEL_MASK_ALL; + self->num_channels = 1; + self->channel_mode = DAC_CHANNEL_MODE_SIMUL; } else if (left_channel_pin == &pin_CHANNEL_0 && right_channel_pin == NULL) { self->channel_mask = DAC_CHANNEL_MASK_CH0; @@ -566,6 +550,32 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t *self) { _active_handle = NULL; } +static void audioio_audioout_start(audioio_audioout_obj_t *self) { + esp_err_t ret; + + self->playing = true; + self->paused = false; + + ret = dac_continuous_start_async_writing(self->handle); + if (ret != ESP_OK) { + mp_raise_RuntimeError(MP_ERROR_TEXT("Failed to start async audio")); + } +} + +static void audioio_audioout_stop(audioio_audioout_obj_t *self, bool full_stop) { + dac_continuous_stop_async_writing(self->handle); + if (full_stop) { + self->get_buffer_index = 0; + self->put_buffer_index = 0; + self->sample_buffer = NULL; + self->sample = NULL; + self->playing = false; + self->paused = false; + } else { + self->paused = true; + } +} + void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self, mp_obj_t sample, bool loop) { @@ -587,11 +597,7 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self, self->looping = loop; freq_hz = audiosample_get_sample_rate(self->sample); - // Workaround: always reset the DAC completely between plays, - // due to a bug that causes the left and right channels to be swapped randomly. - // See https://github.com/espressif/esp-idf/issues/11425 - // TODO: Remove the `true` when this issue is fixed. - if (true || freq_hz != self->freq_hz) { + if (freq_hz != self->freq_hz) { common_hal_audioio_audioout_deinit(self); self->freq_hz = freq_hz; audioout_init(self); diff --git a/ports/espressif/common-hal/os/__init__.c b/ports/espressif/common-hal/os/__init__.c index fff89c8476d8d..4063090fe1f96 100644 --- a/ports/espressif/common-hal/os/__init__.c +++ b/ports/espressif/common-hal/os/__init__.c @@ -15,6 +15,32 @@ #include "esp_system.h" #include "esp_random.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { uint32_t i = 0; while (i < length) { diff --git a/ports/espressif/common-hal/pulseio/PulseIn.c b/ports/espressif/common-hal/pulseio/PulseIn.c index 79d003a8a1e87..cf24b42a052f1 100644 --- a/ports/espressif/common-hal/pulseio/PulseIn.c +++ b/ports/espressif/common-hal/pulseio/PulseIn.c @@ -127,9 +127,6 @@ bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) { } void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) { - if (common_hal_pulseio_pulsein_deinited(self)) { - return; - } rmt_disable(self->channel); reset_pin_number(self->pin->number); rmt_del_channel(self->channel); diff --git a/ports/espressif/common-hal/pulseio/PulseOut.c b/ports/espressif/common-hal/pulseio/PulseOut.c index 68cb64b5e60e1..b76c84385596c 100644 --- a/ports/espressif/common-hal/pulseio/PulseOut.c +++ b/ports/espressif/common-hal/pulseio/PulseOut.c @@ -54,9 +54,6 @@ bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) { } void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t *self) { - if (common_hal_pulseio_pulseout_deinited(self)) { - return; - } rmt_disable(self->channel); rmt_del_encoder(self->encoder); rmt_del_channel(self->channel); diff --git a/ports/espressif/mpconfigport.h b/ports/espressif/mpconfigport.h index 98c1986240b73..443a59b0474bd 100644 --- a/ports/espressif/mpconfigport.h +++ b/ports/espressif/mpconfigport.h @@ -17,6 +17,9 @@ #define CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY (1) +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + #include "py/circuitpy_mpconfig.h" #define MICROPY_NLR_SETJMP (1) diff --git a/ports/litex/common-hal/os/__init__.c b/ports/litex/common-hal/os/__init__.c index 659411187fafb..e6da1904da522 100644 --- a/ports/litex/common-hal/os/__init__.c +++ b/ports/litex/common-hal/os/__init__.c @@ -12,6 +12,32 @@ #include "shared-bindings/os/__init__.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "litex"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "litex"); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { return false; } diff --git a/ports/litex/mpconfigport.h b/ports/litex/mpconfigport.h index 7ac34a44336cf..50986d16026c2 100644 --- a/ports/litex/mpconfigport.h +++ b/ports/litex/mpconfigport.h @@ -9,6 +9,8 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE (0) #define MICROPY_NLR_THUMB (0) +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) #include "py/circuitpy_mpconfig.h" diff --git a/ports/mimxrt10xx/common-hal/os/__init__.c b/ports/mimxrt10xx/common-hal/os/__init__.c index ac168f2ed09b3..79ae228dc4240 100644 --- a/ports/mimxrt10xx/common-hal/os/__init__.c +++ b/ports/mimxrt10xx/common-hal/os/__init__.c @@ -17,6 +17,31 @@ #include "sdk/drivers/trng/fsl_trng.h" #endif +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "mimxrt10xx"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "mimxrt10xx"); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #if CIRCUITPY_RANDOM trng_config_t trngConfig; diff --git a/ports/mimxrt10xx/mpconfigport.h b/ports/mimxrt10xx/mpconfigport.h index 4d5e4e59700bd..4f9acd7a9fd30 100644 --- a/ports/mimxrt10xx/mpconfigport.h +++ b/ports/mimxrt10xx/mpconfigport.h @@ -17,6 +17,10 @@ extern uint8_t _ld_filesystem_end; extern uint8_t _ld_default_stack_size; #define CIRCUITPY_DEFAULT_STACK_SIZE ((uint32_t)&_ld_default_stack_size) +#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0) +#define MICROPY_PY_FUNCTION_ATTRS (0) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR ((uint32_t)&_ld_filesystem_start) #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE ((uint32_t)(&_ld_filesystem_end - &_ld_filesystem_start)) diff --git a/ports/nordic/common-hal/os/__init__.c b/ports/nordic/common-hal/os/__init__.c index 54b8ad026a7de..78aa1e040cf8e 100644 --- a/ports/nordic/common-hal/os/__init__.c +++ b/ports/nordic/common-hal/os/__init__.c @@ -17,6 +17,32 @@ #include "nrf_rng.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "nrf52"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "nrf52"); + +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #ifdef BLUETOOTH_SD uint8_t sd_en = 0; diff --git a/ports/nordic/mpconfigport.h b/ports/nordic/mpconfigport.h index 33fcfa371e0bd..ed6c2827000ca 100644 --- a/ports/nordic/mpconfigport.h +++ b/ports/nordic/mpconfigport.h @@ -13,6 +13,8 @@ #include "nrf_sdm.h" // for SD_FLASH_SIZE #include "peripherals/nrf/nvm.h" // for FLASH_PAGE_SIZE +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) #define MICROPY_PY_SYS_STDIO_BUFFER (1) // 24kiB stack diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 9b582fce83ced..cb58e90352440 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -12,7 +12,6 @@ HAL_DIR=hal/$(MCU_SERIES) ifeq ($(CIRCUITPY_CYW43),1) INC_CYW43 := \ - -isystem lib/cyw43-driver \ -isystem lib/cyw43-driver/firmware \ -isystem lib/cyw43-driver/src \ -isystem lib/lwip/src/include \ @@ -93,6 +92,8 @@ INC += \ -I../shared/timeutils \ -Iboards/$(BOARD) \ -Iboards/ \ + -isystem ./../../lib/cmsis/inc \ + -isystem sdk/ \ -isystem sdk/src/common/boot_picobin_headers/include/ \ -isystem sdk/src/common/boot_picoboot_headers/include/ \ -isystem sdk/src/common/hardware_claim/include/ \ @@ -106,8 +107,6 @@ INC += \ -isystem sdk/src/$(CHIP_VARIANT_LOWER)/hardware_structs/include/ \ -isystem sdk/src/$(CHIP_VARIANT_LOWER)/pico_platform/include/ \ -isystem sdk/src/rp2_common/boot_bootrom_headers/include/ \ - -isystem sdk/src/rp2_common/cmsis/stub/CMSIS/Core/Include/ \ - -isystem sdk/src/rp2_common/cmsis/stub/CMSIS/Device/${CHIP_VARIANT}/Include \ -isystem sdk/src/rp2_common/cmsis/ \ -isystem sdk/src/rp2_common/hardware_adc/include/ \ -isystem sdk/src/rp2_common/hardware_base/include/ \ @@ -154,7 +153,7 @@ INC += \ -isystem sdk/src/rp2_common/pico_platform_panic/include/ \ -isystem sdk/src/rp2_common/pico_time_adapter/include/ \ -isystem sdk/src/rp2_common/pico_unique_id/include/ \ - $(INC_CYW43) \ +$(INC_CYW43) \ -Isdk_config \ -I../../lib/tinyusb/src \ -I../../supervisor/shared/usb \ @@ -223,7 +222,7 @@ endif DISABLE_WARNINGS = -Wno-cast-align -CFLAGS += $(INC) -Wtype-limits -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes +CFLAGS += $(INC) -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes PICO_LDFLAGS = --specs=nosys.specs --specs=nano.specs diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index c17ec102297b8..e3aafbeef0543 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -15,7 +15,7 @@ #include "py/mpstate.h" #include "py/runtime.h" -#include "hardware/irq.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" #include "hardware/regs/intctrl.h" // For isr_ macro. diff --git a/ports/raspberrypi/audio_dma.h b/ports/raspberrypi/audio_dma.h index 48cc024fda98d..b48456f5a83aa 100644 --- a/ports/raspberrypi/audio_dma.h +++ b/ports/raspberrypi/audio_dma.h @@ -9,7 +9,7 @@ #include "py/obj.h" #include "supervisor/background_callback.h" -#include "hardware/dma.h" +#include "src/rp2_common/hardware_dma/include/hardware/dma.h" typedef enum { AUDIO_DMA_OK, diff --git a/ports/raspberrypi/bindings/cyw43/__init__.c b/ports/raspberrypi/bindings/cyw43/__init__.c index 36ac3ff7b6206..c14f15212f5d0 100644 --- a/ports/raspberrypi/bindings/cyw43/__init__.c +++ b/ports/raspberrypi/bindings/cyw43/__init__.c @@ -12,7 +12,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "bindings/cyw43/__init__.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "lib/cyw43-driver/src/cyw43.h" diff --git a/ports/raspberrypi/boards/adafruit_fruit_jam/pins.c b/ports/raspberrypi/boards/adafruit_fruit_jam/pins.c index 54a8869366e0d..1b0c6291d8912 100644 --- a/ports/raspberrypi/boards/adafruit_fruit_jam/pins.c +++ b/ports/raspberrypi/boards/adafruit_fruit_jam/pins.c @@ -13,7 +13,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { // On JST PH connector. { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO40) }, - // On header { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO41) }, { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO42) }, { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO43) }, @@ -28,11 +27,11 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO29) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_GPIO0) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) }, { MP_OBJ_NEW_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON2), MP_ROM_PTR(&pin_GPIO4) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON3), MP_ROM_PTR(&pin_GPIO5) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_GPIO4) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON2), MP_ROM_PTR(&pin_GPIO5) }, { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO20) }, { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO21) }, diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index 673d9303d6b55..60f3fc7317a85 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -10,7 +10,7 @@ #include "shared-module/displayio/mipi_constants.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/board.h" #include "supervisor/shared/board.h" diff --git a/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c b/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c index ae948d089b51b..5a44f1167f0d9 100644 --- a/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c +++ b/ports/raspberrypi/boards/adafruit_qt2040_trinkey/board.c @@ -7,6 +7,6 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/boardsource_blok/board.c b/ports/raspberrypi/boards/boardsource_blok/board.c index 5d714c242b5ee..0c7574ea8a89d 100644 --- a/ports/raspberrypi/boards/boardsource_blok/board.c +++ b/ports/raspberrypi/boards/boardsource_blok/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" void board_init(void) { diff --git a/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c b/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c index a20b16473174c..60efe1e282259 100644 --- a/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c +++ b/ports/raspberrypi/boards/bradanlanestudio_explorer_rp2040/board.c @@ -26,9 +26,9 @@ #include "shared-module/displayio/__init__.h" #include "supervisor/shared/board.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" -#include "hardware/adc.h" +#include "src/rp2_common/hardware_adc/include/hardware/adc.h" #define ADC_FIRST_PIN_NUMBER 26 #define ADC_PIN_COUNT 4 extern void common_hal_mcu_delay_us(uint32_t); diff --git a/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c b/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c index d3c80c5cb87d9..559800e34d962 100644 --- a/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_encoderpad_rp2040/board.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" #include "supervisor/board.h" diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c index 2bb2d06dcad4f..c123fd785c944 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey18/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c index 743e9b14b52a2..f0a3953335557 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey44/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c index ab07a4aaaed27..360f18e382ed0 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey60/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c b/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c index b9fa212c96d91..751726a065da3 100644 --- a/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c +++ b/ports/raspberrypi/boards/jpconstantineau_pykey87/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/ugame22/board.c b/ports/raspberrypi/boards/ugame22/board.c index 6b8152b14eedf..a208326a09439 100644 --- a/ports/raspberrypi/boards/ugame22/board.c +++ b/ports/raspberrypi/boards/ugame22/board.c @@ -7,7 +7,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/fourwire/FourWire.h" diff --git a/ports/raspberrypi/boards/wk-50/board.c b/ports/raspberrypi/boards/wk-50/board.c index 2ea197d2b2e5b..9ebde0a6f3363 100644 --- a/ports/raspberrypi/boards/wk-50/board.c +++ b/ports/raspberrypi/boards/wk-50/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c b/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c index f8e9958433b08..415a7b3b3e8ff 100644 --- a/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c +++ b/ports/raspberrypi/boards/zrichard_rp2.65-f/board.c @@ -6,7 +6,7 @@ #include "supervisor/board.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "supervisor/shared/board.h" void reset_board(void) { diff --git a/ports/raspberrypi/boot_stage2/RP2040.c.jinja b/ports/raspberrypi/boot_stage2/RP2040.c.jinja index c00b35fa662c6..4c001525dcc2f 100644 --- a/ports/raspberrypi/boot_stage2/RP2040.c.jinja +++ b/ports/raspberrypi/boot_stage2/RP2040.c.jinja @@ -1,7 +1,7 @@ -#include "hardware/structs/ssi.h" -#include "hardware/structs/pads_qspi.h" -#include "hardware/regs/addressmap.h" -#include "hardware/regs/m0plus.h" +#include "sdk/src/rp2040/hardware_structs/include/hardware/structs/ssi.h" +#include "sdk/src/rp2040/hardware_structs/include/hardware/structs/pads_qspi.h" +#include "sdk/src/rp2040/hardware_regs/include/hardware/regs/addressmap.h" +#include "sdk/src/rp2040/hardware_regs/include/hardware/regs/m0plus.h" // "Mode bits" are 8 special bits sent immediately after // the address bits in a "Read Data Fast Quad I/O" command sequence. diff --git a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c index 6862f2799f28f..7385b21ea95e3 100644 --- a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c +++ b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.c @@ -11,9 +11,9 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared/runtime/interrupt_char.h" #include "py/runtime.h" -#include "hardware/adc.h" -#include "hardware/dma.h" -#include "pico/stdlib.h" +#include "src/rp2_common/hardware_adc/include/hardware/adc.h" +#include "src/rp2_common/hardware_dma/include/hardware/dma.h" +#include "src/common/pico_stdlib_headers/include/pico/stdlib.h" #define ADC_FIRST_PIN_NUMBER 26 #define ADC_PIN_COUNT 4 diff --git a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h index 587668c1a7bf6..f0c536f392159 100644 --- a/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h +++ b/ports/raspberrypi/common-hal/analogbufio/BufferedIn.h @@ -8,7 +8,7 @@ #pragma once #include "common-hal/microcontroller/Pin.h" -#include "hardware/dma.h" +#include "src/rp2_common/hardware_dma/include/hardware/dma.h" #include "py/obj.h" diff --git a/ports/raspberrypi/common-hal/analogio/AnalogIn.c b/ports/raspberrypi/common-hal/analogio/AnalogIn.c index 9d107c8d14b91..301b965c86c15 100644 --- a/ports/raspberrypi/common-hal/analogio/AnalogIn.c +++ b/ports/raspberrypi/common-hal/analogio/AnalogIn.c @@ -10,7 +10,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "py/runtime.h" -#include "hardware/adc.h" +#include "src/rp2_common/hardware_adc/include/hardware/adc.h" #define ADC_PIN_COUNT (NUM_ADC_CHANNELS - 1) diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index 6fa5bf02c1486..0494e937f4b42 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -20,8 +20,8 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" -#include "hardware/structs/dma.h" -#include "hardware/pwm.h" +#include "src/rp2040/hardware_structs/include/hardware/structs/dma.h" +#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" // The PWM clock frequency is base_clock_rate / PWM_TOP, typically 125_000_000 / PWM_TOP. // We pick BITS_PER_SAMPLE so we get a clock frequency that is above what would cause aliasing. diff --git a/ports/raspberrypi/common-hal/busio/I2C.c b/ports/raspberrypi/common-hal/busio/I2C.c index 0f7e023f0e9c5..3b7cf8662d90e 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.c +++ b/ports/raspberrypi/common-hal/busio/I2C.c @@ -13,7 +13,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/bitbangio/I2C.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" // Synopsys DW_apb_i2c (v2.01) IP diff --git a/ports/raspberrypi/common-hal/busio/I2C.h b/ports/raspberrypi/common-hal/busio/I2C.h index 7a6fd1b9d1f37..b02c1c54a31c4 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.h +++ b/ports/raspberrypi/common-hal/busio/I2C.h @@ -11,7 +11,7 @@ #include "py/obj.h" -#include "hardware/i2c.h" +#include "src/rp2_common/hardware_i2c/include/hardware/i2c.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/busio/SPI.c b/ports/raspberrypi/common-hal/busio/SPI.c index d20bc4d7d10aa..7a033250f9142 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.c +++ b/ports/raspberrypi/common-hal/busio/SPI.c @@ -14,8 +14,8 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/dma.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_dma/include/hardware/dma.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #define NO_INSTANCE 0xff diff --git a/ports/raspberrypi/common-hal/busio/SPI.h b/ports/raspberrypi/common-hal/busio/SPI.h index 8510eb7693ae2..27d4cf6f3c72b 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.h +++ b/ports/raspberrypi/common-hal/busio/SPI.h @@ -10,7 +10,7 @@ #include "py/obj.h" -#include "hardware/spi.h" +#include "src/rp2_common/hardware_spi/include/hardware/spi.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/busio/UART.c b/ports/raspberrypi/common-hal/busio/UART.c index 17fcfa172293d..aeb0ff4bea289 100644 --- a/ports/raspberrypi/common-hal/busio/UART.c +++ b/ports/raspberrypi/common-hal/busio/UART.c @@ -14,8 +14,8 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/irq.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #define NO_PIN 0xff diff --git a/ports/raspberrypi/common-hal/busio/UART.h b/ports/raspberrypi/common-hal/busio/UART.h index 3709907633cb0..ca75235ddf879 100644 --- a/ports/raspberrypi/common-hal/busio/UART.h +++ b/ports/raspberrypi/common-hal/busio/UART.h @@ -9,7 +9,7 @@ #include "py/obj.h" #include "py/ringbuf.h" -#include "hardware/uart.h" +#include "src/rp2_common/hardware_uart/include/hardware/uart.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/countio/Counter.c b/ports/raspberrypi/common-hal/countio/Counter.c index ba82ca8e7ab9d..1a270bf882070 100644 --- a/ports/raspberrypi/common-hal/countio/Counter.c +++ b/ports/raspberrypi/common-hal/countio/Counter.c @@ -13,9 +13,9 @@ #include "shared-bindings/digitalio/Pull.h" #include "common-hal/pwmio/PWMOut.h" -#include "hardware/gpio.h" -#include "hardware/pwm.h" -#include "hardware/irq.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" void common_hal_countio_counter_construct(countio_counter_obj_t *self, diff --git a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c index f20facdad7dfc..60849eb120af8 100644 --- a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c +++ b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c @@ -14,7 +14,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #if CIRCUITPY_CYW43 #include "pico/cyw43_arch.h" diff --git a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c index d1c92eea9988f..4f226fe56e957 100644 --- a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c +++ b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c @@ -14,7 +14,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "py/runtime.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" static i2c_inst_t *i2c[2] = {i2c0, i2c1}; diff --git a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h index 5d4e0690cbffd..0b6c2875e3f40 100644 --- a/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h +++ b/ports/raspberrypi/common-hal/i2ctarget/I2CTarget.h @@ -8,7 +8,7 @@ #include "py/obj.h" #include "common-hal/microcontroller/Pin.h" -#include "hardware/i2c.h" +#include "src/rp2_common/hardware_i2c/include/hardware/i2c.h" typedef struct { mp_obj_base_t base; diff --git a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c index d0a7a1d7b08a1..7be1d5581fcbd 100644 --- a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c @@ -18,8 +18,8 @@ #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/microcontroller/__init__.h" -#include "hardware/pio.h" -#include "hardware/pio_instructions.h" +#include "src/rp2_common/hardware_pio/include/hardware/pio.h" +#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h" // Define this to (1), and you can scope the instruction-pointer of the state machine on D26..28 (note the weird encoding though!) #define DEBUG_STATE_MACHINE (0) diff --git a/ports/raspberrypi/common-hal/max3421e/Max3421E.c b/ports/raspberrypi/common-hal/max3421e/Max3421E.c index 0077b460ed0a0..20ce701b9f3cc 100644 --- a/ports/raspberrypi/common-hal/max3421e/Max3421E.c +++ b/ports/raspberrypi/common-hal/max3421e/Max3421E.c @@ -10,7 +10,7 @@ #include "shared-bindings/busio/SPI.h" #include "supervisor/usb.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" static max3421e_max3421e_obj_t *active_max = NULL; diff --git a/ports/raspberrypi/common-hal/microcontroller/Pin.c b/ports/raspberrypi/common-hal/microcontroller/Pin.c index 3c5286d36c4e9..4ea7516d70915 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Pin.c +++ b/ports/raspberrypi/common-hal/microcontroller/Pin.c @@ -9,7 +9,7 @@ #include "common-hal/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" static uint64_t gpio_bank0_pin_claimed; diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index a3ea890d9aff3..139edc999d669 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -15,21 +15,26 @@ #include "shared-bindings/time/__init__.h" #include "pico/stdlib.h" -#include "hardware/adc.h" -#include "hardware/clocks.h" -#include "hardware/vreg.h" -#include "hardware/watchdog.h" +#include "src/rp2_common/hardware_adc/include/hardware/adc.h" +#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" +#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h" +#include "src/rp2_common/hardware_watchdog/include/hardware/watchdog.h" #ifdef PICO_RP2040 -#include "hardware/regs/vreg_and_chip_reset.h" -#include "hardware/structs/vreg_and_chip_reset.h" +#include "src/rp2040/hardware_regs/include/hardware/regs/vreg_and_chip_reset.h" #endif #ifdef PICO_RP2350 -#include "hardware/regs/powman.h" -#include "hardware/structs/powman.h" +#include "src/rp2350/hardware_regs/include/hardware/regs/powman.h" #endif -#include "hardware/regs/watchdog.h" -#include "hardware/structs/watchdog.h" +#include "src/rp2040/hardware_regs/include/hardware/regs/watchdog.h" + +#ifdef PICO_RP2040 +#include "src/rp2040/hardware_structs/include/hardware/structs/vreg_and_chip_reset.h" +#endif +#ifdef PICO_RP2350 +#include "src/rp2350/hardware_structs/include/hardware/structs/powman.h" +#endif +#include "src/rp2040/hardware_structs/include/hardware/structs/watchdog.h" float common_hal_mcu_processor_get_temperature(void) { adc_init(); diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.h b/ports/raspberrypi/common-hal/microcontroller/Processor.h index df1e1cf2333b9..31f89f58fd308 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.h +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.h @@ -6,7 +6,7 @@ #pragma once -#include "pico/unique_id.h" +#include "src/rp2_common/pico_unique_id/include/pico/unique_id.h" #define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH PICO_UNIQUE_BOARD_ID_SIZE_BYTES diff --git a/ports/raspberrypi/common-hal/microcontroller/__init__.c b/ports/raspberrypi/common-hal/microcontroller/__init__.c index e287e551710b6..1d29b4a29f09d 100644 --- a/ports/raspberrypi/common-hal/microcontroller/__init__.c +++ b/ports/raspberrypi/common-hal/microcontroller/__init__.c @@ -19,8 +19,8 @@ #include "supervisor/port.h" #include "supervisor/shared/safe_mode.h" -#include "hardware/structs/sio.h" -#include "hardware/sync.h" +#include "src/rp2040/hardware_structs/include/hardware/structs/sio.h" +#include "src/rp2_common/hardware_sync/include/hardware/sync.h" #include "hardware/watchdog.h" #include "hardware/irq.h" @@ -51,7 +51,7 @@ void common_hal_mcu_enable_interrupts(void) { asm volatile ("cpsie i" : : : "memory"); } #else -#include "RP2350.h" +#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h" #define PICO_ELEVATED_IRQ_PRIORITY (0x60) // between PICO_DEFAULT and PIOCO_HIGHEST_IRQ_PRIORITY static uint32_t oldBasePri = 0; // 0 (default) masks nothing, other values mask equal-or-larger priority values void common_hal_mcu_disable_interrupts(void) { diff --git a/ports/raspberrypi/common-hal/microcontroller/__init__.h b/ports/raspberrypi/common-hal/microcontroller/__init__.h index 8798c857404c5..e9a7602bc040c 100644 --- a/ports/raspberrypi/common-hal/microcontroller/__init__.h +++ b/ports/raspberrypi/common-hal/microcontroller/__init__.h @@ -6,7 +6,7 @@ #pragma once -#include "hardware/platform_defs.h" +#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h" #include "peripherals/pins.h" const mcu_pin_obj_t *mcu_get_pin_by_number(int); diff --git a/ports/raspberrypi/common-hal/nvm/ByteArray.c b/ports/raspberrypi/common-hal/nvm/ByteArray.c index 558f38240ce4f..c23ccfef4dad2 100644 --- a/ports/raspberrypi/common-hal/nvm/ByteArray.c +++ b/ports/raspberrypi/common-hal/nvm/ByteArray.c @@ -10,7 +10,7 @@ #include #include "py/runtime.h" -#include "hardware/flash.h" +#include "src/rp2_common/hardware_flash/include/hardware/flash.h" #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/internal_flash.h" diff --git a/ports/raspberrypi/common-hal/os/__init__.c b/ports/raspberrypi/common-hal/os/__init__.c index 616bb8d8c7929..d9ad1c238ff34 100644 --- a/ports/raspberrypi/common-hal/os/__init__.c +++ b/ports/raspberrypi/common-hal/os/__init__.c @@ -18,6 +18,32 @@ #include +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + // NIST Special Publication 800-90B (draft) recommends several extractors, // including the SHA hash family and states that if the amount of entropy input // is twice the number of bits output from them, that output can be considered diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c index 788f10d6df6ac..0bfb86b4c8a1f 100644 --- a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c @@ -13,13 +13,13 @@ #include "common-hal/rp2pio/StateMachine.h" #include "supervisor/port.h" -#include "pico/stdlib.h" -#include "hardware/structs/mpu.h" -#include "RP2040.h" // (cmsis) -#include "hardware/clocks.h" -#include "hardware/pwm.h" -#include "hardware/vreg.h" -#include "pico/multicore.h" +#include "src/common/pico_stdlib_headers/include/pico/stdlib.h" +#include "src/rp2040/hardware_structs/include/hardware/structs/mpu.h" +#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include/RP2040.h" +#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" +#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" +#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h" +#include "src/rp2_common/pico_multicore/include/pico/multicore.h" #include "lib/PicoDVI/software/libdvi/tmds_encode.h" diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c index 79ec315d497e4..c6fc593ce8644 100644 --- a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c @@ -31,14 +31,14 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/port.h" -#include "pico/stdlib.h" +#include "src/common/pico_stdlib_headers/include/pico/stdlib.h" // This is from: https://github.com/raspberrypi/pico-examples-rp2350/blob/a1/hstx/dvi_out_hstx_encoder/dvi_out_hstx_encoder.c -#include "hardware/dma.h" -#include "hardware/structs/bus_ctrl.h" -#include "hardware/structs/hstx_ctrl.h" -#include "hardware/structs/hstx_fifo.h" +#include "sdk/src/rp2_common/hardware_dma/include/hardware/dma.h" +#include "sdk/src/rp2350/hardware_structs/include/hardware/structs/bus_ctrl.h" +#include "sdk/src/rp2350/hardware_structs/include/hardware/structs/hstx_ctrl.h" +#include "sdk/src/rp2350/hardware_structs/include/hardware/structs/hstx_fifo.h" // ---------------------------------------------------------------------------- // DVI constants diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index b56c90a9a53bb..a1d281a247548 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: MIT -#include "hardware/gpio.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.h b/ports/raspberrypi/common-hal/pulseio/PulseIn.h index 369d7b8f450fe..cca1dedfabca9 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.h @@ -7,7 +7,7 @@ #pragma once #include "common-hal/microcontroller/Pin.h" -#include "hardware/pio.h" +#include "src/rp2_common/hardware_pio/include/hardware/pio.h" #include "common-hal/rp2pio/StateMachine.h" #include "py/obj.h" diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.c b/ports/raspberrypi/common-hal/pulseio/PulseOut.c index 84d02e20cce15..114bff13979f9 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.c @@ -14,9 +14,9 @@ #include "shared-bindings/microcontroller/__init__.h" #include "common-hal/pwmio/PWMOut.h" #include "hardware/structs/pwm.h" -#include "hardware/gpio.h" -#include "hardware/pwm.h" -#include "pico/time.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" +#include "src/common/pico_time/include/pico/time.h" volatile alarm_id_t cur_alarm = 0; diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.h b/ports/raspberrypi/common-hal/pulseio/PulseOut.h index cff82f2c28c72..fa264c36b7f68 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.h @@ -8,7 +8,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/pwmio/PWMOut.h" -#include "pico/time.h" +#include "src/common/pico_time/include/pico/time.h" #include "py/obj.h" diff --git a/ports/raspberrypi/common-hal/pwmio/PWMOut.c b/ports/raspberrypi/common-hal/pwmio/PWMOut.c index 9ceb5a0185d92..e0572eccd9e44 100644 --- a/ports/raspberrypi/common-hal/pwmio/PWMOut.c +++ b/ports/raspberrypi/common-hal/pwmio/PWMOut.c @@ -12,10 +12,10 @@ #include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/microcontroller/Processor.h" -#include "hardware/platform_defs.h" -#include "hardware/clocks.h" -#include "hardware/gpio.h" -#include "hardware/pwm.h" +#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h" +#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" uint32_t target_slice_frequencies[NUM_PWM_SLICES]; uint32_t slice_variable_frequency; diff --git a/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c index 875da3432510a..029e2b2755ea0 100644 --- a/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c +++ b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c @@ -12,8 +12,8 @@ #include "shared-bindings/pwmio/PWMOut.h" #include "shared-module/rgbmatrix/RGBMatrix.h" -#include "hardware/pwm.h" -#include "hardware/irq.h" +#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) { // Choose a PWM channel based on the first RGB pin diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 3e4579fe49ddb..950fd3cab8ef0 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -14,12 +14,12 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/memorymap/AddressRange.h" -#include "hardware/platform_defs.h" -#include "hardware/structs/iobank0.h" -#include "hardware/clocks.h" -#include "hardware/dma.h" -#include "hardware/pio_instructions.h" -#include "hardware/irq.h" +#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h" +#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" +#include "src/rp2_common/hardware_dma/include/hardware/dma.h" +#include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h" +#include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" #include "shared/runtime/interrupt_char.h" #include "py/obj.h" @@ -222,7 +222,7 @@ static bool is_gpio_compatible(PIO pio, uint32_t used_gpio_ranges) { #endif } -static bool use_existing_program(PIO *pio_out, int *sm_out, int *offset_inout, uint32_t program_id, size_t program_len, uint gpio_base, uint gpio_count) { +static bool use_existing_program(PIO *pio_out, uint *sm_out, int *offset_inout, uint32_t program_id, size_t program_len, uint gpio_base, uint gpio_count) { uint32_t required_gpio_ranges; if (gpio_count) { required_gpio_ranges = (1u << (gpio_base >> 4)) | @@ -307,12 +307,12 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, .origin = offset, }; PIO pio; - int state_machine; + uint state_machine; bool added = false; if (!use_existing_program(&pio, &state_machine, &offset, program_id, program_len, gpio_base, gpio_count)) { uint program_offset; - bool r = pio_claim_free_sm_and_add_program_for_gpio_range(&program_struct, &pio, (uint *)&state_machine, &program_offset, gpio_base, gpio_count, true); + bool r = pio_claim_free_sm_and_add_program_for_gpio_range(&program_struct, &pio, &state_machine, &program_offset, gpio_base, gpio_count, true); if (!r) { return false; } @@ -336,8 +336,6 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, } } - // Sanity check that state_machine number is valid. - assert(state_machine >= 0); self->pio = pio; self->state_machine = state_machine; self->offset = offset; @@ -741,8 +739,6 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, fifo_type, mov_status_type, mov_status_n); if (!ok) { - // indicate state machine never inited - self->state_machine = NUM_PIO_STATE_MACHINES; mp_raise_RuntimeError(MP_ERROR_TEXT("All state machines in use")); } } diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h index c7ef12e1b0177..e163491825424 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h @@ -10,7 +10,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/memorymap/AddressRange.h" -#include "hardware/pio.h" +#include "src/rp2_common/hardware_pio/include/hardware/pio.h" // pio_pinmask_t can hold ANY pin masks, so it is used before selection of gpiobase #if NUM_BANK0_GPIOS > 32 diff --git a/ports/raspberrypi/common-hal/rtc/RTC.c b/ports/raspberrypi/common-hal/rtc/RTC.c index 67935502ad322..3bdf599d2701f 100644 --- a/ports/raspberrypi/common-hal/rtc/RTC.c +++ b/ports/raspberrypi/common-hal/rtc/RTC.c @@ -11,8 +11,8 @@ #include "py/runtime.h" #include "shared/timeutils/timeutils.h" -#include "pico/util/datetime.h" -#include "pico/aon_timer.h" +#include "src/common/pico_util/include/pico/util/datetime.h" +#include "src/rp2_common/pico_aon_timer/include/pico/aon_timer.h" void common_hal_rtc_init(void) { // We start the RTC at 0 which mark as January 1, 2000. diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c index 086fc4a13f78f..fb1fdfb5f65bf 100644 --- a/ports/raspberrypi/common-hal/socketpool/Socket.c +++ b/ports/raspberrypi/common-hal/socketpool/Socket.c @@ -35,7 +35,7 @@ #include "lwip/timeouts.h" #include "lwip/udp.h" -#include "pico/cyw43_arch.h" +#include "sdk/src/rp2_common/pico_cyw43_arch/include/pico/cyw43_arch.h" mp_obj_t socketpool_ip_addr_to_str(const ip_addr_t *addr) { char ip_str[IPADDR_STRLEN_MAX]; // big enough for any supported address type diff --git a/ports/raspberrypi/common-hal/usb_host/Port.c b/ports/raspberrypi/common-hal/usb_host/Port.c index 5439b39bf3aa3..e350c288f71a5 100644 --- a/ports/raspberrypi/common-hal/usb_host/Port.c +++ b/ports/raspberrypi/common-hal/usb_host/Port.c @@ -11,16 +11,17 @@ #include "supervisor/shared/serial.h" #include "supervisor/usb.h" -#include "pico/time.h" -#include "hardware/structs/mpu.h" +#include "src/common/pico_time/include/pico/time.h" #ifdef PICO_RP2040 -#include "RP2040.h" // (cmsis) +#include "src/rp2040/hardware_structs/include/hardware/structs/mpu.h" +#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include/RP2040.h" #endif #ifdef PICO_RP2350 -#include "RP2350.h" // (cmsis) +#include "src/rp2350/hardware_structs/include/hardware/structs/mpu.h" +#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h" #endif -#include "hardware/dma.h" -#include "pico/multicore.h" +#include "src/rp2_common/hardware_dma/include/hardware/dma.h" +#include "src/rp2_common/pico_multicore/include/pico/multicore.h" #include "py/runtime.h" @@ -137,11 +138,10 @@ usb_host_port_obj_t *common_hal_usb_host_port_construct(const mcu_pin_obj_t *dp, } pio_cfg.pio_tx_num = get_usb_pio(); pio_cfg.pio_rx_num = pio_cfg.pio_tx_num; - int dma_ch = dma_claim_unused_channel(false); - if (dma_ch < 0) { + pio_cfg.tx_ch = dma_claim_unused_channel(false); // DMA channel + if (pio_cfg.tx_ch < 0) { mp_raise_RuntimeError(MP_ERROR_TEXT("All dma channels in use")); } - pio_cfg.tx_ch = dma_ch; self->base.type = &usb_host_port_type; self->dp = dp; diff --git a/ports/raspberrypi/cyw43_configport.h b/ports/raspberrypi/cyw43_configport.h index c1769436ae497..62666bee42c23 100644 --- a/ports/raspberrypi/cyw43_configport.h +++ b/ports/raspberrypi/cyw43_configport.h @@ -12,7 +12,7 @@ #include "supervisor/port.h" -#include_next "cyw43_configport.h" +#include "sdk/src/rp2_common/pico_cyw43_driver/include/cyw43_configport.h" #define CYW43_NETUTILS (1) diff --git a/ports/raspberrypi/lib/Pico-PIO-USB b/ports/raspberrypi/lib/Pico-PIO-USB index e0aba546813d8..1862cc008e026 160000 --- a/ports/raspberrypi/lib/Pico-PIO-USB +++ b/ports/raspberrypi/lib/Pico-PIO-USB @@ -1 +1 @@ -Subproject commit e0aba546813d89cb7f321bef3363bfba5f282e14 +Subproject commit 1862cc008e026cbd07b97b28e29eafb5f38b35fb diff --git a/ports/raspberrypi/lwip_inc/lwipopts.h b/ports/raspberrypi/lwip_inc/lwipopts.h index 21d415fad214e..e3ed4ad63dc11 100644 --- a/ports/raspberrypi/lwip_inc/lwipopts.h +++ b/ports/raspberrypi/lwip_inc/lwipopts.h @@ -111,7 +111,6 @@ #define LWIP_NETIF_EXT_STATUS_CALLBACK 1 #define MDNS_MAX_SECONDARY_HOSTNAMES 1 #define MEMP_NUM_SYS_TIMEOUT (8 + 3 * (LWIP_IPV4 + LWIP_IPV6)) -#define MDNS_MAX_SERVICES 25 #endif #ifndef NDEBUG diff --git a/ports/raspberrypi/mpconfigport.h b/ports/raspberrypi/mpconfigport.h index 1181517fdf9a0..00dcafe10fe11 100644 --- a/ports/raspberrypi/mpconfigport.h +++ b/ports/raspberrypi/mpconfigport.h @@ -16,6 +16,9 @@ #define MICROPY_PY_SYS_PLATFORM "RP2350" #endif +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + // Setting a non-default value also requires a non-default link.ld #ifndef CIRCUITPY_FIRMWARE_SIZE #define CIRCUITPY_FIRMWARE_SIZE (1020 * 1024) diff --git a/ports/raspberrypi/mphalport.c b/ports/raspberrypi/mphalport.c index 3d322ba6bca45..3258c4de4f3b6 100644 --- a/ports/raspberrypi/mphalport.c +++ b/ports/raspberrypi/mphalport.c @@ -19,7 +19,7 @@ #include "mphalport.h" #include "supervisor/shared/tick.h" -#include "hardware/timer.h" +#include "src/rp2_common/hardware_timer/include/hardware/timer.h" extern uint32_t common_hal_mcu_processor_get_frequency(void); diff --git a/ports/raspberrypi/supervisor/internal_flash.c b/ports/raspberrypi/supervisor/internal_flash.c index 9d5e13348aac2..ce3bef6c564ce 100644 --- a/ports/raspberrypi/supervisor/internal_flash.c +++ b/ports/raspberrypi/supervisor/internal_flash.c @@ -24,11 +24,11 @@ #include "supervisor/usb.h" #ifdef PICO_RP2350 -#include "hardware/structs/qmi.h" +#include "src/rp2350/hardware_structs/include/hardware/structs/qmi.h" #endif -#include "hardware/structs/sio.h" -#include "hardware/flash.h" -#include "pico/binary_info.h" +#include "src/rp2040/hardware_structs/include/hardware/structs/sio.h" +#include "src/rp2_common/hardware_flash/include/hardware/flash.h" +#include "src/common/pico_binary_info/include/pico/binary_info.h" #if !defined(TOTAL_FLASH_MINIMUM) #define TOTAL_FLASH_MINIMUM (2 * 1024 * 1024) diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 7514b4e6ad4aa..026d9f629c57d 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -37,23 +37,23 @@ #include "supervisor/shared/stack.h" #include "supervisor/shared/tick.h" -#include "hardware/structs/watchdog.h" -#include "hardware/gpio.h" -#include "hardware/uart.h" -#include "hardware/sync.h" -#include "hardware/timer.h" +#include "src/rp2040/hardware_structs/include/hardware/structs/watchdog.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "src/rp2_common/hardware_uart/include/hardware/uart.h" +#include "src/rp2_common/hardware_sync/include/hardware/sync.h" +#include "src/rp2_common/hardware_timer/include/hardware/timer.h" #if CIRCUITPY_CYW43 #include "py/mphal.h" #include "pico/cyw43_arch.h" #endif -#include "pico/time.h" -#include "pico/binary_info.h" +#include "src/common/pico_time/include/pico/time.h" +#include "src/common/pico_binary_info/include/pico/binary_info.h" #include "pico/bootrom.h" #include "hardware/watchdog.h" #ifdef PICO_RP2350 -#include "RP2350.h" // CMSIS +#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h" #endif #include "supervisor/shared/serial.h" @@ -95,10 +95,10 @@ static size_t _psram_size = 0; #ifdef CIRCUITPY_PSRAM_CHIP_SELECT -#include "hardware/regs/qmi.h" -#include "hardware/regs/xip.h" -#include "hardware/structs/qmi.h" -#include "hardware/structs/xip_ctrl.h" +#include "src/rp2350/hardware_regs/include/hardware/regs/qmi.h" +#include "src/rp2350/hardware_regs/include/hardware/regs/xip.h" +#include "src/rp2350/hardware_structs/include/hardware/structs/qmi.h" +#include "src/rp2350/hardware_structs/include/hardware/structs/xip_ctrl.h" static void __no_inline_not_in_flash_func(setup_psram)(void) { gpio_set_function(CIRCUITPY_PSRAM_CHIP_SELECT->number, GPIO_FUNC_XIP_CS1); diff --git a/ports/raspberrypi/supervisor/usb.c b/ports/raspberrypi/supervisor/usb.c index 398f3f448a1d5..97933d5651ea5 100644 --- a/ports/raspberrypi/supervisor/usb.c +++ b/ports/raspberrypi/supervisor/usb.c @@ -7,9 +7,9 @@ #include "lib/tinyusb/src/device/usbd.h" #include "supervisor/background_callback.h" #include "supervisor/usb.h" -#include "hardware/irq.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" #include "pico/platform.h" -#include "hardware/regs/intctrl.h" +#include "src/rp2040/hardware_regs/include/hardware/regs/intctrl.h" void init_usb_hardware(void) { } diff --git a/ports/renode/common-hal/os/__init__.c b/ports/renode/common-hal/os/__init__.c index 14e22960469fa..334742bb594e3 100644 --- a/ports/renode/common-hal/os/__init__.c +++ b/ports/renode/common-hal/os/__init__.c @@ -12,6 +12,32 @@ #include "shared-bindings/os/__init__.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "renode"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "renode"); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { return false; } diff --git a/ports/renode/mpconfigport.h b/ports/renode/mpconfigport.h index 185a884ed313e..19937d749d47b 100644 --- a/ports/renode/mpconfigport.h +++ b/ports/renode/mpconfigport.h @@ -8,6 +8,9 @@ #define MICROPY_PY_SYS_PLATFORM "Renode" +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + #define MICROPY_USE_INTERNAL_PRINTF (1) // This also includes mpconfigboard.h. diff --git a/ports/silabs/common-hal/os/__init__.c b/ports/silabs/common-hal/os/__init__.c index 79e79875fd541..42036536e4ff6 100644 --- a/ports/silabs/common-hal/os/__init__.c +++ b/ports/silabs/common-hal/os/__init__.c @@ -35,6 +35,31 @@ #include "peripherals/periph.h" #define RNG_TIMEOUT 5 +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, EFR32_SERIES_LOWER); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, EFR32_SERIES_LOWER); + +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { return false; diff --git a/ports/silabs/mpconfigport.h b/ports/silabs/mpconfigport.h index 26fe7dfc2f0b5..ce7739cccaea4 100644 --- a/ports/silabs/mpconfigport.h +++ b/ports/silabs/mpconfigport.h @@ -29,6 +29,9 @@ #include +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + // 24kiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 diff --git a/ports/stm/common-hal/os/__init__.c b/ports/stm/common-hal/os/__init__.c index d654f844b1767..b3d9e67d98893 100644 --- a/ports/stm/common-hal/os/__init__.c +++ b/ports/stm/common-hal/os/__init__.c @@ -15,6 +15,32 @@ #include STM32_HAL_H #include "peripherals/periph.h" +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, STM32_SERIES_LOWER); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, STM32_SERIES_LOWER); + +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + #define RNG_TIMEOUT 5 bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { diff --git a/ports/stm/mpconfigport.h b/ports/stm/mpconfigport.h index afa9aa3685c9a..ed36b49ffb92f 100644 --- a/ports/stm/mpconfigport.h +++ b/ports/stm/mpconfigport.h @@ -9,6 +9,9 @@ #include +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + extern uint8_t _ld_default_stack_size; // 24kiB stack diff --git a/ports/zephyr-cp/common-hal/os/__init__.c b/ports/zephyr-cp/common-hal/os/__init__.c index 2f37ba40f47a6..58e6674cb1157 100644 --- a/ports/zephyr-cp/common-hal/os/__init__.c +++ b/ports/zephyr-cp/common-hal/os/__init__.c @@ -13,6 +13,32 @@ #include +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "nrf52"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "nrf52"); + +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { #if !DT_HAS_CHOSEN(zephyr_entropy) return false; diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 2e7bba09d01b8..513f7d2d64d97 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -944,7 +944,7 @@ SRC_CIRCUITPY_COMMON = \ ifeq ($(CIRCUITPY_QRIO),1) SRC_CIRCUITPY_COMMON += lib/quirc/lib/decode.c lib/quirc/lib/identify.c lib/quirc/lib/quirc.c lib/quirc/lib/version_db.c -$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-type-limits -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h +$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h endif ifdef LD_TEMPLATE_FILE diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 42e6f1841a445..0121144f8ced6 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -17,6 +17,12 @@ // Always 1: defined in circuitpy_mpconfig.mk // #define CIRCUITPY (1) +// Can be removed once CircuitPython 10 is released. +// Print warnings or not about deprecated names. See objmodule.c. +#ifndef CIRCUITPY_9_10_WARNINGS +#define CIRCUITPY_9_10_WARNINGS (1) +#endif + // REPR_C encodes qstrs, 31-bit ints, and 30-bit floats in a single 32-bit word. #ifndef MICROPY_OBJ_REPR #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C) @@ -87,7 +93,6 @@ extern void common_hal_mcu_enable_interrupts(void); #define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE) #define MICROPY_OPT_LOAD_ATTR_FAST_PATH (CIRCUITPY_OPT_LOAD_ATTR_FAST_PATH) #define MICROPY_OPT_MAP_LOOKUP_CACHE (CIRCUITPY_OPT_MAP_LOOKUP_CACHE) -#define MICROPY_OPT_MPZ_BITWISE (0) #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (CIRCUITPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) #define MICROPY_PERSISTENT_CODE_LOAD (1) @@ -219,52 +224,31 @@ typedef long mp_off_t; // Turning off FULL_BUILD removes some functionality to reduce flash size on tiny SAMD21s #define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (CIRCUITPY_FULL_BUILD) - #ifndef MICROPY_CPYTHON_COMPAT #define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD) #endif - #ifndef MICROPY_CPYTHON_EXCEPTION_CHAIN #define MICROPY_CPYTHON_EXCEPTION_CHAIN (CIRCUITPY_FULL_BUILD) #endif - #define MICROPY_PY_BUILTINS_POW3 (CIRCUITPY_BUILTINS_POW3) #define MICROPY_PY_FSTRINGS (1) #define MICROPY_MODULE_WEAK_LINKS (0) #define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD) - #ifndef MICROPY_PY_BUILTINS_COMPLEX #define MICROPY_PY_BUILTINS_COMPLEX (CIRCUITPY_FULL_BUILD) #endif - #define MICROPY_PY_BUILTINS_FROZENSET (CIRCUITPY_FULL_BUILD) - -#ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED -#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (CIRCUITPY_FULL_BUILD) -#endif - #define MICROPY_PY_BUILTINS_STR_CENTER (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_BUILTINS_STR_PARTITION (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_BUILTINS_STR_SPLITLINES (CIRCUITPY_FULL_BUILD) - #ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (CIRCUITPY_FULL_BUILD) #endif - #ifndef MICROPY_PY_COLLECTIONS_DEQUE #define MICROPY_PY_COLLECTIONS_DEQUE (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_COLLECTIONS_DEQUE_ITER (CIRCUITPY_FULL_BUILD) #define MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR (CIRCUITPY_FULL_BUILD) #endif - -#ifndef MICROPY_PY_FUNCTION_ATTRS -#define MICROPY_PY_FUNCTION_ATTRS (CIRCUITPY_FULL_BUILD) -#endif - -#ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD) -#endif - #define MICROPY_PY_RE_MATCH_GROUPS (CIRCUITPY_RE) #define MICROPY_PY_RE_MATCH_SPAN_START_END (CIRCUITPY_RE) #define MICROPY_PY_RE_SUB (CIRCUITPY_RE) diff --git a/py/objmodule.c b/py/objmodule.c index 3ccd31b23af22..b6513907e5551 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -67,6 +67,33 @@ static void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *de static void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { + // CIRCUITPY-CHANGE + #if CIRCUITPY_9_10_WARNINGS && CIRCUITPY_DISPLAYIO && CIRCUITPY_WARNINGS + if (self == &displayio_module) { + #if CIRCUITPY_BUSDISPLAY + if (attr == MP_QSTR_Display) { + warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_Display, MP_QSTR_displayio, MP_QSTR_busdisplay); + warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q renamed %q"), MP_QSTR_Display, MP_QSTR_BusDisplay); + } + #endif + #if CIRCUITPY_EPAPERDISPLAY + if (attr == MP_QSTR_EPaperDisplay) { + warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_EPaperDisplay, MP_QSTR_displayio, MP_QSTR_epaperdisplay); + } + #endif + #if CIRCUITPY_FOURWIRE + if (attr == MP_QSTR_FourWire) { + warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_FourWire, MP_QSTR_displayio, MP_QSTR_fourwire); + } + #endif + #if CIRCUITPY_I2CDISPLAYBUS + if (attr == MP_QSTR_I2CDisplay) { + warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_I2CDisplay, MP_QSTR_displayio, MP_QSTR_i2cdisplaybus); + warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q renamed %q"), MP_QSTR_I2CDisplay, MP_QSTR_I2CDisplayBus); + } + #endif + } + #endif // load attribute mp_map_elem_t *elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); if (elem != NULL) { diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index bd5e89b5a67ab..7542941a4f5e4 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -16,8 +16,8 @@ //| """C-level helpers for animation of sprites on a stage //| -//| The `_stage` module contains native code to speed-up the ``stage`` -//| `library `_.""" +//| The `_stage` module contains native code to speed-up the ```stage`` Library +//| `_.""" //| //| //| def render( diff --git a/shared-bindings/aesio/aes.c b/shared-bindings/aesio/aes.c index a6916042fda19..be0935aac9e09 100644 --- a/shared-bindings/aesio/aes.c +++ b/shared-bindings/aesio/aes.c @@ -177,10 +177,8 @@ static void validate_length(aesio_aes_obj_t *self, size_t src_length, //| """Encrypt the buffer from ``src`` into ``dest``. //| //| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the -//| buffers must be a multiple of 16 bytes, and must be equal length. -//| Any included padding must conform to the required padding style for the given mode. -//| For CTR mode, there are no restrictions. -//| """ +//| buffers must be a multiple of 16 bytes, and must be equal length. For +//| CTR mode, there are no restrictions.""" //| ... //| static mp_obj_t aesio_aes_encrypt_into(mp_obj_t self_in, mp_obj_t src, mp_obj_t dest) { diff --git a/shared-bindings/alarm/time/TimeAlarm.c b/shared-bindings/alarm/time/TimeAlarm.c index 0277c22fc44bf..a40e8dd08e6ae 100644 --- a/shared-bindings/alarm/time/TimeAlarm.c +++ b/shared-bindings/alarm/time/TimeAlarm.c @@ -35,12 +35,6 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) { //| If the given time is already in the past, then an exception is raised. //| If the sleep happens after the given time, then it will wake immediately //| due to this time alarm. -//| -//| Example:: -//| -//| # Deep sleep for 30 seconds. -//| time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 30) -//| alarm.exit_and_deep_sleep_until_alarms(time_alarm) //| """ //| ... //| diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index b9e5824f978b7..15fe1657c8714 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -20,9 +20,6 @@ //| //| **Limitations:** Not available on Nordic, RP2040, Spresense, as there is no on-chip DAC. //| On Espressif, available only on ESP32 and ESP32-S2; other chips do not have a DAC. -//| On ESP32-S2 boards, GPIO18 (DAC2) is often connected to a pull-up resistor, which causes -//| `unexpected output values in the lower part of the output range -//| `_. //| //| Example usage:: //| diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 82aecefa370ba..1bfc51cb9ab27 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -28,16 +28,11 @@ //| """Create a AudioOut object associated with the given pin(s). This allows you to //| play audio signals out on the given pin(s). //| -//| :param ~microcontroller.Pin left_channel: Output left channel data to this pin -//| :param ~microcontroller.Pin right_channel: Output right channel data to this pin. May be ``None``. +//| :param ~microcontroller.Pin left_channel: The pin to output the left channel to +//| :param ~microcontroller.Pin right_channel: The pin to output the right channel to //| :param int quiescent_value: The output value when no signal is present. Samples should start //| and end with this value to prevent audible popping. //| -//| .. note:: On ESP32 and ESP32-S2, the DAC channels are usually designated -//| as ``DAC_1`` (right stereo channel) and DAC_2 (left stereo channel). -//| These pins are sometimes labelled as ``A0`` and ``A1``, but they may be assigned -//| in either order. Check your board's pinout to verify which pin is which channel. -//| //| Simple 8ksps 440 Hz sin wave:: //| //| import audiocore @@ -95,12 +90,6 @@ static mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj, MP_QSTR_right_channel); - // Can't use the same pin for both left and right channels. - if (left_channel_pin == right_channel_pin) { - mp_raise_ValueError_varg(MP_ERROR_TEXT("%q and %q must be different"), - MP_QSTR_left_channel, MP_QSTR_right_channel); - } - // create AudioOut object from the given pin audioio_audioout_obj_t *self = mp_obj_malloc_with_finaliser(audioio_audioout_obj_t, &audioio_audioout_type); common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_quiescent_value].u_int); diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 8aa35ec6e0709..1b26a5659abc1 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -39,9 +39,6 @@ //| bit unpacking. Instead, use an existing driver or make one with //| :ref:`Register ` data descriptors. //| -//| .. seealso:: This class provides an I2C controller, which controls I2C targets (peripherals). -//| To act as an I2C target, use `i2ctarget.I2CTarget`. -//| //| :param ~microcontroller.Pin scl: The clock pin //| :param ~microcontroller.Pin sda: The data pin //| :param int frequency: The clock frequency in Hertz diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index 0c8ae1bfdd72c..9fcfc0e87a0ff 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -28,7 +28,7 @@ //| main device. It is typically faster than :py:class:`~bitbangio.I2C` because a //| separate pin is used to select a device rather than a transmitted //| address. This class only manages three of the four SPI lines: `!clock`, -//| `!MOSI`, `!MISO`. It is up to the client to manage the appropriate +//| `!MOSI`, `!MISO`. Its up to the client to manage the appropriate //| select line, often abbreviated `!CS` or `!SS`. (This is common because //| multiple secondaries can share the `!clock`, `!MOSI` and `!MISO` lines //| and therefore the hardware.) @@ -46,8 +46,6 @@ //| //|

//| -//| .. seealso:: This class acts as an SPI main (controller). -//| To act as an SPI secondary (target), use `spitarget.SPITarget`. //| """ //| //| def __init__( diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 8a9b2e5e0d34e..a8757fbcc17f2 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -316,7 +316,7 @@ MP_PROPERTY_GETSET(displayio_tilegrid_transpose_xy_obj, //| inside the tilegrid rectangle bounds.""" //| static mp_obj_t displayio_tilegrid_obj_contains(mp_obj_t self_in, mp_obj_t touch_tuple) { - displayio_tilegrid_t *self = native_tilegrid(self_in); + displayio_tilegrid_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t *touch_tuple_items; mp_obj_get_array_fixed_n(touch_tuple, 3, &touch_tuple_items); diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index e0c35d3bce47d..136f380f3d33d 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -100,8 +100,21 @@ static const mp_rom_map_elem_t displayio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) }, { MP_ROM_QSTR(MP_QSTR_TileGrid), MP_ROM_PTR(&displayio_tilegrid_type) }, - { MP_ROM_QSTR(MP_QSTR_release_displays), MP_ROM_PTR(&displayio_release_displays_obj) }, + // Remove these in CircuitPython 10 + #if CIRCUITPY_BUSDISPLAY + { MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&busdisplay_busdisplay_type) }, + #endif + #if CIRCUITPY_EPAPERDISPLAY + { MP_ROM_QSTR(MP_QSTR_EPaperDisplay), MP_ROM_PTR(&epaperdisplay_epaperdisplay_type) }, + #endif + #if CIRCUITPY_FOURWIRE + { MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&fourwire_fourwire_type) }, + #endif + #if CIRCUITPY_I2CDISPLAYBUS + { MP_ROM_QSTR(MP_QSTR_I2CDisplay), MP_ROM_PTR(&i2cdisplaybus_i2cdisplaybus_type) }, + #endif + { MP_ROM_QSTR(MP_QSTR_release_displays), MP_ROM_PTR(&displayio_release_displays_obj) }, { MP_ROM_QSTR(MP_QSTR_CIRCUITPYTHON_TERMINAL), MP_ROM_PTR(&circuitpython_splash) }, }; static MP_DEFINE_CONST_DICT(displayio_module_globals, displayio_module_globals_table); diff --git a/shared-bindings/epaperdisplay/EPaperDisplay.c b/shared-bindings/epaperdisplay/EPaperDisplay.c index 0d558a1319616..10291b7d99fde 100644 --- a/shared-bindings/epaperdisplay/EPaperDisplay.c +++ b/shared-bindings/epaperdisplay/EPaperDisplay.c @@ -29,8 +29,7 @@ //| is called. This is done so that CircuitPython can use the display itself. //| //| Most people should not use this class directly. Use a specific display driver instead that will -//| contain the startup and shutdown sequences at minimum. -//| """ +//| contain the startup and shutdown sequences at minimum.""" //| //| def __init__( //| self, diff --git a/shared-bindings/fourwire/FourWire.c b/shared-bindings/fourwire/FourWire.c index 083cf21a00367..4b08c00566f44 100644 --- a/shared-bindings/fourwire/FourWire.c +++ b/shared-bindings/fourwire/FourWire.c @@ -20,11 +20,7 @@ //| class FourWire: //| """Manage updating a display over SPI four wire protocol in the background while Python code runs. -//| It doesn't handle display initialization. -//| -//| .. seealso:: See `busdisplay.BusDisplay` and `epaperdisplay.EPaperDisplay` -//| for how to initialize a display, given a `FourWire` bus. -//| """ +//| It doesn't handle display initialization.""" //| //| def __init__( //| self, diff --git a/shared-bindings/i2cdisplaybus/I2CDisplayBus.c b/shared-bindings/i2cdisplaybus/I2CDisplayBus.c index 8633f166805d2..d6e0763052b2d 100644 --- a/shared-bindings/i2cdisplaybus/I2CDisplayBus.c +++ b/shared-bindings/i2cdisplaybus/I2CDisplayBus.c @@ -19,11 +19,7 @@ //| class I2CDisplayBus: //| """Manage updating a display over I2C in the background while Python code runs. -//| It doesn't handle display initialization. -//| -//| .. seealso:: See `busdisplay.BusDisplay` and `epaperdisplay.EPaperDisplay` -//| for how to initialize a display, given an `I2CDisplayBus`. -//| """ +//| It doesn't handle display initialization.""" //| //| def __init__( //| self, diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index 6d3e4d6884209..bf04ae18b1338 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -15,12 +15,6 @@ a list of modules supported on each board. Modules --------- -.. note:: Some modules are documented in :doc:`/docs/library/index`, not here: - `builtins`, `heapq`, `array`, `binascii`, `collections`, `errno`, `gc`, - `io`, `json`, `re`, `sys`, `select`. - - The documentation for :func:`help` is at the end of this page. - .. toctree:: :glob: :maxdepth: 2 diff --git a/shared-bindings/keypad/EventQueue.c b/shared-bindings/keypad/EventQueue.c index a899c652bc546..67d742c3dcd7a 100644 --- a/shared-bindings/keypad/EventQueue.c +++ b/shared-bindings/keypad/EventQueue.c @@ -23,8 +23,7 @@ //| //| def get(self) -> Optional[Event]: -//| """Remove the next key transition event from the `EventQueue` and return it. -//| Return ``None`` if no events are pending. +//| """Return the next key transition event. Return ``None`` if no events are pending. //| //| Note that the queue size is limited; see ``max_events`` in the constructor of //| a scanner such as `Keys` or `KeyMatrix`. @@ -44,7 +43,7 @@ static mp_obj_t keypad_eventqueue_get(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(keypad_eventqueue_get_obj, keypad_eventqueue_get); //| def get_into(self, event: Event) -> bool: -//| """Remove the next key transition event from the ``EventQueue`, store it in ``event``, +//| """Store the next key transition event in the supplied event, if available, //| and return ``True``. //| If there are no queued events, do not touch ``event`` and return ``False``. //| diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index 5e28c02452d05..e6f6d4896dc3d 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -44,30 +44,8 @@ //| machine: str //| //| -static const qstr os_uname_info_fields[] = { - MP_QSTR_sysname, MP_QSTR_nodename, - MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine -}; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); -static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); - - -static MP_DEFINE_ATTRTUPLE( - os_uname_info_obj, - os_uname_info_fields, - 5, - (mp_obj_t)&os_uname_info_sysname_obj, - (mp_obj_t)&os_uname_info_nodename_obj, - (mp_obj_t)&os_uname_info_release_obj, - (mp_obj_t)&os_uname_info_version_obj, - (mp_obj_t)&os_uname_info_machine_obj - ); - static mp_obj_t os_uname(void) { - return (mp_obj_t)&os_uname_info_obj; + return common_hal_os_uname(); } static MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); diff --git a/shared-bindings/os/__init__.h b/shared-bindings/os/__init__.h index 56b643e2edfbe..f273708cf4ed9 100644 --- a/shared-bindings/os/__init__.h +++ b/shared-bindings/os/__init__.h @@ -11,6 +11,9 @@ #include "py/objtuple.h" +extern const mp_rom_obj_tuple_t common_hal_os_uname_info_obj; + +mp_obj_t common_hal_os_uname(void); void common_hal_os_chdir(const char *path); mp_obj_t common_hal_os_getcwd(void); mp_obj_t common_hal_os_getenv(const char *key, mp_obj_t default_); diff --git a/shared-bindings/paralleldisplaybus/ParallelBus.c b/shared-bindings/paralleldisplaybus/ParallelBus.c index dfe363bdcb797..1e0bd63674422 100644 --- a/shared-bindings/paralleldisplaybus/ParallelBus.c +++ b/shared-bindings/paralleldisplaybus/ParallelBus.c @@ -18,11 +18,7 @@ //| class ParallelBus: //| """Manage updating a display over 8-bit parallel bus in the background while Python code runs. This //| protocol may be referred to as 8080-I Series Parallel Interface in datasheets. It doesn't handle -//| display initialization. -//| -//| .. seealso:: See `busdisplay.BusDisplay` and `epaperdisplay.EPaperDisplay` -//| for how to initialize a display, given a `ParallelBus`. -//| """ +//| display initialization.""" //| //| def __init__( //| self, diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c index 0cd94c0756214..810782bc526f6 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.c +++ b/shared-bindings/rotaryio/IncrementalEncoder.c @@ -42,13 +42,7 @@ //| position = enc.position //| if last_position == None or position != last_position: //| print(position) -//| last_position = position -//| -//| .. warning:: On RP2350 boards, any pulldowns used must be 8.2 kohms or less, -//| to overcome a hardware issue. -//| See the RP2350 warning in `digitalio` for more information. -//| """ -//| +//| last_position = position""" //| ... //| static mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index e139e3a077ab2..e58b75ba92877 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -103,6 +103,10 @@ static mp_obj_t socketpool_socketpool_socket(size_t n_args, const mp_obj_t *pos_ socketpool_socketpool_sock_t type = args[ARG_type].u_int; socketpool_socketpool_ipproto_t proto = args[ARG_proto].u_int; + if (proto < 0) { + proto = 0; + } + return common_hal_socketpool_socket(self, family, type, proto); } MP_DEFINE_CONST_FUN_OBJ_KW(socketpool_socketpool_socket_obj, 1, socketpool_socketpool_socket); diff --git a/shared-bindings/synthio/LFO.c b/shared-bindings/synthio/LFO.c index ee2d67d308903..c1935f9e96d89 100644 --- a/shared-bindings/synthio/LFO.c +++ b/shared-bindings/synthio/LFO.c @@ -43,7 +43,7 @@ static const uint16_t triangle[] = {0, 32767, 0, -32767}; //| An LFO's ``value`` property is computed once when it is constructed, and then //| when its associated synthesizer updates it. //| -//| This means that for instance an LFO **created** with ``offset=1`` has ``value==1`` +//| This means that for instance an LFO **created** with ``offset=1`` has ```value==1`` //| immediately, but **updating** the ``offset`` property alone does not //| change ``value``; it only updates through an association with an active synthesizer. //| diff --git a/shared-bindings/tilepalettemapper/TilePaletteMapper.c b/shared-bindings/tilepalettemapper/TilePaletteMapper.c index 88189de549dbb..ee1475d16b50f 100644 --- a/shared-bindings/tilepalettemapper/TilePaletteMapper.c +++ b/shared-bindings/tilepalettemapper/TilePaletteMapper.c @@ -11,7 +11,6 @@ #include "py/runtime.h" #include "shared-bindings/util.h" #include "shared-bindings/displayio/Palette.h" -#include "shared-bindings/displayio/ColorConverter.h" #include "shared-bindings/tilepalettemapper/TilePaletteMapper.h" //| class TilePaletteMapper: @@ -25,29 +24,28 @@ //| ) -> None: //| """Create a TilePaletteMApper object to store a set of color mappings for tiles. //| -//| :param Union[displayio.Palette, displayio.ColorConverter] pixel_shader: -//| The palette or ColorConverter to get mapped colors from. +//| :param displayio.Palette palette: The palette to get mapped colors from. //| :param int input_color_count: The number of colors in in the input bitmap. //| :param int width: The width of the grid in tiles. //| :param int height: The height of the grid in tiles.""" //| static mp_obj_t tilepalettemapper_tilepalettemapper_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_pixel_shader, ARG_input_color_count, ARG_width, ARG_height }; + enum { ARG_palette, ARG_input_color_count, ARG_width, ARG_height }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_palette, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_input_color_count, MP_ARG_INT | MP_ARG_REQUIRED }, { MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED }, { MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; - if (!mp_obj_is_type(pixel_shader, &displayio_palette_type) && !mp_obj_is_type(pixel_shader, &displayio_colorconverter_type)) { + mp_obj_t palette = args[ARG_palette].u_obj; + if (!mp_obj_is_type(palette, &displayio_palette_type)) { mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported %q type"), MP_QSTR_pixel_shader); } tilepalettemapper_tilepalettemapper_t *self = mp_obj_malloc(tilepalettemapper_tilepalettemapper_t, &tilepalettemapper_tilepalettemapper_type); - common_hal_tilepalettemapper_tilepalettemapper_construct(self, pixel_shader, args[ARG_input_color_count].u_int, args[ARG_width].u_int, args[ARG_height].u_int); + common_hal_tilepalettemapper_tilepalettemapper_construct(self, palette, args[ARG_input_color_count].u_int, args[ARG_width].u_int, args[ARG_height].u_int); return MP_OBJ_FROM_PTR(self); } @@ -75,17 +73,17 @@ MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_height_obj, (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_height_obj); -//| pixel_shader: Union[displayio.Palette, displayio.ColorConverter] -//| """The palette or ColorConverter that the mapper uses.""" +//| palette: displayio.Palette +//| """The palette that the mapper uses.""" //| -static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_pixel_shader(mp_obj_t self_in) { +static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_palette(mp_obj_t self_in) { tilepalettemapper_tilepalettemapper_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_tilepalettemapper_tilepalettemapper_get_pixel_shader(self); + return common_hal_tilepalettemapper_tilepalettemapper_get_palette(self); } -MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_pixel_shader_obj, tilepalettemapper_tilepalettemapper_obj_get_pixel_shader); +MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_palette_obj, tilepalettemapper_tilepalettemapper_obj_get_palette); MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_palette_obj, - (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_pixel_shader_obj); + (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_palette_obj); //| def __getitem__(self, index: Union[Tuple[int, int], int]) -> Tuple[int]: diff --git a/shared-bindings/tilepalettemapper/TilePaletteMapper.h b/shared-bindings/tilepalettemapper/TilePaletteMapper.h index 3fa1ab1e3a5cc..0e4eced23b7c3 100644 --- a/shared-bindings/tilepalettemapper/TilePaletteMapper.h +++ b/shared-bindings/tilepalettemapper/TilePaletteMapper.h @@ -13,6 +13,6 @@ void common_hal_tilepalettemapper_tilepalettemapper_construct(tilepalettemapper_ uint16_t common_hal_tilepalettemapper_tilepalettemapper_get_width(tilepalettemapper_tilepalettemapper_t *self); uint16_t common_hal_tilepalettemapper_tilepalettemapper_get_height(tilepalettemapper_tilepalettemapper_t *self); -mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_pixel_shader(tilepalettemapper_tilepalettemapper_t *self); +mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_palette(tilepalettemapper_tilepalettemapper_t *self); mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y); void common_hal_tilepalettemapper_tilepalettemapper_set_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y, size_t len, mp_obj_t *items); diff --git a/shared-bindings/usb/core/Device.c b/shared-bindings/usb/core/Device.c index 683115a842102..28d178b748eae 100644 --- a/shared-bindings/usb/core/Device.c +++ b/shared-bindings/usb/core/Device.c @@ -39,7 +39,6 @@ #include "py/objproperty.h" #include "shared-bindings/usb/core/Device.h" -#include "shared-bindings/util.h" #include "py/runtime.h" //| class Device: @@ -50,12 +49,6 @@ //| ... //| -static void check_for_deinit(usb_core_device_obj_t *self) { - if (common_hal_usb_core_device_deinited(self)) { - raise_deinited_error(); - } -} - //| def __del__(self) -> None: //| """Closes any resources used for this device.""" //| ... @@ -71,7 +64,6 @@ static MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_deinit_obj, usb_core_device_dei //| """The USB vendor ID of the device""" static mp_obj_t usb_core_device_obj_get_idVendor(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_idVendor(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_idVendor_obj, usb_core_device_obj_get_idVendor); @@ -83,7 +75,6 @@ MP_PROPERTY_GETTER(usb_core_device_idVendor_obj, //| """The USB product ID of the device""" static mp_obj_t usb_core_device_obj_get_idProduct(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_idProduct(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_idProduct_obj, usb_core_device_obj_get_idProduct); @@ -95,7 +86,6 @@ MP_PROPERTY_GETTER(usb_core_device_idProduct_obj, //| """The USB device's serial number string.""" static mp_obj_t usb_core_device_obj_get_serial_number(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return common_hal_usb_core_device_get_serial_number(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_serial_number_obj, usb_core_device_obj_get_serial_number); @@ -107,7 +97,6 @@ MP_PROPERTY_GETTER(usb_core_device_serial_number_obj, //| """The USB device's product string.""" static mp_obj_t usb_core_device_obj_get_product(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return common_hal_usb_core_device_get_product(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_product_obj, usb_core_device_obj_get_product); @@ -120,7 +109,6 @@ MP_PROPERTY_GETTER(usb_core_device_product_obj, //| static mp_obj_t usb_core_device_obj_get_manufacturer(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return common_hal_usb_core_device_get_manufacturer(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_manufacturer_obj, usb_core_device_obj_get_manufacturer); @@ -133,7 +121,6 @@ MP_PROPERTY_GETTER(usb_core_device_manufacturer_obj, //| static mp_obj_t usb_core_device_obj_get_bus(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_bus(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_bus_obj, usb_core_device_obj_get_bus); @@ -147,7 +134,6 @@ MP_PROPERTY_GETTER(usb_core_device_bus_obj, //| static mp_obj_t usb_core_device_obj_get_port_numbers(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return common_hal_usb_core_device_get_port_numbers(self); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_port_numbers_obj, usb_core_device_obj_get_port_numbers); @@ -161,7 +147,6 @@ MP_PROPERTY_GETTER(usb_core_device_port_numbers_obj, //| static mp_obj_t usb_core_device_obj_get_speed(mp_obj_t self_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_usb_core_device_get_speed(self)); } MP_DEFINE_CONST_FUN_OBJ_1(usb_core_device_get_speed_obj, usb_core_device_obj_get_speed); @@ -186,7 +171,6 @@ static mp_obj_t usb_core_device_set_configuration(size_t n_args, const mp_obj_t { MP_QSTR_configuration, MP_ARG_INT, {.u_int = 1} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -213,7 +197,6 @@ static mp_obj_t usb_core_device_write(size_t n_args, const mp_obj_t *pos_args, m { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 0} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -245,7 +228,6 @@ static mp_obj_t usb_core_device_read(size_t n_args, const mp_obj_t *pos_args, mp { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 0} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -295,7 +277,6 @@ static mp_obj_t usb_core_device_ctrl_transfer(size_t n_args, const mp_obj_t *pos { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 0} }, }; usb_core_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -329,7 +310,6 @@ MP_DEFINE_CONST_FUN_OBJ_KW(usb_core_device_ctrl_transfer_obj, 2, usb_core_device //| static mp_obj_t usb_core_device_is_kernel_driver_active(mp_obj_t self_in, mp_obj_t interface_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); mp_int_t interface = mp_obj_get_int(interface_in); bool active = common_hal_usb_core_device_is_kernel_driver_active(self, interface); return mp_obj_new_bool(active); @@ -347,7 +327,6 @@ MP_DEFINE_CONST_FUN_OBJ_2(usb_core_device_is_kernel_driver_active_obj, usb_core_ //| static mp_obj_t usb_core_device_detach_kernel_driver(mp_obj_t self_in, mp_obj_t interface_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); mp_int_t interface = mp_obj_get_int(interface_in); common_hal_usb_core_device_detach_kernel_driver(self, interface); return mp_const_none; @@ -364,7 +343,6 @@ MP_DEFINE_CONST_FUN_OBJ_2(usb_core_device_detach_kernel_driver_obj, usb_core_dev //| static mp_obj_t usb_core_device_attach_kernel_driver(mp_obj_t self_in, mp_obj_t interface_in) { usb_core_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); mp_int_t interface = mp_obj_get_int(interface_in); common_hal_usb_core_device_attach_kernel_driver(self, interface); return mp_const_none; diff --git a/shared-bindings/usb/core/Device.h b/shared-bindings/usb/core/Device.h index 28c2cfbe19860..7278ca297ede3 100644 --- a/shared-bindings/usb/core/Device.h +++ b/shared-bindings/usb/core/Device.h @@ -13,7 +13,6 @@ extern const mp_obj_type_t usb_core_device_type; bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t device_number); -bool common_hal_usb_core_device_deinited(usb_core_device_obj_t *self); void common_hal_usb_core_device_deinit(usb_core_device_obj_t *self); uint16_t common_hal_usb_core_device_get_idVendor(usb_core_device_obj_t *self); uint16_t common_hal_usb_core_device_get_idProduct(usb_core_device_obj_t *self); diff --git a/shared-module/audiomp3/MP3Decoder.c b/shared-module/audiomp3/MP3Decoder.c index 3710b8252164d..49bd4835e8855 100644 --- a/shared-module/audiomp3/MP3Decoder.c +++ b/shared-module/audiomp3/MP3Decoder.c @@ -385,7 +385,7 @@ void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t *self, mp_obj_t self->base.channel_count = fi.nChans; self->base.single_buffer = false; self->base.bits_per_sample = 16; - self->base.samples_signed = true; + self->base.samples_signed = false; self->base.max_buffer_length = fi.outputSamps * sizeof(int16_t); self->len = 2 * self->base.max_buffer_length; self->samples_decoded = 0; diff --git a/shared-module/keypad/EventQueue.c b/shared-module/keypad/EventQueue.c index e5b362a045ddf..ad1134417b858 100644 --- a/shared-module/keypad/EventQueue.c +++ b/shared-module/keypad/EventQueue.c @@ -13,11 +13,9 @@ #define EVENT_PRESSED (1 << 15) #define EVENT_KEY_NUM_MASK ((1 << 15) - 1) -#define EVENT_SIZE_BYTES (sizeof(uint16_t) + sizeof(mp_obj_t)) - void common_hal_keypad_eventqueue_construct(keypad_eventqueue_obj_t *self, size_t max_events) { // Event queue is 16-bit values. - ringbuf_alloc(&self->encoded_events, max_events * EVENT_SIZE_BYTES); + ringbuf_alloc(&self->encoded_events, max_events * (sizeof(uint16_t) + sizeof(mp_obj_t))); self->overflowed = false; self->event_handler = NULL; } @@ -65,7 +63,7 @@ void common_hal_keypad_eventqueue_clear(keypad_eventqueue_obj_t *self) { } size_t common_hal_keypad_eventqueue_get_length(keypad_eventqueue_obj_t *self) { - return ringbuf_num_filled(&self->encoded_events) / EVENT_SIZE_BYTES; + return ringbuf_num_filled(&self->encoded_events); } void common_hal_keypad_eventqueue_set_event_handler(keypad_eventqueue_obj_t *self, void (*event_handler)(keypad_eventqueue_obj_t *)) { diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c index 6afe64dd62d5b..81296db854cd3 100644 --- a/shared-module/os/__init__.c +++ b/shared-module/os/__init__.c @@ -17,7 +17,7 @@ #include "shared-bindings/os/__init__.h" // This provides all VFS related OS functions so that ports can share the code -// as needed. +// as needed. It does not provide uname. // Version of mp_vfs_lookup_path that takes and returns uPy string objects. static mp_vfs_mount_t *lookup_path(const char *path, mp_obj_t *path_out) { diff --git a/shared-module/tilepalettemapper/TilePaletteMapper.c b/shared-module/tilepalettemapper/TilePaletteMapper.c index f27c507fdca49..c988e908ab00b 100644 --- a/shared-module/tilepalettemapper/TilePaletteMapper.c +++ b/shared-module/tilepalettemapper/TilePaletteMapper.c @@ -7,28 +7,21 @@ #include "py/runtime.h" #include "shared-bindings/tilepalettemapper/TilePaletteMapper.h" #include "shared-bindings/displayio/Palette.h" -#include "shared-bindings/displayio/ColorConverter.h" void common_hal_tilepalettemapper_tilepalettemapper_construct(tilepalettemapper_tilepalettemapper_t *self, - mp_obj_t pixel_shader, uint16_t input_color_count, uint16_t width, uint16_t height) { + mp_obj_t palette, uint16_t input_color_count, uint16_t width, uint16_t height) { - self->pixel_shader = pixel_shader; + self->palette = palette; self->width_in_tiles = width; self->height_in_tiles = height; self->input_color_count = input_color_count; self->needs_refresh = false; int mappings_len = width * height; - self->tile_mappings = (uint32_t **)m_malloc(mappings_len * sizeof(uint32_t *)); + self->tile_mappings = (uint16_t **)m_malloc(mappings_len * sizeof(uint16_t *)); for (int i = 0; i < mappings_len; i++) { - self->tile_mappings[i] = (uint32_t *)m_malloc(input_color_count * sizeof(uint32_t)); - if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { - for (uint16_t j = 0; j < input_color_count; j++) { - self->tile_mappings[i][j] = j; - } - } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { - for (uint16_t j = 0; j < input_color_count; j++) { - self->tile_mappings[i][j] = 0; - } + self->tile_mappings[i] = (uint16_t *)m_malloc(input_color_count * sizeof(uint16_t)); + for (uint16_t j = 0; j < input_color_count; j++) { + self->tile_mappings[i][j] = j; } } } @@ -41,8 +34,8 @@ uint16_t common_hal_tilepalettemapper_tilepalettemapper_get_height(tilepalettema return self->height_in_tiles; } -mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_pixel_shader(tilepalettemapper_tilepalettemapper_t *self) { - return self->pixel_shader; +mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_palette(tilepalettemapper_tilepalettemapper_t *self) { + return self->palette; } mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y) { @@ -55,16 +48,10 @@ mp_obj_t common_hal_tilepalettemapper_tilepalettemapper_get_mapping(tilepalettem } void common_hal_tilepalettemapper_tilepalettemapper_set_mapping(tilepalettemapper_tilepalettemapper_t *self, uint16_t x, uint16_t y, size_t len, mp_obj_t *items) { - uint32_t palette_max; - if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { - palette_max = common_hal_displayio_palette_get_len(self->pixel_shader) - 1; - } else { // colorconverter type - palette_max = 0xFFFFFF; - } - + uint32_t palette_len = common_hal_displayio_palette_get_len(self->palette); for (uint16_t i = 0; i < MIN(len, self->input_color_count); i++) { int mapping_val = mp_arg_validate_type_int(items[i], MP_QSTR_mapping_value); - mp_arg_validate_int_range(mapping_val, 0, palette_max, MP_QSTR_mapping_value); + mp_arg_validate_int_range(mapping_val, 0, palette_len - 1, MP_QSTR_mapping_value); self->tile_mappings[y * self->width_in_tiles + x][i] = mapping_val; } self->needs_refresh = true; @@ -72,23 +59,14 @@ void common_hal_tilepalettemapper_tilepalettemapper_set_mapping(tilepalettemappe void tilepalettemapper_tilepalettemapper_get_color(tilepalettemapper_tilepalettemapper_t *self, const _displayio_colorspace_t *colorspace, displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color, uint16_t x_tile_index, uint16_t y_tile_index) { if (x_tile_index >= self->width_in_tiles || y_tile_index >= self->height_in_tiles) { - if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { - displayio_palette_get_color(self->pixel_shader, colorspace, input_pixel, output_color); - } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { - displayio_colorconverter_convert(self->pixel_shader, colorspace, input_pixel, output_color); - } + displayio_palette_get_color(self->palette, colorspace, input_pixel, output_color); return; } uint16_t tile_index = y_tile_index * self->width_in_tiles + x_tile_index; uint32_t mapped_index = self->tile_mappings[tile_index][input_pixel->pixel]; displayio_input_pixel_t tmp_pixel; tmp_pixel.pixel = mapped_index; - if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { - displayio_palette_get_color(self->pixel_shader, colorspace, &tmp_pixel, output_color); - } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { - displayio_colorconverter_convert(self->pixel_shader, colorspace, &tmp_pixel, output_color); - } - + displayio_palette_get_color(self->palette, colorspace, &tmp_pixel, output_color); } bool tilepalettemapper_tilepalettemapper_needs_refresh(tilepalettemapper_tilepalettemapper_t *self) { diff --git a/shared-module/tilepalettemapper/TilePaletteMapper.h b/shared-module/tilepalettemapper/TilePaletteMapper.h index 98226ae7e04fa..8502d4bf53601 100644 --- a/shared-module/tilepalettemapper/TilePaletteMapper.h +++ b/shared-module/tilepalettemapper/TilePaletteMapper.h @@ -15,11 +15,11 @@ typedef struct { mp_obj_base_t base; - mp_obj_t pixel_shader; + mp_obj_t palette; uint16_t width_in_tiles; uint16_t height_in_tiles; uint16_t input_color_count; - uint32_t **tile_mappings; + uint16_t **tile_mappings; bool needs_refresh; } tilepalettemapper_tilepalettemapper_t; diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 0a52b925facf1..10fdf63b1ed6f 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -49,22 +49,10 @@ bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t d return true; } -bool common_hal_usb_core_device_deinited(usb_core_device_obj_t *self) { - return self->device_address == 0; -} - void common_hal_usb_core_device_deinit(usb_core_device_obj_t *self) { - if (common_hal_usb_core_device_deinited(self)) { - return; - } - size_t open_size = sizeof(self->open_endpoints); - for (size_t i = 0; i < open_size; i++) { - if (self->open_endpoints[i] != 0) { - tuh_edpt_close(self->device_address, self->open_endpoints[i]); - self->open_endpoints[i] = 0; - } - } - self->device_address = 0; + // TODO: Close all of the endpoints we've opened. Some drivers store state + // for each open endpoint. If we don't close them, then we'll leak memory. + // Waiting for TinyUSB to add this. } uint16_t common_hal_usb_core_device_get_idVendor(usb_core_device_obj_t *self) { diff --git a/shared-module/usb_cdc/Serial.c b/shared-module/usb_cdc/Serial.c index 348729365c2fc..3c67103afcee9 100644 --- a/shared-module/usb_cdc/Serial.c +++ b/shared-module/usb_cdc/Serial.c @@ -19,7 +19,9 @@ size_t common_hal_usb_cdc_serial_read(usb_cdc_serial_obj_t *self, uint8_t *data, // Read up to len bytes immediately. // The number of bytes read will not be larger than what is already in the TinyUSB FIFO. uint32_t total_num_read = 0; - total_num_read = tud_cdc_n_read(self->idx, data, len); + if (tud_cdc_n_connected(self->idx)) { + total_num_read = tud_cdc_n_read(self->idx, data, len); + } if (wait_forever || wait_for_timeout) { // Continue filling the buffer past what we already read. @@ -46,7 +48,9 @@ size_t common_hal_usb_cdc_serial_read(usb_cdc_serial_obj_t *self, uint8_t *data, data += num_read; // Try to read another batch of bytes. - num_read = tud_cdc_n_read(self->idx, data, len); + if (tud_cdc_n_connected(self->idx)) { + num_read = tud_cdc_n_read(self->idx, data, len); + } total_num_read += num_read; } } diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 94b429b6ab650..bc57500ed7c3e 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -298,7 +298,7 @@ char serial_read(void) { #if CIRCUITPY_WEB_WORKFLOW if (websocket_available()) { - int c = websocket_read_char(); + char c = websocket_read_char(); if (c != -1) { return c; } diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index c7a8232d228ad..2b92035d97199 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -26,10 +26,8 @@ #define LUN_COUNT 1 #endif -// The ellipsis range in the designated initializer of `ejected` is not standard C, -// but it works in both gcc and clang. -static bool ejected[LUN_COUNT] = { [0 ... (LUN_COUNT - 1)] = true}; -static bool locked[LUN_COUNT] = {false}; +static bool ejected[LUN_COUNT]; +static bool locked[LUN_COUNT]; #include "tusb.h" diff --git a/tests/circuitpython-manual/usb/device_info.py b/tests/circuitpython-manual/usb/device_info.py index 3481707055507..7b8631a8f865a 100644 --- a/tests/circuitpython-manual/usb/device_info.py +++ b/tests/circuitpython-manual/usb/device_info.py @@ -9,8 +9,7 @@ d.switch_to_output(value=True) print("USB power on") -if hasattr(board, "USB_HOST_DP") and hasattr(board, "USB_HOST_DM"): - h = usb_host.Port(board.USB_HOST_DP, board.USB_HOST_DM) +h = usb_host.Port(board.USB_HOST_DP, board.USB_HOST_DM) while True: for device in usb.core.find(find_all=True): diff --git a/tests/circuitpython/issue9705.py b/tests/circuitpython/issue9705.py index 0c694cc1b9fb1..7a59ed46f2ccb 100644 --- a/tests/circuitpython/issue9705.py +++ b/tests/circuitpython/issue9705.py @@ -1,4 +1,5 @@ import audiomp3, audiocore +import ulab.numpy as np TEST_FILE = ( __file__.rsplit("/", 1)[0] @@ -6,14 +7,19 @@ ) -def loudness(values): - return sum(abs(a) for a in values) +def normalized_rms_ulab(values): + values = np.frombuffer(values, dtype=np.int16) + # this function works with ndarrays only + minbuf = np.mean(values) + values = values - minbuf + samples_sum = np.sum(values * values) + return (samples_sum / len(values)) ** 0.5 def print_frame_loudness(decoder, n): for i in range(n): result, buf = audiocore.get_buffer(decoder) - print(f"{i} {result} {loudness(buf):5.0f}") + print(f"{i} {result} {normalized_rms_ulab(buf):5.0f}") print() diff --git a/tests/circuitpython/issue9705.py.exp b/tests/circuitpython/issue9705.py.exp index b57f8e63395c6..944fb65c8103f 100644 --- a/tests/circuitpython/issue9705.py.exp +++ b/tests/circuitpython/issue9705.py.exp @@ -1,16 +1,16 @@ 0 1 0 -1 1 25 -2 1 830 -3 1 880 -4 1 932 -5 1 892 -6 1 869 -7 1 839 +1 1 4730 +2 1 27914 +3 1 28737 +4 1 29251 +5 1 29219 +6 1 28672 +7 1 28213 0 1 0 -1 1 25 +1 1 4730 0 1 0 -1 1 25 -2 1 830 +1 1 4730 +2 1 27914