vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / main / io / displayport_max7456.c
blob6b858079e74e73a9b61938146ffd9b90b393fce6
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 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
23 #ifdef USE_MAX7456
25 #include "common/utils.h"
27 #include "config/parameter_group.h"
28 #include "config/parameter_group_ids.h"
30 #include "drivers/display.h"
31 #include "drivers/display_font_metadata.h"
32 #include "drivers/max7456.h"
34 #include "io/displayport_max7456.h"
36 displayPort_t max7456DisplayPort;
38 static uint8_t max7456Mode(textAttributes_t attr)
40 uint8_t mode = 0;
41 if (TEXT_ATTRIBUTES_HAVE_BLINK(attr)) {
42 mode |= MAX7456_MODE_BLINK;
44 if (TEXT_ATTRIBUTES_HAVE_INVERTED(attr)) {
45 mode |= MAX7456_MODE_INVERT;
47 if (TEXT_ATTRIBUTES_HAVE_SOLID_BG(attr)) {
48 mode |= MAX7456_MODE_SOLID_BG;
50 return mode;
53 static int grab(displayPort_t *displayPort)
55 UNUSED(displayPort);
56 return 0;
59 static int release(displayPort_t *displayPort)
61 UNUSED(displayPort);
62 return 0;
65 static int clearScreen(displayPort_t *displayPort)
67 UNUSED(displayPort);
68 max7456ClearScreen();
69 return 0;
72 static int drawScreen(displayPort_t *displayPort)
74 UNUSED(displayPort);
75 max7456Update();
77 return 0;
80 static int screenSize(const displayPort_t *displayPort)
82 UNUSED(displayPort);
83 return max7456GetScreenSize();
86 static int writeString(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s, textAttributes_t attr)
88 UNUSED(displayPort);
89 max7456Write(x, y, s, max7456Mode(attr));
91 return 0;
94 static int writeChar(displayPort_t *displayPort, uint8_t x, uint8_t y, uint16_t c, textAttributes_t attr)
96 UNUSED(displayPort);
97 max7456WriteChar(x, y, c, max7456Mode(attr));
99 return 0;
102 static bool readChar(displayPort_t *displayPort, uint8_t x, uint8_t y, uint16_t *c, textAttributes_t *attr)
104 UNUSED(displayPort);
105 return max7456ReadChar(x, y, c, attr);
108 static bool isTransferInProgress(const displayPort_t *displayPort)
110 UNUSED(displayPort);
111 return false;
114 static void resync(displayPort_t *displayPort)
116 UNUSED(displayPort);
117 max7456RefreshAll();
118 displayPort->rows = max7456GetRowsCount();
119 displayPort->cols = 30;
122 static int heartbeat(displayPort_t *displayPort)
124 UNUSED(displayPort);
125 return 0;
128 static uint32_t txBytesFree(const displayPort_t *displayPort)
130 UNUSED(displayPort);
131 return UINT32_MAX;
134 static textAttributes_t supportedTextAttributes(const displayPort_t *displayPort)
136 UNUSED(displayPort);
138 textAttributes_t attr = TEXT_ATTRIBUTES_NONE;
139 TEXT_ATTRIBUTES_ADD_INVERTED(attr);
140 TEXT_ATTRIBUTES_ADD_SOLID_BG(attr);
141 TEXT_ATTRIBUTES_ADD_BLINK(attr);
142 return attr;
145 static bool getFontMetadata(displayFontMetadata_t *metadata, const displayPort_t *displayPort)
147 UNUSED(displayPort);
149 osdCharacter_t chr;
151 max7456ReadNvm(FONT_METADATA_CHR_INDEX, &chr);
153 if (displayFontMetadataUpdateFromCharacter(metadata, &chr)) {
154 // Not all MAX7456 chips support 512 characters. To detect this,
155 // we place metadata in both characters 255 and 256. This way we
156 // can find out how many characters the font in NVM has.
157 max7456ReadNvm(FONT_METADATA_CHR_INDEX_2ND_PAGE, &chr);
158 metadata->charCount = FONT_CHR_IS_METADATA(&chr) ? 512 : 256;
159 return true;
162 return false;
165 static int writeFontCharacter(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr)
167 UNUSED(instance);
169 max7456WriteNvm(addr, chr);
170 return 0;
173 static const displayPortVTable_t max7456VTable = {
174 .grab = grab,
175 .release = release,
176 .clearScreen = clearScreen,
177 .drawScreen = drawScreen,
178 .screenSize = screenSize,
179 .writeString = writeString,
180 .writeChar = writeChar,
181 .readChar = readChar,
182 .isTransferInProgress = isTransferInProgress,
183 .heartbeat = heartbeat,
184 .resync = resync,
185 .txBytesFree = txBytesFree,
186 .supportedTextAttributes = supportedTextAttributes,
187 .getFontMetadata = getFontMetadata,
188 .writeFontCharacter = writeFontCharacter,
191 displayPort_t *max7456DisplayPortInit(const videoSystem_e videoSystem)
193 max7456Init(videoSystem);
194 displayInit(&max7456DisplayPort, &max7456VTable);
195 resync(&max7456DisplayPort);
196 max7456DisplayPort.displayPortType = "MAX7456";
197 return &max7456DisplayPort;
199 #endif // USE_MAX7456