rearranged order of hardware initialization
This commit is contained in:
parent
af815a234f
commit
dbfa058d22
3 changed files with 15 additions and 22 deletions
|
@ -2,21 +2,15 @@
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include "tft_hal_esp32.h"
|
#include "tft_hal_esp32.h"
|
||||||
|
|
||||||
uint8_t SDA_GPIO = 19;
|
|
||||||
uint8_t SCL_GPIO = 22;
|
|
||||||
|
|
||||||
void init_hardware_general_HAL(void) {
|
void init_hardware_general_HAL(void) {
|
||||||
// Make sure ESP32 is running at full speed
|
// Make sure ESP32 is running at full speed
|
||||||
setCpuFrequencyMhz(240);
|
setCpuFrequencyMhz(240);
|
||||||
|
|
||||||
// For I2C to work correctly, the tft has to be powered.
|
// this is power for the TFT IC
|
||||||
// Otherwise the IMU cannot be initialized.
|
|
||||||
// The tft touch controller, being on the same I2C bus, seems to disturb if not powered.
|
|
||||||
pinMode(LCD_EN_GPIO, OUTPUT);
|
pinMode(LCD_EN_GPIO, OUTPUT);
|
||||||
digitalWrite(LCD_EN_GPIO, LOW);
|
digitalWrite(LCD_EN_GPIO, HIGH);
|
||||||
|
// this is power for backlight LEDs
|
||||||
// SDA and SCL need to be set explicitly, because for IMU you cannot set it explicitly in the constructor.
|
pinMode(LCD_BL_GPIO, OUTPUT);
|
||||||
// Configure i2c pins and set frequency to 400kHz
|
digitalWrite(LCD_BL_GPIO, HIGH);
|
||||||
Wire.begin(SDA_GPIO, SCL_GPIO, 400000);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#include "tft_hal_esp32.h"
|
#include "tft_hal_esp32.h"
|
||||||
#include "sleep_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_BL_GPIO = 4;
|
||||||
uint8_t LCD_EN_GPIO = 10;
|
uint8_t LCD_EN_GPIO = 10;
|
||||||
|
|
||||||
|
@ -12,13 +15,6 @@ TS_Point touchPoint;
|
||||||
byte backlightBrightness = 255;
|
byte backlightBrightness = 255;
|
||||||
|
|
||||||
void init_tft(void) {
|
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
|
// Configure the backlight PWM
|
||||||
// Manual setup because ledcSetup() briefly turns on the backlight
|
// Manual setup because ledcSetup() briefly turns on the backlight
|
||||||
ledc_channel_config_t ledc_channel_left;
|
ledc_channel_config_t ledc_channel_left;
|
||||||
|
@ -72,6 +68,9 @@ void init_tft(void) {
|
||||||
tft.fillScreen(TFT_BLACK);
|
tft.fillScreen(TFT_BLACK);
|
||||||
tft.setSwapBytes(true);
|
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
|
// Setup touchscreen
|
||||||
touch.begin(128); // Initialize touchscreen and set sensitivity threshold
|
touch.begin(128); // Initialize touchscreen and set sensitivity threshold
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,16 +47,14 @@ int main(int argc, char *argv[]) {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
// do some general hardware setup, like powering the TFT, I2C, ...
|
// do some general hardware setup, like powering the TFT, I2C, ...
|
||||||
init_hardware_general();
|
init_hardware_general();
|
||||||
|
// get wakeup reason
|
||||||
|
init_sleep();
|
||||||
// Restore settings from internal flash memory
|
// Restore settings from internal flash memory
|
||||||
init_preferences();
|
init_preferences();
|
||||||
// blinking led
|
// blinking led
|
||||||
init_userled();
|
init_userled();
|
||||||
// Power Pin definition
|
// Power Pin definition
|
||||||
init_battery();
|
init_battery();
|
||||||
// get wakeup reason
|
|
||||||
init_sleep();
|
|
||||||
// setup the Inertial Measurement Unit (IMU) for motion detection
|
|
||||||
init_IMU();
|
|
||||||
|
|
||||||
// button Pin definition for hardware keys
|
// button Pin definition for hardware keys
|
||||||
init_keys();
|
init_keys();
|
||||||
|
@ -90,6 +88,8 @@ int main(int argc, char *argv[]) {
|
||||||
// init GUI - will initialize tft, touch and lvgl
|
// init GUI - will initialize tft, touch and lvgl
|
||||||
init_gui();
|
init_gui();
|
||||||
gui_loop(); // Run the LVGL UI once before the loop takes over
|
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 the scenes and their key_commands_*
|
||||||
register_scene_defaultKeys();
|
register_scene_defaultKeys();
|
||||||
|
|
Loading…
Reference in a new issue