Removed excess trailing spaces before new lines on licenses.
[betaflight.git] / src / main / io / displayport_max7456.c
blobf865c2b9972060013fd2faa9710642911436fe40
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"
37 #include "io/osd_slave.h"
39 #include "pg/max7456.h"
40 #include "pg/pg.h"
41 #include "pg/pg_ids.h"
42 #include "pg/vcd.h"
44 displayPort_t max7456DisplayPort;
46 PG_REGISTER_WITH_RESET_FN(displayPortProfile_t, displayPortProfileMax7456, PG_DISPLAY_PORT_MAX7456_CONFIG, 0);
48 void pgResetFn_displayPortProfileMax7456(displayPortProfile_t *displayPortProfile)
50 displayPortProfile->colAdjust = 0;
51 displayPortProfile->rowAdjust = 0;
53 // Set defaults as per MAX7456 datasheet
54 displayPortProfile->invert = false;
55 displayPortProfile->blackBrightness = 0;
56 displayPortProfile->whiteBrightness = 2;
59 static int grab(displayPort_t *displayPort)
61 // FIXME this should probably not have a dependency on the OSD or OSD slave code
62 UNUSED(displayPort);
63 #ifdef USE_OSD
64 osdResetAlarms();
65 resumeRefreshAt = 0;
66 #endif
68 return 0;
71 static int release(displayPort_t *displayPort)
73 UNUSED(displayPort);
75 return 0;
78 static int clearScreen(displayPort_t *displayPort)
80 UNUSED(displayPort);
82 max7456Invert(displayPortProfileMax7456()->invert);
83 max7456Brightness(displayPortProfileMax7456()->blackBrightness, displayPortProfileMax7456()->whiteBrightness);
85 max7456ClearScreen();
87 return 0;
90 static int drawScreen(displayPort_t *displayPort)
92 UNUSED(displayPort);
93 max7456DrawScreen();
95 return 0;
98 static int screenSize(const displayPort_t *displayPort)
100 UNUSED(displayPort);
101 return maxScreenSize;
104 static int writeString(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s)
106 UNUSED(displayPort);
107 max7456Write(x, y, s);
109 return 0;
112 static int writeChar(displayPort_t *displayPort, uint8_t x, uint8_t y, uint8_t c)
114 UNUSED(displayPort);
115 max7456WriteChar(x, y, c);
117 return 0;
120 static bool isTransferInProgress(const displayPort_t *displayPort)
122 UNUSED(displayPort);
123 return max7456DmaInProgress();
126 static bool isSynced(const displayPort_t *displayPort)
128 UNUSED(displayPort);
129 return max7456BuffersSynced();
132 static void resync(displayPort_t *displayPort)
134 UNUSED(displayPort);
135 max7456RefreshAll();
136 displayPort->rows = max7456GetRowsCount() + displayPortProfileMax7456()->rowAdjust;
137 displayPort->cols = 30 + displayPortProfileMax7456()->colAdjust;
140 static int heartbeat(displayPort_t *displayPort)
142 UNUSED(displayPort);
143 return 0;
146 static uint32_t txBytesFree(const displayPort_t *displayPort)
148 UNUSED(displayPort);
149 return UINT32_MAX;
152 static const displayPortVTable_t max7456VTable = {
153 .grab = grab,
154 .release = release,
155 .clearScreen = clearScreen,
156 .drawScreen = drawScreen,
157 .screenSize = screenSize,
158 .writeString = writeString,
159 .writeChar = writeChar,
160 .isTransferInProgress = isTransferInProgress,
161 .heartbeat = heartbeat,
162 .resync = resync,
163 .isSynced = isSynced,
164 .txBytesFree = txBytesFree,
167 displayPort_t *max7456DisplayPortInit(const vcdProfile_t *vcdProfile)
169 displayInit(&max7456DisplayPort, &max7456VTable);
170 #ifdef USE_OSD_SLAVE
171 max7456Init(max7456Config(), vcdProfile, false);
172 #else
173 max7456Init(max7456Config(), vcdProfile, systemConfig()->cpu_overclock);
174 #endif
175 resync(&max7456DisplayPort);
176 return &max7456DisplayPort;
178 #endif // USE_MAX7456