Add a new TP driver¶
Adding a new TP driver mainly includes:
Add macro definitions for the driver IC in the Kconfig file¶
Open the SDK\customer\peripherals\Kconfig file which contains many configs like TSC_USING_XXX, and append a new config:
config TSC_USING_GT911
bool
default n
Copy similar driver code and add it to the compilation¶
Modify the copied TP driver file¶
Modify the registered semaphore name¶
static int rt_tp_device_init(void)
{
...
driver.isr_sem = rt_sem_create("gt911", 0, RT_IPC_FLAG_FIFO); //Change this semaphore name to gt911
rt_touch_drivers_register(&driver);
return 0;
}
Modify the communication interface in the probe function¶
Probe函数一般做几件事情:
Open the communication interface (e.g., I2C), configure the interface frequency, timeout, etc.
Read a certain register and return the status based on whether the TP is present (e.g., a certain status register of the TP).(If multi-TP driver compatibility is not required, you can directly return RT_EOK (TP is present))
Modify the Init function¶
驱动的初始化函数里面主要做:
Reset the TP
Configure the trigger condition of the TP interrupt GPIO, and register the interrupt callback handling function
It is recommended to use the following interfaces instead of rt_pin_xxx interfaces:
rt_touch_irq_pin_attach(PIN_IRQ_MODE_FALLING, irq_handler, NULL); Register the TP interrupt
rt_touch_irq_pin_enable(v) Enable and disable interrupts
Modify the interrupt callback function¶
中断回调一般不需要修改,处理一般都是:
Turn off the GPIO interrupt enable
Release the semaphore (trigger the upper layer to call read_point to read data)
Modify the read TP data callback function¶
读TP数据函数的实现一般是:
Read TP data through the communication interface (e.g., I2C)
Enable the TP interrupt after reading is completed (to trigger the next read)
将数据转存并返回,注意:返回值不能始终返回RT_EOK, 否则会陷入死循环。如果读取触控数据结束,请返回RT_EEMPTY。
static rt_err_t read_point(touch_msg_t p_msg)
{
gt911_piont_t i2c_result;
i2c_read_(0x8150, 6, &i2c_result); //Read TP data via I2C
rt_touch_irq_pin_enable(1); //Enable the TP interrupt
/*Return TP data to p_msg*/
p_msg->event = i2c_result.status ? TOUCH_EVENT_DOWN : TOUCH_EVENT_UP;
p_msg->x = i2c_result.x;
p_msg->y = i2c_result.y;
return RT_EEMPTY; //RT_EEMPTY - Indicates that the data has been read completely.
}