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"
37 #include "io/osd_slave.h"
39 #include "pg/max7456.h"
41 #include "pg/pg_ids.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
71 static int release(displayPort_t
*displayPort
)
78 static int clearScreen(displayPort_t
*displayPort
)
82 max7456Invert(displayPortProfileMax7456()->invert
);
83 max7456Brightness(displayPortProfileMax7456()->blackBrightness
, displayPortProfileMax7456()->whiteBrightness
);
90 static int drawScreen(displayPort_t
*displayPort
)
98 static int screenSize(const displayPort_t
*displayPort
)
101 return maxScreenSize
;
104 static int writeString(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, const char *s
)
107 max7456Write(x
, y
, s
);
112 static int writeChar(displayPort_t
*displayPort
, uint8_t x
, uint8_t y
, uint8_t c
)
115 max7456WriteChar(x
, y
, c
);
120 static bool isTransferInProgress(const displayPort_t
*displayPort
)
123 return max7456DmaInProgress();
126 static bool isSynced(const displayPort_t
*displayPort
)
129 return max7456BuffersSynced();
132 static void resync(displayPort_t
*displayPort
)
136 displayPort
->rows
= max7456GetRowsCount() + displayPortProfileMax7456()->rowAdjust
;
137 displayPort
->cols
= 30 + displayPortProfileMax7456()->colAdjust
;
140 static int heartbeat(displayPort_t
*displayPort
)
146 static uint32_t txBytesFree(const displayPort_t
*displayPort
)
152 static const displayPortVTable_t max7456VTable
= {
155 .clearScreen
= clearScreen
,
156 .drawScreen
= drawScreen
,
157 .screenSize
= screenSize
,
158 .writeString
= writeString
,
159 .writeChar
= writeChar
,
160 .isTransferInProgress
= isTransferInProgress
,
161 .heartbeat
= heartbeat
,
163 .isSynced
= isSynced
,
164 .txBytesFree
= txBytesFree
,
167 displayPort_t
*max7456DisplayPortInit(const vcdProfile_t
*vcdProfile
)
169 displayInit(&max7456DisplayPort
, &max7456VTable
);
171 max7456Init(max7456Config(), vcdProfile
, false);
173 max7456Init(max7456Config(), vcdProfile
, systemConfig()->cpu_overclock
);
175 resync(&max7456DisplayPort
);
176 return &max7456DisplayPort
;
178 #endif // USE_MAX7456