2 * This file is part of Cleanflight, Betaflight and INAV
4 * Cleanflight, Betaflight and INAV are free software. You can
5 * redistribute this software and/or modify this software under
6 * the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License,
8 * or (at your option) any later version.
10 * Cleanflight, Betaflight and INAV are distributed in the hope that
11 * they will be useful, but WITHOUT ANY WARRANTY; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. 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_FRSKYOSD)
28 #include "common/utils.h"
30 #include "drivers/display.h"
31 #include "drivers/display_canvas.h"
33 #include "io/displayport_frsky_osd.h"
34 #include "io/frsky_osd.h"
36 static displayPort_t frskyOsdDisplayPort
;
38 static int grab(displayPort_t
*displayPort
)
44 static int release(displayPort_t
*displayPort
)
50 static int clearScreen(displayPort_t
*displayPort
, displayClearOption_e options
)
54 frskyOsdClearScreen();
58 static bool drawScreen(displayPort_t
*displayPort
)
66 static int screenSize(const displayPort_t
*displayPort
)
69 return frskyOsdGetGridRows() * frskyOsdGetGridCols();
72 static int writeString(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint8_t attr
, const char *s
)
77 frskyOsdDrawStringInGrid(x
, y
, s
);
81 static int writeChar(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint8_t attr
, uint8_t c
)
86 frskyOsdDrawCharInGrid(x
, y
, c
);
90 static bool isTransferInProgress(const displayPort_t
*displayPort
)
96 static void updateGridSize(displayPort_t
*displayPort
)
98 displayPort
->rows
= frskyOsdGetGridRows();
99 displayPort
->cols
= frskyOsdGetGridCols();
102 static void redraw(displayPort_t
*displayPort
)
105 // TODO(agh): Do we need to flush the screen here?
106 // MAX7456's driver does a full redraw in redraw(),
107 // so some callers might be expecting that.
111 static int heartbeat(displayPort_t
*displayPort
)
117 static uint32_t txBytesFree(const displayPort_t
*displayPort
)
123 static bool writeFontCharacter(displayPort_t
*instance
, uint16_t addr
, const osdCharacter_t
*chr
)
127 return frskyOsdWriteFontCharacter(addr
, chr
);
130 static bool checkReady(displayPort_t
*instance
, bool rescan
)
134 if (frskyOsdIsReady()) {
135 updateGridSize(instance
);
141 static void beginTransaction(displayPort_t
*instance
, displayTransactionOption_e opts
)
145 frskyOsdTransactionOptions_e frskyOpts
= 0;
146 if (opts
& DISPLAY_TRANSACTION_OPT_PROFILED
) {
147 frskyOpts
|= FRSKY_OSD_TRANSACTION_OPT_PROFILED
;
149 if (opts
& DISPLAY_TRANSACTION_OPT_RESET_DRAWING
) {
150 frskyOpts
|= FRSKY_OSD_TRANSACTION_OPT_RESET_DRAWING
;
153 frskyOsdBeginTransaction(frskyOpts
);
156 static void commitTransaction(displayPort_t
*instance
)
160 frskyOsdCommitTransaction();
163 static frskyOsdColor_e
frskyOsdGetColor(displayCanvasColor_e color
)
167 case DISPLAY_CANVAS_COLOR_BLACK
:
168 return FRSKY_OSD_COLOR_BLACK
;
169 case DISPLAY_CANVAS_COLOR_TRANSPARENT
:
170 return FRSKY_OSD_COLOR_TRANSPARENT
;
171 case DISPLAY_CANVAS_COLOR_WHITE
:
172 return FRSKY_OSD_COLOR_WHITE
;
173 case DISPLAY_CANVAS_COLOR_GRAY
:
174 return FRSKY_OSD_COLOR_GRAY
;
176 return FRSKY_OSD_COLOR_BLACK
;
179 static void setStrokeColor(displayCanvas_t
*displayCanvas
, displayCanvasColor_e color
)
181 UNUSED(displayCanvas
);
183 frskyOsdSetStrokeColor(frskyOsdGetColor(color
));
186 static void setFillColor(displayCanvas_t
*displayCanvas
, displayCanvasColor_e color
)
188 UNUSED(displayCanvas
);
190 frskyOsdSetFillColor(frskyOsdGetColor(color
));
193 static void setStrokeAndFillColor(displayCanvas_t
*displayCanvas
, displayCanvasColor_e color
)
195 UNUSED(displayCanvas
);
197 frskyOsdSetStrokeAndFillColor(frskyOsdGetColor(color
));
200 static void setColorInversion(displayCanvas_t
*displayCanvas
, bool inverted
)
202 UNUSED(displayCanvas
);
204 frskyOsdSetColorInversion(inverted
);
207 static void setPixel(displayCanvas_t
*displayCanvas
, int x
, int y
, displayCanvasColor_e color
)
209 UNUSED(displayCanvas
);
211 frskyOsdSetPixel(x
, y
, frskyOsdGetColor(color
));
214 static void setPixelToStrokeColor(displayCanvas_t
*displayCanvas
, int x
, int y
)
216 UNUSED(displayCanvas
);
218 frskyOsdSetPixelToStrokeColor(x
, y
);
221 static void setPixelToFillColor(displayCanvas_t
*displayCanvas
, int x
, int y
)
223 UNUSED(displayCanvas
);
225 frskyOsdSetPixelToFillColor(x
, y
);
228 static void setStrokeWidth(displayCanvas_t
*displayCanvas
, unsigned w
)
230 UNUSED(displayCanvas
);
232 frskyOsdSetStrokeWidth(w
);
235 static void setLineOutlineType(displayCanvas_t
*displayCanvas
, displayCanvasOutlineType_e outlineType
)
237 UNUSED(displayCanvas
);
239 frskyOsdSetLineOutlineType((frskyOsdLineOutlineType_e
)outlineType
);
242 static void setLineOutlineColor(displayCanvas_t
*displayCanvas
, displayCanvasColor_e outlineColor
)
244 UNUSED(displayCanvas
);
246 frskyOsdSetLineOutlineColor((frskyOsdColor_e
)outlineColor
);
249 static void clipToRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
251 UNUSED(displayCanvas
);
253 frskyOsdClipToRect(x
, y
, w
, h
);
256 static void clearRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
258 UNUSED(displayCanvas
);
260 frskyOsdClearRect(x
, y
, w
, h
);
263 static void resetDrawingState(displayCanvas_t
*displayCanvas
)
265 UNUSED(displayCanvas
);
267 frskyOsdResetDrawingState();
270 static void drawCharacter(displayCanvas_t
*displayCanvas
, int x
, int y
, uint16_t chr
, displayCanvasBitmapOption_t opts
)
272 UNUSED(displayCanvas
);
274 frskyOsdDrawCharacter(x
, y
, chr
, opts
);
277 static void drawCharacterMask(displayCanvas_t
*displayCanvas
, int x
, int y
, uint16_t chr
, displayCanvasColor_e color
, displayCanvasBitmapOption_t opts
)
279 UNUSED(displayCanvas
);
281 frskyOsdDrawCharacterMask(x
, y
, chr
, frskyOsdGetColor(color
), opts
);
284 static void drawString(displayCanvas_t
*displayCanvas
, int x
, int y
, const char *s
, displayCanvasBitmapOption_t opts
)
286 UNUSED(displayCanvas
);
288 frskyOsdDrawString(x
, y
, s
, opts
);
291 static void drawStringMask(displayCanvas_t
*displayCanvas
, int x
, int y
, const char *s
, displayCanvasColor_e color
, displayCanvasBitmapOption_t opts
)
293 UNUSED(displayCanvas
);
295 frskyOsdDrawStringMask(x
, y
, s
, frskyOsdGetColor(color
), opts
);
298 static void moveToPoint(displayCanvas_t
*displayCanvas
, int x
, int y
)
300 UNUSED(displayCanvas
);
302 frskyOsdMoveToPoint(x
, y
);
305 static void strokeLineToPoint(displayCanvas_t
*displayCanvas
, int x
, int y
)
307 UNUSED(displayCanvas
);
309 frskyOsdStrokeLineToPoint(x
, y
);
312 static void strokeTriangle(displayCanvas_t
*displayCanvas
, int x1
, int y1
, int x2
, int y2
, int x3
, int y3
)
314 UNUSED(displayCanvas
);
316 frskyOsdStrokeTriangle(x1
, y1
, x2
, y2
, x3
, y3
);
319 static void fillTriangle(displayCanvas_t
*displayCanvas
, int x1
, int y1
, int x2
, int y2
, int x3
, int y3
)
321 UNUSED(displayCanvas
);
323 frskyOsdFillTriangle(x1
, y1
, x2
, y2
, x3
, y3
);
326 static void fillStrokeTriangle(displayCanvas_t
*displayCanvas
, int x1
, int y1
, int x2
, int y2
, int x3
, int y3
)
328 UNUSED(displayCanvas
);
330 frskyOsdFillStrokeTriangle(x1
, y1
, x2
, y2
, x3
, y3
);
333 static void strokeRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
335 UNUSED(displayCanvas
);
337 frskyOsdStrokeRect(x
, y
, w
, h
);
340 static void fillRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
342 UNUSED(displayCanvas
);
344 frskyOsdFillRect(x
, y
, w
, h
);
347 static void fillStrokeRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
349 UNUSED(displayCanvas
);
351 frskyOsdFillStrokeRect(x
, y
, w
, h
);
354 static void strokeEllipseInRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
356 UNUSED(displayCanvas
);
358 frskyOsdStrokeEllipseInRect(x
, y
, w
, h
);
361 static void fillEllipseInRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
363 UNUSED(displayCanvas
);
365 frskyOsdFillEllipseInRect(x
, y
, w
, h
);
368 static void fillStrokeEllipseInRect(displayCanvas_t
*displayCanvas
, int x
, int y
, int w
, int h
)
370 UNUSED(displayCanvas
);
372 frskyOsdFillStrokeEllipseInRect(x
, y
, w
, h
);
375 static void ctmReset(displayCanvas_t
*displayCanvas
)
377 UNUSED(displayCanvas
);
382 static void ctmSet(displayCanvas_t
*displayCanvas
, float m11
, float m12
, float m21
, float m22
, float m31
, float m32
)
384 UNUSED(displayCanvas
);
386 frskyOsdCtmSet(m11
, m12
, m21
, m22
, m31
, m32
);
389 static void ctmTranslate(displayCanvas_t
*displayCanvas
, float tx
, float ty
)
391 UNUSED(displayCanvas
);
393 frskyOsdCtmTranslate(tx
, ty
);
396 static void ctmScale(displayCanvas_t
*displayCanvas
, float sx
, float sy
)
398 UNUSED(displayCanvas
);
400 frskyOsdCtmScale(sx
, sy
);
403 static void ctmRotate(displayCanvas_t
*displayCanvas
, float r
)
405 UNUSED(displayCanvas
);
407 frskyOsdCtmRotate(r
);
410 static void contextPush(displayCanvas_t
*displayCanvas
)
412 UNUSED(displayCanvas
);
414 frskyOsdContextPush();
417 static void contextPop(displayCanvas_t
*displayCanvas
)
419 UNUSED(displayCanvas
);
421 frskyOsdContextPop();
425 static const displayCanvasVTable_t frskyOsdCanvasVTable
= {
426 .setStrokeColor
= setStrokeColor
,
427 .setFillColor
= setFillColor
,
428 .setStrokeAndFillColor
= setStrokeAndFillColor
,
429 .setColorInversion
= setColorInversion
,
430 .setPixel
= setPixel
,
431 .setPixelToStrokeColor
= setPixelToStrokeColor
,
432 .setPixelToFillColor
= setPixelToFillColor
,
433 .setStrokeWidth
= setStrokeWidth
,
434 .setLineOutlineType
= setLineOutlineType
,
435 .setLineOutlineColor
= setLineOutlineColor
,
437 .clipToRect
= clipToRect
,
438 .clearRect
= clearRect
,
439 .resetDrawingState
= resetDrawingState
,
440 .drawCharacter
= drawCharacter
,
441 .drawCharacterMask
= drawCharacterMask
,
442 .drawString
= drawString
,
443 .drawStringMask
= drawStringMask
,
444 .moveToPoint
= moveToPoint
,
445 .strokeLineToPoint
= strokeLineToPoint
,
446 .strokeTriangle
= strokeTriangle
,
447 .fillTriangle
= fillTriangle
,
448 .fillStrokeTriangle
= fillStrokeTriangle
,
449 .strokeRect
= strokeRect
,
450 .fillRect
= fillRect
,
451 .fillStrokeRect
= fillStrokeRect
,
452 .strokeEllipseInRect
= strokeEllipseInRect
,
453 .fillEllipseInRect
= fillEllipseInRect
,
454 .fillStrokeEllipseInRect
= fillStrokeEllipseInRect
,
456 .ctmReset
= ctmReset
,
458 .ctmTranslate
= ctmTranslate
,
459 .ctmScale
= ctmScale
,
460 .ctmRotate
= ctmRotate
,
462 .contextPush
= contextPush
,
463 .contextPop
= contextPop
,
466 static bool getCanvas(displayCanvas_t
*canvas
, const displayPort_t
*instance
)
470 canvas
->vTable
= &frskyOsdCanvasVTable
;
471 canvas
->width
= frskyOsdGetPixelWidth();
472 canvas
->height
= frskyOsdGetPixelHeight();
476 static const displayPortVTable_t frskyOsdVTable
= {
479 .clearScreen
= clearScreen
,
480 .drawScreen
= drawScreen
,
481 .screenSize
= screenSize
,
482 .writeString
= writeString
,
483 .writeChar
= writeChar
,
484 .isTransferInProgress
= isTransferInProgress
,
485 .heartbeat
= heartbeat
,
487 .txBytesFree
= txBytesFree
,
488 .writeFontCharacter
= writeFontCharacter
,
489 .checkReady
= checkReady
,
490 .beginTransaction
= beginTransaction
,
491 .commitTransaction
= commitTransaction
,
492 .getCanvas
= getCanvas
,
495 displayPort_t
*frskyOsdDisplayPortInit(const videoSystem_e videoSystem
)
497 if (frskyOsdInit(videoSystem
)) {
498 displayInit(&frskyOsdDisplayPort
, &frskyOsdVTable
, DISPLAYPORT_DEVICE_TYPE_FRSKYOSD
);
499 redraw(&frskyOsdDisplayPort
);
500 return &frskyOsdDisplayPort
;
505 #endif // USE_FRSKYOSD