A class for managing SSD1306 controlled LCD´s (cheap 128x64 models, 0.96'')
Dependents: mbed_ssd1306 USB_meter_SD_file_number_filtro_for EscanerRf escaner_RTOS ... more
ssd1306.h@8:09b1578f93d9, 2017-11-06 (annotated)
- Committer:
- rodriguj
- Date:
- Mon Nov 06 18:22:22 2017 +0000
- Revision:
- 8:09b1578f93d9
- Parent:
- 7:b0e7ccc9138b
- Child:
- 9:57209a7e9cba
Added fill function. Improved documentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rodriguj | 0:3d84b3bfb794 | 1 | /* |
rodriguj | 4:35757c8b7625 | 2 | * ssd1306.cpp |
rodriguj | 0:3d84b3bfb794 | 3 | * |
rodriguj | 0:3d84b3bfb794 | 4 | * Created on: 20 oct. 2017 |
rodriguj | 3:bb6fba3e84ff | 5 | * Author: Miguel Angel Rodriguez Jodar |
rodriguj | 3:bb6fba3e84ff | 6 | * |
rodriguj | 3:bb6fba3e84ff | 7 | * Based upon Adafruit library. |
rodriguj | 3:bb6fba3e84ff | 8 | * GPL licensed. |
rodriguj | 3:bb6fba3e84ff | 9 | * |
rodriguj | 0:3d84b3bfb794 | 10 | */ |
rodriguj | 3:bb6fba3e84ff | 11 | |
rodriguj | 0:3d84b3bfb794 | 12 | #ifndef MBED_SSD1306_LIBRARY |
rodriguj | 0:3d84b3bfb794 | 13 | #define MBED_SSD1306_LIBRARY |
rodriguj | 0:3d84b3bfb794 | 14 | |
rodriguj | 0:3d84b3bfb794 | 15 | #include "mbed.h" |
rodriguj | 0:3d84b3bfb794 | 16 | |
rodriguj | 4:35757c8b7625 | 17 | #define SSD1306_IS_COMMAND 0x00 |
rodriguj | 4:35757c8b7625 | 18 | #define SSD1306_IS_DATA 0x40 |
rodriguj | 4:35757c8b7625 | 19 | #define SSD1306_IS_NOT_LAST 0x80 |
rodriguj | 4:35757c8b7625 | 20 | #define SSD1306_IS_LAST 0x00 |
rodriguj | 0:3d84b3bfb794 | 21 | |
rodriguj | 0:3d84b3bfb794 | 22 | #define SSD1306_SETCONTRAST 0x81 |
rodriguj | 0:3d84b3bfb794 | 23 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 |
rodriguj | 0:3d84b3bfb794 | 24 | #define SSD1306_DISPLAYALLON 0xA5 |
rodriguj | 0:3d84b3bfb794 | 25 | #define SSD1306_NORMALDISPLAY 0xA6 |
rodriguj | 0:3d84b3bfb794 | 26 | #define SSD1306_INVERTDISPLAY 0xA7 |
rodriguj | 0:3d84b3bfb794 | 27 | #define SSD1306_DISPLAYOFF 0xAE |
rodriguj | 0:3d84b3bfb794 | 28 | #define SSD1306_DISPLAYON 0xAF |
rodriguj | 0:3d84b3bfb794 | 29 | |
rodriguj | 0:3d84b3bfb794 | 30 | #define SSD1306_SETDISPLAYOFFSET 0xD3 |
rodriguj | 0:3d84b3bfb794 | 31 | #define SSD1306_SETCOMPINS 0xDA |
rodriguj | 0:3d84b3bfb794 | 32 | |
rodriguj | 0:3d84b3bfb794 | 33 | #define SSD1306_SETVCOMDETECT 0xDB |
rodriguj | 0:3d84b3bfb794 | 34 | |
rodriguj | 0:3d84b3bfb794 | 35 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 |
rodriguj | 0:3d84b3bfb794 | 36 | #define SSD1306_SETPRECHARGE 0xD9 |
rodriguj | 0:3d84b3bfb794 | 37 | |
rodriguj | 0:3d84b3bfb794 | 38 | #define SSD1306_SETMULTIPLEX 0xA8 |
rodriguj | 0:3d84b3bfb794 | 39 | |
rodriguj | 0:3d84b3bfb794 | 40 | #define SSD1306_SETLOWCOLUMN 0x00 |
rodriguj | 0:3d84b3bfb794 | 41 | #define SSD1306_SETHIGHCOLUMN 0x10 |
rodriguj | 0:3d84b3bfb794 | 42 | |
rodriguj | 0:3d84b3bfb794 | 43 | #define SSD1306_SETSTARTLINE 0x40 |
rodriguj | 0:3d84b3bfb794 | 44 | |
rodriguj | 0:3d84b3bfb794 | 45 | #define SSD1306_MEMORYMODE 0x20 |
rodriguj | 0:3d84b3bfb794 | 46 | |
rodriguj | 0:3d84b3bfb794 | 47 | #define SSD1306_COMSCANINC 0xC0 |
rodriguj | 0:3d84b3bfb794 | 48 | #define SSD1306_COMSCANDEC 0xC8 |
rodriguj | 0:3d84b3bfb794 | 49 | |
rodriguj | 0:3d84b3bfb794 | 50 | #define SSD1306_SEGREMAP 0xA0 |
rodriguj | 0:3d84b3bfb794 | 51 | |
rodriguj | 0:3d84b3bfb794 | 52 | #define SSD1306_CHARGEPUMP 0x8D |
rodriguj | 0:3d84b3bfb794 | 53 | |
rodriguj | 0:3d84b3bfb794 | 54 | #define SSD1306_EXTERNALVCC 0x1 |
rodriguj | 0:3d84b3bfb794 | 55 | #define SSD1306_SWITCHCAPVCC 0x2 |
rodriguj | 0:3d84b3bfb794 | 56 | |
rodriguj | 0:3d84b3bfb794 | 57 | // Scrolling #defines |
rodriguj | 0:3d84b3bfb794 | 58 | #define SSD1306_ACTIVATE_SCROLL 0x2F |
rodriguj | 0:3d84b3bfb794 | 59 | #define SSD1306_DEACTIVATE_SCROLL 0x2E |
rodriguj | 0:3d84b3bfb794 | 60 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 |
rodriguj | 0:3d84b3bfb794 | 61 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 |
rodriguj | 0:3d84b3bfb794 | 62 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 |
rodriguj | 0:3d84b3bfb794 | 63 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 |
rodriguj | 0:3d84b3bfb794 | 64 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A |
rodriguj | 0:3d84b3bfb794 | 65 | |
rodriguj | 7:b0e7ccc9138b | 66 | /** |
rodriguj | 7:b0e7ccc9138b | 67 | * SSD1306. A class for interacting with SSD1306 controlled 128x64 cheap OLED displays |
rodriguj | 8:09b1578f93d9 | 68 | * |
rodriguj | 8:09b1578f93d9 | 69 | * Example of use: |
rodriguj | 8:09b1578f93d9 | 70 | * @code |
rodriguj | 8:09b1578f93d9 | 71 | * #include "mbed.h" |
rodriguj | 8:09b1578f93d9 | 72 | * #include "ssd1306.h" |
rodriguj | 8:09b1578f93d9 | 73 | * |
rodriguj | 8:09b1578f93d9 | 74 | * SSD1306 lcd (I2C_SDA, I2C_SCL); // assumes default I2C address of 0x78 |
rodriguj | 8:09b1578f93d9 | 75 | * AnalogIn knob (A0); // potentiometer to analog pin A0 |
rodriguj | 8:09b1578f93d9 | 76 | * |
rodriguj | 8:09b1578f93d9 | 77 | * int main() |
rodriguj | 8:09b1578f93d9 | 78 | * { |
rodriguj | 8:09b1578f93d9 | 79 | * lcd.speed (SSD1306::Medium); // set working frequency |
rodriguj | 8:09b1578f93d9 | 80 | * lcd.init(); // initialize SSD1306 |
rodriguj | 8:09b1578f93d9 | 81 | * lcd.cls(); // clear frame buffer |
rodriguj | 8:09b1578f93d9 | 82 | * lcd.locate (3,1); // set text cursor to line 3, column 1 |
rodriguj | 8:09b1578f93d9 | 83 | * lcd.printf ("Hello, world!"); // print to frame buffer |
rodriguj | 8:09b1578f93d9 | 84 | * lcd.line ( 7, 23, 113, 23, SSD1306::Normal); // |
rodriguj | 8:09b1578f93d9 | 85 | * lcd.line (113, 23, 113, 32, SSD1306::Normal); // Surrounds text with |
rodriguj | 8:09b1578f93d9 | 86 | * lcd.line (113, 32, 7, 32, SSD1306::Normal); // a rectangle |
rodriguj | 8:09b1578f93d9 | 87 | * lcd.line ( 7, 32, 7, 23, SSD1306::Normal); // |
rodriguj | 8:09b1578f93d9 | 88 | * lcd.fill (0, 0); // fills screen outside rectangle |
rodriguj | 8:09b1578f93d9 | 89 | * lcd.redraw(); // updates actual display transferring frame buffer over I2C bus |
rodriguj | 8:09b1578f93d9 | 90 | * while (1) { |
rodriguj | 8:09b1578f93d9 | 91 | * unsigned char level = 255*knob.read(); // reads pot. Scales to 0-255 |
rodriguj | 8:09b1578f93d9 | 92 | * lcd.set_contrast (level); // set contrast |
rodriguj | 8:09b1578f93d9 | 93 | * wait_ms (20); // waits a little to prevent excesive I2C traffic |
rodriguj | 8:09b1578f93d9 | 94 | * } |
rodriguj | 8:09b1578f93d9 | 95 | * } |
rodriguj | 8:09b1578f93d9 | 96 | * @endcode |
rodriguj | 7:b0e7ccc9138b | 97 | */ |
rodriguj | 4:35757c8b7625 | 98 | class SSD1306 { |
rodriguj | 0:3d84b3bfb794 | 99 | public: |
rodriguj | 6:cff0e772910f | 100 | /** |
rodriguj | 6:cff0e772910f | 101 | * PlotStyle. Defines how pixels being plotted interact with existing pixels on the screen |
rodriguj | 6:cff0e772910f | 102 | */ |
rodriguj | 0:3d84b3bfb794 | 103 | enum PlotStyle |
rodriguj | 0:3d84b3bfb794 | 104 | { |
rodriguj | 8:09b1578f93d9 | 105 | Normal, /**< The point is set on the display */ |
rodriguj | 8:09b1578f93d9 | 106 | Inverse, /**< The point is erased on the display */ |
rodriguj | 8:09b1578f93d9 | 107 | Xor /**< The point is erased on the display if it was already set, otherwise, it is set */ |
rodriguj | 0:3d84b3bfb794 | 108 | }; |
rodriguj | 0:3d84b3bfb794 | 109 | |
rodriguj | 6:cff0e772910f | 110 | /** |
rodriguj | 6:cff0e772910f | 111 | * I2CSpeed. Defines the speed of the I2C bus |
rodriguj | 6:cff0e772910f | 112 | */ |
rodriguj | 0:3d84b3bfb794 | 113 | enum I2CSpeed |
rodriguj | 0:3d84b3bfb794 | 114 | { |
rodriguj | 8:09b1578f93d9 | 115 | Slow, /**< I2C frequency is set to 100 kHz */ |
rodriguj | 8:09b1578f93d9 | 116 | Medium, /**< I2C frequency is set to 400 kHz */ |
rodriguj | 8:09b1578f93d9 | 117 | Fast /**< I2C frequency is set to 1 MHz. Use it only with short connections to host */ |
rodriguj | 0:3d84b3bfb794 | 118 | }; |
rodriguj | 0:3d84b3bfb794 | 119 | |
rodriguj | 6:cff0e772910f | 120 | /** |
rodriguj | 6:cff0e772910f | 121 | * Creates an instance of a SSD1306 driver, specifying I2C pins to use |
rodriguj | 6:cff0e772910f | 122 | * |
rodriguj | 6:cff0e772910f | 123 | * @param sda I2C data line pin |
rodriguj | 6:cff0e772910f | 124 | * @param scl I2C clock line pin |
rodriguj | 6:cff0e772910f | 125 | */ |
rodriguj | 3:bb6fba3e84ff | 126 | SSD1306 (PinName sda, PinName scl, char ssd1306_addr = 0x78); |
rodriguj | 3:bb6fba3e84ff | 127 | |
rodriguj | 6:cff0e772910f | 128 | /** |
rodriguj | 6:cff0e772910f | 129 | * Creates an instance of a SSD1306 driver using an existing I2C object |
rodriguj | 6:cff0e772910f | 130 | * |
rodriguj | 6:cff0e772910f | 131 | * @param busi2c I2C object |
rodriguj | 6:cff0e772910f | 132 | * @param ssd1306_addr I2C addr of SSD1306 controller |
rodriguj | 6:cff0e772910f | 133 | */ |
rodriguj | 3:bb6fba3e84ff | 134 | SSD1306 (I2C &busi2c, char ssd1306_addr = 0x78); |
rodriguj | 0:3d84b3bfb794 | 135 | |
rodriguj | 6:cff0e772910f | 136 | /** |
rodriguj | 6:cff0e772910f | 137 | * Set the frequency of the I2C interface |
rodriguj | 6:cff0e772910f | 138 | * |
rodriguj | 6:cff0e772910f | 139 | * @param hz The bus frequency in hertz |
rodriguj | 6:cff0e772910f | 140 | */ |
rodriguj | 0:3d84b3bfb794 | 141 | void speed (I2CSpeed spd); |
rodriguj | 0:3d84b3bfb794 | 142 | |
rodriguj | 6:cff0e772910f | 143 | /** |
rodriguj | 6:cff0e772910f | 144 | * Initialize the SSD1306 controller |
rodriguj | 6:cff0e772910f | 145 | */ |
rodriguj | 0:3d84b3bfb794 | 146 | int init (void); |
rodriguj | 0:3d84b3bfb794 | 147 | |
rodriguj | 6:cff0e772910f | 148 | /** |
rodriguj | 6:cff0e772910f | 149 | * Scrolls up one text line |
rodriguj | 6:cff0e772910f | 150 | * |
rodriguj | 6:cff0e772910f | 151 | * @param refresh (optional) Force an actual screen redraw after scrolling |
rodriguj | 6:cff0e772910f | 152 | */ |
rodriguj | 1:c5cf4ca5939f | 153 | void scroll (bool refresh=false); |
rodriguj | 0:3d84b3bfb794 | 154 | |
rodriguj | 6:cff0e772910f | 155 | /** |
rodriguj | 6:cff0e772910f | 156 | * Print a character at the current text position. Updates the text position and forces a scroll if at the end of the screen |
rodriguj | 6:cff0e772910f | 157 | * |
rodriguj | 6:cff0e772910f | 158 | * @param c ASCII code of the character to print (8-bit ASCII code, use original IBM code page 437. No control codes. |
rodriguj | 6:cff0e772910f | 159 | * @param refresh (optional) Force an actual screen redraw after scrolling |
rodriguj | 6:cff0e772910f | 160 | */ |
rodriguj | 1:c5cf4ca5939f | 161 | void putchar (char c, bool refresh=false); |
rodriguj | 0:3d84b3bfb794 | 162 | |
rodriguj | 6:cff0e772910f | 163 | /** |
rodriguj | 6:cff0e772910f | 164 | * Prints a NUL terminated string |
rodriguj | 6:cff0e772910f | 165 | * |
rodriguj | 6:cff0e772910f | 166 | * @param s C-style string (NUL terminated) to print. |
rodriguj | 8:09b1578f93d9 | 167 | * @param refresh (optional) Force an actual screen redraw after the operation |
rodriguj | 6:cff0e772910f | 168 | */ |
rodriguj | 2:7f1160c1a741 | 169 | void puts (char *s, bool refresh=false); |
rodriguj | 3:bb6fba3e84ff | 170 | |
rodriguj | 6:cff0e772910f | 171 | /** |
rodriguj | 6:cff0e772910f | 172 | * printf interface to SSD1306 controller |
rodriguj | 6:cff0e772910f | 173 | * |
rodriguj | 6:cff0e772910f | 174 | * @param fmt Format string. |
rodriguj | 6:cff0e772910f | 175 | */ |
rodriguj | 4:35757c8b7625 | 176 | void printf (const char *fmt,...); |
rodriguj | 2:7f1160c1a741 | 177 | |
rodriguj | 6:cff0e772910f | 178 | /** |
rodriguj | 6:cff0e772910f | 179 | * Change the text position |
rodriguj | 6:cff0e772910f | 180 | * |
rodriguj | 6:cff0e772910f | 181 | * @param row Text row (0-7) to print the next character |
rodriguj | 6:cff0e772910f | 182 | * @param column Text column (0-15) to print the next character |
rodriguj | 6:cff0e772910f | 183 | */ |
rodriguj | 2:7f1160c1a741 | 184 | void locate (char row, char column); |
rodriguj | 2:7f1160c1a741 | 185 | |
rodriguj | 6:cff0e772910f | 186 | /** |
rodriguj | 8:09b1578f93d9 | 187 | * (Deprecated: use redraw instead) Redraws the physical display, sending the content of the display memory to the SSD1306 controller using the I2C bus. |
rodriguj | 6:cff0e772910f | 188 | */ |
rodriguj | 0:3d84b3bfb794 | 189 | void display (void); |
rodriguj | 0:3d84b3bfb794 | 190 | |
rodriguj | 6:cff0e772910f | 191 | /** |
rodriguj | 8:09b1578f93d9 | 192 | * Redraws the physical display, sending the content of the display memory to the SSD1306 controller using the I2C bus |
rodriguj | 8:09b1578f93d9 | 193 | */ |
rodriguj | 8:09b1578f93d9 | 194 | void redraw (void); |
rodriguj | 8:09b1578f93d9 | 195 | |
rodriguj | 8:09b1578f93d9 | 196 | /** |
rodriguj | 6:cff0e772910f | 197 | * Changes the contrast (actually, pixel brightness) of the screen |
rodriguj | 6:cff0e772910f | 198 | * |
rodriguj | 6:cff0e772910f | 199 | * @param v Contrast level (0-255) |
rodriguj | 6:cff0e772910f | 200 | */ |
rodriguj | 0:3d84b3bfb794 | 201 | void set_contrast (char v); |
rodriguj | 0:3d84b3bfb794 | 202 | |
rodriguj | 6:cff0e772910f | 203 | /** |
rodriguj | 6:cff0e772910f | 204 | * Clear screen and optionally, fills it with a predefined picture (in 128x64 OLED format, see display datasheet). Also resets the text position. |
rodriguj | 6:cff0e772910f | 205 | * |
rodriguj | 6:cff0e772910f | 206 | * @param bkground If not NULL, should point to a 1024 byte buffer with the image to load to the display |
rodriguj | 8:09b1578f93d9 | 207 | * @param refresh (optional) Force an actual screen redraw after the operation |
rodriguj | 6:cff0e772910f | 208 | */ |
rodriguj | 1:c5cf4ca5939f | 209 | void cls (char *bkground=NULL, bool refresh=false); |
rodriguj | 0:3d84b3bfb794 | 210 | |
rodriguj | 6:cff0e772910f | 211 | /** |
rodriguj | 6:cff0e772910f | 212 | * Plots a pixel. |
rodriguj | 6:cff0e772910f | 213 | * |
rodriguj | 6:cff0e772910f | 214 | * @param x x-coordinate (0-127) of the pixel. X coordinates go left to right. |
rodriguj | 6:cff0e772910f | 215 | * @param y y-coordinate (0-63) of the pixel. Y coordinates go up to down. |
rodriguj | 6:cff0e772910f | 216 | * @param mode. Plot style mode: Normal (pixel is drawn), Inverse (pixel is erased), or Xor (pixel is erased if background position is already set, otherwise is drawn) |
rodriguj | 8:09b1578f93d9 | 217 | * @param refresh (optional) Force an actual screen redraw after plotting |
rodriguj | 6:cff0e772910f | 218 | */ |
rodriguj | 4:35757c8b7625 | 219 | void plot (char x, char y, PlotStyle mode, bool refresh=false); |
rodriguj | 1:c5cf4ca5939f | 220 | |
rodriguj | 6:cff0e772910f | 221 | /** |
rodriguj | 6:cff0e772910f | 222 | * Returns the state of a pixel coordinate from screen |
rodriguj | 6:cff0e772910f | 223 | * |
rodriguj | 6:cff0e772910f | 224 | * @param x x-coordinate (0-127) of the pixel. X coordinates go left to right. |
rodriguj | 6:cff0e772910f | 225 | * @param y y-coordinate (0-63) of the pixel. Y coordinates go up to down. |
rodriguj | 6:cff0e772910f | 226 | * @return true if the pixel was set, or false otherwise |
rodriguj | 6:cff0e772910f | 227 | */ |
rodriguj | 3:bb6fba3e84ff | 228 | bool point (char x, char y); |
rodriguj | 3:bb6fba3e84ff | 229 | |
rodriguj | 6:cff0e772910f | 230 | /** |
rodriguj | 6:cff0e772910f | 231 | * Draws a line using the Bresenham algorithm |
rodriguj | 6:cff0e772910f | 232 | * |
rodriguj | 6:cff0e772910f | 233 | * @param x0 x-coordinate (0-127) of the starting point |
rodriguj | 6:cff0e772910f | 234 | * @param y0 y-coordinate (0-63) of the starting point |
rodriguj | 6:cff0e772910f | 235 | * @param x1 x-coordinate (0-127) of the ending point |
rodriguj | 6:cff0e772910f | 236 | * @param y1 y-coordinate (0-63) of the ending point |
rodriguj | 6:cff0e772910f | 237 | * @param mode. Plot style mode: Normal (pixel is drawn), Inverse (pixel is erased), or Xor (pixel is erased if background position is already set, otherwise is drawn) |
rodriguj | 8:09b1578f93d9 | 238 | * @param refresh (optional) Force an actual screen redraw after drawing the line |
rodriguj | 6:cff0e772910f | 239 | */ |
rodriguj | 4:35757c8b7625 | 240 | void line (char x0, char y0, char x1, char y1, PlotStyle mode, bool refresh=false); |
rodriguj | 0:3d84b3bfb794 | 241 | |
rodriguj | 6:cff0e772910f | 242 | /** |
rodriguj | 6:cff0e772910f | 243 | * Draws a circle |
rodriguj | 6:cff0e772910f | 244 | * |
rodriguj | 6:cff0e772910f | 245 | * @param x0 x-coordinate (0-127) of the center point |
rodriguj | 6:cff0e772910f | 246 | * @param y0 y-coordinate (0-63) of the center point |
rodriguj | 6:cff0e772910f | 247 | * @param r radius of the circle |
rodriguj | 6:cff0e772910f | 248 | * @param mode. Plot style mode: Normal (pixel is drawn), Inverse (pixel is erased), or Xor (pixel is erased if background position is already set, otherwise is drawn) |
rodriguj | 8:09b1578f93d9 | 249 | * @param refresh (optional) Force an actual screen redraw after drawing the shape |
rodriguj | 6:cff0e772910f | 250 | */ |
rodriguj | 4:35757c8b7625 | 251 | void circle (char x0, char y0, char r, PlotStyle mode, bool refresh=false); |
rodriguj | 3:bb6fba3e84ff | 252 | |
rodriguj | 8:09b1578f93d9 | 253 | /** |
rodriguj | 8:09b1578f93d9 | 254 | * Flood fills an area surrounded by the screen edge and/or a closed shape. |
rodriguj | 8:09b1578f93d9 | 255 | * |
rodriguj | 8:09b1578f93d9 | 256 | * @param x x-coordinate (0-127) of a point inside the area to fill, not plotted |
rodriguj | 8:09b1578f93d9 | 257 | * @param y y-coordinate (0-63) of a point inside the area to fill, not plotted |
rodriguj | 8:09b1578f93d9 | 258 | * @param refresh (optional) Force an actual screen redraw after the operation |
rodriguj | 8:09b1578f93d9 | 259 | */ |
rodriguj | 8:09b1578f93d9 | 260 | void fill (char x, char y, bool refresh=false); |
rodriguj | 8:09b1578f93d9 | 261 | |
rodriguj | 0:3d84b3bfb794 | 262 | virtual ~SSD1306 () { |
rodriguj | 3:bb6fba3e84ff | 263 | if (!do_not_delete_bus) |
rodriguj | 3:bb6fba3e84ff | 264 | delete bus; |
rodriguj | 0:3d84b3bfb794 | 265 | delete fb; |
rodriguj | 0:3d84b3bfb794 | 266 | } |
rodriguj | 0:3d84b3bfb794 | 267 | |
rodriguj | 0:3d84b3bfb794 | 268 | protected: |
rodriguj | 4:35757c8b7625 | 269 | I2C *bus; // I2C object |
rodriguj | 4:35757c8b7625 | 270 | char ssd1306_i2c_addr; // I2C address of SSD1306 controller |
rodriguj | 4:35757c8b7625 | 271 | char *fb; // pointer to display buffer (1024 bytes) |
rodriguj | 4:35757c8b7625 | 272 | char do_not_delete_bus; // flag to prevent deletion of bus when destroying SSD1306 object |
rodriguj | 4:35757c8b7625 | 273 | int idxfb; // Current text position (referred to screen address memory) |
rodriguj | 4:35757c8b7625 | 274 | int command (char c); // Sends a I2C command to SSD1306 |
rodriguj | 4:35757c8b7625 | 275 | int data (char d); // Sends I2C data to SSD1306 |
rodriguj | 4:35757c8b7625 | 276 | int command_data (char c, char c_or_d, char lastitem); // Sends a command or data and signal if it is not the last command/data in a list |
rodriguj | 4:35757c8b7625 | 277 | char scan (); // Scans the I2C bus searcing for I2C id's 0x78 or 0x7A. Currently not used |
rodriguj | 0:3d84b3bfb794 | 278 | }; |
rodriguj | 0:3d84b3bfb794 | 279 | |
rodriguj | 0:3d84b3bfb794 | 280 | #endif |