fix backlight
This commit is contained in:
parent
db75db33d8
commit
2adff0f1af
4 changed files with 39 additions and 51 deletions
|
@ -1,7 +1,6 @@
|
||||||
#include "HardwareRevX.hpp"
|
#include "HardwareRevX.hpp"
|
||||||
#include "display.hpp"
|
#include "display.hpp"
|
||||||
#include "wifihandler.hpp"
|
#include "wifihandler.hpp"
|
||||||
#include "driver/ledc.h"
|
|
||||||
|
|
||||||
std::shared_ptr<HardwareRevX> HardwareRevX::mInstance = nullptr;
|
std::shared_ptr<HardwareRevX> HardwareRevX::mInstance = nullptr;
|
||||||
|
|
||||||
|
@ -70,19 +69,17 @@ HardwareRevX::WakeReason getWakeReason() {
|
||||||
void HardwareRevX::init() {
|
void HardwareRevX::init() {
|
||||||
// Make sure ESP32 is running at full speed
|
// Make sure ESP32 is running at full speed
|
||||||
setCpuFrequencyMhz(240);
|
setCpuFrequencyMhz(240);
|
||||||
|
wakeup_reason = getWakeReason();
|
||||||
|
initIO();
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
mDisplay = Display::getInstance();
|
mDisplay = Display::getInstance();
|
||||||
mBattery = std::make_shared<Battery>(ADC_BAT,CRG_STAT);
|
mBattery = std::make_shared<Battery>(ADC_BAT,CRG_STAT);
|
||||||
mWifiHandler = wifiHandler::getInstance();
|
mWifiHandler = wifiHandler::getInstance();
|
||||||
|
restorePreferences();
|
||||||
|
|
||||||
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;});
|
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;});
|
||||||
|
|
||||||
wakeup_reason = getWakeReason();
|
|
||||||
initIO();
|
|
||||||
setupBacklight();
|
|
||||||
Serial.begin(115200);
|
|
||||||
restorePreferences();
|
|
||||||
slowDisplayWakeup();
|
|
||||||
setupIMU();
|
setupIMU();
|
||||||
setupIR();
|
setupIR();
|
||||||
|
|
||||||
|
@ -254,29 +251,6 @@ void HardwareRevX::configIMUInterrupts() {
|
||||||
IMU.writeRegister(LIS3DH_CTRL_REG3, dataToWrite);
|
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() {
|
void HardwareRevX::restorePreferences() {
|
||||||
// Restore settings from internal flash memory
|
// Restore settings from internal flash memory
|
||||||
int backlight_brightness = 255;
|
int backlight_brightness = 255;
|
||||||
|
@ -304,19 +278,6 @@ void HardwareRevX::setupIMU() {
|
||||||
IMU.readRegister(&intDataRead, LIS3DH_INT1_SRC); // clear interrupt
|
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() {
|
void HardwareRevX::setupIR() {
|
||||||
// Setup IR
|
// Setup IR
|
||||||
IrSender.begin();
|
IrSender.begin();
|
||||||
|
|
|
@ -43,7 +43,6 @@ public:
|
||||||
protected:
|
protected:
|
||||||
// Init Functions to setup hardware
|
// Init Functions to setup hardware
|
||||||
void initIO();
|
void initIO();
|
||||||
void setupBacklight();
|
|
||||||
void restorePreferences();
|
void restorePreferences();
|
||||||
void slowDisplayWakeup();
|
void slowDisplayWakeup();
|
||||||
void setupIMU();
|
void setupIMU();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "display.hpp"
|
#include "display.hpp"
|
||||||
#include "omoteconfig.h"
|
#include "omoteconfig.h"
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
|
#include "driver/ledc.h"
|
||||||
|
|
||||||
std::shared_ptr<Display> Display::getInstance()
|
std::shared_ptr<Display> Display::getInstance()
|
||||||
{
|
{
|
||||||
|
@ -23,11 +24,12 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(),
|
||||||
pinMode(mBacklightPin, OUTPUT);
|
pinMode(mBacklightPin, OUTPUT);
|
||||||
digitalWrite(mBacklightPin, HIGH);
|
digitalWrite(mBacklightPin, HIGH);
|
||||||
|
|
||||||
ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION);
|
setupBacklight(); // This eliminates the flash of the backlight
|
||||||
ledcAttachPin(mBacklightPin, LCD_BACKLIGHT_LEDC_CHANNEL);
|
|
||||||
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0);
|
|
||||||
|
|
||||||
setupTFT();
|
// This backlight init causes the backlight to come on full during startup
|
||||||
|
// 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);
|
||||||
|
|
||||||
// Slowly charge the VSW voltage to prevent a brownout
|
// Slowly charge the VSW voltage to prevent a brownout
|
||||||
// Workaround for hardware rev 1!
|
// Workaround for hardware rev 1!
|
||||||
|
@ -37,16 +39,40 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(),
|
||||||
digitalWrite(this->mEnablePin, LOW); // LCD Logic on
|
digitalWrite(this->mEnablePin, LOW); // LCD Logic on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupTFT();
|
||||||
setupTouchScreen();
|
setupTouchScreen();
|
||||||
mFadeTaskMutex = xSemaphoreCreateBinary();
|
mFadeTaskMutex = xSemaphoreCreateBinary();
|
||||||
xSemaphoreGive(mFadeTaskMutex);
|
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){
|
void Display::onTouch(Notification<TS_Point>::HandlerTy aTouchHandler){
|
||||||
mTouchEvent.onNotify(std::move(aTouchHandler));
|
mTouchEvent.onNotify(std::move(aTouchHandler));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::setupTFT() {
|
void Display::setupTFT() {
|
||||||
|
delay(100);
|
||||||
tft.init();
|
tft.init();
|
||||||
tft.initDMA();
|
tft.initDMA();
|
||||||
tft.setRotation(0);
|
tft.setRotation(0);
|
||||||
|
@ -74,10 +100,11 @@ uint8_t Display::getBrightness(){
|
||||||
|
|
||||||
void Display::setCurrentBrightness(uint8_t brightness){
|
void Display::setCurrentBrightness(uint8_t brightness){
|
||||||
mBrightness = brightness;
|
mBrightness = brightness;
|
||||||
auto duty = abs(255 - static_cast<int>(mBrightness));
|
// auto duty = abs(255 - static_cast<int>(mBrightness));
|
||||||
|
auto duty = abs(static_cast<int>(mBrightness));
|
||||||
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, duty);
|
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, duty);
|
||||||
Serial.print("Current Brightness:");
|
// Serial.print("Current Brightness:");
|
||||||
Serial.println(mBrightness);
|
// Serial.println(mBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::turnOff()
|
void Display::turnOff()
|
||||||
|
|
|
@ -52,6 +52,7 @@ class Display: public DisplayAbstract
|
||||||
Display(int backlight_pin, int enable_pin);
|
Display(int backlight_pin, int enable_pin);
|
||||||
void setupTFT();
|
void setupTFT();
|
||||||
void setupTouchScreen();
|
void setupTouchScreen();
|
||||||
|
void setupBacklight();
|
||||||
|
|
||||||
int mEnablePin;
|
int mEnablePin;
|
||||||
int mBacklightPin;
|
int mBacklightPin;
|
||||||
|
|
Loading…
Add table
Reference in a new issue