diff --git a/drivers/hub75/hub75.cpp b/drivers/hub75/hub75.cpp index d8f9d32c..3e017dda 100644 --- a/drivers/hub75/hub75.cpp +++ b/drivers/hub75/hub75.cpp @@ -37,8 +37,8 @@ Pixel hsv_to_rgb(float h, float s, float v) { } -Hub75::Hub75(uint8_t width, uint8_t height, Pixel *buffer, PanelType panel_type, bool inverted_stb) - : width(width), height(height), panel_type(panel_type) +Hub75::Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb) + : width(width), height(height), panel_type(panel_type), inverted_stb(inverted_stb) { // 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); @@ -70,7 +70,7 @@ Hub75::Hub75(uint8_t width, uint8_t height, Pixel *buffer, PanelType panel_type, } } -void Hub75::set_rgb(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b) { +void Hub75::set_rgb(uint x, uint y, uint8_t r, uint8_t g, uint8_t b) { int offset = 0; if(y >= height / 2) { y -= height / 2; @@ -82,7 +82,7 @@ void Hub75::set_rgb(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b) { front_buffer[offset] = Pixel(r, g, b); } -void Hub75::set_hsv(uint8_t x, uint8_t y, float h, float s, float v) { +void Hub75::set_hsv(uint x, uint y, float h, float s, float v) { int offset = 0; if(y >= height / 2) { y -= height / 2; @@ -163,12 +163,18 @@ void Hub75::start(irq_handler_t handler) { pio_sm_claim(pio, sm_row); data_prog_offs = pio_add_program(pio, &hub75_data_rgb888_program); - row_prog_offs = pio_add_program(pio, &hub75_row_program); + if (inverted_stb) { + row_prog_offs = pio_add_program(pio, &hub75_row_inverted_program); + } else { + row_prog_offs = pio_add_program(pio, &hub75_row_program); + } hub75_data_rgb888_program_init(pio, sm_data, data_prog_offs, DATA_BASE_PIN, pin_clk); hub75_row_program_init(pio, sm_row, row_prog_offs, ROWSEL_BASE_PIN, ROWSEL_N_PINS, pin_stb); // Prevent flicker in Python caused by the smaller dataset just blasting through the PIO too quickly - pio_sm_set_clkdiv(pio, sm_data, 2.0f); + if (width <= 32) { + pio_sm_set_clkdiv(pio, sm_data, 2.0f); + } if(dma_channel_is_claimed(dma_channel)) { irq_set_enabled(DMA_IRQ_0, false); diff --git a/drivers/hub75/hub75.hpp b/drivers/hub75/hub75.hpp index 3ad3ba11..a8aa9c93 100644 --- a/drivers/hub75/hub75.hpp +++ b/drivers/hub75/hub75.hpp @@ -48,13 +48,14 @@ enum PanelType { class Hub75 { public: - uint8_t width; - uint8_t height; + uint width; + uint height; Pixel *front_buffer; Pixel *back_buffer; bool managed_buffer = false; bool running = false; PanelType panel_type; + bool inverted_stb = false; // DMA & PIO uint dma_channel = 0; @@ -105,15 +106,15 @@ class Hub75 { unsigned int pin_led_g = 17; unsigned int pin_led_b = 18; - Hub75(uint8_t width, uint8_t height, Pixel *buffer) : Hub75(width, height, buffer, PANEL_GENERIC, false) {}; - Hub75(uint8_t width, uint8_t height, Pixel *buffer, PanelType panel_type) : Hub75(width, height, buffer, panel_type, false) {}; - Hub75(uint8_t width, uint8_t height, Pixel *buffer, PanelType panel_type, bool inverted_stb); + Hub75(uint width, uint height, Pixel *buffer) : Hub75(width, height, buffer, PANEL_GENERIC, false) {}; + Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type) : Hub75(width, height, buffer, panel_type, false) {}; + Hub75(uint width, uint height, Pixel *buffer, PanelType panel_type, bool inverted_stb); ~Hub75(); void FM6126A_write_register(uint16_t value, uint8_t position); void FM6126A_setup(); - void set_rgb(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b); - void set_hsv(uint8_t x, uint8_t y, float r, float g, float b); + void set_rgb(uint x, uint y, uint8_t r, uint8_t g, uint8_t b); + void set_hsv(uint x, uint y, float r, float g, float b); void display_update(); void clear(); void start(irq_handler_t handler); diff --git a/micropython/modules/hub75/hub75.cpp b/micropython/modules/hub75/hub75.cpp index 9a329f6e..922c2983 100644 --- a/micropython/modules/hub75/hub75.cpp +++ b/micropython/modules/hub75/hub75.cpp @@ -76,12 +76,14 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c ARG_height, ARG_buffer, ARG_panel_type, + ARG_stb_invert }; static const mp_arg_t allowed_args[] = { { MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_buffer, MP_ARG_OBJ, {.u_obj = nullptr} }, { MP_QSTR_panel_type, MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_stb_invert, MP_ARG_INT, {.u_int = 0} }, }; // Parse args. @@ -91,6 +93,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c int width = args[ARG_width].u_int; int height = args[ARG_height].u_int; PanelType paneltype = (PanelType)args[ARG_panel_type].u_int; + bool stb_invert = args[ARG_stb_invert].u_int; Pixel *buffer = nullptr; @@ -108,7 +111,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c hub75_obj = m_new_obj_with_finaliser(_Hub75_obj_t); hub75_obj->base.type = &Hub75_type; hub75_obj->buf = buffer; - hub75_obj->hub75 = new Hub75(width, height, buffer, paneltype); + hub75_obj->hub75 = new Hub75(width, height, buffer, paneltype, stb_invert); return MP_OBJ_FROM_PTR(hub75_obj); }