1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 00:05:33 +03:00
betaflight/src/main/io/canvas.c
jflyper 720a841008 More displayPort_t, CANVAS as new feature, multi-display cycling
- Further touch-ups with displayPort_t handling.
- CANVAS is a FEATURE now.
- Device specific xxxCmsInit() are registered by device’s init, and
called by CMS upon entry to menu.
- Multiple display devices can be cycled by entering menu invocation
command while in menu.
- The menu invocation command is (was) changed to THR-Mid + YAW-Left +
Pitch-Full to avoid collision with MWOSD menu invocation command.
- More separation attempt.
2016-10-28 13:22:28 +09:00

94 lines
1.6 KiB
C

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include "platform.h"
#include "build/version.h"
#ifdef CANVAS
#include "drivers/system.h"
#include "io/cms.h"
#include "fc/fc_msp.h"
#include "msp/msp_protocol.h"
#include "msp/msp_serial.h"
int canvasOutput(uint8_t cmd, uint8_t *buf, int len)
{
mspSerialPush(cmd, buf, len);
return 6 + len;
}
int canvasBegin(void)
{
uint8_t subcmd[] = { 0 };
return canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
}
int canvasHeartBeat(void)
{
return canvasBegin();
}
int canvasEnd(void)
{
uint8_t subcmd[] = { 1 };
return canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
}
int canvasClear(void)
{
uint8_t subcmd[] = { 2 };
return canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
}
int canvasWrite(uint8_t col, uint8_t row, char *string)
{
int len;
char buf[30 + 4];
if ((len = strlen(string)) >= 30)
len = 30;
buf[0] = 3;
buf[1] = row;
buf[2] = col;
buf[3] = 0;
memcpy((char *)&buf[4], string, len);
return canvasOutput(MSP_CANVAS, (uint8_t *)buf, len + 4);
}
screenFnVTable_t canvasVTable = {
canvasBegin,
canvasEnd,
canvasClear,
canvasWrite,
canvasHeartBeat,
NULL,
};
void canvasCmsInit(displayPort_t *pPort)
{
pPort->rows = 13;
pPort->cols = 30;
pPort->buftime = 23; // = 256/(115200/10)
pPort->bufsize = 192; // 256 * 3/4 (Be conservative)
pPort->VTable = &canvasVTable;
}
void canvasInit()
{
mspSerialPushInit(mspFcPushInit()); // Called once at startup to initialize push function in msp
cmsDeviceRegister(canvasCmsInit);
}
#endif