Skip to content

Commit cacfbd1

Browse files
committed
Previous idea did not work, so now checking color order for every pixel set
1 parent eda6e99 commit cacfbd1

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

drivers/hub75/hub75.cpp

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,9 @@
66

77
namespace pimoroni {
88

9-
void Hub75::swap_pin(unsigned int &pin_a, unsigned int &pin_b) {
10-
unsigned int swap;
11-
swap = pin_a;
12-
pin_a = pin_b;
13-
pin_b = swap;
14-
}
15-
169
Hub75::Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order)
17-
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb)
10+
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb), color_order(color_order)
1811
{
19-
// If the colour order is not RGB, swap the colour pins.
20-
switch(color_order) {
21-
case COLOR_ORDER::RBG:
22-
swap_pin(pin_g0, pin_b0);
23-
swap_pin(pin_g1, pin_b1);
24-
break;
25-
case COLOR_ORDER::GRB:
26-
swap_pin(pin_r0, pin_g0);
27-
swap_pin(pin_r1, pin_g1);
28-
break;
29-
case COLOR_ORDER::GBR:
30-
swap_pin(pin_r0, pin_g0);
31-
swap_pin(pin_r1, pin_g1);
32-
33-
swap_pin(pin_r0, pin_b0);
34-
swap_pin(pin_r1, pin_b1);
35-
break;
36-
case COLOR_ORDER::BRG:
37-
swap_pin(pin_r0, pin_b0);
38-
swap_pin(pin_r1, pin_b1);
39-
40-
swap_pin(pin_r0, pin_g0);
41-
swap_pin(pin_r1, pin_g1);
42-
break;
43-
case COLOR_ORDER::BGR:
44-
swap_pin(pin_r0, pin_b0);
45-
swap_pin(pin_r1, pin_b1);
46-
break;
47-
default:
48-
break;
49-
}
50-
5112
// Set up allllll the GPIO
5213
gpio_init(pin_r0); gpio_set_function(pin_r0, GPIO_FUNC_SIO); gpio_set_dir(pin_r0, true); gpio_put(pin_r0, 0);
5314
gpio_init(pin_g0); gpio_set_function(pin_g0, GPIO_FUNC_SIO); gpio_set_dir(pin_g0, true); gpio_put(pin_g0, 0);
@@ -97,7 +58,26 @@ void Hub75::set_color(uint x, uint y, Pixel c) {
9758
}
9859

9960
void Hub75::set_pixel(uint x, uint y, uint8_t r, uint8_t g, uint8_t b) {
100-
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+
}
10181
}
10282

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

drivers/hub75/hub75.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Hub75 {
6666
bool managed_buffer = false;
6767
PanelType panel_type;
6868
bool inverted_stb = false;
69+
COLOR_ORDER color_order;
6970
Pixel background = 0;
7071

7172
// DMA & PIO
@@ -134,7 +135,5 @@ class Hub75 {
134135
void stop(irq_handler_t handler);
135136
void dma_complete();
136137
void update(PicoGraphics *graphics);
137-
private:
138-
void swap_pin(unsigned int &pin_a, unsigned int &pin_b);
139138
};
140139
}

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_py/interstate75.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ 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

0 commit comments

Comments
 (0)