FIX CONFIG: BARO (#12476)
[betaflight.git] / src / main / drivers / display.c
blobd9b90bf3876a24fd095cb48c8aea034ae7010794
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
25 #include "platform.h"
27 #include "common/utils.h"
29 #include "drivers/display_canvas.h"
30 #include "drivers/osd.h"
32 #include "display.h"
34 void displayClearScreen(displayPort_t *instance, displayClearOption_e options)
36 instance->vTable->clearScreen(instance, options);
37 instance->cleared = true;
38 instance->cursorRow = -1;
41 // Return true if screen still being transferred
42 bool displayDrawScreen(displayPort_t *instance)
44 return instance->vTable->drawScreen(instance);
47 int displayScreenSize(const displayPort_t *instance)
49 return instance->vTable->screenSize(instance);
52 void displayGrab(displayPort_t *instance)
54 instance->vTable->grab(instance);
55 instance->vTable->clearScreen(instance, DISPLAY_CLEAR_WAIT);
56 ++instance->grabCount;
59 void displayRelease(displayPort_t *instance)
61 instance->vTable->release(instance);
62 --instance->grabCount;
65 void displayReleaseAll(displayPort_t *instance)
67 instance->vTable->release(instance);
68 instance->grabCount = 0;
71 bool displayIsGrabbed(const displayPort_t *instance)
73 // can be called before initialised
74 return (instance && instance->grabCount > 0);
77 void displaySetXY(displayPort_t *instance, uint8_t x, uint8_t y)
79 instance->posX = x;
80 instance->posY = y;
83 int displaySys(displayPort_t *instance, uint8_t x, uint8_t y, displayPortSystemElement_e systemElement)
85 if (instance->vTable->writeSys) {
86 return instance->vTable->writeSys(instance, x, y, systemElement);
89 return 0;
92 int displayWrite(displayPort_t *instance, uint8_t x, uint8_t y, uint8_t attr, const char *text)
94 instance->posX = x + strlen(text);
95 instance->posY = y;
96 return instance->vTable->writeString(instance, x, y, attr, text);
99 int displayWriteChar(displayPort_t *instance, uint8_t x, uint8_t y, uint8_t attr, uint8_t c)
101 instance->posX = x + 1;
102 instance->posY = y;
103 return instance->vTable->writeChar(instance, x, y, attr, c);
106 bool displayIsTransferInProgress(const displayPort_t *instance)
108 return instance->vTable->isTransferInProgress(instance);
111 bool displayIsSynced(const displayPort_t *instance)
113 return instance->vTable->isSynced(instance);
116 bool displayHeartbeat(displayPort_t *instance)
118 return instance->vTable->heartbeat(instance);
121 void displayRedraw(displayPort_t *instance)
123 instance->vTable->redraw(instance);
126 uint16_t displayTxBytesFree(const displayPort_t *instance)
128 return instance->vTable->txBytesFree(instance);
131 bool displayLayerSupported(displayPort_t *instance, displayPortLayer_e layer)
133 if (layer == DISPLAYPORT_LAYER_FOREGROUND) {
134 // Every device must support the foreground (default) layer
135 return true;
136 } else if (layer < DISPLAYPORT_LAYER_COUNT && instance->vTable->layerSupported) {
137 return instance->vTable->layerSupported(instance, layer);
139 return false;
142 bool displayLayerSelect(displayPort_t *instance, displayPortLayer_e layer)
144 if (instance->vTable->layerSelect) {
145 return instance->vTable->layerSelect(instance, layer);
147 return false;
150 bool displayLayerCopy(displayPort_t *instance, displayPortLayer_e destLayer, displayPortLayer_e sourceLayer)
152 if (instance->vTable->layerCopy && sourceLayer != destLayer) {
153 return instance->vTable->layerCopy(instance, destLayer, sourceLayer);
155 return false;
158 bool displayWriteFontCharacter(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr)
160 if (instance->vTable->writeFontCharacter) {
161 return instance->vTable->writeFontCharacter(instance, addr, chr);
163 return false;
166 void displaySetBackgroundType(displayPort_t *instance, displayPortBackground_e backgroundType)
168 if (instance->vTable->setBackgroundType) {
169 instance->vTable->setBackgroundType(instance, backgroundType);
173 bool displayCheckReady(displayPort_t *instance, bool rescan)
175 if (instance->vTable->checkReady) {
176 return instance->vTable->checkReady(instance, rescan);
178 // Drivers that don't provide a checkReady method are
179 // assumed to be immediately ready (either by actually
180 // begin ready very quickly or by blocking)
181 return true;
184 void displayBeginTransaction(displayPort_t *instance, displayTransactionOption_e opts)
186 if (instance->vTable->beginTransaction) {
187 instance->vTable->beginTransaction(instance, opts);
191 void displayCommitTransaction(displayPort_t *instance)
193 if (instance->vTable->commitTransaction) {
194 instance->vTable->commitTransaction(instance);
198 bool displayGetCanvas(displayCanvas_t *canvas, const displayPort_t *instance)
200 #if defined(USE_CANVAS)
201 if (canvas && instance->vTable->getCanvas && instance->vTable->getCanvas(canvas, instance)) {
202 canvas->gridElementWidth = canvas->width / instance->cols;
203 canvas->gridElementHeight = canvas->height / instance->rows;
204 return true;
206 #else
207 UNUSED(canvas);
208 UNUSED(instance);
209 #endif
210 return false;
213 bool displaySupportsOsdSymbols(displayPort_t *instance)
215 // Assume device types that support OSD display will support the OSD symbols (since the OSD logic will use them)
216 if ((instance->deviceType == DISPLAYPORT_DEVICE_TYPE_MAX7456)
217 || (instance->deviceType == DISPLAYPORT_DEVICE_TYPE_MSP)
218 || (instance->deviceType == DISPLAYPORT_DEVICE_TYPE_FRSKYOSD)) {
219 return true;
220 } else {
221 return false;
225 void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable, displayPortDeviceType_e deviceType)
227 instance->vTable = vTable;
228 instance->useFullscreen = false;
229 instance->grabCount = 0;
230 instance->deviceType = deviceType;
232 displayBeginTransaction(instance, DISPLAY_TRANSACTION_OPT_NONE);
233 displayClearScreen(instance, DISPLAY_CLEAR_WAIT);
234 displayCommitTransaction(instance);