K230 Touch API Reference#
Overview#
The K230’s touch capabilities consist of two parts:
Touch device management: dynamically register/delete touch devices through canmv_misc
Touch read and write HAL: read touch point and device information through drv_touch instance
Related header files:
src/rtsmart/libs/rtsmart_hal/components/canmv_misc/canmv_misc.hsrc/rtsmart/libs/rtsmart_hal/drivers/touch/drv_touch.h
Key data structures#
struct drv_touch_config_t#
Used to pass in hardware configuration when creating a touch device:
touch_dev_index: device indexrange_x/range_y: coordinate range (0 can be left to the system default)pin_intr/intr_value: Interrupt pin and active level (available when no interrupt is available-1)pin_reset/reset_value: Reset pin and effective level (-1is available when there is no reset)i2c_bus_index/i2c_bus_speed: I2C bus number and speed
struct drv_touch_data#
Single touch point data:
event: event type (NONE/UP/DOWN/MOVE)track_id: Contact tracing IDx_coordinate/y_coordinate: Contact coordinateswidth: contact widthtimestamp: timestamp
struct drv_touch_info#
Device capability information:
type: touch typevendor: Manufacturer informationpoint_num: Maximum number of contactsrange_x/range_y: coordinate range
Device Management API (canmv_misc)#
canmv_misc_create_touch_device#
int canmv_misc_create_touch_device(struct drv_touch_config_t* cfg);
Press cfg to register a touch device.
Return value:
0success, non-0failure.
canmv_misc_delete_touch_device#
int canmv_misc_delete_touch_device(int index);
Unregister touch device by index.
Return value:
0success, non-0failure.
Read and write HAL API (drv_touch)#
drv_touch_inst_create#
int drv_touch_inst_create(int id, drv_touch_inst_t** inst);
Create a touch instance.
Common errors:
-1parameter error,-2device ID is invalid,-3has insufficient memory.
drv_touch_inst_destroy#
void drv_touch_inst_destroy(drv_touch_inst_t** inst);
Destroy the instance and release resources.
drv_touch_read#
int drv_touch_read(drv_touch_inst_t* inst, struct drv_touch_data* touch_data, int max_points);
Read touch points.
Return value:
>0represents the number of contacts,0has no event,<0is an error (common-1/-2).
drv_touch_get_info#
int drv_touch_get_info(drv_touch_inst_t* inst, struct drv_touch_info* info);
Query device capability information.
drv_touch_get_config#
int drv_touch_get_config(drv_touch_inst_t* inst, struct drv_touch_config_t* cfg);
Query the current device configuration.
drv_touch_reset#
int drv_touch_reset(drv_touch_inst_t* inst);
Perform a touch device reset.
drv_touch_get_default_rotate#
int drv_touch_get_default_rotate(drv_touch_inst_t* inst, int* rotate);
Read the default rotation configuration (0/90/180/270/swap_xy).
Recommended calling process#
If you need to dynamically create a device, call
canmv_misc_create_touch_device()first.Call
drv_touch_inst_create()to open the instance.First call
drv_touch_get_info()/drv_touch_get_config()to confirm the capability and coordinate range.Call
drv_touch_read()cyclically to read contact events.Call
drv_touch_inst_destroy()on exit.If it is a dynamically created device,
canmv_misc_delete_touch_device()is called last.
Reference example#
src/rtsmart/examples/peripheral/touch/test_touch.c
