diff options
author | Tectu <joel@unormal.org> | 2012-08-13 04:11:03 +0200 |
---|---|---|
committer | Tectu <joel@unormal.org> | 2012-08-13 04:11:03 +0200 |
commit | 54229cbdaaf585b5adf9b085229a22c9824c112c (patch) | |
tree | 846e654318f88d309bf6f7f0aadbf640d8cdd04b /drivers/lcd | |
parent | e7f0c8e2c2791fd2e571c762f03e277161f98a4b (diff) | |
download | uGFX-54229cbdaaf585b5adf9b085229a22c9824c112c.tar.gz uGFX-54229cbdaaf585b5adf9b085229a22c9824c112c.tar.bz2 uGFX-54229cbdaaf585b5adf9b085229a22c9824c112c.zip |
restructure
Diffstat (limited to 'drivers/lcd')
-rw-r--r-- | drivers/lcd/s6d1121_lld.c | 543 | ||||
-rw-r--r-- | drivers/lcd/s6d1121_lld.h | 73 | ||||
-rw-r--r-- | drivers/lcd/ssd1289_lld.c | 469 | ||||
-rw-r--r-- | drivers/lcd/ssd1289_lld.h | 182 |
4 files changed, 0 insertions, 1267 deletions
diff --git a/drivers/lcd/s6d1121_lld.c b/drivers/lcd/s6d1121_lld.c deleted file mode 100644 index 2fdd055e..00000000 --- a/drivers/lcd/s6d1121_lld.c +++ /dev/null @@ -1,543 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2012 - Joel Bodenmann aka Tectu <joel@unormal.org> - - 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 <http://www.gnu.org/licenses/>. -*/ - -#include "ch.h" -#include "hal.h" - -#include "s6d1121_lld.h" -#include "chprintf.h" - -#ifdef LCD_USE_S6D1121 - -static uint8_t orientation; -extern uint16_t lcd_width, lcd_height; - -/* all interfaces use RST via GPIO */ -/* TODO: option to disable RST; assumes RST is tied high */ -#define LCD_RST_LOW palClearPad(LCD_RST_GPIO, LCD_RST_PIN) -#define LCD_RST_HIGH palSetPad(LCD_RST_GPIO, LCD_RST_PIN) - -#define s6d1121_delay(n) halPolledDelay(MS2RTT(n)); - -static uint16_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)]; - -#if defined(LCD_USE_GPIO) - -#define LCD_CS_LOW palClearPad(LCD_CS_GPIO, LCD_CS_PIN) -#define LCD_CS_HIGH palSetPad(LCD_CS_GPIO, LCD_CS_PIN) - -#define LCD_RS_LOW palClearPad(LCD_RS_GPIO, LCD_RS_PIN) -#define LCD_RS_HIGH palSetPad(LCD_RS_GPIO, LCD_RS_PIN) - -#define LCD_RD_LOW palClearPad(LCD_RD_GPIO, LCD_RD_PIN) -#define LCD_RD_HIGH palSetPad(LCD_RD_GPIO, LCD_RD_PIN) - -#define LCD_WR_LOW palClearPad(LCD_WR_GPIO, LCD_WR_PIN) -#define LCD_WR_HIGH palSetPad(LCD_WR_GPIO, LCD_WR_PIN) - -#define LCD_BL_LOW palClearPad(LCD_BL_GPIO, LCD_BL_PIN) -#define LCD_BL_HIGH palSetPad(LCD_BL_GPIO, LCD_BL_PIN) - - -static inline void lld_lcddelay(void) -{ - asm volatile ("nop"); - asm volatile ("nop"); -} - -static inline void lld_lcdwrite(uint16_t db) -{ - LCD_D4_GPIO->BSRR.W=((~db&0xFFF0)<<16)|(db&0xFFF0); - LCD_D0_GPIO->BSRR.W=((~db&0x000F)<<16)|(db&0x000F); - - LCD_WR_LOW; - lld_lcddelay(); - LCD_WR_HIGH; -} - -static __inline uint16_t lld_lcdReadData(void) { - uint16_t value=0; - - LCD_RS_HIGH; - LCD_WR_HIGH; - LCD_RD_LOW; - -#ifndef STM32F4XX - // change pin mode to digital input - LCD_DATA_PORT->CRH = 0x47444444; - LCD_DATA_PORT->CRL = 0x47444444; -#else - -#endif - -#ifndef STM32F4XX - // change pin mode back to digital output - LCD_DATA_PORT->CRH = 0x33333333; - LCD_DATA_PORT->CRL = 0x33333333; -#else -#endif - LCD_RD_HIGH; - - return value; -} - -static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) { - uint16_t lcdRAM; - - LCD_CS_LOW; - LCD_RS_LOW; - lld_lcdwrite(lcdReg); - LCD_RS_HIGH; - lcdRAM = lld_lcdReadData(); - - LCD_CS_HIGH; - - return lcdRAM; -} - -void lld_lcdWriteIndex(uint16_t lcdReg) { - LCD_RS_LOW; - - lld_lcdwrite(lcdReg); - - LCD_RS_HIGH; -} - -void lld_lcdWriteData(uint16_t lcdData) { - lld_lcdwrite(lcdData); -} - -void lld_lcdWriteReg(uint16_t lcdReg, uint16_t lcdRegValue) { - LCD_CS_LOW; - - lld_lcdWriteIndex(lcdReg); - lld_lcdWriteData(lcdRegValue); - - LCD_CS_HIGH; -} - -static __inline void lld_lcdWriteStreamStart(void) { - LCD_CS_LOW; - lld_lcdWriteIndex(0x0022); -} - -static __inline void lld_lcdWriteStreamStop(void) { - LCD_CS_HIGH; -} - -__inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) { - uint16_t i; - - for(i = 0; i < size; i++) { - lld_lcdwrite(buffer[i]); - } -} - -__inline void lld_lcdReadStreamStart(void) { - /* TODO */ -} - -__inline void lld_lcdReadStreamStop(void) { - /* TODO */ -} - -__inline void lld_lcdReadStream(uint16_t *buffer, size_t size) { - /* TODO */ -} - -#elif defined(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]; -} - -__inline void lld_lcdReadStreamStart(void) { - LCD_REG = 0x0022; -} - -__inline void lld_lcdReadStreamStop(void) { - -} - -__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 - -void lld_lcdSetPowerMode(uint8_t powerMode) { - /* TODO: implement */ -} - -void lld_lcdInit(void) { - palSetPadMode(LCD_RST_GPIO, LCD_RST_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - // A Good idea to reset the module before using - LCD_RST_LOW; - s6d1121_delay(2); - LCD_RST_HIGH; // Hardware Reset - s6d1121_delay(2); - -#ifdef LCD_USE_GPIO - // IO Default Configurations - palSetPadMode(LCD_CS_GPIO, LCD_CS_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - palSetPadMode(LCD_WR_GPIO, LCD_WR_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - palSetPadMode(LCD_RD_GPIO, LCD_RD_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - palSetPadMode(LCD_RS_GPIO, LCD_RS_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - palSetPadMode(LCD_BL_GPIO, LCD_BL_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - - palSetGroupMode(LCD_D0_GPIO, 0x0000000F, 0, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - palSetGroupMode(LCD_D4_GPIO, 0x0000FFF0, 0, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); - - LCD_CS_HIGH; - LCD_RD_HIGH; - LCD_WR_HIGH; - LCD_BL_LOW; - - -#elif defined(LCD_USE_FSMC) -#if defined(STM32F1XX) - /* FSMC setup. TODO: this only works for STM32F1 */ - rccEnableAHB(RCC_AHBENR_FSMCEN, 0); - - /* TODO: pin setup */ -#elif defined(STM32F4XX) - /* STM32F4 FSMC init */ - rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0); - - /* set pins to FSMC mode */ - IOBus busD = {GPIOD, (1 << 0) | (1 << 1) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 8) | - (1 << 9) | (1 << 10) | (1 << 11) | (1 << 14) | (1 << 15), 0}; - - IOBus busE = {GPIOE, (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12) | - (1 << 13) | (1 << 14) | (1 << 15), 0}; - - palSetBusMode(&busD, PAL_MODE_ALTERNATE(12)); - palSetBusMode(&busE, PAL_MODE_ALTERNATE(12)); -#else -#error "FSMC not implemented for this device" -#endif - int FSMC_Bank = 0; - /* FSMC timing */ - FSMC_Bank1->BTCR[FSMC_Bank+1] = (10) | (10 << 8) | (10 << 16); - - /* Bank1 NOR/SRAM control register configuration */ - FSMC_Bank1->BTCR[FSMC_Bank] = FSMC_BCR1_MWID_0 | FSMC_BCR1_WREN | FSMC_BCR1_MBKEN; -#endif - - lld_lcdWriteReg(0x11,0x2004); - lld_lcdWriteReg(0x13,0xCC00); - lld_lcdWriteReg(0x15,0x2600); - lld_lcdWriteReg(0x14,0x252A); - lld_lcdWriteReg(0x12,0x0033); - lld_lcdWriteReg(0x13,0xCC04); - - s6d1121_delay(1); - - lld_lcdWriteReg(0x13,0xCC06); - - s6d1121_delay(1); - - lld_lcdWriteReg(0x13,0xCC4F); - - s6d1121_delay(1); - - lld_lcdWriteReg(0x13,0x674F); - lld_lcdWriteReg(0x11,0x2003); - - s6d1121_delay(1); - - // Gamma Setting - lld_lcdWriteReg(0x30,0x2609); - lld_lcdWriteReg(0x31,0x242C); - lld_lcdWriteReg(0x32,0x1F23); - lld_lcdWriteReg(0x33,0x2425); - lld_lcdWriteReg(0x34,0x2226); - lld_lcdWriteReg(0x35,0x2523); - lld_lcdWriteReg(0x36,0x1C1A); - lld_lcdWriteReg(0x37,0x131D); - lld_lcdWriteReg(0x38,0x0B11); - lld_lcdWriteReg(0x39,0x1210); - lld_lcdWriteReg(0x3A,0x1315); - lld_lcdWriteReg(0x3B,0x3619); - lld_lcdWriteReg(0x3C,0x0D00); - lld_lcdWriteReg(0x3D,0x000D); - - lld_lcdWriteReg(0x16,0x0007); - lld_lcdWriteReg(0x02,0x0013); - lld_lcdWriteReg(0x03,0x0003); - lld_lcdWriteReg(0x01,0x0127); - - s6d1121_delay(1); - - lld_lcdWriteReg(0x08,0x0303); - lld_lcdWriteReg(0x0A,0x000B); - lld_lcdWriteReg(0x0B,0x0003); - lld_lcdWriteReg(0x0C,0x0000); - lld_lcdWriteReg(0x41,0x0000); - lld_lcdWriteReg(0x50,0x0000); - lld_lcdWriteReg(0x60,0x0005); - lld_lcdWriteReg(0x70,0x000B); - lld_lcdWriteReg(0x71,0x0000); - lld_lcdWriteReg(0x78,0x0000); - lld_lcdWriteReg(0x7A,0x0000); - lld_lcdWriteReg(0x79,0x0007); - lld_lcdWriteReg(0x07,0x0051); - - s6d1121_delay(1); - - lld_lcdWriteReg(0x07,0x0053); - lld_lcdWriteReg(0x79,0x0000); - - lld_lcdResetWindow(); -} - -void lld_lcdSetCursor(uint16_t x, uint16_t y) { - /* R20h - 8 bit - * R21h - 9 bit - */ - switch(lcdGetOrientation()) { - case portraitInv: - lld_lcdWriteReg(0x0020, (SCREEN_WIDTH-1-x) & 0x00FF); - lld_lcdWriteReg(0x0021, (SCREEN_HEIGHT-1-y) & 0x01FF); - break; - case portrait: - lld_lcdWriteReg(0x0020, x & 0x00FF); - lld_lcdWriteReg(0x0021, y & 0x01FF); - break; - case landscape: - lld_lcdWriteReg(0x0020, y & 0x00FF); - lld_lcdWriteReg(0x0021, x & 0x01FF); - break; - case landscapeInv: - lld_lcdWriteReg(0x0020, (SCREEN_WIDTH - y - 1) & 0x00FF); - lld_lcdWriteReg(0x0021, (SCREEN_HEIGHT - x - 1) & 0x01FF); - break; - } -} - -void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { - uint32_t index = 0, area; - - area = ((x1-x0)*(y1-y0)); - - lld_lcdSetWindow(x0, y0, x1, y1); - - lld_lcdWriteStreamStart(); - - for(index = 0; index < area; index++) - lld_lcdWriteData(color); - - lld_lcdWriteStreamStop(); - - lld_lcdResetWindow(); -} - -// Do not use now, will be fixed in future -void lld_lcdSetOrientation(uint8_t newOrientation) { - orientation = newOrientation; - - switch(orientation) { - case portrait: - lld_lcdWriteReg(0x0001,0x0127); - lld_lcdWriteReg(0x03, 0b0011); - lcd_height = SCREEN_HEIGHT; - lcd_width = SCREEN_WIDTH; - break; - case landscape: - lld_lcdWriteReg(0x0001,0x0027); - lld_lcdWriteReg(0x0003, 0b1011); - lcd_height = SCREEN_WIDTH; - lcd_width = SCREEN_HEIGHT; - break; - case portraitInv: - lld_lcdWriteReg(0x0001,0x0127); - lld_lcdWriteReg(0x0003, 0b0000); - lcd_height = SCREEN_HEIGHT; - lcd_width = SCREEN_WIDTH; - break; - case landscapeInv: - lld_lcdWriteReg(0x0001,0x0027); - lld_lcdWriteReg(0x0003, 0b1000); - lcd_height = SCREEN_WIDTH; - lcd_width = SCREEN_HEIGHT; - break; - } -} - -void lld_lcdResetWindow(void) { - switch(lcdGetOrientation()) { - case portrait: - case portraitInv: - lld_lcdSetWindow(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); - break; - case landscape: - case landscapeInv: - lld_lcdSetWindow(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH); - break; - } -} - -void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - /* HSA / HEA are 8 bit - * VSA / VEA are 9 bit - * use masks 0x00FF and 0x01FF to enforce this - */ - switch(lcdGetOrientation()) { - case portrait: - lld_lcdWriteReg(0x46, (((x1-1) & 0x00FF) << 8) | (x0 & 0x00FF)); - lld_lcdWriteReg(0x48, y0 & 0x01FF); - lld_lcdWriteReg(0x47, (y1-1) & 0x01FF); - break; - case landscape: - lld_lcdWriteReg(0x46, (((y1-1) & 0x00FF) << 8) | (y1 & 0x00FF)); - lld_lcdWriteReg(0x48, x0 & 0x01FF); - lld_lcdWriteReg(0x47, (x1-1) & 0x01FF); - break; - case portraitInv: - lld_lcdWriteReg(0x46, (((SCREEN_WIDTH-x0-1) & 0x00FF) << 8) | ((SCREEN_WIDTH - x1) & 0x00FF)); - lld_lcdWriteReg(0x48, (SCREEN_HEIGHT-y1) & 0x01FF); - lld_lcdWriteReg(0x47, (SCREEN_HEIGHT-y0-1) & 0x01FF); - break; - case landscapeInv: - lld_lcdWriteReg(0x46, (((SCREEN_WIDTH - y0 - 1) & 0x00FF) << 8) | ((SCREEN_WIDTH - y1) & 0x00FF)); - lld_lcdWriteReg(0x48, (SCREEN_HEIGHT - x1) & 0x01FF); - lld_lcdWriteReg(0x47, (SCREEN_HEIGHT - x0 - 1) & 0x01FF); - break; - } - - lld_lcdSetCursor(x0, y0); -} - -void lld_lcdClear(uint16_t color) { - uint32_t index = 0; - lld_lcdSetCursor(0, 0); - lld_lcdWriteStreamStart(); - - for(index = 0; index < SCREEN_WIDTH * SCREEN_HEIGHT; index++) - lld_lcdWriteData(color); - - lld_lcdWriteStreamStop(); -} - -// Do not use! -uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y) { - uint16_t dummy; - - lld_lcdSetCursor(x,y); - lld_lcdWriteStreamStart(); - - dummy = lld_lcdReadData(); - dummy = lld_lcdReadData(); - - lld_lcdWriteStreamStop(); - - return dummy; -} - -void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) { - lld_lcdSetCursor(x, y); - lld_lcdWriteReg(0x0022, color); -} - -uint16_t lld_lcdGetOrientation(void) { - return orientation; -} - -uint16_t lld_lcdGetHeight(void) { - return lcd_height; -} - -uint16_t lld_lcdGetWidth(void) { - return lcd_width; -} - -/* a positive lines value shifts the screen up, negative down */ -/* TODO: test this */ -void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines) { - uint16_t row0, row1; - uint16_t i; - - for(i = 0; i < ((y1-y0) - abs(lines)); i++) { - if(lines > 0) { - row0 = y0 + i + lines; - row1 = y0 + i; - } else { - row0 = (y1 - i - 1) + lines; - row1 = (y1 - i - 1); - } - - /* read row0 into the buffer and then write at row1*/ - lld_lcdSetWindow(x0, row0, x1, row0); - lld_lcdReadStreamStart(); - lld_lcdReadStream(buf, x1-x0); - lld_lcdReadStreamStop(); - - lld_lcdSetWindow(x0, row1, x1, row1); - lld_lcdWriteStreamStart(); - lld_lcdWriteStream(buf, x1-x0); - lld_lcdWriteStreamStop(); - } - - lld_lcdResetWindow(); -} - - -#endif diff --git a/drivers/lcd/s6d1121_lld.h b/drivers/lcd/s6d1121_lld.h deleted file mode 100644 index dc23d779..00000000 --- a/drivers/lcd/s6d1121_lld.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2012 - Joel Bodenmann aka Tectu <joel@unormal.org> - - 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 <http://www.gnu.org/licenses/>. -*/ - -#ifndef S6D1121_H -#define S6D1121_H - -#include "glcd.h" - -#ifdef LCD_USE_S6D1121 - -// I/O assignments -#define LCD_BL_GPIO GPIOB -#define LCD_BL_PIN 8 - -#define LCD_CS_GPIO GPIOD -#define LCD_CS_PIN 7 - -#define LCD_RS_GPIO GPIOD -#define LCD_RS_PIN 11 - -#define LCD_RST_GPIO GPIOD -#define LCD_RST_PIN 10 - -#define LCD_RD_GPIO GPIOD -#define LCD_RD_PIN 9 - -#define LCD_WR_GPIO GPIOD -#define LCD_WR_PIN 8 - -#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); -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); -uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y); -uint16_t lld_lcdGetOrientation(void); -uint16_t lld_lcdGetHeight(void); -uint16_t lld_lcdGetWidth(void); -void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines); - -#ifdef __cplusplus -} -#endif - -#endif -#endif - diff --git a/drivers/lcd/ssd1289_lld.c b/drivers/lcd/ssd1289_lld.c deleted file mode 100644 index 6c6c15b5..00000000 --- a/drivers/lcd/ssd1289_lld.c +++ /dev/null @@ -1,469 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2012 - Joel Bodenmann aka Tectu <joel@unormal.org> - - 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 <http://www.gnu.org/licenses/>. -*/ - -#include "ssd1289_lld.h" - -#ifdef LCD_USE_SSD1289 - -uint8_t orientation; -uint16_t DeviceCode; -extern uint16_t lcd_width, lcd_height; - -static uint16_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)]; - -#ifdef LCD_USE_GPIO - -static __inline void lld_lcdWriteIndex(uint16_t index) { - Clr_RS; - Set_RD; - - 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; -} - -__inline void lld_lcdWriteStreamStart(void) { - Clr_CS; - - lld_lcdWriteIndex(0x0022); -} - -__inline void lld_lcdWriteStreamStop(void) { - Set_CS; -} - -__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; - } -} - -__inline void lld_lcdReadStreamStart(void) { - Clr_CS - - lld_lcdWriteIndex(0x0022); -} - -__inline void lld_lcdReadStreamStop(void) { - Set_CS; -} - -__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); -} - -__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]; -} - -__inline void lld_lcdReadStreamStart(void) { - LCD_REG = 0x0022; -} - -__inline void lld_lcdReadStreamStop(void) { - -} - -__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); -} - -void lld_lcdSetPowerMode(uint8_t powerMode) { - switch(powerMode) { - case powerOff: - lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode - lld_lcdWriteReg(0x0007, 0x0000); // halt operation - lld_lcdWriteReg(0x0000, 0x0000); // turn off oszillator - lld_lcdWriteReg(0x0010, 0x0001); // enter sleepmode - break; - case powerOn: - lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode - lld_lcdInit(); - break; - case sleepOn: - lld_lcdWriteReg(0x0010, 0x0001); // enter sleep mode - break; - case sleepOff: - lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode - break; - } -} - -void lld_lcdSetCursor(uint16_t x, uint16_t y) { - /* Reg 0x004E is an 8 bit value - * Reg 0x004F is 9 bit - * Use a bit mask to make sure they are not set too high - */ - switch(lcdGetOrientation()) { - 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_lcdSetOrientation(uint8_t newOrientation) { - orientation = newOrientation; - - switch(orientation) { - case portrait: - lld_lcdWriteReg(0x0001, 0x2B3F); - /* ID = 11 AM = 0 */ - lld_lcdWriteReg(0x0011, 0x6070); - lcd_height = SCREEN_HEIGHT; - lcd_width = SCREEN_WIDTH; - break; - case landscape: - lld_lcdWriteReg(0x0001, 0x293F); - /* ID = 11 AM = 1 */ - lld_lcdWriteReg(0x0011, 0x6078); - lcd_height = SCREEN_WIDTH; - lcd_width = SCREEN_HEIGHT; - break; - case portraitInv: - lld_lcdWriteReg(0x0001, 0x2B3F); - /* ID = 01 AM = 0 */ - lld_lcdWriteReg(0x0011, 0x6040); - lcd_height = SCREEN_HEIGHT; - lcd_width = SCREEN_WIDTH; - break; - case landscapeInv: - lld_lcdWriteReg(0x0001, 0x293F); - /* ID = 01 AM = 1 */ - lld_lcdWriteReg(0x0011, 0x6048); - lcd_height = SCREEN_WIDTH; - lcd_width = SCREEN_HEIGHT; - break; - } -} - -void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - lld_lcdSetCursor(x0, y0); - - /* 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(lcdGetOrientation()) { - case portrait: - lld_lcdWriteReg(0x44, (((x1-1) << 8) & 0xFF00 ) | (x0 & 0x00FF)); - lld_lcdWriteReg(0x45, y0 & 0x01FF); - lld_lcdWriteReg(0x46, (y1-1) & 0x01FF); - break; - case landscape: - lld_lcdWriteReg(0x44, (((y1-1) << 8) & 0xFF00) | (y1 & 0x00FF)); - lld_lcdWriteReg(0x45, x0 & 0x01FF); - lld_lcdWriteReg(0x46, (x1-1) & 0x01FF); - break; - case portraitInv: - lld_lcdWriteReg(0x44, (((SCREEN_WIDTH-x0-1) & 0x00FF) << 8) | ((SCREEN_WIDTH - x1) & 0x00FF)); - lld_lcdWriteReg(0x45, (SCREEN_HEIGHT-y1) & 0x01FF); - lld_lcdWriteReg(0x46, (SCREEN_HEIGHT-y0-1) & 0x01FF); - break; - case landscapeInv: - lld_lcdWriteReg(0x44, (((SCREEN_WIDTH - y0 - 1) & 0x00FF) << 8) | ((SCREEN_WIDTH - y1) & 0x00FF)); - lld_lcdWriteReg(0x45, (SCREEN_HEIGHT - x1) & 0x01FF); - lld_lcdWriteReg(0x46, (SCREEN_HEIGHT - x0 - 1) & 0x01FF); - break; - } - - lld_lcdSetCursor(x0, y0); -} - -void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) { - uint32_t index = 0, area; - - area = ((x1-x0)*(y1-y0)); - - lld_lcdSetWindow(x0, y0, x1, y1); - lld_lcdWriteStreamStart(); - - for(index = 0; index < area; index++) - lld_lcdWriteData(color); - - lld_lcdWriteStreamStop(); -} - -void lld_lcdClear(uint16_t color) { - uint32_t index = 0; - - lld_lcdSetCursor(0, 0); - lld_lcdWriteStreamStart(); - - for(index = 0; index < SCREEN_WIDTH * SCREEN_HEIGHT; index++) - lld_lcdWriteData(color); - - lld_lcdWriteStreamStop(); -} - -uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y) { - uint16_t dummy; - - lld_lcdSetCursor(x,y); - lld_lcdWriteStreamStart(); - - dummy = lld_lcdReadData(); - dummy = lld_lcdReadData(); - - lld_lcdWriteStreamStop(); - - return dummy; -} - -void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) { - lld_lcdSetCursor(x, y); - lld_lcdWriteReg(0x0022, 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); 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) { - return orientation; -} - -uint16_t lld_lcdGetHeight(void) { - return lcd_height; -} - -uint16_t lld_lcdGetWidth(void) { - return lcd_width; -} - -/* a positive lines value shifts the screen up, negative down */ -void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines) { - uint16_t row0, row1; - uint16_t i; - - lld_lcdSetWindow(x0, y0, x1, y1); - - for(i = 0; i < ((y1-y0) - abs(lines)); i++) { - if(lines > 0) { - row0 = y0 + i + lines; - row1 = y0 + i; - } else { - row0 = (y1 - i - 1) + lines; - row1 = (y1 - i - 1); - } - - /* read row0 into the buffer and then write at row1*/ - lld_lcdSetWindow(x0, row0, x1, row0); - lld_lcdReadStreamStart(); - lld_lcdReadStream(buf, x1-x0); - lld_lcdReadStreamStop(); - - lld_lcdSetWindow(x0, row1, x1, row1); - lld_lcdWriteStreamStart(); - lld_lcdWriteStream(buf, x1-x0); - lld_lcdWriteStreamStop(); - } -} - -#endif - diff --git a/drivers/lcd/ssd1289_lld.h b/drivers/lcd/ssd1289_lld.h deleted file mode 100644 index 60f9e569..00000000 --- a/drivers/lcd/ssd1289_lld.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2012 - Joel Bodenmann aka Tectu <joel@unormal.org> - - 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 <http://www.gnu.org/licenses/>. -*/ - -#ifndef SSD1289_H -#define SSD1289_H - -#include "glcd.h" - -#ifdef LCD_USE_SSD1289 - -#ifdef __cplusplus -extern "C" { -#endif - -void lld_lcdInit(void); -void lld_lcdWriteStreamStart(void); -void lld_lcdWriteStreamStop(void); -void lld_lcdWriteStream(uint16_t *buffer, uint16_t size); -void lld_lcdSetCursor(uint16_t x, uint16_t y); -void lld_lcdSetOrientation(uint8_t newOrientation); -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); -uint16_t lld_lcdGetWidth(void); -void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines); - -#ifdef __cplusplus -} -#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 - |