Removed SPRACINGF3OSD support.
[betaflight.git] / src / main / io / displayport_max7456.c
blobba0288a76aba0cdb0914ae83d041e29442f31a2f
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * 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/>.
21 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
26 #ifdef USE_MAX7456
28 #include "common/utils.h"
30 #include "drivers/display.h"
31 #include "drivers/max7456.h"
33 #include "fc/config.h"
35 #include "io/displayport_max7456.h"
36 #include "io/osd.h"
38 #include "pg/max7456.h"
39 #include "pg/pg.h"
40 #include "pg/pg_ids.h"
41 #include "pg/vcd.h"
43 displayPort_t max7456DisplayPort;
45 PG_REGISTER_WITH_RESET_FN(displayPortProfile_t, displayPortProfileMax7456, PG_DISPLAY_PORT_MAX7456_CONFIG, 0);
47 void pgResetFn_displayPortProfileMax7456(displayPortProfile_t *displayPortProfile)
49 displayPortProfile->colAdjust = 0;
50 displayPortProfile->rowAdjust = 0;
52 // Set defaults as per MAX7456 datasheet
53 displayPortProfile->invert = false;
54 displayPortProfile->blackBrightness = 0;
55 displayPortProfile->whiteBrightness = 2;
58 static int grab(displayPort_t *displayPort)
60 // FIXME this should probably not have a dependency on the OSD or OSD slave code
61 UNUSED(displayPort);
62 #ifdef USE_OSD
63 osdResetAlarms();
64 resumeRefreshAt = 0;
65 #endif
67 return 0;
70 static int release(displayPort_t *displayPort)
72 UNUSED(displayPort);
74 return 0;
77 static int clearScreen(displayPort_t *displayPort)
79 UNUSED(displayPort);
81 max7456Invert(displayPortProfileMax7456()->invert);
82 max7456Brightness(displayPortProfileMax7456()->blackBrightness, displayPortProfileMax7456()->whiteBrightness);
84 max7456ClearScreen();
86 return 0;
89 static int drawScreen(displayPort_t *displayPort)
91 UNUSED(displayPort);
92 max7456DrawScreen();
94 return 0;
97 static int screenSize(const displayPort_t *displayPort)
99 UNUSED(displayPort);
100 return maxScreenSize;
103 static int writeString(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s)
105 UNUSED(displayPort);
106 max7456Write(x, y, s);
108 return 0;
111 static int writeChar(displayPort_t *displayPort, uint8_t x, uint8_t y, uint8_t c)
113 UNUSED(displayPort);
114 max7456WriteChar(x, y, c);
116 return 0;
119 static bool isTransferInProgress(const displayPort_t *displayPort)
121 UNUSED(displayPort);
122 return max7456DmaInProgress();
125 static bool isSynced(const displayPort_t *displayPort)
127 UNUSED(displayPort);
128 return max7456BuffersSynced();
131 static void resync(displayPort_t *displayPort)
133 UNUSED(displayPort);
134 max7456RefreshAll();
135 displayPort->rows = max7456GetRowsCount() + displayPortProfileMax7456()->rowAdjust;
136 displayPort->cols = 30 + displayPortProfileMax7456()->colAdjust;
139 static int heartbeat(displayPort_t *displayPort)
141 UNUSED(displayPort);
142 return 0;
145 static uint32_t txBytesFree(const displayPort_t *displayPort)
147 UNUSED(displayPort);
148 return UINT32_MAX;
151 static const displayPortVTable_t max7456VTable = {
152 .grab = grab,
153 .release = release,
154 .clearScreen = clearScreen,
155 .drawScreen = drawScreen,
156 .screenSize = screenSize,
157 .writeString = writeString,
158 .writeChar = writeChar,
159 .isTransferInProgress = isTransferInProgress,
160 .heartbeat = heartbeat,
161 .resync = resync,
162 .isSynced = isSynced,
163 .txBytesFree = txBytesFree,
166 displayPort_t *max7456DisplayPortInit(const vcdProfile_t *vcdProfile)
168 if (
169 #ifdef USE_OSD_SLAVE
170 !max7456Init(max7456Config(), vcdProfile, false)
171 #else
172 !max7456Init(max7456Config(), vcdProfile, systemConfig()->cpu_overclock)
173 #endif
175 return NULL;
178 displayInit(&max7456DisplayPort, &max7456VTable);
180 resync(&max7456DisplayPort);
181 return &max7456DisplayPort;
183 #endif // USE_MAX7456