Skip to content

Commit de8cb95

Browse files
authored
Merge pull request #660 from pimoroni/patch/hub75_color_order
Add support to Interstate / HUB 75 for panels with different color orders
2 parents 5e135b8 + cacfbd1 commit de8cb95

File tree

6 files changed

+70
-11
lines changed

6 files changed

+70
-11
lines changed

drivers/hub75/hub75.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
namespace pimoroni {
88

9-
10-
11-
Hub75::Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb)
12-
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb)
9+
Hub75::Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order)
10+
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb), color_order(color_order)
1311
{
1412
// Set up allllll the GPIO
1513
gpio_init(pin_r0); gpio_set_function(pin_r0, GPIO_FUNC_SIO); gpio_set_dir(pin_r0, true); gpio_put(pin_r0, 0);
@@ -60,7 +58,26 @@ void Hub75::set_color(uint x, uint y, Pixel c) {
6058
}
6159

6260
void Hub75::set_pixel(uint x, uint y, uint8_t r, uint8_t g, uint8_t b) {
63-
set_color(x, y, Pixel(r, g, b));
61+
switch(color_order) {
62+
case COLOR_ORDER::RGB:
63+
set_color(x, y, Pixel(r, g, b));
64+
break;
65+
case COLOR_ORDER::RBG:
66+
set_color(x, y, Pixel(r, b, g));
67+
break;
68+
case COLOR_ORDER::GRB:
69+
set_color(x, y, Pixel(g, r, b));
70+
break;
71+
case COLOR_ORDER::GBR:
72+
set_color(x, y, Pixel(g, b, r));
73+
break;
74+
case COLOR_ORDER::BRG:
75+
set_color(x, y, Pixel(b, r, g));
76+
break;
77+
case COLOR_ORDER::BGR:
78+
set_color(x, y, Pixel(b, g, r));
79+
break;
80+
}
6481
}
6582

6683
void Hub75::FM6126A_write_register(uint16_t value, uint8_t position) {

drivers/hub75/hub75.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ Pixel hsv_to_rgb(float h, float s, float v);
5252

5353
class Hub75 {
5454
public:
55+
enum class COLOR_ORDER {
56+
RGB,
57+
RBG,
58+
GRB,
59+
GBR,
60+
BRG,
61+
BGR
62+
};
5563
uint width;
5664
uint height;
5765
Pixel *back_buffer;
5866
bool managed_buffer = false;
5967
PanelType panel_type;
6068
bool inverted_stb = false;
69+
COLOR_ORDER color_order;
6170
Pixel background = 0;
6271

6372
// DMA & PIO
@@ -112,7 +121,7 @@ class Hub75 {
112121
Hub75(uint width, uint height) : Hub75(width, height, nullptr) {};
113122
Hub75(uint width, uint height, Pixel *buffer) : Hub75(width, height, buffer, PANEL_GENERIC) {};
114123
Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type) : Hub75(width, height, buffer, panel_type, false) {};
115-
Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb);
124+
Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order=COLOR_ORDER::RGB);
116125
~Hub75();
117126

118127
void FM6126A_write_register(uint16_t value, uint8_t position);

micropython/modules/hub75/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ It can, in theory, be used with your own custom wiring, though custom pin assign
1111
- [Notes On PIO & DMA Limitations](#notes-on-pio--dma-limitations)
1212
- [Getting Started](#getting-started)
1313
- [FM6216A Panels](#fm6216a-panels)
14+
- [Setting Colour Order](#setting-colour-order)
1415
- [Quick Reference](#quick-reference)
1516
- [Set A Pixel](#set-a-pixel)
1617
- [Clear The Display](#clear-the-display)
@@ -52,9 +53,25 @@ import hub75
5253
WIDTH = 64
5354
HEIGHT = 64
5455

55-
matrix = hub75.Hub75(WIDTH, HEIGHT,panel_type=hub75.PANEL_FM6126A)
56+
matrix = hub75.Hub75(WIDTH, HEIGHT, panel_type=hub75.PANEL_FM6126A)
5657
```
5758

59+
### Setting Colour Order
60+
61+
Some hub 75 panels have varying colour orders. A keyword argument is supplied to configure this:
62+
63+
```python
64+
matrix = hub75.Hub75(WIDTH, HEIGHT, panel_type=hub75.COLOR_ORDER_RBG)
65+
```
66+
67+
The available orders are defined as constants in `hub75`:
68+
69+
* `COLOR_ORDER_RGB`
70+
* `COLOR_ORDER_RBG`
71+
* `COLOR_ORDER_GRB`
72+
* `COLOR_ORDER_GBR`
73+
* `COLOR_ORDER_BRG`
74+
* `COLOR_ORDER_BGR`
5875

5976
## Quick Reference
6077

micropython/modules/hub75/hub75.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ STATIC const mp_map_elem_t hub75_globals_table[] = {
6161
{ MP_ROM_QSTR(MP_QSTR_PIN_SDA), MP_ROM_INT(20) },
6262
{ MP_ROM_QSTR(MP_QSTR_PIN_SCL), MP_ROM_INT(21) },
6363
{ MP_ROM_QSTR(MP_QSTR_CURRENT_SENSE), MP_ROM_INT(29) },
64+
65+
{ MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_RGB), MP_ROM_INT(0x00) },
66+
{ MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_RBG), MP_ROM_INT(0x01) },
67+
{ MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_GRB), MP_ROM_INT(0x02) },
68+
{ MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_GBR), MP_ROM_INT(0x03) },
69+
{ MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_BRG), MP_ROM_INT(0x04) },
70+
{ MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_BGR), MP_ROM_INT(0x05) },
6471
};
6572
STATIC MP_DEFINE_CONST_DICT(mp_module_hub75_globals, hub75_globals_table);
6673

micropython/modules/hub75/hub75.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
8585
ARG_height,
8686
ARG_buffer,
8787
ARG_panel_type,
88-
ARG_stb_invert
88+
ARG_stb_invert,
89+
ARG_color_order
8990
};
9091
static const mp_arg_t allowed_args[] = {
9192
{ MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT },
9293
{ MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_INT },
9394
{ MP_QSTR_buffer, MP_ARG_OBJ, {.u_obj = nullptr} },
9495
{ MP_QSTR_panel_type, MP_ARG_INT, {.u_int = 0} },
9596
{ MP_QSTR_stb_invert, MP_ARG_INT, {.u_int = 0} },
97+
{ MP_QSTR_color_order, MP_ARG_INT, {.u_int = (uint8_t)Hub75::COLOR_ORDER::RGB} },
9698
};
9799

98100
// Parse args.
@@ -103,6 +105,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
103105
int height = args[ARG_height].u_int;
104106
PanelType paneltype = (PanelType)args[ARG_panel_type].u_int;
105107
bool stb_invert = args[ARG_stb_invert].u_int;
108+
Hub75::COLOR_ORDER color_order = (Hub75::COLOR_ORDER)args[ARG_color_order].u_int;
106109

107110
Pixel *buffer = nullptr;
108111

@@ -120,7 +123,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
120123
hub75_obj = m_new_obj_with_finaliser(_Hub75_obj_t);
121124
hub75_obj->base.type = &Hub75_type;
122125
hub75_obj->buf = buffer;
123-
hub75_obj->hub75 = m_new_class(Hub75, width, height, buffer, paneltype, stb_invert);
126+
hub75_obj->hub75 = m_new_class(Hub75, width, height, buffer, paneltype, stb_invert, color_order);
124127

125128
return MP_OBJ_FROM_PTR(hub75_obj);
126129
}

micropython/modules_py/interstate75.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ class Interstate75:
2828

2929
PANEL_GENERIC = hub75.PANEL_GENERIC
3030
PANEL_FM6126A = hub75.PANEL_FM6126A
31+
COLOR_ORDER_RGB = hub75.COLOR_ORDER_RGB
32+
COLOR_ORDER_RBG = hub75.COLOR_ORDER_RBG
33+
COLOR_ORDER_GRB = hub75.COLOR_ORDER_GRB
34+
COLOR_ORDER_GBR = hub75.COLOR_ORDER_GBR
35+
COLOR_ORDER_BRG = hub75.COLOR_ORDER_BRG
36+
COLOR_ORDER_BGR = hub75.COLOR_ORDER_BGR
3137

3238
# Count Constants
3339
NUM_SWITCHES = 2
3440

35-
def __init__(self, display, panel_type=hub75.PANEL_GENERIC, stb_invert=False):
41+
def __init__(self, display, panel_type=hub75.PANEL_GENERIC, stb_invert=False, color_order=hub75.COLOR_ORDER_RGB):
3642
self.display = PicoGraphics(display=display)
3743
self.width, self.height = self.display.get_bounds()
38-
self.hub75 = hub75.Hub75(self.width, self.height, panel_type=panel_type, stb_invert=stb_invert)
44+
self.hub75 = hub75.Hub75(self.width, self.height, panel_type=panel_type, stb_invert=stb_invert, color_order=color_order)
3945
self.hub75.start()
4046

4147
# Set up the user switches

0 commit comments

Comments
 (0)