From 38b5410f2d47b327762a62a87fea477d172e7868 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 19 Jun 2012 23:26:30 +0200 Subject: cleanups --- drivers/lcd/ssd1289_lld.c | 10 +- drivers/lcd/ssd1289_lld.h | 250 +++++++++++++++++++++++----------------------- 2 files changed, 131 insertions(+), 129 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index ac4d050f..5382dd27 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -91,6 +91,10 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { #endif +#ifdef LCD_USE_SPI + /* TODO */ +#endif + #ifdef LCD_USE_FSMC #define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */ @@ -133,16 +137,10 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { } #endif -#ifdef LCD_USE_SPI -/* TODO! */ -#endif - static __inline void lcdDelay(uint16_t us) { chThdSleepMicroseconds(us); } - - void lld_lcdSetCursor(uint16_t x, uint16_t y) { if(PORTRAIT) { lld_lcdWriteReg(0x004e, x); diff --git a/drivers/lcd/ssd1289_lld.h b/drivers/lcd/ssd1289_lld.h index 3cedcc90..49e6d0f0 100644 --- a/drivers/lcd/ssd1289_lld.h +++ b/drivers/lcd/ssd1289_lld.h @@ -6,129 +6,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 @@ -152,6 +29,133 @@ uint16_t lld_lcdGetWidth(void); } #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 -- cgit v1.2.3 From b3fedc8b80bed89957c02eedfb5af336a8399a4e Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 20 Jun 2012 00:03:35 +0200 Subject: moved SCREEN_HEIGHT and SCREEN_WIDTH macros to glcdconf.h --- glcd.c | 4 ++-- glcd.h | 3 --- glcdconf.h | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/glcd.c b/glcd.c index df413154..52318a0c 100644 --- a/glcd.c +++ b/glcd.c @@ -11,8 +11,8 @@ const uint8_t* font; void lcdInit(void) { lld_lcdInit(); - lcd_width = SCREEN_WIDTH; - lcd_height = SCREEN_HEIGHT; + lcd_width = lcdGetWidth(); + lcd_height = lcdGetHeight(); lcdSetOrientation(portrait); lcdSetFontTransparency(transparent); diff --git a/glcd.h b/glcd.h index 222a7eb2..29f92f68 100644 --- a/glcd.h +++ b/glcd.h @@ -7,9 +7,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) diff --git a/glcdconf.h b/glcdconf.h index 657ee32d..b6445e93 100644 --- a/glcdconf.h +++ b/glcdconf.h @@ -1,6 +1,8 @@ #ifndef GLCDCONF_H #define GLCDCONF_H +#define SCREEN_WIDTH 240 +#define SCREEN_HEIGHT 320 /***** LCD CONTROLLER *****/ #define LCD_USE_SSD1289 -- cgit v1.2.3 From 6a2a70e8e68d999e5b8cea74ef49b37e8be3aeda Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 20 Jun 2012 00:17:10 +0200 Subject: added lcdSetPowerMode() --- drivers/lcd/ssd1289_lld.c | 97 +++++++++++++++++++++++++++-------------------- drivers/lcd/ssd1289_lld.h | 1 + glcd.c | 4 ++ glcd.h | 2 + 4 files changed, 62 insertions(+), 42 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index 5382dd27..cfacfb47 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -137,10 +137,23 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { } #endif -static __inline void lcdDelay(uint16_t us) { +static __inline void lld_lcdDelay(uint16_t us) { chThdSleepMicroseconds(us); } +void lld_lcdSetPowerMode(uint8_t powerMode) { + /* TODO */ + + switch(powerMode) { + case poweroff: + break; + case poweron: + break; + case standby: + break; + } +} + void lld_lcdSetCursor(uint16_t x, uint16_t y) { if(PORTRAIT) { lld_lcdWriteReg(0x004e, x); @@ -277,47 +290,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) { diff --git a/drivers/lcd/ssd1289_lld.h b/drivers/lcd/ssd1289_lld.h index 49e6d0f0..5462acd6 100644 --- a/drivers/lcd/ssd1289_lld.h +++ b/drivers/lcd/ssd1289_lld.h @@ -20,6 +20,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); diff --git a/glcd.c b/glcd.c index 52318a0c..ec89a8d4 100644 --- a/glcd.c +++ b/glcd.c @@ -35,6 +35,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); } diff --git a/glcd.h b/glcd.h index 29f92f68..0bf192a7 100644 --- a/glcd.h +++ b/glcd.h @@ -28,6 +28,7 @@ enum orientation {portrait, landscape, portraitInv, landscapeInv}; enum filled {frame, filled}; enum transparency {solid, transparent}; +enum powermode {poweroff, poweron, standby}; // For text rendering only extern uint16_t bgcolor, fgcolor; @@ -49,6 +50,7 @@ void lcdClear(uint16_t color); 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 lcdSetPowerMode(uint8_t powerMode); void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t point); void lcdDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); -- cgit v1.2.3 From 1445173ac6e562817fda8b3890689b1d07a05ceb Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 20 Jun 2012 13:51:48 +0200 Subject: graph does now take int instead of int16 arrays --- graph.c | 8 ++++---- graph.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/graph.c b/graph.c index 440f2507..a9d4a378 100644 --- a/graph.c +++ b/graph.c @@ -35,19 +35,19 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_ } } -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 Date: Wed, 20 Jun 2012 15:32:18 +0200 Subject: very dirty fix --- glcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/glcd.c b/glcd.c index b00fa698..36064df3 100644 --- a/glcd.c +++ b/glcd.c @@ -73,6 +73,7 @@ static const struct GLCDDriverVMT vmt = { uint16_t lcd_width, lcd_height; uint16_t bgcolor = White, fgcolor = Black; uint16_t cx = 0, cy = 0; +uint16_t cursor_x = 0, cursor_y = 0; static uint8_t tpText = 0; const uint8_t* font; @@ -272,6 +273,7 @@ size_t lcdPutString(const char *str) { void lcdMoveCursor(uint16_t x, uint16_t y, uint16_t color, uint16_t bkcolor) { cx = x; + cursor_x = x; cy = y; bgcolor = bkcolor; fgcolor = color; @@ -317,8 +319,7 @@ uint16_t lcdMeasureString(const char *str) { } void lcdLineBreak() { - // x=0 seems too much on the edge. So I keep it at 3 - cx = 3; + cx = cursor_x; cy += lcdGetCurFontHeight(); } -- cgit v1.2.3 From 83f22aaeb65b2cbff240313a851748d3e771e03d Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 20 Jun 2012 15:37:25 +0200 Subject: Revert "very dirty fix" This reverts commit 0a31b48c5ac0a706fb15a64d6c7ee1f49151cc0d. --- glcd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/glcd.c b/glcd.c index 36064df3..b00fa698 100644 --- a/glcd.c +++ b/glcd.c @@ -73,7 +73,6 @@ static const struct GLCDDriverVMT vmt = { uint16_t lcd_width, lcd_height; uint16_t bgcolor = White, fgcolor = Black; uint16_t cx = 0, cy = 0; -uint16_t cursor_x = 0, cursor_y = 0; static uint8_t tpText = 0; const uint8_t* font; @@ -273,7 +272,6 @@ size_t lcdPutString(const char *str) { void lcdMoveCursor(uint16_t x, uint16_t y, uint16_t color, uint16_t bkcolor) { cx = x; - cursor_x = x; cy = y; bgcolor = bkcolor; fgcolor = color; @@ -319,7 +317,8 @@ uint16_t lcdMeasureString(const char *str) { } void lcdLineBreak() { - cx = cursor_x; + // x=0 seems too much on the edge. So I keep it at 3 + cx = 3; cy += lcdGetCurFontHeight(); } -- cgit v1.2.3 From de71035ce4bab711d03514d3137b812f8634e405 Mon Sep 17 00:00:00 2001 From: Tectu Date: Sat, 23 Jun 2012 14:04:56 +0200 Subject: ssd1289 powermodes implemented (powerOn, powerOff, sleepOn, sleepOff) --- drivers/lcd/ssd1289_lld.c | 18 +++++++++++++----- glcd.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index cfacfb47..9f3303f9 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -142,14 +142,22 @@ static __inline void lld_lcdDelay(uint16_t us) { } void lld_lcdSetPowerMode(uint8_t powerMode) { - /* TODO */ - switch(powerMode) { - case poweroff: + 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 poweron: + case sleepOn: + lld_lcdWriteReg(0x0010, 0x0001); // enter sleep mode break; - case standby: + case sleepOff: + lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode break; } } diff --git a/glcd.h b/glcd.h index 99032b2e..8108b21f 100644 --- a/glcd.h +++ b/glcd.h @@ -28,7 +28,7 @@ enum orientation {portrait, landscape, portraitInv, landscapeInv}; enum filled {frame, filled}; enum transparency {solid, transparent}; -enum powermode {poweroff, poweron, standby}; +enum powermode {powerOff, powerOn, sleepOn, sleepOff}; // For text rendering only extern uint16_t bgcolor, fgcolor; -- cgit v1.2.3 From d2471ca6f3907256a5a74b58b5d263a76efe6ed6 Mon Sep 17 00:00:00 2001 From: Tectu Date: Sat, 23 Jun 2012 16:00:52 +0200 Subject: added power modes demo --- demos/powermodes/main.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 demos/powermodes/main.c diff --git a/demos/powermodes/main.c b/demos/powermodes/main.c new file mode 100755 index 00000000..5d71f60f --- /dev/null +++ b/demos/powermodes/main.c @@ -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; +} -- cgit v1.2.3 From 9aba8fad0abf52ccb78190bdf60462e8086fbb35 Mon Sep 17 00:00:00 2001 From: Tectu Date: Sat, 23 Jun 2012 17:50:06 +0200 Subject: added contributors to readme --- readme | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/readme b/readme index 7bee9e10..7e926841 100644 --- a/readme +++ b/readme @@ -45,3 +45,10 @@ Add $(LCDINC) to INCDIR: 2. select the controller type you want to use in glcdconf.h +### Maintainer & Contributors +Contributors: - Badger + - Abhishek + +Maintainer: - Joel Bodenmann aka Tectu + + -- cgit v1.2.3 From 17feb4361e02ceefb3266063ceb04e714895ddb6 Mon Sep 17 00:00:00 2001 From: Tectu Date: Sat, 23 Jun 2012 21:15:31 +0200 Subject: graphDrawSystem() does take now grid-X and grid-Y values --- graph.c | 18 +++++++++--------- graph.h | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/graph.c b/graph.c index a9d4a378..d90eaa95 100644 --- a/graph.c +++ b/graph.c @@ -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,8 +29,8 @@ 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 = x0 + i * grid_Y; lcdDrawLine(x0-MARKSIZE, off, x0+MARKSIZE, off, color); } } diff --git a/graph.h b/graph.h index 25c7191b..d0ebd2c2 100644 --- a/graph.h +++ b/graph.h @@ -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 -- cgit v1.2.3 From 609af8f9a8676411e8cd9a591bc2584f5c7b4f8b Mon Sep 17 00:00:00 2001 From: Tectu Date: Sat, 23 Jun 2012 21:34:24 +0200 Subject: some fix, just esthetical --- graph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph.c b/graph.c index d90eaa95..b9ce8739 100644 --- a/graph.c +++ b/graph.c @@ -30,7 +30,7 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_ 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; + off = y0 + i * grid_Y; lcdDrawLine(x0-MARKSIZE, off, x0+MARKSIZE, off, color); } } -- cgit v1.2.3 From 89a597bfc475e8668e7a8c3849dab4f932a63383 Mon Sep 17 00:00:00 2001 From: Tectu Date: Sun, 24 Jun 2012 16:04:11 +0200 Subject: ssd1289 GPIO split into two 8-bit groups --- drivers/lcd/ssd1289_lld.c | 9 ++++++--- readme | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index 9f3303f9..86c8558f 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -11,7 +11,8 @@ static __inline void lld_lcdWriteIndex(uint16_t index) { Clr_RS; Set_RD; - palWritePort(LCD_DATA_PORT, index); + LCD_DATA_PORT_1->BSRR = (((~index >> 8) << 16) | (index >> 8) << LCD_DATA_PORT_1_BASE); + LCD_DATA_PORT_2->BSRR = (((~index & 0xFF) << 16) | (index & 0xFF) << LCD_DATA_PORT_2_BASE); Clr_WR; Set_WR; @@ -20,7 +21,8 @@ static __inline void lld_lcdWriteIndex(uint16_t index) { static __inline void lld_lcdWriteData(uint16_t data) { Set_RS; - palWritePort(LCD_DATA_PORT, data); + LCD_DATA_PORT_1->BSRR = (((~data >> 8) << 16) | (data >> 8) << LCD_DATA_PORT_1_BASE); + LCD_DATA_PORT_2->BSRR = (((~data & 0xFF) << 16) | (data & 0xFF) << LCD_DATA_PORT_2_BASE); Clr_WR; Set_WR; @@ -83,7 +85,8 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { Set_RS; for(i = 0; i < size; i++) { - palWritePort(LCD_DATA_PORT, buffer[i]); + LCD_DATA_PORT_1->BSRR = (((~buffer[i] >> 8) << 16) | (buffer[i] >> 8) << LCD_DATA_PORT_1_BASE); + LCD_DATA_PORT_2->BSRR = (((~buffer[i] & 0xFF) << 16) | (buffer[i] & 0xFF) << LCD_DATA_PORT_2_BASE); Clr_WR; Set_WR; } diff --git a/readme b/readme index 7e926841..7840b56a 100644 --- a/readme +++ b/readme @@ -6,16 +6,21 @@ 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 + #define TP_PORT GPIOC + #define TP_IRQ 4 + #define TP_CS 6 + + #define LCD_DATA_PORT_1 GPIOB + #define LCD_DATA_PORT_2 GPIOC + #define LCD_DATA_PORT_1_BASE 8 + #define LCD_DATA_PORT_2_BASE 0 + #define LCD_CMD_PORT GPIOD + #define LCD_CS 12 + #define LCD_RS 13 + #define LCD_WR 14 + #define LCD_RD 15 + +in this example, we use GPIOC[0:7] for DB[0:7] and GPIOB[8:15] for DB[8:15] ### Edit Makefile: include lcd.mk: -- cgit v1.2.3 From 73e0021db2fc2a92d4d79129ba5af058e7c85c68 Mon Sep 17 00:00:00 2001 From: Tectu Date: Sun, 24 Jun 2012 16:44:58 +0200 Subject: implemented lld_lcdWriteGPIO() for SSD1289 --- drivers/lcd/ssd1289_lld.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index 86c8558f..f9fa0cfd 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -7,12 +7,17 @@ uint16_t DeviceCode; extern uint16_t lcd_width, lcd_height; #ifdef LCD_USE_GPIO + +static __inline lld_lcdWriteGPIO(uint16_t d) { + LCD_DATA_PORT_1->BSRR = (((~d >> 8) << 16) | (d >> 8) << LCD_DATA_PORT_1_BASE); + LCD_DATA_PORT_2->BSRR = (((~d & 0xFF) << 16) | (d & 0xFF) << LCD_DATA_PORT_2_BASE); +} + static __inline void lld_lcdWriteIndex(uint16_t index) { Clr_RS; Set_RD; - LCD_DATA_PORT_1->BSRR = (((~index >> 8) << 16) | (index >> 8) << LCD_DATA_PORT_1_BASE); - LCD_DATA_PORT_2->BSRR = (((~index & 0xFF) << 16) | (index & 0xFF) << LCD_DATA_PORT_2_BASE); + lld_lcdWriteGPIO(index); Clr_WR; Set_WR; @@ -21,8 +26,7 @@ static __inline void lld_lcdWriteIndex(uint16_t index) { static __inline void lld_lcdWriteData(uint16_t data) { Set_RS; - LCD_DATA_PORT_1->BSRR = (((~data >> 8) << 16) | (data >> 8) << LCD_DATA_PORT_1_BASE); - LCD_DATA_PORT_2->BSRR = (((~data & 0xFF) << 16) | (data & 0xFF) << LCD_DATA_PORT_2_BASE); + lld_lcdWriteGPIO(data); Clr_WR; Set_WR; @@ -85,8 +89,7 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { Set_RS; for(i = 0; i < size; i++) { - LCD_DATA_PORT_1->BSRR = (((~buffer[i] >> 8) << 16) | (buffer[i] >> 8) << LCD_DATA_PORT_1_BASE); - LCD_DATA_PORT_2->BSRR = (((~buffer[i] & 0xFF) << 16) | (buffer[i] & 0xFF) << LCD_DATA_PORT_2_BASE); + lld_lcdWriteGPIO(buffer[i]); Clr_WR; Set_WR; } -- cgit v1.2.3 From ed70b3acc48e16f9c7640ef95152ea6037901e8e Mon Sep 17 00:00:00 2001 From: Tectu Date: Sun, 24 Jun 2012 17:37:33 +0200 Subject: ssd1289 GPIO interface abstraction --- drivers/lcd/ssd1289_lld.c | 6 ++++-- readme | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index f9fa0cfd..d1d34310 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -9,8 +9,10 @@ extern uint16_t lcd_width, lcd_height; #ifdef LCD_USE_GPIO static __inline lld_lcdWriteGPIO(uint16_t d) { - LCD_DATA_PORT_1->BSRR = (((~d >> 8) << 16) | (d >> 8) << LCD_DATA_PORT_1_BASE); - LCD_DATA_PORT_2->BSRR = (((~d & 0xFF) << 16) | (d & 0xFF) << LCD_DATA_PORT_2_BASE); + LCD_DATA_PORT_1->BSRR = ((((~d >> 12 & 0xF) << 16) | (d >> 12 & 0xF)) << LCD_DATA_PORT_1_BASE); + LCD_DATA_PORT_2->BSRR = ((((~d >> 8 & 0xF) << 16) | (d >> 8 & 0xF)) << LCD_DATA_PORT_2_BASE); + LCD_DATA_PORT_3->BSRR = ((((~d >> 4 & 0xF) << 16) | (d >> 4 & 0xF)) << LCD_DATA_PORT_3_BASE); + LCD_DATA_PORT_4->BSRR = ((((~d >> 0 & 0xF) << 16) | (d >> 0 & 0xF)) << LCD_DATA_PORT_4_BASE); } static __inline void lld_lcdWriteIndex(uint16_t index) { diff --git a/readme b/readme index 7840b56a..03c5a9f6 100644 --- a/readme +++ b/readme @@ -11,16 +11,24 @@ add the following to your board.h file, matching to your pinconfig: #define TP_CS 6 #define LCD_DATA_PORT_1 GPIOB - #define LCD_DATA_PORT_2 GPIOC - #define LCD_DATA_PORT_1_BASE 8 - #define LCD_DATA_PORT_2_BASE 0 + #define LCD_DATA_PORT_2 GPIOB + #define LCD_DATA_PORT_3 GPIOC + #define LCD_DATA_PORT_4 GPIOE + #define LCD_DATA_PORT_1_BASE 12 + #define LCD_DATA_PORT_2_BASE 8 + #define LCD_DATA_PORT_3_BASE 4 + #define LCD_DATA_PORT_4_BASE 0 #define LCD_CMD_PORT GPIOD #define LCD_CS 12 #define LCD_RS 13 #define LCD_WR 14 #define LCD_RD 15 -in this example, we use GPIOC[0:7] for DB[0:7] and GPIOB[8:15] for DB[8:15] +in this example we use the following pin config for 16-bit GPIO interfacing: + + GPIOB 8-15 + GPIOC 4-7 + GPIOE 0-3 ### Edit Makefile: include lcd.mk: -- cgit v1.2.3 From e543f15633db2fc915245c5ede020c30e633c1a4 Mon Sep 17 00:00:00 2001 From: Tectu Date: Sun, 24 Jun 2012 18:28:57 +0200 Subject: whitespaces --- glcd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/glcd.c b/glcd.c index b00fa698..01e166a8 100644 --- a/glcd.c +++ b/glcd.c @@ -394,10 +394,10 @@ 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); } -- cgit v1.2.3 From 7401ade97dbfcb851e9155bbabdb061b2b769492 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 10:40:05 +0200 Subject: GUI threads do now take active/inactive state --- gui.c | 53 +++++++++++++++++++++++++++++++---------------------- gui.h | 9 ++++++--- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/gui.c b/gui.c index 1d162d54..1fc8f083 100644 --- a/gui.c +++ b/gui.c @@ -27,10 +27,14 @@ static void buttonThread(struct button_t *a) { y1 = a->y1; while(TRUE) { - if(x >= x0 && x <= x1 && y >= y0 && y <= y1) - *(a->state) = 1; - else + if(*(a->active) == active) { + if(x >= x0 && x <= x1 && y >= y0 && y <= y1) + *(a->state) = 1; + else + *(a->state) = 0; + } else { *(a->state) = 0; + } chThdSleepMilliseconds(a->interval); } @@ -40,25 +44,28 @@ static void barThread(struct bar_t *a) { 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); + if(*(a->active) == active) { + 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; } - value_old = value; chThdSleepMilliseconds(a->interval); } } @@ -68,7 +75,7 @@ void guiInit(uint16_t updateInterval) { 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, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *state) { +Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *active, uint8_t *state) { struct button_t *button; Thread *tp = NULL; @@ -78,6 +85,7 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign button->x1 = x1; button->y1 = y1; button->state = state; + button->active = active; button->interval = interval; lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); @@ -86,7 +94,7 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign return tp; } -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) { +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, uint8_t *active, uint16_t *percent) { struct bar_t *bar; Thread *tp = NULL; @@ -101,6 +109,7 @@ Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint bar->valueColor = valueColor; bar->percent = percent; bar->interval = interval; + bar->active = active; lcdDrawRect(x0, y0, x1, y1, frame, frameColor); tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, barThread, bar); diff --git a/gui.h b/gui.h index d0ec128a..edacf72f 100644 --- a/gui.h +++ b/gui.h @@ -6,7 +6,8 @@ struct button_t { uint16_t y0; uint16_t x1; uint16_t y1; - uint32_t *state; + uint8_t *state; + uint8_t *active; uint16_t interval; }; @@ -21,9 +22,11 @@ struct bar_t { uint16_t valueColor; uint16_t interval; uint8_t *percent; + uint8_t *active; }; enum {horizontal, vertical}; +enum {inactive, active}; #ifdef __cplusplus extern "C" { @@ -53,7 +56,7 @@ void guiInit(uint16_t updateIntervl); * * return: pointer to created thread */ -Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *state); +Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *active, uint8_t *state); /* * Description: draws a bar graph and updates it's value @@ -69,7 +72,7 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign * * return : pointer to created thread */ -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); +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, uint8_t *active, uint16_t *percent); #ifdef __cplusplus } -- cgit v1.2.3 From 4bd671ed2e2a9aaf05f0d4b415c30d3358d58e9d Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 10:44:13 +0200 Subject: documentation --- gui.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui.h b/gui.h index edacf72f..4e1e27e0 100644 --- a/gui.h +++ b/gui.h @@ -52,6 +52,7 @@ void guiInit(uint16_t updateIntervl); * - fontColor: color of string * - buttonColor: color of button * - interval: interval in ms which updates state + * - active: pointer to uint8_t. 1 = thread active, 0 = thread inactive * - state: pointer to variable which keeps state (1 = pressed, 0 = unpressed) * * return: pointer to created thread @@ -68,6 +69,7 @@ Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsign * - 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 + * - active: pointer to uint8_t. 1 = thread active, 0 = thread inactive * - percent: pointer value from 0 to 100 percent * * return : pointer to created thread -- cgit v1.2.3 From f2cb8a0c5310430a88c3392f8f7b8048da97dbc5 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 10:51:57 +0200 Subject: compiler warnings --- gui.c | 2 +- gui.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 1fc8f083..05406373 100644 --- a/gui.c +++ b/gui.c @@ -75,7 +75,7 @@ void guiInit(uint16_t updateInterval) { 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, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *active, uint8_t *state) { +Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *active, uint8_t *state) { struct button_t *button; Thread *tp = NULL; diff --git a/gui.h b/gui.h index 4e1e27e0..66200c7a 100644 --- a/gui.h +++ b/gui.h @@ -57,7 +57,7 @@ void guiInit(uint16_t updateIntervl); * * return: pointer to created thread */ -Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *active, uint8_t *state); +Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *active, uint8_t *state); /* * Description: draws a bar graph and updates it's value -- cgit v1.2.3 From 192282d6aff3a7fbe7c73e7c181d62955586bbce Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 10:52:52 +0200 Subject: guiInit() returns pointer to created thread --- gui.c | 4 +++- gui.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gui.c b/gui.c index 05406373..ec1ee951 100644 --- a/gui.c +++ b/gui.c @@ -70,9 +70,11 @@ static void barThread(struct bar_t *a) { } } -void guiInit(uint16_t updateInterval) { +Thread *guiInit(uint16_t updateInterval) { Thread *tp = NULL; tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval); + + return tp; } Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *active, uint8_t *state) { diff --git a/gui.h b/gui.h index 66200c7a..d56ca6e7 100644 --- a/gui.h +++ b/gui.h @@ -39,9 +39,9 @@ extern "C" { * param: * - updateInterval: update interval in milliseconds until next coordinates read-out * - * return: none + * return: pointer to created thread */ -void guiInit(uint16_t updateIntervl); +Thread *guiInit(uint16_t updateIntervl); /* * Description: draws button and creates thread which keeps pressed/unpressed state up-to-date -- cgit v1.2.3 From 84c868d5f5ae60b893441cb9f2b8b10f2ac8034b Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 11:32:41 +0200 Subject: lld_lcdWriteGPIO() return type --- drivers/lcd/ssd1289_lld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index d1d34310..e0d7fb28 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -8,7 +8,7 @@ extern uint16_t lcd_width, lcd_height; #ifdef LCD_USE_GPIO -static __inline lld_lcdWriteGPIO(uint16_t d) { +static __inline void lld_lcdWriteGPIO(uint16_t d) { LCD_DATA_PORT_1->BSRR = ((((~d >> 12 & 0xF) << 16) | (d >> 12 & 0xF)) << LCD_DATA_PORT_1_BASE); LCD_DATA_PORT_2->BSRR = ((((~d >> 8 & 0xF) << 16) | (d >> 8 & 0xF)) << LCD_DATA_PORT_2_BASE); LCD_DATA_PORT_3->BSRR = ((((~d >> 4 & 0xF) << 16) | (d >> 4 & 0xF)) << LCD_DATA_PORT_3_BASE); -- cgit v1.2.3 From 9e5cd3140a56c3097b62029994cc33216e823c36 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 12:34:38 +0200 Subject: ssd1289 driver fix --- drivers/lcd/ssd1289_lld.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index e0d7fb28..9992ec93 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -9,10 +9,10 @@ extern uint16_t lcd_width, lcd_height; #ifdef LCD_USE_GPIO static __inline void lld_lcdWriteGPIO(uint16_t d) { - LCD_DATA_PORT_1->BSRR = ((((~d >> 12 & 0xF) << 16) | (d >> 12 & 0xF)) << LCD_DATA_PORT_1_BASE); - LCD_DATA_PORT_2->BSRR = ((((~d >> 8 & 0xF) << 16) | (d >> 8 & 0xF)) << LCD_DATA_PORT_2_BASE); - LCD_DATA_PORT_3->BSRR = ((((~d >> 4 & 0xF) << 16) | (d >> 4 & 0xF)) << LCD_DATA_PORT_3_BASE); - LCD_DATA_PORT_4->BSRR = ((((~d >> 0 & 0xF) << 16) | (d >> 0 & 0xF)) << LCD_DATA_PORT_4_BASE); + palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d >> 12); + palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 8); + palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_3_BASE, d >> 4); + palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_4_BASE, d >> 0); } static __inline void lld_lcdWriteIndex(uint16_t index) { -- cgit v1.2.3 From ccf2780be97616371395c974f1f59d1f664e32af Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 12:44:35 +0200 Subject: lld GPIO lsb/msb order fix --- drivers/lcd/ssd1289_lld.c | 8 ++++---- readme | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index 9992ec93..5d5184a5 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -9,10 +9,10 @@ extern uint16_t lcd_width, lcd_height; #ifdef LCD_USE_GPIO static __inline void lld_lcdWriteGPIO(uint16_t d) { - palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d >> 12); - palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 8); - palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_3_BASE, d >> 4); - palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_4_BASE, d >> 0); + palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d >> 0); + palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 4); + palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_3_BASE, d >> 8); + palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_4_BASE, d >> 12); } static __inline void lld_lcdWriteIndex(uint16_t index) { diff --git a/readme b/readme index 03c5a9f6..132fc19c 100644 --- a/readme +++ b/readme @@ -14,10 +14,10 @@ add the following to your board.h file, matching to your pinconfig: #define LCD_DATA_PORT_2 GPIOB #define LCD_DATA_PORT_3 GPIOC #define LCD_DATA_PORT_4 GPIOE - #define LCD_DATA_PORT_1_BASE 12 - #define LCD_DATA_PORT_2_BASE 8 - #define LCD_DATA_PORT_3_BASE 4 - #define LCD_DATA_PORT_4_BASE 0 + #define LCD_DATA_PORT_1_BASE 0 + #define LCD_DATA_PORT_2_BASE 4 + #define LCD_DATA_PORT_3_BASE 8 + #define LCD_DATA_PORT_4_BASE 12 #define LCD_CMD_PORT GPIOD #define LCD_CS 12 #define LCD_RS 13 -- cgit v1.2.3 From 484daa395a7b74692657730b4f487e58b2e231fd Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 13:02:54 +0200 Subject: GPIO interfacing rewrite --- drivers/lcd/ssd1289_lld.c | 18 +----------------- readme | 30 +----------------------------- 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index 5d5184a5..033114cf 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -8,13 +8,6 @@ extern uint16_t lcd_width, lcd_height; #ifdef LCD_USE_GPIO -static __inline void lld_lcdWriteGPIO(uint16_t d) { - palWriteGroup(LCD_DATA_PORT_1, PAL_GROUP_MASK(4), LCD_DATA_PORT_1_BASE, d >> 0); - palWriteGroup(LCD_DATA_PORT_2, PAL_GROUP_MASK(4), LCD_DATA_PORT_2_BASE, d >> 4); - palWriteGroup(LCD_DATA_PORT_3, PAL_GROUP_MASK(4), LCD_DATA_PORT_3_BASE, d >> 8); - palWriteGroup(LCD_DATA_PORT_4, PAL_GROUP_MASK(4), LCD_DATA_PORT_4_BASE, d >> 12); -} - static __inline void lld_lcdWriteIndex(uint16_t index) { Clr_RS; Set_RD; @@ -48,16 +41,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(LCD_DATA_PORT); Set_RD; diff --git a/readme b/readme index 132fc19c..f3fc567f 100644 --- a/readme +++ b/readme @@ -4,32 +4,6 @@ Chibios LCD Driver 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_1 GPIOB - #define LCD_DATA_PORT_2 GPIOB - #define LCD_DATA_PORT_3 GPIOC - #define LCD_DATA_PORT_4 GPIOE - #define LCD_DATA_PORT_1_BASE 0 - #define LCD_DATA_PORT_2_BASE 4 - #define LCD_DATA_PORT_3_BASE 8 - #define LCD_DATA_PORT_4_BASE 12 - #define LCD_CMD_PORT GPIOD - #define LCD_CS 12 - #define LCD_RS 13 - #define LCD_WR 14 - #define LCD_RD 15 - -in this example we use the following pin config for 16-bit GPIO interfacing: - - GPIOB 8-15 - GPIOC 4-7 - GPIOE 0-3 - ### Edit Makefile: include lcd.mk: include $(CHIBIOS)/ext/lcd/lcd.mk @@ -54,9 +28,7 @@ Add $(LCDINC) to INCDIR: $(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 +read here: http://chibios.org/dokuwiki/doku.php?id=chibios:community:introduction ### Maintainer & Contributors Contributors: - Badger -- cgit v1.2.3 From bea97894b50f6cbb4fa4b3c0cafa256c7c85d91b Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 13:20:58 +0200 Subject: whitespaces --- drivers/lcd/ssd1289_lld.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index 033114cf..9065db9a 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -29,8 +29,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; } @@ -62,6 +64,7 @@ static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) { __inline void lld_lcdWriteStreamStart(void) { Clr_CS + lld_lcdWriteIndex(0x0022); } -- cgit v1.2.3 From a52393a483e29928770c8ea127c500f650e04c19 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 13:44:29 +0200 Subject: ssd1289 fix --- drivers/lcd/ssd1289_lld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index 9065db9a..6b199df6 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -43,7 +43,7 @@ static __inline uint16_t lld_lcdReadData(void) { Set_WR; Clr_RD; - value = lld_lcdReadGPIO(LCD_DATA_PORT); + value = lld_lcdReadGPIO(); Set_RD; -- cgit v1.2.3 From 310f0723b9d63d048b0d7b81b477195fa22de78a Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 13:52:30 +0200 Subject: doc --- readme | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/readme b/readme index f3fc567f..56f3d1a3 100644 --- a/readme +++ b/readme @@ -1,34 +1,8 @@ -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&#lcd_driver_touch_screen_graphical_user_interface -### Edit Makefile: -include lcd.mk: - include $(CHIBIOS)/ext/lcd/lcd.mk -Add $(LCDSRC) to CSRC: - 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 -read here: http://chibios.org/dokuwiki/doku.php?id=chibios:community:introduction ### Maintainer & Contributors Contributors: - Badger -- cgit v1.2.3 From f2f18d3b8d8ae3ea5bd190b2abc21b832237cdf0 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 13:54:42 +0200 Subject: doc --- readme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme b/readme index 56f3d1a3..af031182 100644 --- a/readme +++ b/readme @@ -1,6 +1,6 @@ please read the wiki pages to this project carefully, before you ask any questions: -http://chibios.org/dokuwiki/doku.php?id=chibios:community&#lcd_driver_touch_screen_graphical_user_interface +http://chibios.org/dokuwiki/doku.php?id=chibios:community -- cgit v1.2.3 From 12fa4500c84fdca32208753d1883c972f342c7ec Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 25 Jun 2012 13:55:19 +0200 Subject: doc fix --- readme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme b/readme index af031182..9957d358 100644 --- a/readme +++ b/readme @@ -6,8 +6,8 @@ http://chibios.org/dokuwiki/doku.php?id=chibios:community ### Maintainer & Contributors Contributors: - Badger - - Abhishek + - Abhishek -Maintainer: - Joel Bodenmann aka Tectu +Maintainer: - Joel Bodenmann aka Tectu -- cgit v1.2.3 From 588429506c668281354523fec3a7f9009901bf1f Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 12:47:25 +0200 Subject: implemented linkedlist --- gui.c | 181 +++++++++++++++++++++++++++++++++--------------------------------- gui.h | 75 +++++---------------------- 2 files changed, 104 insertions(+), 152 deletions(-) diff --git a/gui.c b/gui.c index ec1ee951..8605dce7 100644 --- a/gui.c +++ b/gui.c @@ -1,120 +1,121 @@ -#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 void TouchPadThread(uint16_t updateInterval) { - chRegSetThreadName("GUI"); +static uint16_t addNode(struct guiNode_t *newNode) { + struct guiNode_t *new; - while(TRUE) { - x = tpReadX(); - y = tpReadY(); + 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; - chThdSleepMilliseconds(updateInterval); + new->next = chHeapAlloc(NULL, sizeof(struct guiNode_t)); + if(new->next == NULL) + return 0; + + new = new->next; + *new = *newNode; + new->next = NULL; } -} -static void buttonThread(struct button_t *a) { - uint16_t x0, y0, x1, y1; + return 1; +} - x0 = a->x0; - y0 = a->y0; - x1 = a->x1; - y1 = a->y1; +static void deleteNode(char *name) { + struct guiNode_t *pointer, *pointer1; - while(TRUE) { - if(*(a->active) == active) { - if(x >= x0 && x <= x1 && y >= y0 && y <= y1) - *(a->state) = 1; - else - *(a->state) = 0; + if(firstGUI != NULL) { + if(strcmp(firstGUI->name, name) == 0) { + pointer = firstGUI->next; + free(firstGUI); + firstGUI = pointer; } else { - *(a->state) = 0; - } + pointer = firstGUI; - chThdSleepMilliseconds(a->interval); - } -} + while(pointer->next != NULL) { + pointer1 = pointer->next; -static void barThread(struct bar_t *a) { - uint16_t percent = 0, value = 0, value_old = 0; + if(strcmp(firstGUI->name, name) == 0) { + pointer->next = pointer1->next; + free(pointer1); + break; + } - while(TRUE) { - if(*(a->active) == active) { - 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); - } + pointer = pointer1; - value_old = value; + } } - - chThdSleepMilliseconds(a->interval); } } -Thread *guiInit(uint16_t updateInterval) { - Thread *tp = NULL; - tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval); - - return tp; +void printNodes(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, "name: %s\r\n", pointer->name); + chprintf(chp, "*active: 0x%x\r\n", pointer->active); + chprintf(chp, "*state: 0x%x\r\n", pointer->state); + chprintf(chp, "*next: 0x%x\r\n", pointer->next); + chprintf(chp, "\r\n\n"); + pointer = pointer->next; + } } -Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *active, uint8_t *state) { - struct button_t *button; - Thread *tp = NULL; +static void guiThread(const uint16_t interval) { + uint16_t x, y; + struct guiNode_t *node; - button = chHeapAlloc(NULL, sizeof(struct button_t)); - button->x0 = x0; - button->y0 = y0; - button->x1 = x1; - button->y1 = y1; - button->state = state; - button->active = active; - button->interval = interval; + chRegSetThreadName("GUI"); - lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); - tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, buttonThread, button); + while(TRUE) { + x = tpReadX(); + y = tpReadY(); - return tp; + chThdSleepMilliseconds(interval); + } } -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, uint8_t *active, uint16_t *percent) { - struct bar_t *bar; +Thread *guiInit(uint16_t interval) { Thread *tp = NULL; - 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; - bar->active = active; - - lcdDrawRect(x0, y0, x1, y1, frame, frameColor); - tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, barThread, bar); + tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(10240), HIGHPRIO-1, guiThread, interval); return tp; } + +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state) { + struct guiNode_t *newNode; + + newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t)); + if(newNode == NULL) + return 0; + + newNode->x0 = x0; + newNode->y0 = y0; + newNode->x1 = x1; + newNode->y1 = y1; + newNode->name = str; + newNode->active = active; + newNode->state = state; + + addNode(newNode); + + lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); + + return 1; +} + diff --git a/gui.h b/gui.h index d56ca6e7..d9faa6fd 100644 --- a/gui.h +++ b/gui.h @@ -1,84 +1,35 @@ #ifndef GUI_H #define GUI_H -struct button_t { - uint16_t x0; - uint16_t y0; - uint16_t x1; - uint16_t y1; - uint8_t *state; - uint8_t *active; - uint16_t interval; -}; +#include "ch.h" +#include "hal.h" +#include "glcd.h" +#include "touchpad.h" -struct bar_t { +static struct guiNode_t { 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; uint8_t *active; + uint8_t *state; + char *name; + struct guiNode_t *next; }; -enum {horizontal, vertical}; -enum {inactive, active}; - #ifdef __cplusplus extern "C" { #endif +enum {horizontal, vertical}; +enum {inactive, active}; -/* - * Description: starts main GUI thread which keeps X and Y coordinates of touchpad updated for guiDraw() threads - * - * param: - * - updateInterval: update interval in milliseconds until next coordinates read-out - * - * return: pointer to created thread - */ -Thread *guiInit(uint16_t updateIntervl); - -/* - * Description: draws button and creates thread which keeps pressed/unpressed state up-to-date - * - * 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 - * - active: pointer to uint8_t. 1 = thread active, 0 = thread inactive - * - state: pointer to variable which keeps state (1 = pressed, 0 = unpressed) - * - * return: pointer to created thread - */ -Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *active, uint8_t *state); - -/* - * Description: draws a bar graph and updates it's value - * - * 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 - * - active: pointer to uint8_t. 1 = thread active, 0 = thread inactive - * - percent: pointer value from 0 to 100 percent - * - * return : pointer to created thread - */ -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, uint8_t *active, uint16_t *percent); +Thread *guiInit(uint16_t interval); +void printNode(BaseSequentialStream *chp); +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state); #ifdef __cplusplus } #endif #endif - -- cgit v1.2.3 From 87888e474da82cfac4ad0ce8f03a1e9647542cd8 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 13:16:36 +0200 Subject: implemented GUI button drawing --- gui.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gui.c b/gui.c index 8605dce7..c4bf6865 100644 --- a/gui.c +++ b/gui.c @@ -56,7 +56,7 @@ static void deleteNode(char *name) { } } -void printNodes(BaseSequentialStream *chp) { +static void printNodes(BaseSequentialStream *chp) { struct guiNode_t *pointer = firstGUI; chprintf(chp, "\r\n\nguiNodes:\r\n\n"); @@ -82,9 +82,20 @@ static void guiThread(const uint16_t interval) { chRegSetThreadName("GUI"); while(TRUE) { - x = tpReadX(); - y = tpReadY(); - + for(node = firstGUI; node; node = node->next) { + if(*(node->active) == active) { + x = tpReadX(); + y = tpReadY(); + + if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1) + *(node->state) = 1; + else + *(node->state) = 0; + + chThdSleepMilliseconds(interval); + } + } + chThdSleepMilliseconds(interval); } } -- cgit v1.2.3 From bbfc18bc27cac2abc276fe526ad7c8734515f946 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 13:44:10 +0200 Subject: fixed active/inactive state of GUI elements --- gui.c | 12 +++++++----- gui.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gui.c b/gui.c index c4bf6865..6e8198ef 100644 --- a/gui.c +++ b/gui.c @@ -56,7 +56,7 @@ static void deleteNode(char *name) { } } -static void printNodes(BaseSequentialStream *chp) { +void guiPrintNodes(BaseSequentialStream *chp) { struct guiNode_t *pointer = firstGUI; chprintf(chp, "\r\n\nguiNodes:\r\n\n"); @@ -67,8 +67,8 @@ static void printNodes(BaseSequentialStream *chp) { chprintf(chp, "x1: %d\r\n", pointer->x1); chprintf(chp, "y1: %d\r\n", pointer->y1); chprintf(chp, "name: %s\r\n", pointer->name); - chprintf(chp, "*active: 0x%x\r\n", pointer->active); - chprintf(chp, "*state: 0x%x\r\n", pointer->state); + 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; @@ -91,9 +91,11 @@ static void guiThread(const uint16_t interval) { *(node->state) = 1; else *(node->state) = 0; - - chThdSleepMilliseconds(interval); + } else { + *(node->state) = 0; } + + chThdSleepMilliseconds(interval); } chThdSleepMilliseconds(interval); diff --git a/gui.h b/gui.h index d9faa6fd..4a6f741f 100644 --- a/gui.h +++ b/gui.h @@ -25,7 +25,7 @@ enum {horizontal, vertical}; enum {inactive, active}; Thread *guiInit(uint16_t interval); -void printNode(BaseSequentialStream *chp); +void guiPrintNode(BaseSequentialStream *chp); uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state); #ifdef __cplusplus -- cgit v1.2.3 From 574f97a7a18d2f708ab3d24037f52b6a5a10a1ea Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 13:46:40 +0200 Subject: guiDrawButton return value fix --- gui.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui.c b/gui.c index 6e8198ef..9f20c4d5 100644 --- a/gui.c +++ b/gui.c @@ -125,7 +125,8 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * newNode->active = active; newNode->state = state; - addNode(newNode); + if(addNode(newNode) != 1) + return 0; lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); -- cgit v1.2.3 From bef27b666391547b56768b2c126a39ec2baf28d6 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 13:50:12 +0200 Subject: guiInit() priority parameter --- gui.c | 4 ++-- gui.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gui.c b/gui.c index 9f20c4d5..bd00d776 100644 --- a/gui.c +++ b/gui.c @@ -102,10 +102,10 @@ static void guiThread(const uint16_t interval) { } } -Thread *guiInit(uint16_t interval) { +Thread *guiInit(uint16_t interval, tprio_t priority) { Thread *tp = NULL; - tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(10240), HIGHPRIO-1, guiThread, interval); + tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(10240), priority, guiThread, interval); return tp; } diff --git a/gui.h b/gui.h index 4a6f741f..44c640a6 100644 --- a/gui.h +++ b/gui.h @@ -24,7 +24,7 @@ extern "C" { enum {horizontal, vertical}; enum {inactive, active}; -Thread *guiInit(uint16_t interval); +Thread *guiInit(uint16_t interval, tprio_t priority); void guiPrintNode(BaseSequentialStream *chp); uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state); -- cgit v1.2.3 From 3a63bff54d5974b597b3a7115ec0b75eab7c5f95 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 13:50:49 +0200 Subject: GUI thread WA size fix --- gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.c b/gui.c index bd00d776..895eb3dd 100644 --- a/gui.c +++ b/gui.c @@ -105,7 +105,7 @@ static void guiThread(const uint16_t interval) { Thread *guiInit(uint16_t interval, tprio_t priority) { Thread *tp = NULL; - tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(10240), priority, guiThread, interval); + tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), priority, guiThread, interval); return tp; } -- cgit v1.2.3 From 6743cde23dc39204f972af24cde93806630bfaa2 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 13:57:00 +0200 Subject: gui doc --- gui.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gui.h b/gui.h index 44c640a6..54031295 100644 --- a/gui.h +++ b/gui.h @@ -24,8 +24,37 @@ extern "C" { enum {horizontal, vertical}; enum {inactive, active}; +/* + * Description: creates the GUI thread + * + * param: - interval: thread sleep in milliseconds after each GUI element update + * - 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 + */ void guiPrintNode(BaseSequentialStream *chp); + +/* + * 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 + * - 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, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state); #ifdef __cplusplus -- cgit v1.2.3 From 9ae31c538923bfee4631547735c8ca6d9d8a05a7 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 13:58:41 +0200 Subject: free memory --- gui.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui.c b/gui.c index 895eb3dd..45a9d686 100644 --- a/gui.c +++ b/gui.c @@ -130,6 +130,8 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); + chHeapFree(newNode); + return 1; } -- cgit v1.2.3 From 9782c3edbcaf45f4ce3b82e9155f4d9cca17ed6e Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 15:09:47 +0200 Subject: sleep fix in gui.c --- gui.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/gui.c b/gui.c index 45a9d686..1059a387 100644 --- a/gui.c +++ b/gui.c @@ -94,8 +94,6 @@ static void guiThread(const uint16_t interval) { } else { *(node->state) = 0; } - - chThdSleepMilliseconds(interval); } chThdSleepMilliseconds(interval); -- cgit v1.2.3 From 4fee89285eea5fa9af69ce1aed250ffc459f1b69 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 15:14:34 +0200 Subject: added GUI usage demo --- demos/gui/main.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 demos/gui/main.c diff --git a/demos/gui/main.c b/demos/gui/main.c new file mode 100755 index 00000000..d37c993c --- /dev/null +++ b/demos/gui/main.c @@ -0,0 +1,74 @@ +#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, &setActive, &setState); + guiDrawButton(70, 10, 120, 60, "Clear", Black, Red, &clearActive, &clearState); + + 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; +} -- cgit v1.2.3 From 969377866601ce3bf1bd15de5a97b291b0f11560 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 16:22:08 +0200 Subject: free memory --- gui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 1059a387..f7da8f8c 100644 --- a/gui.c +++ b/gui.c @@ -35,7 +35,7 @@ static void deleteNode(char *name) { if(firstGUI != NULL) { if(strcmp(firstGUI->name, name) == 0) { pointer = firstGUI->next; - free(firstGUI); + chHeapFree(firstGUI); firstGUI = pointer; } else { pointer = firstGUI; @@ -45,7 +45,7 @@ static void deleteNode(char *name) { if(strcmp(firstGUI->name, name) == 0) { pointer->next = pointer1->next; - free(pointer1); + chHeapFree(pointer1); break; } -- cgit v1.2.3 From cc7943305eab42fd6f687a4dda1f19857ae0efb7 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 20:47:35 +0200 Subject: added type of GUI element --- gui.c | 14 ++++++++------ gui.h | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gui.c b/gui.c index f7da8f8c..598433ba 100644 --- a/gui.c +++ b/gui.c @@ -86,13 +86,14 @@ static void guiThread(const uint16_t interval) { if(*(node->active) == active) { x = tpReadX(); y = tpReadY(); - - if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1) - *(node->state) = 1; - else + 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; - } else { - *(node->state) = 0; + } } } @@ -119,6 +120,7 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * newNode->y0 = y0; newNode->x1 = x1; newNode->y1 = y1; + newNode->type = button; newNode->name = str; newNode->active = active; newNode->state = state; diff --git a/gui.h b/gui.h index 54031295..a95e9d36 100644 --- a/gui.h +++ b/gui.h @@ -7,6 +7,7 @@ #include "touchpad.h" static struct guiNode_t { + uint8_t type; uint16_t x0; uint16_t y0; uint16_t x1; @@ -21,6 +22,7 @@ static struct guiNode_t { extern "C" { #endif +enum {button}; enum {horizontal, vertical}; enum {inactive, active}; -- cgit v1.2.3 From f4917beb6a491ed061e1daa3d41ce913be1e6acd Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 21:17:50 +0200 Subject: added different GUI elements --- gui.c | 13 +++++++++++++ gui.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gui.c b/gui.c index 598433ba..99db4133 100644 --- a/gui.c +++ b/gui.c @@ -83,9 +83,12 @@ static void guiThread(const uint16_t interval) { while(TRUE) { for(node = firstGUI; node; node = node->next) { + // check if GUI element is active if(*(node->active) == active) { x = tpReadX(); y = tpReadY(); + + // we got a button if(node->type == button) { if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1) *(node->state) = 1; @@ -94,6 +97,16 @@ static void guiThread(const uint16_t interval) { } else { *(node->state) = 0; } + + // we got a slider + if(node->type == slider) { + + } + + // we got a keymatrix + if(node->type == keymatrix) { + + } } } diff --git a/gui.h b/gui.h index a95e9d36..05e4c383 100644 --- a/gui.h +++ b/gui.h @@ -22,7 +22,7 @@ static struct guiNode_t { extern "C" { #endif -enum {button}; +enum {button, slider, keymatrix}; enum {horizontal, vertical}; enum {inactive, active}; -- cgit v1.2.3 From a1cc224472060b08e18a6f17e94852d8a461ccf9 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 21:43:21 +0200 Subject: added wheel as GUI type --- gui.c | 33 ++++++++++++++++++++++++++++++++- gui.h | 5 ++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 99db4133..0ecaf52d 100644 --- a/gui.c +++ b/gui.c @@ -103,6 +103,11 @@ static void guiThread(const uint16_t interval) { } + // we got a wheel + if(node->type == wheel) { + + } + // we got a keymatrix if(node->type == keymatrix) { @@ -129,11 +134,11 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * if(newNode == NULL) return 0; + newNode->type = button; newNode->x0 = x0; newNode->y0 = y0; newNode->x1 = x1; newNode->y1 = y1; - newNode->type = button; newNode->name = str; newNode->active = active; newNode->state = state; @@ -148,3 +153,29 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * return 1; } +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, 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->x0 = x0; + newNode->y0 = y0; + newNode->x1 = x1; + newNode->y1 = y1; + newNode->state = value; + newNode->active = active; + newNode->orientation = orientation; + + if(addNode(newNode) != 1) + return 0; + + // lcdDraw functions + + chHeapFree(newNode); + + return 1; +} + diff --git a/gui.h b/gui.h index 05e4c383..9d1842da 100644 --- a/gui.h +++ b/gui.h @@ -12,6 +12,7 @@ static struct guiNode_t { uint16_t y0; uint16_t x1; uint16_t y1; + uint8_t orientation; uint8_t *active; uint8_t *state; char *name; @@ -22,7 +23,7 @@ static struct guiNode_t { extern "C" { #endif -enum {button, slider, keymatrix}; +enum {button, slider, wheel, keymatrix}; enum {horizontal, vertical}; enum {inactive, active}; @@ -59,6 +60,8 @@ void guiPrintNode(BaseSequentialStream *chp); */ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, 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, uint8_t *active, uint8_t *value); + #ifdef __cplusplus } #endif -- cgit v1.2.3 From 191dbc088a36bca40d740f3e0e1ac17373be2b4e Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 21:48:12 +0200 Subject: added guiDrawWheel() dummy --- gui.c | 25 +++++++++++++++++++++++++ gui.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/gui.c b/gui.c index 0ecaf52d..ad285374 100644 --- a/gui.c +++ b/gui.c @@ -179,3 +179,28 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_ return 1; } +uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, 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->x0 = x0; + newNode->y0 = y0; + newNode->r1 = radius1; + newNode->r2 = radius2; + newNode->active = active; + newNode->state = value; + + if(addNode(newNode) != 1) + return 0; + + // lcdDraw functions + + chHeapFree(newNode); + + return 1; +} + diff --git a/gui.h b/gui.h index 9d1842da..54f93d27 100644 --- a/gui.h +++ b/gui.h @@ -12,6 +12,8 @@ static struct guiNode_t { uint16_t y0; uint16_t x1; uint16_t y1; + uint16_t r1; + uint16_t r2; uint8_t orientation; uint8_t *active; uint8_t *state; -- cgit v1.2.3 From 3d041a9d4b8c6592468b4b6e7dca29b4e243d795 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 26 Jun 2012 22:20:55 +0200 Subject: guiDrawSlider() frame drawing --- gui.c | 11 +++++++---- gui.h | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gui.c b/gui.c index ad285374..29a40564 100644 --- a/gui.c +++ b/gui.c @@ -127,7 +127,7 @@ Thread *guiInit(uint16_t interval, tprio_t priority) { return tp; } -uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state) { +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *name, uint8_t *active, uint8_t *state) { struct guiNode_t *newNode; newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t)); @@ -135,6 +135,7 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * return 0; newNode->type = button; + newNode->name = name; newNode->x0 = x0; newNode->y0 = y0; newNode->x1 = x1; @@ -153,7 +154,7 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * return 1; } -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, uint8_t *active, uint8_t *value) { +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 *name, uint8_t *active, uint8_t *value) { struct guiNode_t *newNode; newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t)); @@ -161,6 +162,7 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_ return 0; newNode->type = slider; + newNode->type = name; newNode->x0 = x0; newNode->y0 = y0; newNode->x1 = x1; @@ -172,14 +174,14 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_ if(addNode(newNode) != 1) return 0; - // lcdDraw functions + lcdDrawRect(x0, y0, x1, y1, frame, frameColor); 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, 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 *name, uint8_t *active, uint8_t *value) { struct guiNode_t *newNode; newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t)); @@ -187,6 +189,7 @@ uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius return 0; newNode->type = wheel; + newNode->name = name; newNode->x0 = x0; newNode->y0 = y0; newNode->r1 = radius1; diff --git a/gui.h b/gui.h index 54f93d27..5e08ac00 100644 --- a/gui.h +++ b/gui.h @@ -60,9 +60,11 @@ void guiPrintNode(BaseSequentialStream *chp); * * return: 1 if button successfully created */ -uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state); +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *name, 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, uint8_t *active, uint8_t *value); +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 *name, 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 *name, uint8_t *active, uint8_t *value); #ifdef __cplusplus } -- cgit v1.2.3 From db7d8d0aeacc61e1fe75072b802e5f8790591181 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 10:10:45 +0200 Subject: added guiDeleteElement --- gui.c | 10 +++++++++- gui.h | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gui.c b/gui.c index 29a40564..a1dc3431 100644 --- a/gui.c +++ b/gui.c @@ -29,7 +29,7 @@ static uint16_t addNode(struct guiNode_t *newNode) { return 1; } -static void deleteNode(char *name) { +static uint8_t deleteNode(char *name) { struct guiNode_t *pointer, *pointer1; if(firstGUI != NULL) { @@ -53,7 +53,11 @@ static void deleteNode(char *name) { } } + + return 1; // successful } + + return 0; // not successful } void guiPrintNodes(BaseSequentialStream *chp) { @@ -127,6 +131,10 @@ Thread *guiInit(uint16_t interval, tprio_t priority) { return tp; } +uint8_t guiDeleteElement(char *name) { + return deleteNode(name); +} + uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *name, uint8_t *active, uint8_t *state) { struct guiNode_t *newNode; diff --git a/gui.h b/gui.h index 5e08ac00..18251291 100644 --- a/gui.h +++ b/gui.h @@ -48,6 +48,14 @@ Thread *guiInit(uint16_t interval, tprio_t priority); */ void guiPrintNode(BaseSequentialStream *chp); +/* + * Description: deletes a GUI element from the linked list + * + * param: - name: name of the element (parameter of each guiDrawXXX function) + * + * return: 1 if successful, 0 otherwise + */ +uint8_t guiDeleteElement(char *name); /* * Description: draws a button on the screen and keeps it's state up to date * -- cgit v1.2.3 From 488cf397922d42b59c88c0a028eca8c26c4e6293 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 10:11:42 +0200 Subject: some name changes --- gui.c | 12 ++++++------ gui.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gui.c b/gui.c index a1dc3431..ef31502f 100644 --- a/gui.c +++ b/gui.c @@ -2,7 +2,7 @@ static struct guiNode_t *firstGUI = NULL; -static uint16_t addNode(struct guiNode_t *newNode) { +static uint8_t addElement(struct guiNode_t *newNode) { struct guiNode_t *new; if(firstGUI == NULL) { @@ -29,7 +29,7 @@ static uint16_t addNode(struct guiNode_t *newNode) { return 1; } -static uint8_t deleteNode(char *name) { +static uint8_t deleteElement(char *name) { struct guiNode_t *pointer, *pointer1; if(firstGUI != NULL) { @@ -60,7 +60,7 @@ static uint8_t deleteNode(char *name) { return 0; // not successful } -void guiPrintNodes(BaseSequentialStream *chp) { +void guiPrintElements(BaseSequentialStream *chp) { struct guiNode_t *pointer = firstGUI; chprintf(chp, "\r\n\nguiNodes:\r\n\n"); @@ -152,7 +152,7 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * newNode->active = active; newNode->state = state; - if(addNode(newNode) != 1) + if(addElement(newNode) != 1) return 0; lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); @@ -179,7 +179,7 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_ newNode->active = active; newNode->orientation = orientation; - if(addNode(newNode) != 1) + if(addElement(newNode) != 1) return 0; lcdDrawRect(x0, y0, x1, y1, frame, frameColor); @@ -205,7 +205,7 @@ uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius newNode->active = active; newNode->state = value; - if(addNode(newNode) != 1) + if(addElement(newNode) != 1) return 0; // lcdDraw functions diff --git a/gui.h b/gui.h index 18251291..934c2bee 100644 --- a/gui.h +++ b/gui.h @@ -46,7 +46,7 @@ Thread *guiInit(uint16_t interval, tprio_t priority); * * return: none */ -void guiPrintNode(BaseSequentialStream *chp); +void guiPrintElements(BaseSequentialStream *chp); /* * Description: deletes a GUI element from the linked list -- cgit v1.2.3 From f332a1bb9f10c7dc767a920e8c5d268f656dd048 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 10:21:54 +0200 Subject: fix --- gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.c b/gui.c index ef31502f..c5d2c49c 100644 --- a/gui.c +++ b/gui.c @@ -132,7 +132,7 @@ Thread *guiInit(uint16_t interval, tprio_t priority) { } uint8_t guiDeleteElement(char *name) { - return deleteNode(name); + return deleteElement(name); } uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *name, uint8_t *active, uint8_t *state) { -- cgit v1.2.3 From 57a68c85d50451789450c57720d6d4a25e9f31a2 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 10:23:42 +0200 Subject: name -> label --- gui.c | 26 +++++++++++++------------- gui.h | 12 ++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gui.c b/gui.c index c5d2c49c..70e1dc8a 100644 --- a/gui.c +++ b/gui.c @@ -29,11 +29,11 @@ static uint8_t addElement(struct guiNode_t *newNode) { return 1; } -static uint8_t deleteElement(char *name) { +static uint8_t deleteElement(char *label) { struct guiNode_t *pointer, *pointer1; if(firstGUI != NULL) { - if(strcmp(firstGUI->name, name) == 0) { + if(strcmp(firstGUI->label, label) == 0) { pointer = firstGUI->next; chHeapFree(firstGUI); firstGUI = pointer; @@ -43,7 +43,7 @@ static uint8_t deleteElement(char *name) { while(pointer->next != NULL) { pointer1 = pointer->next; - if(strcmp(firstGUI->name, name) == 0) { + if(strcmp(firstGUI->label, label) == 0) { pointer->next = pointer1->next; chHeapFree(pointer1); break; @@ -70,7 +70,7 @@ void guiPrintElements(BaseSequentialStream *chp) { 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, "name: %s\r\n", pointer->name); + 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); @@ -131,11 +131,11 @@ Thread *guiInit(uint16_t interval, tprio_t priority) { return tp; } -uint8_t guiDeleteElement(char *name) { - return deleteElement(name); +uint8_t guiDeleteElement(char *label) { + return deleteElement(label); } -uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *name, uint8_t *active, uint8_t *state) { +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *label, uint8_t *active, uint8_t *state) { struct guiNode_t *newNode; newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t)); @@ -143,12 +143,12 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * return 0; newNode->type = button; - newNode->name = name; + newNode->label = label; newNode->x0 = x0; newNode->y0 = y0; newNode->x1 = x1; newNode->y1 = y1; - newNode->name = str; + newNode->label = str; newNode->active = active; newNode->state = state; @@ -162,7 +162,7 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * return 1; } -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 *name, uint8_t *active, uint8_t *value) { +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)); @@ -170,7 +170,7 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_ return 0; newNode->type = slider; - newNode->type = name; + newNode->type = label; newNode->x0 = x0; newNode->y0 = y0; newNode->x1 = x1; @@ -189,7 +189,7 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_ return 1; } -uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *name, 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) { struct guiNode_t *newNode; newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t)); @@ -197,7 +197,7 @@ uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius return 0; newNode->type = wheel; - newNode->name = name; + newNode->label = label; newNode->x0 = x0; newNode->y0 = y0; newNode->r1 = radius1; diff --git a/gui.h b/gui.h index 934c2bee..61dead64 100644 --- a/gui.h +++ b/gui.h @@ -17,7 +17,7 @@ static struct guiNode_t { uint8_t orientation; uint8_t *active; uint8_t *state; - char *name; + char *label; struct guiNode_t *next; }; @@ -51,11 +51,11 @@ void guiPrintElements(BaseSequentialStream *chp); /* * Description: deletes a GUI element from the linked list * - * param: - name: name of the element (parameter of each guiDrawXXX function) + * param: - label: label of the element (parameter of each guiDrawXXX function) * * return: 1 if successful, 0 otherwise */ -uint8_t guiDeleteElement(char *name); +uint8_t guiDeleteElement(char *label); /* * Description: draws a button on the screen and keeps it's state up to date * @@ -68,11 +68,11 @@ uint8_t guiDeleteElement(char *name); * * return: 1 if button successfully created */ -uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *name, uint8_t *active, uint8_t *state); +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, 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 *name, uint8_t *active, uint8_t *value); +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 *name, 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 } -- cgit v1.2.3 From de84bc984cd8e7937d2722e672b6f1f35ca0b985 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 10:29:00 +0200 Subject: example code update --- demos/gui/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/demos/gui/main.c b/demos/gui/main.c index d37c993c..16fdc14e 100755 --- a/demos/gui/main.c +++ b/demos/gui/main.c @@ -54,8 +54,13 @@ int main(void) { clearActive = active; // draw a button to set, and one to clear the LED - guiDrawButton(10, 10, 60, 60, "Set", Black, Yellow, &setActive, &setState); - guiDrawButton(70, 10, 120, 60, "Clear", Black, Red, &clearActive, &clearState); + 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) { -- cgit v1.2.3 From 2c95af7413e3d97e3683876a8e201e4a408f5f2b Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 11:12:45 +0200 Subject: added shadow support for buttons --- gui.c | 10 +++++++++- gui.h | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 70e1dc8a..8b3ba893 100644 --- a/gui.c +++ b/gui.c @@ -135,8 +135,9 @@ uint8_t guiDeleteElement(char *label) { return deleteElement(label); } -uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, char *label, uint8_t *active, uint8_t *state) { +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, 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) @@ -157,6 +158,13 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); + if(shadow != 0) { + for(i = 0; i < shadow; i++) { + lcdDrawLine(x1+i, y0-i, x1+i, y1-i-1, Black); + lcdDrawLine(x0+i, y0-i, x1+i, y0-i, Black); + } + } + chHeapFree(newNode); return 1; diff --git a/gui.h b/gui.h index 61dead64..513043aa 100644 --- a/gui.h +++ b/gui.h @@ -63,12 +63,13 @@ uint8_t guiDeleteElement(char *label); * - 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, uint16_t fontColor, uint16_t buttonColor, char *label, uint8_t *active, uint8_t *state); +uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, 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); -- cgit v1.2.3 From 3ada10d048fd388394882afc886071764a592690 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 11:41:38 +0200 Subject: shadowing fix --- gui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 8b3ba893..4b690d58 100644 --- a/gui.c +++ b/gui.c @@ -160,8 +160,8 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char * if(shadow != 0) { for(i = 0; i < shadow; i++) { - lcdDrawLine(x1+i, y0-i, x1+i, y1-i-1, Black); - lcdDrawLine(x0+i, y0-i, x1+i, y0-i, Black); + lcdDrawLine(x0+shadow, y1+i, x1+shadow-1, y1+i, Black); + lcdDrawLine(x1+i, y0+shadow, x1+i, y1+shadow-1, Black); } } -- cgit v1.2.3 From 3a5be9c67812c2ef16f335078f2ec8e8773d2144 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 27 Jun 2012 15:43:49 +0200 Subject: small fix --- gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.c b/gui.c index 4b690d58..945606e7 100644 --- a/gui.c +++ b/gui.c @@ -190,7 +190,7 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_ if(addElement(newNode) != 1) return 0; - lcdDrawRect(x0, y0, x1, y1, frame, frameColor); + // lcdDraw functions chHeapFree(newNode); -- cgit v1.2.3