diff --git a/src/drv/touch/touch_driver_gt911.cpp b/src/drv/touch/touch_driver_gt911.cpp index 1ff67cad3..9e18a5f2b 100644 --- a/src/drv/touch/touch_driver_gt911.cpp +++ b/src/drv/touch/touch_driver_gt911.cpp @@ -92,9 +92,60 @@ IRAM_ATTR bool TouchGt911::read(lv_indev_drv_t* indev_driver, lv_indev_data_t* d return false; } +#ifdef NOISE_REDUCTION +void TouchGt911::setup_noise_reduction(uint8_t nr_level) +{ + uint8_t len = 0x8100 - GT_REG_CFG; + uint8_t cfg[len]; + GTInfo* info; + uint8_t err; + + memset(cfg, 0, len); +/* This is the only way to read the entire config space. + The Goodix driver provides a readConfig() function, but + struct is not packed which leads to errors (when using + struct members). + + Need to do a split read as the WDT will bite for reads + of more than 128 bytes (give or take). +*/ + err = touch.read(GT_REG_CFG, cfg, 100); + if (err != 0) goto end2; + if (cfg[11] == nr_level) { + LOG_INFO(TAG_DRVR, "GT911 noise reduction unchanged"); + return; + } + err = touch.read(GT_REG_CFG+100, cfg+100, len-100); + if (err != 0) goto end2; + + if (cfg[len - 1] != touch.calcChecksum(cfg, len - 1)) goto end2; + + // Check noise_reduction is within limits + if (nr_level < 0 || nr_level > 15) { + LOG_ERROR(TAG_DRVR, "GT911 Noise Reduction value out of range (0-15)"); + return; + } + cfg[11] = nr_level; + cfg[len - 1] = touch.calcChecksum(cfg, len - 1); + + err = touch.write(GT_REG_CFG, cfg, len); + if (err != 0) goto end; + err = touch.write(0x8100, 1); + if (err != 0) goto end; + LOG_INFO(TAG_DRVR, "GT911 noise reduction updated"); + return; +end: + LOG_ERROR(TAG_DRVR, "GT911 Failed to write noise reduction byte"); + return; +end2: + LOG_ERROR(TAG_DRVR, "GT911 Failed to read config space"); +} +#endif + void TouchGt911::init(int w, int h) { Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY); + touch.setHandler(GT911_setXY); GTInfo* info; @@ -102,7 +153,7 @@ void TouchGt911::init(int w, int h) info = touch.readInfo(); if(info->xResolution > 0 && info->yResolution > 0) goto found; } - + #if TOUCH_IRQ == -1 // Probe both addresses if IRQ is not connected for(uint8_t i = 0; i < 4; i++) diff --git a/src/drv/touch/touch_driver_gt911.h b/src/drv/touch/touch_driver_gt911.h index 983e696e8..2ad9a8eb8 100644 --- a/src/drv/touch/touch_driver_gt911.h +++ b/src/drv/touch/touch_driver_gt911.h @@ -14,6 +14,9 @@ class TouchGt911 : public BaseTouch { public: IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data); void init(int w, int h); +#ifdef NOISE_REDUCTION + void setup_noise_reduction(uint8_t nr_level); +#endif }; } // namespace dev diff --git a/src/hasp_config.h b/src/hasp_config.h index 04160d30d..1b3b30c33 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -80,6 +80,7 @@ const char FP_CONFIG_VPN_IP[] PROGMEM = "vpnip"; const char FP_CONFIG_PRIVATE_KEY[] PROGMEM = "privkey"; const char FP_CONFIG_PUBLIC_KEY[] PROGMEM = "pubkey"; const char FP_GUI_ROTATION[] PROGMEM = "rotate"; +const char FP_GUI_NOISE_REDUCTION[] PROGMEM = "noise_reduction"; const char FP_GUI_INVERT[] PROGMEM = "invert"; const char FP_GUI_TICKPERIOD[] PROGMEM = "tick"; const char FP_GUI_IDLEPERIOD1[] PROGMEM = "idle1"; diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index ebb7870af..883b94bb5 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -46,6 +46,7 @@ gui_conf_t gui_settings = {.show_pointer = false, .backlight_pin = TFT_BCKL, .rotation = TFT_ROTATION, .invert_display = INVERT_COLORS, + .noise_reduction = 5, .cal_data = {0, 65535, 0, 65535, 0}}; lv_obj_t* cursor; @@ -347,6 +348,9 @@ void guiSetup() #if HASP_TARGET_ARDUINO // drv_touch_init(gui_settings.rotation); // Touch driver haspTouch.init(tft_width, tft_height); +#ifdef NOISE_REDUCTION + haspTouch.setup_noise_reduction(gui_settings.noise_reduction); +#endif haspTouch.set_calibration(gui_settings.cal_data); haspTouch.set_rotation(gui_settings.rotation); #endif @@ -487,7 +491,10 @@ bool guiGetConfig(const JsonObject& settings) if(gui_settings.rotation != settings[FPSTR(FP_GUI_ROTATION)].as()) changed = true; settings[FPSTR(FP_GUI_ROTATION)] = gui_settings.rotation; - +#ifdef NOISE_REDUCTION + if(gui_settings.noise_reduction != settings[FPSTR(FP_GUI_NOISE_REDUCTION)].as()) changed = true; + settings[FPSTR(FP_GUI_NOISE_REDUCTION)] = gui_settings.noise_reduction; +#endif if(gui_settings.show_pointer != settings[FPSTR(FP_GUI_POINTER)].as()) changed = true; settings[FPSTR(FP_GUI_POINTER)] = (uint8_t)gui_settings.show_pointer; @@ -562,6 +569,9 @@ bool guiSetConfig(const JsonObject& settings) changed |= configSet(guiSleepTime1, settings[FPSTR(FP_GUI_IDLEPERIOD1)], F("guiSleepTime1")); changed |= configSet(guiSleepTime2, settings[FPSTR(FP_GUI_IDLEPERIOD2)], F("guiSleepTime2")); changed |= configSet(gui_settings.rotation, settings[FPSTR(FP_GUI_ROTATION)], F("gui_settings.rotation")); +#ifdef NOISE_REDUCTION + changed |= configSet(gui_settings.noise_reduction, settings[FPSTR(FP_GUI_NOISE_REDUCTION)], F("gui_settings.noise_reduction")); +#endif changed |= configSet(gui_settings.invert_display, settings[FPSTR(FP_GUI_INVERT)], F("guiInvertDisplay")); hasp_set_sleep_time(guiSleepTime1, guiSleepTime2); diff --git a/src/hasp_gui.h b/src/hasp_gui.h index dd3680a80..532dfa23b 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -33,6 +33,7 @@ struct gui_conf_t int8_t backlight_pin; uint8_t rotation; uint8_t invert_display; + uint8_t noise_reduction; #if defined(USER_SETUP_LOADED) uint16_t cal_data[5]; #else diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index eba778bb6..fdbc3bbf4 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1560,8 +1560,14 @@ static void http_handle_gui() - -
+
)"; +#ifdef NOISE_REDUCTION + html[min(i++, len)] = R"(
+
+
+
)"; +#endif + html[min(i++, len)] = R"(
diff --git a/src/sys/svc/hasp_http_async.cpp b/src/sys/svc/hasp_http_async.cpp index e4e882efb..af0c7f531 100644 --- a/src/sys/svc/hasp_http_async.cpp +++ b/src/sys/svc/hasp_http_async.cpp @@ -1297,7 +1297,12 @@ void webHandleGuiConfig(AsyncWebServerRequest* request) httpMessage += getOption(4, F("180 degrees - mirrored"), rotation == 4); httpMessage += getOption(5, F("270 degrees - mirrored"), rotation == 5); httpMessage += F("

"); - +#ifdef NOISE_REDUCTION + httpMessage += F("

Noise Reduction

"); +#endif httpMessage += F("

()) httpMessage += F(" checked"); httpMessage += F(">Invert Colors"); diff --git a/user_setups/esp32s3/esp32-s3-4848S040.ini b/user_setups/esp32s3/esp32-s3-4848S040.ini index 27d89050d..4f4bb4499 100644 --- a/user_setups/esp32s3/esp32-s3-4848S040.ini +++ b/user_setups/esp32s3/esp32-s3-4848S040.ini @@ -52,7 +52,7 @@ build_flags = -D TFT_RST=-1 -D TFT_BUSY=-1 -D TFT_BCKL=38 - -D BACKLIGHT_FREQUENCY=100 + -D BACKLIGHT_FREQUENCY=110 ; Panel Settings -D TFT_HSYNC_POLARITY=1 -D TFT_HSYNC_FRONT_PORCH=10 @@ -67,6 +67,7 @@ build_flags = -D TFT_AUTO_FLUSH=1 ; Touch Settings -D TOUCH_DRIVER=0x911 + -D NOISE_REDUCTION -D TOUCH_WIDTH=480 -D TOUCH_HEIGHT=480 -D TOUCH_SDA=19