merge upstream changes

This commit is contained in:
trsaunders 2012-06-27 17:51:08 +01:00
commit bdcbdd4c38
11 changed files with 594 additions and 365 deletions

79
demos/gui/main.c Executable file
View file

@ -0,0 +1,79 @@
#include "ch.h"
#include "hal.h"
#include "gui.h"
#include "glcd.h"
#include "touchpad.h"
__inline void lld_lcdWriteGPIO(uint16_t data) {
palWritePort(LCD_DATA_PORT, data);
}
__inline uint16_t lld_lcdReadGPIO(void) {
uint16_t value;
// change pin mode to digital input
LCD_DATA_PORT->CRH = 0x44444444;
LCD_DATA_PORT->CRL = 0x44444444;
value = palReadPort(LCD_DATA_PORT); // dummy
value = palReadPort(LCD_DATA_PORT);
// change pin mode back to digital output
LCD_DATA_PORT->CRH = 0x33333333;
LCD_DATA_PORT->CRL = 0x33333333;
return value;
}
// GLCD driver object
static GLCDDriver GLCDD1;
int main(void) {
uint8_t setActive, setState, clearActive, clearState;
halInit();
chSysInit();
// Initializes the LCD
lcdInit(&GLCDD1);
// Initializes the touchpad
tpInit(&SPID1);
// clear the entire LCD screen
lcdClear(Black);
// Initializes the GUI thread
// 10ms interval
// HIGHPRIO-2 thread priority level
guiInit(10, HIGHPRIO-2);
// set the following buttons to active
// buttons wouldn't have any effect if you set these variables to 'inactive'
setActive = active;
clearActive = active;
// draw a button to set, and one to clear the LED
guiDrawButton(10, 10, 60, 60, "Set", Black, Yellow, "SetButton", &setActive, &setState);
guiDrawButton(70, 10, 120, 60, "Clear", Black, Red, "ClearButton", &clearActive, &clearState);
// you can delete a GUI element at any time from the GUI. You have to pass the GUI element name here.
// please note that you have to redraw the screen to delete the element yourself.
// guiDeleteElement("SetButton");
// guiDeleteElement("ClearButton");
while (TRUE) {
// check if button 'set' is pressed
if(setState)
palSetPad(GPIOD, GPIOD_LED3);
// check if button 'clear' is pressed
if(clearState)
palClearPad(GPIOD, GPIOD_LED3);
chThdSleepMilliseconds(200);
}
return 0;
}

34
demos/powermodes/main.c Executable file
View file

@ -0,0 +1,34 @@
#include "ch.h"
#include "hal.h"
#include "glcd.h"
static GLCDDriver GLCDD1;
int main(void) {
halInit();
chSysInit();
lcdInit(&GLCDD1);
lcdClear(Black);
lcdDrawString(100, 100, "Hello World", White, Black);
// wait two seconds to see current LCD content
chThdSleepSeconds(2);
// brings LCD to sleep mode
lcdSetPowerMode(sleepOn);
// wait two seconds to see current LCD content
chThdSleepSeconds(2);
// brings LCD back from sleep mode
// content displayed before gets displayed again
lcdSetPowerMode(sleepOff);
while (TRUE) {
chThdSleepMilliseconds(200);
}
return 0;
}

View file

@ -9,11 +9,12 @@ extern uint16_t lcd_width, lcd_height;
static uint16_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)]; static uint16_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)];
#ifdef LCD_USE_GPIO #ifdef LCD_USE_GPIO
static __inline void lld_lcdWriteIndex(uint16_t index) { static __inline void lld_lcdWriteIndex(uint16_t index) {
Clr_RS; Clr_RS;
Set_RD; Set_RD;
palWritePort(LCD_DATA_PORT, index); lld_lcdWriteGPIO(index);
Clr_WR; Clr_WR;
Set_WR; Set_WR;
@ -22,7 +23,7 @@ static __inline void lld_lcdWriteIndex(uint16_t index) {
static __inline void lld_lcdWriteData(uint16_t data) { static __inline void lld_lcdWriteData(uint16_t data) {
Set_RS; Set_RS;
palWritePort(LCD_DATA_PORT, data); lld_lcdWriteGPIO(data);
Clr_WR; Clr_WR;
Set_WR; Set_WR;
@ -30,8 +31,10 @@ static __inline void lld_lcdWriteData(uint16_t data) {
static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) { static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
Clr_CS; Clr_CS;
lld_lcdWriteIndex(lcdReg); lld_lcdWriteIndex(lcdReg);
lld_lcdWriteData(lcdRegValue); lld_lcdWriteData(lcdRegValue);
Set_CS; Set_CS;
} }
@ -42,16 +45,7 @@ static __inline uint16_t lld_lcdReadData(void) {
Set_WR; Set_WR;
Clr_RD; Clr_RD;
// change pin mode to digital input value = lld_lcdReadGPIO();
LCD_DATA_PORT->CRH = 0x44444444;
LCD_DATA_PORT->CRL = 0x44444444;
value = palReadPort(LCD_DATA_PORT); // dummy
value = palReadPort(LCD_DATA_PORT);
// change pin mode back to digital output
LCD_DATA_PORT->CRH = 0x33333333;
LCD_DATA_PORT->CRL = 0x33333333;
Set_RD; Set_RD;
@ -72,6 +66,7 @@ static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
__inline void lld_lcdWriteStreamStart(void) { __inline void lld_lcdWriteStreamStart(void) {
Clr_CS; Clr_CS;
lld_lcdWriteIndex(0x0022); lld_lcdWriteIndex(0x0022);
} }
@ -85,7 +80,7 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
Set_RS; Set_RS;
for(i = 0; i < size; i++) { for(i = 0; i < size; i++) {
palWritePort(LCD_DATA_PORT, buffer[i]); lld_lcdWriteGPIO(buffer[i]);
Clr_WR; Clr_WR;
Set_WR; Set_WR;
} }
@ -112,6 +107,10 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
#endif #endif
#ifdef LCD_USE_SPI
/* TODO */
#endif
#ifdef LCD_USE_FSMC #ifdef LCD_USE_FSMC
#define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */ #define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
@ -173,15 +172,30 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
} }
#endif #endif
#ifdef LCD_USE_SPI static __inline void lld_lcdDelay(uint16_t us) {
/* TODO! */
#endif
static __inline void lcdDelay(uint16_t us) {
chThdSleepMicroseconds(us); chThdSleepMicroseconds(us);
} }
void lld_lcdSetPowerMode(uint8_t powerMode) {
switch(powerMode) {
case powerOff:
lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode
lld_lcdWriteReg(0x0007, 0x0000); // halt operation
lld_lcdWriteReg(0x0000, 0x0000); // turn off oszillator
lld_lcdWriteReg(0x0010, 0x0001); // enter sleepmode
break;
case powerOn:
lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode
lld_lcdInit();
break;
case sleepOn:
lld_lcdWriteReg(0x0010, 0x0001); // enter sleep mode
break;
case sleepOff:
lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode
break;
}
}
void lld_lcdSetCursor(uint16_t x, uint16_t y) { void lld_lcdSetCursor(uint16_t x, uint16_t y) {
/* Reg 0x004E is an 8 bit value /* Reg 0x004E is an 8 bit value
@ -334,47 +348,47 @@ void lld_lcdInit(void) {
#endif #endif
DeviceCode = lld_lcdReadReg(0x0000); DeviceCode = lld_lcdReadReg(0x0000);
lld_lcdWriteReg(0x0000,0x0001); lcdDelay(5); lld_lcdWriteReg(0x0000,0x0001); lld_lcdDelay(5);
lld_lcdWriteReg(0x0003,0xA8A4); lcdDelay(5); lld_lcdWriteReg(0x0003,0xA8A4); lld_lcdDelay(5);
lld_lcdWriteReg(0x000C,0x0000); lcdDelay(5); lld_lcdWriteReg(0x000C,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x000D,0x080C); lcdDelay(5); lld_lcdWriteReg(0x000D,0x080C); lld_lcdDelay(5);
lld_lcdWriteReg(0x000E,0x2B00); lcdDelay(5); lld_lcdWriteReg(0x000E,0x2B00); lld_lcdDelay(5);
lld_lcdWriteReg(0x001E,0x00B0); lcdDelay(5); lld_lcdWriteReg(0x001E,0x00B0); lld_lcdDelay(5);
lld_lcdWriteReg(0x0001,0x2B3F); lcdDelay(5); lld_lcdWriteReg(0x0001,0x2B3F); lld_lcdDelay(5);
lld_lcdWriteReg(0x0002,0x0600); lcdDelay(5); lld_lcdWriteReg(0x0002,0x0600); lld_lcdDelay(5);
lld_lcdWriteReg(0x0010,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0010,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0011,0x6070); lcdDelay(5); lld_lcdWriteReg(0x0011,0x6070); lld_lcdDelay(5);
lld_lcdWriteReg(0x0005,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0005,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0006,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0006,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0016,0xEF1C); lcdDelay(5); lld_lcdWriteReg(0x0016,0xEF1C); lld_lcdDelay(5);
lld_lcdWriteReg(0x0017,0x0003); lcdDelay(5); lld_lcdWriteReg(0x0017,0x0003); lld_lcdDelay(5);
lld_lcdWriteReg(0x0007,0x0133); lcdDelay(5); lld_lcdWriteReg(0x0007,0x0133); lld_lcdDelay(5);
lld_lcdWriteReg(0x000B,0x0000); lcdDelay(5); lld_lcdWriteReg(0x000B,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x000F,0x0000); lcdDelay(5); lld_lcdWriteReg(0x000F,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0041,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0041,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0042,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0042,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0048,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0048,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0049,0x013F); lcdDelay(5); lld_lcdWriteReg(0x0049,0x013F); lld_lcdDelay(5);
lld_lcdWriteReg(0x004A,0x0000); lcdDelay(5); lld_lcdWriteReg(0x004A,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x004B,0x0000); lcdDelay(5); lld_lcdWriteReg(0x004B,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0044,0xEF00); lcdDelay(5); lld_lcdWriteReg(0x0044,0xEF00); lld_lcdDelay(5);
lld_lcdWriteReg(0x0045,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0045,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0046,0x013F); lcdDelay(5); lld_lcdWriteReg(0x0046,0x013F); lld_lcdDelay(5);
lld_lcdWriteReg(0x0030,0x0707); lcdDelay(5); lld_lcdWriteReg(0x0030,0x0707); lld_lcdDelay(5);
lld_lcdWriteReg(0x0031,0x0204); lcdDelay(5); lld_lcdWriteReg(0x0031,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0032,0x0204); lcdDelay(5); lld_lcdWriteReg(0x0032,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0033,0x0502); lcdDelay(5); lld_lcdWriteReg(0x0033,0x0502); lld_lcdDelay(5);
lld_lcdWriteReg(0x0034,0x0507); lcdDelay(5); lld_lcdWriteReg(0x0034,0x0507); lld_lcdDelay(5);
lld_lcdWriteReg(0x0035,0x0204); lcdDelay(5); lld_lcdWriteReg(0x0035,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0036,0x0204); lcdDelay(5); lld_lcdWriteReg(0x0036,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0037,0x0502); lcdDelay(5); lld_lcdWriteReg(0x0037,0x0502); lld_lcdDelay(5);
lld_lcdWriteReg(0x003A,0x0302); lcdDelay(5); lld_lcdWriteReg(0x003A,0x0302); lld_lcdDelay(5);
lld_lcdWriteReg(0x003B,0x0302); lcdDelay(5); lld_lcdWriteReg(0x003B,0x0302); lld_lcdDelay(5);
lld_lcdWriteReg(0x0023,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0023,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0024,0x0000); lcdDelay(5); lld_lcdWriteReg(0x0024,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0025,0x8000); lcdDelay(5); lld_lcdWriteReg(0x0025,0x8000); lld_lcdDelay(5);
lld_lcdWriteReg(0x004f,0x0000); lcdDelay(5); lld_lcdWriteReg(0x004f,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x004e,0x0000); lcdDelay(5); lld_lcdWriteReg(0x004e,0x0000); lld_lcdDelay(5);
} }
uint16_t lld_lcdGetOrientation(void) { uint16_t lld_lcdGetOrientation(void) {

View file

@ -5,6 +5,31 @@
#ifdef LCD_USE_SSD1289 #ifdef LCD_USE_SSD1289
#ifdef __cplusplus
extern "C" {
#endif
void lld_lcdInit(void);
void lld_lcdWriteStreamStart(void);
void lld_lcdWriteStreamStop(void);
void lld_lcdWriteStream(uint16_t *buffer, uint16_t size);
void lld_lcdSetCursor(uint16_t x, uint16_t y);
void lld_lcdSetOrientation(uint8_t newOrientation);
void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void lld_lcdClear(uint16_t color);
void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color);
void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
void lld_lcdSetPowerMode(uint8_t powerMode);
uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
uint16_t lld_lcdGetOrientation(void);
uint16_t lld_lcdGetHeight(void);
uint16_t lld_lcdGetWidth(void);
void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines);
#ifdef __cplusplus
}
#endif
#ifdef LCD_USE_GPIO #ifdef LCD_USE_GPIO
#define Set_CS palSetPad(LCD_CMD_PORT, LCD_CS); #define Set_CS palSetPad(LCD_CMD_PORT, LCD_CS);
#define Clr_CS palClearPad(LCD_CMD_PORT, LCD_CS); #define Clr_CS palClearPad(LCD_CMD_PORT, LCD_CS);
@ -16,6 +41,10 @@
#define Clr_RD palClearPad(LCD_CMD_PORT, LCD_RD); #define Clr_RD palClearPad(LCD_CMD_PORT, LCD_RD);
#endif #endif
#ifdef LCD_USE_SPI
/* TODO */
#endif
#ifdef LCD_USE_FSMC #ifdef LCD_USE_FSMC
/* LCD Registers */ /* LCD Registers */
#define R0 0x00 #define R0 0x00
@ -128,30 +157,6 @@
#define R229 0xE5 #define R229 0xE5
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
void lld_lcdInit(void);
void lld_lcdWriteStreamStart(void);
void lld_lcdWriteStreamStop(void);
void lld_lcdWriteStream(uint16_t *buffer, uint16_t size);
void lld_lcdSetCursor(uint16_t x, uint16_t y);
void lld_lcdSetOrientation(uint8_t newOrientation);
void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void lld_lcdClear(uint16_t color);
void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color);
void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
uint16_t lld_lcdGetOrientation(void);
uint16_t lld_lcdGetHeight(void);
uint16_t lld_lcdGetWidth(void);
void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines);
#ifdef __cplusplus
}
#endif
#endif #endif
#endif #endif

8
glcd.c
View file

@ -8,8 +8,8 @@ uint16_t lcd_width, lcd_height;
void lcdInit(GLCDDriver *glcdp) { void lcdInit(GLCDDriver *glcdp) {
lld_lcdInit(); lld_lcdInit();
lcd_width = SCREEN_WIDTH; lcd_width = lcdGetWidth();
lcd_height = SCREEN_HEIGHT; lcd_height = lcdGetHeight();
lcdSetOrientation(portrait); lcdSetOrientation(portrait);
} }
@ -30,6 +30,10 @@ static void lcdSetCursor(uint16_t x, uint16_t y) {
lld_lcdSetCursor(x, y); lld_lcdSetCursor(x, y);
} }
void lcdSetPowerMode(uint8_t powerMode) {
lld_lcdSetPowerMode(powerMode);
}
void lcdSetOrientation(uint8_t newOrientation) { void lcdSetOrientation(uint8_t newOrientation) {
lld_lcdSetOrientation(newOrientation); lld_lcdSetOrientation(newOrientation);
} }

5
glcd.h
View file

@ -12,9 +12,6 @@
#include "ssd1289_lld.h" #include "ssd1289_lld.h"
#include "s6d1121_lld.h" #include "s6d1121_lld.h"
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
#define PORTRAIT (lcdGetOrientation() == portrait || lcdGetOrientation() == portraitInv) #define PORTRAIT (lcdGetOrientation() == portrait || lcdGetOrientation() == portraitInv)
#define LANDSCAPE (lcdGetOrientation() == landscape || lcdGetOrientation() == landscapeInv) #define LANDSCAPE (lcdGetOrientation() == landscape || lcdGetOrientation() == landscapeInv)
@ -36,6 +33,7 @@
enum orientation {portrait, landscape, portraitInv, landscapeInv}; enum orientation {portrait, landscape, portraitInv, landscapeInv};
enum filled {frame, filled}; enum filled {frame, filled};
enum transparency {solid, transparent}; enum transparency {solid, transparent};
enum powermode {powerOff, powerOn, sleepOn, sleepOff};
typedef const uint8_t* font_t; typedef const uint8_t* font_t;
@ -62,6 +60,7 @@ void lcdSetOrientation(uint8_t newOrientation);
void lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); void lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); void lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
void lcdWriteArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t *buffer, size_t n); void lcdWriteArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t *buffer, size_t n);
void lcdSetPowerMode(uint8_t powerMode);
/* Drawing functions */ /* Drawing functions */
void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t point); void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t point);

20
graph.c
View file

@ -1,26 +1,26 @@
#include "glcd.h" #include "glcd.h"
#define GRID_X 20
#define GRID_Y 20
#define MARKSIZE 5 // half #define MARKSIZE 5 // half
static uint16_t x, y; // origins in graph static uint16_t x, y; // origins in graph
static uint16_t grid_X, grid_Y; //grids
void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t gridX, uint16_t gridY, uint16_t color) {
uint16_t i, length; uint16_t i, length;
volatile uint16_t off; volatile uint16_t off;
x = x0; x = x0;
y = y0; y = y0;
grid_X = gridX;
grid_Y = gridY;
// X-Axis // X-Axis
length = x1 - x0; length = x1 - x0;
lcdDrawLine(x0, y0, x1, y0, color); lcdDrawLine(x0, y0, x1, y0, color);
lcdDrawLine(x1, y0, x1-5, y0+5, color); lcdDrawLine(x1, y0, x1-5, y0+5, color);
lcdDrawLine(x1, y0, x1-5, y0-5, color); lcdDrawLine(x1, y0, x1-5, y0-5, color);
for(i=1; i<(length / GRID_X); i++) { for(i=1; i<(length / grid_X); i++) {
off = x0 + i*GRID_X; off = x0 + i * grid_X;
lcdDrawLine(off, y0-MARKSIZE, off, y0+MARKSIZE, color); lcdDrawLine(off, y0-MARKSIZE, off, y0+MARKSIZE, color);
} }
@ -29,20 +29,20 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_
lcdDrawLine(x0, y0, x0, y1, color); lcdDrawLine(x0, y0, x0, y1, color);
lcdDrawLine(x0, y1, x0-5, y1+5, color); lcdDrawLine(x0, y1, x0-5, y1+5, color);
lcdDrawLine(x0, y1, x0+5, y1+5, color); lcdDrawLine(x0, y1, x0+5, y1+5, color);
for(i=1; i<(length / GRID_Y); i++) { for(i=1; i<(length / grid_Y); i++) {
off = x0 + i*GRID_Y; off = y0 + i * grid_Y;
lcdDrawLine(x0-MARKSIZE, off, x0+MARKSIZE, off, color); lcdDrawLine(x0-MARKSIZE, off, x0+MARKSIZE, off, color);
} }
} }
void graphDrawDots(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t color) { void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color) {
uint16_t i; uint16_t i;
for(i = 0; i < entries; i++) for(i = 0; i < entries; i++)
lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, color); lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, color);
} }
void graphDrawNet(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor) { void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor) {
uint16_t i; uint16_t i;
for(i = 0; i < entries; ++i) for(i = 0; i < entries; ++i)

View file

@ -11,11 +11,12 @@ extern "C" {
* *
* param: * param:
* - x0, y0, x1, y1: location of arrows * - x0, y0, x1, y1: location of arrows
* - gridX, gridY: grid size in X and Y direction
* - color: color of arrows * - color: color of arrows
* *
* return: none * return: none
*/ */
void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t gridX, uint16_t gridY, uint16_t color);
/* /*
* Description: does draw coordinates into graph as dots * Description: does draw coordinates into graph as dots
@ -28,7 +29,7 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_
* *
* return: none * return: none
*/ */
void graphDrawDots(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t color); void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color);
/* /*
* Description: does draw coordinates into graph connected by lines * Description: does draw coordinates into graph connected by lines
@ -42,7 +43,7 @@ void graphDrawDots(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16
* *
* return: none * return: none
*/ */
void graphDrawNet(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor); void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor);
#ifdef __cplusplus #ifdef __cplusplus
} }

280
gui.c
View file

@ -1,109 +1,225 @@
#include "ch.h"
#include "hal.h"
#include "gui.h" #include "gui.h"
#include "glcd.h"
#include "touchpad.h"
static struct guiNode_t *firstGUI = NULL;
static uint8_t addElement(struct guiNode_t *newNode) {
struct guiNode_t *new;
if(firstGUI == NULL) {
firstGUI = chHeapAlloc(NULL, sizeof(struct guiNode_t));
if(firstGUI == NULL)
return 0;
*firstGUI = *newNode;
firstGUI->next = NULL;
} else {
new = firstGUI;
while(new->next != NULL)
new = new->next;
new->next = chHeapAlloc(NULL, sizeof(struct guiNode_t));
if(new->next == NULL)
return 0;
new = new->next;
*new = *newNode;
new->next = NULL;
}
return 1;
}
static uint8_t deleteElement(char *label) {
struct guiNode_t *pointer, *pointer1;
if(firstGUI != NULL) {
if(strcmp(firstGUI->label, label) == 0) {
pointer = firstGUI->next;
chHeapFree(firstGUI);
firstGUI = pointer;
} else {
pointer = firstGUI;
while(pointer->next != NULL) {
pointer1 = pointer->next;
if(strcmp(firstGUI->label, label) == 0) {
pointer->next = pointer1->next;
chHeapFree(pointer1);
break;
}
pointer = pointer1;
}
}
return 1; // successful
}
return 0; // not successful
}
void guiPrintElements(BaseSequentialStream *chp) {
struct guiNode_t *pointer = firstGUI;
chprintf(chp, "\r\n\nguiNodes:\r\n\n");
while(pointer != NULL) {
chprintf(chp, "x0: %d\r\n", pointer->x0);
chprintf(chp, "y0: %d\r\n", pointer->y0);
chprintf(chp, "x1: %d\r\n", pointer->x1);
chprintf(chp, "y1: %d\r\n", pointer->y1);
chprintf(chp, "label: %s\r\n", pointer->label);
chprintf(chp, "active: %d\r\n", *(pointer->active));
chprintf(chp, "state: %d\r\n", *(pointer->state));
chprintf(chp, "*next: 0x%x\r\n", pointer->next);
chprintf(chp, "\r\n\n");
pointer = pointer->next;
}
}
static void guiThread(const uint16_t interval) {
uint16_t x, y; uint16_t x, y;
unsigned char buffer[32]; struct guiNode_t *node;
static void TouchPadThread(uint16_t updateInterval) {
chRegSetThreadName("GUI"); chRegSetThreadName("GUI");
while(TRUE) { while(TRUE) {
for(node = firstGUI; node; node = node->next) {
// check if GUI element is active
if(*(node->active) == active) {
x = tpReadX(); x = tpReadX();
y = tpReadY(); y = tpReadY();
chThdSleepMilliseconds(updateInterval); // we got a button
} if(node->type == button) {
} if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1)
*(node->state) = 1;
static void buttonThread(struct button_t *a) {
uint16_t x0, y0, x1, y1;
x0 = a->x0;
y0 = a->y0;
x1 = a->x1;
y1 = a->y1;
while(TRUE) {
if(x >= x0 && x <= x1 && y >= y0 && y <= y1)
*(a->state) = 1;
else else
*(a->state) = 0; *(node->state) = 0;
} else {
*(node->state) = 0;
}
chThdSleepMilliseconds(a->interval); // we got a slider
if(node->type == slider) {
}
// we got a wheel
if(node->type == wheel) {
}
// we got a keymatrix
if(node->type == keymatrix) {
}
} }
} }
static void barThread(struct bar_t *a) { chThdSleepMilliseconds(interval);
uint16_t percent = 0, value = 0, value_old = 0;
while(TRUE) {
percent = *(a->percent);
if(percent > 100)
percent = 100;
if(a->orientation == horizontal) {
value = ((((a->x1)-(a->x0)) * percent) / 100);
if(value_old > value || value == 0)
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
else
lcdDrawRect(a->x0+1, a->y0+1, a->x0+value, a->y1, filled, a->valueColor);
} else if(a->orientation == vertical) {
value = ((((a->y1)-(a->y0)) * percent) / 100);
if(value_old > value || value == 0)
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
else
lcdDrawRect(a->x0+1, a->y0+1, a->x1, a->y0+value, filled, a->valueColor);
}
value_old = value;
chThdSleepMilliseconds(a->interval);
} }
} }
void guiInit(uint16_t updateInterval) { Thread *guiInit(uint16_t interval, tprio_t priority) {
Thread *tp = NULL;
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval);
}
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *state) {
struct button_t *button;
Thread *tp = NULL; Thread *tp = NULL;
button = chHeapAlloc(NULL, sizeof(struct button_t)); tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), priority, guiThread, interval);
button->x0 = x0;
button->y0 = y0; return tp;
button->x1 = x1; }
button->y1 = y1;
button->state = state; uint8_t guiDeleteElement(char *label) {
button->interval = interval; return deleteElement(label);
}
uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t shadow, char *label, uint8_t *active, uint8_t *state) {
struct guiNode_t *newNode;
uint16_t i;
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
if(newNode == NULL)
return 0;
newNode->type = button;
newNode->label = label;
newNode->x0 = x0;
newNode->y0 = y0;
newNode->x1 = x1;
newNode->y1 = y1;
newNode->label = str;
newNode->active = active;
newNode->state = state;
if(addElement(newNode) != 1)
return 0;
lcdDrawRectString(x0, y0, x1, y1, str, font, fontColor, buttonColor); lcdDrawRectString(x0, y0, x1, y1, str, font, fontColor, buttonColor);
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, buttonThread, button);
return tp; if(shadow != 0) {
for(i = 0; i < shadow; i++) {
lcdDrawLine(x0+shadow, y1+i, x1+shadow-1, y1+i, Black);
lcdDrawLine(x1+i, y0+shadow, x1+i, y1+shadow-1, Black);
}
} }
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint16_t *percent) { chHeapFree(newNode);
struct bar_t *bar;
Thread *tp = NULL;
bar = chHeapAlloc(NULL, sizeof(struct bar_t)); return 1;
bar->x0 = x0;
bar->y0 = y0;
bar->x1 = x1;
bar->y1 = y1;
bar->orientation = orientation;
bar->frameColor = frameColor;
bar->bkColor = bkColor;
bar->valueColor = valueColor;
bar->percent = percent;
bar->interval = interval;
lcdDrawRect(x0, y0, x1, y1, frame, frameColor);
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, barThread, bar);
return tp;
} }
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
struct guiNode_t *newNode;
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
if(newNode == NULL)
return 0;
newNode->type = slider;
newNode->type = label;
newNode->x0 = x0;
newNode->y0 = y0;
newNode->x1 = x1;
newNode->y1 = y1;
newNode->state = value;
newNode->active = active;
newNode->orientation = orientation;
if(addElement(newNode) != 1)
return 0;
// lcdDraw functions
chHeapFree(newNode);
return 1;
}
uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
struct guiNode_t *newNode;
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
if(newNode == NULL)
return 0;
newNode->type = wheel;
newNode->label = label;
newNode->x0 = x0;
newNode->y0 = y0;
newNode->r1 = radius1;
newNode->r2 = radius2;
newNode->active = active;
newNode->state = value;
if(addElement(newNode) != 1)
return 0;
// lcdDraw functions
chHeapFree(newNode);
return 1;
}

83
gui.h
View file

@ -1,7 +1,10 @@
#ifndef GUI_H #ifndef GUI_H
#define GUI_H #define GUI_H
#include "ch.h"
#include "hal.h"
#include "glcd.h" #include "glcd.h"
#include "touchpad.h"
struct button_t { struct button_t {
uint16_t x0; uint16_t x0;
@ -12,70 +15,78 @@ struct button_t {
uint16_t interval; uint16_t interval;
}; };
struct bar_t { static struct guiNode_t {
uint8_t type;
uint16_t x0; uint16_t x0;
uint16_t y0; uint16_t y0;
uint16_t x1; uint16_t x1;
uint16_t y1; uint16_t y1;
uint16_t orientation; uint16_t r1;
uint16_t frameColor; uint16_t r2;
uint16_t bkColor; uint8_t orientation;
uint16_t valueColor; uint8_t *active;
uint16_t interval; uint8_t *state;
uint8_t *percent; char *label;
struct guiNode_t *next;
}; };
enum {horizontal, vertical};
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
enum {button, slider, wheel, keymatrix};
enum {horizontal, vertical};
enum {inactive, active};
/* /*
* Description: starts main GUI thread which keeps X and Y coordinates of touchpad updated for guiDraw() threads * Description: creates the GUI thread
* *
* param: * param: - interval: thread sleep in milliseconds after each GUI element update
* - updateInterval: update interval in milliseconds until next coordinates read-out * - priority: priority of the thread
*
* return: pointer to created thread
*/
Thread *guiInit(uint16_t interval, tprio_t priority);
/*
* Description: prints all GUI elements structs (linked list)
*
* param: - chp: pointer to output stream
* *
* return: none * return: none
*/ */
void guiInit(uint16_t updateIntervl);
void guiPrintElements(BaseSequentialStream *chp);
/* /*
* Description: draws button and creates thread which keeps pressed/unpressed state up-to-date * Description: deletes a GUI element from the linked list
* *
* param: * param: - label: label of the element (parameter of each guiDrawXXX function)
* - x0, y0, x1, y1: coordinates where button gets drawn
* - str: string written centered into button
* - fontColor: color of string
* - buttonColor: color of button
* - interval: interval in ms which updates state
* - state: pointer to variable which keeps state (1 = pressed, 0 = unpressed)
* *
* return: pointer to created thread * return: 1 if successful, 0 otherwise
*/ */
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *state); uint8_t guiDeleteElement(char *label);
/* /*
* Description: draws a bar graph and updates it's value * Description: draws a button on the screen and keeps it's state up to date
* *
* param: * param: - x0, y0, x1, y1: start and end coordinates of the button's rectangle
* - x0, y0, x1, y1: coordinates where bar graph gets drawn * - str: string that gets drawn into the rectangle - button's lable
* - orientation: horizontal or vertical * - fontColor: color of the lable
* - frameColor: color of the frame * - buttonColor: color of the rectangle
* - bkColor: color of piece inside bar with is not set * - shadow: draws a black shadow with N pixels size if != 0
* - valueColor: color of value that will be drawn into bar * - active: pass pointer to variable which holds the state 'active' or 'inactive'
* - interval: interval in ms which updates percentage * - state: pass pointer to variable whcih will keep the state of the button (pressed / unpressed)'
* - percent: pointer value from 0 to 100 percent
* *
* return : pointer to created thread * return: 1 if button successfully created
*/ */
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint16_t *percent); uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t shadow, char *label, uint8_t *active, uint8_t *state);
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

46
readme
View file

@ -1,47 +1,13 @@
Chibios LCD Driver please read the wiki pages to this project carefully, before you ask any questions:
### checkout Driver code into ext/ http://chibios.org/dokuwiki/doku.php?id=chibios:community
cd chibios/ext
git clone https://github.com/tectu/Chibios-LCD-Driver lcd
### Edit boardfiles:
add the following to your board.h file, matching to your pinconfig:
#define TP_PORT GPIOC
#define TP_IRQ 4
#define TP_CS 6
#define LCD_DATA_PORT GPIOE
#define LCD_CMD_PORT GPIOD
#define LCD_CS 12
#define LCD_RS 13
#define LCD_WR 14
#define LCD_RD 15
### Edit Makefile: ### Maintainer & Contributors
include lcd.mk: Contributors: - Badger
include $(CHIBIOS)/ext/lcd/lcd.mk - Abhishek
Add $(LCDSRC) to CSRC: Maintainer: - Joel Bodenmann aka Tectu <joel@unormal.org>
CSRC = $(PORTSRC) \
$(KERNSRC) \
$(TESTSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
$(FATFSSRC) \
$(LCDSRC) \
$(CHIBIOS)/os/various/evtimer.c \
$(CHIBIOS)/os/various/syscalls.c
Add $(LCDINC) to INCDIR:
INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
$(FATFSINC) \
$(LCDINC) \
$(CHIBIOS)/os/various ../common
### Use
1. include header files wherever you need it.
2. select the controller type you want to use in glcdconf.h