From 7b10e441c81809d724aa58bf63da51bf26766b7a Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 17 Aug 2012 09:10:10 +0200 Subject: [PATCH 01/14] touchpad demo update --- demos/touchpad/main.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/demos/touchpad/main.c b/demos/touchpad/main.c index 52f52e83..e55c195b 100644 --- a/demos/touchpad/main.c +++ b/demos/touchpad/main.c @@ -23,8 +23,19 @@ #include "gdisp.h" #include "touchpad.h" -TOUCHPADDriver TOUCHPADD1 = { - &SPID1, +static const SPIConfig spicfg = { + NULL, // no callback + GPIOC, // CS PORT + 6, // CS PIN + SPI_CR1_BR_1 | SPI_CR1_BR_0, +}; + +TOUCHPADDriver TOUCHPADD1 = { + &SPID1, // SPI driver + &spicfg, // SPI config + GPIO, // IRQ PORT + 4, // IRQ PIN + TRUE // start SPI }; int main(void) { @@ -32,15 +43,14 @@ int main(void) { chSysInit(); gdispInit(); - gdispClear(Lime); tpInit(&TOUCHPADD1); tpCalibrate(); - gdispClear(Lime); + gdispClear(Black); while (TRUE) { - gdispDrawFillCircle(tpReadX(), tpReadY(), 3, Black); + gdispDrawPixel(tpReadX(), tpReadY(), Green); } } From 7bfaea1ca9fbb37472a822c21765739a514a2a80 Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 17 Aug 2012 09:23:15 +0200 Subject: [PATCH 02/14] readme updates --- drivers/gdisp/Nokia6610/readme.txt | 3 +-- drivers/gdisp/S6D1121/readme.txt | 3 +-- drivers/gdisp/SSD1289/readme.txt | 3 +-- drivers/gdisp/TestStub/readme.txt | 3 +-- drivers/touchpad/ADS7843/readme.txt | 3 +-- drivers/touchpad/XPT2046/readme.txt | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/gdisp/Nokia6610/readme.txt b/drivers/gdisp/Nokia6610/readme.txt index facb400f..926f2d3f 100644 --- a/drivers/gdisp/Nokia6610/readme.txt +++ b/drivers/gdisp/Nokia6610/readme.txt @@ -13,5 +13,4 @@ To use this driver: Olimex SAM7-EX256 2. To your makefile add the following lines: - include $(CHIBIOS)/os/halext/halext.mk - include $(CHIBIOS)/os/halext/drivers/gdispXXXXX/gdisp_lld.mk + include $(LCDLIB)/drivers/gdisp/Nokia6610/gdisp_lld.mk diff --git a/drivers/gdisp/S6D1121/readme.txt b/drivers/gdisp/S6D1121/readme.txt index fc24d4a2..9db0786f 100644 --- a/drivers/gdisp/S6D1121/readme.txt +++ b/drivers/gdisp/S6D1121/readme.txt @@ -12,5 +12,4 @@ To use this driver: #define SCREEN_HEIGHT 240 2. To your makefile add the following lines: - include $(CHIBIOS)/os/halext/halext.mk - include $(CHIBIOS)/os/halext/drivers/gdispS6d1121/gdisp_lld.mk + include $(LCDLIB)/drivers/gdisp/S6D1121/gdisp_lld.mk diff --git a/drivers/gdisp/SSD1289/readme.txt b/drivers/gdisp/SSD1289/readme.txt index 17d22223..1b64b46d 100644 --- a/drivers/gdisp/SSD1289/readme.txt +++ b/drivers/gdisp/SSD1289/readme.txt @@ -12,5 +12,4 @@ To use this driver: #define SCREEN_HEIGHT 240 2. To your makefile add the following lines: - include $(CHIBIOS)/os/halext/halext.mk - include $(CHIBIOS)/os/halext/drivers/gdispSsd1289/gdisp_lld.mk + include $(LCDLIB)/drivers/gdisp/SSD1289/gdisp_lld.mk diff --git a/drivers/gdisp/TestStub/readme.txt b/drivers/gdisp/TestStub/readme.txt index 83611acf..73120dfa 100644 --- a/drivers/gdisp/TestStub/readme.txt +++ b/drivers/gdisp/TestStub/readme.txt @@ -13,5 +13,4 @@ To use this driver: you want to compile test eg: GDISP_NEED_MULTITHREAD 2. To your makefile add the following lines: - include $(CHIBIOS)/os/halext/halext.mk - include $(CHIBIOS)/os/halext/drivers/gdispTestStub/gdisp_lld.mk + include $(LCDLIB)/drivers/gdisp/TestStub/gdisp_lld.mk diff --git a/drivers/touchpad/ADS7843/readme.txt b/drivers/touchpad/ADS7843/readme.txt index 34a57bc0..6e62bf39 100644 --- a/drivers/touchpad/ADS7843/readme.txt +++ b/drivers/touchpad/ADS7843/readme.txt @@ -4,6 +4,5 @@ To use this driver: a) #define HAL_USE_TOUCHPAD TRUE 2. To your makefile add the following lines: - include $(LCDLIB)/lcd.mk - include $(LCDLIB)/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.mk + include $(LCDLIB)/drivers/touchpadADS7843/touchpad_lld.mk diff --git a/drivers/touchpad/XPT2046/readme.txt b/drivers/touchpad/XPT2046/readme.txt index 992d346d..e24ec768 100644 --- a/drivers/touchpad/XPT2046/readme.txt +++ b/drivers/touchpad/XPT2046/readme.txt @@ -4,6 +4,5 @@ To use this driver: a) #define HAL_USE_TOUCHPAD TRUE 2. To your makefile add the following lines: - include $(LCDLIB)/lcd.mk - include $(LCDLIB)/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk + include $(LCDLIB)/drivers/touchpad/XPT2046/touchpad_lld.mk From f9dd7d52f4061bcea2b6f99bb6530119f0432012 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 20 Aug 2012 20:43:39 +0200 Subject: [PATCH 03/14] coord_t from uint16_t to int16_t --- include/gdisp_lld.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gdisp_lld.h b/include/gdisp_lld.h index 99865a9f..91485455 100644 --- a/include/gdisp_lld.h +++ b/include/gdisp_lld.h @@ -501,7 +501,7 @@ /** * @brief The type for a coordinate or length on the screen. */ -typedef uint16_t coord_t; +typedef int16_t coord_t; /** * @brief The type of a pixel. */ From bb6bad936a38b8ec893cc4a51cb2dcff95352c56 Mon Sep 17 00:00:00 2001 From: Tectu Date: Mon, 20 Aug 2012 21:01:50 +0200 Subject: [PATCH 04/14] removed deviceCode readout of SSD1289 --- drivers/gdisp/SSD1289/gdisp_lld.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/gdisp/SSD1289/gdisp_lld.c b/drivers/gdisp/SSD1289/gdisp_lld.c index 39c7334c..f9a25d84 100644 --- a/drivers/gdisp/SSD1289/gdisp_lld.c +++ b/drivers/gdisp/SSD1289/gdisp_lld.c @@ -73,8 +73,6 @@ * @notapi */ bool_t GDISP_LLD(init)(void) { - uint16_t deviceCode; - #ifdef LCD_USE_FSMC /* FSMC setup. TODO: this only works for STM32F1 */ rccEnableAHB(RCC_AHBENR_FSMCEN, 0); @@ -94,8 +92,6 @@ bool_t GDISP_LLD(init)(void) { FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN; #endif - deviceCode = lld_lcdReadReg(0x0000); - lld_lcdWriteReg(0x0000,0x0001); lld_lcdDelay(5); lld_lcdWriteReg(0x0003,0xA8A4); lld_lcdDelay(5); lld_lcdWriteReg(0x000C,0x0000); lld_lcdDelay(5); From 4238378e9029d1ef26e48b7ec742467f7df4b7d7 Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 21 Aug 2012 18:18:02 +0200 Subject: [PATCH 05/14] added old glcd.h header backport --- include/glcd.h | 136 ------------------------------------------------- lcd.mk | 2 +- 2 files changed, 1 insertion(+), 137 deletions(-) delete mode 100644 include/glcd.h diff --git a/include/glcd.h b/include/glcd.h deleted file mode 100644 index ab2f6be2..00000000 --- a/include/glcd.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2012 - Joel Bodenmann aka Tectu - - This file is part of ChibiOS-LCD-Driver. - - ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS-LCD-Driver is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/* - This file is an emulation of the GLCD interface using the - new GDISP interface. It is probably not a perfect replica, - some code changes may be necessary. - Note it does not replicate the GLCD low level driver, just - the high level interface. - You may also need to define the various GDISP_NEED_XXX in your - halconf.h in order to turn on the functionality you need. -*/ - -#ifndef GLCD_H -#define GLCD_H - -#include "ch.h" -#include "hal.h" -#include "gdisp.h" - -#define PORTRAIT (lcdGetOrientation() == portrait || lcdGetOrientation() == portraitInv) -#define LANDSCAPE (lcdGetOrientation() == landscape || lcdGetOrientation() == landscapeInv) - -#define RGB565CONVERT(r, g, b) RGB2COLOR(r,g,b) - -enum filled {frame, filled}; -enum transparency {solid, transparent}; -#define sleepOn powerSleep -#define sleepOff powerOn - -#define font_Small (&fontSmall) -#define font_SmallDouble (&fontSmallDouble) -#define font_SmallNarrow (&fontSmall) -#define font_Larger (&fontLarger) -#define font_LargerDouble (&fontLargerDouble) -#define font_LargerNarrow (&fontLargerNarrow) -#define font_MediumBold (&fontUI1) -#define font_MediumBoldDouble (&fontUI1Double) -#define font_MediumBoldNarrow (&fontUI1Narrow) -#define font_LargeNumbers (&fontLargeNumbers) -#define font_LargeNumbersDouble (&fontLargeNumbersDouble) -#define font_LargeNumbersNarrow (&fontLargeNumbersNarrow) - -enum glcd_result { GLCD_DONE, - GLCD_FAILED, - GLCD_PROGRESS, - }; - -typedef enum glcd_result glcd_result_t; - -/* Core functions */ -#define lcdInit(dvr) gdispInit(dvr) -static __inline glcd_result_t lcdClear(color_t color) { - gdispClear(color); - return GLCD_DONE; -} -static __inline glcd_result_t lcdSetOrientation(enum orientation newO) { - gdispControl(GDISP_CONTROL_ORIENTATION, (void *)(int)newO); - return ((enum orientation)(unsigned)gdispQuery(GDISP_QUERY_ORIENTATION)) == (newO) ? GLCD_DONE : GLCD_FAILED; -} -static __inline glcd_result_t lcdFillArea(coord_t x0, coord_t y0, coord_t x1, coord_t y1,color_t c) { - gdispFillArea((x0),(y0),(x1)-(x0)+1,(y1)-(y0)+1,(c)); - return GLCD_DONE; -} -static __inline glcd_result_t lcdWriteArea(coord_t x0, coord_t y0, coord_t x1, coord_t y1, const pixel_t *b, coord_t n) { - (void)n; - gdispBlitArea((x0),(y0),(x1)-(x0)+1,(y1)-(y0)+1,(b)); - return GLCD_DONE; -} -static __inline glcd_result_t lcdSetPowerMode(enum powermode pm) { - gdispControl(GDISP_CONTROL_POWER, (void *)(int)pm); - return ((enum powermode)(unsigned)gdispQuery(GDISP_QUERY_POWER)) == (pm) ? GLCD_DONE : GLCD_FAILED; -} - -/* Drawing functions */ -static __inline glcd_result_t lcdDrawPixel(coord_t x, coord_t y, color_t c) { - gdispDrawPixel((x),(y),(c)); - return GLCD_DONE; -} -#define lcdDrawLine(x0,y0,x1,y1,c) gdispDrawLine((x0),(y0),(x1),(y1),(c)) -#define lcdDrawRect(x0,y0,x1,y1,f,c) {if(f) gdispFillArea((x0),(y0),(x1)-(x0)+1,(y1)-(y0)+1,(c)); else gdispDrawBox((x0),(y0),(x1)-(x0)+1,(y1)-(y0)+1,(c));} -#define lcdDrawRectString(x0,y0,x1,y1,s,f,c,b) gdispFillStringBox((x0),(y0),(x1)-(x0)+1,(y1)-(y0)+1,(s),(f),(c),(b),justifyLeft) -#define lcdDrawCircle(x,y,r,f,c) {if(f) gdispFillCircle((x),(y),(r),(c)); else gdispDrawCircle((x),(y),(r),(c));} -#define lcdDrawEllipse(x,y,a,b,f,c) {if(f) gdispFillEllipse((x),(y),(a),(b),(c)); else gdispDrawEllipse((x),(y),(a),(b),(c));} - -/* Text Rendering Functions */ -static __inline coord_t lcdDrawChar(coord_t x, coord_t y, char h, font_t f, color_t c, color_t b, bool_t t) { - if (t) - gdispDrawChar((x),(y),(h),(f),(c)); - else - gdispFillChar((x),(y),(h),(f),(c),(b)); - return gdispGetCharWidth((h),(f))+gdispGetFontMetric((f), fontCharPadding); -} -static __inline coord_t lcdDrawString(coord_t x, coord_t y, const char *s, font_t f, color_t c, color_t b, bool_t t) { - if (t) - gdispDrawString((x),(y),(s),(f),(c)); - else - gdispFillString((x),(y),(s),(f),(c),(b)); - return gdispGetStringWidth((s),(f))+gdispGetFontMetric((f), fontCharPadding); -} - -/* Character measuring functions */ -#define lcdMeasureChar(h,f) (gdispGetCharWidth((h),(f))+gdispGetFontMetric((f), fontCharPadding)) -#define lcdMeasureString(s,f) (gdispGetStringWidth((s),(f))+gdispGetFontMetric((f), fontCharPadding)) -#define lcdGetFontHeight(f) gdispGetFontMetric((f), fontHeight) - -/* Size and orientation related */ -#define lcdGetHeight() ((coord_t)(unsigned)gdispQuery(GDISP_QUERY_HEIGHT)) -#define lcdGetWidth() ((coord_t)(unsigned)gdispQuery(GDISP_QUERY_WIDTH)) -#define lcdGetOrientation() ((enum orientation)(unsigned)gdispQuery(GDISP_QUERY_ORIENTATION)) - -/* BGR->RGB and pixel readback */ -#define lcdBGR2RGB(c) RGB2COLOR(BLUE_OF(c),GREEN_OF(c),RED_OF(c)) -#define lcdGetPixelColor(x,y) gdispGetPixelColor((x),(y)) - -/* Scrolling function */ -#define lcdVerticalScroll(x0,y0,x1,y1,l) gdispVerticalScroll((x0),(y0),(x1)-(x0)+1,(y1)-(y0)+1,l,Black) - -#endif diff --git a/lcd.mk b/lcd.mk index b2e7d784..f47f8524 100644 --- a/lcd.mk +++ b/lcd.mk @@ -6,6 +6,6 @@ endif LCDSRC += $(LCDLIB)/src/gdisp.c \ $(LCDLIB)/src/gdisp_fonts.c \ $(LCDLIB)/src/touchpad.c \ - $(LCDLIB)/src/console.c + #$(LCDLIB)/src/console.c \ LCDINC += $(LCDLIB)/include From 7021da1b9e5306db27f8b7c86d75c82652dfb8c0 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 22 Aug 2012 10:05:38 +0200 Subject: [PATCH 06/14] gdispSetOrientation() bugfix (by inmarket) --- include/gdisp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gdisp.h b/include/gdisp.h index b5a59cf9..61f851cc 100644 --- a/include/gdisp.h +++ b/include/gdisp.h @@ -245,7 +245,7 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); /* Macro definitions for common gets and sets */ #define gdispSetPowerMode(powerMode) gdispControl(GDISP_CONTROL_POWER, (void *)(unsigned)(powerMode)) -#define gdispSetOrientation(newOrientation) gdispControl(GDISP_CONTROL_ORITENTATION, (void *)(unsigned)(newOrientation)) +#define gdispSetOrientation(newOrientation) gdispControl(GDISP_CONTROL_ORIENTATION, (void *)(unsigned)(newOrientation)) #define gdispSetBacklight(percent) gdispControl(GDISP_CONTROL_BACKLIGHT, (void *)(unsigned)(percent)) #define gdispSetContrast(percent) gdispControl(GDISP_CONTROL_CONTRAST, (void *)(unsigned)(percent)) From 217f15b4d34c19c87a2c188240f26ae1d50ee659 Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 22 Aug 2012 16:06:43 +0200 Subject: [PATCH 07/14] compiler warning fix --- drivers/gdisp/SSD1289/ssd1289_lld.c.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gdisp/SSD1289/ssd1289_lld.c.h b/drivers/gdisp/SSD1289/ssd1289_lld.c.h index 7c0fade2..319013cc 100644 --- a/drivers/gdisp/SSD1289/ssd1289_lld.c.h +++ b/drivers/gdisp/SSD1289/ssd1289_lld.c.h @@ -96,6 +96,8 @@ dummy = lld_lcdReadData(); for(i = 0; i < size; i++) buffer[i] = lld_lcdReadData(); + + (void)dummy; } #elif defined(LCD_USE_FSMC) From bee96e39ad908f1bcee57320c9764dd2ec63bead Mon Sep 17 00:00:00 2001 From: Tectu Date: Wed, 22 Aug 2012 16:33:40 +0200 Subject: [PATCH 08/14] fixed touchpad orientation --- src/touchpad.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/touchpad.c b/src/touchpad.c index a18930da..44d5f426 100644 --- a/src/touchpad.c +++ b/src/touchpad.c @@ -158,8 +158,7 @@ uint16_t tpReadX(void) { x = cal.xm * _tpReadRealX() + cal.xn; y = cal.ym * _tpReadRealY() + cal.yn; - /* - switch(gdispGetOrientation()) { // implement gdispGetOrientation() + switch(gdispGetOrientation()) { case portrait: return x; case landscape: @@ -169,9 +168,6 @@ uint16_t tpReadX(void) { case landscapeInv: return y; } - */ - - return x; } /** @@ -187,8 +183,7 @@ uint16_t tpReadY(void) { x = cal.xm * _tpReadRealX() + cal.xn; y = cal.ym * _tpReadRealY() + cal.yn; - /* - switch(gdispGetOrientation()) { // implement gdispGetOrientation() + switch(gdispGetOrientation()) { case portrait: return y; case landscape: @@ -198,9 +193,6 @@ uint16_t tpReadY(void) { case landscapeInv: return SCREEN_WIDTH - x; } - */ - - return y; } void tpCalibrate(void) { From a7f5b7433e5a7c8ab8fd70cff0d26a1de2d66ccc Mon Sep 17 00:00:00 2001 From: Tectu Date: Thu, 23 Aug 2012 15:36:43 +0200 Subject: [PATCH 09/14] added notepad demo --- demos/notepad/main.c | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 demos/notepad/main.c diff --git a/demos/notepad/main.c b/demos/notepad/main.c new file mode 100755 index 00000000..65247b09 --- /dev/null +++ b/demos/notepad/main.c @@ -0,0 +1,103 @@ +#include "ch.h" +#include "hal.h" +#include "gdisp.h" +#include "touchpad.h" + +#define COLOR_SIZE 20 +#define PEN_SIZE 20 +#define OFFSET 3 + +#define COLOR_BOX(a) (x >= a && x <= a + COLOR_SIZE) +#define PEN_BOX(a) (y >= a && y <= a + COLOR_SIZE) +#define GET_COLOR(a) (COLOR_BOX(a * COLOR_SIZE + OFFSET)) +#define GET_PEN(a) (PEN_BOX(a * 2 * PEN_SIZE + OFFSET)) +#define DRAW_COLOR(a) (a * COLOR_SIZE + OFFSET) +#define DRAW_PEN(a) (a * 2 * PEN_SIZE + OFFSET) +#define DRAW_AREA(x, y) (x >= PEN_SIZE + OFFSET + 3 && x <= gdispGetWidth() && \ + y >= COLOR_SIZE + OFFSET + 3 && y <= gdispGetHeight()) + +static const SPIConfig spicfg = { + NULL, + TP_CS_PORT, + TP_CS, + /* SPI_CR1_BR_2 | */ SPI_CR1_BR_1 | SPI_CR1_BR_0, +}; + +TOUCHPADDriver TOUCHPADD1 = { + &SPID1, + &spicfg, + TP_IRQ_PORT, + TP_IRQ, + TRUE +}; + +void drawScreen(void) { + char *msg = "ChibiOS/GFX"; + uint16_t colorsize = COLOR_SIZE; + uint16_t pensize = PEN_SIZE; + + gdispSetOrientation(landscape); + gdispClear(White); + gdispDrawString(gdispGetWidth()-gdispGetStringWidth(msg, &fontUI2Double)-3, 3, msg, &fontUI2Double, Black); + + /* colors */ + gdispFillArea(0 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* Black */ + gdispFillArea(1 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Red); /* Red */ + gdispFillArea(2 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Yellow); /* Yellow */ + gdispFillArea(3 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Green); /* Green */ + gdispFillArea(4 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Blue); /* Blue */ + gdispDrawBox (5 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* White */ + + /* pens */ + gdispDrawString(OFFSET * 2, DRAW_PEN(1), "1", &fontLargeNumbers, Black); + gdispDrawString(OFFSET * 2, DRAW_PEN(2), "2", &fontLargeNumbers, Black); + gdispDrawString(OFFSET * 2, DRAW_PEN(3), "3", &fontLargeNumbers, Black); + gdispDrawString(OFFSET * 2, DRAW_PEN(4), "4", &fontLargeNumbers, Black); + gdispDrawString(OFFSET * 2, DRAW_PEN(5), "5", &fontLargeNumbers, Black); +} + +int main(void) { + volatile uint16_t x, y; + color_t color = Black; + uint16_t pen = 0; + + halInit(); + chSysInit(); + + gdispInit(); + tpInit(&TOUCHPADD1); + tpCalibrate(); + + drawScreen(); + + while (TRUE) { + x = tpReadX(); + y = tpReadY(); + + /* inside color box ? */ + if(y >= OFFSET && y <= COLOR_SIZE) { + if(GET_COLOR(0)) color = Black; + else if(GET_COLOR(1)) color = Red; + else if(GET_COLOR(2)) color = Yellow; + else if(GET_COLOR(3)) color = Green; + else if(GET_COLOR(4)) color = Blue; + else if(GET_COLOR(5)) color = White; + + /* inside pen box ? */ + } else if(x >= OFFSET && x <= PEN_SIZE) { + if(GET_PEN(1)) pen = 0; + else if(GET_PEN(2)) pen = 1; + else if(GET_PEN(3)) pen = 2; + else if(GET_PEN(4)) pen = 3; + else if(GET_PEN(5)) pen = 4; + + /* inside drawing area ? */ + } else if(DRAW_AREA(x, y)) { + if(pen == 0) + gdispDrawPixel(x, y, color); + else + gdispFillCircle(x, y, pen, color); + } + } +} + From fcfab985179f1a336c52bdbc03ac587767124708 Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 24 Aug 2012 02:35:28 +0200 Subject: [PATCH 10/14] added gdispDrawArc() and gdispFillArc() dummies --- include/gdisp.h | 2 ++ src/gdisp.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/gdisp.h b/include/gdisp.h index 61f851cc..9e856aa9 100644 --- a/include/gdisp.h +++ b/include/gdisp.h @@ -227,6 +227,8 @@ extern "C" { #endif void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); +void gdispDrawArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color); +void gdispFillArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color); /* Extra Text Functions */ #if GDISP_NEED_TEXT diff --git a/src/gdisp.c b/src/gdisp.c index ee2b98e4..6cf58561 100644 --- a/src/gdisp.c +++ b/src/gdisp.c @@ -28,6 +28,7 @@ #include "ch.h" #include "hal.h" #include "gdisp.h" +#include #ifndef _GDISP_C #define _GDISP_C @@ -658,6 +659,38 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { } } +/* + * @brief Draw an arc. + * @pre The GDISP must be in powerOn or powerSleep mode. + * + * @param[in] x0,y0 The center point + * @param[in] radius The radius of the arc + * @param[in] start The start angle (0 to 360) + * @param[in] end The end angle (0 to 360) + * @param[in] color The color of the arc + * + * @api + */ +void gdispDrawArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color) { + +} + +/* + * @brief Draw a filled arc. + * @pre The GDISP must be in powerOn or powerSleep mode. + * + * @param[in] x0,y0 The center point of the filled arc + * @param[in] radius The radius of the filled arc + * @param[in] start The start angle (0 to 360) + * @param[in] end The end angle (0 to 360) + * @param[in] color The color of the filled arc + * + * @api + */ +void gdispFillArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color) { + +} + #if GDISP_NEED_TEXT || defined(__DOXYGEN__) /** * @brief Draw a text string. From ca8a2f3e1151239afbe0513d40e3a15be04dc1fa Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 24 Aug 2012 10:37:12 +0200 Subject: [PATCH 11/14] makefile fix --- lcd.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcd.mk b/lcd.mk index f47f8524..646fc1da 100644 --- a/lcd.mk +++ b/lcd.mk @@ -6,6 +6,6 @@ endif LCDSRC += $(LCDLIB)/src/gdisp.c \ $(LCDLIB)/src/gdisp_fonts.c \ $(LCDLIB)/src/touchpad.c \ - #$(LCDLIB)/src/console.c \ + $(LCDLIB)/src/console.c \ LCDINC += $(LCDLIB)/include From a0162b98c892726da2ba33f3fbde9a16cdb75911 Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 24 Aug 2012 10:43:09 +0200 Subject: [PATCH 12/14] fixed SSD1289 driver --- drivers/gdisp/SSD1289/gdisp_lld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gdisp/SSD1289/gdisp_lld.c b/drivers/gdisp/SSD1289/gdisp_lld.c index f9a25d84..5f017b37 100644 --- a/drivers/gdisp/SSD1289/gdisp_lld.c +++ b/drivers/gdisp/SSD1289/gdisp_lld.c @@ -480,7 +480,7 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { } #endif -#if GDISP_HARDWARE_CONTROL || defined(__DOXYGEN__) +#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__) /** * @brief Driver Control * @detail Unsupported control codes are ignored. From 580c00b8f89ef775636f59e26a36aec7d44c7c5c Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 24 Aug 2012 11:37:47 +0200 Subject: [PATCH 13/14] console patch (thanks to inmarket for helping) --- src/console.c | 355 +++++++++++++++++++++++++------------------------- 1 file changed, 180 insertions(+), 175 deletions(-) diff --git a/src/console.c b/src/console.c index e5f2371c..7805ff2e 100644 --- a/src/console.c +++ b/src/console.c @@ -1,175 +1,180 @@ -/* - ChibiOS/RT - Copyright (C) 2012 - Joel Bodenmann aka Tectu - - This file is part of ChibiOS-LCD-Driver. - - ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS-LCD-Driver is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "ch.h" -#include "hal.h" - -#include "gdisp.h" -#include "gdisp_fonts.h" -#include "console.h" - -#if defined(GDISP_NEED_SCROLL) - -/* - * Interface implementation. The interface is write only - */ -static size_t writes(void *ip, const uint8_t *bp, size_t n) { - return lcdConsoleWrite((GLCDConsole *)ip, bp, n); -} - -static size_t reads(void *ip, uint8_t *bp, size_t n) { - (void)ip; - (void)bp; - (void)n; - - return 0; -} - -static msg_t put(void *ip, uint8_t b) { - return lcdConsolePut((GLCDConsole *)ip, (char)b); -} - -static msg_t get(void *ip) { - (void)ip; - - return RDY_OK; -} - -static msg_t putt(void *ip, uint8_t b, systime_t timeout) { - (void)timeout; - - /* TODO: handle timeout */ - - return lcdConsolePut((GLCDConsole *)ip, (char)b); -} - -static msg_t gett(void *ip, systime_t timeout) { - (void)ip; - (void)timeout; - - return RDY_OK; -} - -static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { - (void)time; - - return lcdConsoleWrite((GLCDConsole *)ip, bp, n); -} - -static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { - (void)ip; - (void)bp; - (void)n; - (void)time; - - return 0; -} - -static uint16_t getflags(void *ip) { - _chn_get_and_clear_flags_impl(ip); -} - -static const struct GLCDConsoleVMT vmt = { - writes, reads, put, get, - putt, gett, writet, readt, - getflags -}; - - -msg_t lcdConsoleInit(GLCDConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) { - const uint8_t* ptr; - uint16_t chi; - uint16_t x,y; - - console->vmt = &vmt; - /* read font, get height */ - console->fy = font->height; - - /* calculate the size of the console as an integer multiple of characters height*/ - console->sx = width; - console->sy = (((int16_t)(height/console->fy))-1)*console->fy; - - console->cx = 0; - console->cy = 0; - console->x0 = x0; - console->y0 = y0; - - console->bkcolor = bkcolor; - console->color = color; - - console->font = font; - - gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor); - return RDY_OK; -} - -msg_t lcdConsolePut(GLCDConsole *console, char c) { - uint8_t width; - - if(c == '\n') { - /* clear the text at the end of the line */ - if(console->cx < console->sx) - gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, - console->x0 + console->sx, console->y0 + console->cy + console->fy, - console->bkcolor); - console->cx = 0; - console->cy += console->fy; - } else if(c == '\r') { - /* TODO: work backwards through the buffer to the start of the current line */ - //console->cx = 0; - } else { - width = _getCharWidth(console->font, c); - if((console->cx + width) >= console->sx) { - /* clear the text at the end of the line */ - gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, - console->x0 + console->cx + width, console->y0 + console->cy + console->fy, - console->bkcolor); - console->cx = 0; - console->cy += console->fy; - } - - if((console->cy > console->sy)) { - /* scroll the screen */ - gdispVerticalScroll(console->x0, console->y0, console->x0 + console->sx, - console->y0 + console->sy + console->fy, console->fy, console->bkcolor); - /* reset the cursor */ - console->cx = 0; - console->cy = console->sy; - } - - gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c, - console->font, console->color); - - /* update cursor */ - console->cx += width; - } - return RDY_OK; -} - -msg_t lcdConsoleWrite(GLCDConsole *console, char *bp, size_t n) { - size_t i; - for(i = 0; i < n; i++) - lcdConsolePut(console, bp[i]); - - return RDY_OK; -} - - -#endif /* GDISP_NEED_SCROLL */ +/* + ChibiOS/RT - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS-LCD-Driver. + + ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS-LCD-Driver is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "ch.h" +#include "hal.h" + +#include "gdisp.h" +#include "console.h" + +/* + * Interface implementation. The interface is write only + */ +static size_t writes(void *ip, const uint8_t *bp, size_t n) { + return lcdConsoleWrite((GLCDConsole *)ip, bp, n); +} + +static size_t reads(void *ip, uint8_t *bp, size_t n) { + (void)ip; + (void)bp; + (void)n; + + return 0; +} + +static msg_t put(void *ip, uint8_t b) { + return lcdConsolePut((GLCDConsole *)ip, (char)b); +} + +static msg_t get(void *ip) { + (void)ip; + + return RDY_OK; +} + +static msg_t putt(void *ip, uint8_t b, systime_t timeout) { + (void)timeout; + + /* TODO: handle timeout */ + + return lcdConsolePut((GLCDConsole *)ip, (char)b); +} + +static msg_t gett(void *ip, systime_t timeout) { + (void)ip; + (void)timeout; + + return RDY_OK; +} + +static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { + (void)time; + + return lcdConsoleWrite((GLCDConsole *)ip, bp, n); +} + +static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { + (void)ip; + (void)bp; + (void)n; + (void)time; + + return 0; +} + +static uint16_t getflags(void *ip) { + _chn_get_and_clear_flags_impl(ip); +} + +static const struct GLCDConsoleVMT vmt = { + writes, reads, put, get, + putt, gett, writet, readt, + getflags +}; + + +msg_t lcdConsoleInit(GLCDConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) { + const uint8_t* ptr; + uint16_t chi; + uint16_t x,y; + + console->vmt = &vmt; + /* read font, get height */ + console->fy = gdispGetFontMetric(font, fontHeight); + + /* calculate the size of the console as an integer multiple of characters height*/ + console->sx = width; + console->sy = (((int16_t)(height/console->fy))-1)*console->fy; + + console->cx = 0; + console->cy = 0; + console->x0 = x0; + console->y0 = y0; + + console->bkcolor = bkcolor; + console->color = color; + + console->font = font; + + gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor); + return RDY_OK; +} + +msg_t lcdConsolePut(GLCDConsole *console, char c) { + uint8_t width; + + if(c == '\n') { + /* clear the text at the end of the line */ + if(console->cx < console->sx) + gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, + console->sx - console->cx, console->fy, + console->bkcolor); + console->cx = 0; + console->cy += console->fy; + } else if(c == '\r') { + /* TODO: work backwards through the buffer to the start of the current line */ + //console->cx = 0; + } else { + width = gdispGetCharWidth(c, console->font) + gdispGetFontMetric(console->font, fontCharPadding); + if((console->cx + width) >= console->sx) { + /* clear the text at the end of the line */ + if (console->cy <= console->sy) + gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, + console->sx - (console->cx + width), console->fy, + console->bkcolor); + console->cx = 0; + console->cy += console->fy; + } + + if((console->cy > console->sy)) { +#if GDISP_NEED_SCROLL + /* scroll the console */ + gdispVerticalScroll(console->x0, console->y0, console->sx, + console->sy + console->fy, console->fy, console->bkcolor); + /* reset the cursor to the start of the line */ + console->cx = 0; + console->cy = console->sy; +#else + /* clear the console */ + gdispFillArea(console->x0, console->y0, + console->sx, console->sy + console->fy, + console->bkcolor); + /* reset the cursor to the top of the console */ + console->cx = 0; + console->cy = 0; +#endif + } + + gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c, + console->font, console->color); + + /* update cursor */ + console->cx += width; + } + return RDY_OK; +} + +msg_t lcdConsoleWrite(GLCDConsole *console, char *bp, size_t n) { + size_t i; + for(i = 0; i < n; i++) + lcdConsolePut(console, bp[i]); + + return RDY_OK; +} From 8fd1de6ef5a806ccc6e23ba1ba18dfc06b6fbbde Mon Sep 17 00:00:00 2001 From: Tectu Date: Fri, 24 Aug 2012 15:54:32 +0200 Subject: [PATCH 14/14] first try to implement gdispDrawARC() (not working yet) --- src/gdisp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gdisp.c b/src/gdisp.c index 6cf58561..f5da45b9 100644 --- a/src/gdisp.c +++ b/src/gdisp.c @@ -672,7 +672,13 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { * @api */ void gdispDrawArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color) { + uint16_t i; + float step = 0.01; + for(i = 0; i <= (int)((abs(end-start)) / step); i++) { + gdispDrawPixel( ((float)x + (float)radius * cosf((float)start * M_PI / 180.0f) + (float)i * step * M_PI / 180.0f), + ((float)y + (float)radius * sinf((float)start * M_PI / 180.0f) + (float)i * step * M_PI / 180.0f), color); + } } /*