Merge pull request #11299 from daleckystepan/vtx-start-bit
[betaflight.git] / src / main / io / displayport_hott.c
blobe854e2cf723c2dac01934a3ff5d1bfd984a8d84a
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"
26 #if defined (USE_HOTT_TEXTMODE) && defined (USE_CMS)
28 #include "common/utils.h"
29 #include "cms/cms.h"
30 #include "telemetry/hott.h"
32 displayPort_t hottDisplayPort;
34 static bool hottDrawScreen(displayPort_t *displayPort)
36 UNUSED(displayPort);
37 return 0;
40 static int hottScreenSize(const displayPort_t *displayPort)
42 return displayPort->rows * displayPort->cols;
45 static int hottWriteChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, uint8_t c)
47 UNUSED(displayPort);
48 UNUSED(attr);
50 hottTextmodeWriteChar(col, row, c);
51 return 0;
54 static int hottWriteString(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, const char *s)
56 UNUSED(attr);
58 while (*s) {
59 hottWriteChar(displayPort, col++, row, DISPLAYPORT_ATTR_NONE, *(s++));
61 return 0;
64 static int hottClearScreen(displayPort_t *displayPort)
66 for (int row = 0; row < displayPort->rows; row++) {
67 for (int col= 0; col < displayPort->cols; col++) {
68 hottWriteChar(displayPort, col, row, DISPLAYPORT_ATTR_NONE, ' ');
71 return 0;
74 static bool hottIsTransferInProgress(const displayPort_t *displayPort)
76 UNUSED(displayPort);
77 return false;
80 static int hottHeartbeat(displayPort_t *displayPort)
82 if (!hottTextmodeIsAlive()) {
83 cmsMenuExit(displayPort, (void*)CMS_EXIT_SAVE);
86 return 0;
89 static void hottRedraw(displayPort_t *displayPort)
91 UNUSED(displayPort);
94 static uint32_t hottTxBytesFree(const displayPort_t *displayPort)
96 UNUSED(displayPort);
97 return UINT32_MAX;
100 static int hottGrab(displayPort_t *displayPort)
102 hottTextmodeGrab();
103 return displayPort->grabCount = 1;
106 static int hottRelease(displayPort_t *displayPort)
108 int cnt = displayPort->grabCount = 0;
109 hottClearScreen(displayPort);
110 hottTextmodeExit();
111 return cnt;
114 static const displayPortVTable_t hottVTable = {
115 .grab = hottGrab,
116 .release = hottRelease,
117 .clearScreen = hottClearScreen,
118 .drawScreen = hottDrawScreen,
119 .screenSize = hottScreenSize,
120 .writeString = hottWriteString,
121 .writeChar = hottWriteChar,
122 .isTransferInProgress = hottIsTransferInProgress,
123 .heartbeat = hottHeartbeat,
124 .redraw = hottRedraw,
125 .txBytesFree = hottTxBytesFree,
126 .layerSupported = NULL,
127 .layerSelect = NULL,
128 .layerCopy = NULL,
131 static displayPort_t *displayPortHottInit()
133 hottDisplayPort.device = NULL;
134 displayInit(&hottDisplayPort, &hottVTable, DISPLAYPORT_DEVICE_TYPE_HOTT);
135 hottDisplayPort.useFullscreen = true;
136 hottDisplayPort.rows = HOTT_TEXTMODE_DISPLAY_ROWS;
137 hottDisplayPort.cols = HOTT_TEXTMODE_DISPLAY_COLUMNS;
138 return &hottDisplayPort;
141 void hottDisplayportRegister()
143 cmsDisplayPortRegister(displayPortHottInit());
146 void hottCmsOpen()
148 if (!cmsInMenu) {
149 cmsDisplayPortSelect(&hottDisplayPort);
150 cmsMenuOpen();
154 void hottSetCmsKey(uint8_t hottKey, bool keepCmsOpen)
156 switch (hottKey) {
157 case HOTTV4_BUTTON_DEC:
158 cmsSetExternKey(CMS_KEY_UP);
159 break;
160 case HOTTV4_BUTTON_INC:
161 cmsSetExternKey(CMS_KEY_DOWN);
162 break;
163 case HOTTV4_BUTTON_SET:
164 if (cmsInMenu) {
165 cmsMenuExit(pCurrentDisplay, (void*)CMS_EXIT_SAVE);
167 cmsSetExternKey(CMS_KEY_NONE);
168 break;
169 case HOTTV4_BUTTON_NEXT:
170 cmsSetExternKey(CMS_KEY_RIGHT);
171 break;
172 case HOTTV4_BUTTON_PREV:
173 cmsSetExternKey(CMS_KEY_LEFT);
174 if (keepCmsOpen) { // Make sure CMS is open until textmode is closed.
175 cmsMenuOpen();
177 break;
178 default:
179 cmsSetExternKey(CMS_KEY_NONE);
180 break;
184 #endif