Skip to content

Commit

Permalink
comms_config.cs_active_low and inverted 1bpp surface
Browse files Browse the repository at this point in the history
  • Loading branch information
elpekenin committed Jun 19, 2024
1 parent a9a7c9f commit 048d8af
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 8 deletions.
2 changes: 1 addition & 1 deletion drivers/painter/comms/qp_comms_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool qp_comms_spi_start(painter_device_t device) {
painter_driver_t * driver = (painter_driver_t *)device;
qp_comms_spi_config_t *comms_config = (qp_comms_spi_config_t *)driver->comms_config;

return spi_start(comms_config->chip_select_pin, comms_config->lsb_first, comms_config->mode, comms_config->divisor);
return spi_start_extended(comms_config->chip_select_pin, comms_config->lsb_first, comms_config->mode, comms_config->divisor, comms_config->cs_active_low);
}

uint32_t qp_comms_spi_send_data(painter_device_t device, const void *data, uint32_t byte_count) {
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/comms/qp_comms_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

typedef struct qp_comms_spi_config_t {
pin_t chip_select_pin;
bool cs_active_low;
uint16_t divisor;
bool lsb_first;
int8_t mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/gc9xxx/qp_gc9107.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ painter_device_t qp_gc9107_make_spi_device(uint16_t panel_width, uint16_t panel_
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/gc9xxx/qp_gc9a01.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ painter_device_t qp_gc9a01_make_spi_device(uint16_t panel_width, uint16_t panel_
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
10 changes: 10 additions & 0 deletions drivers/painter/generic/qp_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ painter_device_t qp_make_rgb565_surface(uint16_t panel_width, uint16_t panel_hei
*/
painter_device_t qp_make_mono1bpp_surface(uint16_t panel_width, uint16_t panel_height, void *buffer);

/**
* Factory method for a 1bpp monochrome surface (aka framebuffer).
*
* @param panel_width[in] the width of the display panel
* @param panel_height[in] the height of the display panel
* @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 1)`
* @return the device handle used with all drawing routines in Quantum Painter
*/
painter_device_t qp_make_mono1bpp_surface_inverted(uint16_t panel_width, uint16_t panel_height, void *buffer);

/**
* Helper method to draw the contents of the framebuffer to the target device.
*
Expand Down
12 changes: 12 additions & 0 deletions drivers/painter/generic/qp_surface_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ painter_device_t qp_make_rgb565_surface_advanced(surface_painter_device_t *devic
*/
painter_device_t qp_make_mono1bpp_surface_advanced(surface_painter_device_t *device_table, size_t device_table_len, uint16_t panel_width, uint16_t panel_height, void *buffer);

/**
* Factory method for a 1bpp monochrome surface (aka framebuffer).
*
* @param device_table[in] the table of devices to use for instantiation
* @param device_table_len[in] the length of the table of devices
* @param panel_width[in] the width of the display panel
* @param panel_height[in] the height of the display panel
* @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)`
* @return the device handle used with all drawing routines in Quantum Painter
*/
painter_device_t qp_make_mono1bpp_surface_inverted_advanced(surface_painter_device_t *device_table, size_t device_table_len, uint16_t panel_width, uint16_t panel_height, void *buffer);

// Driver storage
extern surface_painter_device_t surface_drivers[SURFACE_NUM_DEVICES];

Expand Down
35 changes: 35 additions & 0 deletions drivers/painter/generic/qp_surface_mono1bpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ static bool qp_surface_append_pixels_mono1bpp(painter_device_t device, uint8_t *
return true;
}

// Byte order inverted (7 - x) with respect to above's implementation
// TODO?: Move some common code to funcs
// TODO?: Better name than "inverted"
static bool qp_surface_append_pixels_mono1bpp_inverted(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices) {
for (uint32_t i = 0; i < pixel_count; ++i) {
uint32_t pixel_num = pixel_offset + i;
uint32_t byte_offset = pixel_num / 8;
uint8_t bit_offset = 7 - (pixel_num % 8);
if (palette[palette_indices[i]].mono) {
target_buffer[byte_offset] |= (1 << bit_offset);
} else {
target_buffer[byte_offset] &= ~(1 << bit_offset);
}
}
return true;
}

static bool mono1bpp_target_pixdata_transfer(painter_driver_t *surface_driver, painter_driver_t *target_driver, uint16_t x, uint16_t y, bool entire_surface) {
return false; // Not yet supported.
}
Expand All @@ -110,4 +127,22 @@ const surface_painter_driver_vtable_t mono1bpp_surface_driver_vtable = {

SURFACE_FACTORY_FUNCTION_IMPL(qp_make_mono1bpp_surface, mono1bpp_surface_driver_vtable, 1);

const surface_painter_driver_vtable_t mono1bpp_surface_inverted_driver_vtable = {
.base =
{
.init = qp_surface_init,
.power = qp_surface_power,
.clear = qp_surface_clear,
.flush = qp_surface_flush,
.pixdata = qp_surface_pixdata_mono1bpp,
.viewport = qp_surface_viewport,
.palette_convert = qp_surface_palette_convert_mono1bpp,
.append_pixels = qp_surface_append_pixels_mono1bpp_inverted,
.append_pixdata = qp_surface_append_pixdata_mono1bpp,
},
.target_pixdata_transfer = mono1bpp_target_pixdata_transfer,
};

SURFACE_FACTORY_FUNCTION_IMPL(qp_make_mono1bpp_surface_inverted, mono1bpp_surface_inverted_driver_vtable, 1);

#endif // QUANTUM_PAINTER_SURFACE_ENABLE
1 change: 1 addition & 0 deletions drivers/painter/ili9xxx/qp_ili9163.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ painter_device_t qp_ili9163_make_spi_device(uint16_t panel_width, uint16_t panel
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/ili9xxx/qp_ili9341.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ painter_device_t qp_ili9341_make_spi_device(uint16_t panel_width, uint16_t panel
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/ili9xxx/qp_ili9486.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ painter_device_t qp_ili9486_make_spi_device(uint16_t panel_width, uint16_t panel
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/ili9xxx/qp_ili9488.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ painter_device_t qp_ili9488_make_spi_device(uint16_t panel_width, uint16_t panel
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
18 changes: 11 additions & 7 deletions drivers/painter/mip_panel/qp_ls0xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ painter_device_t qp_ls0xx_device_t_make_spi_device(uint16_t panel_width, uint16_
for (uint32_t i = 0; i < LS0XX_NUM_DEVICES; ++i) {
mip_panel_painter_device_t *driver = &ls0xx_device_t_drivers[i];
if (!driver->base.driver_vtable) {
painter_device_t surface = qp_make_mono1bpp_surface_advanced(&driver->surface, 1, panel_width, panel_height, buf);
painter_device_t surface = qp_make_mono1bpp_surface_inverted_advanced(&driver->surface, 1, panel_width, panel_height, buf);
if (!surface) {
return NULL;
}
Expand All @@ -36,16 +36,20 @@ painter_device_t qp_ls0xx_device_t_make_spi_device(uint16_t panel_width, uint16_
driver->base.rotation = QP_ROTATION_0;
driver->base.offset_x = 0;
driver->base.offset_y = 0;
driver->base.comms_config = &driver->spi_config;
driver->spi_config.chip_select_pin = chip_select_pin;
driver->spi_config.lsb_first = false;
driver->spi_config.divisor = spi_divisor;
driver->spi_config.mode = spi_mode;
driver->surface.invert_order = true;

// SPI and other pin configuration
driver->base.comms_config = &driver->spi_config;
driver->spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = false;
driver->spi_config.lsb_first = false;
driver->spi_config.divisor = spi_divisor;
driver->spi_config.mode = spi_mode;

if (!qp_internal_register_device((painter_device_t)driver)) {
memset(driver, 0, sizeof(mip_panel_painter_device_t));
return NULL;
}

return (painter_device_t)driver;
}
}
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/sh1106/qp_sh1106.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ painter_device_t qp_sh1106_make_spi_device(uint16_t panel_width, uint16_t panel_
// SPI and other pin configuration
driver->oled.base.comms_config = &driver->oled.spi_dc_reset_config;
driver->oled.spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->oled.spi_dc_reset_config.spi_config.cs_active_low = true;
driver->oled.spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->oled.spi_dc_reset_config.spi_config.lsb_first = false;
driver->oled.spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/ssd1351/qp_ssd1351.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/st77xx/qp_st7735.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ painter_device_t qp_st7735_make_spi_device(uint16_t panel_width, uint16_t panel_
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down
1 change: 1 addition & 0 deletions drivers/painter/st77xx/qp_st7789.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ painter_device_t qp_st7789_make_spi_device(uint16_t panel_width, uint16_t panel_
// SPI and other pin configuration
driver->base.comms_config = &driver->spi_dc_reset_config;
driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
driver->spi_dc_reset_config.spi_config.cs_active_low = true;
driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
driver->spi_dc_reset_config.spi_config.lsb_first = false;
driver->spi_dc_reset_config.spi_config.mode = spi_mode;
Expand Down

0 comments on commit 048d8af

Please sign in to comment.