Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / io / displayport_srxl.c
blob3da52ffb20eaae8c0ed6c97a0ee935174ea032b3
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 #if defined(USE_SPEKTRUM_CMS_TELEMETRY)
29 #include "cms/cms.h"
31 #include "common/utils.h"
33 #include "drivers/display.h"
35 #include "telemetry/srxl.h"
37 #include "displayport_srxl.h"
39 displayPort_t srxlDisplayPort;
41 static bool srxlDrawScreen(displayPort_t *displayPort)
43 UNUSED(displayPort);
44 return 0;
47 static int srxlScreenSize(const displayPort_t *displayPort)
49 return displayPort->rows * displayPort->cols;
52 static int srxlWriteChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, uint8_t c)
54 UNUSED(displayPort);
55 UNUSED(attr);
57 return (spektrumTmTextGenPutChar(col, row, c));
61 static int srxlWriteString(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, const char *s)
63 while (*s) {
64 srxlWriteChar(displayPort, col++, row, attr, *(s++));
66 return 0;
69 static int srxlClearScreen(displayPort_t *displayPort)
71 for (int row = 0; row < SPEKTRUM_SRXL_TEXTGEN_BUFFER_ROWS; row++) {
72 for (int col= 0; col < SPEKTRUM_SRXL_TEXTGEN_BUFFER_COLS; col++) {
73 srxlWriteChar(displayPort, col, row, DISPLAYPORT_ATTR_NONE, ' ');
76 srxlWriteString(displayPort, 1, 0, DISPLAYPORT_ATTR_NONE, "BETAFLIGHT");
78 if (displayPort->grabCount == 0) {
79 srxlWriteString(displayPort, 0, 2, DISPLAYPORT_ATTR_NONE, CMS_STARTUP_HELP_TEXT1);
80 srxlWriteString(displayPort, 2, 3, DISPLAYPORT_ATTR_NONE, CMS_STARTUP_HELP_TEXT2);
81 srxlWriteString(displayPort, 2, 4, DISPLAYPORT_ATTR_NONE, CMS_STARTUP_HELP_TEXT3);
83 return 0;
86 static bool srxlIsTransferInProgress(const displayPort_t *displayPort)
88 UNUSED(displayPort);
89 return false;
92 static bool srxlIsSynced(const displayPort_t *displayPort)
94 UNUSED(displayPort);
95 return true;
98 static int srxlHeartbeat(displayPort_t *displayPort)
100 UNUSED(displayPort);
101 return 0;
104 static void srxlRedraw(displayPort_t *displayPort)
106 UNUSED(displayPort);
109 static uint32_t srxlTxBytesFree(const displayPort_t *displayPort)
111 UNUSED(displayPort);
112 return UINT32_MAX;
115 static int srxlGrab(displayPort_t *displayPort)
117 return displayPort->grabCount = 1;
120 static int srxlRelease(displayPort_t *displayPort)
122 int cnt = displayPort->grabCount = 0;
123 srxlClearScreen(displayPort);
124 return cnt;
127 static const displayPortVTable_t srxlVTable = {
128 .grab = srxlGrab,
129 .release = srxlRelease,
130 .clearScreen = srxlClearScreen,
131 .drawScreen = srxlDrawScreen,
132 .screenSize = srxlScreenSize,
133 .writeString = srxlWriteString,
134 .writeChar = srxlWriteChar,
135 .isTransferInProgress = srxlIsTransferInProgress,
136 .heartbeat = srxlHeartbeat,
137 .redraw = srxlRedraw,
138 .isSynced = srxlIsSynced,
139 .txBytesFree = srxlTxBytesFree,
140 .layerSupported = NULL,
141 .layerSelect = NULL,
142 .layerCopy = NULL,
145 static displayPort_t *displayPortSrxlInit()
147 srxlDisplayPort.device = NULL;
148 displayInit(&srxlDisplayPort, &srxlVTable, DISPLAYPORT_DEVICE_TYPE_SRXL);
149 srxlDisplayPort.rows = SPEKTRUM_SRXL_TEXTGEN_BUFFER_ROWS;
150 srxlDisplayPort.cols = SPEKTRUM_SRXL_TEXTGEN_BUFFER_COLS;
152 return &srxlDisplayPort;
155 void srxlDisplayportRegister(void)
157 cmsDisplayPortRegister(displayPortSrxlInit());
159 #endif