单片机:APM32F103RCT7
触摸IC:goodix-gt911
通信:软件模拟I2C
首先配置I2C的SLAVE地址,根据手册
我这里配置为0xBA/0xBB,参考代码:
board_gt911_int_output();
board_gt911_rst_output();
board_gt911_set_rst(0);
delay(20);
board_gt911_set_int(0);
delay(3);
board_gt911_set_rst(1);
delay(10);
board_gt911_int_input();
对应的驱动代码应该是这一段:
/*******************************************************
* Function:
* Reset chip. Control the reset pin and int-pin(if
* defined),
* Input:
* client: i2c device.
* ms: reset time in millisecond
* Output:
* None.
*******************************************************/
void gtp_reset_guitar(struct i2c_client *client, s32 ms)
{
struct goodix_ts_data *ts = i2c_get_clientdata(client);
dev_info(&client->dev, "Guitar reset");
set_bit(PANEL_RESETTING, &ts->flags);
if (!gpio_is_valid(ts->pdata->rst_gpio)) {
dev_warn(&client->dev, "reset failed no valid reset gpio");
return;
}
gpio_direction_output(ts->pdata->rst_gpio, 0);
usleep_range(ms * 1000, ms * 1000 + 100); /* T2: > 10ms */
gtp_int_output(ts, client->addr == 0x14);
usleep_range(2000, 3000); /* T3: > 100us (2ms)*/
gpio_direction_output(ts->pdata->rst_gpio, 1);
usleep_range(6000, 7000); /* T4: > 5ms */
gpio_direction_input(ts->pdata->rst_gpio);
gtp_int_sync(ts, 50);
if (ts->pdata->esd_protect)
gtp_init_ext_watchdog(client);
clear_bit(PANEL_RESETTING, &ts->flags);
}
设置完后延迟500毫米左右就可以去读取触摸数据了,先读取0X8140这个寄存器,测试I2C通信是否正常
参考代码:
static int gtp_i2c_read(uint8_t *buf, uint16_t len){
uint8_t addr_buf[2] = {buf[0], buf[1]};
vg_i2c_msg msgs[] = {
{0x5d, VG_I2C_WR, 2, addr_buf},
{0x5d, VG_I2C_RD, len-2, buf+2}
};
return board_i2c1->transfer(msgs, 2);
}
uint8_t chip[8] = {0x81, 0x40};
gtp_i2c_read(chip, 8);
printf("goodix %c%c%c%c, fw=%02x%02x\n", chip[2], chip[3], chip[4], chip[5], chip[7], chip[6]);
注意INT脚设置为浮空输入,电路上不用接上拉电阻。
读取触摸时读取0x814e这个寄存器
buffer status为1时,可以读数据,读完需要手动写0
number of touch points为触摸的点数,最大支持5点触摸