embed/trezorhal: add touch_sensitivity function

pull/25/head
Pavol Rusnak 6 years ago committed by Pavol Rusnak
parent ce972a7a32
commit 4dc8110b31
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -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);

@ -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);

@ -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;

@ -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.

Loading…
Cancel
Save