Complete tutorial on transplanting touchgfx based on punctual atom F407 development version and SPI interface screen (1)

1. Related software package installation

1. Open the cubemx package manager

insert image description here

2. Install the F4 software package

insert image description here

3. Install the touchgfx software package

insert image description here

2. Engineering configuration

1. New construction

insert image description here

2. sys configuration

insert image description here

3. rcc configuration

insert image description here
insert image description here

4. crc configuration

insert image description here

5. Add touchgfx software package

insert image description here

insert image description here

6. Configure the touchgfx software package

insert image description here
Change width and height to your own screen size

7. Generate project

insert image description here

3. Code modification

1. Load the screen related driver to the project

insert image description here

2. Modify the header file to support c++

Add in the header file

#ifdef __cplusplus
extern "C" {
    
    
#endif
	
,,,,,,

#ifdef __cplusplus
}
#endif

insert image description here

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;
    }
	
}

insert image description here

a. Modify the newly added function in the TouchGFXHAL.cpp file touchgfxTickHandlerto 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();
			}	
		}
	}
}

insert image description here

touchgfxTickHandlerc. Call the function in the 1ms timer

insert image description here
4. Complete project download
Complete project click me to download

Guess you like

Origin blog.csdn.net/qq_15181569/article/details/129830406