implemented worker thread for glcd

ugfx_release_2.6
Tectu 2012-07-16 03:56:46 +02:00
parent e3a1ba08ab
commit b5b68e3461
2 changed files with 235 additions and 17 deletions

169
glcd.c
View File

@ -2,6 +2,8 @@
#include <stdlib.h>
#include <math.h>
#define EMSG(a) const struct a *emsg = (const struct a*)msg
uint16_t lcd_width, lcd_height;
static Thread *workerThread = NULL;
@ -21,18 +23,89 @@ static msg_t ThreadGLCDWorker(void *arg) {
/* do work here */
switch(msg->action) {
case GLCD_SET_CURSOR: {
const struct glcd_msg_set_cursor *emsg = (const struct glcd_msg_set_cursor*)msg;
EMSG(glcd_msg_set_cursor);
lld_lcdSetCursor(emsg->x, emsg->y);
msg->result = GLCD_DONE;
break;
}
case GLCD_SET_POWERMODE: {
EMSG(glcd_msg_powermode);
lld_lcdSetPowerMode(emsg->powermode);
msg->result = GLCD_DONE;
break;
}
case GLCD_SET_ORIENTATION: {
EMSG(glcd_msg_orientation);
lld_lcdSetOrientation(emsg->newOrientation);
msg->result = GLCD_DONE;
break;
}
case GLCD_SET_WINDOW: {
EMSG(glcd_msg_set_window);
lld_lcdSetWindow(emsg->x0, emsg->y0, emsg->x1, emsg->y1);
msg->result = GLCD_DONE;
break;
}
case GLCD_FILL_AREA: {
EMSG(glcd_msg_fill_area);
lld_lcdFillArea(emsg->x0, emsg->y0, emsg->x1, emsg->y1, emsg->color);
msg->result = GLCD_DONE;
break;
}
case GLCD_WRITE_AREA: {
EMSG(glcd_msg_write_area);
lld_lcdSetWindow(emsg->x0, emsg->y0, emsg->x1, emsg->y1);
lld_lcdWriteStreamStart();
lld_lcdWriteStream(emsg->buffer, emsg->size);
lld_lcdWriteStreamStop();
msg->result = GLCD_DONE;
break;
}
case GLCD_CLEAR: {
EMSG(glcd_msg_clear);
lld_lcdClear(emsg->color);
msg->result = GLCD_DONE;
break;
}
case GLCD_GET_PIXEL_COLOR: {
/* ToDo */
msg->result = GLCD_DONE;
break;
}
case GLCD_DRAW_PIXEL: {
const struct glcd_msg_draw_pixel *emsg = (const struct glcd_msg_draw_pixel*)msg;
EMSG(glcd_msg_draw_pixel);
lld_lcdDrawPixel(emsg->x, emsg->y, emsg->color);
msg->result = GLCD_DONE;
break;
}
case GLCD_WRITE_STREAM_START: {
lld_lcdWriteStreamStart();
msg->result = GLCD_DONE;
break;
}
case GLCD_WRITE_STREAM_STOP: {
lld_lcdWriteStreamStop();
msg->result = GLCD_DONE;
break;
}
case GLCD_WRITE_STREAM: {
EMSG(glcd_msg_write_stream);
lld_lcdWriteStream(emsg->buffer, emsg->size);
msg->result = GLCD_DONE;
break;
}
}
/* Done, release msg again. */
@ -76,35 +149,85 @@ static void lcdSetCursor(uint16_t x, uint16_t y) {
}
void lcdSetPowerMode(uint8_t powerMode) {
lld_lcdSetPowerMode(powerMode);
struct glcd_msg_powermode msg;
msg.action = GLCD_SET_POWERMODE;
msg.powermode = powerMode;
chMsgSend(workerThread, (msg_t)&msg);
}
void lcdSetOrientation(uint8_t newOrientation) {
lld_lcdSetOrientation(newOrientation);
struct glcd_msg_orientation msg;
msg.action = GLCD_SET_ORIENTATION;
msg.newOrientation = newOrientation;
chMsgSend(workerThread, (msg_t)&msg);
}
void lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
lld_lcdSetWindow(x0, y0, x1, y1);
struct glcd_msg_set_window msg;
msg.action = GLCD_SET_WINDOW;
msg.x0 = x0;
msg.y0 = y0;
msg.x1 = x1;
msg.y1 = y1;
chMsgSend(workerThread, (msg_t)&msg);
}
void lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
lld_lcdFillArea(x0, y0, x1, y1, color);
struct glcd_msg_fill_area msg;
msg.action = GLCD_FILL_AREA;
msg.x0 = x0;
msg.y0 = y0;
msg.x1 = x1;
msg.y1 = y1;
msg.color = color;
chMsgSend(workerThread, (msg_t)&msg);
}
void lcdWriteArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t *buffer, size_t n) {
lld_lcdSetWindow(x0, y0, x1, y1);
struct glcd_msg_write_area msg;
lld_lcdWriteStreamStart();
lld_lcdWriteStream(buffer, n);
lld_lcdWriteStreamStop();
msg.action = GLCD_WRITE_AREA;
msg.x0 = x0;
msg.y0 = y0;
msg.x1 = x1;
msg.y1 = y1;
msg.buffer = buffer;
msg.size = n;
chMsgSend(workerThread, (msg_t)&msg);
}
void lcdClear(uint16_t color) {
lld_lcdClear(color);
struct glcd_msg_clear msg;
msg.action = GLCD_CLEAR;
msg.color = color;
chMsgSend(workerThread, (msg_t)&msg);
}
uint16_t lcdGetPixelColor(uint16_t x, uint16_t y) {
return lld_lcdGetPixelColor(x, y);
struct glcd_msg_get_pixel_color msg;
uint16_t result;
msg.action = GLCD_GET_PIXEL_COLOR;
msg.x = x;
msg.y = y;
msg.color = &result;
chMsgSend(workerThread, (msg_t)&msg);
while(msg.result != GLCD_DONE);
return result;
}
void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
@ -119,15 +242,29 @@ void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
}
static void lcdWriteStreamStart(void) {
lld_lcdWriteStreamStart();
struct glcd_msg_write_stream_start msg;
msg.action = GLCD_WRITE_STREAM_START;
chMsgSend(workerThread, (msg_t)&msg);
}
static void lcdWriteStreamStop(void) {
lld_lcdWriteStreamStop();
struct glcd_msg_write_stream_stop msg;
msg.action = GLCD_WRITE_STREAM_STOP;
chMsgSend(workerThread, (msg_t)&msg);
}
static void lcdWriteStream(uint16_t *buffer, uint16_t size) {
lld_lcdWriteStream(buffer, size);
struct glcd_msg_write_stream msg;
msg.action = GLCD_WRITE_STREAM;
msg.buffer = buffer;
msg.size = size;
chMsgSend(workerThread, (msg_t)&msg);
}
void lcdDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {

View File

@ -4,12 +4,22 @@
#define GLCD_WORKER_SIZE 2048
enum glcd_action { GLCD_SET_CURSOR,
GLCD_SET_POWERMODE,
GLCD_SET_ORIENTATION,
GLCD_SET_WINDOW,
GLCD_FILL_AREA,
GLCD_WRITE_AREA,
GLCD_CLEAR,
GLCD_GET_PIXEL_COLOR,
GLCD_DRAW_PIXEL,
GLCD_WRITE_STREAM_START,
GLCD_WRITE_STREAM_STOP,
GLCD_WRITE_STREAM,
};
enum glcd_result { GLCD_DONE,
GLCD_FAILED,
GLCD_PROGRESS
GLCD_PROGRESS,
};
#define _glcd_msg_base \
@ -27,6 +37,62 @@ struct glcd_msg_set_cursor {
uint16_t y;
};
struct glcd_msg_powermode {
_glcd_msg_base
uint8_t powermode;
};
struct glcd_msg_orientation {
_glcd_msg_base
uint8_t newOrientation;
};
struct glcd_msg_set_window {
_glcd_msg_base
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
};
struct glcd_msg_fill_area {
_glcd_msg_base
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
uint16_t color;
};
struct glcd_msg_write_area {
_glcd_msg_base
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
uint16_t *buffer;
size_t size;
};
struct glcd_msg_clear {
_glcd_msg_base
uint16_t color;
};
struct glcd_msg_get_pixel_color {
_glcd_msg_base
uint16_t x;
uint16_t y;
uint16_t color;
};
struct glcd_msg_draw_pixel {
_glcd_msg_base
@ -35,5 +101,20 @@ struct glcd_msg_draw_pixel {
uint16_t color;
};
struct glcd_msg_write_stream_start {
_glcd_msg_base
};
struct glcd_msg_write_stream_stop {
_glcd_msg_base
};
struct glcd_msg_write_stream {
_glcd_msg_base
uint16_t *buffer;
uint16_t size;
};
#endif