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/>.
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
)
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
;
53 static int grab(displayPort_t
*displayPort
)
59 static int release(displayPort_t
*displayPort
)
65 static int clearScreen(displayPort_t
*displayPort
)
72 static int drawScreen(displayPort_t
*displayPort
)
80 static int screenSize(const displayPort_t
*displayPort
)
83 return max7456GetScreenSize();
86 static int writeString(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, const char *s
, textAttributes_t attr
)
89 max7456Write(x
, y
, s
, max7456Mode(attr
));
94 static int writeChar(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint16_t c
, textAttributes_t attr
)
97 max7456WriteChar(x
, y
, c
, max7456Mode(attr
));
102 static bool readChar(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint16_t *c
, textAttributes_t
*attr
)
105 return max7456ReadChar(x
, y
, c
, attr
);
108 static bool isTransferInProgress(const displayPort_t
*displayPort
)
114 static void resync(displayPort_t
*displayPort
)
118 displayPort
->rows
= max7456GetRowsCount();
119 displayPort
->cols
= 30;
122 static int heartbeat(displayPort_t
*displayPort
)
128 static uint32_t txBytesFree(const displayPort_t
*displayPort
)
134 static textAttributes_t
supportedTextAttributes(const displayPort_t
*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
);
145 static bool getFontMetadata(displayFontMetadata_t
*metadata
, const displayPort_t
*displayPort
)
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;
165 static int writeFontCharacter(displayPort_t
*instance
, uint16_t addr
, const osdCharacter_t
*chr
)
169 max7456WriteNvm(addr
, chr
);
173 static const displayPortVTable_t max7456VTable
= {
176 .clearScreen
= clearScreen
,
177 .drawScreen
= drawScreen
,
178 .screenSize
= screenSize
,
179 .writeString
= writeString
,
180 .writeChar
= writeChar
,
181 .readChar
= readChar
,
182 .isTransferInProgress
= isTransferInProgress
,
183 .heartbeat
= heartbeat
,
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