Touch Screen Example#
Introduction#
This example demonstrates the touch device point-reading process based on the RT-Smart touch HAL, and includes two modes:
Read point test using an existing touch device
Read point test after dynamically creating a device through configuration parameters
Example source code: src/rtsmart/examples/peripheral/touch/test_touch.c
Example Capabilities#
Read and print touch point events (
DOWN/MOVE/UP)Support multi-touch data reading (example buffer upper limit is 5 points)
Print device capability information (maximum touch points, coordinate range, etc.)
Print current touch configuration and default rotation information
Support Ctrl+C safe exit, and automatically release resources
Key Interfaces (Corresponding to Actual Code)#
drv_touch_inst_create(): Create a touch instancedrv_touch_read(): Read touch point datadrv_touch_get_info(): Query device informationdrv_touch_get_config(): Read device configurationdrv_touch_get_default_rotate(): Read default rotationdrv_touch_inst_destroy(): Destroy instancecanmv_misc_create_touch_device(): Dynamically register a touch devicecanmv_misc_delete_touch_device(): Delete dynamically registered device
Compilation and Running#
Compilation#
Enable the corresponding example in the SDK root directory and then compile, or compile independently:
cd src/rtsmart/examples/peripheral/touch
make
Run Mode 1: Test Existing Device#
./test_touch -d 0
Run Mode 2: Test After Dynamically Creating Device#
./test_touch -c --index 1 --range-x 480 --range-y 800 --int-pin 23 --int-value 1 --reset-pin 22 --reset-value 0 --i2c-bus 3 --i2c-speed 400000
Note: When the example exits, it will automatically attempt to unregister the touch device created through -c.
Common Parameters#
Parameter |
Description |
|---|---|
|
Use an existing touch device ID (default |
|
Dynamically create a touch device based on subsequent parameters |
|
New device index |
|
Coordinate range |
|
Interrupt pin and active level |
|
Reset pin and active level |
|
I2C bus number and speed |
Output Interpretation#
The example will print:
Device basic information: type, vendor, maximum touch points, coordinate range
Current configuration: I2C, pins, display range, etc.
Contact details:
event,track_id,x/y,width,timestamp
When there are no events, the example will periodically output ., indicating the loop is running normally but currently has no touch data.
Tip
Touch input typically depends on I2C + GPIO (interrupt/reset). It is recommended to confirm pin multiplexing and level configuration first, then perform the touch reading test. For complete interface and call sequence, please refer to the Touch API Documentation.
