summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.c40
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.h47
2 files changed, 67 insertions, 20 deletions
diff --git a/shared-module/rgbmatrix/RGBMatrix.c b/shared-module/rgbmatrix/RGBMatrix.c
index c39ec99a2..3007ca4db 100644
--- a/shared-module/rgbmatrix/RGBMatrix.c
+++ b/shared-module/rgbmatrix/RGBMatrix.c
@@ -79,9 +79,9 @@ 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);
} else {
_PM_FREE(self->bufinfo.buf);
- _PM_FREE(self->core.rgbPins);
- _PM_FREE(self->core.addr);
- _PM_FREE(self->core.screenData);
+ _PM_FREE(self->protomatter.rgbPins);
+ _PM_FREE(self->protomatter.addr);
+ _PM_FREE(self->protomatter.screenData);
self->framebuffer = NULL;
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
@@ -89,8 +89,8 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
}
- memset(&self->core, 0, sizeof(self->core));
- 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->rgb_count/6, self->rgb_pins,
self->addr_count, self->addr_pins,
@@ -98,17 +98,17 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
self->doublebuffer, self->timer);
if (stat == PROTOMATTER_OK) {
- _PM_protoPtr = &self->core;
+ _PM_protoPtr = &self->protomatter;
common_hal_mcu_disable_interrupts();
common_hal_rgbmatrix_timer_enable(self->timer);
- stat = _PM_begin(&self->core);
+ stat = _PM_begin(&self->protomatter);
if (stat == PROTOMATTER_OK) {
- _PM_convert_565(&self->core, self->bufinfo.buf, self->width);
+ _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
}
common_hal_mcu_enable_interrupts();
if (stat == PROTOMATTER_OK) {
- _PM_swapbuffer_maybe(&self->core);
+ _PM_swapbuffer_maybe(&self->protomatter);
}
}
@@ -153,7 +153,7 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
self->timer = 0;
}
- if (_PM_protoPtr == &self->core) {
+ if (_PM_protoPtr == &self->protomatter) {
_PM_protoPtr = NULL;
}
@@ -163,10 +163,10 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
free_pin(&self->latch_pin);
free_pin(&self->oe_pin);
- if (self->core.rgbPins) {
- _PM_free(&self->core);
+ if (self->protomatter.rgbPins) {
+ _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
// is zeroed, otherwise the pointer is just zeroed
@@ -180,16 +180,16 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t* self) {
gc_collect_ptr(self->framebuffer);
- gc_collect_ptr(self->core.rgbPins);
- gc_collect_ptr(self->core.addr);
- gc_collect_ptr(self->core.screenData);
+ gc_collect_ptr(self->protomatter.rgbPins);
+ gc_collect_ptr(self->protomatter.addr);
+ gc_collect_ptr(self->protomatter.screenData);
}
void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
if (paused && !self->paused) {
- _PM_stop(&self->core);
+ _PM_stop(&self->protomatter);
} else if (!paused && self->paused) {
- _PM_resume(&self->core);
+ _PM_resume(&self->protomatter);
}
self->paused = paused;
}
@@ -199,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) {
- _PM_convert_565(&self->core, self->bufinfo.buf, self->width);
- _PM_swapbuffer_maybe(&self->core);
+ _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
+ _PM_swapbuffer_maybe(&self->protomatter);
}
int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
diff --git a/shared-module/rgbmatrix/RGBMatrix.h b/shared-module/rgbmatrix/RGBMatrix.h
index e69de29bb..19d7d5f2e 100644
--- a/shared-module/rgbmatrix/RGBMatrix.h
+++ b/shared-module/rgbmatrix/RGBMatrix.h
@@ -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;