1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-24 00:35:34 +03:00

Rename functions and constants

AGH -> FRSKY, agh -> frsky
This commit is contained in:
Alberto García Hierro 2019-05-19 22:27:57 +01:00
parent fc623d4953
commit b950f2abb6
8 changed files with 177 additions and 175 deletions

View file

@ -94,12 +94,12 @@ COMMON_SRC = \
flight/servos.c \ flight/servos.c \
flight/wind_estimator.c \ flight/wind_estimator.c \
flight/gyroanalyse.c \ flight/gyroanalyse.c \
io/agh_osd.c \
io/beeper.c \ io/beeper.c \
io/lights.c \
io/pwmdriver_i2c.c \
io/esc_serialshot.c \ io/esc_serialshot.c \
io/frsky_osd.c \
io/lights.c \
io/piniobox.c \ io/piniobox.c \
io/pwmdriver_i2c.c \
io/serial.c \ io/serial.c \
io/serial_4way.c \ io/serial_4way.c \
io/serial_4way_avrootloader.c \ io/serial_4way_avrootloader.c \
@ -173,7 +173,7 @@ COMMON_SRC = \
io/opflow_cxof.c \ io/opflow_cxof.c \
io/opflow_msp.c \ io/opflow_msp.c \
io/dashboard.c \ io/dashboard.c \
io/displayport_agh_osd.c \ io/displayport_frsky_osd.c \
io/displayport_max7456.c \ io/displayport_max7456.c \
io/displayport_msp.c \ io/displayport_msp.c \
io/displayport_oled.c \ io/displayport_oled.c \

View file

@ -95,7 +95,7 @@
#include "io/beeper.h" #include "io/beeper.h"
#include "io/lights.h" #include "io/lights.h"
#include "io/dashboard.h" #include "io/dashboard.h"
#include "io/displayport_agh_osd.h" #include "io/displayport_frsky_osd.h"
#include "io/displayport_msp.h" #include "io/displayport_msp.h"
#include "io/displayport_max7456.h" #include "io/displayport_max7456.h"
#include "io/flashfs.h" #include "io/flashfs.h"
@ -508,9 +508,9 @@ void init(void)
#ifdef USE_OSD #ifdef USE_OSD
if (feature(FEATURE_OSD)) { if (feature(FEATURE_OSD)) {
#if defined(USE_AGHOSD) #if defined(USE_FRSKYOSD)
if (!osdDisplayPort) { if (!osdDisplayPort) {
osdDisplayPort = aghOSDDisplayPortInit(osdConfig()->video_system); osdDisplayPort = frskyOSDDisplayPortInit(osdConfig()->video_system);
} }
#endif #endif
#if defined(USE_MAX7456) #if defined(USE_MAX7456)

View file

@ -1,18 +0,0 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "drivers/display.h"
#include "drivers/osd.h"
bool aghOSDInit(videoSystem_e videoSystem);
bool aghOSDIsReady(void);
void aghOSDUpdate(void);
bool aghOSDReadFontCharacter(unsigned char_address, osdCharacter_t *chr);
bool aghOSDWriteFontCharacter(unsigned char_address, const osdCharacter_t *chr);
unsigned aghOSDGetGridRows(void);
unsigned aghOSDGetGridCols(void);
void aghOSDDrawStringInGrid(unsigned x, unsigned y, const char *buff, textAttributes_t attr);
void aghOSDDrawCharInGrid(unsigned x, unsigned y, uint16_t chr, textAttributes_t attr);
void aghOSDClearScreen(void);

View file

@ -20,17 +20,17 @@
#include "platform.h" #include "platform.h"
#if defined(USE_AGHOSD) #if defined(USE_FRSKYOSD)
#include "common/utils.h" #include "common/utils.h"
#include "drivers/display.h" #include "drivers/display.h"
#include "drivers/display_font_metadata.h" #include "drivers/display_font_metadata.h"
#include "io/agh_osd.h" #include "io/displayport_frsky_osd.h"
#include "io/displayport_agh_osd.h" #include "io/frsky_osd.h"
static displayPort_t aghOSDDisplayPort; static displayPort_t frskyOSDDisplayPort;
static int grab(displayPort_t *displayPort) static int grab(displayPort_t *displayPort)
{ {
@ -47,14 +47,14 @@ static int release(displayPort_t *displayPort)
static int clearScreen(displayPort_t *displayPort) static int clearScreen(displayPort_t *displayPort)
{ {
UNUSED(displayPort); UNUSED(displayPort);
aghOSDClearScreen(); frskyOSDClearScreen();
return 0; return 0;
} }
static int drawScreen(displayPort_t *displayPort) static int drawScreen(displayPort_t *displayPort)
{ {
UNUSED(displayPort); UNUSED(displayPort);
aghOSDUpdate(); frskyOSDUpdate();
return 0; return 0;
} }
@ -62,14 +62,14 @@ static int drawScreen(displayPort_t *displayPort)
static int screenSize(const displayPort_t *displayPort) static int screenSize(const displayPort_t *displayPort)
{ {
UNUSED(displayPort); UNUSED(displayPort);
return aghOSDGetGridRows() * aghOSDGetGridCols(); return frskyOSDGetGridRows() * frskyOSDGetGridCols();
} }
static int writeString(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s, textAttributes_t attr) static int writeString(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s, textAttributes_t attr)
{ {
UNUSED(displayPort); UNUSED(displayPort);
aghOSDDrawStringInGrid(x, y, s, attr); frskyOSDDrawStringInGrid(x, y, s, attr);
return 0; return 0;
} }
@ -77,7 +77,7 @@ static int writeChar(displayPort_t *displayPort, uint8_t x, uint8_t y, uint16_t
{ {
UNUSED(displayPort); UNUSED(displayPort);
aghOSDDrawCharInGrid(x, y, c, attr); frskyOSDDrawCharInGrid(x, y, c, attr);
return 0; return 0;
} }
@ -96,9 +96,11 @@ static bool isTransferInProgress(const displayPort_t *displayPort)
static void resync(displayPort_t *displayPort) static void resync(displayPort_t *displayPort)
{ {
UNUSED(displayPort); UNUSED(displayPort);
// TODO: Refresh here? // TODO(agh): Do we need to flush the screen here?
displayPort->rows = aghOSDGetGridRows(); // MAX7456's driver does a full redraw in resync(),
displayPort->cols = aghOSDGetGridCols(); // so some callers might be expecting that.
displayPort->rows = frskyOSDGetGridRows();
displayPort->cols = frskyOSDGetGridCols();
} }
static int heartbeat(displayPort_t *displayPort) static int heartbeat(displayPort_t *displayPort)
@ -131,7 +133,7 @@ static bool getFontMetadata(displayFontMetadata_t *metadata, const displayPort_t
osdCharacter_t chr; osdCharacter_t chr;
metadata->charCount = 512; metadata->charCount = 512;
return aghOSDReadFontCharacter(FONT_METADATA_CHR_INDEX, &chr) && return frskyOSDReadFontCharacter(FONT_METADATA_CHR_INDEX, &chr) &&
displayFontMetadataUpdateFromCharacter(metadata, &chr); displayFontMetadataUpdateFromCharacter(metadata, &chr);
} }
@ -140,7 +142,7 @@ static int writeFontCharacter(displayPort_t *instance, uint16_t addr, const osdC
{ {
UNUSED(instance); UNUSED(instance);
aghOSDWriteFontCharacter(addr, chr); frskyOSDWriteFontCharacter(addr, chr);
return 0; return 0;
} }
@ -148,10 +150,10 @@ static bool isReady(const displayPort_t *instance)
{ {
UNUSED(instance); UNUSED(instance);
return aghOSDIsReady(); return frskyOSDIsReady();
} }
static const displayPortVTable_t aghOSDVTable = { static const displayPortVTable_t frskyOSDVTable = {
.grab = grab, .grab = grab,
.release = release, .release = release,
.clearScreen = clearScreen, .clearScreen = clearScreen,
@ -170,14 +172,14 @@ static const displayPortVTable_t aghOSDVTable = {
.isReady = isReady, .isReady = isReady,
}; };
displayPort_t *aghOSDDisplayPortInit(const videoSystem_e videoSystem) displayPort_t *frskyOSDDisplayPortInit(const videoSystem_e videoSystem)
{ {
if (aghOSDInit(videoSystem)) { if (frskyOSDInit(videoSystem)) {
displayInit(&aghOSDDisplayPort, &aghOSDVTable); displayInit(&frskyOSDDisplayPort, &frskyOSDVTable);
resync(&aghOSDDisplayPort); resync(&frskyOSDDisplayPort);
return &aghOSDDisplayPort; return &frskyOSDDisplayPort;
} }
return NULL; return NULL;
} }
#endif // USE_AGHOSD #endif // USE_FRSKYOSD

View file

@ -4,4 +4,4 @@
typedef struct displayPort_s displayPort_t; typedef struct displayPort_s displayPort_t;
displayPort_t *aghOSDDisplayPortInit(const videoSystem_e videoSystem); displayPort_t *frskyOSDDisplayPortInit(const videoSystem_e videoSystem);

View file

@ -4,7 +4,7 @@
#include "platform.h" #include "platform.h"
#if defined(USE_AGHOSD) #if defined(USE_FRSKYOSD)
#include "common/crc.h" #include "common/crc.h"
#include "common/log.h" #include "common/log.h"
@ -13,25 +13,25 @@
#include "drivers/time.h" #include "drivers/time.h"
#include "io/agh_osd.h" #include "io/frsky_osd.h"
#include "io/serial.h" #include "io/serial.h"
#define AGH_OSD_BAUDRATE 115200 #define FRSKY_OSD_BAUDRATE 115200
#define AGH_OSD_PREAMBLE_BYTE_0 '$' #define FRSKY_OSD_PREAMBLE_BYTE_0 '$'
#define AGH_OSD_PREAMBLE_BYTE_1 'A' #define FRSKY_OSD_PREAMBLE_BYTE_1 'A'
#define AGH_OSD_RECV_BUFFER_SIZE 64 #define FRSKY_OSD_RECV_BUFFER_SIZE 64
#define AGH_OSD_CMD_INFO 1 #define FRSKY_OSD_CMD_INFO 1
#define AGH_OSD_CMD_READ_FONT 2 #define FRSKY_OSD_CMD_READ_FONT 2
#define AGH_OSD_CMD_WRITE_FONT 3 #define FRSKY_OSD_CMD_WRITE_FONT 3
#define AGH_OSD_CMD_CLEAR 4 #define FRSKY_OSD_CMD_CLEAR 4
#define AGH_OSD_CMD_DRAW_GRID_CHAR 5 #define FRSKY_OSD_CMD_DRAW_GRID_CHAR 5
#define AGH_OSD_CMD_DRAW_GRID_STR 6 #define FRSKY_OSD_CMD_DRAW_GRID_STR 6
#define AGH_OSD_DEBUG(fmt, ...) LOG_D(OSD, fmt, ##__VA_ARGS__) #define FRSKY_OSD_DEBUG(fmt, ...) LOG_D(OSD, fmt, ##__VA_ARGS__)
#define AGH_OSD_ERROR(fmt, ...) LOG_E(OSD, fmt, ##__VA_ARGS__) #define FRSKY_OSD_ERROR(fmt, ...) LOG_E(OSD, fmt, ##__VA_ARGS__)
typedef enum { typedef enum {
RECV_STATE_NONE, RECV_STATE_NONE,
@ -41,9 +41,9 @@ typedef enum {
RECV_STATE_DATA, RECV_STATE_DATA,
RECV_STATE_CHECKSUM, RECV_STATE_CHECKSUM,
RECV_STATE_DONE, RECV_STATE_DONE,
} aghOSDRecvState_e; } frskyOSDRecvState_e;
typedef struct aghOSDInfoResponse_s { typedef struct frskyOSDInfoResponse_s {
uint8_t magic[3]; uint8_t magic[3];
uint8_t versionMajor; uint8_t versionMajor;
uint8_t versionMinor; uint8_t versionMinor;
@ -52,27 +52,27 @@ typedef struct aghOSDInfoResponse_s {
uint8_t gridColumns; uint8_t gridColumns;
uint16_t pixelWidth; uint16_t pixelWidth;
uint16_t pixelHeight; uint16_t pixelHeight;
} __attribute__((packed)) aghOSDInfoResponse_t; } __attribute__((packed)) frskyOSDInfoResponse_t;
typedef struct aghOSDFontCharacter_s { typedef struct frskyOSDFontCharacter_s {
uint16_t addr; uint16_t addr;
uint8_t data[54]; // 12x18 2bpp uint8_t data[54]; // 12x18 2bpp
} __attribute__((packed)) aghOSDCharacter_t; } __attribute__((packed)) frskyOSDCharacter_t;
typedef struct aghOSDDrawGridCharCmd_s { typedef struct frskyOSDDrawGridCharCmd_s {
uint8_t gx; uint8_t gx;
uint8_t gy; uint8_t gy;
uint16_t chr; uint16_t chr;
uint8_t attr; uint8_t attr;
} __attribute__((packed)) aghOSDDrawGridCharCmd_t; } __attribute__((packed)) frskyOSDDrawGridCharCmd_t;
typedef struct aghOSDState_s { typedef struct frskyOSDState_s {
struct { struct {
uint8_t state; uint8_t state;
uint8_t cmd; uint8_t cmd;
uint8_t crc; uint8_t crc;
uint8_t expected; uint8_t expected;
uint8_t data[AGH_OSD_RECV_BUFFER_SIZE]; uint8_t data[FRSKY_OSD_RECV_BUFFER_SIZE];
uint8_t pos; uint8_t pos;
} recv_buffer; } recv_buffer;
struct { struct {
@ -89,16 +89,16 @@ typedef struct aghOSDState_s {
} viewport; } viewport;
} info; } info;
serialPort_t *port; serialPort_t *port;
} aghOSDState_t; } frskyOSDState_t;
static aghOSDState_t state; static frskyOSDState_t state;
static uint8_t aghOSDChecksum(uint8_t crc, uint8_t c) static uint8_t frskyOSDChecksum(uint8_t crc, uint8_t c)
{ {
return crc8_dvb_s2(crc, c); return crc8_dvb_s2(crc, c);
} }
static void aghOSDResetReceiveBuffer(void) static void frskyOSDResetReceiveBuffer(void)
{ {
state.recv_buffer.state = RECV_STATE_NONE; state.recv_buffer.state = RECV_STATE_NONE;
state.recv_buffer.cmd = 0; state.recv_buffer.cmd = 0;
@ -107,9 +107,9 @@ static void aghOSDResetReceiveBuffer(void)
state.recv_buffer.pos = 0; state.recv_buffer.pos = 0;
} }
static void aghOSDStateReset(serialPort_t *port) static void frskyOSDStateReset(serialPort_t *port)
{ {
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
state.info.grid.rows = 0; state.info.grid.rows = 0;
state.info.grid.columns = 0; state.info.grid.columns = 0;
state.info.viewport.width = 0; state.info.viewport.width = 0;
@ -118,77 +118,77 @@ static void aghOSDStateReset(serialPort_t *port)
state.port = port; state.port = port;
} }
static void aghOSDUpdateReceiveBuffer(void) static void frskyOSDUpdateReceiveBuffer(void)
{ {
while (serialRxBytesWaiting(state.port) > 0) { while (serialRxBytesWaiting(state.port) > 0) {
uint8_t c = serialRead(state.port); uint8_t c = serialRead(state.port);
switch ((aghOSDRecvState_e)state.recv_buffer.state) { switch ((frskyOSDRecvState_e)state.recv_buffer.state) {
case RECV_STATE_NONE: case RECV_STATE_NONE:
if (c != AGH_OSD_PREAMBLE_BYTE_0) { if (c != FRSKY_OSD_PREAMBLE_BYTE_0) {
break; break;
} }
state.recv_buffer.state = RECV_STATE_SYNC; state.recv_buffer.state = RECV_STATE_SYNC;
break; break;
case RECV_STATE_SYNC: case RECV_STATE_SYNC:
if (c != AGH_OSD_PREAMBLE_BYTE_1) { if (c != FRSKY_OSD_PREAMBLE_BYTE_1) {
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
break; break;
} }
state.recv_buffer.state = RECV_STATE_CMD; state.recv_buffer.state = RECV_STATE_CMD;
break; break;
case RECV_STATE_CMD: case RECV_STATE_CMD:
state.recv_buffer.crc = aghOSDChecksum(state.recv_buffer.crc, c); state.recv_buffer.crc = frskyOSDChecksum(state.recv_buffer.crc, c);
state.recv_buffer.cmd = c; state.recv_buffer.cmd = c;
state.recv_buffer.state = RECV_STATE_LENGTH; state.recv_buffer.state = RECV_STATE_LENGTH;
break; break;
case RECV_STATE_LENGTH: case RECV_STATE_LENGTH:
if (c > sizeof(state.recv_buffer.data)) { if (c > sizeof(state.recv_buffer.data)) {
AGH_OSD_ERROR("Can't handle payload of size %u with a buffer of size %u", FRSKY_OSD_ERROR("Can't handle payload of size %u with a buffer of size %u",
c, sizeof(state.recv_buffer.data)); c, sizeof(state.recv_buffer.data));
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
break; break;
} }
state.recv_buffer.crc = aghOSDChecksum(state.recv_buffer.crc, c); state.recv_buffer.crc = frskyOSDChecksum(state.recv_buffer.crc, c);
state.recv_buffer.expected = c; state.recv_buffer.expected = c;
state.recv_buffer.state = c > 0 ? RECV_STATE_DATA : RECV_STATE_CHECKSUM; state.recv_buffer.state = c > 0 ? RECV_STATE_DATA : RECV_STATE_CHECKSUM;
break; break;
case RECV_STATE_DATA: case RECV_STATE_DATA:
state.recv_buffer.data[state.recv_buffer.pos++] = c; state.recv_buffer.data[state.recv_buffer.pos++] = c;
state.recv_buffer.crc = aghOSDChecksum(state.recv_buffer.crc, c); state.recv_buffer.crc = frskyOSDChecksum(state.recv_buffer.crc, c);
if (state.recv_buffer.pos == state.recv_buffer.expected) { if (state.recv_buffer.pos == state.recv_buffer.expected) {
state.recv_buffer.state = RECV_STATE_CHECKSUM; state.recv_buffer.state = RECV_STATE_CHECKSUM;
} }
break; break;
case RECV_STATE_CHECKSUM: case RECV_STATE_CHECKSUM:
if (c != state.recv_buffer.crc) { if (c != state.recv_buffer.crc) {
AGH_OSD_DEBUG("Checksum error %u != %u. Discarding %u bytes", FRSKY_OSD_DEBUG("Checksum error %u != %u. Discarding %u bytes",
c, state.recv_buffer.crc, state.recv_buffer.pos); c, state.recv_buffer.crc, state.recv_buffer.pos);
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
break; break;
} }
state.recv_buffer.state = RECV_STATE_DONE; state.recv_buffer.state = RECV_STATE_DONE;
break; break;
case RECV_STATE_DONE: case RECV_STATE_DONE:
AGH_OSD_DEBUG("Received unexpected byte %u after data", c); FRSKY_OSD_DEBUG("Received unexpected byte %u after data", c);
break; break;
} }
} }
} }
static bool aghOSDIsResponseAvailable(void) static bool frskyOSDIsResponseAvailable(void)
{ {
return state.recv_buffer.state == RECV_STATE_DONE; return state.recv_buffer.state == RECV_STATE_DONE;
} }
static bool aghOSDHandleCommand(void) static bool frskyOSDHandleCommand(void)
{ {
const void *data = state.recv_buffer.data; const void *data = state.recv_buffer.data;
switch (state.recv_buffer.cmd) { switch (state.recv_buffer.cmd) {
case AGH_OSD_CMD_INFO: case FRSKY_OSD_CMD_INFO:
if (state.recv_buffer.expected >= sizeof(aghOSDInfoResponse_t)) { if (state.recv_buffer.expected >= sizeof(frskyOSDInfoResponse_t)) {
const aghOSDInfoResponse_t *resp = data; const frskyOSDInfoResponse_t *resp = data;
if (resp->magic[0] != 'A' || resp->magic[1] != 'G' || resp->magic[2] != 'H') { if (resp->magic[0] != 'A' || resp->magic[1] != 'G' || resp->magic[2] != 'H') {
AGH_OSD_ERROR("Invalid magic number %x %x %x, expecting AGH", FRSKY_OSD_ERROR("Invalid magic number %x %x %x, expecting AGH",
resp->magic[0], resp->magic[1], resp->magic[2]); resp->magic[0], resp->magic[1], resp->magic[2]);
return false; return false;
} }
@ -198,7 +198,7 @@ static bool aghOSDHandleCommand(void)
state.info.grid.columns = resp->gridColumns; state.info.grid.columns = resp->gridColumns;
state.info.viewport.width = resp->pixelWidth; state.info.viewport.width = resp->pixelWidth;
state.info.viewport.height = resp->pixelHeight; state.info.viewport.height = resp->pixelHeight;
AGH_OSD_DEBUG("AGH OSD initialized. Version %u.%u.%u, pixels=%ux%u, grid=%ux%u", FRSKY_OSD_DEBUG("FrSky OSD initialized. Version %u.%u.%u, pixels=%ux%u, grid=%ux%u",
resp->versionMajor, resp->versionMinor, resp->versionPatch, resp->versionMajor, resp->versionMinor, resp->versionPatch,
resp->pixelWidth, resp->pixelHeight, resp->gridColumns, resp->gridRows); resp->pixelWidth, resp->pixelHeight, resp->gridColumns, resp->gridRows);
return true; return true;
@ -208,28 +208,28 @@ static bool aghOSDHandleCommand(void)
return false; return false;
} }
static void aghOSDDispatchCommand(void) static void frskyOSDDispatchCommand(void)
{ {
if (!aghOSDHandleCommand()) { if (!frskyOSDHandleCommand()) {
AGH_OSD_DEBUG("Discarding unknown command %u (%u bytes)", FRSKY_OSD_DEBUG("Discarding unknown command %u (%u bytes)",
state.recv_buffer.cmd, state.recv_buffer.pos); state.recv_buffer.cmd, state.recv_buffer.pos);
} }
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
} }
static void aghOSDClearReceiveBuffer(void) static void frskyOSDClearReceiveBuffer(void)
{ {
aghOSDUpdateReceiveBuffer(); frskyOSDUpdateReceiveBuffer();
if (aghOSDIsResponseAvailable()) { if (frskyOSDIsResponseAvailable()) {
aghOSDDispatchCommand(); frskyOSDDispatchCommand();
} else if (state.recv_buffer.pos > 0) { } else if (state.recv_buffer.pos > 0) {
AGH_OSD_DEBUG("Discarding receive buffer with %u bytes", state.recv_buffer.pos); FRSKY_OSD_DEBUG("Discarding receive buffer with %u bytes", state.recv_buffer.pos);
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
} }
} }
static void aghOSDProcessCommandU8(uint8_t *crc, uint8_t c) static void frskyOSDProcessCommandU8(uint8_t *crc, uint8_t c)
{ {
while (serialTxBytesFree(state.port) == 0) { while (serialTxBytesFree(state.port) == 0) {
}; };
@ -239,142 +239,142 @@ static void aghOSDProcessCommandU8(uint8_t *crc, uint8_t c)
} }
} }
static void aghOSDProcessCommandU16(uint8_t *crc, uint16_t c) static void frskyOSDProcessCommandU16(uint8_t *crc, uint16_t c)
{ {
aghOSDProcessCommandU8(crc, c & 0xFF); frskyOSDProcessCommandU8(crc, c & 0xFF);
aghOSDProcessCommandU8(crc, c >> 8); frskyOSDProcessCommandU8(crc, c >> 8);
} }
static void aghOSDSendPreamble(uint8_t *crc, uint8_t cmd) static void frskyOSDSendPreamble(uint8_t *crc, uint8_t cmd)
{ {
// TODO: Implement uvarint // TODO: Implement uvarint
aghOSDProcessCommandU8(NULL, AGH_OSD_PREAMBLE_BYTE_0); frskyOSDProcessCommandU8(NULL, FRSKY_OSD_PREAMBLE_BYTE_0);
aghOSDProcessCommandU8(NULL, AGH_OSD_PREAMBLE_BYTE_1); frskyOSDProcessCommandU8(NULL, FRSKY_OSD_PREAMBLE_BYTE_1);
aghOSDProcessCommandU8(crc, cmd); frskyOSDProcessCommandU8(crc, cmd);
} }
static void aghOSDSendAsyncCommand(uint8_t cmd, const void *data, size_t size) static void frskyOSDSendAsyncCommand(uint8_t cmd, const void *data, size_t size)
{ {
AGH_OSD_DEBUG("Send async cmd %u", cmd); FRSKY_OSD_DEBUG("Send async cmd %u", cmd);
uint8_t crc = 0; uint8_t crc = 0;
aghOSDSendPreamble(&crc, cmd); frskyOSDSendPreamble(&crc, cmd);
if (data && size > 0) { if (data && size > 0) {
aghOSDProcessCommandU8(&crc, size & 0x7F); frskyOSDProcessCommandU8(&crc, size & 0x7F);
const uint8_t *p = data; const uint8_t *p = data;
const uint8_t *end = p + size; const uint8_t *end = p + size;
for(; p != end; p++) { for(; p != end; p++) {
aghOSDProcessCommandU8(&crc, *p); frskyOSDProcessCommandU8(&crc, *p);
} }
} else { } else {
aghOSDProcessCommandU8(&crc, 0); frskyOSDProcessCommandU8(&crc, 0);
} }
aghOSDProcessCommandU8(NULL, crc); frskyOSDProcessCommandU8(NULL, crc);
} }
static bool aghOSDSendSyncCommand(uint8_t cmd, const void *data, size_t size, timeMs_t timeout) static bool frskyOSDSendSyncCommand(uint8_t cmd, const void *data, size_t size, timeMs_t timeout)
{ {
aghOSDClearReceiveBuffer(); frskyOSDClearReceiveBuffer();
aghOSDSendAsyncCommand(cmd, data, size); frskyOSDSendAsyncCommand(cmd, data, size);
timeMs_t end = millis() + timeout; timeMs_t end = millis() + timeout;
while (millis() < end) { while (millis() < end) {
aghOSDUpdateReceiveBuffer(); frskyOSDUpdateReceiveBuffer();
if (aghOSDIsResponseAvailable()) { if (frskyOSDIsResponseAvailable()) {
return true; return true;
} }
} }
return false; return false;
} }
static void aghOSDRequestInfo(void) static void frskyOSDRequestInfo(void)
{ {
timeMs_t now = millis(); timeMs_t now = millis();
if (state.info.nextRequest < now) { if (state.info.nextRequest < now) {
aghOSDSendAsyncCommand(AGH_OSD_CMD_INFO, NULL, 0); frskyOSDSendAsyncCommand(FRSKY_OSD_CMD_INFO, NULL, 0);
state.info.nextRequest = now + 1000; state.info.nextRequest = now + 1000;
} }
} }
bool aghOSDInit(videoSystem_e videoSystem) bool frskyOSDInit(videoSystem_e videoSystem)
{ {
// TODO: Use videoSystem to set the signal standard when // TODO: Use videoSystem to set the signal standard when
// no input is detected. // no input is detected.
const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_AGH_OSD); const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_FRSKY_OSD);
if (portConfig) { if (portConfig) {
portOptions_t portOptions = 0; portOptions_t portOptions = 0;
serialPort_t *port = openSerialPort(portConfig->identifier, serialPort_t *port = openSerialPort(portConfig->identifier,
FUNCTION_AGH_OSD, NULL, NULL, AGH_OSD_BAUDRATE, FUNCTION_FRSKY_OSD, NULL, NULL, FRSKY_OSD_BAUDRATE,
MODE_RXTX, portOptions); MODE_RXTX, portOptions);
if (port) { if (port) {
aghOSDStateReset(port); frskyOSDStateReset(port);
aghOSDRequestInfo(); frskyOSDRequestInfo();
return true; return true;
} }
} }
return false; return false;
} }
bool aghOSDIsReady(void) bool frskyOSDIsReady(void)
{ {
return state.info.minor > 0 || state.info.major > 0; return state.info.minor > 0 || state.info.major > 0;
} }
void aghOSDUpdate(void) void frskyOSDUpdate(void)
{ {
if (!state.port) { if (!state.port) {
return; return;
} }
aghOSDUpdateReceiveBuffer(); frskyOSDUpdateReceiveBuffer();
if (aghOSDIsResponseAvailable()) { if (frskyOSDIsResponseAvailable()) {
aghOSDDispatchCommand(); frskyOSDDispatchCommand();
} }
if (!aghOSDIsReady()) { if (!frskyOSDIsReady()) {
// Info not received yet // Info not received yet
aghOSDRequestInfo(); frskyOSDRequestInfo();
} }
} }
bool aghOSDReadFontCharacter(unsigned char_address, osdCharacter_t *chr) bool frskyOSDReadFontCharacter(unsigned char_address, osdCharacter_t *chr)
{ {
if (!aghOSDIsReady()) { if (!frskyOSDIsReady()) {
return false; return false;
} }
uint16_t addr = char_address; uint16_t addr = char_address;
// 200ms should be more than enough to receive ~60 bytes @ 115200 bps // 200ms should be more than enough to receive ~60 bytes @ 115200 bps
if (aghOSDSendSyncCommand(AGH_OSD_CMD_READ_FONT, &addr, sizeof(addr), 200)) { if (frskyOSDSendSyncCommand(FRSKY_OSD_CMD_READ_FONT, &addr, sizeof(addr), 200)) {
if (state.recv_buffer.cmd != AGH_OSD_CMD_READ_FONT || if (state.recv_buffer.cmd != FRSKY_OSD_CMD_READ_FONT ||
state.recv_buffer.expected < sizeof(*chr) + sizeof(addr)) { state.recv_buffer.expected < sizeof(*chr) + sizeof(addr)) {
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
AGH_OSD_DEBUG("Bad font character at position %u", char_address); FRSKY_OSD_DEBUG("Bad font character at position %u", char_address);
return false; return false;
} }
// Skip character address // Skip character address
memcpy(chr, &state.recv_buffer.data[2], sizeof(*chr)); memcpy(chr, &state.recv_buffer.data[2], sizeof(*chr));
aghOSDResetReceiveBuffer(); frskyOSDResetReceiveBuffer();
return true; return true;
} }
return false; return false;
} }
bool aghOSDWriteFontCharacter(unsigned char_address, const osdCharacter_t *chr) bool frskyOSDWriteFontCharacter(unsigned char_address, const osdCharacter_t *chr)
{ {
if (!aghOSDIsReady()) { if (!frskyOSDIsReady()) {
return false; return false;
} }
aghOSDCharacter_t c; frskyOSDCharacter_t c;
STATIC_ASSERT(sizeof(*chr) == sizeof(c.data), invalid_character_size); STATIC_ASSERT(sizeof(*chr) == sizeof(c.data), invalid_character_size);
memcpy(c.data, chr, sizeof(c.data)); memcpy(c.data, chr, sizeof(c.data));
c.addr = char_address; c.addr = char_address;
aghOSDSendAsyncCommand(AGH_OSD_CMD_WRITE_FONT, &c, sizeof(c)); frskyOSDSendAsyncCommand(FRSKY_OSD_CMD_WRITE_FONT, &c, sizeof(c));
// Wait until all bytes have been sent. Otherwise uploading // Wait until all bytes have been sent. Otherwise uploading
// the very last character of the font might fail. // the very last character of the font might fail.
// TODO: Investigate if we can change the max7456 handling to // TODO: Investigate if we can change the max7456 handling to
@ -383,59 +383,59 @@ bool aghOSDWriteFontCharacter(unsigned char_address, const osdCharacter_t *chr)
return true; return true;
} }
unsigned aghOSDGetGridRows(void) unsigned frskyOSDGetGridRows(void)
{ {
return state.info.grid.rows; return state.info.grid.rows;
} }
unsigned aghOSDGetGridCols(void) unsigned frskyOSDGetGridCols(void)
{ {
return state.info.grid.columns; return state.info.grid.columns;
} }
void aghOSDDrawStringInGrid(unsigned x, unsigned y, const char *buff, textAttributes_t attr) void frskyOSDDrawStringInGrid(unsigned x, unsigned y, const char *buff, textAttributes_t attr)
{ {
uint8_t crc = 0; uint8_t crc = 0;
aghOSDSendPreamble(&crc, AGH_OSD_CMD_DRAW_GRID_STR); frskyOSDSendPreamble(&crc, FRSKY_OSD_CMD_DRAW_GRID_STR);
uint8_t size = 1 + 1 + strlen(buff) + 1; uint8_t size = 1 + 1 + strlen(buff) + 1;
if (attr != 0) { if (attr != 0) {
size += 1; size += 1;
} }
aghOSDProcessCommandU8(&crc, size); frskyOSDProcessCommandU8(&crc, size);
aghOSDProcessCommandU8(&crc, x); frskyOSDProcessCommandU8(&crc, x);
aghOSDProcessCommandU8(&crc, y); frskyOSDProcessCommandU8(&crc, y);
for (const char *p = buff; *p; p++) { for (const char *p = buff; *p; p++) {
aghOSDProcessCommandU8(&crc, *p); frskyOSDProcessCommandU8(&crc, *p);
} }
// Terminate string // Terminate string
aghOSDProcessCommandU8(&crc, 0); frskyOSDProcessCommandU8(&crc, 0);
if (attr != 0) { if (attr != 0) {
aghOSDProcessCommandU8(&crc, attr); frskyOSDProcessCommandU8(&crc, attr);
} }
aghOSDProcessCommandU8(NULL, crc); frskyOSDProcessCommandU8(NULL, crc);
} }
void aghOSDDrawCharInGrid(unsigned x, unsigned y, uint16_t chr, textAttributes_t attr) void frskyOSDDrawCharInGrid(unsigned x, unsigned y, uint16_t chr, textAttributes_t attr)
{ {
uint8_t crc = 0; uint8_t crc = 0;
aghOSDSendPreamble(&crc, AGH_OSD_CMD_DRAW_GRID_CHAR); frskyOSDSendPreamble(&crc, FRSKY_OSD_CMD_DRAW_GRID_CHAR);
uint8_t size = 1 + 1 + 2; uint8_t size = 1 + 1 + 2;
if (attr != 0) { if (attr != 0) {
size += 1; size += 1;
} }
aghOSDProcessCommandU8(&crc, size); frskyOSDProcessCommandU8(&crc, size);
aghOSDProcessCommandU8(&crc, x); frskyOSDProcessCommandU8(&crc, x);
aghOSDProcessCommandU8(&crc, y); frskyOSDProcessCommandU8(&crc, y);
aghOSDProcessCommandU16(&crc, chr); frskyOSDProcessCommandU16(&crc, chr);
if (attr != 0) { if (attr != 0) {
aghOSDProcessCommandU8(&crc, attr); frskyOSDProcessCommandU8(&crc, attr);
} }
aghOSDProcessCommandU8(NULL, crc); frskyOSDProcessCommandU8(NULL, crc);
} }
void aghOSDClearScreen(void) void frskyOSDClearScreen(void)
{ {
aghOSDSendAsyncCommand(AGH_OSD_CMD_CLEAR, NULL, 0); frskyOSDSendAsyncCommand(FRSKY_OSD_CMD_CLEAR, NULL, 0);
} }
#endif #endif

18
src/main/io/frsky_osd.h Normal file
View file

@ -0,0 +1,18 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "drivers/display.h"
#include "drivers/osd.h"
bool frskyOSDInit(videoSystem_e videoSystem);
bool frskyOSDIsReady(void);
void frskyOSDUpdate(void);
bool frskyOSDReadFontCharacter(unsigned char_address, osdCharacter_t *chr);
bool frskyOSDWriteFontCharacter(unsigned char_address, const osdCharacter_t *chr);
unsigned frskyOSDGetGridRows(void);
unsigned frskyOSDGetGridCols(void);
void frskyOSDDrawStringInGrid(unsigned x, unsigned y, const char *buff, textAttributes_t attr);
void frskyOSDDrawCharInGrid(unsigned x, unsigned y, uint16_t chr, textAttributes_t attr);
void frskyOSDClearScreen(void);

View file

@ -50,8 +50,8 @@ typedef enum {
FUNCTION_RANGEFINDER = (1 << 16), // 65536 FUNCTION_RANGEFINDER = (1 << 16), // 65536
FUNCTION_VTX_FFPV = (1 << 17), // 131072 FUNCTION_VTX_FFPV = (1 << 17), // 131072
FUNCTION_ESCSERIAL = (1 << 18), // 262144: this is used for both SERIALSHOT and ESC_SENSOR telemetry FUNCTION_ESCSERIAL = (1 << 18), // 262144: this is used for both SERIALSHOT and ESC_SENSOR telemetry
FUNCTION_TELEMETRY_SIM = (1 << 19) // 524288 FUNCTION_TELEMETRY_SIM = (1 << 19), // 524288
FUNCTION_AGH_OSD = (1 << 20), // 1048576 FUNCTION_FRSKY_OSD = (1 << 20), // 1048576
} serialPortFunction_e; } serialPortFunction_e;
typedef enum { typedef enum {