1. Related software package installation
1. Open the cubemx package manager
2. Install the F4 software package
3. Install the touchgfx software package
2. Engineering configuration
1. New construction
2. sys configuration
3. rcc configuration
4. crc configuration
5. Add touchgfx software package
6. Configure the touchgfx software package
Change width and height to your own screen size
7. Generate project
3. Code modification
1. Load the screen related driver to the project
2. Modify the header file to support c++
Add in the header file
#ifdef __cplusplus
extern "C" {
#endif
,,,,,,
#ifdef __cplusplus
}
#endif
3. Modify touchgfx source code
a. Modify the function in the TouchGFXHAL.cpp file void TouchGFXHAL::flushFrameBuffer(const touchgfx::Rect& rect)
to refresh the data to the screen
void TouchGFXHAL::flushFrameBuffer(const touchgfx::Rect& rect)
{
volatile uint16_t* buffer = getClientFrameBuffer()+(rect.y*DISPLAY_WIDTH)+rect.x;
uint16_t height,i;
LCD_Address_Set(rect.x,rect.y,rect.x+rect.width-1,rect.y+rect.height-1);
LCD_WR = 1;
for(height=0;height<rect.height;height++)
{
for(i=0;i<rect.width;i++)
{
//LCD_Write_HalfWord(buffer[i]);
SPI1->DR = buffer[i]>>8;
while((SPI1->SR&1<<1)==0);
SPI1->DR = (u8)buffer[i];
while((SPI1->SR&1<<1)==0);
}
buffer += DISPLAY_WIDTH;
}
}
a. Modify the newly added function in the TouchGFXHAL.cpp file touchgfxTickHandler
to provide the clock for touchgfx. Called in 1ms timer. The provided clock is 20ms and the screen refresh is 50hz.
extern "C" void touchgfxTickHandler()
{
static uint8_t ms = 0;
static uint8_t isHigh = 0;
if(isInited)
{
ms++;
if(ms==10)
{
ms = 0;
isHigh = !isHigh;
if(isHigh)
{
HAL::getInstance()->vSync();
OSWrappers::signalVSync();
HAL::getInstance()->swapFrameBuffers();
}else
{
HAL::getInstance()->frontPorchEntered();
}
}
}
}
touchgfxTickHandler
c. Call the function in the 1ms timer
4. Complete project download
Complete project click me to download