Merge pull request #8056 from jepler/matrixportal-s3

Add Adafruit MatrixPortal S3 board def & update protomatter
This commit is contained in:
Jeff Epler 2023-06-13 19:34:08 -05:00 committed by GitHub
commit 666fb94ca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 316 additions and 48 deletions

@ -1 +1 @@
Subproject commit d0a07e14adcd71a7c22bcceb16c55aadb5e0d104
Subproject commit ecab2fa75e9d7675785d2b87f29a22f027da8ce5

View File

@ -0,0 +1,34 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

View File

@ -0,0 +1,42 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// Micropython setup
#define MICROPY_HW_BOARD_NAME "Adafruit MatrixPortal S3"
#define MICROPY_HW_MCU_NAME "ESP32S3"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO4)
#define MICROPY_HW_LED_STATUS (&pin_GPIO13)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO17)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO16)
#define DEFAULT_UART_BUS_RX (&pin_GPIO8)
#define DEFAULT_UART_BUS_TX (&pin_GPIO18)
#define DOUBLE_TAP_PIN (&pin_GPIO1)

View File

@ -0,0 +1,12 @@
USB_VID = 0x239A
USB_PID = 0x8126
USB_PRODUCT = "MatrixPortal S3"
USB_MANUFACTURER = "Adafruit"
IDF_TARGET = esp32s3
CIRCUITPY_ESP_FLASH_MODE = dio
CIRCUITPY_ESP_FLASH_FREQ = 40m
CIRCUITPY_ESP_FLASH_SIZE = 8MB
CIRCUITPY_ESP32_CAMERA = 0

View File

@ -0,0 +1,100 @@
#include "py/objtuple.h"
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_obj_tuple_t matrix_addr_tuple = {
{&mp_type_tuple},
5,
{
MP_ROM_PTR(&pin_GPIO35),
MP_ROM_PTR(&pin_GPIO36),
MP_ROM_PTR(&pin_GPIO48),
MP_ROM_PTR(&pin_GPIO45),
MP_ROM_PTR(&pin_GPIO21),
}
};
STATIC const mp_rom_obj_tuple_t matrix_data_tuple = {
{&mp_type_tuple},
6,
{
MP_ROM_PTR(&pin_GPIO42),
MP_ROM_PTR(&pin_GPIO41),
MP_ROM_PTR(&pin_GPIO40),
MP_ROM_PTR(&pin_GPIO38),
MP_ROM_PTR(&pin_GPIO39),
MP_ROM_PTR(&pin_GPIO37),
}
};
STATIC const mp_rom_map_elem_t matrix_common_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_rgb_pins),MP_ROM_PTR(&matrix_data_tuple) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_clock_pin),MP_ROM_PTR(&pin_GPIO2) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_latch_pin),MP_ROM_PTR(&pin_GPIO47) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_output_enable_pin),MP_ROM_PTR(&pin_GPIO14) },
};
MP_DEFINE_CONST_DICT(matrix_common_dict, matrix_common_table);
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_ADDRESS),MP_ROM_PTR(&matrix_addr_tuple) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_COMMON),MP_ROM_PTR(&matrix_common_dict) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_R1),MP_ROM_PTR(&pin_GPIO42) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_G1),MP_ROM_PTR(&pin_GPIO41) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_B1),MP_ROM_PTR(&pin_GPIO40) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_R2),MP_ROM_PTR(&pin_GPIO38) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_G2),MP_ROM_PTR(&pin_GPIO39) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_B2),MP_ROM_PTR(&pin_GPIO37) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_ADDRA),MP_ROM_PTR(&pin_GPIO35) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_ADDRB),MP_ROM_PTR(&pin_GPIO36) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_ADDRC),MP_ROM_PTR(&pin_GPIO48) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_ADDRD),MP_ROM_PTR(&pin_GPIO45) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_ADDRE),MP_ROM_PTR(&pin_GPIO21) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_CLK),MP_ROM_PTR(&pin_GPIO2) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_LAT),MP_ROM_PTR(&pin_GPIO47) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_MTX_OE),MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_ACCELEROMETER_INTERRUPT), MP_ROM_PTR(&pin_GPIO15) },
// Grounded when closed.
{ MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON_UP),MP_ROM_PTR(&pin_GPIO6) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON_DOWN),MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -0,0 +1,39 @@
#
# Component config
#
#
# ESP32S3-Specific
#
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
#
# SPI RAM config
#
CONFIG_SPIRAM_MODE_QUAD=y
# CONFIG_SPIRAM_MODE_OCT is not set
CONFIG_SPIRAM_TYPE_AUTO=y
# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
CONFIG_SPIRAM_SIZE=2097152
#
# PSRAM Clock and CS IO for ESP32S3
#
CONFIG_DEFAULT_PSRAM_CLK_IO=30
CONFIG_DEFAULT_PSRAM_CS_IO=26
# end of PSRAM Clock and CS IO for ESP32S3
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
# CONFIG_SPIRAM_RODATA is not set
# CONFIG_SPIRAM_SPEED_120M is not set
CONFIG_SPIRAM_SPEED_80M=y
# CONFIG_SPIRAM_SPEED_40M is not set
CONFIG_SPIRAM=y
CONFIG_SPIRAM_BOOT_INIT=y
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
CONFIG_SPIRAM_USE_MEMMAP=y
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
# CONFIG_SPIRAM_USE_MALLOC is not set
CONFIG_SPIRAM_MEMTEST=y
# end of SPI RAM config
CONFIG_LWIP_LOCAL_HOSTNAME="matrixportal-s3"

View File

@ -31,7 +31,7 @@
#include "peripherals/timer.h"
void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
const timer_config_t config = {
static const timer_config_t config = {
.alarm_en = false,
.counter_en = false,
.intr_type = TIMER_INTR_LEVEL,
@ -43,6 +43,7 @@ void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
timer_index_t *timer = malloc(sizeof(timer_index_t));
bool res = peripherals_timer_init(&config, timer);
if (!res) {
free(timer);
return NULL;
}
peripherals_timer_never_reset(timer);
@ -52,6 +53,11 @@ void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
extern bool _PM_esp32timerCallback(void *arg);
void common_hal_rgbmatrix_timer_enable(void *ptr) {
timer_index_t *timer = (timer_index_t *)ptr;
if (timer->idx == TIMER_MAX) {
return;
}
timer_start(timer->group, timer->idx);
}
void common_hal_rgbmatrix_timer_disable(void *ptr) {
@ -60,8 +66,6 @@ void common_hal_rgbmatrix_timer_disable(void *ptr) {
return;
}
timer_pause(timer->group, timer->idx);
timer_disable_intr(timer->group, timer->idx);
timer_isr_callback_remove(timer->group, timer->idx);
}
void common_hal_rgbmatrix_timer_free(void *ptr) {
@ -70,6 +74,8 @@ void common_hal_rgbmatrix_timer_free(void *ptr) {
return;
}
common_hal_rgbmatrix_timer_disable(ptr);
timer_disable_intr(timer->group, timer->idx);
timer_isr_callback_remove(timer->group, timer->idx);
peripherals_timer_deinit(timer);
timer->idx = TIMER_MAX;
free(timer);
}

View File

@ -70,10 +70,12 @@ CIRCUITPY_USB = 0
else ifeq ($(IDF_TARGET),esp32s2)
# Modules
CIRCUITPY_BLEIO = 0
CIRCUITPY_RGBMATRIX_USES_SUPERVISOR_ALLOCATION = 0
else ifeq ($(IDF_TARGET),esp32s3)
# Modules
CIRCUITPY_PARALLELDISPLAY = 0
CIRCUITPY_RGBMATRIX_USES_SUPERVISOR_ALLOCATION = 0
endif
# No room for dualbank on boards with 2MB flash

View File

@ -385,6 +385,8 @@ CFLAGS += -DCIRCUITPY_RP2PIO=$(CIRCUITPY_RP2PIO)
CIRCUITPY_RGBMATRIX ?= 0
CFLAGS += -DCIRCUITPY_RGBMATRIX=$(CIRCUITPY_RGBMATRIX)
CIRCUITPY_RGBMATRIX_USES_SUPERVISOR_ALLOCATION ?= 1
CFLAGS += -DCIRCUITPY_RGBMATRIX_USES_SUPERVISOR_ALLOCATION=$(CIRCUITPY_RGBMATRIX_USES_SUPERVISOR_ALLOCATION)
CIRCUITPY_ROTARYIO ?= 1
CFLAGS += -DCIRCUITPY_ROTARYIO=$(CIRCUITPY_ROTARYIO)

View File

@ -62,13 +62,16 @@ STATIC void claim_and_never_reset_pins(mp_obj_t seq) {
}
STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_t rgb_pin_count, bool allow_inefficient) {
uint32_t port = clock_pin / 32;
uint32_t bit_mask = 1 << (clock_pin % 32);
if (rgb_pin_count <= 0 || rgb_pin_count % 6 != 0 || rgb_pin_count > 30) {
mp_raise_ValueError_varg(translate("The length of rgb_pins must be 6, 12, 18, 24, or 30"));
}
// Most ports have a strict requirement for how the rgbmatrix pins are laid
// out; these two micros don't. Special-case it here.
#if !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32S2)
uint32_t port = clock_pin / 32;
uint32_t bit_mask = 1 << (clock_pin % 32);
for (uint8_t i = 0; i < rgb_pin_count; i++) {
uint32_t pin_port = rgb_pins[i] / 32;
@ -130,6 +133,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
translate("Pinout uses %d bytes per element, which consumes more than the ideal %d bytes. If this cannot be avoided, pass allow_inefficient=True to the constructor"),
bytes_per_element, ideal_bytes_per_element);
}
#endif
}
//| def __init__(
@ -236,12 +240,6 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
preflight_pins_or_throw(clock_pin, rgb_pins, rgb_count, true);
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
if (framebuffer == mp_const_none) {
int bufsize = 2 * width * computed_height;
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
}
common_hal_rgbmatrix_rgbmatrix_construct(self,
width,
bit_depth,
@ -249,7 +247,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
addr_count, addr_pins,
clock_pin, latch_pin, output_enable_pin,
args[ARG_doublebuffer].u_bool,
framebuffer, tile, args[ARG_serpentine].u_bool, NULL);
args[ARG_framebuffer].u_obj, tile, args[ARG_serpentine].u_bool, NULL);
claim_and_never_reset_pins(args[ARG_rgb_list].u_obj);
claim_and_never_reset_pins(args[ARG_addr_list].u_obj);
@ -353,7 +351,6 @@ STATIC MP_DEFINE_CONST_DICT(rgbmatrix_rgbmatrix_locals_dict, rgbmatrix_rgbmatrix
STATIC void rgbmatrix_rgbmatrix_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufinfo) {
rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t *)self_in;
check_for_deinit(self);
*bufinfo = self->bufinfo;
}

View File

@ -34,7 +34,7 @@ extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, int width, int bit_depth, uint8_t rgb_count, uint8_t *rgb_pins, uint8_t addr_count, uint8_t *addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, int8_t tile, bool serpentine, void *timer);
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t *);
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t *);
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self, mp_obj_t framebuffer);
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self);
void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t *self, bool paused);
bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t *self);
void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t *self);

View File

@ -42,6 +42,8 @@
extern Protomatter_core *_PM_protoPtr;
STATIC void common_hal_rgbmatrix_rgbmatrix_construct1(rgbmatrix_rgbmatrix_obj_t *self, mp_obj_t framebuffer);
void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, int width, int bit_depth, uint8_t rgb_count, uint8_t *rgb_pins, uint8_t addr_count, uint8_t *addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, int8_t tile, bool serpentine, void *timer) {
self->width = width;
self->bit_depth = bit_depth;
@ -64,15 +66,11 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
self->width = width;
self->bufsize = 2 * width * common_hal_rgbmatrix_rgbmatrix_get_height(self);
common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
common_hal_rgbmatrix_rgbmatrix_construct1(self, framebuffer);
}
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self, mp_obj_t framebuffer) {
self->paused = 1;
common_hal_rgbmatrix_timer_disable(self->timer);
if (framebuffer) {
self->framebuffer = framebuffer;
STATIC void common_hal_rgbmatrix_rgbmatrix_construct1(rgbmatrix_rgbmatrix_obj_t *self, mp_obj_t framebuffer) {
if (framebuffer != mp_const_none) {
mp_get_buffer_raise(self->framebuffer, &self->bufinfo, MP_BUFFER_READ);
if (mp_get_buffer(self->framebuffer, &self->bufinfo, MP_BUFFER_RW)) {
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
@ -82,16 +80,11 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self,
// verify that the matrix is big enough
mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize - 1), false);
} else {
common_hal_rgbmatrix_free_impl(self->bufinfo.buf);
common_hal_rgbmatrix_free_impl(self->protomatter.rgbPins);
common_hal_rgbmatrix_free_impl(self->protomatter.addr);
common_hal_rgbmatrix_free_impl(self->protomatter.screenData);
self->framebuffer = NULL;
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
self->bufinfo.len = self->bufsize;
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
}
self->framebuffer = framebuffer;
memset(&self->protomatter, 0, sizeof(self->protomatter));
ProtomatterStatus stat = _PM_init(&self->protomatter,
@ -115,6 +108,9 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self,
if (stat != PROTOMATTER_OK) {
common_hal_rgbmatrix_rgbmatrix_deinit(self);
if (!gc_alloc_possible()) {
return;
}
switch (stat) {
case PROTOMATTER_ERR_PINS:
raise_ValueError_invalid_pin();
@ -148,35 +144,65 @@ STATIC void free_pin_seq(uint8_t *seq, int count) {
}
}
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t *self) {
if (self->timer) {
common_hal_rgbmatrix_timer_free(self->timer);
self->timer = 0;
}
extern int pm_row_count;
STATIC void common_hal_rgbmatrix_rgbmatrix_deinit1(rgbmatrix_rgbmatrix_obj_t *self) {
common_hal_rgbmatrix_timer_disable(self->timer);
if (_PM_protoPtr == &self->protomatter) {
_PM_protoPtr = NULL;
}
if (self->protomatter.rgbPins) {
_PM_deallocate(&self->protomatter);
}
memset(&self->protomatter, 0, sizeof(self->protomatter));
// If it was supervisor-allocated, it is supervisor-freed and the pointer
// is zeroed, otherwise the pointer is just zeroed
if (self->bufinfo.buf) {
common_hal_rgbmatrix_free_impl(self->bufinfo.buf);
self->bufinfo.buf = NULL;
}
// If a framebuffer was passed in to the constructor, clear the reference
// here so that it will become GC'able
self->framebuffer = mp_const_none;
}
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t *self) {
common_hal_rgbmatrix_rgbmatrix_deinit1(self);
if (self->timer) {
common_hal_rgbmatrix_timer_free(self->timer);
self->timer = 0;
}
free_pin_seq(self->rgb_pins, self->rgb_count);
free_pin_seq(self->addr_pins, self->addr_count);
free_pin(&self->clock_pin);
free_pin(&self->latch_pin);
free_pin(&self->oe_pin);
if (self->protomatter.rgbPins) {
_PM_deallocate(&self->protomatter);
self->base.type = &mp_type_NoneType;
}
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self) {
if (self->framebuffer != mp_const_none) {
memset(&self->bufinfo, 0, sizeof(self->bufinfo));
}
memset(&self->protomatter, 0, sizeof(self->protomatter));
// If it was supervisor-allocated, it is supervisor-freed and the pointer
// is zeroed, otherwise the pointer is just zeroed
_PM_free(self->bufinfo.buf);
self->base.type = NULL;
// If a framebuffer was passed in to the constructor, NULL the reference
// here so that it will become GC'able
self->framebuffer = NULL;
#if CIRCUITPY_RGBMATRIX_USES_SUPERVISOR_ALLOCATION
common_hal_rgbmatrix_rgbmatrix_set_paused(self, true);
common_hal_rgbmatrix_rgbmatrix_deinit1(self);
common_hal_rgbmatrix_rgbmatrix_construct1(self, mp_const_none);
#endif
if (self->bufinfo.buf == NULL) {
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
self->bufinfo.len = self->bufsize;
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
}
memset(self->bufinfo.buf, 0, self->bufinfo.len);
common_hal_rgbmatrix_rgbmatrix_set_paused(self, false);
}
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t *self) {

View File

@ -31,7 +31,15 @@
#include "py/misc.h"
#include "supervisor/memory.h"
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32S2)
// Use DMA-capable RAM (not PSRAM) for framebuffer:
#include "components/heap/include/esp_heap_caps.h"
#define _PM_allocate(x) heap_caps_malloc(x, MALLOC_CAP_DMA | MALLOC_CAP_8BIT)
#define _PM_free(x) heap_caps_free(x)
#else
#define _PM_allocate common_hal_rgbmatrix_allocator_impl
#define _PM_free(x) (common_hal_rgbmatrix_free_impl((x)), (x) = NULL, (void)0)
#endif
extern void *common_hal_rgbmatrix_allocator_impl(size_t sz);
extern void common_hal_rgbmatrix_free_impl(void *);

View File

@ -191,7 +191,7 @@ void supervisor_display_move_memory(void) {
#if CIRCUITPY_RGBMATRIX
if (display_buses[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) {
rgbmatrix_rgbmatrix_obj_t *pm = &display_buses[i].rgbmatrix;
common_hal_rgbmatrix_rgbmatrix_reconstruct(pm, NULL);
common_hal_rgbmatrix_rgbmatrix_reconstruct(pm);
}
#endif
#if CIRCUITPY_SHARPDISPLAY