*
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* display_fsmc_interface.h
|
||||
*
|
||||
* Created on: 23 îêò. 2016 ã.
|
||||
* Author: l-pro
|
||||
*/
|
||||
|
||||
#ifndef DISPLAY_FSMC_INTERFACE_H_
|
||||
#define DISPLAY_FSMC_INTERFACE_H_
|
||||
|
||||
#include "stm32f7xx_hal.h"
|
||||
|
||||
namespace Stm32PlusPlus { namespace Display {
|
||||
|
||||
#define LCD_REG (*((volatile unsigned short *) 0x60000000))
|
||||
#define LCD_RAM (*((volatile unsigned short *) (0x60000000 | 0x00020000)))
|
||||
|
||||
class DisplayFsmcInterface {
|
||||
public:
|
||||
static constexpr uint16_t* addressLocation = (uint16_t*) 0x60000000;
|
||||
static constexpr uint16_t* dataLocation = (uint16_t*) (0x60000000 | 0x00020000);
|
||||
|
||||
static void 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_1MB;
|
||||
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_ENABLE;
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
// Enable the MPU
|
||||
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
||||
}
|
||||
|
||||
static void reset(){
|
||||
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);
|
||||
}
|
||||
|
||||
static void setAddress(uint16_t address){
|
||||
*addressLocation = address;
|
||||
}
|
||||
|
||||
static void write(uint16_t value){
|
||||
*dataLocation = value;
|
||||
}
|
||||
|
||||
static uint16_t read(){
|
||||
return *dataLocation;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
||||
#endif /* DISPLAY_FSMC_INTERFACE_H_ */
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* ili9325.h
|
||||
*
|
||||
* Created on: 23 îêò. 2016 ã.
|
||||
* Author: l-pro
|
||||
*/
|
||||
|
||||
#ifndef ILI9325_H_
|
||||
#define ILI9325_H_
|
||||
|
||||
#include "ili9325_registers.h"
|
||||
|
||||
namespace Stm32PlusPlus { namespace Display {
|
||||
|
||||
template<typename HardwareInterface>
|
||||
class Ili9325 {
|
||||
public:
|
||||
typedef HardwareInterface HW;
|
||||
|
||||
enum class FrameRate : uint8_t{
|
||||
fr40 = 0,
|
||||
fr43,
|
||||
fr45,
|
||||
fr48,
|
||||
fr51,
|
||||
fr55,
|
||||
fr59,
|
||||
fr64,
|
||||
fr70,
|
||||
fr77,
|
||||
fr85,
|
||||
fr96, //(default)
|
||||
fr110,
|
||||
fr128
|
||||
};
|
||||
|
||||
struct GammaCurve {
|
||||
uint16_t v[10];
|
||||
};
|
||||
|
||||
static void write(uint16_t address, uint16_t data){
|
||||
HW::setAddress(address);
|
||||
HW::write(data);
|
||||
}
|
||||
|
||||
static uint16_t read(uint16_t address, uint16_t data){
|
||||
HW::setAddress(address);
|
||||
return HW::read();
|
||||
}
|
||||
|
||||
static void init(){
|
||||
HW::reset();
|
||||
|
||||
write(Reg::DriverOutputControl::Address, Reg::DriverOutputControl::SS);
|
||||
write(Reg::LcdDrivingControl::Address, Reg::LcdDrivingControl::BC0 | Reg::LcdDrivingControl::EOR); /* set 1 line inversion */
|
||||
setOrientation(0);
|
||||
|
||||
write(Reg::ResizeControl::Address, 0); //Disable resizing
|
||||
setBackAndFrontPorch(2, 2);
|
||||
write(Reg::DisplayControl3::Address, 0); //Set non-display area refresh cycle ISC[3:0]
|
||||
write(Reg::DisplayControl4::Address, 0); //FMARK function
|
||||
write(Reg::RgbDisplayInterfaceControl1::Address, 0); // RGB interface setting
|
||||
write(Reg::FrameMarkerPosition::Address, 0); //Frame marker Position
|
||||
write(Reg::RgbDisplayInterfaceControl2::Address, 0); // RGB interface polarity
|
||||
|
||||
//Power On
|
||||
write(Reg::PowerControl1::Address, 0); // SAP, BT[3:0], AP, DSTB, SLP, STB
|
||||
write(Reg::PowerControl2::Address, REG_SET(Reg::PowerControl2, VC, 7));
|
||||
write(Reg::PowerControl3::Address, 0); // VREG1OUT voltage
|
||||
write(Reg::PowerControl4::Address, 0); // VDV[4:0] for VCOM amplitude
|
||||
write(Reg::DisplayControl1::Address, Reg::DisplayControl1::D0);
|
||||
HAL_Delay(200);
|
||||
|
||||
// Dis-charge capacitor power voltage
|
||||
write(Reg::PowerControl1::Address, Reg::PowerControl1::AP0 | Reg::PowerControl1::APE | Reg::PowerControl1::SAP);
|
||||
|
||||
write(Reg::PowerControl2::Address,
|
||||
REG_SET(Reg::PowerControl2, VC, 7) |
|
||||
REG_SET(Reg::PowerControl2, DC0, 2) |
|
||||
REG_SET(Reg::PowerControl2, DC1, 2));
|
||||
HAL_Delay(50);
|
||||
|
||||
write(Reg::PowerControl3::Address, REG_SET(Reg::PowerControl3, VRH, 0xf) | Reg::PowerControl3::PON);
|
||||
HAL_Delay(50);
|
||||
|
||||
write(Reg::PowerControl4::Address, REG_SET(Reg::PowerControl4, VDV, 0x15)); // VDV for VCOM amplitude
|
||||
|
||||
write(Reg::PowerControl7::Address, REG_SET(Reg::PowerControl7, VCM, 0x27)); // VCM for VCOMH
|
||||
setFrameRate(FrameRate::fr128);
|
||||
HAL_Delay(50);
|
||||
|
||||
//write(0x20, 0x0000); // GRAM horizontal Address
|
||||
//write(0x21, 0x0000); // GRAM Vertical Address
|
||||
|
||||
//Set Gamma Curve
|
||||
GammaCurve curve = {
|
||||
0x0000,0x0707,0x0307,0x0200,0x0008,
|
||||
0x0004,0x0000,0x0707,0x0002,0x1D04
|
||||
};
|
||||
setGammaCurve(curve);
|
||||
|
||||
//Set GRAM area
|
||||
write(Reg::HorizontalAddressStartPosition::Address, 0); // Horizontal GRAM Start Address
|
||||
write(Reg::HorizontalAddressEndPosition::Address, 239); // Horizontal GRAM End Address
|
||||
write(Reg::VerticalAddressStartPosition::Address, 0); // Vertical GRAM Start Address
|
||||
write(Reg::VerticalAddressEndPosition::Address, 319); // Vertical GRAM Start Address
|
||||
write(Reg::DriverOutputControl2::Address, REG_SET(Reg::DriverOutputControl2, NL, 0x27) | Reg::DriverOutputControl2::GS); // Gate Scan Line
|
||||
write(Reg::BaseImageDisplayControl::Address, Reg::BaseImageDisplayControl::REV);
|
||||
write(Reg::VerticalScrollControl::Address, 0); // set scrolling line
|
||||
|
||||
//Partial Display Control
|
||||
write(Reg::PartialImage1DisplayPosition::Address, 0);
|
||||
write(Reg::PartialImage1StartLine::Address, 0);
|
||||
write(Reg::PartialImage1EndLine::Address, 0);
|
||||
write(Reg::PartialImage2DisplayPosition::Address, 0);
|
||||
write(Reg::PartialImage2StartLine::Address, 0);
|
||||
write(Reg::PartialImage2EndLine::Address, 0);
|
||||
|
||||
//Panel Control
|
||||
write(Reg::PanelInterfaceControl1::Address, REG_SET(Reg::PanelInterfaceControl1, RTNI, 0x10));
|
||||
write(Reg::PanelInterfaceControl2::Address, REG_SET(Reg::PanelInterfaceControl2, NOWI, 0x06));
|
||||
write(Reg::DisplayControl1::Address,
|
||||
Reg::DisplayControl1::D0 | Reg::DisplayControl1::D1 |
|
||||
Reg::DisplayControl1::DTE | Reg::DisplayControl1::GON | Reg::DisplayControl1::BASEE); //display ON
|
||||
|
||||
HAL_Delay(50);
|
||||
}
|
||||
|
||||
static void setGammaCurve(GammaCurve curve){
|
||||
write(Reg::GammaControl1::Address, curve.v[0]);
|
||||
write(Reg::GammaControl2::Address, curve.v[1]);
|
||||
write(Reg::GammaControl3::Address, curve.v[2]);
|
||||
write(Reg::GammaControl4::Address, curve.v[3]);
|
||||
write(Reg::GammaControl5::Address, curve.v[4]);
|
||||
write(Reg::GammaControl6::Address, curve.v[5]);
|
||||
write(Reg::GammaControl7::Address, curve.v[6]);
|
||||
write(Reg::GammaControl8::Address, curve.v[7]);
|
||||
write(Reg::GammaControl9::Address, curve.v[8]);
|
||||
write(Reg::GammaControl10::Address, curve.v[9]);
|
||||
}
|
||||
|
||||
static void setFrameRate(FrameRate frameRate){
|
||||
write(Reg::FrameRateAndColorControl::Address, REG_SET(Reg::FrameRateAndColorControl, FRS, (uint8_t)frameRate));
|
||||
}
|
||||
|
||||
static bool setBackAndFrontPorch(uint8_t backPorch, uint8_t frontPorch){
|
||||
if((backPorch < 2) || (frontPorch < 2) || ((backPorch + frontPorch) > 16)){
|
||||
return false;
|
||||
}
|
||||
write(Reg::DisplayControl2::Address,
|
||||
REG_SET(Reg::DisplayControl2, BP, backPorch) |
|
||||
REG_SET(Reg::DisplayControl2, FP, frontPorch));
|
||||
return true;
|
||||
}
|
||||
|
||||
static void setOrientation(uint8_t orientation){
|
||||
//TODO: remove BGR from here
|
||||
if (orientation == 0){
|
||||
write(Reg::EntryMode::Address, Reg::EntryMode::ID0 | Reg::EntryMode::ID1 | Reg::EntryMode::BGR);
|
||||
}else if (orientation == 90){
|
||||
write(Reg::EntryMode::Address, Reg::EntryMode::ID0 | Reg::EntryMode::AM | Reg::EntryMode::BGR);
|
||||
}else if (orientation == 180){
|
||||
write(Reg::EntryMode::Address, Reg::EntryMode::BGR);
|
||||
}else if (orientation == 270){
|
||||
write(Reg::EntryMode::Address, Reg::EntryMode::ID1 | Reg::EntryMode::BGR | Reg::EntryMode::AM);
|
||||
}
|
||||
}
|
||||
|
||||
static void setCursor(uint16_t x, uint16_t y){
|
||||
write(Reg::HorizontalGRAMAddressSet::Address, x);
|
||||
write(Reg::VerticalGRAMAddressSet::Address, y);
|
||||
}
|
||||
|
||||
static void beginWriteGram(){
|
||||
HW::setAddress(Reg::WriteDataToGRAM::Address);
|
||||
}
|
||||
|
||||
static void write(uint16_t value){
|
||||
HW::write(value);
|
||||
}
|
||||
|
||||
static void clear(uint16_t color){
|
||||
setCursor(0, 0);
|
||||
beginWriteGram();
|
||||
|
||||
for(uint32_t index = 0; index < 320*240; index++ ){ //TODO: remove hardcode
|
||||
HW::write(color);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
#endif /* ILI9325_H_ */
|
||||
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* ili9325_registers.h
|
||||
*
|
||||
* Created on: 23 îêò. 2016 ã.
|
||||
* Author: l-pro
|
||||
*/
|
||||
|
||||
#ifndef ILI9325_REGISTERS_H_
|
||||
#define ILI9325_REGISTERS_H_
|
||||
|
||||
|
||||
namespace Stm32PlusPlus { namespace Display { namespace Reg {
|
||||
|
||||
#define COMBINE2(__a, __b) __a##__b
|
||||
#define COMBINE(__a, __b) COMBINE2(__a, __b)
|
||||
|
||||
#define REG_SET(__register, __fieldName, __value)\
|
||||
(((__value) & __register::__fieldName##_bitmask) << (__register::__fieldName##_offset))
|
||||
|
||||
namespace DriverCodeRead {
|
||||
static constexpr uint16_t Address = 0x00;
|
||||
static constexpr uint16_t VAL_bitmask = 0xffff;
|
||||
static constexpr uint16_t VAL_offset = 0;
|
||||
}
|
||||
|
||||
namespace DriverOutputControl {
|
||||
static constexpr uint16_t Address = 0x01;
|
||||
static constexpr uint16_t SS = 1 << 8; //Shift direction select
|
||||
static constexpr uint16_t SM = 1 << 10;
|
||||
}
|
||||
|
||||
namespace LcdDrivingControl {
|
||||
static constexpr uint16_t Address = 0x02;
|
||||
static constexpr uint16_t EOR = 1 << 8; //EOR = 1 and B/C=1 to set the line inversion
|
||||
static constexpr uint16_t BC0 = 1 << 9; //0: Frame/Field inversion, 1: Line inversion
|
||||
}
|
||||
|
||||
namespace EntryMode {
|
||||
static constexpr uint16_t Address = 0x03;
|
||||
//Control the GRAM update direction.
|
||||
//When AM = “0”, the address is updated in horizontal writing direction.
|
||||
//When AM = “1”, the address is updated in vertical writing direction.
|
||||
static constexpr uint16_t AM = 1 << 3;
|
||||
//Control the address counter (AC) to automatically increase or decrease
|
||||
//by 1 when update one pixel display data. Refer to the following figure for the details
|
||||
static constexpr uint16_t ID0 = 1 << 4;
|
||||
static constexpr uint16_t ID1 = 1 << 5;
|
||||
static constexpr uint16_t ORG = 1 << 7;
|
||||
static constexpr uint16_t HWM = 1 << 9;
|
||||
//RGB swap. 0 == RGB, 1 == BGR
|
||||
static constexpr uint16_t BGR = 1 << 12;
|
||||
static constexpr uint16_t DFM = 1 << 14;
|
||||
static constexpr uint16_t TRI = 1 << 15;
|
||||
}
|
||||
|
||||
namespace ResizeControl {
|
||||
static constexpr uint16_t Address = 0x04;
|
||||
static constexpr uint16_t RSZ0 = 1 << 0;
|
||||
static constexpr uint16_t RSZ1 = 1 << 1;
|
||||
static constexpr uint16_t RCH0 = 1 << 4;
|
||||
static constexpr uint16_t RCH1 = 1 << 5;
|
||||
static constexpr uint16_t RCV0 = 1 << 8;
|
||||
static constexpr uint16_t RCV1 = 1 << 9;
|
||||
}
|
||||
|
||||
namespace DisplayControl1 {
|
||||
static constexpr uint16_t Address = 0x07;
|
||||
//Enable internal display operations
|
||||
static constexpr uint16_t D0 = 1 << 0;
|
||||
//Turn on display
|
||||
static constexpr uint16_t D1 = 1 << 1;
|
||||
static constexpr uint16_t CL = 1 << 3;
|
||||
//DTE + GON => Set the output level of gate driver G1 ~ G320
|
||||
static constexpr uint16_t DTE = 1 << 4;
|
||||
static constexpr uint16_t GON = 1 << 5;
|
||||
//Base image display enable
|
||||
static constexpr uint16_t BASEE = 1 << 8;
|
||||
//Partial image 2 and Partial image 1 enable bits
|
||||
static constexpr uint16_t PTDE0 = 1 << 12;
|
||||
static constexpr uint16_t PTDE1 = 1 << 13;
|
||||
}
|
||||
|
||||
namespace DisplayControl2 {
|
||||
static constexpr uint16_t Address = 0x08;
|
||||
//BP + FP <= 16 lines
|
||||
|
||||
//Back porch (>= 2)
|
||||
static constexpr uint16_t BP_bitmask = 0xf;
|
||||
static constexpr uint16_t BP_offset = 0;
|
||||
|
||||
//Front porch (>= 2)
|
||||
static constexpr uint16_t FP_bitmask = 0xf;
|
||||
static constexpr uint16_t FP_offset = 8;
|
||||
}
|
||||
|
||||
namespace DisplayControl3 {
|
||||
static constexpr uint16_t Address = 0x09;
|
||||
|
||||
static constexpr uint16_t ISC_bitmask = 0xf;
|
||||
static constexpr uint16_t ISC_offset = 0;
|
||||
|
||||
static constexpr uint16_t PTG0 = 1 << 4;
|
||||
static constexpr uint16_t PTG1 = 1 << 5;
|
||||
static constexpr uint16_t PTS0 = 1 << 8;
|
||||
static constexpr uint16_t PTS1 = 1 << 9;
|
||||
static constexpr uint16_t PTS2 = 1 << 10;
|
||||
}
|
||||
|
||||
namespace DisplayControl4 {
|
||||
static constexpr uint16_t Address = 0x0A;
|
||||
static constexpr uint16_t FMI0 = 1 << 0;
|
||||
static constexpr uint16_t FMI1 = 1 << 1;
|
||||
static constexpr uint16_t FMI2 = 1 << 2;
|
||||
static constexpr uint16_t FMARKOE = 1 << 3;
|
||||
}
|
||||
|
||||
namespace RgbDisplayInterfaceControl1 {
|
||||
static constexpr uint16_t Address = 0x0C;
|
||||
//RGB Interface Mode 0 == 18 bit, 1 == 16 bit, 2 == 6 bit
|
||||
static constexpr uint16_t RIM0 = 1 << 0;
|
||||
static constexpr uint16_t RIM1 = 1 << 1;
|
||||
|
||||
static constexpr uint16_t DM0 = 1 << 4;
|
||||
static constexpr uint16_t DM1 = 1 << 5;
|
||||
static constexpr uint16_t RM = 1 << 8;
|
||||
static constexpr uint16_t ENC0 = 1 << 12;
|
||||
static constexpr uint16_t ENC1 = 1 << 13;
|
||||
static constexpr uint16_t ENC2 = 1 << 14;
|
||||
}
|
||||
|
||||
namespace FrameMarkerPosition {
|
||||
static constexpr uint16_t Address = 0x0D;
|
||||
static constexpr uint16_t FMP0 = 1 << 0;
|
||||
static constexpr uint16_t FMP1 = 1 << 1;
|
||||
static constexpr uint16_t FMP2 = 1 << 2;
|
||||
static constexpr uint16_t FMP3 = 1 << 3;
|
||||
static constexpr uint16_t FMP4 = 1 << 4;
|
||||
static constexpr uint16_t FMP5 = 1 << 5;
|
||||
static constexpr uint16_t FMP6 = 1 << 6;
|
||||
static constexpr uint16_t FMP7 = 1 << 7;
|
||||
static constexpr uint16_t FMP8 = 1 << 8;
|
||||
}
|
||||
|
||||
namespace RgbDisplayInterfaceControl2 {
|
||||
static constexpr uint16_t Address = 0x0F;
|
||||
static constexpr uint16_t EPL0 = 1 << 0;
|
||||
static constexpr uint16_t DPL = 1 << 1;
|
||||
static constexpr uint16_t HSPL = 1 << 3;
|
||||
static constexpr uint16_t VSPL = 1 << 4;
|
||||
}
|
||||
|
||||
namespace PowerControl1 {
|
||||
static constexpr uint16_t Address = 0x10;
|
||||
//Standby mode
|
||||
static constexpr uint16_t STB = 1 << 0;
|
||||
//Sleep mode (1 == sleep)
|
||||
static constexpr uint16_t SLP = 1 << 1;
|
||||
//Deep standby
|
||||
static constexpr uint16_t DSTB = 1 << 2;
|
||||
//Amplifier value
|
||||
static constexpr uint16_t AP0 = 1 << 4;
|
||||
static constexpr uint16_t AP1 = 1 << 5;
|
||||
static constexpr uint16_t AP2 = 1 << 6;
|
||||
//Power supply enable bit.
|
||||
static constexpr uint16_t APE = 1 << 7;
|
||||
static constexpr uint16_t BT0 = 1 << 8;
|
||||
static constexpr uint16_t BT1 = 1 << 9;
|
||||
static constexpr uint16_t BT2 = 1 << 10;
|
||||
//SAP=0, Source driver is disabled. SAP=1, Source driver is enabled.
|
||||
static constexpr uint16_t SAP = 1 << 12;
|
||||
}
|
||||
|
||||
namespace PowerControl2 {
|
||||
static constexpr uint16_t Address = 0x11;
|
||||
//VCi ratio factor
|
||||
static constexpr uint16_t VC_bitmask = 0x7;
|
||||
static constexpr uint16_t VC_offset = 0;
|
||||
//Frequency of the step-up circuit 1
|
||||
static constexpr uint16_t DC0_bitmask = 0x7;
|
||||
static constexpr uint16_t DC0_offset = 4;
|
||||
//Frequency of the step-up circuit 2
|
||||
static constexpr uint16_t DC1_bitmask = 0x7;
|
||||
static constexpr uint16_t DC1_offset = 8;
|
||||
}
|
||||
|
||||
namespace PowerControl3 {
|
||||
static constexpr uint16_t Address = 0x12;
|
||||
// amplifying rate
|
||||
static constexpr uint16_t VRH_bitmask = 0xf;
|
||||
static constexpr uint16_t VRH_offset = 0;
|
||||
//Control ON/OFF of circuit3 output
|
||||
static constexpr uint16_t PON = 1 << 4;
|
||||
//VCIRE=0 External reference voltage Vci (default) VCIRE = 1 Internal reference voltage 2.5V
|
||||
static constexpr uint16_t VCIRE = 1 << 7;
|
||||
}
|
||||
|
||||
namespace PowerControl4 {
|
||||
static constexpr uint16_t Address = 0x13;
|
||||
static constexpr uint16_t VDV_bitmask = 0x1f;
|
||||
static constexpr uint16_t VDV_offset = 8;
|
||||
}
|
||||
|
||||
namespace HorizontalGRAMAddressSet {
|
||||
static constexpr uint16_t Address = 0x20;
|
||||
static constexpr uint16_t AD0 = 1 << 0;
|
||||
static constexpr uint16_t AD1 = 1 << 1;
|
||||
static constexpr uint16_t AD2 = 1 << 2;
|
||||
static constexpr uint16_t AD3 = 1 << 3;
|
||||
static constexpr uint16_t AD4 = 1 << 4;
|
||||
static constexpr uint16_t AD5 = 1 << 5;
|
||||
static constexpr uint16_t AD6 = 1 << 6;
|
||||
static constexpr uint16_t AD7 = 1 << 7;
|
||||
}
|
||||
|
||||
namespace VerticalGRAMAddressSet {
|
||||
static constexpr uint16_t Address = 0x21;
|
||||
static constexpr uint16_t AD8 = 1 << 0;
|
||||
static constexpr uint16_t AD9 = 1 << 1;
|
||||
static constexpr uint16_t AD10 = 1 << 2;
|
||||
static constexpr uint16_t AD11 = 1 << 3;
|
||||
static constexpr uint16_t AD12 = 1 << 4;
|
||||
static constexpr uint16_t AD13 = 1 << 5;
|
||||
static constexpr uint16_t AD14 = 1 << 6;
|
||||
static constexpr uint16_t AD15 = 1 << 7;
|
||||
static constexpr uint16_t AD16 = 1 << 8;
|
||||
}
|
||||
|
||||
namespace WriteDataToGRAM {
|
||||
//Set the internal VcomH voltage.
|
||||
static constexpr uint16_t Address = 0x22;
|
||||
}
|
||||
|
||||
namespace PowerControl7 {
|
||||
static constexpr uint16_t Address = 0x29;
|
||||
|
||||
static constexpr uint16_t VCM_bitmask = 0x3f;
|
||||
static constexpr uint16_t VCM_offset = 0;
|
||||
}
|
||||
|
||||
namespace FrameRateAndColorControl {
|
||||
static constexpr uint16_t Address = 0x2B;
|
||||
//0000 40
|
||||
//0001 43
|
||||
//0010 45
|
||||
//0011 48
|
||||
//0100 51
|
||||
//0101 55
|
||||
//0110 59
|
||||
//0111 64
|
||||
//1000 70
|
||||
//1001 77
|
||||
//1010 85
|
||||
//1011 96 (default)
|
||||
//1100 110
|
||||
//1101 128
|
||||
static constexpr uint16_t FRS_bitmask = 0xf;
|
||||
static constexpr uint16_t FRS_offset = 0;
|
||||
}
|
||||
|
||||
namespace GammaControl1 {
|
||||
static constexpr uint16_t Address = 0x30;
|
||||
}
|
||||
namespace GammaControl2 {
|
||||
static constexpr uint16_t Address = 0x31;
|
||||
}
|
||||
namespace GammaControl3 {
|
||||
static constexpr uint16_t Address = 0x32;
|
||||
}
|
||||
namespace GammaControl4 {
|
||||
static constexpr uint16_t Address = 0x35;
|
||||
}
|
||||
namespace GammaControl5 {
|
||||
static constexpr uint16_t Address = 0x36;
|
||||
}
|
||||
namespace GammaControl6 {
|
||||
static constexpr uint16_t Address = 0x37;
|
||||
}
|
||||
namespace GammaControl7 {
|
||||
static constexpr uint16_t Address = 0x38;
|
||||
}
|
||||
namespace GammaControl8 {
|
||||
static constexpr uint16_t Address = 0x39;
|
||||
}
|
||||
namespace GammaControl9 {
|
||||
static constexpr uint16_t Address = 0x3C;
|
||||
}
|
||||
namespace GammaControl10 {
|
||||
static constexpr uint16_t Address = 0x3D;
|
||||
}
|
||||
|
||||
namespace HorizontalAddressStartPosition {
|
||||
static constexpr uint16_t Address = 0x50;
|
||||
}
|
||||
|
||||
namespace HorizontalAddressEndPosition {
|
||||
static constexpr uint16_t Address = 0x51;
|
||||
}
|
||||
|
||||
namespace VerticalAddressStartPosition {
|
||||
static constexpr uint16_t Address = 0x52;
|
||||
}
|
||||
|
||||
namespace VerticalAddressEndPosition {
|
||||
static constexpr uint16_t Address = 0x53;
|
||||
}
|
||||
|
||||
namespace DriverOutputControl2 {
|
||||
static constexpr uint16_t Address = 0x60;
|
||||
static constexpr uint16_t GS = 1 << 15;
|
||||
static constexpr uint16_t SCN_bitmask = 0x3f;
|
||||
static constexpr uint16_t SCN_offset = 0;
|
||||
static constexpr uint16_t NL_bitmask = 0x3f;
|
||||
static constexpr uint16_t NL_offset = 8;
|
||||
}
|
||||
|
||||
namespace BaseImageDisplayControl {
|
||||
static constexpr uint16_t Address = 0x61;
|
||||
static constexpr uint16_t REV = 1 << 0;
|
||||
static constexpr uint16_t VLE = 1 << 1;
|
||||
static constexpr uint16_t NDL = 1 << 2;
|
||||
}
|
||||
|
||||
namespace VerticalScrollControl {
|
||||
static constexpr uint16_t Address = 0x6A;
|
||||
static constexpr uint16_t VL_bitmask = 0x1ff;
|
||||
static constexpr uint16_t VL_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
namespace PartialImage1DisplayPosition {
|
||||
static constexpr uint16_t Address = 0x80;
|
||||
static constexpr uint16_t PTDP_bitmask = 0x1ff;
|
||||
static constexpr uint16_t PTDP_offset = 0;
|
||||
}
|
||||
|
||||
namespace PartialImage1StartLine {
|
||||
static constexpr uint16_t Address = 0x81;
|
||||
static constexpr uint16_t PTSA_bitmask = 0x1ff;
|
||||
static constexpr uint16_t PTSA_offset = 0;
|
||||
}
|
||||
|
||||
namespace PartialImage1EndLine {
|
||||
static constexpr uint16_t Address = 0x82;
|
||||
static constexpr uint16_t PTEA_bitmask = 0x1ff;
|
||||
static constexpr uint16_t PTEA_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
namespace PartialImage2DisplayPosition {
|
||||
static constexpr uint16_t Address = 0x83;
|
||||
static constexpr uint16_t PTDP_bitmask = 0x1ff;
|
||||
static constexpr uint16_t PTDP_offset = 0;
|
||||
}
|
||||
|
||||
namespace PartialImage2StartLine {
|
||||
static constexpr uint16_t Address = 0x84;
|
||||
static constexpr uint16_t PTSA_bitmask = 0x1ff;
|
||||
static constexpr uint16_t PTSA_offset = 0;
|
||||
}
|
||||
|
||||
namespace PartialImage2EndLine {
|
||||
static constexpr uint16_t Address = 0x85;
|
||||
static constexpr uint16_t PTEA_bitmask = 0x1ff;
|
||||
static constexpr uint16_t PTEA_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
namespace PanelInterfaceControl1 {
|
||||
static constexpr uint16_t Address = 0x90;
|
||||
static constexpr uint16_t RTNI_bitmask = 0x1f;
|
||||
static constexpr uint16_t RTNI_offset = 0;
|
||||
static constexpr uint16_t DIVI_bitmask = 0x3;
|
||||
static constexpr uint16_t DIVI_offset = 8;
|
||||
}
|
||||
|
||||
namespace PanelInterfaceControl2 {
|
||||
static constexpr uint16_t Address = 0x92;
|
||||
static constexpr uint16_t NOWI_bitmask = 0x7;
|
||||
static constexpr uint16_t NOWI_offset = 8;
|
||||
}
|
||||
|
||||
namespace PanelInterfaceControl4 {
|
||||
static constexpr uint16_t Address = 0x95;
|
||||
static constexpr uint16_t RTNE_bitmask = 0x3f;
|
||||
static constexpr uint16_t RTNE_offset = 0;
|
||||
static constexpr uint16_t DIVE_bitmask = 0x3;
|
||||
static constexpr uint16_t DIVE_offset = 8;
|
||||
}
|
||||
|
||||
namespace OTPVCMProgrammingControl {
|
||||
static constexpr uint16_t Address = 0xA1;
|
||||
static constexpr uint16_t VCM_OTP_bitmask = 0x3f;
|
||||
static constexpr uint16_t VCM_OTP_offset = 0;
|
||||
static constexpr uint16_t OTP_PGM_EN_bitmask = 0x1;
|
||||
static constexpr uint16_t OTP_PGM_EN_offset = 11;
|
||||
}
|
||||
|
||||
namespace OTPVCMStatusAndEnable {
|
||||
static constexpr uint16_t Address = 0xA2;
|
||||
static constexpr uint16_t VCM_EN = 1 << 0;
|
||||
static constexpr uint16_t VCM_D_bitmask = 0x3f;
|
||||
static constexpr uint16_t VCM_D_offset = 8;
|
||||
static constexpr uint16_t PGM_CNT_bitmask = 0x3;
|
||||
static constexpr uint16_t PGM_CNT_offset = 14;
|
||||
}
|
||||
|
||||
namespace OTPProgrammingIDKey {
|
||||
static constexpr uint16_t Address = 0xA5;
|
||||
static constexpr uint16_t KEY_bitmask = 0xffff;
|
||||
static constexpr uint16_t KEY_offset = 0;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
#endif /* ILI9325_REGISTERS_H_ */
|
||||
@@ -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 */
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* lcd.h
|
||||
*
|
||||
* Created on: 01 ìàÿ 2016 ã.
|
||||
* Author: Sergey
|
||||
*/
|
||||
|
||||
#ifndef LCD_H_
|
||||
#define LCD_H_
|
||||
|
||||
#include "stm32f7xx_hal.h"
|
||||
extern SRAM_HandleTypeDef hsram1;
|
||||
|
||||
#define LCD_REG (*((volatile unsigned short *) 0x60000000))
|
||||
#define LCD_RAM (*((volatile unsigned short *) (0x60000000 | 0x00020000)))
|
||||
|
||||
#define ILI9325 1
|
||||
|
||||
|
||||
#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 DISP_ORIENTATION 0
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
#if ( DISP_ORIENTATION == 90 ) || ( DISP_ORIENTATION == 270 )
|
||||
|
||||
#define MAX_X 320
|
||||
#define MAX_Y 240
|
||||
|
||||
#elif ( DISP_ORIENTATION == 0 ) || ( DISP_ORIENTATION == 180 )
|
||||
|
||||
#define MAX_X 240
|
||||
#define MAX_Y 320
|
||||
|
||||
#endif
|
||||
|
||||
#define LCD_WriteIndex(_index) LCD_REG = static_cast<uint16_t>(_index)
|
||||
#define LCD_WriteData(_data) LCD_RAM = static_cast<uint16_t>(_data)
|
||||
|
||||
|
||||
uint16_t LCD_ReadReg(uint16_t LCD_Reg);
|
||||
void LCD_WriteReg(uint16_t LCD_Reg,uint16_t LCD_RegValue);
|
||||
uint16_t LCD_ReadData();
|
||||
|
||||
|
||||
void LCD_SetCursor( unsigned short Xpos, unsigned short Ypos );
|
||||
void LCD_SetPoint(uint16_t Xpos,uint16_t Ypos,uint16_t point);
|
||||
void LCD_FillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
|
||||
void LCD_Init();
|
||||
void LCD_Clear(uint16_t Color);
|
||||
|
||||
#endif /* LCD_H_ */
|
||||
Reference in New Issue
Block a user