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
)
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
);
86 static bool srxlIsTransferInProgress(const displayPort_t
*displayPort
)
92 static bool srxlIsSynced(const displayPort_t
*displayPort
)
98 static int srxlHeartbeat(displayPort_t
*displayPort
)
104 static void srxlRedraw(displayPort_t
*displayPort
)
109 static uint32_t srxlTxBytesFree(const displayPort_t
*displayPort
)
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
);
127 static const displayPortVTable_t srxlVTable
= {
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
,
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());