summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/quantum_painter.md43
-rw-r--r--quantum/painter/qp.c121
-rw-r--r--quantum/painter/qp.h35
3 files changed, 174 insertions, 25 deletions
diff --git a/docs/quantum_painter.md b/docs/quantum_painter.md
index 5e399183f8..8acf6aeb36 100644
--- a/docs/quantum_painter.md
+++ b/docs/quantum_painter.md
@@ -857,13 +857,52 @@ void keyboard_post_init_kb(void) {
857 857
858<!-- tabs:start --> 858<!-- tabs:start -->
859 859
860#### ** Get Geometry ** 860#### ** Gettters **
861
862These functions allow external code to retrieve the current width, height, rotation, and drawing offsets.
863
864<!-- tabs:start -->
865
866#### ** Width **
867
868```c
869uint16_t qp_get_width(painter_device_t device);
870```
871
872#### ** Height **
873
874```c
875uint16_t qp_get_height(painter_device_t device);
876```
877
878#### ** Rotation **
879
880```c
881painter_rotation_t qp_get_rotation(painter_device_t device);
882```
883
884#### ** Offset X **
885
886```c
887uint16_t qp_get_offset_x(painter_device_t device);
888```
889
890#### ** Offset Y **
891
892```c
893uint16_t qp_get_offset_y(painter_device_t device);
894```
895
896##### ** Everything **
897
898Convenience function to call all the previous ones at once.
899Note: You can pass `NULL` for the values you are not interested in.
861 900
862```c 901```c
863void 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); 902void 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);
864``` 903```
865 904
866The `qp_get_geometry` function allows external code to retrieve the current width, height, rotation, and drawing offsets. 905<!-- tabs:end -->
867 906
868#### ** Set Viewport Offsets ** 907#### ** Set Viewport Offsets **
869 908
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) {
131} 131}
132 132
133//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 133////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
134// Quantum Painter External API: qp_get_geometry 134// Quantum Painter External API: qp_get_*
135 135
136void 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) { 136uint16_t qp_get_width(painter_device_t device) {
137 qp_dprintf("qp_get_geometry: entry\n"); 137 qp_dprintf("qp_get_width: entry\n");
138 painter_driver_t *driver = (painter_driver_t *)device; 138 painter_driver_t *driver = (painter_driver_t *)device;
139 139
140 if (!driver) { 140 if (!driver || !driver->validate_ok) {
141 qp_dprintf("qp_get_geometry: fail (pointer to NULL)\n"); 141 qp_dprintf("qp_get_width: fail (invalid driver)\n");
142 return; 142 return 0;
143 }
144
145 uint16_t width;
146 switch (driver->rotation) {
147 default:
148 case QP_ROTATION_0:
149 case QP_ROTATION_180:
150 width = driver->panel_width;
151
152 case QP_ROTATION_90:
153 case QP_ROTATION_270:
154 width = driver->panel_height;
155 }
156
157 qp_dprintf("qp_get_width: ok\n");
158 return width;
159}
160
161uint16_t qp_get_height(painter_device_t device) {
162 qp_dprintf("qp_get_height: entry\n");
163 painter_driver_t *driver = (painter_driver_t *)device;
164
165 if (!driver || !driver->validate_ok) {
166 qp_dprintf("qp_get_height: fail (invalid driver)\n");
167 return 0;
143 } 168 }
144 169
170 uint16_t height;
145 switch (driver->rotation) { 171 switch (driver->rotation) {
146 default: 172 default:
147 case QP_ROTATION_0: 173 case QP_ROTATION_0:
148 case QP_ROTATION_180: 174 case QP_ROTATION_180:
149 if (width) { 175 height = driver->panel_height;
150 *width = driver->panel_width; 176
151 }
152 if (height) {
153 *height = driver->panel_height;
154 }
155 break;
156 case QP_ROTATION_90: 177 case QP_ROTATION_90:
157 case QP_ROTATION_270: 178 case QP_ROTATION_270:
158 if (width) { 179 height = driver->panel_width;
159 *width = driver->panel_height; 180 }
160 } 181
161 if (height) { 182 qp_dprintf("qp_get_height: ok\n");
162 *height = driver->panel_width; 183 return height;
163 } 184}
164 break; 185
186painter_rotation_t qp_get_rotation(painter_device_t device) {
187 qp_dprintf("qp_get_rotation: entry\n");
188 painter_driver_t *driver = (painter_driver_t *)device;
189
190 if (!driver || !driver->validate_ok) {
191 qp_dprintf("qp_get_rotation: fail (invalid driver)\n");
192 return QP_ROTATION_0;
193 }
194
195 qp_dprintf("qp_get_rotation: ok\n");
196 return driver->rotation;
197}
198
199uint16_t qp_get_offset_x(painter_device_t device) {
200 qp_dprintf("qp_get_offset_x: entry\n");
201 painter_driver_t *driver = (painter_driver_t *)device;
202
203 if (!driver || !driver->validate_ok) {
204 qp_dprintf("qp_get_offset_x: fail (invalid driver)\n");
205 return 0;
206 }
207
208 qp_dprintf("qp_get_offset_x: ok\n");
209 return driver->offset_x;
210}
211
212uint16_t qp_get_offset_y(painter_device_t device) {
213 qp_dprintf("qp_get_offset_y: entry\n");
214 painter_driver_t *driver = (painter_driver_t *)device;
215
216 if (!driver || !driver->validate_ok) {
217 qp_dprintf("qp_get_offset_y: fail (invalid driver)\n");
218 return 0;
219 }
220
221 qp_dprintf("qp_get_offset_y: ok\n");
222 return driver->offset_y;
223}
224
225void 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) {
226 qp_dprintf("qp_geometry: entry\n");
227 painter_driver_t *driver = (painter_driver_t *)device;
228
229 if (!driver || !driver->validate_ok) {
230 qp_dprintf("qp_geometry: fail (invalid driver)\n");
231 return;
232 }
233
234 if (width) {
235 *width = qp_get_width(device);
236 }
237
238 if (height) {
239 *height = qp_get_height(device);
165 } 240 }
166 241
167 if (rotation) { 242 if (rotation) {
168 *rotation = driver->rotation; 243 *rotation = qp_get_rotation(device);
169 } 244 }
170 245
171 if (offset_x) { 246 if (offset_x) {
172 *offset_x = driver->offset_x; 247 *offset_x = qp_get_offset_x(device);
173 } 248 }
174 249
175 if (offset_y) { 250 if (offset_y) {
176 *offset_y = driver->offset_y; 251 *offset_y = qp_get_offset_y(device);
177 } 252 }
178 253
179 qp_dprintf("qp_get_geometry: ok\n"); 254 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);
176bool qp_flush(painter_device_t device); 176bool qp_flush(painter_device_t device);
177 177
178/** 178/**
179 * Retrieves the width of the display.
180 *
181 * @param device[in] the handle of the device to control
182 */
183uint16_t qp_get_width(painter_device_t device);
184
185/**
186 * Retrieves the height of the display.
187 *
188 * @param device[in] the handle of the device to control
189 */
190uint16_t qp_get_height(painter_device_t device);
191
192/**
193 * Retrieves the rotation of the display.
194 *
195 * @param device[in] the handle of the device to control
196 */
197painter_rotation_t qp_get_rotation(painter_device_t device);
198
199/**
200 * Retrieves the x-offset of the display.
201 *
202 * @param device[in] the handle of the device to control
203 */
204uint16_t qp_get_offset_x(painter_device_t device);
205
206/**
207 * Retrieves the y-offset of the display.
208 *
209 * @param device[in] the handle of the device to control
210 */
211uint16_t qp_get_offset_y(painter_device_t device);
212
213/**
179 * Retrieves the size, rotation, and offsets for the display. 214 * Retrieves the size, rotation, and offsets for the display.
180 * 215 *
181 * @note Any arguments of NULL will be ignored. 216 * @note Any arguments of NULL will be ignored.