Skip to content

Commit 17a5a85

Browse files
committed
rgbmatrix: Move struct definition to shared-module, rename 'core' member
1 parent 3c08333 commit 17a5a85

File tree

4 files changed

+69
-41
lines changed

4 files changed

+69
-41
lines changed

shared-bindings/rgbmatrix/RGBMatrix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_deinit(mp_obj_t self_in) {
252252
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rgbmatrix_rgbmatrix_deinit_obj, rgbmatrix_rgbmatrix_deinit);
253253

254254
static void check_for_deinit(rgbmatrix_rgbmatrix_obj_t *self) {
255-
if (!self->core.rgbPins) {
255+
if (!self->protomatter.rgbPins) {
256256
raise_deinited_error();
257257
}
258258
}

shared-bindings/rgbmatrix/RGBMatrix.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,12 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_RGBMATRIX_RGBMATRIX_H
28-
#define MICROPY_INCLUDED_SHARED_BINDINGS_RGBMATRIX_RGBMATRIX_H
27+
#pragma once
2928

3029
#include "shared-module/rgbmatrix/RGBMatrix.h"
3130
#include "lib/protomatter/core.h"
3231

3332
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
34-
typedef struct {
35-
mp_obj_base_t base;
36-
mp_obj_t framebuffer;
37-
mp_buffer_info_t bufinfo;
38-
Protomatter_core core;
39-
void *timer;
40-
uint16_t bufsize, width;
41-
uint8_t rgb_pins[30];
42-
uint8_t addr_pins[10];
43-
uint8_t clock_pin, latch_pin, oe_pin;
44-
uint8_t rgb_count, addr_count;
45-
uint8_t bit_depth;
46-
bool core_is_initialized;
47-
bool paused;
48-
bool doublebuffer;
49-
} rgbmatrix_rgbmatrix_obj_t;
5033

5134
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);
5235
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);
5740
void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t* self);
5841
int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self);
5942
int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self);
60-
61-
#endif

shared-module/rgbmatrix/RGBMatrix.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,36 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
7979
mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize-1), false);
8080
} else {
8181
_PM_FREE(self->bufinfo.buf);
82-
_PM_FREE(self->core.rgbPins);
83-
_PM_FREE(self->core.addr);
84-
_PM_FREE(self->core.screenData);
82+
_PM_FREE(self->protomatter.rgbPins);
83+
_PM_FREE(self->protomatter.addr);
84+
_PM_FREE(self->protomatter.screenData);
8585

8686
self->framebuffer = NULL;
8787
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
8888
self->bufinfo.len = self->bufsize;
8989
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
9090
}
9191

92-
memset(&self->core, 0, sizeof(self->core));
93-
ProtomatterStatus stat = _PM_init(&self->core,
92+
memset(&self->protomatter, 0, sizeof(self->protomatter));
93+
ProtomatterStatus stat = _PM_init(&self->protomatter,
9494
self->width, self->bit_depth,
9595
self->rgb_count/6, self->rgb_pins,
9696
self->addr_count, self->addr_pins,
9797
self->clock_pin, self->latch_pin, self->oe_pin,
9898
self->doublebuffer, self->timer);
9999

100100
if (stat == PROTOMATTER_OK) {
101-
_PM_protoPtr = &self->core;
101+
_PM_protoPtr = &self->protomatter;
102102
common_hal_mcu_disable_interrupts();
103103
common_hal_rgbmatrix_timer_enable(self->timer);
104-
stat = _PM_begin(&self->core);
104+
stat = _PM_begin(&self->protomatter);
105105

106106
if (stat == PROTOMATTER_OK) {
107-
_PM_convert_565(&self->core, self->bufinfo.buf, self->width);
107+
_PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
108108
}
109109
common_hal_mcu_enable_interrupts();
110110
if (stat == PROTOMATTER_OK) {
111-
_PM_swapbuffer_maybe(&self->core);
111+
_PM_swapbuffer_maybe(&self->protomatter);
112112
}
113113
}
114114

@@ -153,7 +153,7 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
153153
self->timer = 0;
154154
}
155155

156-
if (_PM_protoPtr == &self->core) {
156+
if (_PM_protoPtr == &self->protomatter) {
157157
_PM_protoPtr = NULL;
158158
}
159159

@@ -163,10 +163,10 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
163163
free_pin(&self->latch_pin);
164164
free_pin(&self->oe_pin);
165165

166-
if (self->core.rgbPins) {
167-
_PM_free(&self->core);
166+
if (self->protomatter.rgbPins) {
167+
_PM_free(&self->protomatter);
168168
}
169-
memset(&self->core, 0, sizeof(self->core));
169+
memset(&self->protomatter, 0, sizeof(self->protomatter));
170170

171171
// If it was supervisor-allocated, it is supervisor-freed and the pointer
172172
// is zeroed, otherwise the pointer is just zeroed
@@ -180,16 +180,16 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
180180

181181
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t* self) {
182182
gc_collect_ptr(self->framebuffer);
183-
gc_collect_ptr(self->core.rgbPins);
184-
gc_collect_ptr(self->core.addr);
185-
gc_collect_ptr(self->core.screenData);
183+
gc_collect_ptr(self->protomatter.rgbPins);
184+
gc_collect_ptr(self->protomatter.addr);
185+
gc_collect_ptr(self->protomatter.screenData);
186186
}
187187

188188
void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
189189
if (paused && !self->paused) {
190-
_PM_stop(&self->core);
190+
_PM_stop(&self->protomatter);
191191
} else if (!paused && self->paused) {
192-
_PM_resume(&self->core);
192+
_PM_resume(&self->protomatter);
193193
}
194194
self->paused = paused;
195195
}
@@ -199,8 +199,8 @@ bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t* self)
199199
}
200200

201201
void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t* self) {
202-
_PM_convert_565(&self->core, self->bufinfo.buf, self->width);
203-
_PM_swapbuffer_maybe(&self->core);
202+
_PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
203+
_PM_swapbuffer_maybe(&self->protomatter);
204204
}
205205

206206
int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {

shared-module/rgbmatrix/RGBMatrix.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#pragma once
28+
29+
#include "lib/protomatter/core.h"
30+
31+
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;
32+
typedef struct {
33+
mp_obj_base_t base;
34+
mp_obj_t framebuffer;
35+
mp_buffer_info_t bufinfo;
36+
Protomatter_core protomatter;
37+
void *timer;
38+
uint16_t bufsize, width;
39+
uint8_t rgb_pins[30];
40+
uint8_t addr_pins[10];
41+
uint8_t clock_pin, latch_pin, oe_pin;
42+
uint8_t rgb_count, addr_count;
43+
uint8_t bit_depth;
44+
bool core_is_initialized;
45+
bool paused;
46+
bool doublebuffer;
47+
} rgbmatrix_rgbmatrix_obj_t;

0 commit comments

Comments
 (0)