bdk: touch: check event count for wait event
And increase checks during autotune execution.
This commit is contained in:
@@ -52,13 +52,29 @@ static int _touch_read_reg(u8 *cmd, u32 csize, u8 *buf, u32 size)
|
|||||||
return !i2c_xfer_packet(I2C_3, FTS4_I2C_ADDR, cmd, csize, buf, size);
|
return !i2c_xfer_packet(I2C_3, FTS4_I2C_ADDR, cmd, csize, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int touch_get_event_count()
|
||||||
|
{
|
||||||
|
u8 cmd[3] = { FTS4_CMD_HW_REG_READ, 0, FTS4_HW_REG_EVENT_COUNT };
|
||||||
|
u8 buf[2];
|
||||||
|
|
||||||
|
if (_touch_read_reg(cmd, sizeof(cmd), buf, sizeof(buf)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return (buf[1] >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
static int _touch_wait_event(u8 event, u8 status, u32 timeout, u8 *buf)
|
static int _touch_wait_event(u8 event, u8 status, u32 timeout, u8 *buf)
|
||||||
{
|
{
|
||||||
u32 timer = get_tmr_ms() + timeout;
|
u32 timer = get_tmr_ms() + timeout;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
u8 tmp[FTS4_EVENT_SIZE] = {0};
|
if (!touch_get_event_count())
|
||||||
|
goto retry;
|
||||||
|
|
||||||
|
u8 tmp[FTS4_EVENT_SIZE];
|
||||||
int res = i2c_recv_buf_big(tmp, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_READ_ONE_EVENT);
|
int res = i2c_recv_buf_big(tmp, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_READ_ONE_EVENT);
|
||||||
|
|
||||||
|
// Check that event type and status match.
|
||||||
if (res && tmp[0] == event && tmp[1] == status)
|
if (res && tmp[0] == event && tmp[1] == status)
|
||||||
{
|
{
|
||||||
if (buf)
|
if (buf)
|
||||||
@@ -66,6 +82,7 @@ static int _touch_wait_event(u8 event, u8 status, u32 timeout, u8 *buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retry:
|
||||||
usleep(500);
|
usleep(500);
|
||||||
|
|
||||||
if (get_tmr_ms() > timer)
|
if (get_tmr_ms() > timer)
|
||||||
@@ -159,7 +176,7 @@ touch_info_t *touch_get_chip_info()
|
|||||||
u8 buf[7] = { 0 };
|
u8 buf[7] = { 0 };
|
||||||
|
|
||||||
// Get chip info.
|
// Get chip info.
|
||||||
u8 cmd[3] = { FTS4_CMD_HW_REG_READ, 0, 4 };
|
u8 cmd[3] = { FTS4_CMD_HW_REG_READ, 0, FTS4_HW_REG_CHIP_ID_INFO };
|
||||||
if (_touch_read_reg(cmd, sizeof(cmd), buf, sizeof(buf)))
|
if (_touch_read_reg(cmd, sizeof(cmd), buf, sizeof(buf)))
|
||||||
{
|
{
|
||||||
memset(&_touch_info, 0, sizeof(touch_info_t));
|
memset(&_touch_info, 0, sizeof(touch_info_t));
|
||||||
@@ -229,7 +246,7 @@ int touch_get_fw_info(touch_fw_info_t *fw)
|
|||||||
|
|
||||||
int touch_sys_reset()
|
int touch_sys_reset()
|
||||||
{
|
{
|
||||||
u8 cmd[3] = { 0, 0x28, 0x80 }; // System reset cmd.
|
u8 cmd[3] = { 0, FTS4_HW_REG_SYS_RESET, 0x80 }; // System reset cmd.
|
||||||
for (u8 retries = 0; retries < 3; retries++)
|
for (u8 retries = 0; retries < 3; retries++)
|
||||||
{
|
{
|
||||||
if (_touch_command(FTS4_CMD_HW_REG_WRITE, cmd, 3))
|
if (_touch_command(FTS4_CMD_HW_REG_WRITE, cmd, 3))
|
||||||
@@ -260,12 +277,11 @@ int touch_panel_ito_test(u8 *err)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Do ITO Production test.
|
// Do ITO Production test.
|
||||||
u8 cmd[2] = { 1, 0 };
|
if (_touch_command(FTS4_CMD_ITO_CHECK, NULL, 0))
|
||||||
if (_touch_command(FTS4_CMD_ITO_CHECK, cmd, 2))
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
u8 buf[6] = { 0 };
|
u8 buf[6] = { 0 };
|
||||||
int res = _touch_wait_event(FTS4_EV_ERROR, 5, 2000, buf);
|
int res = _touch_wait_event(FTS4_EV_ERROR, FTS4_EV_ERROR_ITO_TEST, 2000, buf);
|
||||||
if (!res && err)
|
if (!res && err)
|
||||||
{
|
{
|
||||||
err[0] = buf[0];
|
err[0] = buf[0];
|
||||||
@@ -341,6 +357,8 @@ int touch_sense_enable()
|
|||||||
|
|
||||||
int touch_execute_autotune()
|
int touch_execute_autotune()
|
||||||
{
|
{
|
||||||
|
u8 buf[6] = { 0 };
|
||||||
|
|
||||||
// Reset touchscreen module.
|
// Reset touchscreen module.
|
||||||
if (touch_sys_reset())
|
if (touch_sys_reset())
|
||||||
return 0;
|
return 0;
|
||||||
@@ -354,19 +372,19 @@ int touch_execute_autotune()
|
|||||||
// Apply Mutual Sense Compensation tuning.
|
// Apply Mutual Sense Compensation tuning.
|
||||||
if (_touch_command(FTS4_CMD_MS_CX_TUNING, NULL, 0))
|
if (_touch_command(FTS4_CMD_MS_CX_TUNING, NULL, 0))
|
||||||
return 0;
|
return 0;
|
||||||
if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_MS_CX_TUNING_DONE, 2000, NULL))
|
if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_MS_CX_TUNING_DONE, 2000, buf) || buf[0] || buf[1])
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Apply Self Sense Compensation tuning.
|
// Apply Self Sense Compensation tuning.
|
||||||
if (_touch_command(FTS4_CMD_SS_CX_TUNING, NULL, 0))
|
if (_touch_command(FTS4_CMD_SS_CX_TUNING, NULL, 0))
|
||||||
return 0;
|
return 0;
|
||||||
if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_SS_CX_TUNING_DONE, 2000, NULL))
|
if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_SS_CX_TUNING_DONE, 2000, buf) || buf[0] || buf[1])
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Save Compensation data to EEPROM.
|
// Save Compensation data to EEPROM.
|
||||||
if (_touch_command(FTS4_CMD_SAVE_CX_TUNING, NULL, 0))
|
if (_touch_command(FTS4_CMD_SAVE_CX_TUNING, NULL, 0))
|
||||||
return 0;
|
return 0;
|
||||||
if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_WRITE_CX_TUNE_DONE, 2000, NULL))
|
if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_WRITE_CX_TUNE_DONE, 2000, buf) || buf[0] || buf[1])
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return touch_sense_enable();
|
return touch_sense_enable();
|
||||||
|
|||||||
@@ -75,6 +75,7 @@
|
|||||||
|
|
||||||
/* HW Registers */
|
/* HW Registers */
|
||||||
#define FTS4_HW_REG_CHIP_ID_INFO 0x0004
|
#define FTS4_HW_REG_CHIP_ID_INFO 0x0004
|
||||||
|
#define FTS4_HW_REG_EVENT_COUNT 0x0023
|
||||||
#define FTS4_HW_REG_SYS_RESET 0x0028
|
#define FTS4_HW_REG_SYS_RESET 0x0028
|
||||||
|
|
||||||
/* FB Addresses */
|
/* FB Addresses */
|
||||||
@@ -91,32 +92,28 @@
|
|||||||
#define FTS4_EV_HOVER_MOTION 0x09
|
#define FTS4_EV_HOVER_MOTION 0x09
|
||||||
#define FTS4_EV_KEY_STATUS 0x0E
|
#define FTS4_EV_KEY_STATUS 0x0E
|
||||||
#define FTS4_EV_ERROR 0x0F
|
#define FTS4_EV_ERROR 0x0F
|
||||||
|
#define FTS4_EV_CONTROLLER_READY 0x10
|
||||||
|
#define FTS4_EV_STATUS 0x16
|
||||||
#define FTS4_EV_NOISE_READ 0x17
|
#define FTS4_EV_NOISE_READ 0x17
|
||||||
#define FTS4_EV_NOISE_WRITE 0x18
|
#define FTS4_EV_NOISE_WRITE 0x18
|
||||||
#define FTS4_EV_VENDOR 0x20
|
#define FTS4_EV_VENDOR 0x20
|
||||||
|
|
||||||
#define FTS4_EV_CONTROLLER_READY 0x10
|
|
||||||
#define FTS4_EV_STATUS 0x16
|
|
||||||
#define FTS4_EV_DEBUG 0xDB
|
#define FTS4_EV_DEBUG 0xDB
|
||||||
|
|
||||||
#define FTS4_EV_STATUS_MS_CX_TUNING_DONE 1
|
/* FTS4_EV_STATUS Events. */
|
||||||
#define FTS4_EV_STATUS_SS_CX_TUNING_DONE 2
|
#define FTS4_EV_STATUS_MS_CX_TUNING_DONE 0x01
|
||||||
#define FTS4_EV_STATUS_WRITE_CX_TUNE_DONE 4
|
#define FTS4_EV_STATUS_SS_CX_TUNING_DONE 0x02
|
||||||
|
#define FTS4_EV_STATUS_WRITE_CX_TUNE_DONE 0x04
|
||||||
|
|
||||||
|
#define FTS4_EV_ERROR_ITO_TEST 0x05
|
||||||
|
|
||||||
/* Multi touch related event masks. */
|
/* Multi touch related event masks. */
|
||||||
#define FTS4_MASK_EVENT_ID 0x0F
|
#define FTS4_MASK_EVENT_ID 0x0F
|
||||||
#define FTS4_MASK_TOUCH_ID 0xF0
|
#define FTS4_MASK_TOUCH_ID 0xF0
|
||||||
#define FTS4_MASK_LEFT_EVENT 0x0F
|
|
||||||
#define FTS4_MASK_X_MSB 0x0F
|
#define FTS4_MASK_X_MSB 0x0F
|
||||||
#define FTS4_MASK_Y_LSB 0xF0
|
#define FTS4_MASK_Y_LSB 0xF0
|
||||||
|
|
||||||
/* Key related event masks. */
|
|
||||||
#define FTS4_MASK_KEY_NO_TOUCH 0x00
|
|
||||||
#define FTS4_MASK_KEY_MENU 0x01
|
|
||||||
#define FTS4_MASK_KEY_BACK 0x02
|
|
||||||
|
|
||||||
#define FTS4_EVENT_SIZE 8
|
#define FTS4_EVENT_SIZE 8
|
||||||
#define FTS4_STACK_DEPTH 32
|
#define FTS4_STACK_DEPTH 32 // Actual 128.
|
||||||
#define FTS4_DATA_MAX_SIZE (FTS4_EVENT_SIZE * FTS4_STACK_DEPTH)
|
#define FTS4_DATA_MAX_SIZE (FTS4_EVENT_SIZE * FTS4_STACK_DEPTH)
|
||||||
#define FTS4_MAX_FINGERS 10
|
#define FTS4_MAX_FINGERS 10
|
||||||
|
|
||||||
@@ -175,6 +172,7 @@ int touch_poll(touch_event_t *event);
|
|||||||
touch_info_t *touch_get_chip_info();
|
touch_info_t *touch_get_chip_info();
|
||||||
touch_panel_info_t *touch_get_panel_vendor();
|
touch_panel_info_t *touch_get_panel_vendor();
|
||||||
int touch_get_fw_info(touch_fw_info_t *fw);
|
int touch_get_fw_info(touch_fw_info_t *fw);
|
||||||
|
int touch_get_event_count();
|
||||||
int touch_panel_ito_test(u8 *err);
|
int touch_panel_ito_test(u8 *err);
|
||||||
int touch_execute_autotune();
|
int touch_execute_autotune();
|
||||||
int touch_switch_sense_mode(u8 mode, bool gis_6_2);
|
int touch_switch_sense_mode(u8 mode, bool gis_6_2);
|
||||||
|
|||||||
Reference in New Issue
Block a user