Merge pull request #3344 from jepler/issue-3184
Fix RGBMatrix, FrameBufferDisplay bugs
This commit is contained in:
commit
786f4ed114
@ -1 +1 @@
|
|||||||
Subproject commit 761d6437e8cd6a131d51de96974337121a9c7164
|
Subproject commit 2a1ba8fa4753b2bcb158c9b17351cf18eade0d2b
|
@ -107,7 +107,7 @@ CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk
|
# option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk
|
||||||
CFLAGS += $(OPTIMIZATION_FLAGS) -DNDEBUG
|
CFLAGS += $(OPTIMIZATION_FLAGS)
|
||||||
|
|
||||||
$(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
|
$(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
|
||||||
#Debugging/Optimization
|
#Debugging/Optimization
|
||||||
@ -121,6 +121,7 @@ ifeq ($(DEBUG), 1)
|
|||||||
CFLAGS += -DENABLE_MICRO_TRACE_BUFFER
|
CFLAGS += -DENABLE_MICRO_TRACE_BUFFER
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
|
CFLAGS += -DNDEBUG
|
||||||
# -finline-limit can shrink the image size.
|
# -finline-limit can shrink the image size.
|
||||||
# -finline-limit=80 or so is similar to not having it on.
|
# -finline-limit=80 or so is similar to not having it on.
|
||||||
# There is no simple default value, though.
|
# There is no simple default value, though.
|
||||||
@ -257,6 +258,8 @@ SRC_ASF += \
|
|||||||
$(BUILD)/asf4/$(CHIP_FAMILY)/hpl/sdhc/hpl_sdhc.o: CFLAGS += -Wno-cast-align
|
$(BUILD)/asf4/$(CHIP_FAMILY)/hpl/sdhc/hpl_sdhc.o: CFLAGS += -Wno-cast-align
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
$(BUILD)/asf4/$(CHIP_FAMILY)/hpl/sercom/hpl_sercom.o: CFLAGS += -Wno-maybe-uninitialized
|
||||||
|
|
||||||
SRC_ASF := $(addprefix asf4/$(CHIP_FAMILY)/, $(SRC_ASF))
|
SRC_ASF := $(addprefix asf4/$(CHIP_FAMILY)/, $(SRC_ASF))
|
||||||
|
|
||||||
SRC_C += \
|
SRC_C += \
|
||||||
|
@ -252,7 +252,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_deinit(mp_obj_t self_in) {
|
|||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rgbmatrix_rgbmatrix_deinit_obj, rgbmatrix_rgbmatrix_deinit);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rgbmatrix_rgbmatrix_deinit_obj, rgbmatrix_rgbmatrix_deinit);
|
||||||
|
|
||||||
static void check_for_deinit(rgbmatrix_rgbmatrix_obj_t *self) {
|
static void check_for_deinit(rgbmatrix_rgbmatrix_obj_t *self) {
|
||||||
if (!self->core.rgbPins) {
|
if (!self->protomatter.rgbPins) {
|
||||||
raise_deinited_error();
|
raise_deinited_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,29 +24,12 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_RGBMATRIX_RGBMATRIX_H
|
#pragma once
|
||||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_RGBMATRIX_RGBMATRIX_H
|
|
||||||
|
|
||||||
#include "shared-module/rgbmatrix/RGBMatrix.h"
|
#include "shared-module/rgbmatrix/RGBMatrix.h"
|
||||||
#include "lib/protomatter/core.h"
|
#include "lib/protomatter/core.h"
|
||||||
|
|
||||||
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
|
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
|
||||||
typedef struct {
|
|
||||||
mp_obj_base_t base;
|
|
||||||
mp_obj_t framebuffer;
|
|
||||||
mp_buffer_info_t bufinfo;
|
|
||||||
Protomatter_core core;
|
|
||||||
void *timer;
|
|
||||||
uint16_t bufsize, width;
|
|
||||||
uint8_t rgb_pins[30];
|
|
||||||
uint8_t addr_pins[10];
|
|
||||||
uint8_t clock_pin, latch_pin, oe_pin;
|
|
||||||
uint8_t rgb_count, addr_count;
|
|
||||||
uint8_t bit_depth;
|
|
||||||
bool core_is_initialized;
|
|
||||||
bool paused;
|
|
||||||
bool doublebuffer;
|
|
||||||
} rgbmatrix_rgbmatrix_obj_t;
|
|
||||||
|
|
||||||
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, void* timer);
|
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, void* timer);
|
||||||
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t*);
|
void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t*);
|
||||||
@ -57,5 +40,3 @@ bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t* self);
|
|||||||
void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t* self);
|
void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t* self);
|
||||||
int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self);
|
int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self);
|
||||||
int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self);
|
int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -66,7 +66,7 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
|
|||||||
ram_height,
|
ram_height,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
rotation,
|
0, // rotation
|
||||||
depth,
|
depth,
|
||||||
fb_getter_default(get_grayscale, (depth < 8)),
|
fb_getter_default(get_grayscale, (depth < 8)),
|
||||||
fb_getter_default(get_pixels_in_byte_share_row, false),
|
fb_getter_default(get_pixels_in_byte_share_row, false),
|
||||||
@ -92,6 +92,10 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
|
|||||||
self->native_frames_per_second = fb_getter_default(get_native_frames_per_second, 60);
|
self->native_frames_per_second = fb_getter_default(get_native_frames_per_second, 60);
|
||||||
self->native_ms_per_frame = 1000 / self->native_frames_per_second;
|
self->native_ms_per_frame = 1000 / self->native_frames_per_second;
|
||||||
|
|
||||||
|
if (rotation != 0) {
|
||||||
|
common_hal_framebufferio_framebufferdisplay_set_rotation(self, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
supervisor_start_terminal(self->core.width, self->core.height);
|
supervisor_start_terminal(self->core.width, self->core.height);
|
||||||
|
|
||||||
// Set the group after initialization otherwise we may send pixels while we delay in
|
// Set the group after initialization otherwise we may send pixels while we delay in
|
||||||
|
@ -66,9 +66,9 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, mp_obj_t framebuffer) {
|
||||||
|
common_hal_rgbmatrix_timer_disable(self->timer);
|
||||||
if (framebuffer) {
|
if (framebuffer) {
|
||||||
self->framebuffer = framebuffer;
|
self->framebuffer = framebuffer;
|
||||||
framebuffer = mp_obj_new_bytearray_of_zeros(self->bufsize);
|
|
||||||
mp_get_buffer_raise(self->framebuffer, &self->bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(self->framebuffer, &self->bufinfo, MP_BUFFER_READ);
|
||||||
if (mp_get_buffer(self->framebuffer, &self->bufinfo, MP_BUFFER_RW)) {
|
if (mp_get_buffer(self->framebuffer, &self->bufinfo, MP_BUFFER_RW)) {
|
||||||
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
|
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
|
||||||
@ -79,17 +79,18 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
|
|||||||
mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize-1), false);
|
mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize-1), false);
|
||||||
} else {
|
} else {
|
||||||
_PM_FREE(self->bufinfo.buf);
|
_PM_FREE(self->bufinfo.buf);
|
||||||
_PM_FREE(self->core.rgbPins);
|
_PM_FREE(self->protomatter.rgbPins);
|
||||||
_PM_FREE(self->core.addr);
|
_PM_FREE(self->protomatter.addr);
|
||||||
_PM_FREE(self->core.screenData);
|
_PM_FREE(self->protomatter.screenData);
|
||||||
|
|
||||||
self->framebuffer = NULL;
|
self->framebuffer = NULL;
|
||||||
self->bufinfo.buf = _PM_allocator_impl(self->bufsize);
|
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
|
||||||
self->bufinfo.len = self->bufsize;
|
self->bufinfo.len = self->bufsize;
|
||||||
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
|
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtomatterStatus stat = _PM_init(&self->core,
|
memset(&self->protomatter, 0, sizeof(self->protomatter));
|
||||||
|
ProtomatterStatus stat = _PM_init(&self->protomatter,
|
||||||
self->width, self->bit_depth,
|
self->width, self->bit_depth,
|
||||||
self->rgb_count/6, self->rgb_pins,
|
self->rgb_count/6, self->rgb_pins,
|
||||||
self->addr_count, self->addr_pins,
|
self->addr_count, self->addr_pins,
|
||||||
@ -97,18 +98,21 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
|
|||||||
self->doublebuffer, self->timer);
|
self->doublebuffer, self->timer);
|
||||||
|
|
||||||
if (stat == PROTOMATTER_OK) {
|
if (stat == PROTOMATTER_OK) {
|
||||||
_PM_protoPtr = &self->core;
|
_PM_protoPtr = &self->protomatter;
|
||||||
common_hal_mcu_disable_interrupts();
|
common_hal_mcu_disable_interrupts();
|
||||||
common_hal_rgbmatrix_timer_enable(self->timer);
|
common_hal_rgbmatrix_timer_enable(self->timer);
|
||||||
stat = _PM_begin(&self->core);
|
stat = _PM_begin(&self->protomatter);
|
||||||
_PM_convert_565(&self->core, self->bufinfo.buf, self->width);
|
|
||||||
|
if (stat == PROTOMATTER_OK) {
|
||||||
|
_PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
|
||||||
|
}
|
||||||
common_hal_mcu_enable_interrupts();
|
common_hal_mcu_enable_interrupts();
|
||||||
_PM_swapbuffer_maybe(&self->core);
|
if (stat == PROTOMATTER_OK) {
|
||||||
|
_PM_swapbuffer_maybe(&self->protomatter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat != PROTOMATTER_OK) {
|
if (stat != PROTOMATTER_OK) {
|
||||||
// XXX this deinit() actually makes crashy-crashy
|
|
||||||
// can trigger it by sending inappropriate pins
|
|
||||||
common_hal_rgbmatrix_rgbmatrix_deinit(self);
|
common_hal_rgbmatrix_rgbmatrix_deinit(self);
|
||||||
switch (stat) {
|
switch (stat) {
|
||||||
case PROTOMATTER_ERR_PINS:
|
case PROTOMATTER_ERR_PINS:
|
||||||
@ -117,7 +121,9 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
|
|||||||
case PROTOMATTER_ERR_ARG:
|
case PROTOMATTER_ERR_ARG:
|
||||||
mp_raise_ValueError(translate("Invalid argument"));
|
mp_raise_ValueError(translate("Invalid argument"));
|
||||||
break;
|
break;
|
||||||
case PROTOMATTER_ERR_MALLOC: /// should have already been signaled as NLR
|
case PROTOMATTER_ERR_MALLOC:
|
||||||
|
mp_raise_msg(&mp_type_MemoryError, NULL);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
mp_raise_msg_varg(&mp_type_RuntimeError,
|
mp_raise_msg_varg(&mp_type_RuntimeError,
|
||||||
translate("Internal error #%d"), (int)stat);
|
translate("Internal error #%d"), (int)stat);
|
||||||
@ -126,7 +132,6 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
self->paused = 0;
|
self->paused = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void free_pin(uint8_t *pin) {
|
STATIC void free_pin(uint8_t *pin) {
|
||||||
@ -148,7 +153,7 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
|
|||||||
self->timer = 0;
|
self->timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PM_protoPtr == &self->core) {
|
if (_PM_protoPtr == &self->protomatter) {
|
||||||
_PM_protoPtr = NULL;
|
_PM_protoPtr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,10 +163,10 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
|
|||||||
free_pin(&self->latch_pin);
|
free_pin(&self->latch_pin);
|
||||||
free_pin(&self->oe_pin);
|
free_pin(&self->oe_pin);
|
||||||
|
|
||||||
if (self->core.rgbPins) {
|
if (self->protomatter.rgbPins) {
|
||||||
_PM_free(&self->core);
|
_PM_free(&self->protomatter);
|
||||||
}
|
}
|
||||||
memset(&self->core, 0, sizeof(self->core));
|
memset(&self->protomatter, 0, sizeof(self->protomatter));
|
||||||
|
|
||||||
// If it was supervisor-allocated, it is supervisor-freed and the pointer
|
// If it was supervisor-allocated, it is supervisor-freed and the pointer
|
||||||
// is zeroed, otherwise the pointer is just zeroed
|
// is zeroed, otherwise the pointer is just zeroed
|
||||||
@ -175,16 +180,16 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
|
|||||||
|
|
||||||
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t* self) {
|
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t* self) {
|
||||||
gc_collect_ptr(self->framebuffer);
|
gc_collect_ptr(self->framebuffer);
|
||||||
gc_collect_ptr(self->core.rgbPins);
|
gc_collect_ptr(self->protomatter.rgbPins);
|
||||||
gc_collect_ptr(self->core.addr);
|
gc_collect_ptr(self->protomatter.addr);
|
||||||
gc_collect_ptr(self->core.screenData);
|
gc_collect_ptr(self->protomatter.screenData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
|
void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
|
||||||
if (paused && !self->paused) {
|
if (paused && !self->paused) {
|
||||||
_PM_stop(&self->core);
|
_PM_stop(&self->protomatter);
|
||||||
} else if (!paused && self->paused) {
|
} else if (!paused && self->paused) {
|
||||||
_PM_resume(&self->core);
|
_PM_resume(&self->protomatter);
|
||||||
}
|
}
|
||||||
self->paused = paused;
|
self->paused = paused;
|
||||||
}
|
}
|
||||||
@ -194,8 +199,8 @@ bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t* self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t* self) {
|
void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t* self) {
|
||||||
_PM_convert_565(&self->core, self->bufinfo.buf, self->width);
|
_PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
|
||||||
_PM_swapbuffer_maybe(&self->core);
|
_PM_swapbuffer_maybe(&self->protomatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
|
int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
|
||||||
@ -206,3 +211,20 @@ int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
|
|||||||
int computed_height = (self->rgb_count / 3) << (self->addr_count);
|
int computed_height = (self->rgb_count / 3) << (self->addr_count);
|
||||||
return computed_height;
|
return computed_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *common_hal_rgbmatrix_allocator_impl(size_t sz) {
|
||||||
|
if (gc_alloc_possible()) {
|
||||||
|
return m_malloc_maybe(sz + sizeof(void*), true);
|
||||||
|
} else {
|
||||||
|
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
|
||||||
|
return allocation ? allocation->ptr : NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void common_hal_rgbmatrix_free_impl(void *ptr_in) {
|
||||||
|
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
|
||||||
|
|
||||||
|
if (allocation) {
|
||||||
|
free_memory(allocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Micro Python project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Jeff Epler 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "lib/protomatter/core.h"
|
||||||
|
|
||||||
|
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
|
||||||
|
typedef struct {
|
||||||
|
mp_obj_base_t base;
|
||||||
|
mp_obj_t framebuffer;
|
||||||
|
mp_buffer_info_t bufinfo;
|
||||||
|
Protomatter_core protomatter;
|
||||||
|
void *timer;
|
||||||
|
uint16_t bufsize, width;
|
||||||
|
uint8_t rgb_pins[30];
|
||||||
|
uint8_t addr_pins[10];
|
||||||
|
uint8_t clock_pin, latch_pin, oe_pin;
|
||||||
|
uint8_t rgb_count, addr_count;
|
||||||
|
uint8_t bit_depth;
|
||||||
|
bool core_is_initialized;
|
||||||
|
bool paused;
|
||||||
|
bool doublebuffer;
|
||||||
|
} rgbmatrix_rgbmatrix_obj_t;
|
@ -1,29 +1,37 @@
|
|||||||
#ifndef MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
|
/*
|
||||||
#define MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
|
* This file is part of the Micro Python project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Jeff Epler 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "py/gc.h"
|
#include "py/gc.h"
|
||||||
#include "py/misc.h"
|
#include "py/misc.h"
|
||||||
#include "supervisor/memory.h"
|
#include "supervisor/memory.h"
|
||||||
|
|
||||||
#define _PM_ALLOCATOR _PM_allocator_impl
|
#define _PM_ALLOCATOR common_hal_rgbmatrix_allocator_impl
|
||||||
#define _PM_FREE(x) (_PM_free_impl((x)), (x)=NULL, (void)0)
|
#define _PM_FREE(x) (common_hal_rgbmatrix_free_impl((x)), (x)=NULL, (void)0)
|
||||||
|
extern void *common_hal_rgbmatrix_allocator_impl(size_t sz);
|
||||||
static inline void *_PM_allocator_impl(size_t sz) {
|
extern void common_hal_rgbmatrix_free_impl(void *);
|
||||||
if (gc_alloc_possible()) {
|
|
||||||
return m_malloc(sz + sizeof(void*), true);
|
|
||||||
} else {
|
|
||||||
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
|
|
||||||
return allocation ? allocation->ptr : NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void _PM_free_impl(void *ptr_in) {
|
|
||||||
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
|
|
||||||
|
|
||||||
if (allocation) {
|
|
||||||
free_memory(allocation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -65,10 +65,14 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
|
|||||||
if (width_in_tiles < 80) {
|
if (width_in_tiles < 80) {
|
||||||
scale = 1;
|
scale = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
width_in_tiles = (width_px - blinka_bitmap.width * scale) / (grid->tile_width * scale);
|
width_in_tiles = (width_px - blinka_bitmap.width * scale) / (grid->tile_width * scale);
|
||||||
|
if (width_in_tiles < 1) {
|
||||||
|
width_in_tiles = 1;
|
||||||
|
}
|
||||||
uint16_t height_in_tiles = height_px / (grid->tile_height * scale);
|
uint16_t height_in_tiles = height_px / (grid->tile_height * scale);
|
||||||
uint16_t remaining_pixels = height_px % (grid->tile_height * scale);
|
uint16_t remaining_pixels = height_px % (grid->tile_height * scale);
|
||||||
if (remaining_pixels > 0) {
|
if (height_in_tiles < 1 || remaining_pixels > 0) {
|
||||||
height_in_tiles += 1;
|
height_in_tiles += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +98,8 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
|
|||||||
}
|
}
|
||||||
grid->width_in_tiles = width_in_tiles;
|
grid->width_in_tiles = width_in_tiles;
|
||||||
grid->height_in_tiles = height_in_tiles;
|
grid->height_in_tiles = height_in_tiles;
|
||||||
|
assert(width_in_tiles > 0);
|
||||||
|
assert(height_in_tiles > 0);
|
||||||
grid->pixel_width = width_in_tiles * grid->tile_width;
|
grid->pixel_width = width_in_tiles * grid->tile_width;
|
||||||
grid->pixel_height = height_in_tiles * grid->tile_height;
|
grid->pixel_height = height_in_tiles * grid->tile_height;
|
||||||
grid->tiles = tiles;
|
grid->tiles = tiles;
|
||||||
|
Loading…
Reference in New Issue
Block a user