[Cleanup] Quantum Painter (#19825)

Co-authored-by: Nick Brassel <nick@tzarc.org>
This commit is contained in:
Pablo Martínez 2023-03-25 18:56:04 +01:00 committed by GitHub
parent e640fd65ff
commit cd542a0f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 171 additions and 169 deletions

View File

@ -10,8 +10,8 @@
// Base SPI support
bool qp_comms_spi_init(painter_device_t device) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct qp_comms_spi_config_t *comms_config = (struct qp_comms_spi_config_t *)driver->comms_config;
painter_driver_t * driver = (painter_driver_t *)device;
qp_comms_spi_config_t *comms_config = (qp_comms_spi_config_t *)driver->comms_config;
// Initialize the SPI peripheral
spi_init();
@ -24,8 +24,8 @@ bool qp_comms_spi_init(painter_device_t device) {
}
bool qp_comms_spi_start(painter_device_t device) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct qp_comms_spi_config_t *comms_config = (struct qp_comms_spi_config_t *)driver->comms_config;
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);
}
@ -33,8 +33,10 @@ bool qp_comms_spi_start(painter_device_t device) {
uint32_t qp_comms_spi_send_data(painter_device_t device, const void *data, uint32_t byte_count) {
uint32_t bytes_remaining = byte_count;
const uint8_t *p = (const uint8_t *)data;
const uint32_t max_msg_length = 1024;
while (bytes_remaining > 0) {
uint32_t bytes_this_loop = bytes_remaining < 1024 ? bytes_remaining : 1024;
uint32_t bytes_this_loop = QP_MIN(bytes_remaining, max_msg_length);
spi_transmit(p, bytes_this_loop);
p += bytes_this_loop;
bytes_remaining -= bytes_this_loop;
@ -44,13 +46,13 @@ uint32_t qp_comms_spi_send_data(painter_device_t device, const void *data, uint3
}
void qp_comms_spi_stop(painter_device_t device) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct qp_comms_spi_config_t *comms_config = (struct qp_comms_spi_config_t *)driver->comms_config;
painter_driver_t * driver = (painter_driver_t *)device;
qp_comms_spi_config_t *comms_config = (qp_comms_spi_config_t *)driver->comms_config;
spi_stop();
writePinHigh(comms_config->chip_select_pin);
}
const struct painter_comms_vtable_t spi_comms_vtable = {
const painter_comms_vtable_t spi_comms_vtable = {
.comms_init = qp_comms_spi_init,
.comms_start = qp_comms_spi_start,
.comms_send = qp_comms_spi_send_data,
@ -67,8 +69,8 @@ bool qp_comms_spi_dc_reset_init(painter_device_t device) {
return false;
}
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct qp_comms_spi_dc_reset_config_t *comms_config = (struct qp_comms_spi_dc_reset_config_t *)driver->comms_config;
painter_driver_t * driver = (painter_driver_t *)device;
qp_comms_spi_dc_reset_config_t *comms_config = (qp_comms_spi_dc_reset_config_t *)driver->comms_config;
// Set up D/C as output low, if specified
if (comms_config->dc_pin != NO_PIN) {
@ -89,15 +91,15 @@ bool qp_comms_spi_dc_reset_init(painter_device_t device) {
}
uint32_t qp_comms_spi_dc_reset_send_data(painter_device_t device, const void *data, uint32_t byte_count) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct qp_comms_spi_dc_reset_config_t *comms_config = (struct qp_comms_spi_dc_reset_config_t *)driver->comms_config;
painter_driver_t * driver = (painter_driver_t *)device;
qp_comms_spi_dc_reset_config_t *comms_config = (qp_comms_spi_dc_reset_config_t *)driver->comms_config;
writePinHigh(comms_config->dc_pin);
return qp_comms_spi_send_data(device, data, byte_count);
}
void qp_comms_spi_dc_reset_send_command(painter_device_t device, uint8_t cmd) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct qp_comms_spi_dc_reset_config_t *comms_config = (struct qp_comms_spi_dc_reset_config_t *)driver->comms_config;
painter_driver_t * driver = (painter_driver_t *)device;
qp_comms_spi_dc_reset_config_t *comms_config = (qp_comms_spi_dc_reset_config_t *)driver->comms_config;
writePinLow(comms_config->dc_pin);
spi_write(cmd);
}
@ -118,7 +120,7 @@ void qp_comms_spi_dc_reset_bulk_command_sequence(painter_device_t device, const
}
}
const struct painter_comms_with_command_vtable_t spi_comms_with_dc_vtable = {
const painter_comms_with_command_vtable_t spi_comms_with_dc_vtable = {
.base =
{
.comms_init = qp_comms_spi_dc_reset_init,

View File

@ -13,36 +13,36 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Base SPI support
struct qp_comms_spi_config_t {
typedef struct qp_comms_spi_config_t {
pin_t chip_select_pin;
uint16_t divisor;
bool lsb_first;
int8_t mode;
};
} qp_comms_spi_config_t;
bool qp_comms_spi_init(painter_device_t device);
bool qp_comms_spi_start(painter_device_t device);
uint32_t qp_comms_spi_send_data(painter_device_t device, const void* data, uint32_t byte_count);
void qp_comms_spi_stop(painter_device_t device);
extern const struct painter_comms_vtable_t spi_comms_vtable;
extern const painter_comms_vtable_t spi_comms_vtable;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SPI with D/C and RST pins
# ifdef QUANTUM_PAINTER_SPI_DC_RESET_ENABLE
struct qp_comms_spi_dc_reset_config_t {
struct qp_comms_spi_config_t spi_config;
pin_t dc_pin;
pin_t reset_pin;
};
typedef struct qp_comms_spi_dc_reset_config_t {
qp_comms_spi_config_t spi_config;
pin_t dc_pin;
pin_t reset_pin;
} qp_comms_spi_dc_reset_config_t;
void qp_comms_spi_dc_reset_send_command(painter_device_t device, uint8_t cmd);
uint32_t qp_comms_spi_dc_reset_send_data(painter_device_t device, const void* data, uint32_t byte_count);
void qp_comms_spi_dc_reset_bulk_command_sequence(painter_device_t device, const uint8_t* sequence, size_t sequence_len);
extern const struct painter_comms_with_command_vtable_t spi_comms_with_dc_vtable;
extern const painter_comms_with_command_vtable_t spi_comms_with_dc_vtable;
# endif // QUANTUM_PAINTER_SPI_DC_RESET_ENABLE

View File

@ -94,7 +94,7 @@ __attribute__((weak)) bool qp_gc9a01_init(painter_device_t device, painter_rotat
// Driver vtable
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const struct tft_panel_dc_reset_painter_driver_vtable_t gc9a01_driver_vtable = {
const tft_panel_dc_reset_painter_driver_vtable_t gc9a01_driver_vtable = {
.base =
{
.init = qp_gc9a01_init,
@ -125,8 +125,8 @@ painter_device_t qp_gc9a01_make_spi_device(uint16_t panel_width, uint16_t panel_
for (uint32_t i = 0; i < GC9A01_NUM_DEVICES; ++i) {
tft_panel_dc_reset_painter_device_t *driver = &gc9a01_drivers[i];
if (!driver->base.driver_vtable) {
driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&gc9a01_driver_vtable;
driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.driver_vtable = (const painter_driver_vtable_t *)&gc9a01_driver_vtable;
driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.native_bits_per_pixel = 16; // RGB565
driver->base.panel_width = panel_width;
driver->base.panel_height = panel_height;

View File

@ -9,7 +9,7 @@
// Device definition
typedef struct rgb565_surface_painter_device_t {
struct painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type
painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type
// The target buffer
uint16_t *buffer;
@ -95,7 +95,7 @@ static inline void stream_pixdata(rgb565_surface_painter_device_t *surface, cons
// Driver vtable
static bool qp_rgb565_surface_init(painter_device_t device, painter_rotation_t rotation) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
painter_driver_t * driver = (painter_driver_t *)device;
rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver;
memset(surface->buffer, 0, driver->panel_width * driver->panel_height * driver->native_bits_per_pixel / 8);
return true;
@ -107,13 +107,13 @@ static bool qp_rgb565_surface_power(painter_device_t device, bool power_on) {
}
static bool qp_rgb565_surface_clear(painter_device_t device) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
driver->driver_vtable->init(device, driver->rotation); // Re-init the surface
return true;
}
static bool qp_rgb565_surface_flush(painter_device_t device) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
painter_driver_t * driver = (painter_driver_t *)device;
rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver;
surface->dirty_l = surface->dirty_t = UINT16_MAX;
surface->dirty_r = surface->dirty_b = 0;
@ -122,7 +122,7 @@ static bool qp_rgb565_surface_flush(painter_device_t device) {
}
static bool qp_rgb565_surface_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
painter_driver_t * driver = (painter_driver_t *)device;
rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver;
// Set the viewport locations
@ -139,7 +139,7 @@ static bool qp_rgb565_surface_viewport(painter_device_t device, uint16_t left, u
// Stream pixel data to the current write position in GRAM
static bool qp_rgb565_surface_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
painter_driver_t * driver = (painter_driver_t *)device;
rgb565_surface_painter_device_t *surface = (rgb565_surface_painter_device_t *)driver;
stream_pixdata(surface, (const uint16_t *)pixel_data, native_pixel_count);
return true;
@ -170,7 +170,7 @@ static bool qp_rgb565_surface_append_pixdata(painter_device_t device, uint8_t *t
return true;
}
const struct painter_driver_vtable_t rgb565_surface_driver_vtable = {
const painter_driver_vtable_t rgb565_surface_driver_vtable = {
.init = qp_rgb565_surface_init,
.power = qp_rgb565_surface_power,
.clear = qp_rgb565_surface_clear,
@ -201,7 +201,7 @@ uint32_t qp_rgb565_surface_comms_send(painter_device_t device, const void *data,
return byte_count;
}
struct painter_comms_vtable_t rgb565_surface_driver_comms_vtable = {
painter_comms_vtable_t rgb565_surface_driver_comms_vtable = {
// These are all effective no-op's because they're not actually needed.
.comms_init = qp_rgb565_surface_comms_init,
.comms_start = qp_rgb565_surface_comms_start,
@ -234,7 +234,7 @@ painter_device_t qp_rgb565_make_surface(uint16_t panel_width, uint16_t panel_hei
// Drawing routine to copy out the dirty region and send it to another device
bool qp_rgb565_surface_draw(painter_device_t surface, painter_device_t display, uint16_t x, uint16_t y) {
struct painter_driver_t * surface_driver = (struct painter_driver_t *)surface;
painter_driver_t * surface_driver = (painter_driver_t *)surface;
rgb565_surface_painter_device_t *surface_handle = (rgb565_surface_painter_device_t *)surface_driver;
// If we're not dirty... we're done.

View File

@ -58,7 +58,7 @@ __attribute__((weak)) bool qp_ili9163_init(painter_device_t device, painter_rota
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable
const struct tft_panel_dc_reset_painter_driver_vtable_t ili9163_driver_vtable = {
const tft_panel_dc_reset_painter_driver_vtable_t ili9163_driver_vtable = {
.base =
{
.init = qp_ili9163_init,
@ -93,8 +93,8 @@ painter_device_t qp_ili9163_make_spi_device(uint16_t panel_width, uint16_t panel
for (uint32_t i = 0; i < ILI9163_NUM_DEVICES; ++i) {
tft_panel_dc_reset_painter_device_t *driver = &ili9163_drivers[i];
if (!driver->base.driver_vtable) {
driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ili9163_driver_vtable;
driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.driver_vtable = (const painter_driver_vtable_t *)&ili9163_driver_vtable;
driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.panel_width = panel_width;
driver->base.panel_height = panel_height;
driver->base.rotation = QP_ROTATION_0;

View File

@ -65,7 +65,7 @@ __attribute__((weak)) bool qp_ili9341_init(painter_device_t device, painter_rota
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable
const struct tft_panel_dc_reset_painter_driver_vtable_t ili9341_driver_vtable = {
const tft_panel_dc_reset_painter_driver_vtable_t ili9341_driver_vtable = {
.base =
{
.init = qp_ili9341_init,
@ -100,8 +100,8 @@ painter_device_t qp_ili9341_make_spi_device(uint16_t panel_width, uint16_t panel
for (uint32_t i = 0; i < ILI9341_NUM_DEVICES; ++i) {
tft_panel_dc_reset_painter_device_t *driver = &ili9341_drivers[i];
if (!driver->base.driver_vtable) {
driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ili9341_driver_vtable;
driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.driver_vtable = (const painter_driver_vtable_t *)&ili9341_driver_vtable;
driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.native_bits_per_pixel = 16; // RGB565
driver->base.panel_width = panel_width;
driver->base.panel_height = panel_height;

View File

@ -58,7 +58,7 @@ __attribute__((weak)) bool qp_ili9488_init(painter_device_t device, painter_rota
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable
const struct tft_panel_dc_reset_painter_driver_vtable_t ili9488_driver_vtable = {
const tft_panel_dc_reset_painter_driver_vtable_t ili9488_driver_vtable = {
.base =
{
.init = qp_ili9488_init,
@ -93,8 +93,8 @@ painter_device_t qp_ili9488_make_spi_device(uint16_t panel_width, uint16_t panel
for (uint32_t i = 0; i < ILI9488_NUM_DEVICES; ++i) {
tft_panel_dc_reset_painter_device_t *driver = &ili9488_drivers[i];
if (!driver->base.driver_vtable) {
driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ili9488_driver_vtable;
driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.driver_vtable = (const painter_driver_vtable_t *)&ili9488_driver_vtable;
driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.native_bits_per_pixel = 24; // RGB888
driver->base.panel_width = panel_width;
driver->base.panel_height = panel_height;

View File

@ -62,7 +62,7 @@ __attribute__((weak)) bool qp_ssd1351_init(painter_device_t device, painter_rota
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable
const struct tft_panel_dc_reset_painter_driver_vtable_t ssd1351_driver_vtable = {
const tft_panel_dc_reset_painter_driver_vtable_t ssd1351_driver_vtable = {
.base =
{
.init = qp_ssd1351_init,
@ -97,8 +97,8 @@ painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel
for (uint32_t i = 0; i < SSD1351_NUM_DEVICES; ++i) {
tft_panel_dc_reset_painter_device_t *driver = &ssd1351_drivers[i];
if (!driver->base.driver_vtable) {
driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ssd1351_driver_vtable;
driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.driver_vtable = (const painter_driver_vtable_t *)&ssd1351_driver_vtable;
driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.panel_width = panel_width;
driver->base.panel_height = panel_height;
driver->base.rotation = QP_ROTATION_0;

View File

@ -25,7 +25,7 @@ tft_panel_dc_reset_painter_device_t st7735_drivers[ST7735_NUM_DEVICES] = {0};
#ifndef ST7735_NO_AUTOMATIC_OFFSETS
static inline void st7735_automatic_viewport_offsets(painter_device_t device, painter_rotation_t rotation) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
// clang-format off
const struct {
@ -82,7 +82,7 @@ __attribute__((weak)) bool qp_st7735_init(painter_device_t device, painter_rotat
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable
const struct tft_panel_dc_reset_painter_driver_vtable_t st7735_driver_vtable = {
const tft_panel_dc_reset_painter_driver_vtable_t st7735_driver_vtable = {
.base =
{
.init = qp_st7735_init,
@ -117,8 +117,8 @@ painter_device_t qp_st7735_make_spi_device(uint16_t panel_width, uint16_t panel_
for (uint32_t i = 0; i < ST7735_NUM_DEVICES; ++i) {
tft_panel_dc_reset_painter_device_t *driver = &st7735_drivers[i];
if (!driver->base.driver_vtable) {
driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&st7735_driver_vtable;
driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.driver_vtable = (const painter_driver_vtable_t *)&st7735_driver_vtable;
driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.panel_width = panel_width;
driver->base.panel_height = panel_height;
driver->base.rotation = QP_ROTATION_0;

View File

@ -24,7 +24,7 @@ tft_panel_dc_reset_painter_device_t st7789_drivers[ST7789_NUM_DEVICES] = {0};
#ifndef ST7789_NO_AUTOMATIC_OFFSETS
static inline void st7789_automatic_viewport_offsets(painter_device_t device, painter_rotation_t rotation) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
// clang-format off
const struct {
@ -81,7 +81,7 @@ __attribute__((weak)) bool qp_st7789_init(painter_device_t device, painter_rotat
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable
const struct tft_panel_dc_reset_painter_driver_vtable_t st7789_driver_vtable = {
const tft_panel_dc_reset_painter_driver_vtable_t st7789_driver_vtable = {
.base =
{
.init = qp_st7789_init,
@ -116,8 +116,8 @@ painter_device_t qp_st7789_make_spi_device(uint16_t panel_width, uint16_t panel_
for (uint32_t i = 0; i < ST7789_NUM_DEVICES; ++i) {
tft_panel_dc_reset_painter_device_t *driver = &st7789_drivers[i];
if (!driver->base.driver_vtable) {
driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&st7789_driver_vtable;
driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.driver_vtable = (const painter_driver_vtable_t *)&st7789_driver_vtable;
driver->base.comms_vtable = (const painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
driver->base.panel_width = panel_width;
driver->base.panel_height = panel_height;
driver->base.rotation = QP_ROTATION_0;

View File

@ -12,15 +12,15 @@
// Power control
bool qp_tft_panel_power(painter_device_t device, bool power_on) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct tft_panel_dc_reset_painter_driver_vtable_t *vtable = (struct tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable;
painter_driver_t * driver = (painter_driver_t *)device;
tft_panel_dc_reset_painter_driver_vtable_t *vtable = (tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable;
qp_comms_command(device, power_on ? vtable->opcodes.display_on : vtable->opcodes.display_off);
return true;
}
// Screen clear
bool qp_tft_panel_clear(painter_device_t device) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
driver->driver_vtable->init(device, driver->rotation); // Re-init the LCD
return true;
}
@ -33,8 +33,8 @@ bool qp_tft_panel_flush(painter_device_t device) {
// Viewport to draw to
bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct tft_panel_dc_reset_painter_driver_vtable_t *vtable = (struct tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable;
painter_driver_t * driver = (painter_driver_t *)device;
tft_panel_dc_reset_painter_driver_vtable_t *vtable = (tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable;
// Fix up the drawing location if required
left += driver->offset_x;
@ -80,7 +80,7 @@ bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top,
// Stream pixel data to the current write position in GRAM
bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
qp_comms_send(device, pixel_data, native_pixel_count * driver->native_bits_per_pixel / 8);
return true;
}

View File

@ -12,8 +12,8 @@
// Common TFT panel implementation using D/C, and RST pins.
// Driver vtable with extras
struct tft_panel_dc_reset_painter_driver_vtable_t {
struct painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type
typedef struct tft_panel_dc_reset_painter_driver_vtable_t {
painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type
// Number of bytes for transmitting x/y coordinates
uint8_t num_window_bytes;
@ -29,16 +29,16 @@ struct tft_panel_dc_reset_painter_driver_vtable_t {
uint8_t set_row_address;
uint8_t enable_writes;
} opcodes;
};
} tft_panel_dc_reset_painter_driver_vtable_t;
// Device definition
typedef struct tft_panel_dc_reset_painter_device_t {
struct painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type
painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type
union {
#ifdef QUANTUM_PAINTER_SPI_ENABLE
// SPI-based configurables
struct qp_comms_spi_dc_reset_config_t spi_dc_reset_config;
qp_comms_spi_dc_reset_config_t spi_dc_reset_config;
#endif // QUANTUM_PAINTER_SPI_ENABLE
// TODO: I2C/parallel etc.

View File

@ -60,7 +60,7 @@ bool qp_lvgl_attach(painter_device_t device) {
qp_dprintf("qp_lvgl_start: entry\n");
qp_lvgl_detach();
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_lvgl_attach: fail (validation_ok == false)\n");
qp_lvgl_detach();

View File

@ -21,7 +21,7 @@
#define QFF_FONT_DESCRIPTOR_TYPEID 0x00
typedef struct __attribute__((packed)) qff_font_descriptor_v1_t {
typedef struct QP_PACKED qff_font_descriptor_v1_t {
qgf_block_header_v1_t header; // = { .type_id = 0x00, .neg_type_id = (~0x00), .length = 20 }
uint32_t magic : 24; // constant, equal to 0x464651 ("QFF")
uint8_t qff_version; // constant, equal to 0x01
@ -50,13 +50,13 @@ _Static_assert(sizeof(qff_font_descriptor_v1_t) == (sizeof(qgf_block_header_v1_t
#define QFF_GLYPH_OFFSET_BITS 18
#define QFF_GLYPH_OFFSET_MASK (((1 << QFF_GLYPH_OFFSET_BITS) - 1) << QFF_GLYPH_WIDTH_BITS)
typedef struct __attribute__((packed)) qff_ascii_glyph_v1_t {
typedef struct QP_PACKED qff_ascii_glyph_v1_t {
uint32_t value : 24; // Uses QFF_GLYPH_*_(BITS|MASK) as bitfield ordering is compiler-defined
} qff_ascii_glyph_v1_t;
_Static_assert(sizeof(qff_ascii_glyph_v1_t) == 3, "qff_ascii_glyph_v1_t must be 3 bytes in v1 of QFF");
typedef struct __attribute__((packed)) qff_ascii_glyph_table_v1_t {
typedef struct QP_PACKED qff_ascii_glyph_table_v1_t {
qgf_block_header_v1_t header; // = { .type_id = 0x01, .neg_type_id = (~0x01), .length = 285 }
qff_ascii_glyph_v1_t glyph[95]; // 95 glyphs, 0x20..0x7E
} qff_ascii_glyph_table_v1_t;
@ -68,14 +68,14 @@ _Static_assert(sizeof(qff_ascii_glyph_table_v1_t) == (sizeof(qgf_block_header_v1
#define QFF_UNICODE_GLYPH_DESCRIPTOR_TYPEID 0x02
typedef struct __attribute__((packed)) qff_unicode_glyph_v1_t {
typedef struct QP_PACKED qff_unicode_glyph_v1_t {
uint32_t code_point : 24;
uint32_t value : 24; // Uses QFF_GLYPH_*_(BITS|MASK) as bitfield ordering is compiler-defined
} qff_unicode_glyph_v1_t;
_Static_assert(sizeof(qff_unicode_glyph_v1_t) == 6, "qff_unicode_glyph_v1_t must be 6 bytes in v1 of QFF");
typedef struct __attribute__((packed)) qff_unicode_glyph_table_v1_t {
typedef struct QP_PACKED qff_unicode_glyph_table_v1_t {
qgf_block_header_v1_t header; // = { .type_id = 0x02, .neg_type_id = (~0x02), .length = (N * 6) }
qff_unicode_glyph_v1_t glyph[0]; // Extent of '0' signifies that this struct is immediately followed by the glyph data
} qff_unicode_glyph_table_v1_t;

View File

@ -11,15 +11,15 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal driver validation
static bool validate_driver_vtable(struct painter_driver_t *driver) {
static bool validate_driver_vtable(painter_driver_t *driver) {
return (driver->driver_vtable && driver->driver_vtable->init && driver->driver_vtable->power && driver->driver_vtable->clear && driver->driver_vtable->viewport && driver->driver_vtable->pixdata && driver->driver_vtable->palette_convert && driver->driver_vtable->append_pixels && driver->driver_vtable->append_pixdata) ? true : false;
}
static bool validate_comms_vtable(struct painter_driver_t *driver) {
static bool validate_comms_vtable(painter_driver_t *driver) {
return (driver->comms_vtable && driver->comms_vtable->comms_init && driver->comms_vtable->comms_start && driver->comms_vtable->comms_stop && driver->comms_vtable->comms_send) ? true : false;
}
static bool validate_driver_integrity(struct painter_driver_t *driver) {
static bool validate_driver_integrity(painter_driver_t *driver) {
return validate_driver_vtable(driver) && validate_comms_vtable(driver);
}
@ -28,7 +28,7 @@ static bool validate_driver_integrity(struct painter_driver_t *driver) {
bool qp_init(painter_device_t device, painter_rotation_t rotation) {
qp_dprintf("qp_init: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
driver->validate_ok = false;
if (!validate_driver_integrity(driver)) {
@ -64,7 +64,7 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) {
bool qp_power(painter_device_t device, bool power_on) {
qp_dprintf("qp_power: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_power: fail (validation_ok == false)\n");
return false;
@ -86,7 +86,7 @@ bool qp_power(painter_device_t device, bool power_on) {
bool qp_clear(painter_device_t device) {
qp_dprintf("qp_clear: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_clear: fail (validation_ok == false)\n");
return false;
@ -108,7 +108,7 @@ bool qp_clear(painter_device_t device) {
bool qp_flush(painter_device_t device) {
qp_dprintf("qp_flush: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_flush: fail (validation_ok == false)\n");
return false;
@ -130,7 +130,7 @@ bool qp_flush(painter_device_t device) {
void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height, painter_rotation_t *rotation, uint16_t *offset_x, uint16_t *offset_y) {
qp_dprintf("qp_geometry: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
switch (driver->rotation) {
default:
@ -174,7 +174,7 @@ void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height,
void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_t offset_y) {
qp_dprintf("qp_set_viewport_offsets: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
driver->offset_x = offset_x;
driver->offset_y = offset_y;
@ -187,7 +187,7 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_
bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) {
qp_dprintf("qp_viewport: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_viewport: fail (validation_ok == false)\n");
return false;
@ -210,7 +210,7 @@ bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t
bool qp_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) {
qp_dprintf("qp_pixdata: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_pixdata: fail (validation_ok == false)\n");
return false;

View File

@ -7,7 +7,7 @@
// Base comms APIs
bool qp_comms_init(painter_device_t device) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_comms_init: fail (validation_ok == false)\n");
return false;
@ -17,7 +17,7 @@ bool qp_comms_init(painter_device_t device) {
}
bool qp_comms_start(painter_device_t device) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_comms_start: fail (validation_ok == false)\n");
return false;
@ -27,7 +27,7 @@ bool qp_comms_start(painter_device_t device) {
}
void qp_comms_stop(painter_device_t device) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_comms_stop: fail (validation_ok == false)\n");
return;
@ -37,7 +37,7 @@ void qp_comms_stop(painter_device_t device) {
}
uint32_t qp_comms_send(painter_device_t device, const void *data, uint32_t byte_count) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_comms_send: fail (validation_ok == false)\n");
return false;
@ -50,8 +50,8 @@ uint32_t qp_comms_send(painter_device_t device, const void *data, uint32_t byte_
// Comms APIs that use a D/C pin
void qp_comms_command(painter_device_t device, uint8_t cmd) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct painter_comms_with_command_vtable_t *comms_vtable = (struct painter_comms_with_command_vtable_t *)driver->comms_vtable;
painter_driver_t * driver = (painter_driver_t *)device;
painter_comms_with_command_vtable_t *comms_vtable = (painter_comms_with_command_vtable_t *)driver->comms_vtable;
comms_vtable->send_command(device, cmd);
}
@ -66,7 +66,7 @@ uint32_t qp_comms_command_databuf(painter_device_t device, uint8_t cmd, const vo
}
void qp_comms_bulk_command_sequence(painter_device_t device, const uint8_t *sequence, size_t sequence_len) {
struct painter_driver_t * driver = (struct painter_driver_t *)device;
struct painter_comms_with_command_vtable_t *comms_vtable = (struct painter_comms_with_command_vtable_t *)driver->comms_vtable;
painter_driver_t * driver = (painter_driver_t *)device;
painter_comms_with_command_vtable_t *comms_vtable = (painter_comms_with_command_vtable_t *)driver->comms_vtable;
comms_vtable->bulk_command_sequence(device, sequence, sequence_len);
}

View File

@ -63,7 +63,7 @@ enum qp_internal_rle_mode_t {
NON_REPEATING_RUN,
};
struct qp_internal_byte_input_state {
typedef struct qp_internal_byte_input_state_t {
painter_device_t device;
qp_stream_t* src_stream;
int16_t curr;
@ -74,22 +74,22 @@ struct qp_internal_byte_input_state {
uint8_t remain; // number of bytes remaining in the current mode
} rle;
};
};
} qp_internal_byte_input_state_t;
struct qp_internal_pixel_output_state {
typedef struct qp_internal_pixel_output_state_t {
painter_device_t device;
uint32_t pixel_write_pos;
uint32_t max_pixels;
};
} qp_internal_pixel_output_state_t;
bool qp_internal_pixel_appender(qp_pixel_t* palette, uint8_t index, void* cb_arg);
struct qp_internal_byte_output_state {
typedef struct qp_internal_byte_output_state_t {
painter_device_t device;
uint32_t byte_write_pos;
uint32_t max_bytes;
};
} qp_internal_byte_output_state_t;
bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg);
qp_internal_byte_input_callback qp_internal_prepare_input_state(struct qp_internal_byte_input_state* input_state, painter_compression_t compression);
qp_internal_byte_input_callback qp_internal_prepare_input_state(qp_internal_byte_input_state_t* input_state, painter_compression_t compression);

View File

@ -127,7 +127,7 @@ static bool qp_circle_helper_impl(painter_device_t device, uint16_t centerx, uin
bool qp_circle(painter_device_t device, uint16_t x, uint16_t y, uint16_t radius, uint8_t hue, uint8_t sat, uint8_t val, bool filled) {
qp_dprintf("qp_circle: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_circle: fail (validation_ok == false)\n");
return false;

View File

@ -54,8 +54,8 @@ bool qp_internal_decode_grayscale(painter_device_t device, uint32_t pixel_count,
}
bool qp_internal_decode_recolor(painter_device_t device, uint32_t pixel_count, uint8_t bits_per_pixel, qp_internal_byte_input_callback input_callback, void* input_arg, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888, qp_internal_pixel_output_callback output_callback, void* output_arg) {
struct painter_driver_t* driver = (struct painter_driver_t*)device;
int16_t steps = 1 << bits_per_pixel; // number of items we need to interpolate
painter_driver_t* driver = (painter_driver_t*)device;
int16_t steps = 1 << bits_per_pixel; // number of items we need to interpolate
if (qp_internal_interpolate_palette(fg_hsv888, bg_hsv888, steps)) {
if (!driver->driver_vtable->palette_convert(device, steps, qp_internal_global_pixel_lookup_table)) {
return false;
@ -84,13 +84,13 @@ bool qp_internal_send_bytes(painter_device_t device, uint32_t byte_count, qp_int
// Progressive pull of bytes, push of pixels
static inline int16_t qp_drawimage_byte_uncompressed_decoder(void* cb_arg) {
struct qp_internal_byte_input_state* state = (struct qp_internal_byte_input_state*)cb_arg;
state->curr = qp_stream_get(state->src_stream);
qp_internal_byte_input_state_t* state = (qp_internal_byte_input_state_t*)cb_arg;
state->curr = qp_stream_get(state->src_stream);
return state->curr;
}
static inline int16_t qp_drawimage_byte_rle_decoder(void* cb_arg) {
struct qp_internal_byte_input_state* state = (struct qp_internal_byte_input_state*)cb_arg;
qp_internal_byte_input_state_t* state = (qp_internal_byte_input_state_t*)cb_arg;
// Work out if we're parsing the initial marker byte
if (state->rle.mode == MARKER_BYTE) {
@ -126,8 +126,8 @@ static inline int16_t qp_drawimage_byte_rle_decoder(void* cb_arg) {
}
bool qp_internal_pixel_appender(qp_pixel_t* palette, uint8_t index, void* cb_arg) {
struct qp_internal_pixel_output_state* state = (struct qp_internal_pixel_output_state*)cb_arg;
struct painter_driver_t* driver = (struct painter_driver_t*)state->device;
qp_internal_pixel_output_state_t* state = (qp_internal_pixel_output_state_t*)cb_arg;
painter_driver_t* driver = (painter_driver_t*)state->device;
if (!driver->driver_vtable->append_pixels(state->device, qp_internal_global_pixdata_buffer, palette, state->pixel_write_pos++, 1, &index)) {
return false;
@ -145,8 +145,8 @@ bool qp_internal_pixel_appender(qp_pixel_t* palette, uint8_t index, void* cb_arg
}
bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg) {
struct qp_internal_byte_output_state* state = (struct qp_internal_byte_output_state*)cb_arg;
struct painter_driver_t* driver = (struct painter_driver_t*)state->device;
qp_internal_byte_output_state_t* state = (qp_internal_byte_output_state_t*)cb_arg;
painter_driver_t* driver = (painter_driver_t*)state->device;
if (!driver->driver_vtable->append_pixdata(state->device, qp_internal_global_pixdata_buffer, state->byte_write_pos++, byteval)) {
return false;
@ -154,7 +154,7 @@ bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg) {
// If we've hit the transmit limit, send out the entire buffer and reset the write position
if (state->byte_write_pos == state->max_bytes) {
struct painter_driver_t* driver = (struct painter_driver_t*)state->device;
painter_driver_t* driver = (painter_driver_t*)state->device;
if (!driver->driver_vtable->pixdata(state->device, qp_internal_global_pixdata_buffer, state->byte_write_pos * 8 / driver->native_bits_per_pixel)) {
return false;
}
@ -164,7 +164,7 @@ bool qp_internal_byte_appender(uint8_t byteval, void* cb_arg) {
return true;
}
qp_internal_byte_input_callback qp_internal_prepare_input_state(struct qp_internal_byte_input_state* input_state, painter_compression_t compression) {
qp_internal_byte_input_callback qp_internal_prepare_input_state(qp_internal_byte_input_state_t* input_state, painter_compression_t compression) {
switch (compression) {
case IMAGE_UNCOMPRESSED:
return qp_drawimage_byte_uncompressed_decoder;

View File

@ -37,21 +37,21 @@ __attribute__((__aligned__(4))) qp_pixel_t qp_internal_global_pixel_lookup_table
// Helpers
uint32_t qp_internal_num_pixels_in_buffer(painter_device_t device) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
return ((QUANTUM_PAINTER_PIXDATA_BUFFER_SIZE * 8) / driver->native_bits_per_pixel);
}
// qp_setpixel internal implementation, but accepts a buffer with pre-converted native pixel. Only the first pixel is used.
bool qp_internal_setpixel_impl(painter_device_t device, uint16_t x, uint16_t y) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
return driver->driver_vtable->viewport(device, x, y, x, y) && driver->driver_vtable->pixdata(device, qp_internal_global_pixdata_buffer, 1);
}
// Fills the global native pixel buffer with equivalent pixels matching the supplied HSV
void qp_internal_fill_pixdata(painter_device_t device, uint32_t num_pixels, uint8_t hue, uint8_t sat, uint8_t val) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device);
num_pixels = QP_MIN(pixels_in_pixdata, num_pixels);
painter_driver_t *driver = (painter_driver_t *)device;
uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device);
num_pixels = QP_MIN(pixels_in_pixdata, num_pixels);
// Convert the color to native pixel format
qp_pixel_t color = {.hsv888 = {.h = hue, .s = sat, .v = val}};
@ -144,7 +144,7 @@ bool qp_internal_load_qgf_palette(qp_stream_t *stream, uint8_t bpp) {
// Quantum Painter External API: qp_setpixel
bool qp_setpixel(painter_device_t device, uint16_t x, uint16_t y, uint8_t hue, uint8_t sat, uint8_t val) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_setpixel: fail (validation_ok == false)\n");
return false;
@ -174,7 +174,7 @@ bool qp_line(painter_device_t device, uint16_t x0, uint16_t y0, uint16_t x1, uin
}
qp_dprintf("qp_line(%d, %d, %d, %d): entry\n", (int)x0, (int)y0, (int)x1, (int)y1);
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_line: fail (validation_ok == false)\n");
return false;
@ -228,8 +228,8 @@ bool qp_line(painter_device_t device, uint16_t x0, uint16_t y0, uint16_t x1, uin
// Quantum Painter External API: qp_rect
bool qp_internal_fillrect_helper_impl(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) {
uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device);
struct painter_driver_t *driver = (struct painter_driver_t *)device;
uint32_t pixels_in_pixdata = qp_internal_num_pixels_in_buffer(device);
painter_driver_t *driver = (painter_driver_t *)device;
uint16_t l = QP_MIN(left, right);
uint16_t r = QP_MAX(left, right);
@ -252,7 +252,7 @@ bool qp_internal_fillrect_helper_impl(painter_device_t device, uint16_t left, ui
bool qp_rect(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint8_t hue, uint8_t sat, uint8_t val, bool filled) {
qp_dprintf("qp_rect(%d, %d, %d, %d): entry\n", (int)left, (int)top, (int)right, (int)bottom);
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_rect: fail (validation_ok == false)\n");
return false;

View File

@ -61,7 +61,7 @@ static bool qp_ellipse_helper_impl(painter_device_t device, uint16_t centerx, ui
bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex, uint16_t sizey, uint8_t hue, uint8_t sat, uint8_t val, bool filled) {
qp_dprintf("qp_ellipse: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_ellipse: fail (validation_ok == false)\n");
return false;

View File

@ -124,7 +124,7 @@ typedef struct qgf_frame_info_t {
} qgf_frame_info_t;
static bool qp_drawimage_prepare_frame_for_stream_read(painter_device_t device, qgf_image_handle_t *qgf_image, uint16_t frame_number, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888, qgf_frame_info_t *info) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
// Drop out if we can't actually place the data we read out anywhere
if (!info) {
@ -209,7 +209,7 @@ static bool qp_drawimage_prepare_frame_for_stream_read(painter_device_t device,
static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint16_t y, painter_image_handle_t image, int frame_number, qgf_frame_info_t *frame_info, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888) {
qp_dprintf("qp_drawimage_recolor: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_drawimage_recolor: fail (validation_ok == false)\n");
return false;
@ -254,8 +254,8 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1
}
// Set up the input state
struct qp_internal_byte_input_state input_state = {.device = device, .src_stream = &qgf_image->stream};
qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, frame_info->compression_scheme);
qp_internal_byte_input_state_t input_state = {.device = device, .src_stream = &qgf_image->stream};
qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, frame_info->compression_scheme);
if (input_callback == NULL) {
qp_dprintf("qp_drawimage_recolor: fail (invalid image compression scheme)\n");
qp_comms_stop(device);
@ -265,7 +265,7 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1
bool ret = false;
if (frame_info->bpp <= 8) {
// Set up the output state
struct qp_internal_pixel_output_state output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)};
qp_internal_pixel_output_state_t output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)};
// Decode the pixel data and stream to the display
ret = qp_internal_decode_palette(device, pixel_count, frame_info->bpp, input_callback, &input_state, qp_internal_global_pixel_lookup_table, qp_internal_pixel_appender, &output_state);
@ -275,7 +275,7 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1
}
} else {
// Set up the output state
struct qp_internal_byte_output_state output_state = {.device = device, .byte_write_pos = 0, .max_bytes = qp_internal_num_pixels_in_buffer(device) * driver->native_bits_per_pixel / 8};
qp_internal_byte_output_state_t output_state = {.device = device, .byte_write_pos = 0, .max_bytes = qp_internal_num_pixels_in_buffer(device) * driver->native_bits_per_pixel / 8};
// Stream the raw pixel data to the display
uint32_t byte_count = pixel_count * frame_info->bpp / 8;

View File

@ -164,7 +164,7 @@ typedef bool (*code_point_handler)(qff_font_handle_t *qff_font, uint32_t code_po
// Helper that sets up the palette (if required) and returns the offset in the stream that the data starts
static inline bool qp_drawtext_prepare_font_for_render(painter_device_t device, qff_font_handle_t *qff_font, qp_pixel_t fg_hsv888, qp_pixel_t bg_hsv888, uint32_t *data_offset) {
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
// Drop out if we can't actually place the data we read out anywhere
if (!data_offset) {
@ -319,13 +319,13 @@ static inline bool qp_iterate_code_points(qff_font_handle_t *qff_font, const cha
// String width calculation
// Callback state
struct code_point_iter_calcwidth_state {
typedef struct code_point_iter_calcwidth_state_t {
int16_t width;
};
} code_point_iter_calcwidth_state_t;
// Codepoint handler callback: width calc
static inline bool qp_font_code_point_handler_calcwidth(qff_font_handle_t *qff_font, uint32_t code_point, uint8_t width, uint8_t height, void *cb_arg) {
struct code_point_iter_calcwidth_state *state = (struct code_point_iter_calcwidth_state *)cb_arg;
code_point_iter_calcwidth_state_t *state = (code_point_iter_calcwidth_state_t *)cb_arg;
// Increment the overall width by this glyph's width
state->width += width;
@ -337,19 +337,19 @@ static inline bool qp_font_code_point_handler_calcwidth(qff_font_handle_t *qff_f
// String drawing implementation
// Callback state
struct code_point_iter_drawglyph_state {
painter_device_t device;
int16_t xpos;
int16_t ypos;
qp_internal_byte_input_callback input_callback;
struct qp_internal_byte_input_state * input_state;
struct qp_internal_pixel_output_state *output_state;
};
typedef struct code_point_iter_drawglyph_state_t {
painter_device_t device;
int16_t xpos;
int16_t ypos;
qp_internal_byte_input_callback input_callback;
qp_internal_byte_input_state_t * input_state;
qp_internal_pixel_output_state_t *output_state;
} code_point_iter_drawglyph_state_t;
// Codepoint handler callback: drawing
static inline bool qp_font_code_point_handler_drawglyph(qff_font_handle_t *qff_font, uint32_t code_point, uint8_t width, uint8_t height, void *cb_arg) {
struct code_point_iter_drawglyph_state *state = (struct code_point_iter_drawglyph_state *)cb_arg;
struct painter_driver_t * driver = (struct painter_driver_t *)state->device;
code_point_iter_drawglyph_state_t *state = (code_point_iter_drawglyph_state_t *)cb_arg;
painter_driver_t * driver = (painter_driver_t *)state->device;
// Reset the input state's RLE mode -- the stream should already be correctly positioned by qp_iterate_code_points()
state->input_state->rle.mode = MARKER_BYTE; // ignored if not using RLE
@ -386,7 +386,7 @@ int16_t qp_textwidth(painter_font_handle_t font, const char *str) {
}
// Create the codepoint iterator state
struct code_point_iter_calcwidth_state state = {.width = 0};
code_point_iter_calcwidth_state_t state = {.width = 0};
// Iterate each codepoint, return the calculated width if successful.
return qp_iterate_code_points(qff_font, str, qp_font_code_point_handler_calcwidth, &state) ? state.width : 0;
}
@ -405,7 +405,7 @@ int16_t qp_drawtext(painter_device_t device, uint16_t x, uint16_t y, painter_fon
int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, painter_font_handle_t font, const char *str, uint8_t hue_fg, uint8_t sat_fg, uint8_t val_fg, uint8_t hue_bg, uint8_t sat_bg, uint8_t val_bg) {
qp_dprintf("qp_drawtext_recolor: entry\n");
struct painter_driver_t *driver = (struct painter_driver_t *)device;
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver->validate_ok) {
qp_dprintf("qp_drawtext_recolor: fail (validation_ok == false)\n");
return 0;
@ -423,8 +423,8 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai
}
// Set up the byte input state and input callback
struct qp_internal_byte_input_state input_state = {.device = device, .src_stream = &qff_font->stream};
qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, qff_font->compression_scheme);
qp_internal_byte_input_state_t input_state = {.device = device, .src_stream = &qff_font->stream};
qp_internal_byte_input_callback input_callback = qp_internal_prepare_input_state(&input_state, qff_font->compression_scheme);
if (input_callback == NULL) {
qp_dprintf("qp_drawtext_recolor: fail (invalid font compression scheme)\n");
qp_comms_stop(device);
@ -432,18 +432,18 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai
}
// Set up the pixel output state
struct qp_internal_pixel_output_state output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)};
qp_internal_pixel_output_state_t output_state = {.device = device, .pixel_write_pos = 0, .max_pixels = qp_internal_num_pixels_in_buffer(device)};
// Set up the codepoint iteration state
struct code_point_iter_drawglyph_state state = {// Common
.device = device,
.xpos = x,
.ypos = y,
// Input
.input_callback = input_callback,
.input_state = &input_state,
// Output
.output_state = &output_state};
code_point_iter_drawglyph_state_t state = {// Common
.device = device,
.xpos = x,
.ypos = y,
// Input
.input_callback = input_callback,
.input_state = &input_state,
// Output
.output_state = &output_state};
qp_pixel_t fg_hsv888 = {.hsv888 = {.h = hue_fg, .s = sat_fg, .v = val_fg}};
qp_pixel_t bg_hsv888 = {.hsv888 = {.h = hue_bg, .s = sat_bg, .v = val_bg}};

View File

@ -19,7 +19,7 @@ typedef bool (*painter_driver_append_pixels)(painter_device_t device, uint8_t *t
typedef bool (*painter_driver_append_pixdata)(painter_device_t device, uint8_t *target_buffer, uint32_t pixdata_offset, uint8_t pixdata_byte);
// Driver vtable definition
struct painter_driver_vtable_t {
typedef struct painter_driver_vtable_t {
painter_driver_init_func init;
painter_driver_power_func power;
painter_driver_clear_func clear;
@ -29,7 +29,7 @@ struct painter_driver_vtable_t {
painter_driver_convert_palette_func palette_convert;
painter_driver_append_pixels append_pixels;
painter_driver_append_pixdata append_pixdata;
};
} painter_driver_vtable_t;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Comms callbacks
@ -39,28 +39,28 @@ typedef bool (*painter_driver_comms_start_func)(painter_device_t device);
typedef void (*painter_driver_comms_stop_func)(painter_device_t device);
typedef uint32_t (*painter_driver_comms_send_func)(painter_device_t device, const void *data, uint32_t byte_count);
struct painter_comms_vtable_t {
typedef struct painter_comms_vtable_t {
painter_driver_comms_init_func comms_init;
painter_driver_comms_start_func comms_start;
painter_driver_comms_stop_func comms_stop;
painter_driver_comms_send_func comms_send;
};
} painter_comms_vtable_t;
typedef void (*painter_driver_comms_send_command_func)(painter_device_t device, uint8_t cmd);
typedef void (*painter_driver_comms_bulk_command_sequence)(painter_device_t device, const uint8_t *sequence, size_t sequence_len);
struct painter_comms_with_command_vtable_t {
struct painter_comms_vtable_t base; // must be first, so this object can be cast from the painter_comms_vtable_t* type
typedef struct painter_comms_with_command_vtable_t {
painter_comms_vtable_t base; // must be first, so this object can be cast from the painter_comms_vtable_t* type
painter_driver_comms_send_command_func send_command;
painter_driver_comms_bulk_command_sequence bulk_command_sequence;
};
} painter_comms_with_command_vtable_t;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver base definition
struct painter_driver_t {
const struct painter_driver_vtable_t *driver_vtable;
const struct painter_comms_vtable_t * comms_vtable;
typedef struct painter_driver_t {
const painter_driver_vtable_t *driver_vtable;
const painter_comms_vtable_t * comms_vtable;
// Flag signifying if validation was successful
bool validate_ok;
@ -81,7 +81,7 @@ struct painter_driver_t {
// Comms config pointer -- needs to point to an appropriate comms config if the comms driver requires it.
void *comms_config;
};
} painter_driver_t;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Device internals

View File

@ -48,14 +48,14 @@ uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint3
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Stream definition
struct qp_stream_t {
typedef struct qp_stream_t {
int16_t (*get)(qp_stream_t *stream);
bool (*put)(qp_stream_t *stream, uint8_t c);
int (*seek)(qp_stream_t *stream, int32_t offset, int origin);
int32_t (*tell)(qp_stream_t *stream);
bool (*is_eof)(qp_stream_t *stream);
void (*close)(qp_stream_t *stream);
};
} qp_stream_t;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Memory streams