BaseSequentialStream support
This commit is contained in:
parent
1f1f9ee38a
commit
57c7ec763b
@ -2,13 +2,19 @@
|
||||
#include "hal.h"
|
||||
#include "glcd.h"
|
||||
|
||||
static GLCDDriver GLCDD1;
|
||||
|
||||
int main(void) {
|
||||
halInit();
|
||||
chSysInit();
|
||||
|
||||
lcdInit();
|
||||
lcdInit(&GLCDD1);
|
||||
lcdClear(Black);
|
||||
lcdDrawString(100, 100, "Hello World", White, Black);
|
||||
|
||||
lcdMoveCursor(10,10,White, Black);
|
||||
chprintf((BaseSequentialStream *)&GLCDD1, "chTimeNow: %d", chTimeNow());
|
||||
|
||||
lcdDrawCircle(150, 150, 10, filled, Green);
|
||||
lcdDrawLine(0, 0, lcdGetWidth(), lcdGetHeight(), Yellow);
|
||||
|
||||
|
108
glcd.c
108
glcd.c
@ -3,13 +3,82 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*
|
||||
* Interface implementation. The interface is write only
|
||||
*/
|
||||
|
||||
static size_t writes(void *ip, const uint8_t *bp, size_t n) {
|
||||
(void)ip;
|
||||
return lcdWriteString(bp, n);
|
||||
}
|
||||
|
||||
static size_t reads(void *ip, uint8_t *bp, size_t n) {
|
||||
(void)ip;
|
||||
(void)bp;
|
||||
(void)n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static msg_t put(void *ip, uint8_t b) {
|
||||
(void)ip;
|
||||
return lcdDrawChar((char)b);
|
||||
}
|
||||
|
||||
static msg_t get(void *ip) {
|
||||
(void)ip;
|
||||
return RDY_OK;
|
||||
}
|
||||
|
||||
static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
|
||||
(void)ip;
|
||||
(void)timeout;
|
||||
/* TODO: handle timeout */
|
||||
return lcdDrawChar((char)b);
|
||||
}
|
||||
|
||||
static msg_t gett(void *ip, systime_t timeout) {
|
||||
(void)ip;
|
||||
(void)timeout;
|
||||
return RDY_OK;
|
||||
}
|
||||
|
||||
static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
|
||||
(void)ip;
|
||||
(void)time;
|
||||
return lcdWriteString(bp, n);
|
||||
}
|
||||
|
||||
static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
|
||||
(void)ip;
|
||||
(void)bp;
|
||||
(void)n;
|
||||
(void)time;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static chnflags_t getflags(void *ip) {
|
||||
_chn_get_and_clear_flags_impl(ip);
|
||||
}
|
||||
|
||||
static const struct GLCDDriverVMT vmt = {
|
||||
writes, reads, put, get,
|
||||
putt, gett, writet, readt,
|
||||
getflags
|
||||
};
|
||||
|
||||
uint16_t lcd_width, lcd_height;
|
||||
uint16_t bgcolor = White, fgcolor = Black;
|
||||
uint16_t cx = 0, cy = 0;
|
||||
static uint8_t tpText = 0;
|
||||
const uint8_t* font;
|
||||
|
||||
void lcdInit(void) {
|
||||
void lcdInit(GLCDDriver *glcdp) {
|
||||
glcdp->vmt = &vmt;
|
||||
|
||||
lld_lcdInit();
|
||||
lcd_width = SCREEN_WIDTH;
|
||||
lcd_height = SCREEN_HEIGHT;
|
||||
@ -128,7 +197,7 @@ void lcdSetFontTransparency(uint8_t transparency) {
|
||||
tpText = transparency;
|
||||
}
|
||||
|
||||
void lcdDrawChar(char c) {
|
||||
msg_t lcdDrawChar(char c) {
|
||||
const uint8_t* ptr;
|
||||
uint8_t fontHeight = lcdGetCurFontHeight();
|
||||
uint8_t sps = font[FONT_TABLE_PAD_AFTER_CHAR_IDX];
|
||||
@ -139,7 +208,7 @@ void lcdDrawChar(char c) {
|
||||
if(c < 0x20 || c > 0x7F) {
|
||||
if(c == '\n')
|
||||
lcdLineBreak();
|
||||
return;
|
||||
return RDY_OK;
|
||||
}
|
||||
|
||||
chi = *(uint16_t*)(&font[FONT_TABLE_CHAR_LOOKUP_IDX + (c-0x20)*2]);
|
||||
@ -170,11 +239,38 @@ void lcdDrawChar(char c) {
|
||||
lcdFillArea(cx, cy, cx+sps, cy+fontHeight, bgcolor);
|
||||
cx += sps;
|
||||
}
|
||||
|
||||
/* TODO: proper return codes */
|
||||
return RDY_OK;
|
||||
}
|
||||
|
||||
void lcdPutString(const char *str) {
|
||||
while(*str)
|
||||
lcdDrawChar(*str++);
|
||||
size_t lcdWriteString(const char *str, size_t n) {
|
||||
size_t l = 0;
|
||||
for(l = 0; l < n; l++) {
|
||||
if(lcdDrawChar(*str++) != RDY_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
size_t lcdPutString(const char *str) {
|
||||
size_t l = 0;
|
||||
while(*str) {
|
||||
if(lcdDrawChar(*str++) != RDY_OK)
|
||||
break;
|
||||
|
||||
l++;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void lcdMoveCursor(uint16_t x, uint16_t y, uint16_t color, uint16_t bkcolor) {
|
||||
cx = x;
|
||||
cy = y;
|
||||
bgcolor = bkcolor;
|
||||
fgcolor = color;
|
||||
}
|
||||
|
||||
void lcdDrawString(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bkcolor) {
|
||||
|
41
glcd.h
41
glcd.h
@ -41,12 +41,45 @@ extern const uint8_t* font;
|
||||
#define lcdGotoXY(x,y) { cx=x; cy=y; }
|
||||
#define lcdGetCurFontHeight() (font[FONT_TABLE_HEIGHT_IDX])
|
||||
|
||||
/**
|
||||
* @brief Structure representing a GLCD driver.
|
||||
*/
|
||||
typedef struct GLCDDriver GLCDDriver;
|
||||
|
||||
/**
|
||||
* @brief @p GLCDDriver specific methods.
|
||||
*/
|
||||
#define _glcd_driver_methods \
|
||||
_base_asynchronous_channel_methods
|
||||
|
||||
/**
|
||||
* @extends BaseAsynchronousChannelVMT
|
||||
*
|
||||
* @brief @p GLCDDriver virtual methods table.
|
||||
*/
|
||||
struct GLCDDriverVMT {
|
||||
_glcd_driver_methods
|
||||
};
|
||||
|
||||
/**
|
||||
* @extends BaseAsynchronousChannel
|
||||
*
|
||||
* @brief GLCD driver class.
|
||||
* @details This class extends @p BaseAsynchronousChannel by adding physical
|
||||
* I/O queues.
|
||||
*/
|
||||
struct GLCDDriver {
|
||||
/** @brief Virtual Methods Table.*/
|
||||
const struct GLCDDriverVMT *vmt;
|
||||
_base_asynchronous_channel_data
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
void lcdInit(void);
|
||||
void lcdInit(GLCDDriver *);
|
||||
|
||||
void lcdClear(uint16_t color);
|
||||
void lcdSetOrientation(uint8_t newOrientation);
|
||||
@ -61,8 +94,10 @@ void lcdDrawCircle(uint16_t x, uint16_t y, uint16_t radius, uint8_t filled, uint
|
||||
|
||||
void lcdSetFontTransparency(uint8_t transparency);
|
||||
void lcdSetFont(const uint8_t *newFont);
|
||||
void lcdDrawChar(char c);
|
||||
void lcdPutString(const char *str);
|
||||
void lcdMoveCursor(uint16_t x, uint16_t y, uint16_t color, uint16_t bkcolor);
|
||||
msg_t lcdDrawChar(char c);
|
||||
size_t lcdWriteString(const char *str, size_t n);
|
||||
size_t lcdPutString(const char *str);
|
||||
void lcdDrawString(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bkcolor);
|
||||
void lcdLineBreak(void);
|
||||
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
|
||||
/***** LCD INTERFACE *****/
|
||||
#define LCD_USE_GPIO
|
||||
// #define LCD_USE_GPIO
|
||||
// #define LCD_USE_SPI
|
||||
// #define LCD_USE_FSMC
|
||||
#define LCD_USE_FSMC
|
||||
|
||||
|
||||
/***** TOUCHPAD CONTROLLER *****/
|
||||
// #define TOUCHPAD_USE_ADS7843
|
||||
#define TOUCHPAD_USE_XPT2046
|
||||
//#define TOUCHPAD_USE_XPT2046
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user