|
56 | 56 |
|
57 | 57 | // SOME DEFINES AND STATIC VARIABLES USED INTERNALLY -----------------------
|
58 | 58 |
|
| 59 | +typedef void (* dfunc_t)(void);//void function pointer |
| 60 | + |
59 | 61 | #if defined(I2C_BUFFER_LENGTH)
|
60 | 62 | #define WIRE_MAX min(256, I2C_BUFFER_LENGTH) ///< Particle or similar Wire lib
|
61 | 63 | #elif defined(BUFFER_LENGTH)
|
|
113 | 115 | // so other I2C device types still work). All of these are encapsulated
|
114 | 116 | // in the TRANSACTION_* macros.
|
115 | 117 |
|
| 118 | + |
116 | 119 | // Check first if Wire, then hardware SPI, then soft SPI:
|
117 | 120 | #define TRANSACTION_START \
|
118 | 121 | if (wire) { \
|
@@ -970,6 +973,71 @@ void Adafruit_SSD1306::display(void) {
|
970 | 973 | #endif
|
971 | 974 | }
|
972 | 975 |
|
| 976 | +/*! |
| 977 | + @brief display with added call to user function pointer |
| 978 | + @param dfunc pointer to users display function |
| 979 | + |
| 980 | + @return None (void). |
| 981 | +*/ |
| 982 | +void Adafruit_SSD1306::display_d(dfunc_t dfunc){ |
| 983 | + TRANSACTION_START |
| 984 | + static const uint8_t PROGMEM dlist1[] = { |
| 985 | + SSD1306_PAGEADDR, |
| 986 | + 0, // Page start address |
| 987 | + 0xFF, // Page end (not really, but works here) |
| 988 | + SSD1306_COLUMNADDR, 0}; // Column start address |
| 989 | + ssd1306_commandList(dlist1, sizeof(dlist1)); |
| 990 | + ssd1306_command1(WIDTH - 1); // Column end address |
| 991 | + |
| 992 | +#if defined(ESP8266) |
| 993 | + // ESP8266 needs a periodic yield() call to avoid watchdog reset. |
| 994 | + // With the limited size of SSD1306 displays, and the fast bitrate |
| 995 | + // being used (1 MHz or more), I think one yield() immediately before |
| 996 | + // a screen write and one immediately after should cover it. But if |
| 997 | + // not, if this becomes a problem, yields() might be added in the |
| 998 | + // 32-byte transfer condition below. |
| 999 | + yield(); |
| 1000 | +#endif |
| 1001 | + uint16_t count = WIDTH * ((HEIGHT + 7) / 8); |
| 1002 | + uint8_t *ptr = buffer; |
| 1003 | + if (wire) { // I2C |
| 1004 | + wire->beginTransmission(i2caddr); |
| 1005 | + WIRE_WRITE((uint8_t)0x40); |
| 1006 | + uint16_t bytesOut = 1; |
| 1007 | + while (count--) { |
| 1008 | + if (bytesOut >= WIRE_MAX) { |
| 1009 | + wire->endTransmission(); |
| 1010 | + wire->beginTransmission(i2caddr); |
| 1011 | + WIRE_WRITE((uint8_t)0x40); |
| 1012 | + bytesOut = 1; |
| 1013 | + } |
| 1014 | + WIRE_WRITE(*ptr++); |
| 1015 | + bytesOut++; |
| 1016 | + //every line give the dfunc a chance to run |
| 1017 | + if(dfunc !=NULL){ |
| 1018 | + if(!(count % WIDTH)){ |
| 1019 | + wire->endTransmission(); |
| 1020 | + TRANSACTION_END |
| 1021 | + dfunc(); |
| 1022 | + TRANSACTION_START |
| 1023 | + wire->beginTransmission(i2caddr); |
| 1024 | + WIRE_WRITE((uint8_t)0x40); |
| 1025 | + bytesOut = 1; |
| 1026 | + } |
| 1027 | + } |
| 1028 | + } |
| 1029 | + wire->endTransmission(); |
| 1030 | + } else { // SPI |
| 1031 | + SSD1306_MODE_DATA |
| 1032 | + while (count--) |
| 1033 | + SPIwrite(*ptr++); |
| 1034 | + } |
| 1035 | + TRANSACTION_END |
| 1036 | +#if defined(ESP8266) |
| 1037 | + yield(); |
| 1038 | +#endif |
| 1039 | +} |
| 1040 | + |
973 | 1041 | // SCROLLING FUNCTIONS -----------------------------------------------------
|
974 | 1042 |
|
975 | 1043 | /*!
|
|
0 commit comments