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