1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-10 04:21:45 +00:00

touch: Small refactor

This commit is contained in:
CTCaer 2020-03-25 01:31:58 +02:00
parent dd4dd91152
commit 4ec7befe82
2 changed files with 38 additions and 40 deletions

View file

@ -236,34 +236,8 @@ int touch_sys_reset()
return 1;
}
int touch_execute_autotune()
int touch_sense_enable()
{
// Reset touchscreen module.
if (touch_sys_reset())
return 0;
// Trim low power oscillator.
touch_command(STMFTS_LP_TIMER_CALIB, NULL, 0);
msleep(200);
// Apply Mutual Sense Compensation tuning.
if (touch_command(STMFTS_MS_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, 1, 2000))
return 0;
// Apply Self Sense Compensation tuning.
if (touch_command(STMFTS_SS_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, 2, 2000))
return 0;
// Save Compensation data to EEPROM.
if (touch_command(STMFTS_SAVE_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, 4, 2000))
return 0;
// Enable auto tuning calibration and multi-touch sensing.
u8 cmd = 1;
if (touch_command(STMFTS_AUTO_CALIBRATION, &cmd, 1))
@ -278,24 +252,45 @@ int touch_execute_autotune()
return 1;
}
int touch_execute_autotune()
{
// Reset touchscreen module.
if (touch_sys_reset())
return 0;
// Trim low power oscillator.
if (touch_command(STMFTS_LP_TIMER_CALIB, NULL, 0))
return 0;
msleep(200);
// Apply Mutual Sense Compensation tuning.
if (touch_command(STMFTS_MS_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_MS_CX_TUNING_DONE, 2000))
return 0;
// Apply Self Sense Compensation tuning.
if (touch_command(STMFTS_SS_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_SS_CX_TUNING_DONE, 2000))
return 0;
// Save Compensation data to EEPROM.
if (touch_command(STMFTS_SAVE_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_WRITE_CX_TUNE_DONE, 2000))
return 0;
return touch_sense_enable();
}
static int touch_init()
{
// Initialize touchscreen module.
if (touch_sys_reset())
return 0;
// Enable auto tuning calibration and multi-touch sensing.
u8 cmd = 1;
if (touch_command(STMFTS_AUTO_CALIBRATION, &cmd, 1))
return 0;
if (touch_command(STMFTS_MS_MT_SENSE_ON, NULL, 0))
return 0;
if (touch_command(STMFTS_CLEAR_EVENT_STACK, NULL, 0))
return 0;
return 1;
return touch_sense_enable();
}
int touch_power_on()

View file

@ -75,10 +75,13 @@
#define STMFTS_EV_NOISE_WRITE 0x18
#define STMFTS_EV_CONTROLLER_READY 0x10
#define STMFTS_EV_SLEEP_OUT_CONTROLLER_READY 0x11
#define STMFTS_EV_STATUS 0x16
#define STMFTS_EV_DEBUG 0xDB
#define STMFTS_EV_STATUS_MS_CX_TUNING_DONE 1
#define STMFTS_EV_STATUS_SS_CX_TUNING_DONE 2
#define STMFTS_EV_STATUS_WRITE_CX_TUNE_DONE 4
/* multi touch related event masks */
#define STMFTS_MASK_EVENT_ID 0x0F
#define STMFTS_MASK_TOUCH_ID 0xF0