1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 21:21:24 +01:00

Reduce RAM and flash requirement a few more bytes.

This commit is contained in:
Neil McKechnie 2021-02-19 12:43:24 +00:00
parent a965bed82e
commit fd05d062e7
2 changed files with 22 additions and 86 deletions

View File

@ -1,7 +1,5 @@
/* Arduino SSD1306Ascii Library
* Copyright (C) 2015 by William Greiman
*
* This file is part of the Arduino SSD1306Ascii Library
/* Based on Arduino SSD1306Ascii Library, Copyright (C) 2015 by William Greiman
* Modifications (C) 2021 Neil McKechnie
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,10 +27,8 @@ void SSD1306Ascii::clear(uint8_t c0, uint8_t c1, uint8_t r0, uint8_t r1) {
for (uint8_t r = r0; r <= r1; r++) {
setCursor(c0, r);
for (uint8_t c = c0; c <= c1; c++) {
// Ensure clear() writes zero. result is (m_invertMask^m_invertMask).
ssd1306WriteRamBuf(m_invertMask);
}
for (uint8_t c = c0; c <= c1; c++)
ssd1306WriteRamBuf(0);
}
setCursor(c0, r0);
}
@ -76,11 +72,6 @@ void SSD1306Ascii::setCursor(uint8_t col, uint8_t row) {
//------------------------------------------------------------------------------
void SSD1306Ascii::setFont(const uint8_t* font) {
m_font = font;
m_letterSpacing = 1;
m_fontFirstChar = readFontByte(m_font + FONT_FIRST_CHAR);
m_fontCharCount = readFontByte(m_font + FONT_CHAR_COUNT);
m_fontHeight = readFontByte(m_font + FONT_HEIGHT);
m_fontWidth = readFontByte(m_font + FONT_WIDTH);
}
//------------------------------------------------------------------------------
void SSD1306Ascii::setRow(uint8_t row) {
@ -92,14 +83,14 @@ void SSD1306Ascii::setRow(uint8_t row) {
//------------------------------------------------------------------------------
void SSD1306Ascii::ssd1306WriteRam(uint8_t c) {
if (m_col < m_displayWidth) {
writeDisplay(c^m_invertMask, SSD1306_MODE_RAM);
writeDisplay(c, SSD1306_MODE_RAM);
m_col++;
}
}
//------------------------------------------------------------------------------
void SSD1306Ascii::ssd1306WriteRamBuf(uint8_t c) {
if (m_col < m_displayWidth) {
writeDisplay(c^m_invertMask, SSD1306_MODE_RAM_BUF);
writeDisplay(c, SSD1306_MODE_RAM_BUF);
m_col++;
}
}
@ -108,30 +99,21 @@ size_t SSD1306Ascii::write(uint8_t ch) {
if (!m_font) {
return 0;
}
uint8_t w = readFontByte(m_font + FONT_WIDTH);
uint8_t h = readFontByte(m_font + FONT_HEIGHT);
uint8_t nr = (h + 7)/8;
uint8_t first = readFontByte(m_font + FONT_FIRST_CHAR);
uint8_t count = readFontByte(m_font + FONT_CHAR_COUNT);
const uint8_t* base = m_font + FONT_WIDTH_TABLE;
const uint8_t letterSpacing = 1;
uint8_t fontFirstChar = readFontByte(m_font + FONT_FIRST_CHAR);
uint8_t fontCharCount = readFontByte(m_font + FONT_CHAR_COUNT);
uint8_t fontWidth = readFontByte(m_font + FONT_WIDTH);
if (ch < first || ch >= (first + count)) return 0;
ch -= first;
uint8_t s = letterSpacing();
// Fixed width font.
base += nr*w*ch;
uint8_t scol = m_col;
for (uint8_t r = 0; r < nr; r++) {
if (r) {
setCursor(scol, m_row + 1);
}
for (uint8_t c = 0; c < w; c++) {
uint8_t b = readFontByte(base + c + r*w);
ssd1306WriteRamBuf(b);
}
for (uint8_t i = 0; i < s; i++) {
ssd1306WriteRamBuf(0);
}
if (ch < fontFirstChar || ch >= (fontFirstChar + fontCharCount)) return 0;
ch -= fontFirstChar;
base += fontWidth * ch;
for (uint8_t c = 0; c < fontWidth; c++) {
uint8_t b = readFontByte(base + c);
ssd1306WriteRamBuf(b);
}
for (uint8_t i = 0; i < letterSpacing; i++) {
ssd1306WriteRamBuf(0);
}
flushDisplay();
return 1;

View File

@ -1,7 +1,5 @@
/* Arduino SSD1306Ascii Library
* Copyright (C) 2015 by William Greiman
*
* This file is part of the Arduino SSD1306Ascii Library
/* Based on Arduino SSD1306Ascii Library, Copyright (C) 2015 by William Greiman
* Modifications (C) 2021 Neil McKechnie
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,7 +25,7 @@
#include "SSD1306init.h"
#include "fonts/allFonts.h"
//------------------------------------------------------------------------------
/** SSD1306Ascii version */
/** SSD1306Ascii version basis */
#define SDD1306_ASCII_VERSION 1.3.0
//------------------------------------------------------------------------------
// Configuration options.
@ -124,22 +122,6 @@ class SSD1306Ascii : public Print {
* @return The display width in pixels.
*/
inline uint8_t displayWidth() const {return m_displayWidth;}
/**
* @return The current font pointer.
*/
const uint8_t* font() const {return m_font;}
/**
* @return The count of characters in a font.
*/
inline uint8_t fontCharCount() const {return m_fontCharCount;};
/**
* @return The first character in a font.
*/
inline char fontFirstChar() const {return m_fontFirstChar;};
/**
* @return The current font height in pixels.
*/
inline uint8_t fontHeight() const {return m_fontHeight;};
/**
* @brief Set the cursor position to (0, 0).
*/
@ -150,26 +132,6 @@ class SSD1306Ascii : public Print {
* @param[in] dev A display initialization structure.
*/
void init(const DevType* dev);
/**
* @brief Set pixel mode for for entire display.
*
* @param[in] invert Inverted display if true or normal display if false.
*/
void invertDisplay(bool invert);
/**
* @return invert mode.
*/
inline bool invertMode() const {return !!m_invertMask;}
/**
* @brief Set invert mode for write/print.
*
* @param[in] mode Invert pixels if true and use normal mode if false.
*/
inline void setInvertMode(bool mode) {m_invertMask = mode ? 0XFF : 0;}
/**
* @return letter-spacing in pixels with magnification factor.
*/
inline uint8_t letterSpacing() const {return m_letterSpacing;}
/**
* @return the current row number with eight pixels to a row.
*/
@ -245,14 +207,6 @@ class SSD1306Ascii : public Print {
uint8_t m_displayWidth; // Display width.
uint8_t m_displayHeight; // Display height.
uint8_t m_colOffset; // Column offset RAM to SEG.
uint8_t m_letterSpacing; // Letter-spacing in pixels.
const uint8_t* m_font = nullptr; // Current font.
uint8_t m_invertMask = 0; // font invert mask
char m_fontFirstChar;
uint8_t m_fontCharCount;
uint8_t m_fontHeight;
uint8_t m_fontWidth;
};
#endif // SSD1306Ascii_h