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/>.
26 #if defined (USE_SPEKTRUM_CMS_TELEMETRY) && defined (USE_CMS) && defined(USE_TELEMETRY_SRXL)
28 #include "common/utils.h"
30 #include "drivers/display.h"
33 #include "telemetry/srxl.h"
35 displayPort_t srxlDisplayPort
;
37 static int srxlDrawScreen(displayPort_t
*displayPort
)
43 static int srxlScreenSize(const displayPort_t
*displayPort
)
45 return displayPort
->rows
* displayPort
->cols
;
48 static int srxlWriteChar(displayPort_t
*displayPort
, uint8_t col
, uint8_t row
, uint16_t c
, textAttributes_t attr
)
50 return (spektrumTmTextGenPutChar(col
, row
, c
));
56 static int srxlWriteString(displayPort_t
*displayPort
, uint8_t col
, uint8_t row
, const char *s
, textAttributes_t attr
)
59 srxlWriteChar(displayPort
, col
++, row
, *(s
++), attr
);
64 static int srxlClearScreen(displayPort_t
*displayPort
)
66 textAttributes_t attr
= 0;
67 for (int row
= 0; row
< SPEKTRUM_SRXL_TEXTGEN_BUFFER_ROWS
; row
++) {
68 for (int col
= 0; col
< SPEKTRUM_SRXL_TEXTGEN_BUFFER_COLS
; col
++) {
69 srxlWriteChar(displayPort
, col
, row
, ' ', attr
);
72 srxlWriteString(displayPort
, 1, 0, "INAV", attr
);
74 if (displayPort
->grabCount
== 0) {
75 srxlWriteString(displayPort
, 0, 2, CMS_STARTUP_HELP_TEXT1
, attr
);
76 srxlWriteString(displayPort
, 2, 3, CMS_STARTUP_HELP_TEXT2
, attr
);
77 srxlWriteString(displayPort
, 2, 4, CMS_STARTUP_HELP_TEXT3
, attr
);
82 static bool srxlIsTransferInProgress(const displayPort_t
*displayPort
)
89 static bool srxlIsSynced(const displayPort_t *displayPort)
96 static int srxlHeartbeat(displayPort_t
*displayPort
)
102 static void srxlResync(displayPort_t
*displayPort
)
107 static uint32_t srxlTxBytesFree(const displayPort_t
*displayPort
)
113 static int srxlGrab(displayPort_t
*displayPort
)
115 return displayPort
->grabCount
= 1;
118 static int srxlRelease(displayPort_t
*displayPort
)
120 int cnt
= displayPort
->grabCount
= 0;
121 srxlClearScreen(displayPort
);
125 static const displayPortVTable_t srxlVTable
= {
127 .release
= srxlRelease
,
128 .clearScreen
= srxlClearScreen
,
129 .drawScreen
= srxlDrawScreen
,
130 .screenSize
= srxlScreenSize
,
131 .writeString
= srxlWriteString
,
132 .writeChar
= srxlWriteChar
,
133 .isTransferInProgress
= srxlIsTransferInProgress
,
134 .heartbeat
= srxlHeartbeat
,
135 .resync
= srxlResync
,
136 //.isSynced = srxlIsSynced,
137 .txBytesFree
= srxlTxBytesFree
,
138 //.layerSupported = NULL,
139 //.layerSelect = NULL,
143 displayPort_t
*displayPortSrxlInit(void)
145 srxlDisplayPort
.device
= NULL
;
146 displayInit(&srxlDisplayPort
, &srxlVTable
);
147 srxlDisplayPort
.rows
= SPEKTRUM_SRXL_TEXTGEN_BUFFER_ROWS
;
148 srxlDisplayPort
.cols
= SPEKTRUM_SRXL_TEXTGEN_BUFFER_COLS
;
149 return &srxlDisplayPort
;