Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all MAX7456 specific code, replace it with generic interfaces #4384

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/drivers/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ bool displayGetFontMetadata(displayFontMetadata_t *metadata, const displayPort_t
return false;
}

int displayWriteFontCharacter(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr)
{
if (instance->vTable->writeFontCharacter) {
return instance->vTable->writeFontCharacter(instance, addr, chr);
}
return -1;
}

void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable)
{
instance->vTable = vTable;
Expand Down
4 changes: 4 additions & 0 deletions src/main/drivers/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "config/parameter_group.h"

typedef struct osdCharacter_s osdCharacter_t;

typedef struct displayConfig_s {
bool force_sw_blink; // Enable SW blinking. Used for chips which don't work correctly with HW blink.
} displayConfig_t;
Expand Down Expand Up @@ -91,6 +93,7 @@ typedef struct displayPortVTable_s {
uint32_t (*txBytesFree)(const displayPort_t *displayPort);
textAttributes_t (*supportedTextAttributes)(const displayPort_t *displayPort);
bool (*getFontMetadata)(displayFontMetadata_t *metadata, const displayPort_t *displayPort);
int (*writeFontCharacter)(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr);
} displayPortVTable_t;

typedef struct displayPortProfile_s {
Expand Down Expand Up @@ -119,4 +122,5 @@ void displayHeartbeat(displayPort_t *instance);
void displayResync(displayPort_t *instance);
uint16_t displayTxBytesFree(const displayPort_t *instance);
bool displayGetFontMetadata(displayFontMetadata_t *metadata, const displayPort_t *instance);
int displayWriteFontCharacter(displayPort_t *instance, uint16_t addr, const osdCharacter_t *chr);
void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable);
12 changes: 5 additions & 7 deletions src/main/drivers/max7456.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
#include "common/utils.h"

#include "drivers/bus.h"
#include "drivers/light_led.h"
#include "drivers/dma.h"
#include "drivers/io.h"
#include "drivers/time.h"
#include "drivers/light_led.h"
#include "drivers/nvic.h"
#include "drivers/dma.h"
#include "drivers/vcd.h"
#include "drivers/time.h"

#include "max7456.h"
#include "max7456_symbols.h"

// VM0 bits
#define VIDEO_BUFFER_DISABLE 0x01
Expand Down Expand Up @@ -637,7 +635,7 @@ void max7456RefreshAll(void)
}
}

void max7456ReadNvm(uint16_t char_address, max7456Character_t *chr)
void max7456ReadNvm(uint16_t char_address, osdCharacter_t *chr)
{
// Check if device is available
if (state.dev == NULL) {
Expand Down Expand Up @@ -669,7 +667,7 @@ void max7456ReadNvm(uint16_t char_address, max7456Character_t *chr)
max7456Unlock();
}

void max7456WriteNvm(uint16_t char_address, const max7456Character_t *chr)
void max7456WriteNvm(uint16_t char_address, const osdCharacter_t *chr)
{
uint8_t spiBuff[(sizeof(chr->data) * 2 + 2) * 2];
int bufPtr = 0;
Expand Down
11 changes: 4 additions & 7 deletions src/main/drivers/max7456.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#pragma once

#include <stdbool.h>
#include "drivers/vcd.h"

#include "drivers/osd.h"

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

typedef struct max7456Character_s {
uint8_t data[54];
} max7456Character_t;

void max7456Init(const videoSystem_e videoSystem);
void max7456Update(void);
void max7456ReadNvm(uint16_t char_address, max7456Character_t *chr);
void max7456WriteNvm(uint16_t char_address, const max7456Character_t *chr);
void max7456ReadNvm(uint16_t char_address, osdCharacter_t *chr);
void max7456WriteNvm(uint16_t char_address, const osdCharacter_t *chr);
uint16_t max7456GetScreenSize(void);
uint8_t max7456GetRowsCount(void);
void max7456Write(uint8_t x, uint8_t y, const char *buff, uint8_t mode);
Expand Down
56 changes: 56 additions & 0 deletions src/main/drivers/osd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This file is part of Cleanflight, Betaflight and INAV
*
* Cleanflight, Betaflight and INAV are free software. You can
* redistribute this software and/or modify this software under
* the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Cleanflight, Betaflight and INAV are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <stdint.h>

#define OSD_CHAR_WIDTH 12
#define OSD_CHAR_HEIGHT 18
#define OSD_CHAR_BITS_PER_PIXEL 2
#define OSD_CHAR_BYTES (OSD_CHAR_WIDTH * OSD_CHAR_HEIGHT * OSD_CHAR_BITS_PER_PIXEL / 8)

#define OSD_CHARACTER_COLOR_BLACK 0
#define OSD_CHARACTER_COLOR_TRANSPARENT 1
#define OSD_CHARACTER_COLOR_WHITE 2

// 3 is unused but it's interpreted as transparent by all drivers


// Video Character Display parameters

typedef enum {
VIDEO_SYSTEM_AUTO = 0,
VIDEO_SYSTEM_PAL,
VIDEO_SYSTEM_NTSC
} videoSystem_e;

typedef enum {
OSD_DRIVER_NONE = 0,
OSD_DRIVER_MAX7456 = 1,
} osdDriver_e;

// osdCharacter_t represents the binary data for an OSD
// character. All OSD drivers use the same character format
// as defined by OSD_CHARACTER_WIDTH, OSD_CHARACTER_HEIGHT
// and OSD_CHARACTER_BITS_PER_PIXEL.
typedef struct osdCharacter_s {
uint8_t data[OSD_CHAR_BYTES];
} osdCharacter_t;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @file max7456_symbols.h
* @brief max7456 symbols for the mwosd font set
/* @file osd_symbols.h
* @brief Based on max7456 symbols for the mwosd font set
*
* @author Nathan Tsoi [email protected]
*
Expand All @@ -21,7 +21,7 @@

#pragma once

#ifdef USE_MAX7456
#ifdef USE_OSD

#define SYM_RSSI 0x01 // 001 Icon RSSI
#define SYM_AH_LEFT 0x02 // 002 Arrow left
Expand Down Expand Up @@ -53,8 +53,8 @@
#define SYM_HEADING_S 0x19 // 025 Heading Graphic south
#define SYM_HEADING_E 0x1A // 026 Heading Graphic east
#define SYM_HEADING_W 0x1B // 027 Heading Graphic west
#define SYM_HEADING_DIVIDED_LINE 0x1C // 028 Heading Graphic
#define SYM_HEADING_LINE 0x1D // 029 Heading Graphic
#define SYM_HEADING_DIVIDED_LINE 0x1C // 028 Heading Graphic
#define SYM_HEADING_LINE 0x1D // 029 Heading Graphic

#define SYM_SAT_L 0x1E // 030 Sats left
#define SYM_SAT_R 0x1F // 031 Sats right
Expand Down Expand Up @@ -124,13 +124,13 @@
#define SYM_BATT_FULL 0x90 // 144 Battery full
#define SYM_BATT_5 0x91 // 145 Battery
#define SYM_BATT_4 0x92 // 146 Battery
#define SYM_BATT_3 0x93 // 147 Battery
#define SYM_BATT_3 0x93 // 147 Battery
#define SYM_BATT_2 0x94 // 148 Battery
#define SYM_BATT_1 0x95 // 149 Battery
#define SYM_BATT_EMPTY 0x96 // 150 Battery empty

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

#define SYM_AH_CH_AIRCRAFT0 0xDA // 218 Crossair aircraft left
#define SYM_AH_CH_AIRCRAFT1 0xDB // 219 Crossair aircraft
#define SYM_AH_CH_AIRCRAFT1 0xDB // 219 Crossair aircraft
#define SYM_AH_CH_AIRCRAFT2 0xDC // 220 Crossair aircraft center
#define SYM_AH_CH_AIRCRAFT3 0xDD // 221 Crossair aircraft
#define SYM_AH_CH_AIRCRAFT3 0xDD // 221 Crossair aircraft
#define SYM_AH_CH_AIRCRAFT4 0xDE // 222 Crossair aircraft right

#define SYM_PITCH_DOWN 0xDF // 223 Pitch down
Expand Down
26 changes: 0 additions & 26 deletions src/main/drivers/vcd.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extern uint8_t __config_end;
#include "drivers/io.h"
#include "drivers/io_impl.h"
#include "drivers/logging.h"
#include "drivers/max7456_symbols.h"
#include "drivers/osd_symbols.h"
#include "drivers/rx_pwm.h"
#include "drivers/sdcard.h"
#include "drivers/sensor.h"
Expand Down
2 changes: 1 addition & 1 deletion src/main/fc/fc_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "drivers/light_led.h"
#include "drivers/logging.h"
#include "drivers/nvic.h"
#include "drivers/osd.h"
#include "drivers/pwm_esc_detect.h"
#include "drivers/pwm_mapping.h"
#include "drivers/pwm_output.h"
Expand All @@ -70,7 +71,6 @@
#include "drivers/time.h"
#include "drivers/timer.h"
#include "drivers/uart_inverter.h"
#include "drivers/vcd.h"
#include "drivers/io.h"
#include "drivers/exti.h"
#include "drivers/io_pca9685.h"
Expand Down
34 changes: 15 additions & 19 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
#include "drivers/accgyro/accgyro.h"
#include "drivers/bus_i2c.h"
#include "drivers/compass/compass.h"
#include "drivers/max7456.h"
#include "drivers/max7456_symbols.h"
#include "drivers/display.h"
#include "drivers/osd.h"
#include "drivers/osd_symbols.h"
#include "drivers/pwm_mapping.h"
#include "drivers/sdcard.h"
#include "drivers/serial.h"
Expand Down Expand Up @@ -315,7 +316,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
// 0 = no OSD
// 1 = OSD slave (not supported in INAV)
// 2 = OSD chip on board
#if defined(USE_OSD) && defined(USE_MAX7456)
#if defined(USE_OSD)
sbufWriteU8(dst, 2);
#else
sbufWriteU8(dst, 0);
Expand Down Expand Up @@ -1020,13 +1021,9 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF

case MSP_OSD_CONFIG:
#ifdef USE_OSD
sbufWriteU8(dst, 1); // OSD supported
sbufWriteU8(dst, OSD_DRIVER_MAX7456); // OSD supported
// send video system (AUTO/PAL/NTSC)
#ifdef USE_MAX7456
sbufWriteU8(dst, osdConfig()->video_system);
#else
sbufWriteU8(dst, 0);
#endif
sbufWriteU8(dst, osdConfig()->units);
sbufWriteU8(dst, osdConfig()->rssi_alarm);
sbufWriteU16(dst, currentBatteryProfile->capacity.warning);
Expand All @@ -1038,7 +1035,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
sbufWriteU16(dst, osdConfig()->item_pos[0][i]);
}
#else
sbufWriteU8(dst, 0); // OSD not supported
sbufWriteU8(dst, OSD_DRIVER_NONE); // OSD not supported
#endif
break;

Expand Down Expand Up @@ -2234,11 +2231,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
// set all the other settings
if ((int8_t)tmp_u8 == -1) {
if (dataSize >= 10) {
#ifdef USE_MAX7456
osdConfigMutable()->video_system = sbufReadU8(src);
#else
sbufReadU8(src); // Skip video system
#endif
osdConfigMutable()->units = sbufReadU8(src);
osdConfigMutable()->rssi_alarm = sbufReadU8(src);
currentBatteryProfileMutable->capacity.warning = sbufReadU16(src);
Expand All @@ -2264,23 +2257,26 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
break;

case MSP_OSD_CHAR_WRITE:
#ifdef USE_MAX7456
if (dataSize >= 55) {
max7456Character_t chr;
osdCharacter_t chr;
uint16_t addr;
if (dataSize >= 56) {
// 16 bit character address
addr = sbufReadU16(src);
} else {
// 8 bit character address, for backwards compatibility
addr = sbufReadU8(src);
}
for (unsigned ii = 0; ii < sizeof(chr.data); ii++) {
chr.data[ii] = sbufReadU8(src);
}
// !!TODO - replace this with a device independent implementation
max7456WriteNvm(addr, &chr);
} else
displayPort_t *osdDisplayPort = osdGetDisplayPort();
if (osdDisplayPort) {
displayWriteFontCharacter(osdDisplayPort, addr, &chr);
}
} else {
return MSP_RESULT_ERROR;
#endif // USE_MAX7456
}
break;
#endif // USE_OSD

Expand Down
2 changes: 1 addition & 1 deletion src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ groups:

- name: PG_OSD_CONFIG
type: osdConfig_t
headers: ["io/osd.h", "drivers/vcd.h"]
headers: ["io/osd.h", "drivers/osd.h"]
condition: USE_OSD
members:
- name: osd_video_system
Expand Down
Loading