merge upstream changes

ugfx_release_2.6
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 100755
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;
}

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)];
#ifdef LCD_USE_GPIO
static __inline void lld_lcdWriteIndex(uint16_t index) {
Clr_RS;
Set_RD;
palWritePort(LCD_DATA_PORT, index);
lld_lcdWriteGPIO(index);
Clr_WR;
Set_WR;
@ -22,7 +23,7 @@ static __inline void lld_lcdWriteIndex(uint16_t index) {
static __inline void lld_lcdWriteData(uint16_t data) {
Set_RS;
palWritePort(LCD_DATA_PORT, data);
lld_lcdWriteGPIO(data);
Clr_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) {
Clr_CS;
lld_lcdWriteIndex(lcdReg);
lld_lcdWriteData(lcdRegValue);
Set_CS;
}
@ -42,16 +45,7 @@ static __inline uint16_t lld_lcdReadData(void) {
Set_WR;
Clr_RD;
// 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;
value = lld_lcdReadGPIO();
Set_RD;
@ -72,6 +66,7 @@ static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
__inline void lld_lcdWriteStreamStart(void) {
Clr_CS;
lld_lcdWriteIndex(0x0022);
}
@ -85,7 +80,7 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
Set_RS;
for(i = 0; i < size; i++) {
palWritePort(LCD_DATA_PORT, buffer[i]);
lld_lcdWriteGPIO(buffer[i]);
Clr_WR;
Set_WR;
}
@ -112,6 +107,10 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
#endif
#ifdef LCD_USE_SPI
/* TODO */
#endif
#ifdef LCD_USE_FSMC
#define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
@ -173,15 +172,30 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
}
#endif
#ifdef LCD_USE_SPI
/* TODO! */
#endif
static __inline void lcdDelay(uint16_t us) {
static __inline void lld_lcdDelay(uint16_t 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) {
/* Reg 0x004E is an 8 bit value
@ -334,47 +348,47 @@ void lld_lcdInit(void) {
#endif
DeviceCode = lld_lcdReadReg(0x0000);
lld_lcdWriteReg(0x0000,0x0001); lcdDelay(5);
lld_lcdWriteReg(0x0003,0xA8A4); lcdDelay(5);
lld_lcdWriteReg(0x000C,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x000D,0x080C); lcdDelay(5);
lld_lcdWriteReg(0x000E,0x2B00); lcdDelay(5);
lld_lcdWriteReg(0x001E,0x00B0); lcdDelay(5);
lld_lcdWriteReg(0x0001,0x2B3F); lcdDelay(5);
lld_lcdWriteReg(0x0002,0x0600); lcdDelay(5);
lld_lcdWriteReg(0x0010,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0011,0x6070); lcdDelay(5);
lld_lcdWriteReg(0x0005,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0006,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0016,0xEF1C); lcdDelay(5);
lld_lcdWriteReg(0x0017,0x0003); lcdDelay(5);
lld_lcdWriteReg(0x0007,0x0133); lcdDelay(5);
lld_lcdWriteReg(0x000B,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x000F,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0041,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0042,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0048,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0049,0x013F); lcdDelay(5);
lld_lcdWriteReg(0x004A,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x004B,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0044,0xEF00); lcdDelay(5);
lld_lcdWriteReg(0x0045,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0046,0x013F); lcdDelay(5);
lld_lcdWriteReg(0x0030,0x0707); lcdDelay(5);
lld_lcdWriteReg(0x0031,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0032,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0033,0x0502); lcdDelay(5);
lld_lcdWriteReg(0x0034,0x0507); lcdDelay(5);
lld_lcdWriteReg(0x0035,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0036,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0037,0x0502); lcdDelay(5);
lld_lcdWriteReg(0x003A,0x0302); lcdDelay(5);
lld_lcdWriteReg(0x003B,0x0302); lcdDelay(5);
lld_lcdWriteReg(0x0023,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0024,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0025,0x8000); lcdDelay(5);
lld_lcdWriteReg(0x004f,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x004e,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0000,0x0001); lld_lcdDelay(5);
lld_lcdWriteReg(0x0003,0xA8A4); lld_lcdDelay(5);
lld_lcdWriteReg(0x000C,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x000D,0x080C); lld_lcdDelay(5);
lld_lcdWriteReg(0x000E,0x2B00); lld_lcdDelay(5);
lld_lcdWriteReg(0x001E,0x00B0); lld_lcdDelay(5);
lld_lcdWriteReg(0x0001,0x2B3F); lld_lcdDelay(5);
lld_lcdWriteReg(0x0002,0x0600); lld_lcdDelay(5);
lld_lcdWriteReg(0x0010,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0011,0x6070); lld_lcdDelay(5);
lld_lcdWriteReg(0x0005,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0006,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0016,0xEF1C); lld_lcdDelay(5);
lld_lcdWriteReg(0x0017,0x0003); lld_lcdDelay(5);
lld_lcdWriteReg(0x0007,0x0133); lld_lcdDelay(5);
lld_lcdWriteReg(0x000B,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x000F,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0041,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0042,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0048,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0049,0x013F); lld_lcdDelay(5);
lld_lcdWriteReg(0x004A,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x004B,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0044,0xEF00); lld_lcdDelay(5);
lld_lcdWriteReg(0x0045,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0046,0x013F); lld_lcdDelay(5);
lld_lcdWriteReg(0x0030,0x0707); lld_lcdDelay(5);
lld_lcdWriteReg(0x0031,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0032,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0033,0x0502); lld_lcdDelay(5);
lld_lcdWriteReg(0x0034,0x0507); lld_lcdDelay(5);
lld_lcdWriteReg(0x0035,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0036,0x0204); lld_lcdDelay(5);
lld_lcdWriteReg(0x0037,0x0502); lld_lcdDelay(5);
lld_lcdWriteReg(0x003A,0x0302); lld_lcdDelay(5);
lld_lcdWriteReg(0x003B,0x0302); lld_lcdDelay(5);
lld_lcdWriteReg(0x0023,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0024,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x0025,0x8000); lld_lcdDelay(5);
lld_lcdWriteReg(0x004f,0x0000); lld_lcdDelay(5);
lld_lcdWriteReg(0x004e,0x0000); lld_lcdDelay(5);
}
uint16_t lld_lcdGetOrientation(void) {

View File

@ -5,129 +5,6 @@
#ifdef LCD_USE_SSD1289
#ifdef LCD_USE_GPIO
#define Set_CS palSetPad(LCD_CMD_PORT, LCD_CS);
#define Clr_CS palClearPad(LCD_CMD_PORT, LCD_CS);
#define Set_RS palSetPad(LCD_CMD_PORT, LCD_RS);
#define Clr_RS palClearPad(LCD_CMD_PORT, LCD_RS);
#define Set_WR palSetPad(LCD_CMD_PORT, LCD_WR);
#define Clr_WR palClearPad(LCD_CMD_PORT, LCD_WR);
#define Set_RD palSetPad(LCD_CMD_PORT, LCD_RD);
#define Clr_RD palClearPad(LCD_CMD_PORT, LCD_RD);
#endif
#ifdef LCD_USE_FSMC
/* LCD Registers */
#define R0 0x00
#define R1 0x01
#define R2 0x02
#define R3 0x03
#define R4 0x04
#define R5 0x05
#define R6 0x06
#define R7 0x07
#define R8 0x08
#define R9 0x09
#define R10 0x0A
#define R12 0x0C
#define R13 0x0D
#define R14 0x0E
#define R15 0x0F
#define R16 0x10
#define R17 0x11
#define R18 0x12
#define R19 0x13
#define R20 0x14
#define R21 0x15
#define R22 0x16
#define R23 0x17
#define R24 0x18
#define R25 0x19
#define R26 0x1A
#define R27 0x1B
#define R28 0x1C
#define R29 0x1D
#define R30 0x1E
#define R31 0x1F
#define R32 0x20
#define R33 0x21
#define R34 0x22
#define R36 0x24
#define R37 0x25
#define R40 0x28
#define R41 0x29
#define R43 0x2B
#define R45 0x2D
#define R48 0x30
#define R49 0x31
#define R50 0x32
#define R51 0x33
#define R52 0x34
#define R53 0x35
#define R54 0x36
#define R55 0x37
#define R56 0x38
#define R57 0x39
#define R59 0x3B
#define R60 0x3C
#define R61 0x3D
#define R62 0x3E
#define R63 0x3F
#define R64 0x40
#define R65 0x41
#define R66 0x42
#define R67 0x43
#define R68 0x44
#define R69 0x45
#define R70 0x46
#define R71 0x47
#define R72 0x48
#define R73 0x49
#define R74 0x4A
#define R75 0x4B
#define R76 0x4C
#define R77 0x4D
#define R78 0x4E
#define R79 0x4F
#define R80 0x50
#define R81 0x51
#define R82 0x52
#define R83 0x53
#define R96 0x60
#define R97 0x61
#define R106 0x6A
#define R118 0x76
#define R128 0x80
#define R129 0x81
#define R130 0x82
#define R131 0x83
#define R132 0x84
#define R133 0x85
#define R134 0x86
#define R135 0x87
#define R136 0x88
#define R137 0x89
#define R139 0x8B
#define R140 0x8C
#define R141 0x8D
#define R143 0x8F
#define R144 0x90
#define R145 0x91
#define R146 0x92
#define R147 0x93
#define R148 0x94
#define R149 0x95
#define R150 0x96
#define R151 0x97
#define R152 0x98
#define R153 0x99
#define R154 0x9A
#define R157 0x9D
#define R192 0xC0
#define R193 0xC1
#define R229 0xE5
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -142,6 +19,7 @@ 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);
@ -152,6 +30,133 @@ void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, i
}
#endif
#ifdef LCD_USE_GPIO
#define Set_CS palSetPad(LCD_CMD_PORT, LCD_CS);
#define Clr_CS palClearPad(LCD_CMD_PORT, LCD_CS);
#define Set_RS palSetPad(LCD_CMD_PORT, LCD_RS);
#define Clr_RS palClearPad(LCD_CMD_PORT, LCD_RS);
#define Set_WR palSetPad(LCD_CMD_PORT, LCD_WR);
#define Clr_WR palClearPad(LCD_CMD_PORT, LCD_WR);
#define Set_RD palSetPad(LCD_CMD_PORT, LCD_RD);
#define Clr_RD palClearPad(LCD_CMD_PORT, LCD_RD);
#endif
#ifdef LCD_USE_SPI
/* TODO */
#endif
#ifdef LCD_USE_FSMC
/* LCD Registers */
#define R0 0x00
#define R1 0x01
#define R2 0x02
#define R3 0x03
#define R4 0x04
#define R5 0x05
#define R6 0x06
#define R7 0x07
#define R8 0x08
#define R9 0x09
#define R10 0x0A
#define R12 0x0C
#define R13 0x0D
#define R14 0x0E
#define R15 0x0F
#define R16 0x10
#define R17 0x11
#define R18 0x12
#define R19 0x13
#define R20 0x14
#define R21 0x15
#define R22 0x16
#define R23 0x17
#define R24 0x18
#define R25 0x19
#define R26 0x1A
#define R27 0x1B
#define R28 0x1C
#define R29 0x1D
#define R30 0x1E
#define R31 0x1F
#define R32 0x20
#define R33 0x21
#define R34 0x22
#define R36 0x24
#define R37 0x25
#define R40 0x28
#define R41 0x29
#define R43 0x2B
#define R45 0x2D
#define R48 0x30
#define R49 0x31
#define R50 0x32
#define R51 0x33
#define R52 0x34
#define R53 0x35
#define R54 0x36
#define R55 0x37
#define R56 0x38
#define R57 0x39
#define R59 0x3B
#define R60 0x3C
#define R61 0x3D
#define R62 0x3E
#define R63 0x3F
#define R64 0x40
#define R65 0x41
#define R66 0x42
#define R67 0x43
#define R68 0x44
#define R69 0x45
#define R70 0x46
#define R71 0x47
#define R72 0x48
#define R73 0x49
#define R74 0x4A
#define R75 0x4B
#define R76 0x4C
#define R77 0x4D
#define R78 0x4E
#define R79 0x4F
#define R80 0x50
#define R81 0x51
#define R82 0x52
#define R83 0x53
#define R96 0x60
#define R97 0x61
#define R106 0x6A
#define R118 0x76
#define R128 0x80
#define R129 0x81
#define R130 0x82
#define R131 0x83
#define R132 0x84
#define R133 0x85
#define R134 0x86
#define R135 0x87
#define R136 0x88
#define R137 0x89
#define R139 0x8B
#define R140 0x8C
#define R141 0x8D
#define R143 0x8F
#define R144 0x90
#define R145 0x91
#define R146 0x92
#define R147 0x93
#define R148 0x94
#define R149 0x95
#define R150 0x96
#define R151 0x97
#define R152 0x98
#define R153 0x99
#define R154 0x9A
#define R157 0x9D
#define R192 0xC0
#define R193 0xC1
#define R229 0xE5
#endif
#endif
#endif

18
glcd.c
View File

@ -8,8 +8,8 @@ uint16_t lcd_width, lcd_height;
void lcdInit(GLCDDriver *glcdp) {
lld_lcdInit();
lcd_width = SCREEN_WIDTH;
lcd_height = SCREEN_HEIGHT;
lcd_width = lcdGetWidth();
lcd_height = lcdGetHeight();
lcdSetOrientation(portrait);
}
@ -30,6 +30,10 @@ static void lcdSetCursor(uint16_t x, uint16_t y) {
lld_lcdSetCursor(x, y);
}
void lcdSetPowerMode(uint8_t powerMode) {
lld_lcdSetPowerMode(powerMode);
}
void lcdSetOrientation(uint8_t newOrientation) {
lld_lcdSetOrientation(newOrientation);
}
@ -307,11 +311,11 @@ void lcdDrawCircle(uint16_t x, uint16_t y, uint16_t radius, uint8_t filled, uint
lcdDrawPixel(x-b, y-a, color);
}
if(P < 0)
P += 3 + 2*a++;
else
P += 5 + 2*(a++ - b--);
} while(a <= b);
if(P < 0)
P += 3 + 2*a++;
else
P += 5 + 2*(a++ - b--);
} while(a <= b);
}
void lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines) {

5
glcd.h
View File

@ -12,9 +12,6 @@
#include "ssd1289_lld.h"
#include "s6d1121_lld.h"
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
#define PORTRAIT (lcdGetOrientation() == portrait || lcdGetOrientation() == portraitInv)
#define LANDSCAPE (lcdGetOrientation() == landscape || lcdGetOrientation() == landscapeInv)
@ -36,6 +33,7 @@
enum orientation {portrait, landscape, portraitInv, landscapeInv};
enum filled {frame, filled};
enum transparency {solid, transparent};
enum powermode {powerOff, powerOn, sleepOn, sleepOff};
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 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 lcdSetPowerMode(uint8_t powerMode);
/* Drawing functions */
void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t point);

26
graph.c
View File

@ -1,26 +1,26 @@
#include "glcd.h"
#define GRID_X 20
#define GRID_Y 20
#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;
volatile uint16_t off;
x = x0;
y = y0;
grid_X = gridX;
grid_Y = gridY;
// X-Axis
length = x1 - x0;
lcdDrawLine(x0, y0, x1, y0, 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++) {
off = x0 + i*GRID_X;
for(i=1; i<(length / grid_X); i++) {
off = x0 + i * grid_X;
lcdDrawLine(off, y0-MARKSIZE, off, y0+MARKSIZE, color);
}
@ -29,25 +29,25 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_
lcdDrawLine(x0, y0, x0, y1, 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++) {
off = x0 + i*GRID_Y;
for(i=1; i<(length / grid_Y); i++) {
off = y0 + i * grid_Y;
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;
for(i=0; i<entries; i++)
for(i = 0; i < entries; i++)
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;
for(i = 0; i < entries; ++i)
lcdDrawLine(coord[i-1][0]+x, y-coord[i-1][1], coord[i][0]+x, y-coord[i][1], lineColor);
for(i=0; i<entries; ++i)
for(i = 0; i < entries; ++i)
if(radius != 0)
lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, dotColor);
}

View File

@ -11,11 +11,12 @@ extern "C" {
*
* param:
* - x0, y0, x1, y1: location of arrows
* - gridX, gridY: grid size in X and Y direction
* - color: color of arrows
*
* 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
@ -28,7 +29,7 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_
*
* 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
@ -42,7 +43,7 @@ void graphDrawDots(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16
*
* 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
}

274
gui.c
View File

@ -1,109 +1,225 @@
#include "ch.h"
#include "hal.h"
#include "gui.h"
#include "glcd.h"
#include "touchpad.h"
uint16_t x, y;
unsigned char buffer[32];
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;
struct guiNode_t *node;
static void TouchPadThread(uint16_t updateInterval) {
chRegSetThreadName("GUI");
while(TRUE) {
x = tpReadX();
y = tpReadY();
for(node = firstGUI; node; node = node->next) {
// check if GUI element is active
if(*(node->active) == active) {
x = tpReadX();
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;
else
*(node->state) = 0;
} else {
*(node->state) = 0;
}
static void buttonThread(struct button_t *a) {
uint16_t x0, y0, x1, y1;
// we got a slider
if(node->type == slider) {
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
*(a->state) = 0;
// we got a wheel
if(node->type == wheel) {
chThdSleepMilliseconds(a->interval);
}
}
}
static void barThread(struct bar_t *a) {
uint16_t percent = 0, value = 0, value_old = 0;
// we got a keymatrix
if(node->type == keymatrix) {
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);
chThdSleepMilliseconds(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);
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), priority, guiThread, interval);
return tp;
}
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;
uint8_t guiDeleteElement(char *label) {
return deleteElement(label);
}
button = chHeapAlloc(NULL, sizeof(struct button_t));
button->x0 = x0;
button->y0 = y0;
button->x1 = x1;
button->y1 = y1;
button->state = state;
button->interval = interval;
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);
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);
}
}
chHeapFree(newNode);
return 1;
}
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) {
struct bar_t *bar;
Thread *tp = NULL;
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;
bar = chHeapAlloc(NULL, sizeof(struct bar_t));
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;
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
if(newNode == NULL)
return 0;
lcdDrawRect(x0, y0, x1, y1, frame, frameColor);
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, barThread, bar);
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;
return tp;
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;
}

85
gui.h
View File

@ -1,7 +1,10 @@
#ifndef GUI_H
#define GUI_H
#include "ch.h"
#include "hal.h"
#include "glcd.h"
#include "touchpad.h"
struct button_t {
uint16_t x0;
@ -12,70 +15,78 @@ struct button_t {
uint16_t interval;
};
struct bar_t {
static struct guiNode_t {
uint8_t type;
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;
uint8_t *percent;
uint16_t r1;
uint16_t r2;
uint8_t orientation;
uint8_t *active;
uint8_t *state;
char *label;
struct guiNode_t *next;
};
enum {horizontal, vertical};
#ifdef __cplusplus
extern "C" {
#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:
* - updateInterval: update interval in milliseconds until next coordinates read-out
* param: - interval: thread sleep in milliseconds after each GUI element update
* - priority: priority of the thread
*
* return: none
* return: pointer to created thread
*/
void guiInit(uint16_t updateIntervl);
Thread *guiInit(uint16_t interval, tprio_t priority);
/*
* Description: draws button and creates thread which keeps pressed/unpressed state up-to-date
* Description: prints all GUI elements structs (linked list)
*
* param: - chp: pointer to output stream
*
* param:
* - 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: none
*/
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);
void guiPrintElements(BaseSequentialStream *chp);
/*
* Description: draws a bar graph and updates it's value
* Description: deletes a GUI element from the linked list
*
* param:
* - x0, y0, x1, y1: coordinates where bar graph gets drawn
* - orientation: horizontal or vertical
* - frameColor: color of the frame
* - bkColor: color of piece inside bar with is not set
* - valueColor: color of value that will be drawn into bar
* - interval: interval in ms which updates percentage
* - percent: pointer value from 0 to 100 percent
* param: - label: label of the element (parameter of each guiDrawXXX function)
*
* return : pointer to created thread
* return: 1 if successful, 0 otherwise
*/
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 guiDeleteElement(char *label);
/*
* Description: draws a button on the screen and keeps it's state up to date
*
* param: - x0, y0, x1, y1: start and end coordinates of the button's rectangle
* - str: string that gets drawn into the rectangle - button's lable
* - fontColor: color of the lable
* - buttonColor: color of the rectangle
* - shadow: draws a black shadow with N pixels size if != 0
* - active: pass pointer to variable which holds the state 'active' or 'inactive'
* - state: pass pointer to variable whcih will keep the state of the button (pressed / unpressed)'
*
* return: 1 if button successfully created
*/
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
}
#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/
cd chibios/ext
git clone https://github.com/tectu/Chibios-LCD-Driver lcd
http://chibios.org/dokuwiki/doku.php?id=chibios:community
### 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:
include lcd.mk:
include $(CHIBIOS)/ext/lcd/lcd.mk
### Maintainer & Contributors
Contributors: - Badger
- Abhishek
Add $(LCDSRC) to CSRC:
CSRC = $(PORTSRC) \
$(KERNSRC) \
$(TESTSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
$(FATFSSRC) \
$(LCDSRC) \
$(CHIBIOS)/os/various/evtimer.c \
$(CHIBIOS)/os/various/syscalls.c
Maintainer: - Joel Bodenmann aka Tectu <joel@unormal.org>
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