summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-04-21 17:47:51 -0400
committerDan Halbert <halbert@halwitz.org>2020-04-21 17:47:51 -0400
commit77cd93ac2d8ebce240055caf81f1b6bdd7c9bfcc (patch)
tree3425ef969688971abedb3095e73e2e56b2da66b5 /shared-module
parent38ec3bc57476c6fde45cd7d722370a5408fd8e10 (diff)
parent51dbe9109fb6a474fe7f4cf4e3766e27ba0b34b5 (diff)
merge from adafruit
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/displayio/__init__.c24
-rw-r--r--shared-module/displayio/__init__.h6
-rw-r--r--shared-module/framebufferio/FramebufferDisplay.c32
-rw-r--r--shared-module/framebufferio/FramebufferDisplay.h11
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.c (renamed from shared-module/_protomatter/Protomatter.c)41
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.h (renamed from shared-module/_protomatter/Protomatter.h)0
-rw-r--r--shared-module/rgbmatrix/__init__.c (renamed from shared-module/_protomatter/__init__.c)0
-rw-r--r--shared-module/rgbmatrix/__init__.h (renamed from shared-module/_protomatter/__init__.h)0
-rw-r--r--shared-module/rgbmatrix/allocator.h (renamed from shared-module/_protomatter/allocator.h)4
9 files changed, 76 insertions, 42 deletions
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index cf1bc45d9..c898bbb98 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -21,8 +21,8 @@
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
-#if CIRCUITPY_PROTOMATTER
-STATIC bool any_display_uses_this_protomatter(protomatter_protomatter_obj_t* pm) {
+#if CIRCUITPY_RGBMATRIX
+STATIC bool any_display_uses_this_rgbmatrix(rgbmatrix_rgbmatrix_obj_t* pm) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
framebufferio_framebufferdisplay_obj_t* display = &displays[i].framebuffer_display;
@@ -103,8 +103,8 @@ void common_hal_displayio_release_displays(void) {
} else if (bus_type == &displayio_parallelbus_type) {
common_hal_displayio_parallelbus_deinit(&displays[i].parallel_bus);
#if CIRCUITPY_FRAMEBUFFERIO
- } else if (bus_type == &protomatter_Protomatter_type) {
- common_hal_protomatter_protomatter_deinit(&displays[i].protomatter);
+ } else if (bus_type == &rgbmatrix_RGBMatrix_type) {
+ common_hal_rgbmatrix_rgbmatrix_deinit(&displays[i].rgbmatrix);
#endif
}
displays[i].fourwire_bus.base.type = &mp_type_NoneType;
@@ -167,11 +167,11 @@ void reset_displays(void) {
}
}
}
-#if CIRCUITPY_PROTOMATTER
- } else if (displays[i].protomatter.base.type == &protomatter_Protomatter_type) {
- protomatter_protomatter_obj_t * pm = &displays[i].protomatter;
- if(!any_display_uses_this_protomatter(pm)) {
- common_hal_protomatter_protomatter_deinit(pm);
+#if CIRCUITPY_RGBMATRIX
+ } else if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) {
+ rgbmatrix_rgbmatrix_obj_t * pm = &displays[i].rgbmatrix;
+ if(!any_display_uses_this_rgbmatrix(pm)) {
+ common_hal_rgbmatrix_rgbmatrix_deinit(pm);
}
#endif
} else {
@@ -200,9 +200,9 @@ void reset_displays(void) {
void displayio_gc_collect(void) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
-#if CIRCUITPY_PROTOMATTER
- if (displays[i].protomatter.base.type == &protomatter_Protomatter_type) {
- protomatter_protomatter_collect_ptrs(&displays[i].protomatter);
+#if CIRCUITPY_RGBMATRIX
+ if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) {
+ rgbmatrix_rgbmatrix_collect_ptrs(&displays[i].rgbmatrix);
}
#endif
diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h
index 278a5e78f..9eb10c28b 100644
--- a/shared-module/displayio/__init__.h
+++ b/shared-module/displayio/__init__.h
@@ -36,15 +36,15 @@
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/displayio/I2CDisplay.h"
#include "shared-bindings/displayio/ParallelBus.h"
-#include "shared-bindings/_protomatter/Protomatter.h"
+#include "shared-bindings/rgbmatrix/RGBMatrix.h"
typedef struct {
union {
displayio_fourwire_obj_t fourwire_bus;
displayio_i2cdisplay_obj_t i2cdisplay_bus;
displayio_parallelbus_obj_t parallel_bus;
-#if CIRCUITPY_PROTOMATTER
- protomatter_protomatter_obj_t protomatter;
+#if CIRCUITPY_RGBMATRIX
+ rgbmatrix_rgbmatrix_obj_t rgbmatrix;
#endif
};
union {
diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c
index bd0764e8e..13fbb2629 100644
--- a/shared-module/framebufferio/FramebufferDisplay.c
+++ b/shared-module/framebufferio/FramebufferDisplay.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
+ * 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
@@ -42,10 +43,9 @@
#include "tick.h"
void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
- mp_obj_t framebuffer, uint16_t width, uint16_t height,
- uint16_t rotation, uint16_t color_depth,
- uint8_t bytes_per_cell,
- bool auto_refresh, uint16_t native_frames_per_second) {
+ mp_obj_t framebuffer,
+ uint16_t rotation,
+ bool auto_refresh) {
// Turn off auto-refresh as we init.
self->auto_refresh = false;
self->framebuffer = framebuffer;
@@ -54,15 +54,29 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
uint16_t ram_width = 0x100;
uint16_t ram_height = 0x100;
- displayio_display_core_construct(&self->core, NULL, width, height, ram_width, ram_height, 0, 0, rotation,
- color_depth, false, false, bytes_per_cell, false, false);
+ displayio_display_core_construct(
+ &self->core,
+ NULL,
+ self->framebuffer_protocol->get_width(self->framebuffer),
+ self->framebuffer_protocol->get_height(self->framebuffer),
+ ram_width,
+ ram_height,
+ 0,
+ 0,
+ rotation,
+ self->framebuffer_protocol->get_color_depth(self->framebuffer),
+ false,
+ false,
+ self->framebuffer_protocol->get_bytes_per_cell(self->framebuffer),
+ false,
+ false);
self->first_manual_refresh = !auto_refresh;
- self->native_frames_per_second = native_frames_per_second;
- self->native_ms_per_frame = 1000 / native_frames_per_second;
+ self->native_frames_per_second = self->framebuffer_protocol->get_native_frames_per_second(self->framebuffer);
+ self->native_ms_per_frame = 1000 / self->native_frames_per_second;
- supervisor_start_terminal(width, height);
+ supervisor_start_terminal(self->core.width, self->core.height);
// Set the group after initialization otherwise we may send pixels while we delay in
// initialization.
diff --git a/shared-module/framebufferio/FramebufferDisplay.h b/shared-module/framebufferio/FramebufferDisplay.h
index a7b91a522..1b68d2ab0 100644
--- a/shared-module/framebufferio/FramebufferDisplay.h
+++ b/shared-module/framebufferio/FramebufferDisplay.h
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
+ * 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
@@ -66,12 +67,22 @@ typedef bool (*framebuffer_set_brightness_fun)(mp_obj_t, mp_float_t);
typedef mp_float_t (*framebuffer_get_brightness_fun)(mp_obj_t);
typedef bool (*framebuffer_set_auto_brightness_fun)(mp_obj_t, bool);
typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t);
+typedef int (*framebuffer_get_width_fun)(mp_obj_t);
+typedef int (*framebuffer_get_height_fun)(mp_obj_t);
+typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t);
+typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t);
+typedef int (*framebuffer_get_native_frames_per_second_fun)(mp_obj_t);
typedef struct _framebuffer_p_t {
MP_PROTOCOL_HEAD // MP_QSTR_protocol_framebuffer
framebuffer_get_bufinfo_fun get_bufinfo;
framebuffer_swapbuffers_fun swapbuffers;
framebuffer_deinit_fun deinit;
+ framebuffer_get_width_fun get_width;
+ framebuffer_get_height_fun get_height;
+ framebuffer_get_color_depth_fun get_color_depth;
+ framebuffer_get_bytes_per_cell_fun get_bytes_per_cell;
+ framebuffer_get_native_frames_per_second_fun get_native_frames_per_second;
framebuffer_get_brightness_fun get_brightness;
framebuffer_set_brightness_fun set_brightness;
framebuffer_get_auto_brightness_fun get_auto_brightness;
diff --git a/shared-module/_protomatter/Protomatter.c b/shared-module/rgbmatrix/RGBMatrix.c
index 77ca63476..df064ff81 100644
--- a/shared-module/_protomatter/Protomatter.c
+++ b/shared-module/rgbmatrix/RGBMatrix.c
@@ -32,9 +32,9 @@
#include "py/objproperty.h"
#include "py/runtime.h"
-#include "common-hal/_protomatter/Protomatter.h"
-#include "shared-module/_protomatter/allocator.h"
-#include "shared-bindings/_protomatter/Protomatter.h"
+#include "common-hal/rgbmatrix/RGBMatrix.h"
+#include "shared-module/rgbmatrix/allocator.h"
+#include "shared-bindings/rgbmatrix/RGBMatrix.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/util.h"
@@ -42,7 +42,7 @@
extern Protomatter_core *_PM_protoPtr;
-void common_hal_protomatter_protomatter_construct(protomatter_protomatter_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) {
self->width = width;
self->bit_depth = bit_depth;
self->rgb_count = rgb_count;
@@ -54,7 +54,7 @@ void common_hal_protomatter_protomatter_construct(protomatter_protomatter_obj_t
self->latch_pin = latch_pin;
self->doublebuffer = doublebuffer;
- self->timer = timer ? timer : common_hal_protomatter_timer_allocate();
+ self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate();
if (self->timer == NULL) {
mp_raise_ValueError(translate("No timer available"));
}
@@ -62,10 +62,10 @@ void common_hal_protomatter_protomatter_construct(protomatter_protomatter_obj_t
self->width = width;
self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
- common_hal_protomatter_protomatter_reconstruct(self, framebuffer);
+ common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
}
-void common_hal_protomatter_protomatter_reconstruct(protomatter_protomatter_obj_t* self, mp_obj_t framebuffer) {
+void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self, mp_obj_t framebuffer) {
if (framebuffer) {
self->framebuffer = framebuffer;
framebuffer = mp_obj_new_bytearray_of_zeros(self->bufsize);
@@ -99,7 +99,7 @@ void common_hal_protomatter_protomatter_reconstruct(protomatter_protomatter_obj_
if (stat == PROTOMATTER_OK) {
_PM_protoPtr = &self->core;
common_hal_mcu_disable_interrupts();
- common_hal_protomatter_timer_enable(self->timer);
+ common_hal_rgbmatrix_timer_enable(self->timer);
stat = _PM_begin(&self->core);
_PM_convert_565(&self->core, self->bufinfo.buf, self->width);
common_hal_mcu_enable_interrupts();
@@ -109,7 +109,7 @@ void common_hal_protomatter_protomatter_reconstruct(protomatter_protomatter_obj_
if (stat != PROTOMATTER_OK) {
// XXX this deinit() actually makes crashy-crashy
// can trigger it by sending inappropriate pins
- common_hal_protomatter_protomatter_deinit(self);
+ common_hal_rgbmatrix_rgbmatrix_deinit(self);
switch (stat) {
case PROTOMATTER_ERR_PINS:
mp_raise_ValueError(translate("Invalid pin"));
@@ -120,7 +120,7 @@ void common_hal_protomatter_protomatter_reconstruct(protomatter_protomatter_obj_
case PROTOMATTER_ERR_MALLOC: /// should have already been signaled as NLR
default:
mp_raise_msg_varg(&mp_type_RuntimeError,
- translate("Protomatter internal error #%d"), (int)stat);
+ translate("Internal error #%d"), (int)stat);
break;
}
}
@@ -142,9 +142,9 @@ STATIC void free_pin_seq(uint8_t *seq, int count) {
}
}
-void common_hal_protomatter_protomatter_deinit(protomatter_protomatter_obj_t* self) {
+void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
if (self->timer) {
- common_hal_protomatter_timer_free(self->timer);
+ common_hal_rgbmatrix_timer_free(self->timer);
self->timer = 0;
}
@@ -173,14 +173,14 @@ void common_hal_protomatter_protomatter_deinit(protomatter_protomatter_obj_t* se
self->framebuffer = NULL;
}
-void protomatter_protomatter_collect_ptrs(protomatter_protomatter_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);
}
-void common_hal_protomatter_protomatter_set_paused(protomatter_protomatter_obj_t* self, bool paused) {
+void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
if (paused && !self->paused) {
_PM_stop(&self->core);
} else if (!paused && self->paused) {
@@ -189,12 +189,21 @@ void common_hal_protomatter_protomatter_set_paused(protomatter_protomatter_obj_t
self->paused = paused;
}
-bool common_hal_protomatter_protomatter_get_paused(protomatter_protomatter_obj_t* self) {
+bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t* self) {
return self->paused;
}
-void common_hal_protomatter_protomatter_refresh(protomatter_protomatter_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);
}
+int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
+ return self->width;
+}
+
+int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
+ int computed_height = (self->rgb_count / 3) << (self->addr_count);
+ return computed_height;
+}
+
diff --git a/shared-module/_protomatter/Protomatter.h b/shared-module/rgbmatrix/RGBMatrix.h
index e69de29bb..e69de29bb 100644
--- a/shared-module/_protomatter/Protomatter.h
+++ b/shared-module/rgbmatrix/RGBMatrix.h
diff --git a/shared-module/_protomatter/__init__.c b/shared-module/rgbmatrix/__init__.c
index e69de29bb..e69de29bb 100644
--- a/shared-module/_protomatter/__init__.c
+++ b/shared-module/rgbmatrix/__init__.c
diff --git a/shared-module/_protomatter/__init__.h b/shared-module/rgbmatrix/__init__.h
index e69de29bb..e69de29bb 100644
--- a/shared-module/_protomatter/__init__.h
+++ b/shared-module/rgbmatrix/__init__.h
diff --git a/shared-module/_protomatter/allocator.h b/shared-module/rgbmatrix/allocator.h
index b7f517ce5..5e6f0b41d 100644
--- a/shared-module/_protomatter/allocator.h
+++ b/shared-module/rgbmatrix/allocator.h
@@ -1,5 +1,5 @@
-#ifndef MICROPY_INCLUDED_SHARED_MODULE_PROTOMATTER_ALLOCATOR_H
-#define MICROPY_INCLUDED_SHARED_MODULE_PROTOMATTER_ALLOCATOR_H
+#ifndef MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
+#define MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
#include <stdbool.h>
#include "py/gc.h"