Skip to content

Commit

Permalink
pull in touch screen, IMU and slow screen wake into hardware
Browse files Browse the repository at this point in the history
Change-Id: I61b49a6d0551463becbc3bdf1418ac9fde9d9376
  • Loading branch information
Matthew Colvin authored and Matthew Colvin committed Jul 28, 2023
1 parent 9ea98fc commit 98ecfb0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 41 deletions.
56 changes: 49 additions & 7 deletions Platformio/src/HardwareRevX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ void HardwareRevX::init() {

// Make sure ESP32 is running at full speed
setCpuFrequencyMhz(240);
Serial.begin(115200);

wakeup_reason = getWakeReason();
setupTouchScreen();

slowDisplayWakeup();

initIO();
restorePreferences();
setupBacklight();

// Setup TFT
tft.init();
tft.initDMA();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true);
setupTFT();
setupIMU();

initLVGL();
}
Expand Down Expand Up @@ -319,4 +319,46 @@ void HardwareRevX::restorePreferences() {
backlight_brightness = preferences.getUChar("blBrightness");
currentDevice = preferences.getUChar("currentDevice");
}
}

void HardwareRevX::setupTFT() {
// Setup TFT
tft.init();
tft.initDMA();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true);
}

void HardwareRevX::setupTouchScreen() {
// Configure i2c pins and set frequency to 400kHz
Wire.begin(SDA, SCL, 400000);
touch.begin(128); // Initialize touchscreen and set sensitivity threshold
}

void HardwareRevX::setupIMU() {
// Setup hal
IMU.settings.accelSampleRate =
50; // Hz. Can be: 0,1,10,25,50,100,200,400,1600,5000 Hz
IMU.settings.accelRange = 2; // Max G force readable. Can be: 2, 4, 8, 16
IMU.settings.adcEnabled = 0;
IMU.settings.tempEnabled = 0;
IMU.settings.xAccelEnabled = 1;
IMU.settings.yAccelEnabled = 1;
IMU.settings.zAccelEnabled = 1;
IMU.begin();
uint8_t intDataRead;
IMU.readRegister(&intDataRead, LIS3DH_INT1_SRC); // clear interrupt
}

void HardwareRevX::slowDisplayWakeup() {
// Slowly charge the VSW voltage to prevent a brownout
// Workaround for hardware rev 1!
for (int i = 0; i < 100; i++) {
digitalWrite(LCD_EN, HIGH); // LCD Logic off
delayMicroseconds(1);
digitalWrite(LCD_EN, LOW); // LCD Logic on
}

delay(100); // Wait for the LCD driver to power on
}
7 changes: 7 additions & 0 deletions Platformio/src/HardwareRevX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "HardwareAbstractionInterface.h"
#include "WiFi.h"
#include "Wire.h"
#include "lvgl.h"
#include <Adafruit_FT6206.h>
#include <Preferences.h>
Expand Down Expand Up @@ -56,6 +57,12 @@ class HardwareRevX : public HardwareAbstractionInterface {

void setupTFT();

void setupTouchScreen();

void setupIMU();

void slowDisplayWakeup();

public:
static void displayFlushImpl(lv_disp_drv_t *disp, const lv_area_t *area,
lv_color_t *color_p) {
Expand Down
34 changes: 0 additions & 34 deletions Platformio/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// OMOTE firmware for ESP32
// 2023 Maximilian Kern

#include "Wire.h"
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
Expand Down Expand Up @@ -100,31 +99,12 @@ void WiFiEvent(WiFiEvent_t event) {

void setup() {

// --- Startup ---

Serial.begin(115200);

// Slowly charge the VSW voltage to prevent a brownout
// Workaround for hardware rev 1!
for (int i = 0; i < 100; i++) {
digitalWrite(LCD_EN, HIGH); // LCD Logic off
delayMicroseconds(1);
digitalWrite(LCD_EN, LOW); // LCD Logic on
}

delay(100); // Wait for the LCD driver to power on

// Setup touchscreen
Wire.begin(SDA, SCL,
400000); // Configure i2c pins and set frequency to 400kHz

hal = HardwareRevX::getInstance();
hal->init();

auto ui = OmoteUI::getInstance(hal);
ui->layout_UI();

hal->touch.begin(128); // Initialize touchscreen and set sensitivity threshold
#ifdef ENABLE_WIFI
// Setup WiFi
WiFi.setHostname("OMOTE"); // define hostname
Expand All @@ -133,20 +113,6 @@ void setup() {
WiFi.setSleep(true);
#endif

// Setup hal->IMU
hal->IMU.settings.accelSampleRate =
50; // Hz. Can be: 0,1,10,25,50,100,200,400,1600,5000 Hz
hal->IMU.settings.accelRange =
2; // Max G force readable. Can be: 2, 4, 8, 16
hal->IMU.settings.adcEnabled = 0;
hal->IMU.settings.tempEnabled = 0;
hal->IMU.settings.xAccelEnabled = 1;
hal->IMU.settings.yAccelEnabled = 1;
hal->IMU.settings.zAccelEnabled = 1;
hal->IMU.begin();
uint8_t intDataRead;
hal->IMU.readRegister(&intDataRead, LIS3DH_INT1_SRC); // clear interrupt

// Setup IR
IrSender.begin();
digitalWrite(IR_VCC, HIGH); // Turn on IR receiver
Expand Down

0 comments on commit 98ecfb0

Please sign in to comment.