commit
04936d1245
4 changed files with 35 additions and 53 deletions
|
@ -1,7 +1,6 @@
|
|||
#include "HardwareRevX.hpp"
|
||||
#include "display.hpp"
|
||||
#include "wifihandler.hpp"
|
||||
#include "driver/ledc.h"
|
||||
|
||||
std::shared_ptr<HardwareRevX> HardwareRevX::mInstance = nullptr;
|
||||
|
||||
|
@ -70,19 +69,17 @@ HardwareRevX::WakeReason getWakeReason() {
|
|||
void HardwareRevX::init() {
|
||||
// Make sure ESP32 is running at full speed
|
||||
setCpuFrequencyMhz(240);
|
||||
wakeup_reason = getWakeReason();
|
||||
initIO();
|
||||
Serial.begin(115200);
|
||||
|
||||
mDisplay = Display::getInstance();
|
||||
mBattery = std::make_shared<Battery>(ADC_BAT,CRG_STAT);
|
||||
mWifiHandler = wifiHandler::getInstance();
|
||||
restorePreferences();
|
||||
|
||||
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;});
|
||||
|
||||
wakeup_reason = getWakeReason();
|
||||
initIO();
|
||||
setupBacklight();
|
||||
Serial.begin(115200);
|
||||
restorePreferences();
|
||||
slowDisplayWakeup();
|
||||
setupIMU();
|
||||
setupIR();
|
||||
|
||||
|
@ -254,29 +251,6 @@ void HardwareRevX::configIMUInterrupts() {
|
|||
IMU.writeRegister(LIS3DH_CTRL_REG3, dataToWrite);
|
||||
}
|
||||
|
||||
// TODO move to display
|
||||
void HardwareRevX::setupBacklight() {
|
||||
// Configure the backlight PWM
|
||||
// Manual setup because ledcSetup() briefly turns on the backlight
|
||||
ledc_channel_config_t ledc_channel_left;
|
||||
ledc_channel_left.gpio_num = (gpio_num_t)LCD_BL;
|
||||
ledc_channel_left.speed_mode = LEDC_HIGH_SPEED_MODE;
|
||||
ledc_channel_left.channel = LEDC_CHANNEL_5;
|
||||
ledc_channel_left.intr_type = LEDC_INTR_DISABLE;
|
||||
ledc_channel_left.timer_sel = LEDC_TIMER_1;
|
||||
ledc_channel_left.flags.output_invert = 1; // Can't do this with ledcSetup()
|
||||
ledc_channel_left.duty = 0;
|
||||
|
||||
ledc_timer_config_t ledc_timer;
|
||||
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
|
||||
ledc_timer.duty_resolution = LEDC_TIMER_8_BIT;
|
||||
ledc_timer.timer_num = LEDC_TIMER_1;
|
||||
ledc_timer.freq_hz = 640;
|
||||
|
||||
ledc_channel_config(&ledc_channel_left);
|
||||
ledc_timer_config(&ledc_timer);
|
||||
}
|
||||
|
||||
void HardwareRevX::restorePreferences() {
|
||||
// Restore settings from internal flash memory
|
||||
int backlight_brightness = 255;
|
||||
|
@ -304,19 +278,6 @@ void HardwareRevX::setupIMU() {
|
|||
IMU.readRegister(&intDataRead, LIS3DH_INT1_SRC); // clear interrupt
|
||||
}
|
||||
|
||||
// TODO move to display
|
||||
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
|
||||
}
|
||||
|
||||
void HardwareRevX::setupIR() {
|
||||
// Setup IR
|
||||
IrSender.begin();
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
protected:
|
||||
// Init Functions to setup hardware
|
||||
void initIO();
|
||||
void setupBacklight();
|
||||
void restorePreferences();
|
||||
void slowDisplayWakeup();
|
||||
void setupIMU();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "display.hpp"
|
||||
#include "omoteconfig.h"
|
||||
#include "Wire.h"
|
||||
#include "driver/ledc.h"
|
||||
|
||||
std::shared_ptr<Display> Display::getInstance()
|
||||
{
|
||||
|
@ -23,11 +24,7 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(),
|
|||
pinMode(mBacklightPin, OUTPUT);
|
||||
digitalWrite(mBacklightPin, HIGH);
|
||||
|
||||
ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION);
|
||||
ledcAttachPin(mBacklightPin, LCD_BACKLIGHT_LEDC_CHANNEL);
|
||||
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0);
|
||||
|
||||
setupTFT();
|
||||
setupBacklight(); // This eliminates the flash of the backlight
|
||||
|
||||
// Slowly charge the VSW voltage to prevent a brownout
|
||||
// Workaround for hardware rev 1!
|
||||
|
@ -37,16 +34,40 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(),
|
|||
digitalWrite(this->mEnablePin, LOW); // LCD Logic on
|
||||
}
|
||||
|
||||
setupTFT();
|
||||
setupTouchScreen();
|
||||
mFadeTaskMutex = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(mFadeTaskMutex);
|
||||
}
|
||||
|
||||
void Display::setupBacklight() {
|
||||
// Configure the backlight PWM
|
||||
// Manual setup because ledcSetup() briefly turns on the backlight
|
||||
ledc_channel_config_t ledc_channel_left;
|
||||
ledc_channel_left.gpio_num = (gpio_num_t)mBacklightPin;
|
||||
ledc_channel_left.speed_mode = LEDC_HIGH_SPEED_MODE;
|
||||
ledc_channel_left.channel = LEDC_CHANNEL_5;
|
||||
ledc_channel_left.intr_type = LEDC_INTR_DISABLE;
|
||||
ledc_channel_left.timer_sel = LEDC_TIMER_1;
|
||||
ledc_channel_left.flags.output_invert = 1; // Can't do this with ledcSetup()
|
||||
ledc_channel_left.duty = 0;
|
||||
ledc_channel_left.hpoint = 0;
|
||||
ledc_timer_config_t ledc_timer;
|
||||
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
|
||||
ledc_timer.duty_resolution = LEDC_TIMER_8_BIT;
|
||||
ledc_timer.timer_num = LEDC_TIMER_1;
|
||||
ledc_timer.clk_cfg = LEDC_AUTO_CLK;
|
||||
ledc_timer.freq_hz = 640;
|
||||
ledc_channel_config(&ledc_channel_left);
|
||||
ledc_timer_config(&ledc_timer);
|
||||
}
|
||||
|
||||
void Display::onTouch(Notification<TS_Point>::HandlerTy aTouchHandler){
|
||||
mTouchEvent.onNotify(std::move(aTouchHandler));
|
||||
}
|
||||
|
||||
void Display::setupTFT() {
|
||||
delay(100);
|
||||
tft.init();
|
||||
tft.initDMA();
|
||||
tft.setRotation(0);
|
||||
|
@ -74,10 +95,10 @@ uint8_t Display::getBrightness(){
|
|||
|
||||
void Display::setCurrentBrightness(uint8_t brightness){
|
||||
mBrightness = brightness;
|
||||
auto duty = abs(255 - static_cast<int>(mBrightness));
|
||||
auto duty = static_cast<int>(mBrightness);
|
||||
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, duty);
|
||||
Serial.print("Current Brightness:");
|
||||
Serial.println(mBrightness);
|
||||
// Serial.print("Current Brightness:");
|
||||
// Serial.println(mBrightness);
|
||||
}
|
||||
|
||||
void Display::turnOff()
|
||||
|
@ -170,4 +191,4 @@ void Display::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_
|
|||
tft.endWrite();
|
||||
|
||||
lv_disp_flush_ready(disp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ class Display: public DisplayAbstract
|
|||
Display(int backlight_pin, int enable_pin);
|
||||
void setupTFT();
|
||||
void setupTouchScreen();
|
||||
void setupBacklight();
|
||||
|
||||
int mEnablePin;
|
||||
int mBacklightPin;
|
||||
|
|
Loading…
Add table
Reference in a new issue