From 53fcdedb889df4ade991a217ab1cee51e86fc4be Mon Sep 17 00:00:00 2001 From: zxkmm Date: Fri, 26 May 2023 15:50:32 +0800 Subject: [PATCH] init commit for fix touchscreen bad corner (#1071) fix a rounding issue and allow more sensible touchscreen --- firmware/application/hw/touch_adc.cpp | 8 ++++---- firmware/application/touch.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/firmware/application/hw/touch_adc.cpp b/firmware/application/hw/touch_adc.cpp index 7254f156..fe472812 100644 --- a/firmware/application/hw/touch_adc.cpp +++ b/firmware/application/hw/touch_adc.cpp @@ -71,10 +71,10 @@ Samples get() { const auto yp_reg = LPC_ADC0->DR[portapack::adc0_touch_yp_input]; const auto yn_reg = LPC_ADC0->DR[portapack::adc0_touch_yn_input]; return { - (xp_reg >> 6) & 0x3ff, - (xn_reg >> 6) & 0x3ff, - (yp_reg >> 6) & 0x3ff, - (yn_reg >> 6) & 0x3ff, + ((xp_reg >> 6) & 0x3ff) * 16, + ((xn_reg >> 6) & 0x3ff) * 16, + ((yp_reg >> 6) & 0x3ff) * 16, + ((yn_reg >> 6) & 0x3ff) * 16, }; } diff --git a/firmware/application/touch.cpp b/firmware/application/touch.cpp index 16e9c218..21573ef8 100644 --- a/firmware/application/touch.cpp +++ b/firmware/application/touch.cpp @@ -34,16 +34,16 @@ Metrics calculate_metrics(const Frame& frame) { * fast *enough*?), so maybe leave it alone at least for now. */ - const auto x_max = frame.x.xp; - const auto x_min = frame.x.xn; + const auto x_max = frame.x.xp / 16; + const auto x_min = frame.x.xn / 16; const auto x_range = x_max - x_min; - const float x_position = (frame.x.yp + frame.x.yn) * 0.5f; + const float x_position = (frame.x.yp / 16 + frame.x.yn / 16) * 0.5f; const float x_norm = (x_position - x_min) / x_range; - const auto y_max = frame.y.yn; - const auto y_min = frame.y.yp; + const auto y_max = frame.y.yn / 16; + const auto y_min = frame.y.yp / 16; const auto y_range = y_max - y_min; - const float y_position = (frame.y.xp + frame.y.xn) * 0.5f; + const float y_position = (frame.y.xp / 16 + frame.y.xn / 16) * 0.5f; const float y_norm = (y_position - y_min) / y_range; const auto z_max = frame.pressure.yp;