diff options
Diffstat (limited to 'halext/drivers/gdispSsd1289/gdisp_lld.c')
-rw-r--r-- | halext/drivers/gdispSsd1289/gdisp_lld.c | 296 |
1 files changed, 38 insertions, 258 deletions
diff --git a/halext/drivers/gdispSsd1289/gdisp_lld.c b/halext/drivers/gdispSsd1289/gdisp_lld.c index c2f460b1..fb32418b 100644 --- a/halext/drivers/gdispSsd1289/gdisp_lld.c +++ b/halext/drivers/gdispSsd1289/gdisp_lld.c @@ -45,7 +45,7 @@ #include "ch.h"
#include "hal.h"
#include "gdisp.h"
-#include "ssd1289_lld.h"
+#include "gdisp_fonts.h"
#if HAL_USE_GDISP || defined(__DOXYGEN__)
@@ -67,7 +67,7 @@ /*===========================================================================*/
#if !defined(__DOXYGEN__)
- GDISPDriver GDISP1;
+ GDISPDriver GDISP;
#endif
/*===========================================================================*/
@@ -78,233 +78,7 @@ /* Driver local functions. */
/*===========================================================================*/
-#ifdef LCD_USE_GPIO
- static __inline void lld_lcdWriteIndex(uint16_t index) {
- Clr_RS;
- Set_RD;
-
- lld_lcdWriteGPIO(index);
-
- Clr_WR;
- Set_WR;
- }
-
- static __inline void lld_lcdWriteData(uint16_t data) {
- Set_RS;
-
- lld_lcdWriteGPIO(data);
-
- Clr_WR;
- Set_WR;
- }
-
- static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
- Clr_CS;
-
- lld_lcdWriteIndex(lcdReg);
- lld_lcdWriteData(lcdRegValue);
-
- Set_CS;
- }
-
- static __inline uint16_t lld_lcdReadData(void) {
- uint16_t value;
-
- Set_RS;
- Set_WR;
- Clr_RD;
-
- value = lld_lcdReadGPIO();
-
- Set_RD;
-
- return value;
- }
-
- static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
- uint16_t lcdRAM;
-
- Clr_CS;
- lld_lcdWriteIndex(lcdReg);
- lcdRAM = lld_lcdReadData();
-
- Set_CS;
-
- return lcdRAM;
- }
-
- static __inline void lld_lcdWriteStreamStart(void) {
- Clr_CS;
-
- lld_lcdWriteIndex(0x0022);
- }
-
- static __inline void lld_lcdWriteStreamStop(void) {
- Set_CS;
- }
-
- static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
- uint16_t i;
-
- Set_RS;
-
- for(i = 0; i < size; i++) {
- lld_lcdWriteGPIO(buffer[i]);
- Clr_WR;
- Set_WR;
- }
- }
-
- static __inline void lld_lcdReadStreamStart(void) {
- Clr_CS
-
- lld_lcdWriteIndex(0x0022);
- }
-
- static __inline void lld_lcdReadStreamStop(void) {
- Set_CS;
- }
-
- static __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
- uint16_t i;
- volatile uint16_t dummy;
-
- dummy = lld_lcdReadData();
- for(i = 0; i < size; i++)
- buffer[i] = lld_lcdReadData();
- }
-#endif // LCD_USE_GPIO
-
-#ifdef LCD_USE_SPI
- /* TODO */
-#endif // LCD_USE_SPI
-
-#ifdef LCD_USE_FSMC
- #define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
- #define LCD_RAM (*((volatile uint16_t *) 0x60020000)) /* RS = 1 */
-
- static __inline void lld_lcdWriteIndex(uint16_t index) {
- LCD_REG = index;
- }
-
- static __inline void lld_lcdWriteData(uint16_t data) {
- LCD_RAM = data;
- }
-
- static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
- LCD_REG = lcdReg;
- LCD_RAM = lcdRegValue;
- }
-
- static __inline uint16_t lld_lcdReadData(void) {
- return (LCD_RAM);
- }
-
- static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
- LCD_REG = lcdReg;
- volatile uint16_t dummy = LCD_RAM;
- return (LCD_RAM);
- }
-
- static __inline void lld_lcdWriteStreamStart(void) {
- LCD_REG = 0x0022;
- }
-
- static __inline void lld_lcdWriteStreamStop(void) {
-
- }
-
- static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
- uint16_t i;
- for(i = 0; i < size; i++)
- LCD_RAM = buffer[i];
- }
-
- static __inline void lld_lcdReadStreamStart(void) {
- LCD_REG = 0x0022;
- }
-
- static __inline void lld_lcdReadStreamStop(void) {
-
- }
-
- static __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
- uint16_t i;
- /* throw away first value read */
- volatile uint16_t dummy = LCD_RAM;
-
- for(i = 0; i < size; i++) {
- buffer[i] = LCD_RAM;
- }
- }
-#endif // LCD_USE_FSMC
-
-static __inline void lld_lcdDelay(uint16_t us) {
- chThdSleepMicroseconds(us);
-}
-
-static void lld_lcdSetCursor(uint16_t x, uint16_t y) {
- /* Reg 0x004E is an 8 bit value
- * Reg 0x004F is 9 bit
- * Use a bit mask to make sure they are not set too high
- */
- switch(GDISP1.Orientation) {
- case portraitInv:
- lld_lcdWriteReg(0x004e, (SCREEN_WIDTH-1-x) & 0x00FF);
- lld_lcdWriteReg(0x004f, (SCREEN_HEIGHT-1-y) & 0x01FF);
- break;
- case portrait:
- lld_lcdWriteReg(0x004e, x & 0x00FF);
- lld_lcdWriteReg(0x004f, y & 0x01FF);
- break;
- case landscape:
- lld_lcdWriteReg(0x004e, y & 0x00FF);
- lld_lcdWriteReg(0x004f, x & 0x01FF);
- break;
- case landscapeInv:
- lld_lcdWriteReg(0x004e, (SCREEN_WIDTH - y - 1) & 0x00FF);
- lld_lcdWriteReg(0x004f, (SCREEN_HEIGHT - x - 1) & 0x01FF);
- break;
- }
-}
-
-void lld_lcdSetViewPort(uint16_t x, uint16_t y, uint16_t cx, uint16_t cy) {
- lld_lcdSetCursor(x, y);
-
- /* Reg 0x44 - Horizontal RAM address position
- * Upper Byte - HEA
- * Lower Byte - HSA
- * 0 <= HSA <= HEA <= 0xEF
- * Reg 0x45,0x46 - Vertical RAM address position
- * Lower 9 bits gives 0-511 range in each value
- * 0 <= Reg(0x45) <= Reg(0x46) <= 0x13F
- */
-
- switch(GDISP1.Orientation) {
- case portrait:
- lld_lcdWriteReg(0x44, (((x+cx-1) << 8) & 0xFF00 ) | (x & 0x00FF));
- lld_lcdWriteReg(0x45, y & 0x01FF);
- lld_lcdWriteReg(0x46, (y+cy-1) & 0x01FF);
- break;
- case landscape:
- lld_lcdWriteReg(0x44, (((x+cx-1) << 8) & 0xFF00) | ((y+cy) & 0x00FF));
- lld_lcdWriteReg(0x45, x & 0x01FF);
- lld_lcdWriteReg(0x46, (x+cx-1) & 0x01FF);
- break;
- case portraitInv:
- lld_lcdWriteReg(0x44, (((SCREEN_WIDTH-x-1) & 0x00FF) << 8) | ((SCREEN_WIDTH - (x+cx)) & 0x00FF));
- lld_lcdWriteReg(0x45, (SCREEN_HEIGHT-(y+cy)) & 0x01FF);
- lld_lcdWriteReg(0x46, (SCREEN_HEIGHT-y-1) & 0x01FF);
- break;
- case landscapeInv:
- lld_lcdWriteReg(0x44, (((SCREEN_WIDTH - y - 1) & 0x00FF) << 8) | ((SCREEN_WIDTH - (y+cy)) & 0x00FF));
- lld_lcdWriteReg(0x45, (SCREEN_HEIGHT - (x+cx)) & 0x01FF);
- lld_lcdWriteReg(0x46, (SCREEN_HEIGHT - x - 1) & 0x01FF);
- break;
- }
-
- lld_lcdSetCursor(x, y);
-}
+#include "ssd1289_lld.c.h"
/*===========================================================================*/
/* Driver interrupt handlers. */
@@ -314,6 +88,9 @@ void lld_lcdSetViewPort(uint16_t x, uint16_t y, uint16_t cx, uint16_t cy) { /* Driver exported functions. */
/*===========================================================================*/
+/* Include the software emulation routines */
+#include "gdisp_lld_inc_emulation.c.h"
+
/* ---- Required Routines ---- */
/*
The following 2 routines are required.
@@ -392,10 +169,10 @@ void gdisp_lld_init(void) { lld_lcdWriteReg(0x004e,0x0000); lld_lcdDelay(5);
/* Initialise the GDISP structure */
- GDISP1.Width = SCREEN_WIDTH;
- GDISP1.Height = SCREEN_HEIGHT;
- GDISP1.Orientation = portrait;
- GDISP1.Powermode = powerOn;
+ GDISP.Width = SCREEN_WIDTH;
+ GDISP.Height = SCREEN_HEIGHT;
+ GDISP.Orientation = portrait;
+ GDISP.Powermode = powerOn;
}
/**
@@ -409,7 +186,7 @@ void gdisp_lld_init(void) { */
void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) {
#if GDISP_NEED_VALIDATION
- if (x >= GDISP1.Width || y >= GDISP1.Height) return;
+ if (x >= GDISP.Width || y >= GDISP.Height) return;
#endif
lld_lcdSetCursor(x, y);
lld_lcdWriteReg(0x0022, color);
@@ -443,7 +220,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { * @notapi
*/
void gdisp_lld_setpowermode(gdisp_powermode_t powerMode) {
- if (GDISP1.Powermode == powerMode)
+ if (GDISP.Powermode == powerMode)
return;
switch(powerMode) {
@@ -455,7 +232,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { break;
case powerOn:
lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode
- if (GDISP1.Powermode != powerSleep)
+ if (GDISP.Powermode != powerSleep)
gdisp_lld_init();
break;
case powerSleep:
@@ -465,7 +242,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { return;
}
- GDISP1.Powermode = powerMode;
+ GDISP.Powermode = powerMode;
}
#endif
@@ -479,7 +256,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { * @notapi
*/
void gdisp_lld_setorientation(gdisp_orientation_t newOrientation) {
- if (GDISP1.Orientation == newOrientation)
+ if (GDISP.Orientation == newOrientation)
return;
switch(newOrientation) {
@@ -487,34 +264,34 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { lld_lcdWriteReg(0x0001, 0x2B3F);
/* ID = 11 AM = 0 */
lld_lcdWriteReg(0x0011, 0x6070);
- GDISP1.Height = SCREEN_HEIGHT;
- GDISP1.Width = SCREEN_WIDTH;
+ GDISP.Height = SCREEN_HEIGHT;
+ GDISP.Width = SCREEN_WIDTH;
break;
case landscape:
lld_lcdWriteReg(0x0001, 0x293F);
/* ID = 11 AM = 1 */
lld_lcdWriteReg(0x0011, 0x6078);
- GDISP1.Height = SCREEN_WIDTH;
- GDISP1.Width = SCREEN_HEIGHT;
+ GDISP.Height = SCREEN_WIDTH;
+ GDISP.Width = SCREEN_HEIGHT;
break;
case portraitInv:
lld_lcdWriteReg(0x0001, 0x2B3F);
/* ID = 01 AM = 0 */
lld_lcdWriteReg(0x0011, 0x6040);
- GDISP1.Height = SCREEN_HEIGHT;
- GDISP1.Width = SCREEN_WIDTH;
+ GDISP.Height = SCREEN_HEIGHT;
+ GDISP.Width = SCREEN_WIDTH;
break;
case landscapeInv:
lld_lcdWriteReg(0x0001, 0x293F);
/* ID = 01 AM = 1 */
lld_lcdWriteReg(0x0011, 0x6048);
- GDISP1.Height = SCREEN_WIDTH;
- GDISP1.Width = SCREEN_HEIGHT;
+ GDISP.Height = SCREEN_WIDTH;
+ GDISP.Width = SCREEN_HEIGHT;
break;
default:
return;
}
- GDISP1.Orientation = newOrientation;
+ GDISP.Orientation = newOrientation;
}
#endif
@@ -528,7 +305,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { * @notapi
*/
void gdisp_lld_clear(color_t color) {
- unsigned i = 0;
+ unsigned i;
lld_lcdSetCursor(0, 0);
lld_lcdWriteStreamStart();
@@ -586,9 +363,9 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { */
void gdisp_lld_fillarea(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
#if GDISP_NEED_VALIDATION
- if (cx < 1 || cy < 1 || x >= GDISP1.Width || y >= GDISP1.Height) return;
- if (x+cx > GDISP1.Width) cx = GDISP1.Width - x;
- if (y+cy > GDISP1.Height) cy = GDISP1.Height - y;
+ if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return;
+ if (x+cx > GDISP.Width) cx = GDISP.Width - x;
+ if (y+cy > GDISP.Height) cy = GDISP.Height - y;
#endif
unsigned i, area;
@@ -599,6 +376,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { for(i = 0; i < area; i++)
lld_lcdWriteData(color);
lld_lcdWriteStreamStop();
+ lld_lcdResetViewPort();
}
#endif
@@ -617,9 +395,9 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { unsigned i, area;
#if GDISP_NEED_VALIDATION
- if (cx < 1 || cy < 1 || x >= GDISP1.Width || y >= GDISP1.Height) return;
- if (x+cx > GDISP1.Width) return;
- if (y+cy > GDISP1.Height) cy = GDISP1.Height - y;
+ if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return;
+ if (x+cx > GDISP.Width) return;
+ if (y+cy > GDISP.Height) cy = GDISP.Height - y;
#endif
area = cx*cy;
@@ -628,6 +406,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { for(i = 0; i < area; i++)
lld_lcdWriteData(*buffer++);
lld_lcdWriteStreamStop();
+ lld_lcdResetViewPort();
}
#endif
@@ -751,7 +530,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { color_t color;
#if GDISP_NEED_VALIDATION
- if (x >= GDISP1.Width || y >= GDISP1.Height) return 0;
+ if (x >= GDISP.Width || y >= GDISP.Height) return 0;
#endif
lld_lcdSetCursor(x, y);
@@ -788,9 +567,9 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { abslines = lines < 0 ? -lines : lines;
#if GDISP_NEED_VALIDATION
- if (cx < 1 || cy < 1 || x >= GDISP1.Width || y >= GDISP1.Height) return;
- if (x+cx > GDISP1.Width) cx = GDISP1.Width - x;
- if (y+cy > GDISP1.Height) cy = GDISP1.Height - y;
+ if (cx < 1 || cy < 1 || x >= GDISP.Width || y >= GDISP.Height) return;
+ if (x+cx > GDISP.Width) cx = GDISP.Width - x;
+ if (y+cy > GDISP.Height) cy = GDISP.Height - y;
#endif
if (!abslines) return;
@@ -827,6 +606,7 @@ void gdisp_lld_drawpixel(coord_t x, coord_t y, color_t color) { gap = cx*abslines;
for(i = 0; i < gap; i++) lld_lcdWriteData(color);
lld_lcdWriteStreamStop();
+ lld_lcdResetViewPort();
}
#endif
|