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)
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/>.
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"
38 #include "pg/max7456.h"
40 #include "pg/pg_ids.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
70 static int release(displayPort_t
*displayPort
)
77 static int clearScreen(displayPort_t
*displayPort
)
81 max7456Invert(displayPortProfileMax7456()->invert
);
82 max7456Brightness(displayPortProfileMax7456()->blackBrightness
, displayPortProfileMax7456()->whiteBrightness
);
89 static int drawScreen(displayPort_t
*displayPort
)
97 static int screenSize(const displayPort_t
*displayPort
)
100 return maxScreenSize
;
103 static int writeString(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, const char *s
)
106 max7456Write(x
, y
, s
);
111 static int writeChar(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint8_t c
)
114 max7456WriteChar(x
, y
, c
);
119 static bool isTransferInProgress(const displayPort_t
*displayPort
)
122 return max7456DmaInProgress();
125 static bool isSynced(const displayPort_t
*displayPort
)
128 return max7456BuffersSynced();
131 static void resync(displayPort_t
*displayPort
)
135 displayPort
->rows
= max7456GetRowsCount() + displayPortProfileMax7456()->rowAdjust
;
136 displayPort
->cols
= 30 + displayPortProfileMax7456()->colAdjust
;
139 static int heartbeat(displayPort_t
*displayPort
)
145 static uint32_t txBytesFree(const displayPort_t
*displayPort
)
151 static const displayPortVTable_t max7456VTable
= {
154 .clearScreen
= clearScreen
,
155 .drawScreen
= drawScreen
,
156 .screenSize
= screenSize
,
157 .writeString
= writeString
,
158 .writeChar
= writeChar
,
159 .isTransferInProgress
= isTransferInProgress
,
160 .heartbeat
= heartbeat
,
162 .isSynced
= isSynced
,
163 .txBytesFree
= txBytesFree
,
166 displayPort_t
*max7456DisplayPortInit(const vcdProfile_t
*vcdProfile
)
170 !max7456Init(max7456Config(), vcdProfile
, false)
172 !max7456Init(max7456Config(), vcdProfile
, systemConfig()->cpu_overclock
)
178 displayInit(&max7456DisplayPort
, &max7456VTable
);
180 resync(&max7456DisplayPort
);
181 return &max7456DisplayPort
;
183 #endif // USE_MAX7456