mirror of
https://github.com/firewalkwithm3/qmk_firmware.git
synced 2024-11-22 11:30:30 +08:00
[Enhancement] QP Getters (#21171)
This commit is contained in:
parent
4e7e824a73
commit
a360900fbb
|
@ -857,13 +857,52 @@ void keyboard_post_init_kb(void) {
|
|||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### ** Get Geometry **
|
||||
#### ** Gettters **
|
||||
|
||||
These functions allow external code to retrieve the current width, height, rotation, and drawing offsets.
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### ** Width **
|
||||
|
||||
```c
|
||||
uint16_t qp_get_width(painter_device_t device);
|
||||
```
|
||||
|
||||
#### ** Height **
|
||||
|
||||
```c
|
||||
uint16_t qp_get_height(painter_device_t device);
|
||||
```
|
||||
|
||||
#### ** Rotation **
|
||||
|
||||
```c
|
||||
painter_rotation_t qp_get_rotation(painter_device_t device);
|
||||
```
|
||||
|
||||
#### ** Offset X **
|
||||
|
||||
```c
|
||||
uint16_t qp_get_offset_x(painter_device_t device);
|
||||
```
|
||||
|
||||
#### ** Offset Y **
|
||||
|
||||
```c
|
||||
uint16_t qp_get_offset_y(painter_device_t device);
|
||||
```
|
||||
|
||||
##### ** Everything **
|
||||
|
||||
Convenience function to call all the previous ones at once.
|
||||
Note: You can pass `NULL` for the values you are not interested in.
|
||||
|
||||
```c
|
||||
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);
|
||||
```
|
||||
|
||||
The `qp_get_geometry` function allows external code to retrieve the current width, height, rotation, and drawing offsets.
|
||||
<!-- tabs:end -->
|
||||
|
||||
#### ** Set Viewport Offsets **
|
||||
|
||||
|
|
|
@ -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:
|
||||
if (width) {
|
||||
*width = driver->panel_width;
|
||||
}
|
||||
if (height) {
|
||||
*height = driver->panel_height;
|
||||
}
|
||||
break;
|
||||
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:
|
||||
height = driver->panel_height;
|
||||
|
||||
case QP_ROTATION_90:
|
||||
case QP_ROTATION_270:
|
||||
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 = driver->panel_height;
|
||||
*width = qp_get_width(device);
|
||||
}
|
||||
|
||||
if (height) {
|
||||
*height = driver->panel_width;
|
||||
}
|
||||
break;
|
||||
*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");
|
||||
|
|
|
@ -175,6 +175,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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue