This commit is contained in:
cod3doomy 2025-04-17 19:27:08 -07:00
commit 50f6e8a089
17 changed files with 245 additions and 34 deletions

View file

@ -29,12 +29,16 @@ public:
uint16_t getBattMilliVolts() override {
#ifdef BATTERY_PIN
#ifdef PIN_3V3_EN
digitalWrite(PIN_3V3_EN, HIGH);
#endif
analogReference(AR_INTERNAL_3_0);
analogReadResolution(12);
delay(10);
float volts = (analogRead(BATTERY_PIN) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096;
#ifdef PIN_3V3_EN
digitalWrite(PIN_3V3_EN, LOW);
#endif
analogReference(AR_DEFAULT); // put back to default
analogReadResolution(10);

View file

@ -7,7 +7,7 @@ class DisplayDriver {
protected:
DisplayDriver(int w, int h) { _w = w; _h = h; }
public:
enum Color { DARK, LIGHT };
enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
int width() const { return _w; }
int height() const { return _h; }

View file

@ -38,7 +38,7 @@ void SSD1306Display::setTextSize(int sz) {
}
void SSD1306Display::setColor(Color c) {
_color = (c == LIGHT) ? SSD1306_WHITE : SSD1306_BLACK;
_color = (c != 0) ? SSD1306_WHITE : SSD1306_BLACK;
display.setTextColor(_color);
}

View file

@ -0,0 +1,117 @@
#ifdef ST7789
#include "ST7789Display.h"
bool ST7789Display::i2c_probe(TwoWire& wire, uint8_t addr) {
return true;
/*
wire.beginTransmission(addr);
uint8_t error = wire.endTransmission();
return (error == 0);
*/
}
bool ST7789Display::begin() {
if(!_isOn) {
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
pinMode(PIN_TFT_LEDA_CTL, OUTPUT);
digitalWrite(PIN_TFT_VDD_CTL, LOW);
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
digitalWrite(PIN_TFT_RST, HIGH);
display.init(135, 240);
display.setRotation(2);
display.setSPISpeed(40000000);
display.fillScreen(ST77XX_BLACK);
display.setTextColor(ST77XX_WHITE);
display.setTextSize(2);
display.cp437(true); // Use full 256 char 'Code Page 437' font
_isOn = true;
}
return true;
}
void ST7789Display::turnOn() {
ST7789Display::begin();
}
void ST7789Display::turnOff() {
digitalWrite(PIN_TFT_VDD_CTL, HIGH);
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
digitalWrite(PIN_TFT_RST, LOW);
// digitalWrite(PIN_TFT_VDD_CTL, LOW);
// digitalWrite(PIN_TFT_LEDA_CTL, LOW);
_isOn = false;
}
void ST7789Display::clear() {
display.fillScreen(ST77XX_BLACK);
}
void ST7789Display::startFrame(Color bkg) {
display.fillScreen(0x00);
display.setTextColor(ST77XX_WHITE);
display.setTextSize(2);
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
void ST7789Display::setTextSize(int sz) {
display.setTextSize(sz);
}
void ST7789Display::setColor(Color c) {
switch (c) {
case DisplayDriver::DARK :
_color = ST77XX_BLACK;
break;
case DisplayDriver::LIGHT :
_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
_color = ST77XX_ORANGE;
break;
default:
_color = ST77XX_WHITE;
break;
}
display.setTextColor(_color);
}
void ST7789Display::setCursor(int x, int y) {
display.setCursor(x, y);
}
void ST7789Display::print(const char* str) {
display.print(str);
}
void ST7789Display::fillRect(int x, int y, int w, int h) {
display.fillRect(x, y, w, h, _color);
}
void ST7789Display::drawRect(int x, int y, int w, int h) {
display.drawRect(x, y, w, h, _color);
}
void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
display.drawBitmap(x, y, bits, w, h, _color);
}
void ST7789Display::endFrame() {
// display.display();
}
#endif

View file

@ -0,0 +1,33 @@
#pragma once
#include "DisplayDriver.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
class ST7789Display : public DisplayDriver {
Adafruit_ST7789 display;
bool _isOn;
uint16_t _color;
bool i2c_probe(TwoWire& wire, uint8_t addr);
public:
ST7789Display() : DisplayDriver(135, 240), display(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST) { _isOn = false; }
// ST7789Display() : DisplayDriver(135, 240), display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST) { _isOn = false; }
bool begin();
bool isOn() override { return _isOn; }
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setCursor(int x, int y) override;
void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
void endFrame() override;
};