diff options
Diffstat (limited to 'quantum/painter')
-rw-r--r-- | quantum/painter/lvgl/qp_lvgl.c | 11 | ||||
-rw-r--r-- | quantum/painter/lvgl/qp_lvgl.h | 4 | ||||
-rw-r--r-- | quantum/painter/qp.c | 121 | ||||
-rw-r--r-- | quantum/painter/qp.h | 35 | ||||
-rw-r--r-- | quantum/painter/qp_draw_ellipse.c | 12 |
5 files changed, 149 insertions, 34 deletions
diff --git a/quantum/painter/lvgl/qp_lvgl.c b/quantum/painter/lvgl/qp_lvgl.c index 280aeaf91f..877b2652c6 100644 --- a/quantum/painter/lvgl/qp_lvgl.c +++ b/quantum/painter/lvgl/qp_lvgl.c @@ -81,8 +81,8 @@ bool qp_lvgl_attach(painter_device_t device) { lvgl_state_t *lv_task_handler_state = &lvgl_states[1]; lv_task_handler_state->fnc_id = 1; - lv_task_handler_state->delay_ms = 5; - lv_task_handler_state->defer_token = defer_exec_advanced(lvgl_executors, 2, 5, tick_task_callback, lv_task_handler_state); + lv_task_handler_state->delay_ms = QP_LVGL_TASK_PERIOD; + lv_task_handler_state->defer_token = defer_exec_advanced(lvgl_executors, 2, QP_LVGL_TASK_PERIOD, tick_task_callback, lv_task_handler_state); if (lv_task_handler_state->defer_token == INVALID_DEFERRED_TOKEN) { qp_dprintf("qp_lvgl_attach: fail (could not set up qp_lvgl executor)\n"); @@ -96,13 +96,14 @@ bool qp_lvgl_attach(painter_device_t device) { // Set up lvgl display buffer static lv_disp_draw_buf_t draw_buf; // Allocate a buffer for 1/10 screen size - const size_t count_required = driver->panel_width * driver->panel_height / 10; - color_buffer = color_buffer ? realloc(color_buffer, sizeof(lv_color_t) * count_required) : malloc(sizeof(lv_color_t) * count_required); - if (!color_buffer) { + const size_t count_required = driver->panel_width * driver->panel_height / 10; + void * new_color_buffer = realloc(color_buffer, sizeof(lv_color_t) * count_required); + if (!new_color_buffer) { qp_dprintf("qp_lvgl_attach: fail (could not set up memory buffer)\n"); qp_lvgl_detach(); return false; } + color_buffer = new_color_buffer; memset(color_buffer, 0, sizeof(lv_color_t) * count_required); // Initialize the display buffer. lv_disp_draw_buf_init(&draw_buf, color_buffer, NULL, count_required); diff --git a/quantum/painter/lvgl/qp_lvgl.h b/quantum/painter/lvgl/qp_lvgl.h index d9ad5e8df1..87ba3ac0a5 100644 --- a/quantum/painter/lvgl/qp_lvgl.h +++ b/quantum/painter/lvgl/qp_lvgl.h @@ -7,6 +7,10 @@ #include "qp.h" #include "lvgl.h" +#ifndef QP_LVGL_TASK_PERIOD +# define QP_LVGL_TASK_PERIOD 5 +#endif + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Quantum Painter - LVGL External API diff --git a/quantum/painter/qp.c b/quantum/painter/qp.c index f27bb7892a..609163afe2 100644 --- a/quantum/painter/qp.c +++ b/quantum/painter/qp.c @@ -131,49 +131,124 @@ bool qp_flush(painter_device_t device) { } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Quantum Painter External API: qp_get_geometry +// Quantum Painter External API: qp_get_* -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_get_geometry: entry\n"); +uint16_t qp_get_width(painter_device_t device) { + qp_dprintf("qp_get_width: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; - if (!driver) { - qp_dprintf("qp_get_geometry: fail (pointer to NULL)\n"); - return; + if (!driver || !driver->validate_ok) { + qp_dprintf("qp_get_width: fail (invalid driver)\n"); + return 0; + } + + uint16_t width; + switch (driver->rotation) { + default: + case QP_ROTATION_0: + case QP_ROTATION_180: + width = driver->panel_width; + + case QP_ROTATION_90: + case QP_ROTATION_270: + width = driver->panel_height; + } + + qp_dprintf("qp_get_width: ok\n"); + return width; +} + +uint16_t qp_get_height(painter_device_t device) { + qp_dprintf("qp_get_height: entry\n"); + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver || !driver->validate_ok) { + qp_dprintf("qp_get_height: fail (invalid driver)\n"); + return 0; } + uint16_t height; switch (driver->rotation) { default: case QP_ROTATION_0: case QP_ROTATION_180: - if (width) { - *width = driver->panel_width; - } - if (height) { - *height = driver->panel_height; - } - break; + height = driver->panel_height; + case QP_ROTATION_90: case QP_ROTATION_270: - if (width) { - *width = driver->panel_height; - } - if (height) { - *height = driver->panel_width; - } - break; + height = driver->panel_width; + } + + qp_dprintf("qp_get_height: ok\n"); + return height; +} + +painter_rotation_t qp_get_rotation(painter_device_t device) { + qp_dprintf("qp_get_rotation: entry\n"); + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver || !driver->validate_ok) { + qp_dprintf("qp_get_rotation: fail (invalid driver)\n"); + return QP_ROTATION_0; + } + + qp_dprintf("qp_get_rotation: ok\n"); + return driver->rotation; +} + +uint16_t qp_get_offset_x(painter_device_t device) { + qp_dprintf("qp_get_offset_x: entry\n"); + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver || !driver->validate_ok) { + qp_dprintf("qp_get_offset_x: fail (invalid driver)\n"); + return 0; + } + + qp_dprintf("qp_get_offset_x: ok\n"); + return driver->offset_x; +} + +uint16_t qp_get_offset_y(painter_device_t device) { + qp_dprintf("qp_get_offset_y: entry\n"); + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver || !driver->validate_ok) { + qp_dprintf("qp_get_offset_y: fail (invalid driver)\n"); + return 0; + } + + qp_dprintf("qp_get_offset_y: ok\n"); + return driver->offset_y; +} + +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"); + painter_driver_t *driver = (painter_driver_t *)device; + + if (!driver || !driver->validate_ok) { + qp_dprintf("qp_geometry: fail (invalid driver)\n"); + return; + } + + if (width) { + *width = qp_get_width(device); + } + + if (height) { + *height = qp_get_height(device); } if (rotation) { - *rotation = driver->rotation; + *rotation = qp_get_rotation(device); } if (offset_x) { - *offset_x = driver->offset_x; + *offset_x = qp_get_offset_x(device); } if (offset_y) { - *offset_y = driver->offset_y; + *offset_y = qp_get_offset_y(device); } qp_dprintf("qp_get_geometry: ok\n"); diff --git a/quantum/painter/qp.h b/quantum/painter/qp.h index 7222d3b413..68cb40aa59 100644 --- a/quantum/painter/qp.h +++ b/quantum/painter/qp.h @@ -176,6 +176,41 @@ bool qp_clear(painter_device_t device); bool qp_flush(painter_device_t device); /** + * Retrieves the width of the display. + * + * @param device[in] the handle of the device to control + */ +uint16_t qp_get_width(painter_device_t device); + +/** + * Retrieves the height of the display. + * + * @param device[in] the handle of the device to control + */ +uint16_t qp_get_height(painter_device_t device); + +/** + * Retrieves the rotation of the display. + * + * @param device[in] the handle of the device to control + */ +painter_rotation_t qp_get_rotation(painter_device_t device); + +/** + * Retrieves the x-offset of the display. + * + * @param device[in] the handle of the device to control + */ +uint16_t qp_get_offset_x(painter_device_t device); + +/** + * Retrieves the y-offset of the display. + * + * @param device[in] the handle of the device to control + */ +uint16_t qp_get_offset_y(painter_device_t device); + +/** * Retrieves the size, rotation, and offsets for the display. * * @note Any arguments of NULL will be ignored. diff --git a/quantum/painter/qp_draw_ellipse.c b/quantum/painter/qp_draw_ellipse.c index e912a3e91f..9e77bca8b0 100644 --- a/quantum/painter/qp_draw_ellipse.c +++ b/quantum/painter/qp_draw_ellipse.c @@ -67,10 +67,10 @@ bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex, return false; } - int16_t aa = ((int16_t)sizex) * ((int16_t)sizex); - int16_t bb = ((int16_t)sizey) * ((int16_t)sizey); - int16_t fa = 4 * ((int16_t)aa); - int16_t fb = 4 * ((int16_t)bb); + int32_t aa = ((int32_t)sizex) * ((int32_t)sizex); + int32_t bb = ((int32_t)sizey) * ((int32_t)sizey); + int32_t fa = 4 * aa; + int32_t fb = 4 * bb; int16_t dx = 0; int16_t dy = ((int16_t)sizey); @@ -83,7 +83,7 @@ bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex, } bool ret = true; - for (int16_t delta = (2 * bb) + (aa * (1 - (2 * sizey))); bb * dx <= aa * dy; dx++) { + for (int32_t delta = (2 * bb) + (aa * (1 - (2 * sizey))); bb * dx <= aa * dy; dx++) { if (!qp_ellipse_helper_impl(device, x, y, dx, dy, filled)) { ret = false; break; @@ -98,7 +98,7 @@ bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex, dx = sizex; dy = 0; - for (int16_t delta = (2 * aa) + (bb * (1 - (2 * sizex))); aa * dy <= bb * dx; dy++) { + for (int32_t delta = (2 * aa) + (bb * (1 - (2 * sizex))); aa * dy <= bb * dx; dy++) { if (!qp_ellipse_helper_impl(device, x, y, dx, dy, filled)) { ret = false; break; |