2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
24 #include "build/debug.h"
26 #include "drivers/video_textscreen.h"
27 #include "common/utils.h"
29 #include "osd/osd_element.h"
30 #include "osd/osd_screen.h"
33 textScreen_t osdTextScreen
;
35 typedef struct osdCursor_s
{
40 static osdCursor_t cursor
= {0, 0};
42 static uint16_t osdCalculateBufferOffset(osdCoordVal_t x
, osdCoordVal_t y
) {
45 // positive y = top aligned
48 // negative y = bottom aligned
49 yy
= osdTextScreen
.height
+ y
;
51 // prevent bottom aligned PAL screen coordinate from appearing off-screen when NTSC is used
52 // e.g. when PAL rows = 16, and Y = -15 it's OK, but when NTSC with 13 rows is used a negative value is calculated for yy.
57 uint16_t offset
= (yy
* osdTextScreen
.width
) + x
;
60 // Does not move the cursor.
61 void osdSetCharacterAtPosition(osdCoordVal_t x
, osdCoordVal_t y
, char c
)
63 uint8_t mappedCharacter
= asciiToFontMapping
[(uint8_t)c
];
65 uint16_t offset
= osdCalculateBufferOffset(x
,y
);
66 textScreenBuffer
[offset
] = mappedCharacter
;
69 // Does not move the cursor.
70 void osdSetRawCharacterAtPosition(osdCoordVal_t x
, osdCoordVal_t y
, char c
)
72 uint16_t offset
= osdCalculateBufferOffset(x
,y
);
73 textScreenBuffer
[offset
] = c
;
76 void osdResetCursor(void)
82 void osdSetCursor(osdCoordVal_t x
, osdCoordVal_t y
)
88 // software cursor, handles line wrapping and row wrapping, resets to 0,0 when the end of the screen is reached
89 static void osdAdvanceCursor(void)
92 if (cursor
.x
>= osdTextScreen
.width
) {
95 if (cursor
.y
> osdTextScreen
.height
) {
101 void osdPrint(char *message
)
103 uint8_t *charPtr
= (uint8_t *)message
;
107 if (*charPtr
== 0xff) {
114 osdSetRawCharacterAtPosition(cursor
.x
, cursor
.y
, *charPtr
);
117 osdSetCharacterAtPosition(cursor
.x
, cursor
.y
, *charPtr
);
125 void osdPrintAt(osdCoordVal_t x
, osdCoordVal_t y
, char *message
)
131 void osdSetTextScreen(textScreen_t
*textScreen
)
133 osdTextScreen
= *textScreen
;
136 void osdClearScreen(void)
138 uint8_t mappedSpaceCharacter
= asciiToFontMapping
[(uint8_t)' '];
141 for (int y
= 0; y
< osdTextScreen
.height
; y
++) {
142 for (int x
= 0; x
< osdTextScreen
.width
; x
++) {
143 textScreenBuffer
[offset
++] = mappedSpaceCharacter
;