diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-05-27 17:50:49 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-05-27 17:50:49 +0300 |
commit | 8a8d675ade52b4b524b6c26713a6d61ea7ec4861 (patch) | |
tree | 552aa59eb6e2fe852d78fd8669856cc144cfdaac | |
parent | 60536aa33e5965bba25ce130281e7761fa96e1a8 (diff) |
Added support for font chip on TFT display
-rw-r--r-- | src/Config/Pins.h | 4 | ||||
-rw-r--r-- | src/Config/Pins_FMDC.h | 5 | ||||
-rw-r--r-- | src/Display/Display.cpp | 14 | ||||
-rw-r--r-- | src/Display/Lcd/Fonts/ER3301_1.cpp | 199 | ||||
-rw-r--r-- | src/Display/Lcd/Fonts/ER3301_1.h | 62 | ||||
-rw-r--r-- | src/Display/Lcd/ILI9488/ILI9488.cpp | 5 | ||||
-rw-r--r-- | src/Display/Lcd/ILI9488/ILI9488.h | 6 | ||||
-rw-r--r-- | src/Display/Lcd/Lcd.cpp | 75 | ||||
-rw-r--r-- | src/Display/Lcd/Lcd.h | 23 | ||||
-rw-r--r-- | src/Display/Lcd/TFTLcd.cpp | 5 | ||||
-rw-r--r-- | src/Display/Lcd/TFTLcd.h | 5 |
11 files changed, 381 insertions, 22 deletions
diff --git a/src/Config/Pins.h b/src/Config/Pins.h index 3ef1c5e7..e2500106 100644 --- a/src/Config/Pins.h +++ b/src/Config/Pins.h @@ -72,6 +72,10 @@ # define SUPPORT_ILI9488_LCD 0 #endif +#ifndef USE_FONT_CHIP +# define USE_FONT_CHIP 0 +#endif + #define SUPPORT_DIRECT_LCD (SUPPORT_12864_LCD || SUPPORT_ILI9488_LCD) #define SUPPORT_ROTARY_ENCODER SUPPORT_12864_LCD #define SUPPORT_RESISTIVE_TOUCH SUPPORT_ILI9488_LCD diff --git a/src/Config/Pins_FMDC.h b/src/Config/Pins_FMDC.h index 8e3baa69..40895d7a 100644 --- a/src/Config/Pins_FMDC.h +++ b/src/Config/Pins_FMDC.h @@ -52,6 +52,7 @@ constexpr uint32_t IAP_IMAGE_START = 0x20028000; #define SUPPORT_WORKPLACE_COORDINATES 1 // set nonzero to support G10 L2 and G53..59 #define SUPPORT_12864_LCD 0 // set nonzero to support 12864 LCD and rotary encoder #define SUPPORT_ILI9488_LCD 1 +#define USE_FONT_CHIP 1 #define SUPPORT_ACCELEROMETERS 1 #define SUPPORT_OBJECT_MODEL 1 #define SUPPORT_FTP 0 @@ -242,9 +243,11 @@ constexpr Pin LcdResetPin = PortCPin(6); #if defined(FMDC_V03) constexpr Pin LcdFlashCsPin = PortAPin(20); constexpr Pin LcdBacklightPin = PortBPin(16); +constexpr Pin LcdFontCsPin = PortBPin(20); #elif defined(FMDC_V02) constexpr Pin LcdFlashCsPin = PortBPin(10); constexpr Pin LcdBacklightPin = PortBPin(12); +constexpr Pin LcdFontCsPin = PortBPin(15); #endif constexpr Pin LcdFlashWpPin = PortAPin(2); @@ -403,7 +406,7 @@ constexpr PinDescription PinTable[] = #elif defined(FMDC_V02) { TcOutput::none, TccOutput::none, AdcInput::none, SercomIo::none, SercomIo::none, Nx, PinCapability::none, nullptr }, // PB18 SDHC DAT0 { TcOutput::none, TccOutput::none, AdcInput::none, SercomIo::none, SercomIo::none, Nx, PinCapability::none, nullptr }, // PB19 SDHC DAT1 - { TcOutput::none, TccOutput::none, AdcInput::none, SercomIo::none, SercomIo::none, Nx, PinCapability::none, nullptr }, // PB20 SDHC DAT2 + { TcOutput::none, TccOutput::none, AdcInput::none, SercomIo::none, SercomIo::none, Nx, PinCapability::none, "ate.lcd.fontcs" }, // PB20 SDHC DAT2 { TcOutput::none, TccOutput::none, AdcInput::none, SercomIo::none, SercomIo::none, Nx, PinCapability::none, nullptr }, // PB21 SDHC DAT3 #endif { TcOutput::none, TccOutput::none, AdcInput::none, SercomIo::none, SercomIo::none, Nx, PinCapability::none, nullptr }, // PB22 crystal XIN1 diff --git a/src/Display/Display.cpp b/src/Display/Display.cpp index a114921a..1cf2c256 100644 --- a/src/Display/Display.cpp +++ b/src/Display/Display.cpp @@ -34,12 +34,17 @@ constexpr size_t LargeFontNumber = 1; #endif #if SUPPORT_ILI9488_LCD +# if USE_FONT_CHIP +constexpr size_t SmallFontNumber = 0; +constexpr size_t LargeFontNumber = 1; +# else // The FMDC prototypes don't have enough flash memory for more than one font //extern const LcdFont font19x21; extern const LcdFont font28x32; const LcdFont * const tftFonts[] = { /*&font19x21 ,*/ &font28x32 }; constexpr size_t SmallFontNumber = 0; constexpr size_t LargeFontNumber = 0; +# endif #endif constexpr uint32_t NormalRefreshMillis = 250; @@ -254,7 +259,14 @@ GCodeResult Display::Configure(GCodeBuffer& gb, const StringRef& reply) THROWS(G SetPinFunction(LcdSpiMosiPin, LcdSpiPinFunction); SetPinFunction(LcdSpiMisoPin, LcdSpiPinFunction); SetPinFunction(LcdSpiSclkPin, LcdSpiPinFunction); - InitDisplay(gb, new LcdILI9488(tftFonts, ARRAY_SIZE(tftFonts), LcdSercomNumber), LcdSpiCsPin, NoPin, false); + pinMode(LcdFlashCsPin, OUTPUT_HIGH); // in case the flash chip is fitted, deselect it + InitDisplay(gb, +# if USE_FONT_CHIP + new LcdILI9488(LcdFontCsPin, LcdSercomNumber), +# else + new LcdILI9488(tftFonts, ARRAY_SIZE(tftFonts), LcdSercomNumber), +# endif + LcdSpiCsPin, NoPin, false); touchController = new ResistiveTouch(RtpSpiCsPin, RtpPenPin); touchController->Init(lcd->GetNumCols(), lcd->GetNumRows(), DisplayOrientation::ReverseY); break; diff --git a/src/Display/Lcd/Fonts/ER3301_1.cpp b/src/Display/Lcd/Fonts/ER3301_1.cpp new file mode 100644 index 00000000..d3296294 --- /dev/null +++ b/src/Display/Lcd/Fonts/ER3301_1.cpp @@ -0,0 +1,199 @@ +/* + * ER3301_1.cpp + * + * Created on: 27 May 2022 + * Author: David + * + * Support for ER3303-1 font chip included on some variants of the ER-TFTM035-6 display + */ + +#include "ER3301_1.h" + +#if USE_FONT_CHIP + +#include <Hardware/Spi/SharedSpiDevice.h> + +// This font chip contains several fonts. We are only interested in the 12-dot and 16 dot high Unicode Latin/Greek Cyrillic and Arabic fonts. +// We number those as fonts 0 and 1. Fonts 2 and 3 are the same ones expanded to double size. + +struct FontTableEntry +{ + uint16_t startCharacter; + uint16_t endCharacter; + uint32_t startAddress; +}; + +struct FontDescriptor +{ + const FontTableEntry *tableStart; + const FontTableEntry *tableEnd; + uint16_t height; + uint16_t spaceWidth; + unsigned int bytesPerCharacter; +}; + +static constexpr FontTableEntry Font12[] = +{ + { 0x0020, 0x007F, 0x19AD22 }, // Latin + { 0x00A0, 0x017F, 0x19AD22 + 96 * 26}, // Latin + { 0x0384, 0x03CE, 0x19AD22 + 350 * 26 }, // Greek + { 0x0400, 0x045F, 0x19AD22 + 425 * 26 }, // Cyrillic + { 0x0490, 0x04A3, 0x19AD22 + (425 + 96) * 26 }, // Cyrillic + { 0x04AE, 0x04B3, 0x19AD22 + (425 + 117) * 26 }, // Cyrillic + { 0x04B8, 0x04BB, 0x19AD22 + (425 + 122) * 26 }, // Cyrillic + { 0x04D8, 0x04D9, 0x19AD22 + (425 + 126) * 26 }, // Cyrillic + { 0x04E8, 0x04E9, 0x19AD22 + (425 + 128) * 26 }, // Cyrillic + { 0x0600, 0x06F9, 0x1AA0E6 } // Arabic +}; + +static constexpr FontTableEntry Font16[] = +{ + { 0x0020, 0x007F, 0x19E580 }, // Latin + { 0x00A0, 0x017F, 0x19E580 + 96 * 34}, // Latin + { 0x0384, 0x03CE, 0x19E580 + 350 * 34 }, // Greek + { 0x0400, 0x045F, 0x19E580 + 425 * 34 }, // Cyrillic + { 0x0490, 0x04A3, 0x19E580 + (425 + 96) * 34 }, // Cyrillic + { 0x04AE, 0x04B3, 0x19E580 + (425 + 117) * 34 }, // Cyrillic + { 0x04B8, 0x04BB, 0x19E580 + (425 + 122) * 34 }, // Cyrillic + { 0x04D8, 0x04D9, 0x19E580 + (425 + 126) * 34 }, // Cyrillic + { 0x04E8, 0x04E9, 0x19E580 + (425 + 128) * 34 }, // Cyrillic + { 0x0600, 0x06F9, 0x1A2F36 } // Arabic +}; + +static constexpr FontDescriptor Fonts[] = +{ + { Font12, Font12 + ARRAY_SIZE(Font12), 12, 1, 26 }, + { Font16, Font16 + ARRAY_SIZE(Font16), 16, 1, 34 }, +}; + +constexpr bool FontSizeOK(const FontDescriptor *descriptor, size_t numFonts) noexcept +{ + return descriptor->bytesPerCharacter <= ER3301_1::MaxBytesPerCharacter && (numFonts == 1 || FontSizeOK(descriptor + 1, numFonts - 1)); +} + +static_assert(FontSizeOK(Fonts, ARRAY_SIZE(Fonts))); + +// Search for a character in the font table, returning its address of found, 0 if not found +static uint32_t LookupCharacter(uint16_t codePoint, const FontDescriptor& font) noexcept +{ + const FontTableEntry *table = font.tableStart; + do + { + if (codePoint <= table->endCharacter) + { + if (codePoint >= table->startCharacter) + { + return table->startAddress + ((codePoint - table->startCharacter) * font.bytesPerCharacter); + } + break; + } + ++table; + } while (table != font.tableEnd); + return 0; +} + +ER3301_1::ER3301_1(Pin csPin) noexcept + : spiClient(SharedSpiDevice::GetMainSharedSpiDevice(), SpiFrequency, SpiMode::mode0, csPin, false), currentAddress(0) +{ +} + +// Return the count of available fonts +unsigned int ER3301_1::GetNumFonts() const noexcept +{ + return 2 * ARRAY_SIZE(Fonts); +} + +// Return the height of the specified font +uint16_t ER3301_1::GetFontHeight(unsigned int fontNumber) const noexcept +{ + const uint16_t nativeFontHeight = Fonts[fontNumber % ARRAY_SIZE(Fonts)].height; + return (fontNumber >= ARRAY_SIZE(Fonts)) ? 2 * nativeFontHeight : nativeFontHeight; +} + +// Get the inter-character spacing in the specified font +uint16_t ER3301_1::GetSpacing(unsigned int fontNumber) const noexcept +{ + const uint16_t nativeSpacing = Fonts[fontNumber % ARRAY_SIZE(Fonts)].spaceWidth; + return (fontNumber >= ARRAY_SIZE(Fonts)) ? 2 * nativeSpacing : nativeSpacing; +} + +// Fetch the data for the next column and advance the column counter +uint32_t ER3301_1::GetColumnData(uint16_t column) noexcept +{ + uint32_t ret = 0; + if (doubleSize) + { + for (unsigned int row = 0; row < nativeHeight; ++row) + { + const uint16_t data = __builtin_bswap16(charBuffer.data[row]); + if ((data << ((column >> 1) + columnOffset)) & 0x8000) // if pixel is set + { + ret |= 3u << (row << 1); + } + } + } + else + { + for (unsigned int row = 0; row < nativeHeight; ++row) + { + const uint16_t data = __builtin_bswap16(charBuffer.data[row]); + if ((data << (column + columnOffset)) & 0x8000) // if pixel is set + { + ret |= 1u << row; + } + } + } + return ret; +} + +// Fetch the specified character into the buffer, set nextColumn to zero and return its width +uint16_t ER3301_1::GetCharacter(unsigned int fontNumber, uint16_t codePoint) noexcept +{ + uint32_t addr = LookupCharacter(codePoint, Fonts[fontNumber % ARRAY_SIZE(Fonts)]); + if (addr == 0) + { + addr = LookupCharacter(0x007F, Fonts[fontNumber % ARRAY_SIZE(Fonts)]); + if (addr == 0) + { + return 0; + } + } + if (addr != currentAddress) + { + // Fetch the character from the font chip + spiClient.Select(); + charBuffer.cmd = 0x03; + charBuffer.addr[0] = (uint8_t)(addr >> 16); + charBuffer.addr[1] = (uint8_t)(addr >> 8); + charBuffer.addr[2] = (uint8_t)addr; + spiClient.TransceivePacket((const uint8_t *)&charBuffer, (uint8_t *)&charBuffer, 4 + Fonts[fontNumber % ARRAY_SIZE(Fonts)].bytesPerCharacter); + spiClient.Deselect(); + + currentAddress = addr; + nativeHeight = Fonts[fontNumber % ARRAY_SIZE(Fonts)].height; // this is the native height + nativeWidth = __builtin_bswap16(charBuffer.width); + + // Check whether there is a leading blank column that we need to remove + uint16_t pixels = 0; + for (unsigned int row = 0; row < nativeHeight; ++row) + { + pixels |= charBuffer.data[row]; + } + if ((pixels & 0x0080) != 0 && nativeWidth != 0) // use 0x0080 instead of 0x8000 because we didn't swap the bytes + { + columnOffset = 0; + } + else + { + // Remove the leading space column + --nativeWidth; + columnOffset = 1; + } + } + doubleSize = (fontNumber >= ARRAY_SIZE(Fonts)); + return (doubleSize) ? 2 * nativeWidth : nativeWidth; +} + +#endif + +// End diff --git a/src/Display/Lcd/Fonts/ER3301_1.h b/src/Display/Lcd/Fonts/ER3301_1.h new file mode 100644 index 00000000..ee999aa9 --- /dev/null +++ b/src/Display/Lcd/Fonts/ER3301_1.h @@ -0,0 +1,62 @@ +/* + * ER3301_1.h + * + * Created on: 27 May 2022 + * Author: David + */ + +#ifndef SRC_DISPLAY_LCD_FONTS_ER3301_1_H_ +#define SRC_DISPLAY_LCD_FONTS_ER3301_1_H_ + +#include <RepRapFirmware.h> + +#if USE_FONT_CHIP + +#include <Hardware/Spi/SharedSpiClient.h> + +class ER3301_1 +{ +public: + ER3301_1(Pin csPin) noexcept; + + // Return the count of available fonts + unsigned int GetNumFonts() const noexcept; + + // Return the height of the specified font + uint16_t GetFontHeight(unsigned int fontNumber) const noexcept; + + // Get the inter-character spacing in the specified font + uint16_t GetSpacing(unsigned int fontNumber) const noexcept; + + // Fetch the specified character into the buffer and return its width + uint16_t GetCharacter(unsigned int fontNumber, uint16_t codePoint) noexcept; + + // Fetch the data for the next column and advance the column counter + uint32_t GetColumnData(uint16_t column) noexcept; + + static constexpr size_t MaxBytesPerCharacter = 34; + +private: + static constexpr uint32_t SpiFrequency = 4000000; // the SPI frequency we use (max supported is 20MHz in Read mode, 30MHz in FastRead mode) + + SharedSpiClient spiClient; + uint32_t currentAddress; // the address for which we have a character in the buffer + uint16_t nativeHeight; // the native height of the character in the buffer + uint16_t nativeWidth; // the width of the character in the buffer, after removing a leading space if we need to + uint16_t columnOffset; // the number of words of leading spaces we need to skip (we need to manage spaces ourselves to do auto kerning) + bool doubleSize; // true if the current font scales the size by two + + struct CharData + { + uint8_t cmd; // space for the Read command + uint8_t addr[3]; // the 3-byte address we want, MSB first + uint16_t width; // the width of the character + uint16_t data[MaxBytesPerCharacter/2 - 1]; // the character data, one word per row + }; + + CharData charBuffer; // buffer to hold the SPI command and the fetched font data +}; + +#endif + +#endif /* SRC_DISPLAY_LCD_FONTS_ER3301_1_H_ */ diff --git a/src/Display/Lcd/ILI9488/ILI9488.cpp b/src/Display/Lcd/ILI9488/ILI9488.cpp index 016c6ed5..7fe8b8e1 100644 --- a/src/Display/Lcd/ILI9488/ILI9488.cpp +++ b/src/Display/Lcd/ILI9488/ILI9488.cpp @@ -12,8 +12,13 @@ constexpr PwmFrequency BacklightPwmFrequency = 1000; +#if USE_FONT_CHIP +LcdILI9488::LcdILI9488(Pin fontCsPin, uint8_t sercomNum) noexcept + : TFTLcd(320, 480, fontCsPin, SpiMode::mode0, sercomNum) +#else LcdILI9488::LcdILI9488(const LcdFont * const fnts[], size_t nFonts, uint8_t sercomNum) noexcept : TFTLcd(320, 480, fnts, nFonts, SpiMode::mode0, sercomNum) +#endif { } diff --git a/src/Display/Lcd/ILI9488/ILI9488.h b/src/Display/Lcd/ILI9488/ILI9488.h index 9b57ee6b..d5d37d42 100644 --- a/src/Display/Lcd/ILI9488/ILI9488.h +++ b/src/Display/Lcd/ILI9488/ILI9488.h @@ -15,8 +15,12 @@ class LcdILI9488 : public TFTLcd { public: - // Construct a GLCD driver. + // Construct a GLCD driver +#if USE_FONT_CHIP + LcdILI9488(Pin fontCsPin, uint8_t sercomNum) noexcept; +#else LcdILI9488(const LcdFont * const fnts[], size_t nFonts, uint8_t sercomNum) noexcept; +#endif ~LcdILI9488(); diff --git a/src/Display/Lcd/Lcd.cpp b/src/Display/Lcd/Lcd.cpp index f67f7c33..6eab8398 100644 --- a/src/Display/Lcd/Lcd.cpp +++ b/src/Display/Lcd/Lcd.cpp @@ -5,8 +5,14 @@ #if SUPPORT_DIRECT_LCD +#if USE_FONT_CHIP +Lcd::Lcd(PixelNumber nr, PixelNumber nc, Pin fontCsPin) noexcept + : fontChip(fontCsPin), +#else Lcd::Lcd(PixelNumber nr, PixelNumber nc, const LcdFont * const fnts[], size_t nFonts) noexcept - : numRows(nr), numCols(nc), fonts(fnts), numFonts(nFonts), + : fonts(fnts), numFonts(nFonts), +#endif + numRows(nr), numCols(nc), currentFontNumber(0), textInverted(false), numContinuationBytesLeft(0) { } @@ -15,9 +21,19 @@ Lcd::~Lcd() { } +// Return the number of fonts +size_t Lcd::GetNumFonts() const noexcept +{ +#if USE_FONT_CHIP + return fontChip.GetNumFonts(); +#else + return numFonts; +#endif +} + void Lcd::SetFont(size_t newFont) noexcept { - if (newFont < numFonts) + if (newFont < GetNumFonts()) { currentFontNumber = newFont; } @@ -26,17 +42,25 @@ void Lcd::SetFont(size_t newFont) noexcept // Get the current font height PixelNumber Lcd::GetFontHeight() const noexcept { +#if USE_FONT_CHIP + return fontChip.GetFontHeight(currentFontNumber); +#else return fonts[currentFontNumber]->height; +#endif } // Get the height of a specified font PixelNumber Lcd::GetFontHeight(size_t fontNumber) const noexcept { - if (fontNumber >= numFonts) + if (fontNumber >= GetNumFonts()) { fontNumber = currentFontNumber; } +#if USE_FONT_CHIP + return fontChip.GetFontHeight(fontNumber); +#else return fonts[fontNumber]->height; +#endif } // Write a UTF8 byte. @@ -107,15 +131,19 @@ size_t Lcd::write(uint8_t c) noexcept size_t Lcd::writeNative(uint16_t ch) noexcept { - const LcdFont * const currentFont = fonts[currentFontNumber]; if (ch == '\n') { - SetCursor(row + currentFont->height + 1, leftMargin); + SetCursor(row + GetFontHeight() + 1, leftMargin); } else { if (column < rightMargin) // keep column <= rightMargin in the following code { +#if USE_FONT_CHIP + PixelNumber numFontColumns = fontChip.GetCharacter(currentFontNumber, ch); + const PixelNumber fontHeight = GetFontHeight(); +#else + const LcdFont * const currentFont = fonts[currentFontNumber]; const uint16_t startChar = currentFont->startCharacter; const uint16_t endChar = currentFont->endCharacter; @@ -128,22 +156,37 @@ size_t Lcd::writeNative(uint16_t ch) noexcept const PixelNumber fontBytesPerColumn = (fontHeight + 7)/8; const PixelNumber fontBytesPerChar = (fontBytesPerColumn * currentFont->width) + 1; const uint8_t *fontPtr = currentFont->ptr + (fontBytesPerChar * (ch - startChar)); - const uint32_t cmask = (currentFont->height < 32) ? (1u << currentFont->height) - 1 : 0xFFFFFFFF; - PixelNumber numFontColumns = *fontPtr++; +#endif + const uint32_t cmask = (fontHeight < 32) ? (1u << fontHeight) - 1 : 0xFFFFFFFF; PixelNumber columnsLeft = rightMargin - column; PixelNumber numSpaces; if (lastCharColData != 0) // if we have written anything other than spaces { - numSpaces = currentFont->numSpaces; - // Decide whether to add space columns first, and whether to add one less then usual (auto-kerning) - uint32_t thisCharColData = *reinterpret_cast<const uint32_t*>(fontPtr) & cmask; + uint32_t thisCharColData = +#if USE_FONT_CHIP + fontChip.GetColumnData(0); +#else + *reinterpret_cast<const uint32_t*>(fontPtr) & cmask; +#endif if (thisCharColData == 0) // for characters with deliberate space column at the start, e.g. decimal point { - thisCharColData = *reinterpret_cast<const uint32_t*>(fontPtr + fontBytesPerChar) & cmask; + thisCharColData = +#if USE_FONT_CHIP + fontChip.GetColumnData(1); +#else + *reinterpret_cast<const uint32_t*>(fontPtr + fontBytesPerChar) & cmask; +#endif } + numSpaces = +#if USE_FONT_CHIP + fontChip.GetSpacing(currentFontNumber); +#else + currentFont->numSpaces; +#endif + const bool kern = (numSpaces >= 2) ? ((thisCharColData & lastCharColData) == 0) : (((thisCharColData | (thisCharColData << 1)) & (lastCharColData | (lastCharColData << 1))) == 0); @@ -184,10 +227,14 @@ size_t Lcd::writeNative(uint16_t ch) noexcept } column += numSpaces; - while (numFontColumns != 0) + for (PixelNumber charColumn = 0; charColumn < numFontColumns; ++charColumn) { +#if USE_FONT_CHIP + const uint32_t colData = fontChip.GetColumnData(charColumn); +#else const uint32_t colData = *reinterpret_cast<const uint32_t*>(fontPtr); fontPtr += fontBytesPerColumn; +#endif if ((colData & cmask) != 0) { lastCharColData = colData & cmask; @@ -196,7 +243,6 @@ size_t Lcd::writeNative(uint16_t ch) noexcept { WriteColumnData(ySize, colData); } - --numFontColumns; ++column; } if (ySize != 0) @@ -224,8 +270,7 @@ void Lcd::Clear(PixelNumber top, PixelNumber left, PixelNumber bottom, PixelNumb // Write some spaces void Lcd::WriteSpaces(PixelNumber numPixels) noexcept { - const LcdFont * const currentFont = fonts[currentFontNumber]; - uint8_t ySize = currentFont->height; + uint8_t ySize = GetFontHeight(); if (row < numRows) { if (row + ySize > numRows) diff --git a/src/Display/Lcd/Lcd.h b/src/Display/Lcd/Lcd.h index d93042ca..5aa5a5fd 100644 --- a/src/Display/Lcd/Lcd.h +++ b/src/Display/Lcd/Lcd.h @@ -6,10 +6,15 @@ #if SUPPORT_DIRECT_LCD #include <Print.h> -#include "Fonts/LcdFont.h" #include <Hardware/Spi/SharedSpiClient.h> #include <General/SafeVsnprintf.h> +#if USE_FONT_CHIP +# include "Fonts/ER3301_1.h" +#else +# include "Fonts/LcdFont.h" +#endif + typedef uint16_t PixelNumber; struct Colour @@ -38,7 +43,12 @@ class Lcd { public: // Construct a GLCD driver. +#if USE_FONT_CHIP + Lcd(PixelNumber nr, PixelNumber nc, Pin fontCsPin) noexcept; +#else Lcd(PixelNumber nr, PixelNumber nc, const LcdFont * const fnts[], size_t nFonts) noexcept; +#endif + virtual ~Lcd(); // Flush just some data, returning true if this needs to be called again @@ -109,7 +119,7 @@ public: void WriteSpaces(PixelNumber numPixels) noexcept; // Return the number of fonts - size_t GetNumFonts() const noexcept { return numFonts; } + size_t GetNumFonts() const noexcept; // Get the current font height PixelNumber GetFontHeight() const noexcept; @@ -171,12 +181,17 @@ protected: // Write a decoded character size_t writeNative(uint16_t c) noexcept; +#if USE_FONT_CHIP + ER3301_1 fontChip; +#else + const LcdFont * const *_ecv_array fonts; + const size_t numFonts; +#endif + const PixelNumber numRows, numCols; PixelNumber row, column; PixelNumber leftMargin, rightMargin; - const LcdFont * const *_ecv_array fonts; - const size_t numFonts; size_t currentFontNumber = 0; // index of the current font bool textInverted = false; diff --git a/src/Display/Lcd/TFTLcd.cpp b/src/Display/Lcd/TFTLcd.cpp index 087bfa66..e69ad830 100644 --- a/src/Display/Lcd/TFTLcd.cpp +++ b/src/Display/Lcd/TFTLcd.cpp @@ -9,8 +9,13 @@ #if SUPPORT_ILI9488_LCD +#if USE_FONT_CHIP +TFTLcd::TFTLcd(PixelNumber nr, PixelNumber nc, Pin fontCsPin, SpiMode mode, uint8_t sercomNum) noexcept + : Lcd(nr, nc, fontCsPin), +#else TFTLcd::TFTLcd(PixelNumber nr, PixelNumber nc, const LcdFont * const fnts[], size_t nFonts, SpiMode mode, uint8_t sercomNum) noexcept : Lcd(nr, nc, fnts, nFonts), +#endif spiDev(sercomNum), fgColour(Colours::White), bgColour(Colours::Blue), spiMode(mode) diff --git a/src/Display/Lcd/TFTLcd.h b/src/Display/Lcd/TFTLcd.h index 531f13a6..1b4e635d 100644 --- a/src/Display/Lcd/TFTLcd.h +++ b/src/Display/Lcd/TFTLcd.h @@ -17,7 +17,12 @@ class TFTLcd : public Lcd { public: +#if USE_FONT_CHIP + TFTLcd(PixelNumber nr, PixelNumber nc, Pin fontCsPin, SpiMode mode, uint8_t sercomNum) noexcept; +#else TFTLcd(PixelNumber nr, PixelNumber nc, const LcdFont * const fnts[], size_t nFonts, SpiMode mode, uint8_t sercomNum) noexcept; +#endif + virtual ~TFTLcd(); // Get the SPI frequency |