-Added typedef dfunc_t for user display function

-Added void display_d(dfunc_t dfunc) which is a variant of the display() that calls a user function after each row
-changed private data to protected to more easily derive and modify.
This commit is contained in:
b.moniey
2021-10-01 21:54:11 -07:00
parent 35ad5448ed
commit 0de2f56f0a
2 changed files with 72 additions and 1 deletions
+68
View File
@@ -56,6 +56,8 @@
// SOME DEFINES AND STATIC VARIABLES USED INTERNALLY -----------------------
typedef void (* dfunc_t)(void);//void function pointer
#if defined(I2C_BUFFER_LENGTH)
#define WIRE_MAX min(256, I2C_BUFFER_LENGTH) ///< Particle or similar Wire lib
#elif defined(BUFFER_LENGTH)
@@ -113,6 +115,7 @@
// so other I2C device types still work). All of these are encapsulated
// in the TRANSACTION_* macros.
// Check first if Wire, then hardware SPI, then soft SPI:
#define TRANSACTION_START \
if (wire) { \
@@ -970,6 +973,71 @@ void Adafruit_SSD1306::display(void) {
#endif
}
/*!
@brief display with added call to user function pointer
@param dfunc pointer to users display function
@return None (void).
*/
void Adafruit_SSD1306::display_d(dfunc_t dfunc){
TRANSACTION_START
static const uint8_t PROGMEM dlist1[] = {
SSD1306_PAGEADDR,
0, // Page start address
0xFF, // Page end (not really, but works here)
SSD1306_COLUMNADDR, 0}; // Column start address
ssd1306_commandList(dlist1, sizeof(dlist1));
ssd1306_command1(WIDTH - 1); // Column end address
#if defined(ESP8266)
// ESP8266 needs a periodic yield() call to avoid watchdog reset.
// With the limited size of SSD1306 displays, and the fast bitrate
// being used (1 MHz or more), I think one yield() immediately before
// a screen write and one immediately after should cover it. But if
// not, if this becomes a problem, yields() might be added in the
// 32-byte transfer condition below.
yield();
#endif
uint16_t count = WIDTH * ((HEIGHT + 7) / 8);
uint8_t *ptr = buffer;
if (wire) { // I2C
wire->beginTransmission(i2caddr);
WIRE_WRITE((uint8_t)0x40);
uint16_t bytesOut = 1;
while (count--) {
if (bytesOut >= WIRE_MAX) {
wire->endTransmission();
wire->beginTransmission(i2caddr);
WIRE_WRITE((uint8_t)0x40);
bytesOut = 1;
}
WIRE_WRITE(*ptr++);
bytesOut++;
//every line give the dfunc a chance to run
if(dfunc !=NULL){
if(!(count % WIDTH)){
wire->endTransmission();
TRANSACTION_END
dfunc();
TRANSACTION_START
wire->beginTransmission(i2caddr);
WIRE_WRITE((uint8_t)0x40);
bytesOut = 1;
}
}
}
wire->endTransmission();
} else { // SPI
SSD1306_MODE_DATA
while (count--)
SPIwrite(*ptr++);
}
TRANSACTION_END
#if defined(ESP8266)
yield();
#endif
}
// SCROLLING FUNCTIONS -----------------------------------------------------
/*!
+4 -1
View File
@@ -40,6 +40,8 @@ typedef class HardwareSPI SPIClass;
#include <SPI.h>
#include <Wire.h>
typedef void (* dfunc_t)(void);
#if defined(__AVR__)
typedef volatile uint8_t PortReg;
typedef uint8_t PortMask;
@@ -145,6 +147,7 @@ public:
bool begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = 0,
bool reset = true, bool periphBegin = true);
void display(void);
void display_d(dfunc_t dfunc);
void clearDisplay(void);
void invertDisplay(bool i);
void dim(bool dim);
@@ -160,7 +163,7 @@ public:
bool getPixel(int16_t x, int16_t y);
uint8_t *getBuffer(void);
private:
protected:
inline void SPIwrite(uint8_t d) __attribute__((always_inline));
void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color);
void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color);