K230 Touch API Reference#
Overview#
K230’s touch capability consists of two parts:
Touch device management: dynamically register/remove touch devices via
canmv_miscTouch read/write HAL: read touch points and device information via
drv_touchinstance
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 hardware configuration when creating a touch device:
touch_dev_index: device indexrange_x/range_y: coordinate range (0 can be left to system default)pin_intr/intr_value: interrupt pin and active level (use-1when no interrupt)pin_reset/reset_value: reset pin and active level (use-1when 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: touch point tracking IDx_coordinate/y_coordinate: touch point coordinateswidth: touch point widthtimestamp: timestamp
struct drv_touch_info#
Device capability information:
type: touch typevendor: vendor informationpoint_num: maximum number of touch pointsrange_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);
Register a touch device by cfg.
Return value:
0on success, non-0on failure.
canmv_misc_delete_touch_device#
int canmv_misc_delete_touch_device(int index);
Unregister a touch device by index.
Return value:
0on success, non-0on failure.
Read/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,-2invalid device ID,-3out of 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:
>0indicates the number of touch points,0no event,<0error (commonly-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 Call Flow#
If a device needs to be dynamically created, first call
canmv_misc_create_touch_device().Call
drv_touch_inst_create()to open the instance.First call
drv_touch_get_info()/drv_touch_get_config()to confirm capabilities and coordinate ranges.Loop call
drv_touch_read()to read touch events.Call
drv_touch_inst_destroy()on exit.If the device was dynamically created, finally call
canmv_misc_delete_touch_device().
Reference Example#
src/rtsmart/examples/peripheral/touch/test_touch.c
