Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QP] Color inversion control functions. #22098

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/quantum_painter.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,17 @@ void housekeeping_task_user(void) {
}
```

#### ** Display Color Inversion **

```c
bool qp_gc9a01_set_inversion(painter_device_t device, bool invert);
bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert);
bool qp_ssd1351_set_inversion(painter_device_t device, bool invert);
bool qp_st77xx_set_inversion(painter_device_t device, bool invert);
```

This set of functions allow changing the inversion (ie: red is drawn blue, and so on) of a display, this may be needed when the default init sequence for a device does not match your hardware.

<!-- tabs:end -->

### ** Drawing Primitives **
Expand Down
14 changes: 14 additions & 0 deletions drivers/painter/gc9a01/qp_gc9a01.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ __attribute__((weak)) bool qp_gc9a01_init(painter_device_t device, painter_rotat
return true;
}

bool qp_gc9a01_set_inversion(painter_device_t device, bool invert) {
if (!device) {
qp_dprintf("qp_gc9a01_set_inversion: fail (un-initialized device handle)\n");
return false;
}

qp_comms_start(device);
qp_comms_command(device, invert ? GC9A01_CMD_INVERT_ON : GC9A01_CMD_INVERT_OFF);
qp_comms_stop(device);

qp_dprintf("qp_gc9a01_set_inversion: ok\n");
return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 9 additions & 0 deletions drivers/painter/gc9a01/qp_gc9a01.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@
*/
painter_device_t qp_gc9a01_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode);
#endif // QUANTUM_PAINTER_GC9A01_SPI_ENABLE

/**
* Function to control color inversion on a GC9A01 device.
*
* @param device[in] device handle to operate on.
* @param invert[in] whether to invert colors or not.
* @return Whether the operation was successful.
*/
bool qp_gc9a01_set_inversion(painter_device_t device, bool invert);
19 changes: 19 additions & 0 deletions drivers/painter/ili9xxx/qp_ili9xxx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 Pablo Martinez (@elpekenin) <elpekenin@elpekenin.dev>
// SPDX-License-Identifier: GPL-2.0-or-later

#include "qp_comms.h"
#include "qp_ili9xxx_opcodes.h"

bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert) {
if (!device) {
qp_dprintf("qp_ili9xxx_set_inversion: fail (un-initialized device handle)\n");
return false;
}

qp_comms_start(device);
qp_comms_command(device, invert ? ILI9XXX_CMD_INVERT_ON : ILI9XXX_CMD_INVERT_OFF);
qp_comms_stop(device);

qp_dprintf("qp_ili9xxx_set_inversion: ok\n");
return true;
}
15 changes: 15 additions & 0 deletions drivers/painter/ili9xxx/qp_ili9xxx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 Pablo Martinez (@elpekenin) <elpekenin@elpekenin.dev>
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "qp.h"

/**
* Function to control color inversion on a ILI9XXX device.
*
* @param device[in] device handle to operate on.
* @param invert[in] whether to invert colors or not.
* @return Whether the operation was successful.
*/
bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert);
14 changes: 14 additions & 0 deletions drivers/painter/ssd1351/qp_ssd1351.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ __attribute__((weak)) bool qp_ssd1351_init(painter_device_t device, painter_rota
return true;
}

bool qp_ssd1351_set_inversion(painter_device_t device, bool invert) {
if (!device) {
qp_dprintf("qp_ssd1351_set_inversion: fail (un-initialized device handle)\n");
return false;
}

qp_comms_start(device);
qp_comms_command(device, invert ? SSD1351_INVERTDISPLAY : SSD1351_NORMALDISPLAY);
qp_comms_stop(device);

qp_dprintf("qp_ssd1351_set_inversion: ok\n");
return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Driver vtable

Expand Down
9 changes: 9 additions & 0 deletions drivers/painter/ssd1351/qp_ssd1351.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@
*/
painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode);
#endif // QUANTUM_PAINTER_SSD1351_SPI_ENABLE

/**
* Function to control color inversion on a SSD1351 device.
*
* @param device[in] device handle to operate on.
* @param invert[in] whether to invert colors or not.
* @return Whether the operation was successful.
*/
bool qp_ssd1351_set_inversion(painter_device_t device, bool invert);
19 changes: 19 additions & 0 deletions drivers/painter/st77xx/qp_st77xx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 Pablo Martinez (@elpekenin) <elpekenin@elpekenin.dev>
// SPDX-License-Identifier: GPL-2.0-or-later

#include "qp_comms.h"
#include "qp_st77xx_opcodes.h"

bool qp_st77xx_set_inversion(painter_device_t device, bool invert) {
if (!device) {
qp_dprintf("qp_st77xx_set_inversion: fail (un-initialized device handle)\n");
return false;
}

qp_comms_start(device);
qp_comms_command(device, invert ? ST77XX_CMD_INVERT_ON : ST77XX_CMD_INVERT_OFF);
qp_comms_stop(device);

qp_dprintf("qp_st77xx_set_inversion: ok\n");
return true;
}
15 changes: 15 additions & 0 deletions drivers/painter/st77xx/qp_st77xx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 Pablo Martinez (@elpekenin) <elpekenin@elpekenin.dev>
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "qp.h"

/**
* Function to control color inversion on a ST77XX device.
*
* @param device[in] device handle to operate on.
* @param invert[in] whether to invert colors or not.
* @return Whether the operation was successful.
*/
bool qp_st77xx_set_inversion(painter_device_t device, bool invert);
2 changes: 1 addition & 1 deletion quantum/painter/lvgl/qp_lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool qp_lvgl_attach(painter_device_t device) {

painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_lvgl_attach: fail (validation_ok == false)\n");
qp_dprintf("qp_lvgl_attach: fail (bad device handle)\n");
qp_lvgl_detach();
return false;
}
Expand Down
14 changes: 7 additions & 7 deletions quantum/painter/qp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) {
painter_driver_t *driver = (painter_driver_t *)device;

if (!driver) {
qp_dprintf("qp_init: fail (pointer to NULL)\n");
qp_dprintf("qp_init: fail (un-initialized device handle)\n");
return false;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ bool qp_power(painter_device_t device, bool power_on) {
qp_dprintf("qp_power: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_power: fail (validation_ok == false)\n");
qp_dprintf("qp_power: fail (bad device handle)\n");
return false;
}

Expand All @@ -93,7 +93,7 @@ bool qp_clear(painter_device_t device) {
qp_dprintf("qp_clear: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_clear: fail (validation_ok == false)\n");
qp_dprintf("qp_clear: fail (bad device handle)\n");
return false;
}

Expand All @@ -115,7 +115,7 @@ bool qp_flush(painter_device_t device) {
qp_dprintf("qp_flush: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_flush: fail (validation_ok == false)\n");
qp_dprintf("qp_flush: fail (bad device handle)\n");
return false;
}

Expand Down Expand Up @@ -264,7 +264,7 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_
painter_driver_t *driver = (painter_driver_t *)device;

if (!driver) {
qp_dprintf("qp_set_viewport_offsets: fail (pointer to NULL)\n");
qp_dprintf("qp_set_viewport_offsets: fail (un-initialized device handle)\n");
return;
}

Expand All @@ -281,7 +281,7 @@ bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t
qp_dprintf("qp_viewport: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_viewport: fail (validation_ok == false)\n");
qp_dprintf("qp_viewport: fail (bad device handle)\n");
return false;
}

Expand All @@ -304,7 +304,7 @@ bool qp_pixdata(painter_device_t device, const void *pixel_data, uint32_t native
qp_dprintf("qp_pixdata: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_pixdata: fail (validation_ok == false)\n");
qp_dprintf("qp_pixdata: fail (bad device handle)\n");
return false;
}

Expand Down
11 changes: 11 additions & 0 deletions quantum/painter/qp.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,17 @@ 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);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter Families

#ifdef QUANTUM_PAINTER_ILI9XXX_ENABLE
# include "qp_ili9xxx.h"
#endif // QUANTUM_PAINTER_ILI9XXX_ENABLE

#ifdef QUANTUM_PAINTER_ST77XX_ENABLE
# include "qp_st77xx.h"
#endif // QUANTUM_PAINTER_ST77XX_ENABLE

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter Drivers

Expand Down
8 changes: 4 additions & 4 deletions quantum/painter/qp_comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
bool qp_comms_init(painter_device_t device) {
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_comms_init: fail (validation_ok == false)\n");
qp_dprintf("qp_comms_init: fail (bad device handle)\n");
return false;
}

Expand All @@ -19,7 +19,7 @@ bool qp_comms_init(painter_device_t device) {
bool qp_comms_start(painter_device_t device) {
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_comms_start: fail (validation_ok == false)\n");
qp_dprintf("qp_comms_start: fail (bad device handle)\n");
return false;
}

Expand All @@ -29,7 +29,7 @@ bool qp_comms_start(painter_device_t device) {
void qp_comms_stop(painter_device_t device) {
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_comms_stop: fail (validation_ok == false)\n");
qp_dprintf("qp_comms_stop: fail (bad device handle)\n");
return;
}

Expand All @@ -39,7 +39,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) {
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_comms_send: fail (validation_ok == false)\n");
qp_dprintf("qp_comms_send: fail (bad device handle)\n");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/painter/qp_draw_circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool qp_circle(painter_device_t device, uint16_t x, uint16_t y, uint16_t radius,
qp_dprintf("qp_circle: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_circle: fail (validation_ok == false)\n");
qp_dprintf("qp_circle: fail (bad device handle)\n");
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions quantum/painter/qp_draw_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool qp_internal_load_qgf_palette(qp_stream_t *stream, uint8_t bpp) {
bool qp_setpixel(painter_device_t device, uint16_t x, uint16_t y, uint8_t hue, uint8_t sat, uint8_t val) {
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_setpixel: fail (validation_ok == false)\n");
qp_dprintf("qp_setpixel: fail (bad device handle)\n");
return false;
}

Expand Down Expand Up @@ -176,7 +176,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);
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_line: fail (validation_ok == false)\n");
qp_dprintf("qp_line: fail (bad device handle)\n");
return false;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ bool qp_rect(painter_device_t device, uint16_t left, uint16_t top, uint16_t righ
qp_dprintf("qp_rect(%d, %d, %d, %d): entry\n", (int)left, (int)top, (int)right, (int)bottom);
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_rect: fail (validation_ok == false)\n");
qp_dprintf("qp_rect: fail (bad device handle)\n");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/painter/qp_draw_ellipse.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex,
qp_dprintf("qp_ellipse: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_ellipse: fail (validation_ok == false)\n");
qp_dprintf("qp_ellipse: fail (bad device handle)\n");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/painter/qp_draw_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1
qp_dprintf("qp_drawimage_recolor: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_drawimage_recolor: fail (validation_ok == false)\n");
qp_dprintf("qp_drawimage_recolor: fail (bad device handle)\n");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/painter/qp_draw_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai
qp_dprintf("qp_drawtext_recolor: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
if (!driver || !driver->validate_ok) {
qp_dprintf("qp_drawtext_recolor: fail (validation_ok == false)\n");
qp_dprintf("qp_drawtext_recolor: fail (bad device handle)\n");
return 0;
}

Expand Down
Loading