SSD1308 128x64 OLED Driver with I2C interface

Dependents:   sense xadow_m0_ada_gps xadow_m0_SD_Hello sense-DHT11 ... more

See http://mbed.org/users/wim/notebook/oled-display-with-ssd1308-driver/#c6729

Committer:
wim
Date:
Mon Dec 18 18:46:05 2017 +0000
Revision:
5:e564cde8e03e
Parent:
4:df92b0c0cb92
Fixed non-copyable issue (Thx kenjiArai)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 1:b7e8f5139026 1 /** @file SSD1308 I2C device class header file
wim 1:b7e8f5139026 2 * Based on Solomon Systech SSD1308 datasheet, rev. 1, 10/2008
wim 1:b7e8f5139026 3 * The SSD1308 is used for example in the Seeed 128x64 OLED Display
wim 1:b7e8f5139026 4 * http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167
wim 1:b7e8f5139026 5 */
wim 0:300d08d9b058 6 // The original code by Andrew Schamp is using (and has been submitted as a part of) Jeff Rowberg's I2Cdevlib library,
wim 0:300d08d9b058 7 // which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
wim 0:300d08d9b058 8 // Some parts also mashed up from Graphic Library for driving monochrome displays based on the PCD8544,
wim 0:300d08d9b058 9 // Copyright (c) 2011, Wim De Roeve, who in turn did partial port of code found on
wim 0:300d08d9b058 10 // http://serdisplib.sourceforge.net/ser/pcd8544.html#links and by Petras Saduikis <petras@petras.co.uk>
wim 0:300d08d9b058 11 //
wim 0:300d08d9b058 12 // Changelog:
wim 0:300d08d9b058 13 // 2011-08-25 - Initial release by Andrew Schamp <schamp@gmail.com>
wim 0:300d08d9b058 14 // 2012-06-19 - Ported to mbed and optimised (WH)
wim 4:df92b0c0cb92 15 // 2013-07-12 - Minor comment fix and placeholder for SSD1306 (WH)
wim 4:df92b0c0cb92 16 // 2015-01-01 - Switch for optimised I2C calls to test on F401 (WH)
wim 5:e564cde8e03e 17 // 2017-12-18 - Fixed non-copyable issue (Thx kenjiArai)
wim 0:300d08d9b058 18 //
wim 4:df92b0c0cb92 19 /*
wim 4:df92b0c0cb92 20 ================================================================================
wim 0:300d08d9b058 21 I2Cdev device library code is placed under the MIT license
wim 0:300d08d9b058 22 Copyright (c) 2011 Andrew Schamp
wim 5:e564cde8e03e 23 Copyright (c) 2012,2013,2017 WH (mbed port)
wim 0:300d08d9b058 24
wim 0:300d08d9b058 25 Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:300d08d9b058 26 of this software and associated documentation files (the "Software"), to deal
wim 0:300d08d9b058 27 in the Software without restriction, including without limitation the rights
wim 0:300d08d9b058 28 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:300d08d9b058 29 copies of the Software, and to permit persons to whom the Software is
wim 0:300d08d9b058 30 furnished to do so, subject to the following conditions:
wim 0:300d08d9b058 31
wim 0:300d08d9b058 32 The above copyright notice and this permission notice shall be included in
wim 0:300d08d9b058 33 all copies or substantial portions of the Software.
wim 0:300d08d9b058 34
wim 0:300d08d9b058 35 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:300d08d9b058 36 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:300d08d9b058 37 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:300d08d9b058 38 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:300d08d9b058 39 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:300d08d9b058 40 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:300d08d9b058 41 THE SOFTWARE.
wim 4:df92b0c0cb92 42 ================================================================================
wim 0:300d08d9b058 43 */
wim 0:300d08d9b058 44
wim 0:300d08d9b058 45 #ifndef SSD1308_H
wim 0:300d08d9b058 46 #define SSD1308_H
wim 0:300d08d9b058 47
wim 0:300d08d9b058 48 // This is the I2C address (8 bit)
wim 0:300d08d9b058 49 // There are two possible addresses: with D/C# (pin 13) grounded, the address is 0x78,
wim 0:300d08d9b058 50 // with D/C# tied high it is 0x7A. Assume grounded by default.
wim 0:300d08d9b058 51 #define SSD1308_SA0 0x78
wim 0:300d08d9b058 52 #define SSD1308_SA1 0x7A
wim 0:300d08d9b058 53 #define SSD1308_DEF_SA SSD1308_SA0
wim 0:300d08d9b058 54
wim 0:300d08d9b058 55 // Display dimensions
wim 0:300d08d9b058 56 #define ROWS 64
wim 0:300d08d9b058 57 #define COLUMNS 128
wim 0:300d08d9b058 58 #define PAGES (ROWS / 8)
wim 0:300d08d9b058 59 #define MAX_PAGE (PAGES - 1)
wim 2:16c84a134393 60 #define MAX_ROW (ROWS - 1)
wim 0:300d08d9b058 61 #define MAX_COL (COLUMNS - 1)
wim 0:300d08d9b058 62
wim 0:300d08d9b058 63 // Character dimensions 8x8 font
wim 0:300d08d9b058 64 #define CHARS (COLUMNS / FONT8x8_WIDTH)
wim 0:300d08d9b058 65
wim 0:300d08d9b058 66 // Command and Datamode
wim 0:300d08d9b058 67 #define COMMAND_MODE 0x80 // continuation bit is set!
wim 0:300d08d9b058 68 #define DATA_MODE 0x40
wim 0:300d08d9b058 69
wim 0:300d08d9b058 70 // Commands and Parameter defines
wim 2:16c84a134393 71 #define SET_LOWER_COLUMN 0x00 // | with lower nibble (Page mode only)
wim 2:16c84a134393 72 #define SET_HIGHER_COLUMN 0x10 // | with higher nibble (Page mode only)
wim 2:16c84a134393 73
wim 0:300d08d9b058 74 #define HORIZONTAL_ADDRESSING_MODE 0x00
wim 0:300d08d9b058 75 #define VERTICAL_ADDRESSING_MODE 0x01
wim 0:300d08d9b058 76 #define PAGE_ADDRESSING_MODE 0x02
wim 0:300d08d9b058 77 #define SET_MEMORY_ADDRESSING_MODE 0x20 // takes one byte as given above
wim 0:300d08d9b058 78
wim 0:300d08d9b058 79 #define SET_COLUMN_ADDRESS 0x21 // takes two bytes, start address and end address of display data RAM
wim 0:300d08d9b058 80 #define SET_PAGE_ADDRESS 0x22 // takes two bytes, start address and end address of display data RAM
wim 0:300d08d9b058 81
wim 0:300d08d9b058 82 // Command maybe unsupported by SSD1308
wim 0:300d08d9b058 83 #define FADE_INTERVAL_8_FRAMES 0x00
wim 0:300d08d9b058 84 #define FADE_INTERVAL_16_FRAMES 0x01
wim 0:300d08d9b058 85 #define FADE_INTERVAL_24_FRAMES 0x02
wim 0:300d08d9b058 86 #define FADE_INTERVAL_32_FRAMES 0x03
wim 0:300d08d9b058 87 #define FADE_INTERVAL_64_FRAMES 0x07
wim 0:300d08d9b058 88 #define FADE_INTERVAL_128_FRAMES 0x0F
wim 0:300d08d9b058 89 #define FADE_BLINK_DISABLE 0x00
wim 0:300d08d9b058 90 #define FADE_OUT_ENABLE 0x20
wim 0:300d08d9b058 91 #define BLINK_ENABLE 0x30
wim 0:300d08d9b058 92 #define SET_FADE_BLINK 0x23 // takes one byte
wim 0:300d08d9b058 93 // bit5-4 = 0, fade/blink mode
wim 0:300d08d9b058 94 // bit3-0 = Time interval in frames
wim 0:300d08d9b058 95
wim 2:16c84a134393 96 #define SET_DISPLAY_START_LINE 0x40 // | with a row number 0-63 to set start row. (Reset = 0)
wim 0:300d08d9b058 97
wim 0:300d08d9b058 98 #define SET_CONTRAST 0x81 // takes one byte, 0x00 - 0xFF
wim 0:300d08d9b058 99
wim 0:300d08d9b058 100 #define SET_SEGMENT_REMAP_0 0xA0 // column address 0 is mapped to SEG0 (Reset)
wim 0:300d08d9b058 101 #define SET_SEGMENT_REMAP_127 0xA1 // column address 127 is mapped to SEG0
wim 0:300d08d9b058 102
wim 0:300d08d9b058 103 #define SET_DISPLAY_GDDRAM 0xA4 // restores display to contents of RAM
wim 0:300d08d9b058 104 #define SET_ENTIRE_DISPLAY_ON 0xA5 // turns all pixels on, does not affect RAM
wim 0:300d08d9b058 105
wim 0:300d08d9b058 106 #define SET_NORMAL_DISPLAY 0xA6 // a databit of 1 indicates pixel 'ON'
wim 0:300d08d9b058 107 #define SET_INVERSE_DISPLAY 0xA7 // a databit of 1 indicates pixel 'OFF'
wim 0:300d08d9b058 108
wim 0:300d08d9b058 109 #define SET_MULTIPLEX_RATIO 0xA8 // takes one byte, from 16xMUX to 64xMUX (MUX Ratio = byte+1; Default 64)
wim 0:300d08d9b058 110
wim 0:300d08d9b058 111 #define EXTERNAL_IREF 0x10
wim 0:300d08d9b058 112 #define INTERNAL_IREF 0x00
wim 0:300d08d9b058 113 #define SET_IREF_SELECTION 0xAD // sets internal or external Iref
wim 0:300d08d9b058 114
wim 0:300d08d9b058 115 #define SET_DISPLAY_POWER_OFF 0xAE
wim 0:300d08d9b058 116 #define SET_DISPLAY_POWER_ON 0xAF
wim 0:300d08d9b058 117
wim 0:300d08d9b058 118 #define PAGE0 0x00
wim 0:300d08d9b058 119 #define PAGE1 0x01
wim 0:300d08d9b058 120 #define PAGE2 0x02
wim 0:300d08d9b058 121 #define PAGE3 0x03
wim 0:300d08d9b058 122 #define PAGE4 0x04
wim 0:300d08d9b058 123 #define PAGE5 0x05
wim 0:300d08d9b058 124 #define PAGE6 0x06
wim 0:300d08d9b058 125 #define PAGE7 0x07
wim 2:16c84a134393 126 #define SET_PAGE_START_ADDRESS 0xB0 // | with a page number to get start address (Page mode only)
wim 0:300d08d9b058 127
wim 0:300d08d9b058 128 #define SET_COMMON_REMAP_0 0xC0 // row address 0 is mapped to COM0 (Reset)
wim 0:300d08d9b058 129 #define SET_COMMON_REMAP_63 0xC8 // row address 63 is mapped to COM0
wim 0:300d08d9b058 130
wim 0:300d08d9b058 131 #define SET_DISPLAY_OFFSET 0xD3 // takes one byte from 0-63 for vertical shift, Reset = 0
wim 0:300d08d9b058 132
wim 0:300d08d9b058 133 #define SET_DISPLAY_CLOCK 0xD5 // takes one byte
wim 0:300d08d9b058 134 // bit7-4 = Osc Freq DCLK (Reset = 1000b)
wim 0:300d08d9b058 135 // bit3-0 = Divide ration (Reset = oooob, Ratio = 1)
wim 0:300d08d9b058 136
wim 0:300d08d9b058 137 #define SET_PRECHARGE_TIME 0xD9 // takes one byte
wim 0:300d08d9b058 138 // bit7-4 = Phase2, upto 15 DCLKs (Reset = 0010b)
wim 0:300d08d9b058 139 // bit3-0 = Phase1, upto 15 DCLKs (Reset = 0010b)
wim 0:300d08d9b058 140
wim 0:300d08d9b058 141
wim 0:300d08d9b058 142 #define COMMON_BASE 0x02 //
wim 0:300d08d9b058 143 #define COMMON_SEQUENTIAL 0x00 // Sequential common pins config
wim 0:300d08d9b058 144 #define COMMON_ALTERNATIVE 0x10 // Odd/Even common pins config (Reset)
wim 0:300d08d9b058 145 #define COMMON_LEFTRIGHT_NORMAL 0x00 // LeftRight Normal (Reset)
wim 0:300d08d9b058 146 #define COMMON_LEFTRIGHT_FLIP 0x20 // LeftRight Flip
wim 0:300d08d9b058 147 #define SET_COMMON_CONF 0xDA // takes one byte as given above
wim 0:300d08d9b058 148
wim 0:300d08d9b058 149
wim 0:300d08d9b058 150 #define VCOMH_DESELECT_0_65_CODE 0x00
wim 0:300d08d9b058 151 #define VCOMH_DESELECT_0_77_CODE 0x20
wim 0:300d08d9b058 152 #define VCOMH_DESELECT_0_83_CODE 0x30
wim 0:300d08d9b058 153 #define SET_VCOMH_DESELECT_LEVEL 0xDB // takes one byte as given above
wim 0:300d08d9b058 154
wim 0:300d08d9b058 155 #define NOP 0xE3
wim 0:300d08d9b058 156
wim 0:300d08d9b058 157 #define SCROLL_INTERVAL_5_FRAMES 0x00
wim 0:300d08d9b058 158 #define SCROLL_INTERVAL_64_FRAMES 0x01
wim 0:300d08d9b058 159 #define SCROLL_INTERVAL_128_FRAMES 0x02
wim 0:300d08d9b058 160 #define SCROLL_INTERVAL_256_FRAMES 0x03
wim 0:300d08d9b058 161 #define SCROLL_INTERVAL_3_FRAMES 0x04
wim 0:300d08d9b058 162 #define SCROLL_INTERVAL_4_FRAMES 0x05
wim 0:300d08d9b058 163 #define SCROLL_INTERVAL_25_FRAMES 0x06
wim 0:300d08d9b058 164 #define SCROLL_INTERVAL_2_FRAMES 0x07
wim 0:300d08d9b058 165
wim 0:300d08d9b058 166 #define SET_RIGHT_HOR_SCROLL 0x26 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF
wim 0:300d08d9b058 167 #define SET_LEFT_HOR_SCROLL 0x27 // takes 6 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, 0x00, 0xFF
wim 0:300d08d9b058 168
wim 0:300d08d9b058 169 #define SET_VERT_RIGHT_HOR_SCROLL 0x29 // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset
wim 0:300d08d9b058 170 #define SET_VERT_LEFT_HOR_SCROLL 0x2A // takes 5 bytes: 0x00, PageStart, Scroll_Interval, PageEnd, VertOffset
wim 0:300d08d9b058 171
wim 0:300d08d9b058 172 #define SET_DEACTIVATE_SCROLL 0x2E
wim 0:300d08d9b058 173 #define SET_ACTIVATE_SCROLL 0x2F
wim 0:300d08d9b058 174
wim 0:300d08d9b058 175 #define SET_VERTICAL_SCROLL_AREA 0xA3 // takes 2 bytes: Rows in Top Area (Reset=0), Rows in Scroll Area (Reset=64)
wim 0:300d08d9b058 176
wim 3:fa18169dd7e6 177
wim 3:fa18169dd7e6 178
wim 3:fa18169dd7e6 179 /** Class to control an SSD1308 based oled Display
wim 3:fa18169dd7e6 180 *
wim 3:fa18169dd7e6 181 * Example:
wim 3:fa18169dd7e6 182 * @code
wim 3:fa18169dd7e6 183 * #include "mbed.h"
wim 3:fa18169dd7e6 184 * #include "mbed_logo.h"
wim 3:fa18169dd7e6 185 * #include "SSD1308.h"
wim 3:fa18169dd7e6 186
wim 3:fa18169dd7e6 187 * //Pin Defines for I2C Bus
wim 3:fa18169dd7e6 188 * #define D_SDA p28
wim 3:fa18169dd7e6 189 * #define D_SCL p27
wim 3:fa18169dd7e6 190 * I2C i2c(D_SDA, D_SCL);
wim 3:fa18169dd7e6 191 *
wim 3:fa18169dd7e6 192 * // Host PC Communication channels
wim 3:fa18169dd7e6 193 * Serial pc(USBTX, USBRX); // tx, rx
wim 3:fa18169dd7e6 194 *
wim 3:fa18169dd7e6 195 * // Instantiate OLED
wim 5:e564cde8e03e 196 * SSD1308 oled = SSD1308(&i2c, SSD1308_SA0);
wim 3:fa18169dd7e6 197 *
wim 3:fa18169dd7e6 198 * int main() {
wim 3:fa18169dd7e6 199 * pc.printf("OLED test start\r");
wim 3:fa18169dd7e6 200 * oled.writeString(0, 0, "Hello World !");
wim 3:fa18169dd7e6 201 * // oled.printf("Hello World !");
wim 3:fa18169dd7e6 202 *
wim 3:fa18169dd7e6 203 * oled.fillDisplay(0xAA);
wim 3:fa18169dd7e6 204 * oled.setDisplayOff();
wim 3:fa18169dd7e6 205 * wait(1);
wim 3:fa18169dd7e6 206 * oled.setDisplayOn();
wim 3:fa18169dd7e6 207 *
wim 3:fa18169dd7e6 208 * oled.clearDisplay();
wim 3:fa18169dd7e6 209 * oled.setDisplayInverse();
wim 3:fa18169dd7e6 210 * wait(0.5);
wim 3:fa18169dd7e6 211 * oled.setDisplayNormal();
wim 3:fa18169dd7e6 212 *
wim 3:fa18169dd7e6 213 * oled.writeBitmap((uint8_t*) mbed_logo);
wim 3:fa18169dd7e6 214 *
wim 3:fa18169dd7e6 215 * pc.printf("OLED test done\r\n");
wim 3:fa18169dd7e6 216 * }
wim 3:fa18169dd7e6 217 *
wim 3:fa18169dd7e6 218 * @endcode
wim 3:fa18169dd7e6 219 */
wim 0:300d08d9b058 220 class SSD1308 : public Stream {
wim 0:300d08d9b058 221 public:
wim 0:300d08d9b058 222
wim 2:16c84a134393 223 /**
wim 2:16c84a134393 224 *@brief Constructor
wim 2:16c84a134393 225 *@param I2C &i2c reference to i2c,
wim 2:16c84a134393 226 *@param uint8_t deviceAddress slaveaddress (8bit to use for the controller (0x78 by default, assumes D/C# (pin 13) grounded)
wim 2:16c84a134393 227 */
wim 5:e564cde8e03e 228 SSD1308(I2C *i2c, uint8_t address = SSD1308_DEF_SA);
wim 0:300d08d9b058 229
wim 0:300d08d9b058 230 // High Level methods
wim 2:16c84a134393 231
wim 2:16c84a134393 232 /** @brief High level Init, most settings remain at Power-On reset value
wim 2:16c84a134393 233 */
wim 0:300d08d9b058 234 void initialize();
wim 0:300d08d9b058 235
wim 2:16c84a134393 236 /** @brief clear the display
wim 2:16c84a134393 237 */
wim 0:300d08d9b058 238 void clearDisplay();
wim 2:16c84a134393 239
wim 2:16c84a134393 240
wim 2:16c84a134393 241 /** @brief fill the display
wim 2:16c84a134393 242 * @param uint8_t pattern fillpattern vertical patch or 8 bits
wim 4:df92b0c0cb92 243 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 4:df92b0c0cb92 244 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 4:df92b0c0cb92 245 * @param uint8_t start_col begin column (0..MAX_COL)
wim 4:df92b0c0cb92 246 * @param uint8_t end_col end column (start_col..MAX_COL)
wim 2:16c84a134393 247 */
wim 0:300d08d9b058 248 void fillDisplay(uint8_t pattern = 0x00,
wim 0:300d08d9b058 249 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
wim 0:300d08d9b058 250 uint8_t start_col=0, uint8_t end_col=MAX_COL);
wim 2:16c84a134393 251
wim 2:16c84a134393 252
wim 2:16c84a134393 253 /** @brief write a bitmap to the display
wim 2:16c84a134393 254 * @param uint8_t* data pointer to bitmap
wim 2:16c84a134393 255 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 256 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 257 * @param uint8_t start_col begin column (0..MAX_COL)
wim 2:16c84a134393 258 * @param uint8_t end_col end column (start_col..MAX_COL)
wim 2:16c84a134393 259 */
wim 0:300d08d9b058 260 void writeBitmap(uint8_t* data,
wim 0:300d08d9b058 261 uint8_t start_page=0, uint8_t end_page=MAX_PAGE,
wim 0:300d08d9b058 262 uint8_t start_col=0, uint8_t end_col=MAX_COL);
wim 0:300d08d9b058 263
wim 2:16c84a134393 264 /** @brief write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
wim 2:16c84a134393 265 * @param uint8_t page begin page (0..MAX_PAGE)
wim 2:16c84a134393 266 * @param uint8_t col begin column (0..MAX_COL)
wim 2:16c84a134393 267 * @param int percentage value (0..100)
wim 2:16c84a134393 268 */
wim 2:16c84a134393 269 void writeProgressBar(uint8_t page, uint8_t col, int percentage);
wim 1:b7e8f5139026 270
wim 2:16c84a134393 271
wim 2:16c84a134393 272 /** @brief write a level meter to the display, Width is (PRG_MAX_SCALE + 2) pixels
wim 2:16c84a134393 273 * @param uint8_t page begin page (0..MAX_PAGE)
wim 2:16c84a134393 274 * @param uint8_t col begin column (0..MAX_COL)
wim 2:16c84a134393 275 * @param int percentage value (0..100)
wim 2:16c84a134393 276 */
wim 2:16c84a134393 277 void writeLevelBar(uint8_t page, uint8_t col, int percentage);
wim 1:b7e8f5139026 278
wim 0:300d08d9b058 279 //void setXY(uint8_t, uint8_t y);
wim 0:300d08d9b058 280
wim 0:300d08d9b058 281 // Select inverted or normal text
wim 0:300d08d9b058 282 void setInverted(bool inverted) { _inverted = inverted; };
wim 0:300d08d9b058 283
wim 2:16c84a134393 284 /** @brief Write single character to the display using the 8x8 fontable
wim 2:16c84a134393 285 * @brief Start at current cursor location
wim 2:16c84a134393 286 * @param char chr character to write
wim 2:16c84a134393 287 */
wim 0:300d08d9b058 288 void writeChar(char chr);
wim 0:300d08d9b058 289
wim 2:16c84a134393 290 /** @brief Write large character (16x24 font)
wim 2:16c84a134393 291 * @param uint8_t row row number (0...MAX_ROW)
wim 2:16c84a134393 292 * @param uint8_t col column number (0...MAX_COL)
wim 2:16c84a134393 293 * @param char chr Used for displaying numbers 0 - 9 and '+', '-', '.'
wim 2:16c84a134393 294 */
wim 0:300d08d9b058 295 void writeBigChar(uint8_t row, uint8_t col, char chr);
wim 0:300d08d9b058 296
wim 2:16c84a134393 297 /** @brief Write a string to the display using the 8x8 font
wim 2:16c84a134393 298 * @brief Start at selected cursor location, text will wrap around until it is done
wim 2:16c84a134393 299 * @param uint8_t row row number (0...ROWS/FONT_HEIGHT)
wim 2:16c84a134393 300 * @param uint8_t col column number (0...COLUMNS/FONT_WIDTH)
wim 2:16c84a134393 301 * @param const char * text pointer to text
wim 2:16c84a134393 302 */
wim 2:16c84a134393 303 void writeString(uint8_t row, uint8_t col, const char* txt);
wim 2:16c84a134393 304
wim 0:300d08d9b058 305 // Stream implementation - provides printf() interface
wim 0:300d08d9b058 306 // You would otherwise be forced to use writeChar() or writeString()
wim 0:300d08d9b058 307 virtual int _putc(int value) { writeChar(value); return 1; };
wim 0:300d08d9b058 308 virtual int _getc() { return -1; };
wim 0:300d08d9b058 309
wim 0:300d08d9b058 310 // Future extension with graphics features
wim 0:300d08d9b058 311 // this must be defined by the subclass
wim 0:300d08d9b058 312 // virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
wim 0:300d08d9b058 313
wim 0:300d08d9b058 314 // Medium Level methods
wim 2:16c84a134393 315
wim 2:16c84a134393 316 /** @brief Set Horizontal Addressing Mode (cursor incr left-to-right, top-to-bottom)
wim 2:16c84a134393 317 *
wim 2:16c84a134393 318 */
wim 0:300d08d9b058 319 void setHorizontalAddressingMode();
wim 2:16c84a134393 320
wim 2:16c84a134393 321 /** @brief Set Vertical Addressing Mode (cursor incr top-to-bottom, left-to-right)
wim 2:16c84a134393 322 *
wim 2:16c84a134393 323 */
wim 0:300d08d9b058 324 void setVerticalAddressingMode();
wim 0:300d08d9b058 325
wim 2:16c84a134393 326 /** @brief Set Page Addressing Mode (cursor incr left-to-right)
wim 2:16c84a134393 327 *
wim 2:16c84a134393 328 */
wim 2:16c84a134393 329 void setPageAddressingMode();
wim 2:16c84a134393 330
wim 2:16c84a134393 331 /** @brief Set Addressing Mode
wim 2:16c84a134393 332 * @param uint8_t mode
wim 2:16c84a134393 333 */
wim 2:16c84a134393 334 void setMemoryAddressingMode(uint8_t mode);
wim 2:16c84a134393 335
wim 2:16c84a134393 336
wim 2:16c84a134393 337 /**
wim 2:16c84a134393 338 * @brief Set Column Start (for Page Addressing Mode only)
wim 2:16c84a134393 339 * @param uint8_t column column start (valid range 0..MAX_COLS)
wim 2:16c84a134393 340 */
wim 2:16c84a134393 341 void setColumnStartForPageAddressingMode(uint8_t column);
wim 0:300d08d9b058 342
wim 2:16c84a134393 343 /**
wim 2:16c84a134393 344 * @brief Set Page Start (for Page Addressing Mode only)
wim 2:16c84a134393 345 * @param uint8_t page page start (valid range PAGE0 - PAGE7)
wim 2:16c84a134393 346 */
wim 2:16c84a134393 347 void setPageStartForPageAddressingMode(uint8_t page);
wim 2:16c84a134393 348
wim 2:16c84a134393 349
wim 2:16c84a134393 350
wim 2:16c84a134393 351 /** @param uint8_t start startcolumn (valid range 0..MAX_COL)
wim 2:16c84a134393 352 * @param uint8_t end endcolumn (valid range start..MAX_COL)
wim 2:16c84a134393 353 */
wim 0:300d08d9b058 354 void setColumnAddress(uint8_t start, uint8_t end);
wim 0:300d08d9b058 355
wim 2:16c84a134393 356 /** @param uint8_t start startpage (valid range 0..MAX_PAGE)
wim 2:16c84a134393 357 * @param uint8_t end endpage (valid range start..MAX_PAGE)
wim 2:16c84a134393 358 */
wim 0:300d08d9b058 359 void setPageAddress(uint8_t start, uint8_t end);
wim 0:300d08d9b058 360
wim 2:16c84a134393 361
wim 2:16c84a134393 362 /**
wim 2:16c84a134393 363 * @brief Set Display StartLine, takes one byte, 0x00-0x3F
wim 2:16c84a134393 364 * @param uint8_t line startline (valid range 0..MAX_ROWS)
wim 2:16c84a134393 365 */
wim 0:300d08d9b058 366 void setDisplayStartLine(uint8_t line);
wim 0:300d08d9b058 367
wim 2:16c84a134393 368 /** @brief Set Contrast
wim 2:16c84a134393 369 * @param uint8_t contrast (valid range 0x00 (lowest) - 0xFF (highest))
wim 2:16c84a134393 370 */
wim 0:300d08d9b058 371 void setContrastControl(uint8_t contrast);
wim 2:16c84a134393 372
wim 2:16c84a134393 373
wim 2:16c84a134393 374 /** @brief Shows All Pixels On
wim 2:16c84a134393 375 */
wim 2:16c84a134393 376 void setEntireDisplayOn();
wim 0:300d08d9b058 377
wim 2:16c84a134393 378 /** @brief Shows Pixels as RAM content
wim 2:16c84a134393 379 */
wim 0:300d08d9b058 380 void setEntireDisplayRAM();
wim 2:16c84a134393 381
wim 2:16c84a134393 382 /** @brief Shows Pixels On or as RAM content
wim 2:16c84a134393 383 * @param bool on (true is All on, false is RAM content)
wim 2:16c84a134393 384 */
wim 0:300d08d9b058 385 void setEntireDisplay(bool on);
wim 0:300d08d9b058 386
wim 2:16c84a134393 387
wim 2:16c84a134393 388 // @brief Set Display line MPX Ratio, takes one byte, 0x00-0x3F
wim 2:16c84a134393 389 // @param uint8_t lines (valid range 0..MAX_ROWS)
wim 2:16c84a134393 390 void setMultiplexRatio(uint8_t lines);
wim 2:16c84a134393 391
wim 2:16c84a134393 392
wim 2:16c84a134393 393 /** @brief Sets Internal Iref
wim 2:16c84a134393 394 */
wim 0:300d08d9b058 395 void setInternalIref();
wim 2:16c84a134393 396
wim 2:16c84a134393 397 /** @brief Sets External Iref (default)
wim 2:16c84a134393 398 */
wim 0:300d08d9b058 399 void setExternalIref();
wim 2:16c84a134393 400
wim 2:16c84a134393 401
wim 2:16c84a134393 402 /** @brief Enable Display
wim 2:16c84a134393 403 */
wim 0:300d08d9b058 404 void setDisplayOn();
wim 2:16c84a134393 405
wim 2:16c84a134393 406 /** @brief Disable Display
wim 2:16c84a134393 407 */
wim 0:300d08d9b058 408 void setDisplayOff();
wim 2:16c84a134393 409
wim 2:16c84a134393 410 /** @brief Enable or Disable Display
wim 2:16c84a134393 411 * @param bool on
wim 2:16c84a134393 412 */
wim 0:300d08d9b058 413 void setDisplayPower(bool on);
wim 0:300d08d9b058 414
wim 2:16c84a134393 415 /** @brief Show White pixels on Black background
wim 2:16c84a134393 416 */
wim 0:300d08d9b058 417 void setDisplayNormal();
wim 2:16c84a134393 418
wim 2:16c84a134393 419 /** @brief Show Black pixels on White background
wim 2:16c84a134393 420 */
wim 0:300d08d9b058 421 void setDisplayInverse();
wim 2:16c84a134393 422
wim 2:16c84a134393 423 /** @brief Blink display by fading in and out over a set number of frames
wim 2:16c84a134393 424 * @param bool on
wim 2:16c84a134393 425 */
wim 2:16c84a134393 426 void setDisplayBlink(bool on);
wim 0:300d08d9b058 427
wim 2:16c84a134393 428 /** @brief Fade out display in set number of frames
wim 2:16c84a134393 429 * @param bool on
wim 2:16c84a134393 430 */
wim 0:300d08d9b058 431 void setDisplayFade(bool on);
wim 0:300d08d9b058 432
wim 2:16c84a134393 433 /** @brief Display Flip (Left/Right, Up/Down)
wim 2:16c84a134393 434 * @param bool left flip Left/Right
wim 2:16c84a134393 435 * @param bool down flip Up/Down
wim 2:16c84a134393 436 */
wim 0:300d08d9b058 437 void setDisplayFlip(bool left, bool down);
wim 0:300d08d9b058 438
wim 2:16c84a134393 439 // Set vertical shift by COM from 0 - 63 (0x00 - 0x3F) (Reset = 0x00)
wim 0:300d08d9b058 440 void setDisplayOffset(uint8_t offset);
wim 0:300d08d9b058 441
wim 2:16c84a134393 442 // Oscillator freq 0x00-0x0F (reset 0x08)
wim 0:300d08d9b058 443 // Divide ratio 0x00-0x0F, value +1 (reset 0x00)
wim 0:300d08d9b058 444 void setDisplayClock(uint8_t divideRatio, uint8_t oscFreq);
wim 0:300d08d9b058 445
wim 0:300d08d9b058 446 // Phase1 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
wim 0:300d08d9b058 447 // Phase2 0x01-0x0F period of up to 15 DCLK clocks (reset 0x02, 0 is invalid)
wim 0:300d08d9b058 448 void setPrechargePeriod(uint8_t phase1, uint8_t phase2);
wim 0:300d08d9b058 449
wim 2:16c84a134393 450 // See defines above for levels
wim 0:300d08d9b058 451 void setVcomhDeselectLevel(uint8_t level);
wim 2:16c84a134393 452
wim 2:16c84a134393 453
wim 0:300d08d9b058 454 // Command for no-operation
wim 0:300d08d9b058 455 void nop();
wim 0:300d08d9b058 456
wim 2:16c84a134393 457
wim 2:16c84a134393 458 /** @brief Horizontal scroll by one column per interval
wim 2:16c84a134393 459 * @param bool left select Left/Right scroll
wim 2:16c84a134393 460 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 461 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 462 * @param uint8_t interval scroll interval in frames (see codes above)
wim 2:16c84a134393 463 */
wim 2:16c84a134393 464 void setContinuousHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page, uint8_t interval);
wim 2:16c84a134393 465
wim 2:16c84a134393 466
wim 2:16c84a134393 467 /** @brief Horizontal and Vertical scroll by one column per interval
wim 2:16c84a134393 468 * @param bool left select Left/Right scroll
wim 2:16c84a134393 469 * @param uint8_t start_page begin page (0..MAX_PAGE)
wim 2:16c84a134393 470 * @param uint8_t end_page end page (start_page..MAX_PAGE)
wim 2:16c84a134393 471 * @param uint8_t offset vert offset (0x01..0x63)
wim 2:16c84a134393 472 * @param uint8_t interval scroll interval in frames (see codes above)
wim 2:16c84a134393 473 */
wim 2:16c84a134393 474 void setContinuousVerticalAndHorizontalScroll(bool left, uint8_t start_page, uint8_t end_page,
wim 2:16c84a134393 475 uint8_t offset, uint8_t interval);
wim 0:300d08d9b058 476
wim 2:16c84a134393 477 /** @brief Activate or Deactivate Horizontal and Vertical scroll
wim 2:16c84a134393 478 * @brief Note: after deactivating scrolling, the RAM data needs to be rewritten
wim 2:16c84a134393 479 * @param bool on activate scroll
wim 2:16c84a134393 480 */
wim 2:16c84a134393 481 void setDisplayScroll(bool on);
wim 0:300d08d9b058 482
wim 2:16c84a134393 483
wim 2:16c84a134393 484 /** @brief Set Vertical scroll area
wim 2:16c84a134393 485 * @param uint8_t topRowsFixed fixed rows (0..MAX_ROW)
wim 2:16c84a134393 486 * @param uint8_t scrollRowsoffset scroll rows (topRowsFixed..MAX_ROW)
wim 2:16c84a134393 487 */
wim 0:300d08d9b058 488 void setVerticalScrollArea(uint8_t topRowsFixed, uint8_t scrollRows);
wim 0:300d08d9b058 489
wim 0:300d08d9b058 490 private:
wim 0:300d08d9b058 491
wim 0:300d08d9b058 492 // Low Level methods
wim 2:16c84a134393 493
wim 2:16c84a134393 494 /** @brief Write command that has no parameters
wim 2:16c84a134393 495 */
wim 2:16c84a134393 496 void _sendCommand(uint8_t command);
wim 2:16c84a134393 497
wim 2:16c84a134393 498 /** @brief Write command that has one parameter
wim 2:16c84a134393 499 */
wim 0:300d08d9b058 500 void _sendCommand(uint8_t command, uint8_t param1);
wim 2:16c84a134393 501
wim 2:16c84a134393 502 /** @brief Write command that has two parameters
wim 2:16c84a134393 503 */
wim 0:300d08d9b058 504 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2);
wim 0:300d08d9b058 505 // void sendCommands(uint8_t len, uint8_t* buf);
wim 2:16c84a134393 506
wim 2:16c84a134393 507 /** @brief Write command that has five parameters
wim 2:16c84a134393 508 */
wim 2:16c84a134393 509 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
wim 2:16c84a134393 510 uint8_t param3, uint8_t param4,
wim 2:16c84a134393 511 uint8_t param5);
wim 2:16c84a134393 512
wim 2:16c84a134393 513 /** @brief Write command that has six parameters
wim 2:16c84a134393 514 */
wim 2:16c84a134393 515 void _sendCommand(uint8_t command, uint8_t param1, uint8_t param2,
wim 2:16c84a134393 516 uint8_t param3, uint8_t param4,
wim 2:16c84a134393 517 uint8_t param5, uint8_t param6);
wim 0:300d08d9b058 518
wim 2:16c84a134393 519 /** @brief Write databyte to display
wim 2:16c84a134393 520 * @brief Start at current cursor location
wim 2:16c84a134393 521 * @param uint8_t data databyte to write
wim 2:16c84a134393 522 */
wim 0:300d08d9b058 523 void _sendData(uint8_t data);
wim 2:16c84a134393 524
wim 2:16c84a134393 525 /** @brief Write len bytes from buffer data to display,
wim 2:16c84a134393 526 * @brief Start at current cursor location
wim 2:16c84a134393 527 * @param uint8_t len number of bytes to write
wim 2:16c84a134393 528 * @param uint8_t* data pointer to data
wim 2:16c84a134393 529 */
wim 0:300d08d9b058 530 void _sendData(uint8_t len, uint8_t* data);
wim 0:300d08d9b058 531
wim 2:16c84a134393 532 /** @brief Low level Init
wim 2:16c84a134393 533 * @brief Init the configuration registers in accordance with the datasheet
wim 2:16c84a134393 534 */
wim 0:300d08d9b058 535 void _init();
wim 0:300d08d9b058 536
wim 5:e564cde8e03e 537 I2C *_i2c; // I2C bus reference
wim 1:b7e8f5139026 538 uint8_t _readOpcode; // contains the I2C address of the device
wim 1:b7e8f5139026 539 uint8_t _writeOpcode; // contains the I2C address of the device
wim 0:300d08d9b058 540
wim 0:300d08d9b058 541 bool _inverted; // inverted or normal text
wim 0:300d08d9b058 542 };
wim 0:300d08d9b058 543
wim 0:300d08d9b058 544 #endif