Skip to content

Commit f460845

Browse files
committed
First test of support for dual hub75s
1 parent e1e456d commit f460845

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

drivers/hub75/hub75.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,28 @@
88

99
namespace pimoroni {
1010

11-
Hub75::Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order)
12-
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb), color_order(color_order)
11+
Hub75::Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order, bool duo)
12+
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb), color_order(color_order), duo_mode(duo)
1313
{
14+
if(duo) {
15+
pin_r0 += 32;
16+
pin_g0 += 32;
17+
pin_b0 += 32;
18+
pin_r1 += 32;
19+
pin_g1 += 32;
20+
pin_b1 += 32;
21+
pin_row_a += 32;
22+
pin_row_b += 32;
23+
pin_row_c += 32;
24+
pin_row_d += 32;
25+
pin_row_e += 32;
26+
pin_clk += 32;
27+
pin_stb += 32;
28+
pin_oe += 32;
29+
pio = pio1;
30+
pio_set_gpio_base(pio, 16);
31+
}
32+
1433
// Set up allllll the GPIO
1534
gpio_init(pin_r0); gpio_set_function(pin_r0, GPIO_FUNC_SIO); gpio_set_dir(pin_r0, true); gpio_put(pin_r0, 0);
1635
gpio_init(pin_g0); gpio_set_function(pin_g0, GPIO_FUNC_SIO); gpio_set_dir(pin_g0, true); gpio_put(pin_g0, 0);
@@ -159,8 +178,15 @@ void Hub75::start(irq_handler_t handler) {
159178
} else {
160179
row_prog_offs = pio_add_program(pio, &hub75_row_program);
161180
}
162-
hub75_data_rgb888_program_init(pio, sm_data, data_prog_offs, DATA_BASE_PIN, pin_clk);
163-
hub75_row_program_init(pio, sm_row, row_prog_offs, ROWSEL_BASE_PIN, ROWSEL_N_PINS, pin_stb, latch_cycles);
181+
182+
if(duo_mode) {
183+
hub75_data_rgb888_program_init(pio, sm_data, data_prog_offs, DUO_DATA_BASE_PIN, pin_clk);
184+
hub75_row_program_init(pio, sm_row, row_prog_offs, DUO_ROWSEL_BASE_PIN, ROWSEL_N_PINS, pin_stb, latch_cycles);
185+
}
186+
else {
187+
hub75_data_rgb888_program_init(pio, sm_data, data_prog_offs, DATA_BASE_PIN, pin_clk);
188+
hub75_row_program_init(pio, sm_row, row_prog_offs, ROWSEL_BASE_PIN, ROWSEL_N_PINS, pin_stb, latch_cycles);
189+
}
164190

165191
// Prevent flicker in Python caused by the smaller dataset just blasting through the PIO too quickly
166192
pio_sm_set_clkdiv(pio, sm_data, width <= 32 ? 2.0f : 1.0f);

drivers/hub75/hub75.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const uint ROWSEL_BASE_PIN = 6;
1717
const uint ROWSEL_N_PINS = 5;
1818
const uint BIT_DEPTH = 10;
1919

20+
const uint DUO_DATA_BASE_PIN = DATA_BASE_PIN + 32;
21+
const uint DUO_ROWSEL_BASE_PIN = ROWSEL_BASE_PIN + 32;
22+
2023
/*
2124
10-bit gamma table, allowing us to gamma correct our 8-bit colour values up
2225
to 10-bit without losing dynamic range.
@@ -86,6 +89,7 @@ class Hub75 {
8689
PanelType panel_type;
8790
bool inverted_stb = false;
8891
COLOR_ORDER color_order;
92+
bool duo_mode = false;
8993
Pixel background = 0;
9094

9195
// DMA & PIO
@@ -140,7 +144,7 @@ class Hub75 {
140144
Hub75(uint width, uint height) : Hub75(width, height, nullptr) {};
141145
Hub75(uint width, uint height, Pixel *buffer) : Hub75(width, height, buffer, PANEL_GENERIC) {};
142146
Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type) : Hub75(width, height, buffer, panel_type, false) {};
143-
Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order=COLOR_ORDER::RGB);
147+
Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order=COLOR_ORDER::RGB, bool duo=false);
144148
~Hub75();
145149

146150
void FM6126A_write_register(uint16_t value, uint8_t position);

micropython/modules/hub75/hub75.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
8686
ARG_buffer,
8787
ARG_panel_type,
8888
ARG_stb_invert,
89-
ARG_color_order
89+
ARG_color_order,
90+
ARG_duo
9091
};
9192
static const mp_arg_t allowed_args[] = {
9293
{ MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT },
@@ -95,6 +96,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
9596
{ MP_QSTR_panel_type, MP_ARG_INT, {.u_int = 0} },
9697
{ MP_QSTR_stb_invert, MP_ARG_INT, {.u_int = 0} },
9798
{ MP_QSTR_color_order, MP_ARG_INT, {.u_int = (uint8_t)Hub75::COLOR_ORDER::RGB} },
99+
{ MP_QSTR_duo, MP_ARG_INT, {.u_int = 0} },
98100
};
99101

100102
// Parse args.
@@ -106,6 +108,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
106108
PanelType paneltype = (PanelType)args[ARG_panel_type].u_int;
107109
bool stb_invert = args[ARG_stb_invert].u_int;
108110
Hub75::COLOR_ORDER color_order = (Hub75::COLOR_ORDER)args[ARG_color_order].u_int;
111+
bool duo_mode = args[ARG_duo].u_int;
109112

110113
Pixel *buffer = nullptr;
111114

@@ -122,7 +125,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
122125

123126
hub75_obj = mp_obj_malloc_with_finaliser(_Hub75_obj_t, &Hub75_type);
124127
hub75_obj->buf = buffer;
125-
hub75_obj->hub75 = m_new_class(Hub75, width, height, buffer, paneltype, stb_invert, color_order);
128+
hub75_obj->hub75 = m_new_class(Hub75, width, height, buffer, paneltype, stb_invert, color_order, duo_mode);
126129

127130
return MP_OBJ_FROM_PTR(hub75_obj);
128131
}

0 commit comments

Comments
 (0)