From dbfa058d2289b2e729489a43915d3db9f8e0f12f Mon Sep 17 00:00:00 2001 From: KlausMu Date: Fri, 15 Mar 2024 21:35:13 +0100 Subject: [PATCH] rearranged order of hardware initialization --- .../ESP32/hardware_general_hal_esp32.cpp | 16 +++++----------- Platformio/hardware/ESP32/tft_hal_esp32.cpp | 13 ++++++------- Platformio/src/main.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Platformio/hardware/ESP32/hardware_general_hal_esp32.cpp b/Platformio/hardware/ESP32/hardware_general_hal_esp32.cpp index e5a9d6c..841c8f4 100644 --- a/Platformio/hardware/ESP32/hardware_general_hal_esp32.cpp +++ b/Platformio/hardware/ESP32/hardware_general_hal_esp32.cpp @@ -2,21 +2,15 @@ #include #include "tft_hal_esp32.h" -uint8_t SDA_GPIO = 19; -uint8_t SCL_GPIO = 22; - void init_hardware_general_HAL(void) { // Make sure ESP32 is running at full speed setCpuFrequencyMhz(240); - // For I2C to work correctly, the tft has to be powered. - // Otherwise the IMU cannot be initialized. - // The tft touch controller, being on the same I2C bus, seems to disturb if not powered. + // this is power for the TFT IC pinMode(LCD_EN_GPIO, OUTPUT); - digitalWrite(LCD_EN_GPIO, LOW); - - // SDA and SCL need to be set explicitly, because for IMU you cannot set it explicitly in the constructor. - // Configure i2c pins and set frequency to 400kHz - Wire.begin(SDA_GPIO, SCL_GPIO, 400000); + digitalWrite(LCD_EN_GPIO, HIGH); + // this is power for backlight LEDs + pinMode(LCD_BL_GPIO, OUTPUT); + digitalWrite(LCD_BL_GPIO, HIGH); } diff --git a/Platformio/hardware/ESP32/tft_hal_esp32.cpp b/Platformio/hardware/ESP32/tft_hal_esp32.cpp index 5bd9376..9317e9e 100644 --- a/Platformio/hardware/ESP32/tft_hal_esp32.cpp +++ b/Platformio/hardware/ESP32/tft_hal_esp32.cpp @@ -3,6 +3,9 @@ #include "tft_hal_esp32.h" #include "sleep_hal_esp32.h" +uint8_t SDA_GPIO = 19; +uint8_t SCL_GPIO = 22; + uint8_t LCD_BL_GPIO = 4; uint8_t LCD_EN_GPIO = 10; @@ -12,13 +15,6 @@ TS_Point touchPoint; byte backlightBrightness = 255; void init_tft(void) { - // this is power for the TFT IC - pinMode(LCD_EN_GPIO, OUTPUT); - digitalWrite(LCD_EN_GPIO, HIGH); - // this is power for backlight LEDs - pinMode(LCD_BL_GPIO, OUTPUT); - digitalWrite(LCD_BL_GPIO, HIGH); - // Configure the backlight PWM // Manual setup because ledcSetup() briefly turns on the backlight ledc_channel_config_t ledc_channel_left; @@ -72,6 +68,9 @@ void init_tft(void) { tft.fillScreen(TFT_BLACK); tft.setSwapBytes(true); + // SDA and SCL need to be set explicitly, because for IMU you cannot set it explicitly in the constructor. + // Configure i2c pins and set frequency to 400kHz + Wire.begin(SDA_GPIO, SCL_GPIO, 400000); // Setup touchscreen touch.begin(128); // Initialize touchscreen and set sensitivity threshold } diff --git a/Platformio/src/main.cpp b/Platformio/src/main.cpp index 5f68fcc..288c066 100644 --- a/Platformio/src/main.cpp +++ b/Platformio/src/main.cpp @@ -47,16 +47,14 @@ int main(int argc, char *argv[]) { Serial.begin(115200); // do some general hardware setup, like powering the TFT, I2C, ... init_hardware_general(); + // get wakeup reason + init_sleep(); // Restore settings from internal flash memory init_preferences(); // blinking led init_userled(); // Power Pin definition init_battery(); - // get wakeup reason - init_sleep(); - // setup the Inertial Measurement Unit (IMU) for motion detection - init_IMU(); // button Pin definition for hardware keys init_keys(); @@ -90,6 +88,8 @@ int main(int argc, char *argv[]) { // init GUI - will initialize tft, touch and lvgl init_gui(); gui_loop(); // Run the LVGL UI once before the loop takes over + // setup the Inertial Measurement Unit (IMU) for motion detection. Has to be after init_gui(), otherwise I2C will not work + init_IMU(); // register the scenes and their key_commands_* register_scene_defaultKeys();