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)
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/>.
27 #if defined(USE_SPEKTRUM_CMS_TELEMETRY)
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
)
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
)
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
)
64 srxlWriteChar(displayPort
, col
++, row
, attr
, *(s
++));
69 static int srxlClearScreen(displayPort_t
*displayPort
, displayClearOption_e options
)
72 for (int row
= 0; row
< SPEKTRUM_SRXL_TEXTGEN_BUFFER_ROWS
; row
++) {
73 for (int col
= 0; col
< SPEKTRUM_SRXL_TEXTGEN_BUFFER_COLS
; col
++) {
74 srxlWriteChar(displayPort
, col
, row
, DISPLAYPORT_SEVERITY_NORMAL
, ' ');
77 srxlWriteString(displayPort
, 1, 0, DISPLAYPORT_SEVERITY_NORMAL
, "BETAFLIGHT");
79 if (displayPort
->grabCount
== 0) {
80 srxlWriteString(displayPort
, 0, 2, DISPLAYPORT_SEVERITY_NORMAL
, CMS_STARTUP_HELP_TEXT1
);
81 srxlWriteString(displayPort
, 2, 3, DISPLAYPORT_SEVERITY_NORMAL
, CMS_STARTUP_HELP_TEXT2
);
82 srxlWriteString(displayPort
, 2, 4, DISPLAYPORT_SEVERITY_NORMAL
, CMS_STARTUP_HELP_TEXT3
);
87 static bool srxlIsTransferInProgress(const displayPort_t
*displayPort
)
93 static bool srxlIsSynced(const displayPort_t
*displayPort
)
99 static int srxlHeartbeat(displayPort_t
*displayPort
)
105 static void srxlRedraw(displayPort_t
*displayPort
)
110 static uint32_t srxlTxBytesFree(const displayPort_t
*displayPort
)
116 static int srxlGrab(displayPort_t
*displayPort
)
118 return displayPort
->grabCount
= 1;
121 static int srxlRelease(displayPort_t
*displayPort
)
123 int cnt
= displayPort
->grabCount
= 0;
124 srxlClearScreen(displayPort
, DISPLAY_CLEAR_WAIT
);
128 static const displayPortVTable_t srxlVTable
= {
130 .release
= srxlRelease
,
131 .clearScreen
= srxlClearScreen
,
132 .drawScreen
= srxlDrawScreen
,
133 .screenSize
= srxlScreenSize
,
134 .writeString
= srxlWriteString
,
135 .writeChar
= srxlWriteChar
,
136 .isTransferInProgress
= srxlIsTransferInProgress
,
137 .heartbeat
= srxlHeartbeat
,
138 .redraw
= srxlRedraw
,
139 .isSynced
= srxlIsSynced
,
140 .txBytesFree
= srxlTxBytesFree
,
141 .layerSupported
= NULL
,
146 static displayPort_t
*displayPortSrxlInit(void)
148 srxlDisplayPort
.device
= NULL
;
149 displayInit(&srxlDisplayPort
, &srxlVTable
, DISPLAYPORT_DEVICE_TYPE_SRXL
);
150 srxlDisplayPort
.rows
= SPEKTRUM_SRXL_TEXTGEN_BUFFER_ROWS
;
151 srxlDisplayPort
.cols
= SPEKTRUM_SRXL_TEXTGEN_BUFFER_COLS
;
153 return &srxlDisplayPort
;
156 void srxlDisplayportRegister(void)
158 cmsDisplayPortRegister(displayPortSrxlInit());