Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / drivers / display.h
blobe23e18fb8bc5133e69af6fcda35240b66e415e71
1 /*
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/>.
18 #pragma once
20 #include <stdbool.h>
21 #include <stdint.h>
23 #include "drivers/time.h"
25 #include "config/parameter_group.h"
27 #define SW_BLINK_CYCLE_MS 500 // Xms on / Xms off
29 #define getBlinkOnOff() ( (millis() / SW_BLINK_CYCLE_MS) & 1 )
31 typedef struct osdCharacter_s osdCharacter_t;
33 typedef struct displayConfig_s {
34 bool force_sw_blink; // Enable SW blinking. Used for chips which don't work correctly with HW blink.
35 } displayConfig_t;
37 PG_DECLARE(displayConfig_t, displayConfig);
39 typedef enum {
40 DISPLAY_TRANSACTION_OPT_NONE = 0,
41 DISPLAY_TRANSACTION_OPT_PROFILED = 1 << 0,
42 DISPLAY_TRANSACTION_OPT_RESET_DRAWING = 1 << 1,
43 } displayTransactionOption_e;
45 // Represents the attributes for a given piece of text
46 // either a single character or a string. For forward
47 // compatibility, always use the TEXT_ATTRIBUTE...
48 // macros when manipulating or testing textAttributes_t.
49 typedef uint8_t textAttributes_t;
52 #define _TEXT_ATTRIBUTES_BLINK_BIT (1 << 0)
53 #define _TEXT_ATTRIBUTES_INVERTED_BIT (1 << 1)
54 #define _TEXT_ATTRIBUTES_SOLID_BG_BIT (1 << 2)
56 #define TEXT_ATTRIBUTES_NONE 0
57 #define TEXT_ATTRIBUTES_ADD_BLINK(x) ((x) |= _TEXT_ATTRIBUTES_BLINK_BIT)
58 #define TEXT_ATTRIBUTES_ADD_INVERTED(x) ((x) |= _TEXT_ATTRIBUTES_INVERTED_BIT)
59 #define TEXT_ATTRIBUTES_ADD_SOLID_BG(x) ((x) |= _TEXT_ATTRIBUTES_SOLID_BG_BIT)
61 #define TEXT_ATTRIBUTES_REMOVE_BLINK(x) ((x) &= ~_TEXT_ATTRIBUTES_BLINK_BIT)
62 #define TEXT_ATTRIBUTES_REMOVE_INVERTED(x) ((x) &= ~_TEXT_ATTRIBUTES_INVERTED_BIT)
63 #define TEXT_ATTRIBUTES_REMOVE_SOLID_BG(x) ((x) &= ~_TEXT_ATTRIBUTES_SOLID_BG_BIT)
65 #define TEXT_ATTRIBUTES_HAVE_BLINK(x) (x & _TEXT_ATTRIBUTES_BLINK_BIT)
66 #define TEXT_ATTRIBUTES_HAVE_INVERTED(x) (x & _TEXT_ATTRIBUTES_INVERTED_BIT)
67 #define TEXT_ATTRIBUTES_HAVE_SOLID_BG(x) (x & _TEXT_ATTRIBUTES_SOLID_BG_BIT)
69 static inline void TEXT_ATTRIBUTES_COPY(textAttributes_t *dst, textAttributes_t *src) { *dst = *src; }
71 typedef struct displayCanvas_s displayCanvas_t;
72 typedef struct displayFontMetadata_s displayFontMetadata_t;
73 typedef struct displayPortVTable_s displayPortVTable_t;
75 typedef struct displayPort_s {
76 const displayPortVTable_t *vTable;
77 void *device;
78 const char* displayPortType;
79 uint8_t rows;
80 uint8_t cols;
81 uint8_t posX;
82 uint8_t posY;
84 // CMS state
85 bool useFullscreen;
86 bool cleared;
87 int8_t cursorRow;
88 int8_t grabCount;
89 textAttributes_t cachedSupportedTextAttributes;
90 uint16_t maxChar;
91 } displayPort_t;
93 typedef struct displayPortVTable_s {
94 int (*grab)(displayPort_t *displayPort);
95 int (*release)(displayPort_t *displayPort);
96 int (*clearScreen)(displayPort_t *displayPort);
97 int (*drawScreen)(displayPort_t *displayPort);
98 int (*screenSize)(const displayPort_t *displayPort);
99 int (*writeString)(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *text, textAttributes_t attr);
100 int (*writeChar)(displayPort_t *displayPort, uint8_t x, uint8_t y, uint16_t c, textAttributes_t attr);
101 bool (*readChar)(displayPort_t *displayPort, uint8_t x, uint8_t y, uint16_t *c, textAttributes_t *attr);
102 bool (*isTransferInProgress)(const displayPort_t *displayPort);
103 int (*heartbeat)(displayPort_t *displayPort);
104 void (*resync)(displayPort_t *displayPort);
105 uint32_t (*txBytesFree)(const displayPort_t *displayPort);
106 textAttributes_t (*supportedTextAttributes)(const displayPort_t *displayPort);
107 bool (*getFontMetadata)(displayFontMetadata_t *metadata, const displayPort_t *displayPort);
108 int (*writeFontCharacter)(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr);
109 bool (*isReady)(displayPort_t *displayPort);
110 void (*beginTransaction)(displayPort_t *displayPort, displayTransactionOption_e opts);
111 void (*commitTransaction)(displayPort_t *displayPort);
112 bool (*getCanvas)(displayCanvas_t *canvas, const displayPort_t *displayPort);
113 } displayPortVTable_t;
115 typedef struct displayPortProfile_s {
116 int8_t colAdjust;
117 int8_t rowAdjust;
118 bool invert;
119 uint8_t blackBrightness;
120 uint8_t whiteBrightness;
121 } displayPortProfile_t;
123 void displayGrab(displayPort_t *instance);
124 void displayRelease(displayPort_t *instance);
125 void displayReleaseAll(displayPort_t *instance);
126 bool displayIsGrabbed(const displayPort_t *instance);
127 void displayClearScreen(displayPort_t *instance);
128 void displayDrawScreen(displayPort_t *instance);
129 int displayScreenSize(const displayPort_t *instance);
130 void displaySetXY(displayPort_t *instance, uint8_t x, uint8_t y);
131 int displayWrite(displayPort_t *instance, uint8_t x, uint8_t y, const char *s);
132 int displayWriteWithAttr(displayPort_t *instance, uint8_t x, uint8_t y, const char *s, textAttributes_t attr);
133 int displayWriteChar(displayPort_t *instance, uint8_t x, uint8_t y, uint16_t c);
134 int displayWriteCharWithAttr(displayPort_t *instance, uint8_t x, uint8_t y, uint16_t c, textAttributes_t attr);
135 bool displayReadCharWithAttr(displayPort_t *instance, uint8_t x, uint8_t y, uint16_t *c, textAttributes_t *attr);
136 bool displayIsTransferInProgress(const displayPort_t *instance);
137 void displayHeartbeat(displayPort_t *instance);
138 void displayResync(displayPort_t *instance);
139 uint16_t displayTxBytesFree(const displayPort_t *instance);
140 bool displayGetFontMetadata(displayFontMetadata_t *metadata, const displayPort_t *instance);
141 int displayWriteFontCharacter(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr);
142 bool displayIsReady(displayPort_t *instance);
143 void displayBeginTransaction(displayPort_t *instance, displayTransactionOption_e opts);
144 void displayCommitTransaction(displayPort_t *instance);
145 bool displayGetCanvas(displayCanvas_t *canvas, const displayPort_t *instance);
146 void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable);