From 4dc8110b3103e395c10a7f4df6278bef49eb1463 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sun, 16 Dec 2018 23:01:24 +0100 Subject: [PATCH] embed/trezorhal: add touch_sensitivity function --- embed/prodtest/main.c | 30 ++++++++++++++++++++++++++++++ embed/trezorhal/touch.h | 1 + embed/trezorhal/touch_1.h | 2 ++ embed/trezorhal/touch_t.h | 8 ++++++++ 4 files changed, 41 insertions(+) diff --git a/embed/prodtest/main.c b/embed/prodtest/main.c index 4287965e6..8f3ca2fd2 100644 --- a/embed/prodtest/main.c +++ b/embed/prodtest/main.c @@ -226,6 +226,33 @@ static void test_touch(const char *args) touch_power_off(); } +static void test_sensitivity(const char *args) +{ + int v = atoi(args); + + touch_power_on(); + touch_sensitivity(v & 0xFF); + + display_clear(); + display_refresh(); + + for (;;) { + uint32_t evt = touch_read(); + if (evt & TOUCH_START || evt & TOUCH_MOVE) { + int x = touch_unpack_x(evt); + int y = touch_unpack_y(evt); + display_clear(); + display_bar(x - 48, y - 48, 96, 96, 0xFFFF); + display_refresh(); + } else if (evt & TOUCH_END) { + display_clear(); + display_refresh(); + } + } + + touch_power_off(); +} + static void test_pwm(const char *args) { int v = atoi(args); @@ -373,6 +400,9 @@ int main(void) } else if (startswith(line, "TOUCH ")) { test_touch(line + 6); + } else if (startswith(line, "SENS ")) { + test_sensitivity(line + 5); + } else if (startswith(line, "PWM ")) { test_pwm(line + 4); diff --git a/embed/trezorhal/touch.h b/embed/trezorhal/touch.h index 2ea6aa55b..4e18ac43c 100644 --- a/embed/trezorhal/touch.h +++ b/embed/trezorhal/touch.h @@ -29,6 +29,7 @@ void touch_init(void); void touch_power_on(void); void touch_power_off(void); +void touch_sensitivity(uint8_t value); uint32_t touch_read(void); uint32_t touch_click(void); uint32_t touch_is_detected(void); diff --git a/embed/trezorhal/touch_1.h b/embed/trezorhal/touch_1.h index 9f1aea28e..402e963e2 100644 --- a/embed/trezorhal/touch_1.h +++ b/embed/trezorhal/touch_1.h @@ -23,6 +23,8 @@ void touch_power_on(void) { } void touch_power_off(void) { } +void touch_sensitivity(uint8_t value) { (void)value; } + uint32_t touch_read(void) { static char last_left = 0, last_right = 0; diff --git a/embed/trezorhal/touch_t.h b/embed/trezorhal/touch_t.h index 13ff904ff..c8cd35a0f 100644 --- a/embed/trezorhal/touch_t.h +++ b/embed/trezorhal/touch_t.h @@ -109,6 +109,8 @@ void touch_power_on(void) { // set register 0xA4 G_MODE to interrupt polling mode (0x00). basically, CTPM keeps this input line (to PC4) low while a finger is on the screen. uint8_t touch_panel_config[] = {0xA4, 0x00}; ensure(sectrue * (HAL_OK == HAL_I2C_Master_Transmit(&i2c_handle, TOUCH_ADDRESS, touch_panel_config, sizeof(touch_panel_config), 10)), NULL); + + touch_sensitivity(0x06); } void touch_power_off(void) { @@ -121,6 +123,12 @@ void touch_power_off(void) { touch_default_pin_state(); } +void touch_sensitivity(uint8_t value) { + // set panel threshold (TH_GROUP) - default value is 0x12 + uint8_t touch_panel_threshold[] = {0x80, value}; + ensure(sectrue * (HAL_OK == HAL_I2C_Master_Transmit(&i2c_handle, TOUCH_ADDRESS, touch_panel_threshold, sizeof(touch_panel_threshold), 10)), NULL); +} + uint32_t touch_is_detected(void) { // check the interrupt line coming in from the CTPM.