*
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* lcd.cpp
|
||||
*
|
||||
* Created on: 01 ìàÿ 2016 ã.
|
||||
* Author: Sergey
|
||||
*/
|
||||
|
||||
#include "lcd.h"
|
||||
|
||||
static uint8_t LCD_Code;
|
||||
uint16_t DeviceCode;
|
||||
|
||||
|
||||
|
||||
void LCD_SetPoint(uint16_t Xpos,uint16_t Ypos,uint16_t point){
|
||||
if( Xpos >= MAX_X || Ypos >= MAX_Y ){
|
||||
return;
|
||||
}
|
||||
LCD_SetCursor(Xpos,Ypos);
|
||||
LCD_WriteReg(0x0022,point);
|
||||
}
|
||||
|
||||
void LCD_SetCursor( unsigned short Xpos, unsigned short Ypos ){
|
||||
LCD_WriteReg(0x0020, Xpos); /* 0 0 0 239*/
|
||||
LCD_WriteReg(0x0021, Ypos); /* 0 319 319 0*/
|
||||
LCD_WriteIndex(0x0022);
|
||||
}
|
||||
|
||||
|
||||
uint16_t LCD_ReadData(){
|
||||
return LCD_RAM;
|
||||
}
|
||||
|
||||
void LCD_WriteReg(uint16_t LCD_Reg,uint16_t LCD_RegValue){
|
||||
LCD_WriteIndex(LCD_Reg);
|
||||
LCD_WriteData(LCD_RegValue);
|
||||
}
|
||||
|
||||
uint16_t LCD_ReadReg(uint16_t LCD_Reg){
|
||||
LCD_WriteIndex(LCD_Reg);
|
||||
return LCD_ReadData();
|
||||
}
|
||||
|
||||
void LCD_Clear(uint16_t Color){
|
||||
uint32_t index=0;
|
||||
|
||||
LCD_SetCursor(0,0);
|
||||
LCD_WriteIndex(0x0022);
|
||||
|
||||
for( index = 0; index < MAX_X * MAX_Y; index++ ){
|
||||
LCD_WriteData(Color);
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_FillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color){
|
||||
for(uint16_t cy = y; cy < (y + height); ++cy){
|
||||
LCD_SetCursor(x,cy);
|
||||
for(uint16_t cx = x; cx < (x + width); ++cx){
|
||||
LCD_WriteReg(0x0022, color);
|
||||
//LCD_SetPoint(cx, cy, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_Init(){
|
||||
MPU_Region_InitTypeDef MPU_InitStruct;
|
||||
|
||||
// Disable the MPU
|
||||
HAL_MPU_Disable();
|
||||
|
||||
// Configure the MPU attributes for 16Mb NOR Flash
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.BaseAddress = 0x60000000;
|
||||
MPU_InitStruct.Size = MPU_REGION_SIZE_16MB;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
||||
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
||||
MPU_InitStruct.SubRegionDisable = 0x00;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
// Enable the MPU
|
||||
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
||||
|
||||
HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(1);
|
||||
HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_SET);
|
||||
|
||||
HAL_Delay(10);
|
||||
DeviceCode = 0x0123;
|
||||
DeviceCode = LCD_ReadReg(0x0000); /* Read LCD ID */
|
||||
|
||||
if( DeviceCode == 0x9325 || DeviceCode == 0x9328 ){
|
||||
LCD_Code = ILI9325;
|
||||
//LCD_WriteReg(0xE5, 0x78F0); /* set SRAM internal timing */
|
||||
LCD_WriteReg(0x01, 0x0100); /* set Driver Output Control */
|
||||
LCD_WriteReg(0x02, 0x0700); /* set 1 line inversion */
|
||||
|
||||
#if (DISP_ORIENTATION == 0) /* set GRAM write direction and BGR=1 */
|
||||
LCD_WriteReg(0x03,(1<<12)|(1<<5)|(1<<4)|(0<<3));
|
||||
#elif (DISP_ORIENTATION == 90)
|
||||
LCD_WriteReg(0x03,(1<<12)|(0<<5)|(1<<4)|(1<<3));
|
||||
#elif (DISP_ORIENTATION == 180)
|
||||
LCD_WriteReg(0x03,(1<<12)|(0<<5)|(0<<4)|(0<<3));
|
||||
#elif (DISP_ORIENTATION == 270)
|
||||
LCD_WriteReg(0x03,(1<<12)|(1<<5)|(0<<4)|(1<<3));
|
||||
#endif
|
||||
LCD_WriteReg(0x04, 0x0000); /* Resize register */
|
||||
LCD_WriteReg(0x08, 0x0207); /* set the back porch and front porch */
|
||||
LCD_WriteReg(0x09, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
|
||||
LCD_WriteReg(0x0A, 0x0000); /* FMARK function */
|
||||
LCD_WriteReg(0x0C, 0x0000); /* RGB interface setting */
|
||||
LCD_WriteReg(0x0D, 0x0000); /* Frame marker Position */
|
||||
LCD_WriteReg(0x0F, 0x0000); /* RGB interface polarity */
|
||||
/*************Power On sequence ****************/
|
||||
LCD_WriteReg(0x10, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
|
||||
LCD_WriteReg(0x11, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
|
||||
LCD_WriteReg(0x12, 0x0000); /* VREG1OUT voltage */
|
||||
LCD_WriteReg(0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
|
||||
LCD_WriteReg(0x07, 0x0001);
|
||||
HAL_Delay(200);
|
||||
/* Dis-charge capacitor power voltage */
|
||||
LCD_WriteReg(0x10, 0x1090); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
|
||||
LCD_WriteReg(0x11, 0x0227); /* Set DC1[2:0], DC0[2:0], VC[2:0] */
|
||||
HAL_Delay(50); /* Delay 50ms */
|
||||
LCD_WriteReg(0x12, 0x001F);
|
||||
HAL_Delay(50); /* Delay 50ms */
|
||||
LCD_WriteReg(0x13, 0x1500); /* VDV[4:0] for VCOM amplitude */
|
||||
LCD_WriteReg(0x29, 0x0027); /* 04 VCM[5:0] for VCOMH */
|
||||
LCD_WriteReg(0x2B, 0x000D); /* Set Frame Rate */
|
||||
HAL_Delay(50); /* Delay 50ms */
|
||||
LCD_WriteReg(0x20, 0x0000); /* GRAM horizontal Address */
|
||||
LCD_WriteReg(0x21, 0x0000); /* GRAM Vertical Address */
|
||||
/* ----------- Adjust the Gamma Curve ---------- */
|
||||
LCD_WriteReg(0x30, 0x0000);
|
||||
LCD_WriteReg(0x31, 0x0707);
|
||||
LCD_WriteReg(0x32, 0x0307);
|
||||
LCD_WriteReg(0x35, 0x0200);
|
||||
LCD_WriteReg(0x36, 0x0008);
|
||||
LCD_WriteReg(0x37, 0x0004);
|
||||
LCD_WriteReg(0x38, 0x0000);
|
||||
LCD_WriteReg(0x39, 0x0707);
|
||||
LCD_WriteReg(0x3C, 0x0002);
|
||||
LCD_WriteReg(0x3D, 0x1D04);
|
||||
/* ------------------ Set GRAM area --------------- */
|
||||
LCD_WriteReg(0x50, 0x0000); /* Horizontal GRAM Start Address */
|
||||
LCD_WriteReg(0x51, 0x00EF); /* Horizontal GRAM End Address */
|
||||
LCD_WriteReg(0x52, 0x0000); /* Vertical GRAM Start Address */
|
||||
LCD_WriteReg(0x53, 0x013F); /* Vertical GRAM Start Address */
|
||||
LCD_WriteReg(0x60, 0xA700); /* Gate Scan Line */
|
||||
LCD_WriteReg(0x61, 0x0001); /* NDL,VLE, REV */
|
||||
LCD_WriteReg(0x6A, 0x0000); /* set scrolling line */
|
||||
/* -------------- Partial Display Control --------- */
|
||||
LCD_WriteReg(0x80, 0x0000);
|
||||
LCD_WriteReg(0x81, 0x0000);
|
||||
LCD_WriteReg(0x82, 0x0000);
|
||||
LCD_WriteReg(0x83, 0x0000);
|
||||
LCD_WriteReg(0x84, 0x0000);
|
||||
LCD_WriteReg(0x85, 0x0000);
|
||||
/* -------------- Panel Control ------------------- */
|
||||
LCD_WriteReg(0x90, 0x0010);
|
||||
LCD_WriteReg(0x92, 0x0600);
|
||||
LCD_WriteReg(0x07, 0x0133); /* 262K color and display ON */
|
||||
}
|
||||
HAL_Delay(50); /* delay 50 ms */
|
||||
}
|
||||
Reference in New Issue
Block a user