2012-08-13 02:12:42 +00:00
|
|
|
/*
|
|
|
|
ChibiOS/RT - Copyright (C) 2012
|
|
|
|
Joel Bodenmann aka Tectu <joel@unormal.org>
|
|
|
|
|
2012-09-24 22:19:10 +00:00
|
|
|
This file is part of ChibiOS/GFX.
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-24 22:19:10 +00:00
|
|
|
ChibiOS/GFX is free software; you can redistribute it and/or modify
|
2012-08-13 02:12:42 +00:00
|
|
|
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.
|
|
|
|
|
2012-09-24 22:19:10 +00:00
|
|
|
ChibiOS/GFX is distributed in the hope that it will be useful,
|
2012-08-13 02:12:42 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
// I/O assignments
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_BL_GPIO GPIOB
|
|
|
|
#define GDISP_BL_PIN 8
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_CS_GPIO GPIOD
|
|
|
|
#define GDISP_CS_PIN 7
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_RS_GPIO GPIOD
|
|
|
|
#define GDISP_RS_PIN 11
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_RST_GPIO GPIOD
|
|
|
|
#define GDISP_RST_PIN 10
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_RD_GPIO GPIOD
|
|
|
|
#define GDISP_RD_PIN 9
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_WR_GPIO GPIOD
|
|
|
|
#define GDISP_WR_PIN 8
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_D0_GPIO GPIOD
|
|
|
|
#define GDISP_D4_GPIO GPIOE
|
2012-08-13 02:12:42 +00:00
|
|
|
|
|
|
|
/* all interfaces use RST via GPIO */
|
|
|
|
/* TODO: option to disable RST; assumes RST is tied high */
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_RST_LOW palClearPad(GDISP_RST_GPIO, GDISP_RST_PIN)
|
|
|
|
#define GDISP_RST_HIGH palSetPad(GDISP_RST_GPIO, GDISP_RST_PIN)
|
2012-08-13 02:12:42 +00:00
|
|
|
|
|
|
|
#define s6d1121_delay(n) halPolledDelay(MS2RTT(n));
|
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#if defined(GDISP_USE_GPIO)
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_CS_LOW palClearPad(GDISP_CS_GPIO, GDISP_CS_PIN)
|
|
|
|
#define GDISP_CS_HIGH palSetPad(GDISP_CS_GPIO, GDISP_CS_PIN)
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_RS_LOW palClearPad(GDISP_RS_GPIO, GDISP_RS_PIN)
|
|
|
|
#define GDISP_RS_HIGH palSetPad(GDISP_RS_GPIO, GDISP_RS_PIN)
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_RD_LOW palClearPad(GDISP_RD_GPIO, GDISP_RD_PIN)
|
|
|
|
#define GDISP_RD_HIGH palSetPad(GDISP_RD_GPIO, GDISP_RD_PIN)
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_WR_LOW palClearPad(GDISP_WR_GPIO, GDISP_WR_PIN)
|
|
|
|
#define GDISP_WR_HIGH palSetPad(GDISP_WR_GPIO, GDISP_WR_PIN)
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#define GDISP_BL_LOW palClearPad(GDISP_BL_GPIO, GDISP_BL_PIN)
|
|
|
|
#define GDISP_BL_HIGH palSetPad(GDISP_BL_GPIO, GDISP_BL_PIN)
|
2012-08-13 02:12:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
static inline void lld_lcddelay(void) { asm volatile ("nop"); asm volatile ("nop"); }
|
|
|
|
static inline void lld_lcdwrite(uint16_t db) {
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_D4_GPIO->BSRR.W=((~db&0xFFF0)<<16)|(db&0xFFF0);
|
|
|
|
GDISP_D0_GPIO->BSRR.W=((~db&0x000F)<<16)|(db&0x000F);
|
|
|
|
GDISP_WR_LOW;
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcddelay();
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_WR_HIGH;
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
|
|
|
static __inline uint16_t lld_lcdReadData(void) {
|
|
|
|
uint16_t value=0;
|
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_RS_HIGH; GDISP_WR_HIGH; GDISP_RD_LOW;
|
2012-08-13 02:12:42 +00:00
|
|
|
#ifndef STM32F4XX
|
|
|
|
// change pin mode to digital input
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_DATA_PORT->CRH = 0x47444444;
|
|
|
|
GDISP_DATA_PORT->CRL = 0x47444444;
|
2012-08-13 02:12:42 +00:00
|
|
|
#endif
|
|
|
|
#ifndef STM32F4XX
|
|
|
|
// change pin mode back to digital output
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_DATA_PORT->CRH = 0x33333333;
|
|
|
|
GDISP_DATA_PORT->CRL = 0x33333333;
|
2012-08-13 02:12:42 +00:00
|
|
|
#endif
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_RD_HIGH;
|
2012-08-13 02:12:42 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
|
|
|
|
uint16_t lcdRAM;
|
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_CS_LOW; GDISP_RS_LOW;
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdwrite(lcdReg);
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_RS_HIGH;
|
2012-08-13 02:12:42 +00:00
|
|
|
lcdRAM = lld_lcdReadData();
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_CS_HIGH;
|
2012-08-13 02:12:42 +00:00
|
|
|
return lcdRAM;
|
|
|
|
}
|
|
|
|
static void lld_lcdWriteIndex(uint16_t lcdReg) {
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_RS_LOW;
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdwrite(lcdReg);
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_RS_HIGH;
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
|
|
|
static void lld_lcdWriteData(uint16_t lcdData) {
|
|
|
|
lld_lcdwrite(lcdData);
|
|
|
|
}
|
|
|
|
static void lld_lcdWriteReg(uint16_t lcdReg, uint16_t lcdRegValue) {
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_CS_LOW;
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdWriteIndex(lcdReg);
|
|
|
|
lld_lcdWriteData(lcdRegValue);
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_CS_HIGH;
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
|
|
|
static __inline void lld_lcdWriteStreamStart(void) {
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_CS_LOW;
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdWriteIndex(0x0022);
|
|
|
|
}
|
|
|
|
static __inline void lld_lcdWriteStreamStop(void) {
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_CS_HIGH;
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
|
|
|
static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
|
|
|
|
uint16_t i;
|
|
|
|
|
|
|
|
for(i = 0; i < size; i++) { lld_lcdwrite(buffer[i]); }
|
|
|
|
}
|
|
|
|
static __inline void lld_lcdReadStreamStart(void) { /* TODO */ }
|
|
|
|
static __inline void lld_lcdReadStreamStop(void) { /* TODO */ }
|
2012-09-26 18:18:18 +00:00
|
|
|
static __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
|
|
|
(void)buffer;
|
|
|
|
(void)size;
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
}
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#elif defined(GDISP_USE_FSMC)
|
|
|
|
#define GDISP_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
|
|
|
|
#define GDISP_RAM (*((volatile uint16_t *) 0x60020000)) /* RS = 1 */
|
2012-08-13 02:12:42 +00:00
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
static __inline void lld_lcdWriteIndex(uint16_t index) { GDISP_REG = index; }
|
|
|
|
static __inline void lld_lcdWriteData(uint16_t data) { GDISP_RAM = data; }
|
2012-08-13 02:12:42 +00:00
|
|
|
static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_REG = lcdReg;
|
|
|
|
GDISP_RAM = lcdRegValue;
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
2012-09-29 18:56:30 +00:00
|
|
|
static __inline uint16_t lld_lcdReadData(void) { return (GDISP_RAM); }
|
2012-08-13 02:12:42 +00:00
|
|
|
static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
|
2012-09-29 18:56:30 +00:00
|
|
|
GDISP_REG = lcdReg;
|
|
|
|
return GDISP_RAM;
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
2012-09-29 18:56:30 +00:00
|
|
|
static __inline void lld_lcdWriteStreamStart(void) { GDISP_REG = 0x0022; }
|
2012-08-13 02:12:42 +00:00
|
|
|
static __inline void lld_lcdWriteStreamStop(void) {}
|
|
|
|
static __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
|
|
|
|
uint16_t i;
|
2012-09-29 18:56:30 +00:00
|
|
|
for(i = 0; i < size; i++) GDISP_RAM = buffer[i];
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
2012-09-29 18:56:30 +00:00
|
|
|
static __inline void lld_lcdReadStreamStart(void) { GDISP_REG = 0x0022; }
|
2012-08-13 02:12:42 +00:00
|
|
|
static __inline void lld_lcdReadStreamStop(void) {}
|
|
|
|
static __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
|
|
|
uint16_t i;
|
|
|
|
volatile uint16_t dummy;
|
|
|
|
|
|
|
|
/* throw away first value read */
|
2012-09-29 18:56:30 +00:00
|
|
|
dummy = GDISP_RAM;
|
|
|
|
for(i = 0; i < size; i++) buffer[i] = GDISP_RAM;
|
2012-08-13 02:12:42 +00:00
|
|
|
}
|
|
|
|
|
2012-09-29 18:56:30 +00:00
|
|
|
#elif defined(GDISP_USE_SPI)
|
|
|
|
#error "gdispS6d1121: GDISP_USE_SPI not implemented yet"
|
2012-08-13 02:12:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void lld_lcdSetCursor(coord_t x, coord_t y) {
|
|
|
|
/* R20h - 8 bit
|
|
|
|
* R21h - 9 bit
|
|
|
|
*/
|
|
|
|
switch(GDISP.Orientation) {
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_0:
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdWriteReg(0x0020, x & 0x00FF);
|
|
|
|
lld_lcdWriteReg(0x0021, y & 0x01FF);
|
|
|
|
break;
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_90:
|
2012-10-05 19:08:34 +00:00
|
|
|
/* Note X has already been mirrored, so we do it directly */
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdWriteReg(0x0020, y & 0x00FF);
|
|
|
|
lld_lcdWriteReg(0x0021, x & 0x01FF);
|
|
|
|
break;
|
2012-10-05 19:08:34 +00:00
|
|
|
case GDISP_ROTATE_180:
|
2012-10-10 23:41:18 +00:00
|
|
|
lld_lcdWriteReg(0x0020, (GDISP_SCREEN_WIDTH - 1 - x) & 0x00FF);
|
|
|
|
lld_lcdWriteReg(0x0021, (GDISP_SCREEN_HEIGHT - 1 - y) & 0x01FF);
|
2012-10-05 19:08:34 +00:00
|
|
|
break;
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_270:
|
2012-10-10 23:41:18 +00:00
|
|
|
lld_lcdWriteReg(0x0020, (GDISP_SCREEN_WIDTH - 1 - y) & 0x00FF);
|
|
|
|
lld_lcdWriteReg(0x0021, (GDISP_SCREEN_HEIGHT - 1 - x) & 0x01FF);
|
2012-08-13 02:12:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lld_lcdSetViewPort(uint16_t x, uint16_t y, uint16_t cx, uint16_t cy) {
|
|
|
|
/* HSA / HEA are 8 bit
|
|
|
|
* VSA / VEA are 9 bit
|
|
|
|
* use masks 0x00FF and 0x01FF to enforce this
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch(GDISP.Orientation) {
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_0:
|
2012-10-05 19:08:34 +00:00
|
|
|
lld_lcdWriteReg(0x46, (((x + cx - 1) << 8) & 0xFF00 ) |
|
|
|
|
(x & 0x00FF));
|
|
|
|
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdWriteReg(0x48, y & 0x01FF);
|
2012-10-05 19:08:34 +00:00
|
|
|
lld_lcdWriteReg(0x47, (y + cy - 1) & 0x01FF);
|
2012-08-13 02:12:42 +00:00
|
|
|
break;
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_90:
|
2012-10-05 19:08:34 +00:00
|
|
|
lld_lcdWriteReg(0x46, (((y + cy - 1) << 8) & 0xFF00) |
|
|
|
|
(y & 0x00FF));
|
|
|
|
|
2012-08-13 02:12:42 +00:00
|
|
|
lld_lcdWriteReg(0x48, x & 0x01FF);
|
2012-10-05 19:08:34 +00:00
|
|
|
lld_lcdWriteReg(0x47, (x + cx - 1) & 0x01FF);
|
2012-08-13 02:12:42 +00:00
|
|
|
break;
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_180:
|
2012-10-10 23:41:18 +00:00
|
|
|
lld_lcdWriteReg(0x46, (((GDISP_SCREEN_WIDTH - x - 1) & 0x00FF) << 8) |
|
|
|
|
((GDISP_SCREEN_WIDTH - (x + cx)) & 0x00FF));
|
|
|
|
lld_lcdWriteReg(0x48, (GDISP_SCREEN_HEIGHT - (y + cy)) & 0x01FF);
|
|
|
|
lld_lcdWriteReg(0x47, (GDISP_SCREEN_HEIGHT- y - 1) & 0x01FF);
|
2012-08-13 02:12:42 +00:00
|
|
|
break;
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_270:
|
2012-10-10 23:41:18 +00:00
|
|
|
lld_lcdWriteReg(0x46, (((GDISP_SCREEN_WIDTH - y - 1) & 0x00FF) << 8) |
|
|
|
|
((GDISP_SCREEN_WIDTH - (y + cy)) & 0x00FF));
|
|
|
|
lld_lcdWriteReg(0x48, (GDISP_SCREEN_HEIGHT - (x + cx)) & 0x01FF);
|
|
|
|
lld_lcdWriteReg(0x47, (GDISP_SCREEN_HEIGHT - x - 1) & 0x01FF);
|
2012-08-13 02:12:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lld_lcdSetCursor(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lld_lcdResetViewPort(void) {
|
|
|
|
switch(GDISP.Orientation) {
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
case GDISP_ROTATE_180:
|
2012-10-10 23:41:18 +00:00
|
|
|
lld_lcdSetViewPort(0, 0, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT);
|
2012-08-13 02:12:42 +00:00
|
|
|
break;
|
2012-10-05 07:20:39 +00:00
|
|
|
case GDISP_ROTATE_90:
|
|
|
|
case GDISP_ROTATE_270:
|
2012-10-10 23:41:18 +00:00
|
|
|
lld_lcdSetViewPort(0, 0, GDISP_SCREEN_HEIGHT, GDISP_SCREEN_WIDTH);
|
2012-08-13 02:12:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* S6D1121_H */
|