/* ----------------------------------------------------------------------------
|
* SAM Software Package License
|
* ----------------------------------------------------------------------------
|
* Copyright (c) 2011, Atmel Corporation
|
*
|
* All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* - Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the disclaimer below.
|
*
|
* Atmel's name may not be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
*
|
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ----------------------------------------------------------------------------
|
*/
|
|
/**
|
* \file
|
*
|
* Implementation of ILI9325 driver.
|
*
|
*/
|
|
/*----------------------------------------------------------------------------
|
* Headers
|
*----------------------------------------------------------------------------*/
|
|
#include <string.h>
|
#include <stdio.h>
|
#include <stdint.h>
|
#include "lcd_r61509v.h"
|
#include "stm32f10x.h"
|
#include "stm32f10x_fsmc.h"
|
#include "stm32v5_systick.h"
|
#include "lcd_r61509v.h"
|
|
/*----------------------------------------------------------------------------
|
* Local variables
|
*----------------------------------------------------------------------------*/
|
|
/* Pixel cache used to speed up communication */
|
#define LCD_DATA_CACHE_SIZE BOARD_LCD_WIDTH
|
static LcdColor_t gLcdPixelCache[LCD_DATA_CACHE_SIZE];
|
|
|
/* ³õʼ»¯LCDËùʹÓõĹܽÅΪGPIOģʽ»òFSMCģʽ */
|
static void lcd_gpio_init(void)
|
{
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* ʹÄÜFSMCÍâÉèʱÖÓ */
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE); /* ʹÄÜLCD±³¹âºÍ¸´Î»¹Ü½ÅʱÖÓ */
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; /* LCD±³¹â¿ØÖ¹¹Ü½Å PD13 */
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; /* LCD¸´Î»¿ØÖƹܽŠPE1 */
|
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
|
/* ¸´ÓÃGPIODµÄGPIO¶Ë¿ÚΪFSMCģʽ,²Î¿¼datasheet <Table 5. High-density STM32F103xx pin definitions> */
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 /* PD14 - D0 */
|
| GPIO_Pin_15 /* PD15 - D1 */
|
| GPIO_Pin_0 /* PD0 - D2 */
|
| GPIO_Pin_1 /* PD1 - D3 */
|
| GPIO_Pin_8 /* PD8 - D13 */
|
| GPIO_Pin_9 /* PD9 - D14 */
|
| GPIO_Pin_10 /* PD10 - D15 */
|
| GPIO_Pin_4 /* PD4 - nOE Êä³öʹÄÜ */
|
| GPIO_Pin_5 /* PD5 - nEW дʹÄÜ */
|
| GPIO_Pin_7 /* PD7 - FSMC_NE1 LCDƬѡ */
|
| GPIO_Pin_11; /* PD11 - A16(LCD RS) LCDÖ¸Áî/Êý¾ÝÇл» */
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
|
/* ¸´ÓÃGPIOEµÄGPIO¶Ë¿ÚΪFSMCģʽ,²Î¿¼datasheet <Table 5. High-density STM32F103xx pin definitions> */
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 /* PE7 - D4 */
|
| GPIO_Pin_8 /* PE8 - D5 */
|
| GPIO_Pin_9 /* PE9 - D6 */
|
| GPIO_Pin_10 /* PE10 - D7 */
|
| GPIO_Pin_11 /* PE11 - D8 */
|
| GPIO_Pin_12 /* PE12 - D9 */
|
| GPIO_Pin_13 /* PE13 - D10 */
|
| GPIO_Pin_14 /* PE14 - D11 */
|
| GPIO_Pin_15; /* PE15 - D12 */
|
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
|
/* ´ò¿ªLCD±³¹â */
|
GPIO_SetBits(GPIOD, GPIO_Pin_13);
|
}
|
|
|
/* ³õʼ»¯FSMC¹¤×÷ģʽ¼°ÆäÅäÖà */
|
static void lcd_fsmc_init(void)
|
{
|
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
|
FSMC_NORSRAMTimingInitTypeDef p;
|
|
/* FSMC½Ó¿ÚÌØÐÔÅäÖòÎÊý,¶ÔÏÂÃæ¸÷³ÉÔ±¸³µÄÖµX±íʾX¸öʱÖÓÖÜÆÚ£¬ËüµÄʱÖÓÊÇÓÉHCLK¾¹ý
|
FSMC_CLKDivisionÉèÖÃµÄ·ÖÆµ²ÎÊý·ÖƵºóµÃµ½¡£*/
|
p.FSMC_AddressSetupTime = 0x02; /* µØÖ·½¨Á¢Ê±¼ä */
|
p.FSMC_AddressHoldTime = 0x00; /* µØÖ·±£³Öʱ¼ä */
|
p.FSMC_DataSetupTime = 0x05; /* Êý¾Ý½¨Á¢Ê±¼ä */
|
p.FSMC_DataLatency = 0x00; /* Êý¾Ý±£³Öʱ¼ä */
|
p.FSMC_BusTurnAroundDuration = 0x00;/* ×ÜÏ߻ָ´Ê±¼ä */
|
p.FSMC_CLKDivision = 0x00; /* ʱÖÓ·ÖÆµ */
|
/*FSMC_AccessMode: ÔÚµØÖ·Ïß²»¸´ÓõÄÇé¿öÏ£¬ABCDģʽµÄÇø±ð²»´ó¡£¸ÃÅäÖÃÖ»ÔÚÀ©Õ¹Ä£Ê½ÓÐЧ */
|
p.FSMC_AccessMode = FSMC_AccessMode_B;
|
|
/* LCDµÄCSÁ¬µÄPD7(NE1),ËùÒÔÎÒÃÇʹÓõÄÊÇNorflashµÄBank1 */
|
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
|
/* PD11Á¬µØÖ·ÏßA16, ʵ¼ÊÉÏֻʹÓÃÁËÒ»ÌõµØÖ·Ïߣ¬ÒòΪI/O×ÊÔ´²»½ôÕÅ£¬ËùÒÔÅäÖõØÖ·ÏߺÍÊý¾ÝÏß²»¸´Óà */
|
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
|
/* ´æ´¢Æ÷ÀàÐÍΪNorflashÀàÐÍ,ËüµÄʱÐòÓë8080×ÜÏ߸ü½Ó½ü,¸ÃÅäÖû¹¿ÉÒÔΪPSRAMºÎSRAMģʽ.*/
|
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
|
/* Êý¾Ýλ¿íΪ16λ */
|
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
|
/* ʹÓÃÒ첽дģʽ£¬½ûֹͻ·¢Ä£Ê½£»8080×ÜÏ߸üÊʺÏÒ첽ģʽ¡£ */
|
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
|
/* ±¾³ÉÔ±Ö»ÔÚÍ»·¢Ä£Ê½ÏÂÓÐЧ£¬µÈ´ýÐźż«ÐÔΪµÍ */
|
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
|
/* ±¾³ÉÔ±Ö»ÔÚÍ»·¢Ä£Ê½ÏÂÓÐЧ£¬½ûÖ¹·Ç¶ÔÆëÍ»·¢Ä£Ê½ */
|
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
|
/* ±¾³ÉÔ±Ö»ÔÚÍ»·¢Ä£Ê½ÏÂÓÐЧ£¬NWAITÐźÅÔÚʲôʱÆÚ²úÉú */
|
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
|
/* ±¾³ÉÔ±Ö»ÔÚÍ»·¢Ä£Ê½ÏÂÓÐЧ£¬½ûÓÃNWAITÐźŠ*/
|
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
|
/* ±¾³ÉÔ±Ö»ÔÚÍ»·¢Ä£Ê½ÏÂÓÐЧ£¬½ûֹͻ·¢Ð´²Ù×÷ */
|
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
|
|
/* дʹÄÜ£¬Èç¹û½ûÖ¹ÁËд²Ù×÷£¬FSMC²»»á²úÉúдʱÐò£¬µ«¿ÉÒÔ¶Á³öÊý¾Ý */
|
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
|
/* ½ûÖ¹À©Õ¹Ä£Ê½£¬À©Õ¹Ä£Ê½¿ÉÒÔʹÓöÀÁ¢µÄ¶Á¡¢Ð´Ä£Ê½ */
|
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
|
|
/* ÅäÖöÁдʱÐò£¡Èç¹ûʹÓÃÁËÀ©Õ¹Ä£Ê½£¬ÔòǰÕßÅäÖõÄÊǶÁʱÐò£¬ºóÕßÅäÖõÄÊÇдʱÐò¡£
|
* Èç¹û½ûÖ¹ÁËÀ©Õ¹Ä£Ê½£¬Ôò¶ÁдʱÐò¶¼Ê¹ÓÃFSMC_ReadWriteTimingStruct½á¹¹ÌåÖеIJÎÊý¡£
|
*/
|
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
|
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
|
|
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
|
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); /* ʹÄÜFSMC Bank1_SRAM Bank */
|
}
|
|
void lcd_reset(void)
|
{
|
GPIO_ResetBits(GPIOE, GPIO_Pin_1); /* PE1 ΪLCD ¸´Î»ÐźŠ*/
|
msleep(500);
|
GPIO_SetBits(GPIOE, GPIO_Pin_1);
|
msleep(500);
|
}
|
|
|
/*----------------------------------------------------------------------------
|
* Export functions
|
*----------------------------------------------------------------------------*/
|
|
/**
|
* \brief Write data to LCD Register.
|
*
|
* \param reg Register address.
|
* \param data Data to be written.
|
*/
|
void LCD_WriteReg( uint16_t reg, uint16_t data )
|
{
|
LCD_IR() = 0;
|
LCD_IR() = reg;
|
LCD_D() = data;
|
}
|
|
/**
|
* \brief Read data from LCD Register.
|
*
|
* \param reg Register address.
|
*
|
* \return Readed data.
|
*/
|
uint16_t LCD_ReadReg( uint16_t reg )
|
{
|
uint16_t value;
|
|
LCD_IR() = 0;
|
LCD_IR() = reg;
|
value = LCD_D();
|
|
return value;
|
}
|
|
/**
|
* \brief Write two byte to LCD GRAM.
|
*
|
* \param color 16-bits RGB color.
|
*/
|
extern void LCD_WriteRAMWord( uint16_t wColor )
|
{
|
LCD_D() = wColor ;
|
}
|
|
/**
|
* \brief Prepare to write GRAM data.
|
*/
|
extern void LCD_WriteRAM_Prepare( void )
|
{
|
LCD_IR() = 0 ;
|
LCD_IR() = R61509V_R202H ; /* Write Data to GRAM (R202h) */
|
}
|
|
/**
|
* \brief Write data to LCD GRAM.
|
*
|
* \param color 16-bits RGB color.
|
*/
|
extern void LCD_WriteRAM( LcdColor_t wColor )
|
{
|
LCD_WriteRAMWord(wColor);
|
}
|
|
/**
|
* \brief Write mutiple data in buffer to LCD controller.
|
*
|
* \param pBuf data buffer.
|
* \param size size in pixels.
|
*/
|
static void LCD_WriteRAMBuffer(const LcdColor_t *pBuf, uint32_t size)
|
{
|
uint32_t addr ;
|
|
for ( addr = 0 ; addr < size ; addr++ )
|
{
|
LCD_WriteRAM(pBuf[addr]);
|
}
|
}
|
|
/**
|
* \brief Prepare to read GRAM data.
|
*/
|
extern void LCD_ReadRAM_Prepare( void )
|
{
|
LCD_IR() = 0 ;
|
LCD_IR() = R61509V_R202H ; /* Read Data from GRAM (R202h) */
|
}
|
|
/**
|
* \brief Read data to LCD GRAM.
|
*
|
* \note Because pixel data LCD GRAM is 18-bits, so convertion to RGB 24-bits
|
* will cause low color bit lose.
|
*
|
* \return color 24-bits RGB color.
|
*/
|
extern uint32_t LCD_ReadRAM( void )
|
{
|
uint16_t color;
|
|
color = LCD_D(); /* dummy read */
|
color = LCD_D(); /* data */
|
|
return color;
|
}
|
|
/*----------------------------------------------------------------------------
|
* Basic R61509V primitives
|
*----------------------------------------------------------------------------*/
|
|
|
/**
|
* \brief Check Box coordinates. Return upper left and bottom right coordinates.
|
*
|
* \param pX1 X-coordinate of upper-left corner on LCD.
|
* \param pY1 Y-coordinate of upper-left corner on LCD.
|
* \param pX2 X-coordinate of lower-right corner on LCD.
|
* \param pY2 Y-coordinate of lower-right corner on LCD.
|
*/
|
static void CheckBoxCoordinates( uint32_t *pX1, uint32_t *pY1, uint32_t *pX2, uint32_t *pY2 )
|
{
|
uint32_t dw;
|
|
if ( *pX1 >= BOARD_LCD_WIDTH )
|
{
|
*pX1 = BOARD_LCD_WIDTH-1 ;
|
}
|
if ( *pX2 >= BOARD_LCD_WIDTH )
|
{
|
*pX2 = BOARD_LCD_WIDTH-1 ;
|
}
|
if ( *pY1 >= BOARD_LCD_HEIGHT )
|
{
|
*pY1 = BOARD_LCD_HEIGHT-1 ;
|
}
|
if ( *pY2 >= BOARD_LCD_HEIGHT )
|
{
|
*pY2 = BOARD_LCD_HEIGHT-1 ;
|
}
|
if (*pX1 > *pX2)
|
{
|
dw = *pX1;
|
*pX1 = *pX2;
|
*pX2 = dw;
|
}
|
if (*pY1 > *pY2)
|
{
|
dw = *pY1;
|
*pY1 = *pY2;
|
*pY2 = dw;
|
}
|
}
|
|
/**
|
* \brief Initialize the LCD controller.
|
*/
|
uint32_t LCD_Initialize( void )
|
{
|
uint16_t chipid ;
|
|
lcd_gpio_init(); /* ³õʼ»¯LCDʹÓõ½µÄ¹Ü½Å */
|
lcd_fsmc_init(); /* ³õʼ»¯FSMCÅäÖà */
|
lcd_reset();
|
|
/* Check R61509V chipid */
|
chipid = LCD_ReadReg( R61509V_R000H ) ; /* Driver Code Read (R000h) */
|
if ( chipid != R61509V_DEVICE_CODE )
|
{
|
//printf( "Read R61509V chip ID (0x%04x) error, skip initialization.\r\n", chipid ) ;
|
return 1 ;
|
}
|
|
/* Register settins reference to R61509 LCD drvier datasheet <CPT 3.0¡±(C030JB) Initial Code> */
|
|
/* Device Code Read */
|
LCD_WriteReg(R61509V_R000H, 0x0000);
|
LCD_WriteReg(R61509V_R000H, 0x0000);
|
LCD_WriteReg(R61509V_R000H, 0x0000);
|
LCD_WriteReg(R61509V_R000H, 0x0000);
|
|
msleep(10);
|
|
/* Base Image Number of Line */
|
LCD_WriteReg(R61509V_R400H, 0x6200);
|
/* Display Control 2 */
|
LCD_WriteReg(R61509V_R008H, 0x0808);
|
|
/* Gamma Control settings */
|
LCD_WriteReg(R61509V_R300H, 0x0C00);
|
LCD_WriteReg(R61509V_R301H, 0x5A0B);
|
LCD_WriteReg(R61509V_R302H, 0x0906);
|
LCD_WriteReg(R61509V_R303H, 0x1017);
|
LCD_WriteReg(R61509V_R304H, 0x2300);
|
LCD_WriteReg(R61509V_R305H, 0x1700);
|
LCD_WriteReg(R61509V_R306H, 0x6309);
|
LCD_WriteReg(R61509V_R307H, 0x0C09);
|
LCD_WriteReg(R61509V_R308H, 0x100C);
|
LCD_WriteReg(R61509V_R309H, 0x2232);
|
|
/* Panel Interface Control settings */
|
LCD_WriteReg(R61509V_R010H, 0x0016);//69.5Hz
|
LCD_WriteReg(R61509V_R011H, 0x0101);//
|
LCD_WriteReg(R61509V_R012H, 0x0000);//
|
LCD_WriteReg(R61509V_R013H, 0x0001);//
|
|
/* Power Control settings */
|
LCD_WriteReg(R61509V_R100H, 0x0330);//BT,AP
|
LCD_WriteReg(R61509V_R101H, 0x0237);//DC0,DC1,VC
|
LCD_WriteReg(R61509V_R103H, 0x0F00);//VDV
|
|
LCD_WriteReg(R61509V_R280H, 0x6100);//VCM
|
LCD_WriteReg(R61509V_R102H, 0xC1B0);//VRH[11000],VCMR[1],PSON,PON[11]
|
msleep(10);
|
|
LCD_WriteReg(R61509V_R001H, 0x00100);
|
LCD_WriteReg(R61509V_R002H, 0x00100);
|
LCD_WriteReg(R61509V_R003H, 0x01030);
|
LCD_WriteReg(R61509V_R009H, 0x00001);
|
LCD_WriteReg(R61509V_R00CH, 0x00000);
|
LCD_WriteReg(R61509V_R090H, 0x08000);
|
LCD_WriteReg(R61509V_R00FH, 0x00000);
|
LCD_WriteReg(R61509V_R210H, 0x00000);
|
LCD_WriteReg(R61509V_R211H, 0x000EF);
|
LCD_WriteReg(R61509V_R212H, 0x00000);
|
LCD_WriteReg(R61509V_R213H, 0x0018F);//432=1AF, 400=18F
|
LCD_WriteReg(R61509V_R500H, 0x00000);
|
LCD_WriteReg(R61509V_R501H, 0x00000);
|
LCD_WriteReg(R61509V_R502H, 0x0005F);
|
|
LCD_WriteReg(R61509V_R401H, 0x00001);
|
LCD_WriteReg(R61509V_R404H, 0x00000);
|
msleep(100);
|
|
LCD_WriteReg(R61509V_R007H, 0x00100);//BASEE
|
msleep(100);
|
|
LCD_WriteReg(R61509V_R200H, 0x00000); /* Horizontal GRAM Address Set */
|
LCD_WriteReg(R61509V_R201H, 0x00000); /* Vertical GRAM Address Set */
|
|
LCD_SetWindow( 0, 0, BOARD_LCD_WIDTH, BOARD_LCD_HEIGHT ) ;
|
LCD_SetCursor( 0, 0 ) ;
|
|
return 0;
|
}
|
|
|
/**
|
* \brief Turn on the LCD.
|
*/
|
extern void LCD_On( void )
|
{
|
uint16_t Reg;
|
|
/* Display Control 1 (R007h) When BASEE = 1 the base image is displayed. */
|
Reg = LCD_ReadReg( R61509V_R007H );
|
LCD_WriteReg( R61509V_R007H, Reg|R61509V_R007H_BASEE ) ;
|
|
Reg = LCD_ReadReg( R61509V_R102H );
|
LCD_WriteReg(R61509V_R102H, Reg|R61509V_R102H_PSON|R61509V_R102H_PON);//PSON[1],PON[1]
|
}
|
|
|
/**
|
* \brief Turn off the LCD.
|
*/
|
extern void LCD_Off( void )
|
{
|
uint16_t Reg;
|
Reg = LCD_ReadReg( R61509V_R007H );
|
|
/* Display Control 1 (R007h) When BASEE = 0 No base image is displayed. */
|
LCD_WriteReg( R61509V_R007H, (Reg & ~R61509V_R007H_BASEE) ) ;
|
}
|
|
/**
|
* \brief Power down the LCD.
|
*/
|
extern void LCD_PowerDown( void )
|
{
|
uint16_t Reg;
|
|
LCD_Off();
|
|
Reg = LCD_ReadReg( R61509V_R102H );
|
LCD_WriteReg(R61509V_R102H, Reg&(~(R61509V_R102H_PSON|R61509V_R102H_PON)) );//PSON[0],PON[0]
|
}
|
|
/**
|
* \brief Convert 24 bit RGB color into 5-6-5 rgb color space.
|
*
|
* Initialize the LcdColor_t cache with the color pattern.
|
* \param x 24-bits RGB color.
|
* \return 0 for successfull operation.
|
*/
|
extern uint32_t LCD_SetColor( uint32_t dwRgb24Bits )
|
{
|
uint32_t i ;
|
|
/* Fill the cache with selected color */
|
for ( i = 0 ; i < LCD_DATA_CACHE_SIZE ; ++i )
|
{
|
gLcdPixelCache[i] = dwRgb24Bits ;
|
}
|
|
return 0;
|
}
|
|
/**
|
* \brief Set cursor of LCD srceen.
|
*
|
* \param x X-coordinate of upper-left corner on LCD.
|
* \param y Y-coordinate of upper-left corner on LCD.
|
*/
|
extern void LCD_SetCursor( uint16_t x, uint16_t y )
|
{
|
/* GRAM Horizontal/Vertical Address Set (R20h, R21h) */
|
LCD_WriteReg( R61509V_R200H, x ) ; /* column */
|
LCD_WriteReg( R61509V_R201H, y ) ; /* row */
|
}
|
|
extern void LCD_SetWindow( uint32_t dwX, uint32_t dwY, uint32_t dwWidth, uint32_t dwHeight )
|
{
|
/* Horizontal and Vertical RAM Address Position (R50h, R51h, R52h, R53h) */
|
|
/* Set Horizontal Address Start Position */
|
LCD_WriteReg( R61509V_R210H, (uint16_t)dwX ) ;
|
|
/* Set Horizontal Address End Position */
|
LCD_WriteReg( R61509V_R211H, (uint16_t)dwX+dwWidth-1 ) ;
|
|
/* Set Vertical Address Start Position */
|
LCD_WriteReg( R61509V_R212H, (uint16_t)dwY ) ;
|
|
/* Set Vertical Address End Position */
|
LCD_WriteReg( R61509V_R213H, (uint16_t)dwY+dwHeight-1 ) ;
|
}
|
|
extern void LCD_SetDisplayLandscape( uint32_t dwRGB )
|
{
|
uint16_t dwValue ;
|
|
/* When AM = ?? the address is updated in vertical writing direction. */
|
/* DFM Set the mode of transferring data to the internal RAM when TRI = ?? */
|
/* When TRI = ?? data are transferred to the internal RAM in 8-bit x 3 transfers mode via the 8-bit interface. */
|
/* Use the high speed write mode (HWM=1) */
|
/* ORG = ?? The original address ?0000h?moves according to the I/D[1:0] setting. */
|
/* I/D[1:0] = 00 Horizontal : decrement Vertical : decrement, AM=0:Horizontal */
|
dwValue = R61509V_R003H_AM | R61509V_R003H_DFM | R61509V_R003H_TRI | R61509V_R003H_ORG ;
|
|
if ( dwRGB == 0 )
|
{
|
/* BGR=?? Swap the RGB data to BGR in writing into GRAM. */
|
dwValue |= R61509V_R003H_BGR ;
|
}
|
LCD_WriteReg( R61509V_R003H, dwValue ) ;
|
|
// LCD_WriteReg( ILI9325_R60H, (0x1d<<8)|0x00 ) ; /*Gate Scan Control */
|
|
LCD_SetWindow( 0, 0, BOARD_LCD_HEIGHT, BOARD_LCD_WIDTH ) ;
|
}
|
|
extern void LCD_SetDisplayPortrait( uint16_t wRGB )
|
{
|
uint16_t dwValue ;
|
|
/* Use the high speed write mode (HWM=1) */
|
/* When TRI = 1 data are transferred to the internal RAM in 8-bit x 3 transfers mode via the 8-bit interface. */
|
/* DFM=0: 18bpp (R:G:B = 6:6:6), DFM=1: 16bpp (R:G:B = 5:6:5) */
|
/* I/D[1:0] = 11 Horizontal : increment Vertical : increment, AM=0:Horizontal */
|
dwValue = R61509V_R003H_DFM | R61509V_R003H_ID1 | R61509V_R003H_ID0 ;
|
|
if ( wRGB == MODE_BGR )
|
{
|
/* BGR=?? Swap the RGB data to BGR in writing into GRAM. */
|
dwValue |= R61509V_R003H_BGR ;
|
}
|
LCD_WriteReg( R61509V_R003H, dwValue ) ;
|
|
/* Gate Scan Control (R400h, R401h, R404h) */
|
/* SCN[5:0]->bit[6:1] = 00 */
|
/* NL[5:0]->bit[14:9] = 0x27: Sets the number of lines to drive the LCD at an interval of 8 lines. */
|
//LCD_WriteReg( R61509V_R400H, R61509V_R400H_GS|(0x27<<9)|0x00 ) ;
|
}
|
|
|
extern void LCD_VerticalScroll( uint16_t wY )
|
{
|
/* Gate Scan Control (R400h, R401h, R404h) */
|
/* Enables the grayscale inversion of the image by setting REV=1. */
|
/* VLE[1]: Vertical scroll display enable bit */
|
LCD_WriteReg( R61509V_R401H, 3 ) ;
|
LCD_WriteReg( R61509V_R404H, wY ) ;
|
}
|
|
|
extern void LCD_SetPartialImage1( uint32_t dwDisplayPos, uint32_t dwStart, uint32_t dwEnd )
|
{
|
if( dwStart <= dwEnd )
|
return;
|
|
/* Partial Image 1 Display Position (R500h) */
|
LCD_WriteReg( R61509V_R500H, dwDisplayPos&0x1ff ) ;
|
/* Partial Image 1 RAM Start/End Address (R501h, R502h) */
|
LCD_WriteReg( R61509V_R501H, dwStart&0x1ff ) ;
|
LCD_WriteReg( R61509V_R502H, dwEnd&0x1ff ) ;
|
|
}
|
|
extern void LCD_EnablePartialImage1( uint32_t OnOff )
|
{
|
uint16_t Reg;
|
|
Reg = LCD_ReadReg( R61509V_R007H );
|
LCD_WriteReg( R61509V_R007H, (Reg & ~R61509V_R007H_BASEE) | R61509V_R007H_PTDE ) ;
|
}
|
|
|
/**
|
* \brief Draw a LcdColor_t on LCD of given color.
|
*
|
* \param x X-coordinate of pixel.
|
* \param y Y-coordinate of pixel.
|
*/
|
extern uint32_t LCD_DrawPixel( uint32_t x, uint32_t y )
|
{
|
if( (x >= BOARD_LCD_WIDTH) || (y >= BOARD_LCD_HEIGHT) )
|
{
|
return 1;
|
}
|
|
/* Set cursor */
|
LCD_SetCursor( x, y );
|
|
/* Prepare to write in GRAM */
|
LCD_WriteRAM_Prepare();
|
LCD_WriteRAM( *gLcdPixelCache );
|
|
return 0;
|
}
|
|
|
|
extern void LCD_TestPattern( uint32_t dwRGB )
|
{
|
uint32_t dwLine ;
|
uint32_t dw ;
|
|
LCD_SetWindow( 10, 10, 100, 20 ) ;
|
LCD_SetCursor( 10, 10 ) ;
|
LCD_WriteRAM_Prepare() ;
|
|
for ( dwLine=0 ; dwLine < 20 ; dwLine++ )
|
{
|
/* Draw White bar */
|
for ( dw=0 ; dw < 20 ; dw++ )
|
{
|
LCD_D() = 0xff ;
|
LCD_D() = 0xff ;
|
LCD_D() = 0xff ;
|
}
|
/* Draw Red bar */
|
for ( dw=0 ; dw < 20 ; dw++ )
|
{
|
if ( dwRGB == 0 )
|
{
|
LCD_D() = 0xff ;
|
LCD_D() = 0x00 ;
|
LCD_D() = 0x00 ;
|
}
|
else
|
{
|
LCD_D() = 0x00 ;
|
LCD_D() = 0x00 ;
|
LCD_D() = 0xff ;
|
}
|
}
|
/* Draw Green bar */
|
for ( dw=0 ; dw < 20 ; dw++ )
|
{
|
LCD_D() = 0x00 ;
|
LCD_D() = 0xff ;
|
LCD_D() = 0x00 ;
|
}
|
/* Draw Blue bar */
|
for ( dw=0 ; dw < 20 ; dw++ )
|
{
|
if ( dwRGB == 0 )
|
{
|
LCD_D() = 0x00 ;
|
LCD_D() = 0x00 ;
|
LCD_D() = 0xff ;
|
}
|
else
|
{
|
LCD_D() = 0xff ;
|
LCD_D() = 0x00 ;
|
LCD_D() = 0x00 ;
|
}
|
}
|
/* Draw Black bar */
|
for ( dw=0 ; dw < 20 ; dw++ )
|
{
|
LCD_D() = 0x00 ;
|
LCD_D() = 0x00 ;
|
LCD_D() = 0x00 ;
|
}
|
}
|
|
LCD_SetWindow( 0, 0, BOARD_LCD_WIDTH, BOARD_LCD_HEIGHT ) ;
|
}
|
|
|
/**
|
* \brief Write several pixels with the same color to LCD GRAM.
|
*
|
* LcdColor_t color is set by the LCD_SetColor() function.
|
* This function is optimized using an sram buffer to transfer block instead of
|
* individual pixels in order to limit the number of SPI interrupts.
|
* \param dwX1 X-coordinate of upper-left corner on LCD.
|
* \param dwY1 Y-coordinate of upper-left corner on LCD.
|
* \param dwX2 X-coordinate of lower-right corner on LCD.
|
* \param dwY2 Y-coordinate of lower-right corner on LCD.
|
*/
|
extern uint32_t LCD_DrawFilledRectangle( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2 )
|
{
|
uint32_t size, blocks;
|
|
/* Swap coordinates if necessary */
|
CheckBoxCoordinates(&dwX1, &dwY1, &dwX2, &dwY2);
|
|
/* Determine the refresh window area */
|
/* Horizontal and Vertical RAM Address Position (R210h, R211h, R212h, R213h) */
|
LCD_WriteReg(R61509V_R210H, (uint16_t)dwX1);
|
LCD_WriteReg(R61509V_R211H, (uint16_t)dwX2);
|
LCD_WriteReg(R61509V_R212H, (uint16_t)dwY1);
|
LCD_WriteReg(R61509V_R213H, (uint16_t)dwY2);
|
|
/* Set cursor */
|
LCD_SetCursor( dwX1, dwY1 );
|
|
/* Prepare to write in GRAM */
|
LCD_WriteRAM_Prepare();
|
|
size = (dwX2 - dwX1 + 1) * (dwY2 - dwY1 + 1);
|
/* Send pixels blocks => one SPI IT / block */
|
blocks = size / LCD_DATA_CACHE_SIZE;
|
while (blocks--)
|
{
|
LCD_WriteRAMBuffer(gLcdPixelCache, LCD_DATA_CACHE_SIZE);
|
}
|
/* Send remaining pixels */
|
LCD_WriteRAMBuffer(gLcdPixelCache, size % LCD_DATA_CACHE_SIZE);
|
|
/* Reset the refresh window area */
|
/* Horizontal and Vertical RAM Address Position (R210h, R211h, R212h, R213h) */
|
LCD_WriteReg(R61509V_R210H, (uint16_t)0 ) ;
|
LCD_WriteReg(R61509V_R211H, (uint16_t)BOARD_LCD_WIDTH - 1 ) ;
|
LCD_WriteReg(R61509V_R212H, (uint16_t)0) ;
|
LCD_WriteReg(R61509V_R213H, (uint16_t)BOARD_LCD_HEIGHT - 1 ) ;
|
|
return 0 ;
|
}
|
|
/**
|
* \brief Write several pixels pre-formatted in a bufer to LCD GRAM.
|
*
|
* \param dwX1 X-coordinate of upper-left corner on LCD.
|
* \param dwY1 Y-coordinate of upper-left corner on LCD.
|
* \param dwX2 X-coordinate of lower-right corner on LCD.
|
* \param dwY2 Y-coordinate of lower-right corner on LCD.
|
* \param pBuffer LcdColor_t buffer area.
|
*/
|
extern uint32_t LCD_DrawPicture( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2, const LcdColor_t *pBuffer )
|
{
|
uint32_t size;
|
|
/* Swap coordinates if necessary */
|
CheckBoxCoordinates(&dwX1, &dwY1, &dwX2, &dwY2);
|
|
/* Determine the refresh window area */
|
/* Horizontal and Vertical RAM Address Position (R210h, R211h, R212h, R213h) */
|
LCD_WriteReg(R61509V_R210H, (uint16_t)dwX1 ) ;
|
LCD_WriteReg(R61509V_R211H, (uint16_t)dwX2 ) ;
|
LCD_WriteReg(R61509V_R212H, (uint16_t)dwY1 ) ;
|
LCD_WriteReg(R61509V_R213H, (uint16_t)dwY2 ) ;
|
|
/* Set cursor */
|
LCD_SetCursor( dwX1, dwY1 );
|
|
/* Prepare to write in GRAM */
|
LCD_WriteRAM_Prepare();
|
|
size = (dwX2 - dwX1 + 1) * (dwY2 - dwY1 + 1);
|
|
LCD_WriteRAMBuffer(pBuffer, size);
|
|
/* Reset the refresh window area */
|
/* Horizontal and Vertical RAM Address Position (R210h, R211h, R212h, R213h) */
|
LCD_WriteReg(R61509V_R210H, (uint16_t)0 ) ;
|
LCD_WriteReg(R61509V_R211H, (uint16_t)BOARD_LCD_WIDTH - 1 ) ;
|
LCD_WriteReg(R61509V_R212H, (uint16_t)0 ) ;
|
LCD_WriteReg(R61509V_R213H, (uint16_t)BOARD_LCD_HEIGHT - 1 ) ;
|
|
return 0 ;
|
}
|
|
/*
|
* \brief Draw a line on LCD, which is not horizontal or vertical.
|
*
|
* \param x X-coordinate of line start.
|
* \param y Y-coordinate of line start.
|
* \param length line length.
|
* \param direction line direction: 0 - horizontal, 1 - vertical.
|
* \param color LcdColor_t color.
|
*/
|
static uint32_t DrawLineBresenham( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2 )
|
{
|
int dx, dy ;
|
int i ;
|
int xinc, yinc, cumul ;
|
int x, y ;
|
|
x = dwX1 ;
|
y = dwY1 ;
|
dx = dwX2 - dwX1 ;
|
dy = dwY2 - dwY1 ;
|
|
xinc = ( dx > 0 ) ? 1 : -1 ;
|
yinc = ( dy > 0 ) ? 1 : -1 ;
|
dx = ( dx > 0 ) ? dx : -dx ;
|
dy = ( dy > 0 ) ? dy : -dy ;
|
|
LCD_DrawPixel( x, y ) ;
|
|
if ( dx > dy )
|
{
|
cumul = dx / 2 ;
|
for ( i = 1 ; i <= dx ; i++ )
|
{
|
x += xinc ;
|
cumul += dy ;
|
|
if ( cumul >= dx )
|
{
|
cumul -= dx ;
|
y += yinc ;
|
}
|
LCD_DrawPixel( x, y ) ;
|
}
|
}
|
else
|
{
|
cumul = dy / 2 ;
|
for ( i = 1 ; i <= dy ; i++ )
|
{
|
y += yinc ;
|
cumul += dx ;
|
|
if ( cumul >= dy )
|
{
|
cumul -= dy ;
|
x += xinc ;
|
}
|
|
LCD_DrawPixel( x, y ) ;
|
}
|
}
|
|
return 0 ;
|
}
|
|
/*
|
* \brief Draw a line on LCD, horizontal and vertical line are supported.
|
*
|
* \param dwX1 X-coordinate of line start.
|
* \param dwY1 Y-coordinate of line start.
|
* \param dwX2 X-coordinate of line end.
|
* \param dwY2 Y-coordinate of line end.
|
*/
|
extern uint32_t LCD_DrawLine ( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2 )
|
{
|
/* Optimize horizontal or vertical line drawing */
|
if (( dwY1 == dwY2 ) || (dwX1 == dwX2))
|
{
|
LCD_DrawFilledRectangle( dwX1, dwY1, dwX2, dwY2 );
|
}
|
else
|
{
|
DrawLineBresenham( dwX1, dwY1, dwX2, dwY2 ) ;
|
}
|
|
return 0 ;
|
}
|
|
/**
|
* \brief Draws a circle on LCD, at the given coordinates.
|
*
|
* \param dwX X-coordinate of circle center.
|
* \param dwY Y-coordinate of circle center.
|
* \param dwR circle radius.
|
*/
|
extern uint32_t LCD_DrawCircle( uint32_t dwX, uint32_t dwY, uint32_t dwR )
|
{
|
int32_t d; /* Decision Variable */
|
uint32_t curX; /* Current X Value */
|
uint32_t curY; /* Current Y Value */
|
|
if (dwR == 0)
|
{
|
return 0;
|
}
|
d = 3 - (dwR << 1);
|
curX = 0;
|
curY = dwR;
|
|
while (curX <= curY)
|
{
|
LCD_DrawPixel(dwX + curX, dwY + curY);
|
LCD_DrawPixel(dwX + curX, dwY - curY);
|
LCD_DrawPixel(dwX - curX, dwY + curY);
|
LCD_DrawPixel(dwX - curX, dwY - curY);
|
LCD_DrawPixel(dwX + curY, dwY + curX);
|
LCD_DrawPixel(dwX + curY, dwY - curX);
|
LCD_DrawPixel(dwX - curY, dwY + curX);
|
LCD_DrawPixel(dwX - curY, dwY - curX);
|
|
if (d < 0)
|
{
|
d += (curX << 2) + 6;
|
}
|
else
|
{
|
d += ((curX - curY) << 2) + 10;
|
curY--;
|
}
|
curX++;
|
}
|
return 0;
|
}
|
|
extern uint32_t LCD_DrawFilledCircle( uint32_t dwX, uint32_t dwY, uint32_t dwRadius)
|
{
|
signed int d ; /* Decision Variable */
|
uint32_t dwCurX ; /* Current X Value */
|
uint32_t dwCurY ; /* Current Y Value */
|
uint32_t dwXmin, dwYmin;
|
|
if (dwRadius == 0)
|
{
|
return 0;
|
}
|
d = 3 - (dwRadius << 1) ;
|
dwCurX = 0 ;
|
dwCurY = dwRadius ;
|
|
while ( dwCurX <= dwCurY )
|
{
|
dwXmin = (dwCurX > dwX) ? 0 : dwX-dwCurX;
|
dwYmin = (dwCurY > dwY) ? 0 : dwY-dwCurY;
|
LCD_DrawFilledRectangle( dwXmin, dwYmin, dwX+dwCurX, dwYmin ) ;
|
LCD_DrawFilledRectangle( dwXmin, dwY+dwCurY, dwX+dwCurX, dwY+dwCurY ) ;
|
dwXmin = (dwCurY > dwX) ? 0 : dwX-dwCurY;
|
dwYmin = (dwCurX > dwY) ? 0 : dwY-dwCurX;
|
LCD_DrawFilledRectangle( dwXmin, dwYmin, dwX+dwCurY, dwYmin ) ;
|
LCD_DrawFilledRectangle( dwXmin, dwY+dwCurX, dwX+dwCurY, dwY+dwCurX ) ;
|
|
if ( d < 0 )
|
{
|
d += (dwCurX << 2) + 6 ;
|
}
|
else
|
{
|
d += ((dwCurX - dwCurY) << 2) + 10;
|
dwCurY-- ;
|
}
|
|
dwCurX++ ;
|
}
|
|
return 0 ;
|
}
|
|
extern uint32_t LCD_DrawRectangle( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2 )
|
{
|
CheckBoxCoordinates(&dwX1, &dwY1, &dwX2, &dwY2);
|
|
LCD_DrawFilledRectangle( dwX1, dwY1, dwX2, dwY1 ) ;
|
LCD_DrawFilledRectangle( dwX1, dwY2, dwX2, dwY2 ) ;
|
|
LCD_DrawFilledRectangle( dwX1, dwY1, dwX1, dwY2 ) ;
|
LCD_DrawFilledRectangle( dwX2, dwY1, dwX2, dwY2 ) ;
|
|
return 0 ;
|
}
|
|
|
|