From 7f60fd9f8067f7405fffffa2884ca88692c7cf09 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Sun, 15 Nov 2009 14:34:14 +0000 Subject: [PATCH] add lcd driver for U-EasyTech STM32F103, STM32F107 board. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@164 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- bsp/stm3210/stm3210c_eval_lcd.c | 551 ++++++++++++++++++++++++++++++++ bsp/stm3210/stm3210c_eval_lcd.h | 135 ++++++++ bsp/stm3210/stm3210e_eval_lcd.c | 487 ++++++++++++++++++++++++++++ bsp/stm3210/stm3210e_eval_lcd.h | 148 +++++++++ 4 files changed, 1321 insertions(+) create mode 100644 bsp/stm3210/stm3210c_eval_lcd.c create mode 100644 bsp/stm3210/stm3210c_eval_lcd.h create mode 100644 bsp/stm3210/stm3210e_eval_lcd.c create mode 100644 bsp/stm3210/stm3210e_eval_lcd.h diff --git a/bsp/stm3210/stm3210c_eval_lcd.c b/bsp/stm3210/stm3210c_eval_lcd.c new file mode 100644 index 0000000000..729ea11fc0 --- /dev/null +++ b/bsp/stm3210/stm3210c_eval_lcd.c @@ -0,0 +1,551 @@ +#include +#include "stm3210c_eval_lcd.h" +#include "stm32f10x.h" +#include "stm32f10x_spi.h" + +#include +#include +#include +#include + +#define START_BYTE 0x70 +#define SET_INDEX 0x00 +#define READ_STATUS 0x01 +#define LCD_WRITE_REG 0x02 +#define LCD_READ_REG 0x03 + +void rt_hw_lcd_update(rtgui_rect_t *rect); +rt_uint8_t * rt_hw_lcd_get_framebuffer(void); +void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); +void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); +void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y); +void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2); +void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y); + +struct rtgui_graphic_driver _rtgui_lcd_driver = + { + "lcd", + 2, + 320, + 240, + rt_hw_lcd_update, + rt_hw_lcd_get_framebuffer, + rt_hw_lcd_set_pixel, + rt_hw_lcd_get_pixel, + rt_hw_lcd_draw_hline, + rt_hw_lcd_draw_vline, + rt_hw_lcd_draw_raw_hline + }; + +static void _delay_(__IO uint32_t nCount) +{ + __IO uint32_t index = 0; + for(index = (100000 * nCount); index != 0; index--) + {} +} + +/** + * @brief Sets or reset LCD control lines. + * @param GPIOx: where x can be B or D to select the GPIO peripheral. + * @param CtrlPins: the Control line. This parameter can be: + * @arg LCD_NCS_PIN: Chip Select pin + * @param BitVal: specifies the value to be written to the selected bit. + * This parameter can be: + * @arg Bit_RESET: to clear the port pin + * @arg Bit_SET: to set the port pin + * @retval None + */ +void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal) +{ + /* Set or Reset the control line */ + GPIO_WriteBit(GPIOx, CtrlPins, BitVal); +} + +/** + * @brief Reset LCD control line(/CS) and Send Start-Byte + * @param Start_Byte: the Start-Byte to be sent + * @retval None + */ +void LCD_nCS_StartByte(uint8_t Start_Byte) +{ + LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET); + SPI_I2S_SendData(LCD_SPI, Start_Byte); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} +} + +/** + * @brief Configures LCD control lines in Output Push-Pull mode. + * @param None + * @retval None + */ +void LCD_CtrlLinesConfig(void) +{ + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_APB2PeriphClockCmd(LCD_NCS_GPIO_CLK, ENABLE); + + /* Configure NCS in Output Push-Pull mode */ + GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure); +} + +/** + * @brief Writes index to select the LCD register. + * @param LCD_Reg: address of the selected register. + * @retval None + */ +void LCD_WriteRegIndex(uint8_t LCD_Reg) +{ + /* Reset LCD control line(/CS) and Send Start-Byte */ + LCD_nCS_StartByte(START_BYTE | SET_INDEX); + /* Write 16-bit Reg Index (High Byte is 0) */ + SPI_I2S_SendData(LCD_SPI, 0x00); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + SPI_I2S_SendData(LCD_SPI, LCD_Reg); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); +} + +/** + * @brief Reads the selected LCD Register. + * @param None + * @retval LCD Register Value. + */ +uint16_t LCD_ReadReg(uint8_t LCD_Reg) +{ + uint16_t tmp = 0; + uint8_t i = 0; + + /* LCD_SPI prescaler: 4 */ + LCD_SPI->CR1 &= 0xFFC7; + LCD_SPI->CR1 |= 0x0008; + /* Write 16-bit Index (then Read Reg) */ + LCD_WriteRegIndex(LCD_Reg); + /* Read 16-bit Reg */ + /* Reset LCD control line(/CS) and Send Start-Byte */ + LCD_nCS_StartByte(START_BYTE | LCD_READ_REG); + + for(i = 0; i < 5; i++) + { + SPI_I2S_SendData(LCD_SPI, 0xFF); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + /* One byte of invalid dummy data read after the start byte */ + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET) + {} + SPI_I2S_ReceiveData(LCD_SPI); + } + SPI_I2S_SendData(LCD_SPI, 0xFF); + /* Read upper byte */ + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + /* Read lower byte */ + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET) + {} + tmp = SPI_I2S_ReceiveData(LCD_SPI); + + + SPI_I2S_SendData(LCD_SPI, 0xFF); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + /* Read lower byte */ + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET) + {} + tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(LCD_SPI); + LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); + /* LCD_SPI prescaler: 2 */ + LCD_SPI->CR1 &= 0xFFC7; + return tmp; +} + +/** + * @brief Writes to the selected LCD register. + * @param LCD_Reg: address of the selected register. + * @param LCD_RegValue: value to write to the selected register. + * @retval None + */ +void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue) +{ + /* Write 16-bit Index (then Write Reg) */ + LCD_WriteRegIndex(LCD_Reg); + /* Write 16-bit Reg */ + /* Reset LCD control line(/CS) and Send Start-Byte */ + LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG); + SPI_I2S_SendData(LCD_SPI, LCD_RegValue>>8); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + SPI_I2S_SendData(LCD_SPI, (LCD_RegValue & 0xFF)); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); +} + +/** + * @brief Writes to the LCD RAM. + * @param RGB_Code: the pixel color in RGB mode (5-6-5). + * @retval None + */ +void LCD_WriteRAM(uint16_t RGB_Code) +{ + SPI_I2S_SendData(LCD_SPI, RGB_Code >> 8); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} + SPI_I2S_SendData(LCD_SPI, RGB_Code & 0xFF); + while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) + {} +} + +/** + * @brief Prepare to write to the LCD RAM. + * @param None + * @retval None + */ +void LCD_WriteRAM_Prepare(void) +{ + LCD_WriteRegIndex(R34); /* Select GRAM Reg */ + /* Reset LCD control line(/CS) and Send Start-Byte */ + LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG); +} + +/** + * @brief Writes 1 word to the LCD RAM. + * @param RGB_Code: the pixel color in RGB mode (5-6-5). + * @retval None + */ +void LCD_WriteRAMWord(uint16_t RGB_Code) +{ + LCD_WriteRAM_Prepare(); + LCD_WriteRAM(RGB_Code); + LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); +} + +/** + * @brief Power on the LCD. + * @param None + * @retval None + */ +void LCD_PowerOn(void) +{ + /* Power On sequence ---------------------------------------------------------*/ + LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ + LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ + LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */ + LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */ + _delay_(20); /* Dis-charge capacitor power voltage (200ms) */ + LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ + LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ + _delay_(5); /* Delay 50 ms */ + LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */ + _delay_(5); /* delay 50 ms */ + LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ + LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */ + _delay_(5); /* delay 50 ms */ + LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */ +} + +/** + * @brief Enables the Display. + * @param None + * @retval None + */ +void LCD_DisplayOn(void) +{ + /* Display On */ + LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */ + +} + +/** + * @brief Disables the Display. + * @param None + * @retval None + */ +void LCD_DisplayOff(void) +{ + /* Display Off */ + LCD_WriteReg(R7, 0x0); +} + +/** + * @brief Configures the LCD_SPI interface. + * @param None + * @retval None + */ +void LCD_SPIConfig(void) +{ + SPI_InitTypeDef SPI_InitStructure; + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable GPIO clock */ + RCC_APB2PeriphClockCmd(LCD_SPI_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE); + GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE); + + /* Enable SPI clock */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); + + /* Configure SPI pins: SCK, MISO and MOSI */ + GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN | LCD_SPI_MISO_PIN | LCD_SPI_MOSI_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Init(LCD_SPI_GPIO_PORT, &GPIO_InitStructure); + + SPI_I2S_DeInit(LCD_SPI); + + /* SPI Config */ + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_Init(LCD_SPI, &SPI_InitStructure); + + /* SPI enable */ + SPI_Cmd(LCD_SPI, ENABLE); +} + +/** + * @brief Setups the LCD. + * @param None + * @retval None + */ +void LCD_Setup(void) +{ + /* Configure the LCD Control pins --------------------------------------------*/ + LCD_CtrlLinesConfig(); + + /* Configure the LCD_SPI interface ----------------------------------------------*/ + LCD_SPIConfig(); + _delay_(5); /* Delay 50 ms */ + /* Start Initial Sequence ------------------------------------------------*/ + LCD_WriteReg(R229, 0x8000); /* Set the internal vcore voltage */ + LCD_WriteReg(R0, 0x0001); /* Start internal OSC. */ + LCD_WriteReg(R1, 0x0100); /* set SS and SM bit */ + LCD_WriteReg(R2, 0x0700); /* set 1 line inversion */ + LCD_WriteReg(R3, 0x1030); /* set GRAM write direction and BGR=1. */ + LCD_WriteReg(R4, 0x0000); /* Resize register */ + LCD_WriteReg(R8, 0x0202); /* set the back porch and front porch */ + LCD_WriteReg(R9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ + LCD_WriteReg(R10, 0x0000); /* FMARK function */ + LCD_WriteReg(R12, 0x0000); /* RGB interface setting */ + LCD_WriteReg(R13, 0x0000); /* Frame marker Position */ + LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */ + /* Power On sequence -----------------------------------------------------*/ + LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ + LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ + LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */ + LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */ + _delay_(20); /* Dis-charge capacitor power voltage (200ms) */ + LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ + LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ + _delay_(5); /* Delay 50 ms */ + LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */ + _delay_(5); /* Delay 50 ms */ + LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ + LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */ + _delay_(5); /* Delay 50 ms */ + LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */ + LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */ + /* Adjust the Gamma Curve ------------------------------------------------*/ + LCD_WriteReg(R48, 0x0006); + LCD_WriteReg(R49, 0x0101); + LCD_WriteReg(R50, 0x0003); + LCD_WriteReg(R53, 0x0106); + LCD_WriteReg(R54, 0x0b02); + LCD_WriteReg(R55, 0x0302); + LCD_WriteReg(R56, 0x0707); + LCD_WriteReg(R57, 0x0007); + LCD_WriteReg(R60, 0x0600); + LCD_WriteReg(R61, 0x020b); + + /* Set GRAM area ---------------------------------------------------------*/ + LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */ + LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */ + LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */ + LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */ + LCD_WriteReg(R96, 0xa700); /* Gate Scan Line */ + LCD_WriteReg(R97, 0x0001); /* NDL,VLE, REV */ + LCD_WriteReg(R106, 0x0000); /* set scrolling line */ + /* Partial Display Control -----------------------------------------------*/ + LCD_WriteReg(R128, 0x0000); + LCD_WriteReg(R129, 0x0000); + LCD_WriteReg(R130, 0x0000); + LCD_WriteReg(R131, 0x0000); + LCD_WriteReg(R132, 0x0000); + LCD_WriteReg(R133, 0x0000); + /* Panel Control ---------------------------------------------------------*/ + LCD_WriteReg(R144, 0x0010); + LCD_WriteReg(R146, 0x0000); + LCD_WriteReg(R147, 0x0003); + LCD_WriteReg(R149, 0x0110); + LCD_WriteReg(R151, 0x0000); + LCD_WriteReg(R152, 0x0000); + /* Set GRAM write direction and BGR = 1 */ + /* I/D=01 (Horizontal : increment, Vertical : decrement) */ + /* AM=1 (address is updated in vertical writing direction) */ + LCD_WriteReg(R3, 0x1018); + LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */ +} + +/** + * @brief Sets the cursor position. + * @param Xpos: specifies the X position. + * @param Ypos: specifies the Y position. + * @retval None + */ +void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos) +{ + LCD_WriteReg(R32, Xpos); + LCD_WriteReg(R33, Ypos); +} + + +void rt_hw_lcd_update(rtgui_rect_t *rect) +{ + /* nothing for none-DMA mode driver */ +} + +rt_uint8_t * rt_hw_lcd_get_framebuffer(void) +{ + return RT_NULL; /* no framebuffer driver */ +} + +void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) +{ + unsigned short p; + + /* get color pixel */ + p = rtgui_color_to_565p(*c); + + /* set x and y */ + LCD_SetCursor(y, 319 - x); + LCD_WriteRAMWord(p); +} + +void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) +{ + // unsigned short p; + + /* set x and y */ + LCD_SetCursor(y, 319 - x); + + *c = rtgui_color_from_565p(0xffff); +} + +void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y) +{ + unsigned short p; + + /* get color pixel */ + p = rtgui_color_to_565p(*c); + + LCD_SetCursor(y, 319 - x1); + LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ + while (x1 < x2) + { + LCD_WriteRAM(p); + x1 ++; + } + LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); +} + +void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2) +{ + unsigned short p; + + /* get color pixel */ + p = rtgui_color_to_565p(*c); + + LCD_SetCursor(y1, 319 - x); + while (y1 < y2) + { + LCD_WriteRAMWord(p); + + y1++; + LCD_SetCursor(y1, 319 - x); + } +} + +void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) +{ + rt_uint16_t *ptr; + + /* get pixel */ + ptr = (rt_uint16_t*) pixels; + + LCD_SetCursor(y, 319 - x1); + LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ + while (x1 < x2) + { + LCD_WriteRAM(*ptr); + x1 ++; ptr ++; + } + LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); +} + +rt_err_t rt_hw_lcd_init(void) +{ + LCD_Setup(); + + /* add lcd driver into graphic driver */ + rtgui_graphic_driver_add(&_rtgui_lcd_driver); + return RT_EOK; +} + +void stm3210c_rtgui_init() +{ + rtgui_rect_t rect; + + rtgui_system_server_init(); + + /* register dock panel */ + rect.x1 = 0; + rect.y1 = 0; + rect.x2 = 320; + rect.y2 = 25; + rtgui_panel_register("info", &rect); + + /* register main panel */ + rect.x1 = 0; + rect.y1 = 25; + rect.x2 = 320; + rect.y2 = 240; + rtgui_panel_register("main", &rect); + rtgui_panel_set_default_focused("main"); + + rt_hw_lcd_init(); + + info_init(); + today_init(); +} + +#include + +void hline(rt_base_t x1, rt_base_t x2, rt_base_t y, rt_uint32_t pixel) +{ + rt_hw_lcd_draw_hline(&pixel, x1, x2, y); +} +FINSH_FUNCTION_EXPORT(hline, draw a hline); + +void vline(int x, int y1, int y2, rt_uint32_t pixel) +{ + rt_hw_lcd_draw_vline(&pixel, x, y1, y2); +} +FINSH_FUNCTION_EXPORT(vline, draw a vline); + +void cls(rt_uint32_t c) +{ + rt_size_t index; + + for(index = 0; index < 240; index ++) + rt_hw_lcd_draw_hline(&c, 0, 320, index); +} +FINSH_FUNCTION_EXPORT(cls, clear screen); diff --git a/bsp/stm3210/stm3210c_eval_lcd.h b/bsp/stm3210/stm3210c_eval_lcd.h new file mode 100644 index 0000000000..c83d7262ee --- /dev/null +++ b/bsp/stm3210/stm3210c_eval_lcd.h @@ -0,0 +1,135 @@ +#ifndef __STM3210C_EVAL_LCD_H__ +#define __STM3210C_EVAL_LCD_H__ + + +/** + * @brief LCD Control pins + */ +#define LCD_NCS_PIN GPIO_Pin_2 +#define LCD_NCS_GPIO_PORT GPIOB +#define LCD_NCS_GPIO_CLK RCC_APB2Periph_GPIOB + +/** + * @brief LCD SPI Interface pins + */ +#define LCD_SPI_SCK_PIN GPIO_Pin_10 +#define LCD_SPI_MISO_PIN GPIO_Pin_11 +#define LCD_SPI_MOSI_PIN GPIO_Pin_12 +#define LCD_SPI_GPIO_PORT GPIOC +#define LCD_SPI_GPIO_CLK RCC_APB2Periph_GPIOC +#define LCD_SPI SPI3 +#define LCD_SPI_CLK RCC_APB1Periph_SPI3 + +/** + * @brief 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 diff --git a/bsp/stm3210/stm3210e_eval_lcd.c b/bsp/stm3210/stm3210e_eval_lcd.c new file mode 100644 index 0000000000..f53fe02cd9 --- /dev/null +++ b/bsp/stm3210/stm3210e_eval_lcd.c @@ -0,0 +1,487 @@ +#include + +#include "stm32f10x.h" +#include "stm32f10x_fsmc.h" +#include "stm3210e_eval_lcd.h" + +#ifdef RT_USING_RTGUI + +#include +#include + +/* + * LCD Driver + * RGB mode (5-6-5) + * 240 x 320 pixel LCD + */ +/* convert rtgui color to hardware color, rgb 5-6-5 */ +typedef struct +{ + rt_uint16_t LCD_REG; + rt_uint16_t LCD_RAM; +} LCD_TypeDef; + +/* Note: LCD /CS is CE4 - Bank 4 of NOR/SRAM Bank 1~4 */ +#define LCD_BASE ((rt_uint32_t)(0x60000000 | 0x0C000000)) +#define LCD ((LCD_TypeDef *) LCD_BASE) + +/******************************************************************************* +* Function Name : LCD_WriteReg +* Description : Writes to the selected LCD register. +* Input : - LCD_Reg: address of the selected register. +* - LCD_RegValue: value to write to the selected register. +* Output : None +* Return : None +*******************************************************************************/ +void LCD_WriteReg(rt_uint8_t LCD_Reg, rt_uint16_t LCD_RegValue) +{ + /* Write 16-bit Index, then Write Reg */ + LCD->LCD_REG = LCD_Reg; + /* Write 16-bit Reg */ + LCD->LCD_RAM = LCD_RegValue; +} + +/******************************************************************************* +* Function Name : LCD_ReadReg +* Description : Reads the selected LCD Register. +* Input : None +* Output : None +* Return : LCD Register Value. +*******************************************************************************/ +rt_uint16_t LCD_ReadReg(rt_uint8_t LCD_Reg) +{ + /* Write 16-bit Index (then Read Reg) */ + LCD->LCD_REG = LCD_Reg; + /* Read 16-bit Reg */ + return (LCD->LCD_RAM); +} + +/******************************************************************************* +* Function Name : LCD_WriteRAM_Prepare +* Description : Prepare to write to the LCD RAM. +* Input : None +* Output : None +* Return : None +*******************************************************************************/ +void LCD_WriteRAM_Prepare(void) +{ + LCD->LCD_REG = R34; +} + +/******************************************************************************* +* Function Name : LCD_WriteRAM +* Description : Writes to the LCD RAM. +* Input : - RGB_Code: the pixel color in RGB mode (5-6-5). +* Output : None +* Return : None +*******************************************************************************/ +rt_inline void LCD_WriteRAM(rt_uint16_t RGB_Code) +{ + /* Write 16-bit GRAM Reg */ + LCD->LCD_RAM = RGB_Code; +} + +/******************************************************************************* +* Function Name : LCD_ReadRAM +* Description : Reads the LCD RAM. +* Input : None +* Output : None +* Return : LCD RAM Value. +*******************************************************************************/ +rt_inline rt_uint16_t LCD_ReadRAM(void) +{ + /* Write 16-bit Index (then Read Reg) */ + LCD->LCD_REG = R34; /* Select GRAM Reg */ + /* Read 16-bit Reg */ + return LCD->LCD_RAM; +} + +/******************************************************************************* +* Function Name : LCD_DisplayOn +* Description : Enables the Display. +* Input : None +* Output : None +* Return : None +*******************************************************************************/ +void LCD_DisplayOn(void) +{ + /* Display On */ + LCD_WriteReg(0x26, 0x3C); /* 262K color and display ON */ +} + +/******************************************************************************* +* Function Name : LCD_DisplayOff +* Description : Disables the Display. +* Input : None +* Output : None +* Return : None +*******************************************************************************/ +void LCD_DisplayOff(void) +{ + /* Display Off */ + LCD_WriteReg(0x26, 0x0); +} + +/******************************************************************************* +* Function Name : LCD_SetCursor +* Description : Sets the cursor position. +* Input : - Xpos: specifies the X position. +* - Ypos: specifies the Y position. +* Output : None +* Return : None +*******************************************************************************/ +void LCD_SetCursor(rt_uint32_t x, rt_uint32_t y) +{ + LCD_WriteReg(0x06, (x & 0xff00) >> 8); + LCD_WriteReg(0x07, (x & 0x00ff)); + + LCD_WriteReg(0x02, (y & 0xff00) >> 8); + LCD_WriteReg(0x03, (y & 0x00ff)); +} + +/******************************************************************************* +* Function Name : LCD_CtrlLinesConfig +* Description : Configures LCD Control lines (FSMC Pins) in alternate function + Push-Pull mode. +* Input : None +* Output : None +* Return : None +*******************************************************************************/ +void LCD_CtrlLinesConfig(void) +{ + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | + RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG | + RCC_APB2Periph_AFIO, ENABLE); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; + //±³¹â + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_ResetBits(GPIOA, GPIO_Pin_8); + //·äÃùÆ÷ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; + GPIO_Init(GPIOC, &GPIO_InitStructure); + GPIO_SetBits(GPIOC, GPIO_Pin_6); + + /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14), + PD.10(D15), PD.14(D0), PD.15(D1) as alternate + function push pull */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | + GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | + GPIO_Pin_15; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Init(GPIOD, &GPIO_InitStructure); + + /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10), + PE.14(D11), PE.15(D12) as alternate function push pull */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | + GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | + GPIO_Pin_15; + GPIO_Init(GPIOE, &GPIO_InitStructure); + + // GPIO_WriteBit(GPIOE, GPIO_Pin_6, Bit_SET); + /* Set PF.00(A0 (RS)) as alternate function push pull */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; + GPIO_Init(GPIOF, &GPIO_InitStructure); + + /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; + GPIO_Init(GPIOG, &GPIO_InitStructure); +} + +/******************************************************************************* +* Function Name : LCD_FSMCConfig +* Description : Configures the Parallel interface (FSMC) for LCD(Parallel mode) +* Input : None +* Output : None +* Return : None +*******************************************************************************/ +void LCD_FSMCConfig(void) +{ + FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; + FSMC_NORSRAMTimingInitTypeDef p; + + /*-- FSMC Configuration ------------------------------------------------------*/ + /*----------------------- SRAM Bank 4 ----------------------------------------*/ + /* FSMC_Bank1_NORSRAM4 configuration */ + p.FSMC_AddressSetupTime = 0; + p.FSMC_AddressHoldTime = 0; + p.FSMC_DataSetupTime = 2; + p.FSMC_BusTurnAroundDuration = 0; + p.FSMC_CLKDivision = 0; + p.FSMC_DataLatency = 0; + p.FSMC_AccessMode = FSMC_AccessMode_A; + + /* Color LCD configuration ------------------------------------ + LCD configured as follow: + - Data/Address MUX = Disable + - Memory Type = SRAM + - Data Width = 16bit + - Write Operation = Enable + - Extended Mode = Enable + - Asynchronous Wait = Disable */ + FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4; + FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; + FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; + FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; + FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; + FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; + FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; + FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; + FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; + FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; + FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; + // FSMC_NORSRAMInitStructure.FSMC_AsyncWait = FSMC_AsyncWait_Disable; + FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; + FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; + FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; + + FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); + + /* BANK 4 (of NOR/SRAM Bank 1~4) is enabled */ + FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE); +} + +void rt_hw_lcd_update(rtgui_rect_t *rect) +{ + /* nothing */ +} + +rt_uint8_t * rt_hw_lcd_get_framebuffer(void) +{ + return RT_NULL; +} + +void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) +{ + unsigned short p; + + /* get color pixel */ + p = rtgui_color_to_565p(*c); + + LCD_SetCursor(y, x); + + /* Prepare to write GRAM */ + LCD_WriteRAM_Prepare(); + LCD_WriteRAM(p); +} + +void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) +{ + rt_uint16_t hc; + + LCD_SetCursor(y, x); + hc = LCD_ReadRAM(); + *c = rtgui_color_from_565p(hc); +} + +void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y) +{ + rt_uint16_t hc; + + hc = rtgui_color_to_565p(*c); + + LCD_SetCursor(y, x1); + LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ + + while (x1 < x2) + { + LCD_WriteRAM(hc); + x1 ++; + } +} + +void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2) +{ + rt_uint16_t hc; + + hc = rtgui_color_to_565p(*c); + + while (y1 < y2) + { + LCD_SetCursor(y1, x); y1 ++; + + /* Prepare to write GRAM */ + LCD_WriteRAM_Prepare(); + LCD_WriteRAM(hc); + } +} + +void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) +{ + rt_uint16_t *ptr; + + /* get pixel */ + ptr = (rt_uint16_t*) pixels; + + LCD_SetCursor(y, x1); + LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ + + while (x1 < x2) + { + LCD_WriteRAM(*ptr); + x1 ++; ptr ++; + } +} + +struct rtgui_graphic_driver _rtgui_lcd_driver = +{ + "lcd", + 2, + 320, + 240, + rt_hw_lcd_update, + rt_hw_lcd_get_framebuffer, + rt_hw_lcd_set_pixel, + rt_hw_lcd_get_pixel, + rt_hw_lcd_draw_hline, + rt_hw_lcd_draw_vline, + rt_hw_lcd_draw_raw_hline +}; + +#define Delay(v) \ + { \ + volatile rt_uint32_t index; \ + for (index = 0; index < v * 100; index ++) \ + ; \ + } + +void rt_hw_lcd_init() +{ + /* Configure the LCD Control pins --------------------------------------------*/ + LCD_CtrlLinesConfig(); + + /* Configure the FSMC Parallel interface -------------------------------------*/ + LCD_FSMCConfig(); + + Delay(5); /* delay 50 ms */ + // Gamma for CMO 3.2¡± + LCD_WriteReg(0x46,0x94); + LCD_WriteReg(0x47,0x41); + LCD_WriteReg(0x48,0x00); + LCD_WriteReg(0x49,0x33); + LCD_WriteReg(0x4a,0x23); + LCD_WriteReg(0x4b,0x45); + LCD_WriteReg(0x4c,0x44); + LCD_WriteReg(0x4d,0x77); + LCD_WriteReg(0x4e,0x12); + LCD_WriteReg(0x4f,0xcc); + LCD_WriteReg(0x50,0x46); + LCD_WriteReg(0x51,0x82); + + //240x320 window setting + LCD_WriteReg(0x02,0x00); + LCD_WriteReg(0x03,0x00); + LCD_WriteReg(0x04,0x01); + LCD_WriteReg(0x05,0x3f); + LCD_WriteReg(0x06,0x00); + LCD_WriteReg(0x07,0x00); + LCD_WriteReg(0x08,0x00); + LCD_WriteReg(0x09,0xef); + + // Display Setting + LCD_WriteReg(0x01,0x06); + LCD_WriteReg(0x16,0x68); + LCD_WriteReg(0x23,0x95); + LCD_WriteReg(0x24,0x95); + LCD_WriteReg(0x25,0xff); + + LCD_WriteReg(0x27,0x02); + LCD_WriteReg(0x28,0x02); + LCD_WriteReg(0x29,0x02); + LCD_WriteReg(0x2a,0x02); + LCD_WriteReg(0x2c,0x02); + LCD_WriteReg(0x2d,0x02); + + LCD_WriteReg(0x3a,0x01);///******************* + LCD_WriteReg(0x3b,0x01); + LCD_WriteReg(0x3c,0xf0); + LCD_WriteReg(0x3d,0x00); + + Delay(2); + + LCD_WriteReg(0x35,0x38); + LCD_WriteReg(0x36,0x78); + + LCD_WriteReg(0x3e,0x38); + + LCD_WriteReg(0x40,0x0f); + LCD_WriteReg(0x41,0xf0); + + // Power Supply Setting + LCD_WriteReg(0x19,0x49);//******** + LCD_WriteReg(0x93,0x0f);//******* + + Delay(1); + + LCD_WriteReg(0x20,0x30); + LCD_WriteReg(0x1d,0x07); + LCD_WriteReg(0x1e,0x00); + LCD_WriteReg(0x1f,0x07); + + // VCOM Setting for CMO 3.2¡± Panel + LCD_WriteReg(0x44,0x4d);//4d***************4f + LCD_WriteReg(0x45,0x13);//0x0a); + Delay(1); + LCD_WriteReg(0x1c,0x04); + Delay(2); + LCD_WriteReg(0x43,0x80); + Delay(5); + LCD_WriteReg(0x1b,0x08); + Delay(4); + LCD_WriteReg(0x1b,0x10); + Delay(4); + + // Display ON Setting + LCD_WriteReg(0x90,0x7f); + LCD_WriteReg(0x26,0x04); + Delay(4); + LCD_WriteReg(0x26,0x24); + LCD_WriteReg(0x26,0x2c); + Delay(4); + LCD_WriteReg(0x26,0x3c); + + // Set internal VDDD voltage + LCD_WriteReg(0x57,0x02); + LCD_WriteReg(0x55,0x00); + LCD_WriteReg(0x57,0x00); + + /* add lcd driver into graphic driver */ + rtgui_list_init(&_rtgui_lcd_driver.list); + rtgui_graphic_driver_add(&_rtgui_lcd_driver); +} + +#endif + +void stm3210e_rtgui_init() +{ + rtgui_rect_t rect; + + rtgui_system_server_init(); + + /* register dock panel */ + rect.x1 = 0; + rect.y1 = 0; + rect.x2 = 320; + rect.y2 = 25; + rtgui_panel_register("info", &rect); + + /* register main panel */ + rect.x1 = 0; + rect.y1 = 25; + rect.x2 = 320; + rect.y2 = 240; + rtgui_panel_register("main", &rect); + rtgui_panel_set_default_focused("main"); + + rt_hw_lcd_init(); + + info_init(); + today_init(); +} diff --git a/bsp/stm3210/stm3210e_eval_lcd.h b/bsp/stm3210/stm3210e_eval_lcd.h new file mode 100644 index 0000000000..72cc1211a7 --- /dev/null +++ b/bsp/stm3210/stm3210e_eval_lcd.h @@ -0,0 +1,148 @@ +#ifndef __LCD_H__ +#define __LCD_H__ + +#include +#include + +/* 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 + +/* LCD Control pins */ +#define CtrlPin_NCS GPIO_Pin_2 /* PB.02 */ +#define CtrlPin_RS GPIO_Pin_7 /* PD.07 */ +#define CtrlPin_NWR GPIO_Pin_15 /* PD.15 */ + +/* LCD color */ +#define White 0xFFFF +#define Black 0x0000 +#define Grey 0xF7DE +#define Blue 0x001F +#define Blue2 0x051F +#define Red 0xF800 +#define Magenta 0xF81F +#define Green 0x07E0 +#define Cyan 0x7FFF +#define Yellow 0xFFE0 + +#define Line0 0 +#define Line1 24 +#define Line2 48 +#define Line3 72 +#define Line4 96 +#define Line5 120 +#define Line6 144 +#define Line7 168 +#define Line8 192 +#define Line9 216 + +#define Horizontal 0x00 +#define Vertical 0x01 + +#endif