From 1f1f9ee38a6c2beb38285d550728d9661d0dc698 Mon Sep 17 00:00:00 2001 From: trsaunders Date: Tue, 19 Jun 2012 20:05:01 +0100 Subject: c++ compatibility, FSMC driver for ssd1289 --- drivers/lcd/s6d1121_lld.h | 9 ++++ drivers/lcd/ssd1289_lld.c | 127 +++++++++++++++++++++++++++++++++------------- drivers/lcd/ssd1289_lld.h | 122 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+), 35 deletions(-) (limited to 'drivers') diff --git a/drivers/lcd/s6d1121_lld.h b/drivers/lcd/s6d1121_lld.h index 173f6e40..edc6da33 100644 --- a/drivers/lcd/s6d1121_lld.h +++ b/drivers/lcd/s6d1121_lld.h @@ -28,6 +28,11 @@ #define LCD_D0_GPIO GPIOD #define LCD_D4_GPIO GPIOE +#ifdef __cplusplus +extern "C" { +#endif + + void lld_lcdInit(void); void lld_lcdSetCursor(uint16_t x, uint16_t y); void lld_lcdSetOrientation(uint8_t newOrientation); @@ -39,6 +44,10 @@ uint16_t lld_lcdGetOrientation(void); uint16_t lld_lcdGetHeight(void); uint16_t lld_lcdGetWidth(void); +#ifdef __cplusplus +} +#endif + #endif #endif diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c index f391a250..ac4d050f 100644 --- a/drivers/lcd/ssd1289_lld.c +++ b/drivers/lcd/ssd1289_lld.c @@ -6,6 +6,7 @@ uint8_t orientation; uint16_t DeviceCode; extern uint16_t lcd_width, lcd_height; +#ifdef LCD_USE_GPIO static __inline void lld_lcdWriteIndex(uint16_t index) { Clr_RS; Set_RD; @@ -67,48 +68,81 @@ static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) { return lcdRAM; } -static __inline void lcdDelay(uint16_t us) { - chThdSleepMicroseconds(us); -} - __inline void lld_lcdWriteStreamStart(void) { - #ifdef LCD_USE_GPIO - Clr_CS - lld_lcdWriteIndex(0x0022); - #endif - - #ifdef LCD_USE_SPI - #endif - - #ifdef LCD_USE_FSCM - #endif + Clr_CS + lld_lcdWriteIndex(0x0022); } __inline void lld_lcdWriteStreamStop(void) { - #ifdef LCD_USE_GPIO - Set_CS; - #endif - - #ifdef LCD_USE_SPI - #endif - - #ifdef LCD_USE_FSMC - #endif + Set_CS; } __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { uint16_t i; Set_RS; - + for(i = 0; i < size; i++) { palWritePort(LCD_DATA_PORT, buffer[i]); - Clr_WR; Set_WR; } } +#endif + +#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; + return (LCD_RAM); +} + +__inline void lld_lcdWriteStreamStart(void) { + LCD_REG = 0x0022; +} + +__inline void lld_lcdWriteStreamStop(void) { + +} + +__inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { + uint16_t i; + for(i = 0; i < size; i++) + LCD_RAM = buffer[i]; +} +#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); @@ -183,33 +217,38 @@ void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_ area = ((x1-x0)*(y1-y0)); lld_lcdSetWindow(x0, y0, x1, y1); - Clr_CS; - lld_lcdWriteIndex(0x0022); + + + lld_lcdWriteStreamStart(); + for(index = 0; index < area; index++) lld_lcdWriteData(color); - Set_CS; + + lld_lcdWriteStreamStop(); } void lld_lcdClear(uint16_t color) { uint32_t index = 0; lld_lcdSetCursor(0, 0); - Clr_CS; - lld_lcdWriteIndex(0x0022); + lld_lcdWriteStreamStart(); + for(index = 0; index < SCREEN_WIDTH * SCREEN_HEIGHT; index++) - lld_lcdWriteData(color); - Set_CS; + lld_lcdWriteData(color); + + lld_lcdWriteStreamStop(); } uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y) { uint16_t dummy; lld_lcdSetCursor(x,y); - Clr_CS; - lld_lcdWriteIndex(0x0022); + lld_lcdWriteStreamStart(); + dummy = lld_lcdReadData(); dummy = lld_lcdReadData(); - Set_CS; + + lld_lcdWriteStreamStop(); return dummy; } @@ -220,6 +259,24 @@ void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) { } void lld_lcdInit(void) { +#ifdef LCD_USE_FSMC + /* FSMC setup. TODO: this only works for STM32F1 */ + rccEnableAHB(RCC_AHBENR_FSMCEN, 0); + int FSMC_Bank = 0; + /* timing structure */ + /* from datasheet: + address setup: 0ns + address hold: 0ns + Data setup: 5ns + Data hold: 5ns + Data access: 250ns + output hold: 100ns + */ + FSMC_Bank1->BTCR[FSMC_Bank+1] = FSMC_BTR1_ADDSET_1 | FSMC_BTR1_DATAST_1; + + /* Bank1 NOR/SRAM control register configuration */ + FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN; +#endif DeviceCode = lld_lcdReadReg(0x0000); lld_lcdWriteReg(0x0000,0x0001); lcdDelay(5); diff --git a/drivers/lcd/ssd1289_lld.h b/drivers/lcd/ssd1289_lld.h index 6d26d3ad..3cedcc90 100644 --- a/drivers/lcd/ssd1289_lld.h +++ b/drivers/lcd/ssd1289_lld.h @@ -6,6 +6,7 @@ #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); @@ -14,6 +15,123 @@ #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 void lld_lcdInit(void); void lld_lcdWriteStreamStart(void); @@ -30,6 +148,10 @@ uint16_t lld_lcdGetOrientation(void); uint16_t lld_lcdGetHeight(void); uint16_t lld_lcdGetWidth(void); +#ifdef __cplusplus +} +#endif + #endif #endif -- cgit v1.2.3