Skip to content

Commit

Permalink
Previous idea did not work, so now checking color order for every pix…
Browse files Browse the repository at this point in the history
…el set
  • Loading branch information
ZodiusInfuser committed Jan 31, 2023
1 parent eda6e99 commit cacfbd1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
62 changes: 21 additions & 41 deletions drivers/hub75/hub75.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,9 @@

namespace pimoroni {

void Hub75::swap_pin(unsigned int &pin_a, unsigned int &pin_b) {
unsigned int swap;
swap = pin_a;
pin_a = pin_b;
pin_b = swap;
}

Hub75::Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb, COLOR_ORDER color_order)
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb)
: width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb), color_order(color_order)
{
// If the colour order is not RGB, swap the colour pins.
switch(color_order) {
case COLOR_ORDER::RBG:
swap_pin(pin_g0, pin_b0);
swap_pin(pin_g1, pin_b1);
break;
case COLOR_ORDER::GRB:
swap_pin(pin_r0, pin_g0);
swap_pin(pin_r1, pin_g1);
break;
case COLOR_ORDER::GBR:
swap_pin(pin_r0, pin_g0);
swap_pin(pin_r1, pin_g1);

swap_pin(pin_r0, pin_b0);
swap_pin(pin_r1, pin_b1);
break;
case COLOR_ORDER::BRG:
swap_pin(pin_r0, pin_b0);
swap_pin(pin_r1, pin_b1);

swap_pin(pin_r0, pin_g0);
swap_pin(pin_r1, pin_g1);
break;
case COLOR_ORDER::BGR:
swap_pin(pin_r0, pin_b0);
swap_pin(pin_r1, pin_b1);
break;
default:
break;
}

// Set up allllll the GPIO
gpio_init(pin_r0); gpio_set_function(pin_r0, GPIO_FUNC_SIO); gpio_set_dir(pin_r0, true); gpio_put(pin_r0, 0);
gpio_init(pin_g0); gpio_set_function(pin_g0, GPIO_FUNC_SIO); gpio_set_dir(pin_g0, true); gpio_put(pin_g0, 0);
Expand Down Expand Up @@ -97,7 +58,26 @@ void Hub75::set_color(uint x, uint y, Pixel c) {
}

void Hub75::set_pixel(uint x, uint y, uint8_t r, uint8_t g, uint8_t b) {
set_color(x, y, Pixel(r, g, b));
switch(color_order) {
case COLOR_ORDER::RGB:
set_color(x, y, Pixel(r, g, b));
break;
case COLOR_ORDER::RBG:
set_color(x, y, Pixel(r, b, g));
break;
case COLOR_ORDER::GRB:
set_color(x, y, Pixel(g, r, b));
break;
case COLOR_ORDER::GBR:
set_color(x, y, Pixel(g, b, r));
break;
case COLOR_ORDER::BRG:
set_color(x, y, Pixel(b, r, g));
break;
case COLOR_ORDER::BGR:
set_color(x, y, Pixel(b, g, r));
break;
}
}

void Hub75::FM6126A_write_register(uint16_t value, uint8_t position) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/hub75/hub75.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Hub75 {
bool managed_buffer = false;
PanelType panel_type;
bool inverted_stb = false;
COLOR_ORDER color_order;
Pixel background = 0;

// DMA & PIO
Expand Down Expand Up @@ -134,7 +135,5 @@ class Hub75 {
void stop(irq_handler_t handler);
void dma_complete();
void update(PicoGraphics *graphics);
private:
void swap_pin(unsigned int &pin_a, unsigned int &pin_b);
};
}
19 changes: 18 additions & 1 deletion micropython/modules/hub75/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ It can, in theory, be used with your own custom wiring, though custom pin assign
- [Notes On PIO & DMA Limitations](#notes-on-pio--dma-limitations)
- [Getting Started](#getting-started)
- [FM6216A Panels](#fm6216a-panels)
- [Setting Colour Order](#setting-colour-order)
- [Quick Reference](#quick-reference)
- [Set A Pixel](#set-a-pixel)
- [Clear The Display](#clear-the-display)
Expand Down Expand Up @@ -52,9 +53,25 @@ import hub75
WIDTH = 64
HEIGHT = 64

matrix = hub75.Hub75(WIDTH, HEIGHT,panel_type=hub75.PANEL_FM6126A)
matrix = hub75.Hub75(WIDTH, HEIGHT, panel_type=hub75.PANEL_FM6126A)
```

### Setting Colour Order

Some hub 75 panels have varying colour orders. A keyword argument is supplied to configure this:

```python
matrix = hub75.Hub75(WIDTH, HEIGHT, panel_type=hub75.COLOR_ORDER_RBG)
```

The available orders are defined as constants in `hub75`:

* `COLOR_ORDER_RGB`
* `COLOR_ORDER_RBG`
* `COLOR_ORDER_GRB`
* `COLOR_ORDER_GBR`
* `COLOR_ORDER_BRG`
* `COLOR_ORDER_BGR`

## Quick Reference

Expand Down
6 changes: 6 additions & 0 deletions micropython/modules_py/interstate75.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class Interstate75:

PANEL_GENERIC = hub75.PANEL_GENERIC
PANEL_FM6126A = hub75.PANEL_FM6126A
COLOR_ORDER_RGB = hub75.COLOR_ORDER_RGB
COLOR_ORDER_RBG = hub75.COLOR_ORDER_RBG
COLOR_ORDER_GRB = hub75.COLOR_ORDER_GRB
COLOR_ORDER_GBR = hub75.COLOR_ORDER_GBR
COLOR_ORDER_BRG = hub75.COLOR_ORDER_BRG
COLOR_ORDER_BGR = hub75.COLOR_ORDER_BGR

# Count Constants
NUM_SWITCHES = 2
Expand Down

0 comments on commit cacfbd1

Please sign in to comment.