mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-27 02:14:37 +00:00
TFT display kinda draws stuff (badly)
This commit is contained in:
parent
338445d175
commit
e049eac38a
@ -10,11 +10,12 @@
|
|||||||
#include <SSD1306Wire.h>
|
#include <SSD1306Wire.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "concurrency/PeriodicTask.h"
|
#include "TFT.h"
|
||||||
#include "TypedQueue.h"
|
#include "TypedQueue.h"
|
||||||
#include "concurrency/LockGuard.h"
|
|
||||||
#include "power.h"
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "concurrency/LockGuard.h"
|
||||||
|
#include "concurrency/PeriodicTask.h"
|
||||||
|
#include "power.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace graphics
|
namespace graphics
|
||||||
@ -60,9 +61,12 @@ class DebugInfo
|
|||||||
*/
|
*/
|
||||||
class Screen : public concurrency::PeriodicTask
|
class Screen : public concurrency::PeriodicTask
|
||||||
{
|
{
|
||||||
CallbackObserver<Screen, const meshtastic::Status *> powerStatusObserver = CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
CallbackObserver<Screen, const meshtastic::Status *> powerStatusObserver =
|
||||||
CallbackObserver<Screen, const meshtastic::Status *> gpsStatusObserver = CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
||||||
CallbackObserver<Screen, const meshtastic::Status *> nodeStatusObserver = CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
CallbackObserver<Screen, const meshtastic::Status *> gpsStatusObserver =
|
||||||
|
CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
||||||
|
CallbackObserver<Screen, const meshtastic::Status *> nodeStatusObserver =
|
||||||
|
CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Screen(uint8_t address, int sda = -1, int scl = -1);
|
Screen(uint8_t address, int sda = -1, int scl = -1);
|
||||||
@ -125,7 +129,8 @@ class Screen : public concurrency::PeriodicTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Overrides the default utf8 character conversion, to replace empty space with question marks
|
/// Overrides the default utf8 character conversion, to replace empty space with question marks
|
||||||
static char customFontTableLookup(const uint8_t ch) {
|
static char customFontTableLookup(const uint8_t ch)
|
||||||
|
{
|
||||||
// UTF-8 to font table index converter
|
// UTF-8 to font table index converter
|
||||||
// Code form http://playground.arduino.cc/Main/Utf8ascii
|
// Code form http://playground.arduino.cc/Main/Utf8ascii
|
||||||
static uint8_t LASTCHAR;
|
static uint8_t LASTCHAR;
|
||||||
@ -141,18 +146,28 @@ class Screen : public concurrency::PeriodicTask
|
|||||||
LASTCHAR = ch;
|
LASTCHAR = ch;
|
||||||
|
|
||||||
switch (last) { // conversion depnding on first UTF8-character
|
switch (last) { // conversion depnding on first UTF8-character
|
||||||
case 0xC2: { SKIPREST = false; return (uint8_t) ch; }
|
case 0xC2: {
|
||||||
case 0xC3: { SKIPREST = false; return (uint8_t) (ch | 0xC0); }
|
SKIPREST = false;
|
||||||
|
return (uint8_t)ch;
|
||||||
|
}
|
||||||
|
case 0xC3: {
|
||||||
|
SKIPREST = false;
|
||||||
|
return (uint8_t)(ch | 0xC0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to strip out prefix chars for two-byte char formats
|
// We want to strip out prefix chars for two-byte char formats
|
||||||
if (ch == 0xC2 || ch == 0xC3 || ch == 0x82) return (uint8_t) 0;
|
if (ch == 0xC2 || ch == 0xC3 || ch == 0x82)
|
||||||
|
return (uint8_t)0;
|
||||||
|
|
||||||
// If we already returned an unconvertable-character symbol for this unconvertable-character sequence, return NULs for the rest of it
|
// If we already returned an unconvertable-character symbol for this unconvertable-character sequence, return NULs for the
|
||||||
if (SKIPREST) return (uint8_t) 0;
|
// rest of it
|
||||||
|
if (SKIPREST)
|
||||||
|
return (uint8_t)0;
|
||||||
SKIPREST = true;
|
SKIPREST = true;
|
||||||
|
|
||||||
return (uint8_t) 191; // otherwise: return ¿ if character can't be converted (note that the font map we're using doesn't stick to standard EASCII codes)
|
return (uint8_t)191; // otherwise: return ¿ if character can't be converted (note that the font map we're using doesn't
|
||||||
|
// stick to standard EASCII codes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a handle to the DebugInfo screen.
|
/// Returns a handle to the DebugInfo screen.
|
||||||
@ -215,8 +230,10 @@ class Screen : public concurrency::PeriodicTask
|
|||||||
DebugInfo debugInfo;
|
DebugInfo debugInfo;
|
||||||
|
|
||||||
/// Display device
|
/// Display device
|
||||||
/** @todo display abstraction */
|
/** FIXME cleanup display abstraction */
|
||||||
#ifdef USE_SH1106
|
#ifdef ST7735_CS
|
||||||
|
TFTDisplay dispdev;
|
||||||
|
#elif defined(USE_SH1106)
|
||||||
SH1106Wire dispdev;
|
SH1106Wire dispdev;
|
||||||
#else
|
#else
|
||||||
SSD1306Wire dispdev;
|
SSD1306Wire dispdev;
|
||||||
|
@ -2,12 +2,35 @@
|
|||||||
|
|
||||||
#ifdef ST7735_CS
|
#ifdef ST7735_CS
|
||||||
|
|
||||||
|
#include "TFT.h"
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
|
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
|
||||||
|
|
||||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
||||||
|
|
||||||
void TFTinit()
|
|
||||||
|
TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl)
|
||||||
|
{
|
||||||
|
setGeometry(
|
||||||
|
GEOMETRY_128_64); // FIXME - currently we lie and claim 128x64 because I'm not yet sure other resolutions will work
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the buffer to the display memory
|
||||||
|
void TFTDisplay::display(void)
|
||||||
|
{
|
||||||
|
// FIXME - only draw bits have changed (use backbuf similar to the other displays)
|
||||||
|
tft.drawBitmap(0, 0, buffer, 128, 64, TFT_YELLOW, TFT_BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send a command to the display (low level function)
|
||||||
|
void TFTDisplay::sendCommand(uint8_t com)
|
||||||
|
{
|
||||||
|
(void)com;
|
||||||
|
// Drop all commands to device (we just update the buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to the display
|
||||||
|
bool TFTDisplay::connect()
|
||||||
{
|
{
|
||||||
DEBUG_MSG("Doing TFT init\n");
|
DEBUG_MSG("Doing TFT init\n");
|
||||||
|
|
||||||
@ -17,8 +40,11 @@ void TFTinit()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
tft.init();
|
tft.init();
|
||||||
tft.setRotation(1);
|
tft.setRotation(3); // Orient horizontal and wide underneath the silkscreen name label
|
||||||
tft.fillScreen(TFT_GREEN);
|
tft.fillScreen(TFT_BLUE);
|
||||||
|
// tft.drawRect(0, 0, 40, 10, TFT_PURPLE); // wide rectangle in upper left
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,3 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void TFTinit();
|
#include <OLEDDisplay.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An adapter class that allows using the TFT_eSPI library as if it was an OLEDDisplay implementation.
|
||||||
|
*
|
||||||
|
* Remaining TODO:
|
||||||
|
* optimize display() to only draw changed pixels (see other OLED subclasses for examples)
|
||||||
|
* implement displayOn/displayOff to turn off the TFT device (and backlight)
|
||||||
|
* Use the fast NRF52 SPI API rather than the slow standard arduino version
|
||||||
|
* turn radio back on
|
||||||
|
*/
|
||||||
|
class TFTDisplay : public OLEDDisplay
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/* constructor
|
||||||
|
FIXME - the parameters are not used, just a temporary hack to keep working like the old displays
|
||||||
|
*/
|
||||||
|
TFTDisplay(uint8_t address, int sda, int scl);
|
||||||
|
|
||||||
|
// Write the buffer to the display memory
|
||||||
|
virtual void display(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// the header size of the buffer used, e.g. for the SPI command header
|
||||||
|
virtual int getBufferOffset(void) { return 0; }
|
||||||
|
|
||||||
|
// Send a command to the display (low level function)
|
||||||
|
virtual void sendCommand(uint8_t com);
|
||||||
|
|
||||||
|
// Connect to the display
|
||||||
|
virtual bool connect();
|
||||||
|
};
|
||||||
|
@ -221,8 +221,12 @@ void setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize the screen first so we can show the logo while we start up everything else.
|
// Initialize the screen first so we can show the logo while we start up everything else.
|
||||||
|
#ifdef ST7735_CS
|
||||||
|
screen.setup();
|
||||||
|
#else
|
||||||
if (ssd1306_found)
|
if (ssd1306_found)
|
||||||
screen.setup();
|
screen.setup();
|
||||||
|
#endif
|
||||||
|
|
||||||
screen.print("Started...\n");
|
screen.print("Started...\n");
|
||||||
|
|
||||||
|
@ -99,9 +99,4 @@ void nrf52Setup()
|
|||||||
// randomSeed(r);
|
// randomSeed(r);
|
||||||
DEBUG_MSG("FIXME, call randomSeed\n");
|
DEBUG_MSG("FIXME, call randomSeed\n");
|
||||||
// ::printf("TESTING PRINTF\n");
|
// ::printf("TESTING PRINTF\n");
|
||||||
|
|
||||||
// Setup TFT display - FIXME do somewhere else
|
|
||||||
#ifdef ST7735_CS
|
|
||||||
TFTinit();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user