Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ezSBC_MPU9250 Test_OLED_Display untodoenuno OledI2CDisplay ... more
Fork of Adafruit_GFX by
Adafruit_SSD1306.cpp
00001 /********************************************************************* 00002 This is a library for our Monochrome OLEDs based on SSD1306 drivers 00003 00004 Pick one up today in the adafruit shop! 00005 ------> http://www.adafruit.com/category/63_98 00006 00007 These displays use SPI to communicate, 4 or 5 pins are required to 00008 interface 00009 00010 Adafruit invests time and resources providing this open source code, 00011 please support Adafruit and open-source hardware by purchasing 00012 products from Adafruit! 00013 00014 Written by Limor Fried/Ladyada for Adafruit Industries. 00015 BSD license, check license.txt for more information 00016 All text above, and the splash screen below must be included in any redistribution 00017 *********************************************************************/ 00018 00019 /* 00020 * Modified by Neal Horman 7/14/2012 for use in mbed 00021 * Modified by JojoS 03/07/2015 00022 * add flipVertical option to constructor 00023 * add use of 'rst' is optional, maybe NC in constructor 00024 * add command SSD1306_SETPAGESTARTADDRESS to reset page start address (important when no hardware reset is uesed) 00025 */ 00026 00027 #include "mbed.h" 00028 #include "Adafruit_SSD1306.h" 00029 00030 #define SSD1306_SETCONTRAST 0x81 00031 #define SSD1306_DISPLAYALLON_RESUME 0xA4 00032 #define SSD1306_DISPLAYALLON 0xA5 00033 #define SSD1306_NORMALDISPLAY 0xA6 00034 #define SSD1306_INVERTDISPLAY 0xA7 00035 #define SSD1306_DISPLAYOFF 0xAE 00036 #define SSD1306_DISPLAYON 0xAF 00037 #define SSD1306_SETDISPLAYOFFSET 0xD3 00038 #define SSD1306_SETCOMPINS 0xDA 00039 #define SSD1306_SETVCOMDETECT 0xDB 00040 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 00041 #define SSD1306_SETPRECHARGE 0xD9 00042 #define SSD1306_SETMULTIPLEX 0xA8 00043 #define SSD1306_SETLOWCOLUMN 0x00 00044 #define SSD1306_SETHIGHCOLUMN 0x10 00045 #define SSD1306_SETSTARTLINE 0x40 00046 #define SSD1306_MEMORYMODE 0x20 00047 #define SSD1306_COMSCANINC 0xC0 00048 #define SSD1306_COMSCANDEC 0xC8 00049 #define SSD1306_SEGREMAP 0xA0 00050 #define SSD1306_CHARGEPUMP 0x8D 00051 #define SSD1306_SETPAGESTARTADDRESS 0xB0 00052 00053 Adafruit_SSD1306::Adafruit_SSD1306(PinName reset, uint8_t rawHeight, uint8_t rawWidth, bool flipVertical) 00054 : Adafruit_GFX(rawWidth,rawHeight) 00055 , _reset(reset,false) 00056 , _flipVertical(flipVertical) 00057 { 00058 buffer.resize(rawHeight * rawWidth / 8); 00059 } 00060 00061 void Adafruit_SSD1306::begin(uint8_t vccstate) 00062 { 00063 if (_reset.is_connected()) { // reset input is not present on every SSD1306 display board, so usage is optional 00064 _reset = 1; 00065 // VDD (3.3V) goes high at start, lets just chill for a ms 00066 wait_ms(1); 00067 // bring reset low 00068 _reset = 0; 00069 // wait 10ms 00070 wait_ms(10); 00071 // bring out of reset 00072 _reset = 1; 00073 // turn on VCC (9V?) 00074 } 00075 00076 00077 command(SSD1306_DISPLAYOFF); 00078 command(SSD1306_SETDISPLAYCLOCKDIV); 00079 command(0x80); // the suggested ratio 0x80 00080 00081 command(SSD1306_SETMULTIPLEX); 00082 command(_rawHeight-1); 00083 00084 command(SSD1306_SETDISPLAYOFFSET); 00085 command(0x0); // no offset 00086 00087 command(SSD1306_SETSTARTLINE | 0x0); // line #0 00088 00089 command(SSD1306_CHARGEPUMP); 00090 command((vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0x14); 00091 00092 command(SSD1306_MEMORYMODE); 00093 command(0x00); // 0x0 act like ks0108 00094 00095 00096 if (_flipVertical) { 00097 command(SSD1306_SEGREMAP | 0x0); 00098 command(SSD1306_COMSCANINC); 00099 } else { 00100 command(SSD1306_SEGREMAP | 0x1); 00101 command(SSD1306_COMSCANDEC); // flip vertically 00102 } 00103 00104 00105 command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 00106 command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 00107 command(SSD1306_SETSTARTLINE | 0x0); // line #0 00108 command(SSD1306_SETPAGESTARTADDRESS | 0x0); 00109 00110 command(SSD1306_SETCOMPINS); 00111 command(_rawHeight == 32 ? 0x02 : 0x12); // TODO - calculate based on _rawHieght ? 00112 00113 command(SSD1306_SETCONTRAST); 00114 command(_rawHeight == 32 ? 0x8F : ((vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF) ); 00115 00116 command(SSD1306_SETPRECHARGE); 00117 command((vccstate == SSD1306_EXTERNALVCC) ? 0x22 : 0xF1); 00118 00119 command(SSD1306_SETVCOMDETECT); 00120 command(0x40); 00121 00122 command(SSD1306_DISPLAYALLON_RESUME); 00123 00124 command(SSD1306_NORMALDISPLAY); 00125 00126 command(SSD1306_DISPLAYON); 00127 } 00128 00129 // Set a single pixel 00130 void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) 00131 { 00132 if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) 00133 return; 00134 00135 // check rotation, move pixel around if necessary 00136 switch (getRotation()) { 00137 case 1: 00138 swap(x, y); 00139 x = _rawWidth - x - 1; 00140 break; 00141 case 2: 00142 x = _rawWidth - x - 1; 00143 y = _rawHeight - y - 1; 00144 break; 00145 case 3: 00146 swap(x, y); 00147 y = _rawHeight - y - 1; 00148 break; 00149 } 00150 00151 // x is which column 00152 if (color == WHITE) 00153 buffer[x+ (y/8)*_rawWidth] |= _BV((y%8)); 00154 else // else black 00155 buffer[x+ (y/8)*_rawWidth] &= ~_BV((y%8)); 00156 } 00157 00158 void Adafruit_SSD1306::invertDisplay(bool i) 00159 { 00160 command(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY); 00161 } 00162 00163 void Adafruit_SSD1306::flipVertical(bool flip) 00164 { 00165 _flipVertical = flip; 00166 00167 if (_flipVertical) { 00168 command(SSD1306_SEGREMAP | 0x0); 00169 command(SSD1306_COMSCANINC); 00170 } else { 00171 command(SSD1306_SEGREMAP | 0x1); 00172 command(SSD1306_COMSCANDEC); // flip vertically 00173 } 00174 } 00175 00176 // Send the display buffer out to the display 00177 void Adafruit_SSD1306::display(void) 00178 { 00179 command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0 00180 command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0 00181 command(SSD1306_SETSTARTLINE | 0x0); // line #0 00182 sendDisplayBuffer(); 00183 } 00184 00185 // Clear the display buffer. Requires a display() call at some point afterwards 00186 void Adafruit_SSD1306::clearDisplay(void) 00187 { 00188 std::fill(buffer.begin(),buffer.end(),0); 00189 } 00190 00191 void Adafruit_SSD1306::splash(void) 00192 { 00193 #ifndef NO_SPLASH_ADAFRUIT 00194 const uint8_t adaFruitLogo[64 * 128 / 8] = { 00195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 00199 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00200 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00204 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 00205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 00206 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF, 00207 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 00208 0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 00209 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, 00210 0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00211 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 00212 0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 00213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, 00214 0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF, 00215 0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00, 00216 0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF, 00217 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF, 00218 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00219 0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F, 00220 0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 00221 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03, 00222 0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 00223 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, 00224 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 00225 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03, 00226 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00227 // 128x32^^^ 128x64vvv 00228 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F, 00229 0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF, 00230 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00, 00231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00232 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, 00234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 00235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00236 0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, 00237 0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, 00238 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 00239 0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E, 00240 0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC, 00241 0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06, 00242 0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8, 00243 0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80, 00244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00245 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03, 00246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 00247 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C, 00248 0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 00249 0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 00250 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07, 00251 0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 00252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 00260 }; 00261 00262 std::copy( 00263 &adaFruitLogo[0] 00264 , &adaFruitLogo[0] + (_rawHeight == 32 ? sizeof(adaFruitLogo)/2 : sizeof(adaFruitLogo)) 00265 , buffer.begin() 00266 ); 00267 #endif 00268 } 00269 00270 /* 00271 * 00272 * SPI specific implementation 00273 * 00274 */ 00275 00276 Adafruit_SSD1306_Spi::Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght, uint8_t rawWidth, bool flipVertical) 00277 : Adafruit_SSD1306(RST, rawHieght, rawWidth, flipVertical) 00278 , cs(CS,true) 00279 , dc(DC,false) 00280 , mspi(spi) 00281 { 00282 begin(); 00283 splash(); 00284 display(); 00285 } 00286 00287 void Adafruit_SSD1306_Spi::command(uint8_t c) 00288 { 00289 cs = 1; 00290 dc = 0; 00291 cs = 0; 00292 mspi.write(c); 00293 cs = 1; 00294 } 00295 00296 void Adafruit_SSD1306_Spi::data(uint8_t c) 00297 { 00298 cs = 1; 00299 dc = 1; 00300 cs = 0; 00301 mspi.write(c); 00302 cs = 1; 00303 }; 00304 00305 void Adafruit_SSD1306_Spi::sendDisplayBuffer() 00306 { 00307 cs = 1; 00308 dc = 1; 00309 cs = 0; 00310 00311 for(uint16_t i=0, q=buffer.size(); i<q; i++) 00312 mspi.write(buffer[i]); 00313 00314 if(height() == 32) 00315 { 00316 for(uint16_t i=0, q=buffer.size(); i<q; i++) 00317 mspi.write(0); 00318 } 00319 00320 cs = 1; 00321 } 00322 00323 /* 00324 * 00325 * I2C specific implementation 00326 * 00327 */ 00328 00329 Adafruit_SSD1306_I2c::Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress, uint8_t rawHeight, uint8_t rawWidth, bool flipVertical) 00330 : Adafruit_SSD1306(RST, rawHeight, rawWidth, flipVertical) 00331 , mi2c(i2c) 00332 , mi2cAddress(i2cAddress) 00333 { 00334 begin(); 00335 splash(); 00336 display(); 00337 } 00338 00339 void Adafruit_SSD1306_I2c::command(uint8_t c) 00340 { 00341 char buff[2]; 00342 buff[0] = 0; // Command Mode 00343 buff[1] = c; 00344 mi2c.write(mi2cAddress, buff, sizeof(buff)); 00345 } 00346 00347 void Adafruit_SSD1306_I2c::data(uint8_t c) 00348 { 00349 char buff[2]; 00350 buff[0] = 0x40; // Data Mode 00351 buff[1] = c; 00352 mi2c.write(mi2cAddress, buff, sizeof(buff)); 00353 } 00354 00355 void Adafruit_SSD1306_I2c::sendDisplayBuffer() 00356 { 00357 char buff[17]; 00358 buff[0] = 0x40; // Data Mode 00359 00360 // send display buffer in 16 byte chunks 00361 for(uint16_t i=0, q=buffer.size(); i<q; i+=16 ) 00362 { uint8_t x ; 00363 00364 // TODO - this will segfault if buffer.size() % 16 != 0 00365 for(x=1; x<sizeof(buff); x++) 00366 buff[x] = buffer[i+x-1]; 00367 mi2c.write(mi2cAddress, buff, sizeof(buff)); 00368 } 00369 }
Generated on Thu Jul 14 2022 22:51:53 by
