This post was last edited by dirty on 2024-8-31 23:20
This article mainly talks about the touch function of the development board display screen, and organizes, writes and tests this function.
1. Understand the principles
The development board uses a capacitive touch screen (CTP) and a touch driver IC GT911, which supports five-point touch. Let's learn about the hardware principle below.
Figure: Touch pin definition
I2C2_SCL--PA8
I2C2_SDA--PA9
RST -- PA10
INT--PA11
2. Code Preparation
1.scons --menuconfig configure pins and enable
Figure 2: Configuring the touch pins
2. Enable touch drive test command
Figure 3: Enable touch driver test command
3. Touch driver testing requires closing LVGL Demo. Disabling it with the scons --menuconfig configuration command will cause compilation problems. Here , the LVGL system initialization function is blocked when testing the touch function in the SDK code , which will not cause compilation problems and will not use LVGL.
Figure 4: Disable LVGL function
4. Test the touch function, find and open the device, register event callback, create semaphores and tasks, and import the test command function through MSH_CMD_EXPORT
Figure 5: Touch function code
Figure 6: Touch test printing and touch driver source code and configuration
3. Test
1. Compile and burn, enter the command list device in the serial port, you can find the gt911 device, the log is as follows
Figure 7: Command query gt911 device
2. Enter the command test_gt911 to start the touch test function. Touch the screen with your finger and you can see the following log
Figure 8: Touch test
You can see the touch information includes dot track ID, up to 5 (0-4), dot width, X coordinate, Y coordinate and received data timestamp.
At this point, you have an intuitive and comprehensive understanding of the touch function of the development board, which lays a good foundation for the future.