Skip to content

Commit 75da202

Browse files
committed
Remove all MAX7456 specific code, replace it with generic interfaces
- Rename max7456_symbols.h to osd_symbols.h. We'll expect all supported OSD drivers to use the same font style. - Introduce drivers/osd.h, which defines the supported video systems and the format for the OSD characters that all drivers must support. - Remove drivers/vcd.h, since having a file for a single enum is kind of annoying, move this enum to the new drivers/osd.h file. - Add osdGetDisplayPort() for retriving the display port used by the OSD. - Add a new display function named writeFontCharacter() which takes a character address and its data. - Use the aforementioned 2 functions to implement character font uploading in fc_msp.c, so it's not MAX7456-specific anymore.
1 parent fb62330 commit 75da202

File tree

15 files changed

+129
-80
lines changed

15 files changed

+129
-80
lines changed

src/main/drivers/display.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ bool displayGetFontMetadata(displayFontMetadata_t *metadata, const displayPort_t
229229
return false;
230230
}
231231

232+
int displayWriteFontCharacter(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr)
233+
{
234+
if (instance->vTable->writeFontCharacter) {
235+
return instance->vTable->writeFontCharacter(instance, addr, chr);
236+
}
237+
return -1;
238+
}
239+
232240
void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable)
233241
{
234242
instance->vTable = vTable;

src/main/drivers/display.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "config/parameter_group.h"
2424

25+
#include "drivers/osd.h"
26+
2527
typedef struct displayConfig_s {
2628
bool force_sw_blink; // Enable SW blinking. Used for chips which don't work correctly with HW blink.
2729
} displayConfig_t;
@@ -91,6 +93,7 @@ typedef struct displayPortVTable_s {
9193
uint32_t (*txBytesFree)(const displayPort_t *displayPort);
9294
textAttributes_t (*supportedTextAttributes)(const displayPort_t *displayPort);
9395
bool (*getFontMetadata)(displayFontMetadata_t *metadata, const displayPort_t *displayPort);
96+
int (*writeFontCharacter)(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr);
9497
} displayPortVTable_t;
9598

9699
typedef struct displayPortProfile_s {
@@ -119,4 +122,5 @@ void displayHeartbeat(displayPort_t *instance);
119122
void displayResync(displayPort_t *instance);
120123
uint16_t displayTxBytesFree(const displayPort_t *instance);
121124
bool displayGetFontMetadata(displayFontMetadata_t *metadata, const displayPort_t *instance);
125+
int displayWriteFontCharacter(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr);
122126
void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable);

src/main/drivers/max7456.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929
#include "common/utils.h"
3030

3131
#include "drivers/bus.h"
32-
#include "drivers/light_led.h"
32+
#include "drivers/dma.h"
3333
#include "drivers/io.h"
34-
#include "drivers/time.h"
34+
#include "drivers/light_led.h"
3535
#include "drivers/nvic.h"
36-
#include "drivers/dma.h"
37-
#include "drivers/vcd.h"
36+
#include "drivers/time.h"
3837

3938
#include "max7456.h"
40-
#include "max7456_symbols.h"
4139

4240
// VM0 bits
4341
#define VIDEO_BUFFER_DISABLE 0x01
@@ -637,7 +635,7 @@ void max7456RefreshAll(void)
637635
}
638636
}
639637

640-
void max7456ReadNvm(uint16_t char_address, max7456Character_t *chr)
638+
void max7456ReadNvm(uint16_t char_address, osdCharacter_t *chr)
641639
{
642640
// Check if device is available
643641
if (state.dev == NULL) {
@@ -669,7 +667,7 @@ void max7456ReadNvm(uint16_t char_address, max7456Character_t *chr)
669667
max7456Unlock();
670668
}
671669

672-
void max7456WriteNvm(uint16_t char_address, const max7456Character_t *chr)
670+
void max7456WriteNvm(uint16_t char_address, const osdCharacter_t *chr)
673671
{
674672
uint8_t spiBuff[(sizeof(chr->data) * 2 + 2) * 2];
675673
int bufPtr = 0;

src/main/drivers/max7456.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#pragma once
1919

2020
#include <stdbool.h>
21-
#include "drivers/vcd.h"
21+
22+
#include "drivers/osd.h"
2223

2324
#ifndef WHITEBRIGHTNESS
2425
#define WHITEBRIGHTNESS 0x01
@@ -41,14 +42,10 @@ enum VIDEO_TYPES { AUTO = 0, PAL, NTSC };
4142
#define MAX7456_MODE_BLINK (1 << 4)
4243
#define MAX7456_MODE_SOLID_BG (1 << 5)
4344

44-
typedef struct max7456Character_s {
45-
uint8_t data[54];
46-
} max7456Character_t;
47-
4845
void max7456Init(const videoSystem_e videoSystem);
4946
void max7456Update(void);
50-
void max7456ReadNvm(uint16_t char_address, max7456Character_t *chr);
51-
void max7456WriteNvm(uint16_t char_address, const max7456Character_t *chr);
47+
void max7456ReadNvm(uint16_t char_address, osdCharacter_t *chr);
48+
void max7456WriteNvm(uint16_t char_address, const osdCharacter_t *chr);
5249
uint16_t max7456GetScreenSize(void);
5350
uint8_t max7456GetRowsCount(void);
5451
void max7456Write(uint8_t x, uint8_t y, const char *buff, uint8_t mode);

src/main/drivers/osd.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of Cleanflight, Betaflight and INAV
3+
*
4+
* Cleanflight, Betaflight and INAV are free software. You can
5+
* redistribute this software and/or modify this software under
6+
* the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License,
8+
* or (at your option) any later version.
9+
*
10+
* Cleanflight, Betaflight and INAV are distributed in the hope that
11+
* they will be useful, but WITHOUT ANY WARRANTY; without even the
12+
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13+
* PURPOSE. See the GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this software.
17+
*
18+
* If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#pragma once
22+
23+
#include <stdint.h>
24+
25+
#define OSD_CHAR_WIDTH 12
26+
#define OSD_CHAR_HEIGHT 18
27+
#define OSD_CHAR_BITS_PER_PIXEL 2
28+
#define OSD_CHAR_BYTES (OSD_CHAR_WIDTH * OSD_CHAR_HEIGHT * OSD_CHAR_BITS_PER_PIXEL / 8)
29+
30+
#define OSD_CHARACTER_COLOR_BLACK 0
31+
#define OSD_CHARACTER_COLOR_TRANSPARENT 1
32+
#define OSD_CHARACTER_COLOR_WHITE 2
33+
34+
// 3 is unused but it's interpreted as transparent by all drivers
35+
36+
37+
// Video Character Display parameters
38+
39+
typedef enum {
40+
VIDEO_SYSTEM_AUTO = 0,
41+
VIDEO_SYSTEM_PAL,
42+
VIDEO_SYSTEM_NTSC
43+
} videoSystem_e;
44+
45+
typedef enum {
46+
OSD_DRIVER_NONE = 0,
47+
OSD_DRIVER_MAX7456 = 1,
48+
} osdDriver_e;
49+
50+
// osdCharacter_t represents the binary data for an OSD
51+
// character. All OSD drivers use the same character format
52+
// as defined by OSD_CHARACTER_WIDTH, OSD_CHARACTER_HEIGHT
53+
// and OSD_CHARACTER_BITS_PER_PIXEL.
54+
typedef struct osdCharacter_s {
55+
uint8_t data[OSD_CHAR_BYTES];
56+
} osdCharacter_t;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* @file max7456_symbols.h
2-
* @brief max7456 symbols for the mwosd font set
1+
/* @file osd_symbols.h
2+
* @brief Based on max7456 symbols for the mwosd font set
33
*
44
* @author Nathan Tsoi [email protected]
55
*
@@ -21,7 +21,7 @@
2121

2222
#pragma once
2323

24-
#ifdef USE_MAX7456
24+
#ifdef USE_OSD
2525

2626
#define SYM_RSSI 0x01 // 001 Icon RSSI
2727
#define SYM_AH_RIGHT 0x02 // 002 Arrow left
@@ -53,8 +53,8 @@
5353
#define SYM_HEADING_S 0x19 // 025 Heading Graphic south
5454
#define SYM_HEADING_E 0x1A // 026 Heading Graphic east
5555
#define SYM_HEADING_W 0x1B // 027 Heading Graphic west
56-
#define SYM_HEADING_DIVIDED_LINE 0x1C // 028 Heading Graphic
57-
#define SYM_HEADING_LINE 0x1D // 029 Heading Graphic
56+
#define SYM_HEADING_DIVIDED_LINE 0x1C // 028 Heading Graphic
57+
#define SYM_HEADING_LINE 0x1D // 029 Heading Graphic
5858

5959
#define SYM_SAT_L 0x1E // 030 Sats left
6060
#define SYM_SAT_R 0x1F // 031 Sats right
@@ -124,13 +124,13 @@
124124
#define SYM_BATT_FULL 0x90 // 144 Battery full
125125
#define SYM_BATT_5 0x91 // 145 Battery
126126
#define SYM_BATT_4 0x92 // 146 Battery
127-
#define SYM_BATT_3 0x93 // 147 Battery
127+
#define SYM_BATT_3 0x93 // 147 Battery
128128
#define SYM_BATT_2 0x94 // 148 Battery
129129
#define SYM_BATT_1 0x95 // 149 Battery
130130
#define SYM_BATT_EMPTY 0x96 // 150 Battery empty
131131

132132
#define SYM_AIR 0x97 // 151 Air speed
133-
// 0x98 // 152 Home point map
133+
// 0x98 // 152 Home point map
134134
#define SYM_FTS 0x99 // 153 FT/S
135135
#define SYM_AMP 0x9A // 154 A
136136
#define SYM_ON_M 0x9B // 155 On MN
@@ -187,9 +187,9 @@
187187
#define SYM_ZERO_HALF_LEADING_DOT 0xD0 // 208 to 217 Numbers with leading dot
188188

189189
#define SYM_AH_CH_AIRCRAFT0 0xDA // 218 Crossair aircraft left
190-
#define SYM_AH_CH_AIRCRAFT1 0xDB // 219 Crossair aircraft
190+
#define SYM_AH_CH_AIRCRAFT1 0xDB // 219 Crossair aircraft
191191
#define SYM_AH_CH_AIRCRAFT2 0xDC // 220 Crossair aircraft center
192-
#define SYM_AH_CH_AIRCRAFT3 0xDD // 221 Crossair aircraft
192+
#define SYM_AH_CH_AIRCRAFT3 0xDD // 221 Crossair aircraft
193193
#define SYM_AH_CH_AIRCRAFT4 0xDE // 222 Crossair aircraft right
194194

195195
#define SYM_PITCH_DOWN 0xDF // 223 Pitch down

src/main/drivers/vcd.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/fc/cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extern uint8_t __config_end;
5656
#include "drivers/io.h"
5757
#include "drivers/io_impl.h"
5858
#include "drivers/logging.h"
59-
#include "drivers/max7456_symbols.h"
59+
#include "drivers/osd_symbols.h"
6060
#include "drivers/rx_pwm.h"
6161
#include "drivers/sdcard.h"
6262
#include "drivers/sensor.h"

src/main/fc/fc_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "drivers/light_led.h"
5555
#include "drivers/logging.h"
5656
#include "drivers/nvic.h"
57+
#include "drivers/osd.h"
5758
#include "drivers/pwm_esc_detect.h"
5859
#include "drivers/pwm_mapping.h"
5960
#include "drivers/pwm_output.h"
@@ -70,7 +71,6 @@
7071
#include "drivers/time.h"
7172
#include "drivers/timer.h"
7273
#include "drivers/uart_inverter.h"
73-
#include "drivers/vcd.h"
7474
#include "drivers/io.h"
7575
#include "drivers/exti.h"
7676
#include "drivers/io_pca9685.h"

src/main/fc/fc_msp.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
#include "drivers/accgyro/accgyro.h"
4242
#include "drivers/bus_i2c.h"
4343
#include "drivers/compass/compass.h"
44-
#include "drivers/max7456.h"
45-
#include "drivers/max7456_symbols.h"
44+
#include "drivers/display.h"
45+
#include "drivers/osd.h"
46+
#include "drivers/osd_symbols.h"
4647
#include "drivers/pwm_mapping.h"
4748
#include "drivers/sdcard.h"
4849
#include "drivers/serial.h"
@@ -315,7 +316,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
315316
// 0 = no OSD
316317
// 1 = OSD slave (not supported in INAV)
317318
// 2 = OSD chip on board
318-
#if defined(USE_OSD) && defined(USE_MAX7456)
319+
#if defined(USE_OSD)
319320
sbufWriteU8(dst, 2);
320321
#else
321322
sbufWriteU8(dst, 0);
@@ -1020,13 +1021,9 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
10201021

10211022
case MSP_OSD_CONFIG:
10221023
#ifdef USE_OSD
1023-
sbufWriteU8(dst, 1); // OSD supported
1024+
sbufWriteU8(dst, OSD_DRIVER_MAX7456); // OSD supported
10241025
// send video system (AUTO/PAL/NTSC)
1025-
#ifdef USE_MAX7456
10261026
sbufWriteU8(dst, osdConfig()->video_system);
1027-
#else
1028-
sbufWriteU8(dst, 0);
1029-
#endif
10301027
sbufWriteU8(dst, osdConfig()->units);
10311028
sbufWriteU8(dst, osdConfig()->rssi_alarm);
10321029
sbufWriteU16(dst, currentBatteryProfile->capacity.warning);
@@ -1038,7 +1035,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
10381035
sbufWriteU16(dst, osdConfig()->item_pos[0][i]);
10391036
}
10401037
#else
1041-
sbufWriteU8(dst, 0); // OSD not supported
1038+
sbufWriteU8(dst, OSD_DRIVER_NONE); // OSD not supported
10421039
#endif
10431040
break;
10441041

@@ -2234,11 +2231,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
22342231
// set all the other settings
22352232
if ((int8_t)tmp_u8 == -1) {
22362233
if (dataSize >= 10) {
2237-
#ifdef USE_MAX7456
22382234
osdConfigMutable()->video_system = sbufReadU8(src);
2239-
#else
2240-
sbufReadU8(src); // Skip video system
2241-
#endif
22422235
osdConfigMutable()->units = sbufReadU8(src);
22432236
osdConfigMutable()->rssi_alarm = sbufReadU8(src);
22442237
currentBatteryProfileMutable->capacity.warning = sbufReadU16(src);
@@ -2264,23 +2257,26 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
22642257
break;
22652258

22662259
case MSP_OSD_CHAR_WRITE:
2267-
#ifdef USE_MAX7456
22682260
if (dataSize >= 55) {
2269-
max7456Character_t chr;
2261+
osdCharacter_t chr;
22702262
uint16_t addr;
22712263
if (dataSize >= 56) {
2264+
// 16 bit character address
22722265
addr = sbufReadU16(src);
22732266
} else {
2267+
// 8 bit character address, for backwards compatibility
22742268
addr = sbufReadU8(src);
22752269
}
22762270
for (unsigned ii = 0; ii < sizeof(chr.data); ii++) {
22772271
chr.data[ii] = sbufReadU8(src);
22782272
}
2279-
// !!TODO - replace this with a device independent implementation
2280-
max7456WriteNvm(addr, &chr);
2281-
} else
2273+
displayPort_t *osdDisplayPort = osdGetDisplayPort();
2274+
if (osdDisplayPort) {
2275+
displayWriteFontCharacter(osdDisplayPort, addr, &chr);
2276+
}
2277+
} else {
22822278
return MSP_RESULT_ERROR;
2283-
#endif // USE_MAX7456
2279+
}
22842280
break;
22852281
#endif // USE_OSD
22862282

0 commit comments

Comments
 (0)