HUB75 Panel Types for FM6126A setup, fixes for 32x32

pull/193/head
Phil Howard 2021-11-23 11:29:41 +00:00
rodzic eed7992127
commit c07567f922
4 zmienionych plików z 27 dodań i 9 usunięć

Wyświetl plik

@ -39,6 +39,8 @@ const mp_obj_type_t Hub75_type = {
STATIC const mp_map_elem_t hub75_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_hub75) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Hub75), (mp_obj_t)&Hub75_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_PANEL_GENERIC), MP_ROM_INT(0) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_PANEL_FM6126A), MP_ROM_INT(1) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_hub75_globals, hub75_globals_table);

Wyświetl plik

@ -66,11 +66,13 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
ARG_width,
ARG_height,
ARG_buffer,
ARG_panel_type,
};
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_buffer, MP_ARG_OBJ, {.u_obj = nullptr} },
{ MP_QSTR_panel_type, MP_ARG_INT, {.u_int = 0} },
};
// Parse args.
@ -79,6 +81,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;
Pixel *buffer = nullptr;
@ -96,7 +99,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);
hub75_obj->hub75 = new Hub75(width, height, buffer, paneltype);
return MP_OBJ_FROM_PTR(hub75_obj);
}

Wyświetl plik

@ -37,7 +37,7 @@ Pixel hsv_to_rgb(float h, float s, float v) {
}
Hub75::Hub75(uint8_t width, uint8_t height, Pixel *buffer)
Hub75::Hub75(uint8_t width, uint8_t height, Pixel *buffer, PanelType panel_type)
: width(width), height(height), front_buffer(buffer), back_buffer(buffer + width * height)
{
// Set up allllll the GPIO
@ -58,6 +58,10 @@ Hub75::Hub75(uint8_t width, uint8_t height, Pixel *buffer)
gpio_init(pin_clk); gpio_set_function(pin_clk, GPIO_FUNC_SIO); gpio_set_dir(pin_clk, true); gpio_put(pin_clk, !clk_polarity);
gpio_init(pin_stb); gpio_set_function(pin_stb, GPIO_FUNC_SIO); gpio_set_dir(pin_stb, true); gpio_put(pin_clk, !stb_polarity);
gpio_init(pin_oe); gpio_set_function(pin_oe, GPIO_FUNC_SIO); gpio_set_dir(pin_oe, true); gpio_put(pin_clk, !oe_polarity);
if (panel_type == PANEL_FM6126A) {
FM6126A_setup();
}
}
void Hub75::set_rgb(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b) {
@ -74,8 +78,8 @@ void Hub75::set_rgb(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b) {
void Hub75::set_hsv(uint8_t x, uint8_t y, float h, float s, float v) {
int offset = 0;
if(y >= 32) {
y -= 32;
if(y >= height / 2) {
y -= height / 2;
offset = (y * width + x) * 2;
offset += 1;
} else {
@ -109,12 +113,14 @@ void Hub75::FM6126A_write_register(uint16_t value, uint8_t position) {
}
}
void Hub75::start(irq_handler_t handler) {
running = true;
void Hub75::FM6126A_setup() {
// Ridiculous register write nonsense for the FM6126A-based 64x64 matrix
FM6126A_write_register(0b1111111111111110, 12);
FM6126A_write_register(0b0000001000000000, 13);
}
void Hub75::start(irq_handler_t handler) {
running = true;
if(handler) {
dma_channel = 0;

Wyświetl plik

@ -45,6 +45,11 @@ struct alignas(4) Pixel {
};
#pragma pack(pop)
enum PanelType {
PANEL_GENERIC = 0,
PANEL_FM6126A,
};
class Hub75 {
public:
uint8_t width;
@ -101,10 +106,12 @@ class Hub75 {
unsigned int pin_led_g = 17;
unsigned int pin_led_b = 18;
Hub75(uint8_t width, uint8_t height, Pixel *buffer);
Hub75(uint8_t width, uint8_t height, Pixel *buffer) : Hub75(width, height, buffer, PANEL_GENERIC) {};
Hub75(uint8_t width, uint8_t height, Pixel *buffer, PanelType panel_type);
~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 display_update();