Add lcd_printf function (allow use printf for lcd output)

Removed_REF_marker
DiSlord 5 years ago
parent f50d7e7f47
commit 753d397f61

@ -23,7 +23,7 @@
#ifdef TINYSA4
#include "si4432.h"
#endif
#include "chprintf.h"
#include "spi.h"
// Pin macros for LCD
@ -841,6 +841,50 @@ void ili9341_drawstring_10x14(const char *str, int x, int y)
#endif
}
typedef struct {
const void *vmt;
int16_t start_x;
int16_t start_y;
int16_t x;
int16_t y;
} lcdPrintStream;
static msg_t lcd_put(void *ip, uint8_t ch) {
lcdPrintStream *ps = ip;
if (ch == '\n') {ps->x = ps->start_x; ps->y+=FONT_STR_HEIGHT; return MSG_OK;}
uint16_t w = FONT_GET_WIDTH(ch);
ili9341_blitBitmap(ps->x, ps->y, w, FONT_GET_HEIGHT, FONT_GET_DATA(ch));
ps->x+= w;
return MSG_OK;
}
#if 0
static msg_t lcd_put_7x13(void *ip, uint8_t ch) {
lcdPrintStream *ps = ip;
if (ch == '\n') {ps->x = ps->start_x; ps->y+=FONT_STR_HEIGHT; return MSG_OK;}
uint16_t w = FONT_GET_WIDTH(ch);
ili9341_blitBitmap(ps->x, ps->y, w, FONT_GET_HEIGHT, FONT_GET_DATA(ch));
ps->x+= w;
return MSG_OK;
}
#endif
// Simple print in buffer function
int lcd_printf(int16_t x, int16_t y, const char *fmt, ...) {
// Init small lcd print stream
struct lcd_printStreamVMT {
_base_sequential_stream_methods
} lcd_vmt = {NULL, NULL, lcd_put, NULL};
lcdPrintStream ps = {&lcd_vmt, x, y, x, y};
// Performing the print operation using the common code.
va_list ap;
va_start(ap, fmt);
int retval = chvprintf((BaseSequentialStream *)(void *)&ps, fmt, ap);
va_end(ap);
// Return number of bytes that would have been written.
return retval;
}
void ili9341_drawstringV(const char *str, int x, int y)
{
ili9341_set_rotation(DISPLAY_ROTATION_270);

@ -961,6 +961,7 @@ void ili9341_drawchar(uint8_t ch, int x, int y);
void ili9341_drawstring(const char *str, int x, int y);
void ili9341_drawstring_7x13(const char *str, int x, int y);
void ili9341_drawstring_10x14(const char *str, int x, int y);
int lcd_printf(int16_t x, int16_t y, const char *fmt, ...);
void ili9341_drawstringV(const char *str, int x, int y);
int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size);
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size);

Loading…
Cancel
Save

Powered by TurnKey Linux.