Displayport tidy

This commit is contained in:
Martin Budden 2017-06-28 21:21:29 +01:00
parent c1576cdba6
commit 1c7f574a55
5 changed files with 23 additions and 9 deletions

View File

@ -17,6 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include "platform.h" #include "platform.h"
@ -66,13 +67,23 @@ bool displayIsGrabbed(const displayPort_t *instance)
return (instance && instance->grabCount > 0); return (instance && instance->grabCount > 0);
} }
void displaySetXY(displayPort_t *instance, uint8_t x, uint8_t y)
{
instance->posX = x;
instance->posY = y;
}
int displayWrite(displayPort_t *instance, uint8_t x, uint8_t y, const char *s) int displayWrite(displayPort_t *instance, uint8_t x, uint8_t y, const char *s)
{ {
return instance->vTable->write(instance, x, y, s); instance->posX = x + strlen(s);
instance->posY = y;
return instance->vTable->writeString(instance, x, y, s);
} }
int displayWriteChar(displayPort_t *instance, uint8_t x, uint8_t y, uint8_t c) int displayWriteChar(displayPort_t *instance, uint8_t x, uint8_t y, uint8_t c)
{ {
instance->posX = x + 1;
instance->posY = y;
return instance->vTable->writeChar(instance, x, y, c); return instance->vTable->writeChar(instance, x, y, c);
} }

View File

@ -23,6 +23,8 @@ typedef struct displayPort_s {
void *device; void *device;
uint8_t rows; uint8_t rows;
uint8_t cols; uint8_t cols;
uint8_t posX;
uint8_t posY;
// CMS state // CMS state
bool cleared; bool cleared;
@ -36,7 +38,7 @@ typedef struct displayPortVTable_s {
int (*clearScreen)(displayPort_t *displayPort); int (*clearScreen)(displayPort_t *displayPort);
int (*drawScreen)(displayPort_t *displayPort); int (*drawScreen)(displayPort_t *displayPort);
int (*screenSize)(const displayPort_t *displayPort); int (*screenSize)(const displayPort_t *displayPort);
int (*write)(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *text); int (*writeString)(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *text);
int (*writeChar)(displayPort_t *displayPort, uint8_t x, uint8_t y, uint8_t c); int (*writeChar)(displayPort_t *displayPort, uint8_t x, uint8_t y, uint8_t c);
bool (*isTransferInProgress)(const displayPort_t *displayPort); bool (*isTransferInProgress)(const displayPort_t *displayPort);
int (*heartbeat)(displayPort_t *displayPort); int (*heartbeat)(displayPort_t *displayPort);
@ -59,6 +61,7 @@ bool displayIsGrabbed(const displayPort_t *instance);
void displayClearScreen(displayPort_t *instance); void displayClearScreen(displayPort_t *instance);
void displayDrawScreen(displayPort_t *instance); void displayDrawScreen(displayPort_t *instance);
int displayScreenSize(const displayPort_t *instance); int displayScreenSize(const displayPort_t *instance);
void displaySetXY(displayPort_t *instance, uint8_t x, uint8_t y);
int displayWrite(displayPort_t *instance, uint8_t x, uint8_t y, const char *s); int displayWrite(displayPort_t *instance, uint8_t x, uint8_t y, const char *s);
int displayWriteChar(displayPort_t *instance, uint8_t x, uint8_t y, uint8_t c); int displayWriteChar(displayPort_t *instance, uint8_t x, uint8_t y, uint8_t c);
bool displayIsTransferInProgress(const displayPort_t *instance); bool displayIsTransferInProgress(const displayPort_t *instance);

View File

@ -95,7 +95,7 @@ static int screenSize(const displayPort_t *displayPort)
return maxScreenSize; return maxScreenSize;
} }
static int write(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s) static int writeString(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s)
{ {
UNUSED(displayPort); UNUSED(displayPort);
max7456Write(x, y, s); max7456Write(x, y, s);
@ -143,7 +143,7 @@ static const displayPortVTable_t max7456VTable = {
.clearScreen = clearScreen, .clearScreen = clearScreen,
.drawScreen = drawScreen, .drawScreen = drawScreen,
.screenSize = screenSize, .screenSize = screenSize,
.write = write, .writeString = writeString,
.writeChar = writeChar, .writeChar = writeChar,
.isTransferInProgress = isTransferInProgress, .isTransferInProgress = isTransferInProgress,
.heartbeat = heartbeat, .heartbeat = heartbeat,

View File

@ -100,7 +100,7 @@ static int screenSize(const displayPort_t *displayPort)
return displayPort->rows * displayPort->cols; return displayPort->rows * displayPort->cols;
} }
static int write(displayPort_t *displayPort, uint8_t col, uint8_t row, const char *string) static int writeString(displayPort_t *displayPort, uint8_t col, uint8_t row, const char *string)
{ {
#define MSP_OSD_MAX_STRING_LENGTH 30 // FIXME move this #define MSP_OSD_MAX_STRING_LENGTH 30 // FIXME move this
uint8_t buf[MSP_OSD_MAX_STRING_LENGTH + 4]; uint8_t buf[MSP_OSD_MAX_STRING_LENGTH + 4];
@ -125,7 +125,7 @@ static int writeChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8
buf[0] = c; buf[0] = c;
buf[1] = 0; buf[1] = 0;
return write(displayPort, col, row, buf); //!!TODO - check if there is a direct MSP command to do this return writeString(displayPort, col, row, buf); //!!TODO - check if there is a direct MSP command to do this
} }
static bool isTransferInProgress(const displayPort_t *displayPort) static bool isTransferInProgress(const displayPort_t *displayPort)
@ -152,7 +152,7 @@ static const displayPortVTable_t mspDisplayPortVTable = {
.clearScreen = clearScreen, .clearScreen = clearScreen,
.drawScreen = drawScreen, .drawScreen = drawScreen,
.screenSize = screenSize, .screenSize = screenSize,
.write = write, .writeString = writeString,
.writeChar = writeChar, .writeChar = writeChar,
.isTransferInProgress = isTransferInProgress, .isTransferInProgress = isTransferInProgress,
.heartbeat = heartbeat, .heartbeat = heartbeat,

View File

@ -56,7 +56,7 @@ static int oledScreenSize(const displayPort_t *displayPort)
return displayPort->rows * displayPort->cols; return displayPort->rows * displayPort->cols;
} }
static int oledWrite(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s) static int oledWriteString(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s)
{ {
i2c_OLED_set_xy(displayPort->device, x, y); i2c_OLED_set_xy(displayPort->device, x, y);
i2c_OLED_send_string(displayPort->device, s); i2c_OLED_send_string(displayPort->device, s);
@ -99,7 +99,7 @@ static const displayPortVTable_t oledVTable = {
.clearScreen = oledClearScreen, .clearScreen = oledClearScreen,
.drawScreen = oledDrawScreen, .drawScreen = oledDrawScreen,
.screenSize = oledScreenSize, .screenSize = oledScreenSize,
.write = oledWrite, .writeString = oledWriteString,
.writeChar = oledWriteChar, .writeChar = oledWriteChar,
.isTransferInProgress = oledIsTransferInProgress, .isTransferInProgress = oledIsTransferInProgress,
.heartbeat = oledHeartbeat, .heartbeat = oledHeartbeat,