Skip to content

Commit

Permalink
rearranged order of hardware initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed Mar 15, 2024
1 parent af815a2 commit dbfa058
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
16 changes: 5 additions & 11 deletions Platformio/hardware/ESP32/hardware_general_hal_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
#include <Wire.h>
#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);

}
13 changes: 6 additions & 7 deletions Platformio/hardware/ESP32/tft_hal_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions Platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit dbfa058

Please sign in to comment.