mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 09:42:35 +00:00
For #4154 - change TFT driver to use virtual GPIO for backlight enable
This commit is contained in:
parent
02c34e6214
commit
db6e591c07
@ -516,6 +516,21 @@ extern unPhone unphone;
|
|||||||
TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus)
|
TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("TFTDisplay!\n");
|
LOG_DEBUG("TFTDisplay!\n");
|
||||||
|
|
||||||
|
#ifdef TFT_BL
|
||||||
|
GpioPin *p = new GpioHwPin(TFT_BL);
|
||||||
|
|
||||||
|
if (!TFT_BACKLIGHT_ON) { // Need to invert the pin before hardware
|
||||||
|
auto virtPin = new GpioVirtPin();
|
||||||
|
new GpioNotTransformer(
|
||||||
|
virtPin, p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio
|
||||||
|
p = virtPin;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
GpioPin *p = new GpioVirtPin(); // Just simulate a pin
|
||||||
|
#endif
|
||||||
|
backlightEnable = p;
|
||||||
|
|
||||||
#if ARCH_PORTDUINO
|
#if ARCH_PORTDUINO
|
||||||
if (settingsMap[displayRotate]) {
|
if (settingsMap[displayRotate]) {
|
||||||
setGeometry(GEOMETRY_RAWMODE, settingsMap[configNames::displayHeight], settingsMap[configNames::displayWidth]);
|
setGeometry(GEOMETRY_RAWMODE, settingsMap[configNames::displayHeight], settingsMap[configNames::displayWidth]);
|
||||||
@ -569,13 +584,11 @@ void TFTDisplay::sendCommand(uint8_t com)
|
|||||||
// handle display on/off directly
|
// handle display on/off directly
|
||||||
switch (com) {
|
switch (com) {
|
||||||
case DISPLAYON: {
|
case DISPLAYON: {
|
||||||
|
backlightEnable->set(true);
|
||||||
#if ARCH_PORTDUINO
|
#if ARCH_PORTDUINO
|
||||||
display(true);
|
display(true);
|
||||||
if (settingsMap[displayBacklight] > 0)
|
if (settingsMap[displayBacklight] > 0)
|
||||||
digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON);
|
digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON);
|
||||||
#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON)
|
|
||||||
pinMode(TFT_BL, OUTPUT);
|
|
||||||
digitalWrite(TFT_BL, TFT_BACKLIGHT_ON);
|
|
||||||
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
|
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
|
||||||
tft->wakeup();
|
tft->wakeup();
|
||||||
tft->powerSaveOff();
|
tft->powerSaveOff();
|
||||||
@ -594,13 +607,11 @@ void TFTDisplay::sendCommand(uint8_t com)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DISPLAYOFF: {
|
case DISPLAYOFF: {
|
||||||
|
backlightEnable->set(false);
|
||||||
#if ARCH_PORTDUINO
|
#if ARCH_PORTDUINO
|
||||||
tft->clear();
|
tft->clear();
|
||||||
if (settingsMap[displayBacklight] > 0)
|
if (settingsMap[displayBacklight] > 0)
|
||||||
digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON);
|
digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON);
|
||||||
#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON)
|
|
||||||
pinMode(TFT_BL, OUTPUT);
|
|
||||||
digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON);
|
|
||||||
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
|
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
|
||||||
tft->sleep();
|
tft->sleep();
|
||||||
tft->powerSaveOn();
|
tft->powerSaveOn();
|
||||||
@ -689,13 +700,8 @@ bool TFTDisplay::connect()
|
|||||||
tft = new LGFX;
|
tft = new LGFX;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TFT_BL
|
backlightEnable->set(true);
|
||||||
pinMode(TFT_BL, OUTPUT);
|
|
||||||
digitalWrite(TFT_BL, TFT_BACKLIGHT_ON);
|
|
||||||
// pinMode(PIN_3V3_EN, OUTPUT);
|
|
||||||
// digitalWrite(PIN_3V3_EN, HIGH);
|
|
||||||
LOG_INFO("Power to TFT Backlight\n");
|
LOG_INFO("Power to TFT Backlight\n");
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef UNPHONE
|
#ifdef UNPHONE
|
||||||
unphone.backlight(true); // using unPhone library
|
unphone.backlight(true); // using unPhone library
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <GpioLogic.h>
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,6 +40,12 @@ class TFTDisplay : public OLEDDisplay
|
|||||||
*/
|
*/
|
||||||
void setDetected(uint8_t detected);
|
void setDetected(uint8_t detected);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is normally managed entirely by TFTDisplay, but some rare applications (heltec tracker) might need to replace the
|
||||||
|
* default GPIO behavior with something a bit more complex.
|
||||||
|
*/
|
||||||
|
GpioPin *backlightEnable;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// the header size of the buffer used, e.g. for the SPI command header
|
// the header size of the buffer used, e.g. for the SPI command header
|
||||||
virtual int getBufferOffset(void) override { return 0; }
|
virtual int getBufferOffset(void) override { return 0; }
|
||||||
|
Loading…
Reference in New Issue
Block a user