Seed I2C OLED library for mbed
SeeedGrayOLED.cpp@0:e14364aac2ca, 2017-01-25 (annotated)
- Committer:
- jacobjohnson
- Date:
- Wed Jan 25 18:33:22 2017 +0000
- Revision:
- 0:e14364aac2ca
Seeed OLED Library for mbed;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jacobjohnson | 0:e14364aac2ca | 1 | /* |
jacobjohnson | 0:e14364aac2ca | 2 | * SeeedGrayOLED.cpp |
jacobjohnson | 0:e14364aac2ca | 3 | * SSD1327 Gray OLED Driver Library for SSD1327 |
jacobjohnson | 0:e14364aac2ca | 4 | * |
jacobjohnson | 0:e14364aac2ca | 5 | * Copyright (c) 2011 seeed technology inc. |
jacobjohnson | 0:e14364aac2ca | 6 | * Author : Visweswara R |
jacobjohnson | 0:e14364aac2ca | 7 | * Create Time : Dec 2011 |
jacobjohnson | 0:e14364aac2ca | 8 | * Change Log : |
jacobjohnson | 0:e14364aac2ca | 9 | * |
jacobjohnson | 0:e14364aac2ca | 10 | * This library is free software; you can redistribute it and/or |
jacobjohnson | 0:e14364aac2ca | 11 | * modify it under the terms of the GNU Lesser General Public |
jacobjohnson | 0:e14364aac2ca | 12 | * License as published by the Free Software Foundation; either |
jacobjohnson | 0:e14364aac2ca | 13 | * version 2.1 of the License, or (at your option) any later version. |
jacobjohnson | 0:e14364aac2ca | 14 | * |
jacobjohnson | 0:e14364aac2ca | 15 | * This library is distributed in the hope that it will be useful, |
jacobjohnson | 0:e14364aac2ca | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
jacobjohnson | 0:e14364aac2ca | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
jacobjohnson | 0:e14364aac2ca | 18 | * Lesser General Public License for more details. |
jacobjohnson | 0:e14364aac2ca | 19 | * |
jacobjohnson | 0:e14364aac2ca | 20 | * You should have received a copy of the GNU Lesser General Public |
jacobjohnson | 0:e14364aac2ca | 21 | * License along with this library; if not, write to the Free Software |
jacobjohnson | 0:e14364aac2ca | 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
jacobjohnson | 0:e14364aac2ca | 23 | */ |
jacobjohnson | 0:e14364aac2ca | 24 | |
jacobjohnson | 0:e14364aac2ca | 25 | #include "mbed.h" |
jacobjohnson | 0:e14364aac2ca | 26 | #include "SeeedGrayOLED.h" |
jacobjohnson | 0:e14364aac2ca | 27 | #include <stdio.h> |
jacobjohnson | 0:e14364aac2ca | 28 | #include <string.h> |
jacobjohnson | 0:e14364aac2ca | 29 | |
jacobjohnson | 0:e14364aac2ca | 30 | // 8x8 Font ASCII 32 - 127 Implemented |
jacobjohnson | 0:e14364aac2ca | 31 | // Users can modify this to support more characters(glyphs) |
jacobjohnson | 0:e14364aac2ca | 32 | // BasicFont is placed in code memory. |
jacobjohnson | 0:e14364aac2ca | 33 | |
jacobjohnson | 0:e14364aac2ca | 34 | // This font can be freely used without any restriction(It is placed in public domain) |
jacobjohnson | 0:e14364aac2ca | 35 | // const unsigned char BasicFont[][8] PROGMEM= |
jacobjohnson | 0:e14364aac2ca | 36 | |
jacobjohnson | 0:e14364aac2ca | 37 | |
jacobjohnson | 0:e14364aac2ca | 38 | const uint8_t BasicFont[][8] = { |
jacobjohnson | 0:e14364aac2ca | 39 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 40 | {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 41 | {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 42 | {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 43 | {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 44 | {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 45 | {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 46 | {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 47 | {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 48 | {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 49 | {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 50 | {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 51 | {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 52 | {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 53 | {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 54 | {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 55 | {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 56 | {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 57 | {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 58 | {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 59 | {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 60 | {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 61 | {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 62 | {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 63 | {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 64 | {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 65 | {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 66 | {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 67 | {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 68 | {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 69 | {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 70 | {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 71 | {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 72 | {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 73 | {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 74 | {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 75 | {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 76 | {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 77 | {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 78 | {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 79 | {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 80 | {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 81 | {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 82 | {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 83 | {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 84 | {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 85 | {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 86 | {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 87 | {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 88 | {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 89 | {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 90 | {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 91 | {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 92 | {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 93 | {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 94 | {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 95 | {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 96 | {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 97 | {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 98 | {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 99 | {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 100 | {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 101 | {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 102 | {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 103 | {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 104 | {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 105 | {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 106 | {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 107 | {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 108 | {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 109 | {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 110 | {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 111 | {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 112 | {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 113 | {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 114 | {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 115 | {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 116 | {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 117 | {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 118 | {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 119 | {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 120 | {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 121 | {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 122 | {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 123 | {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 124 | {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 125 | {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 126 | {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 127 | {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 128 | {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 129 | {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 130 | {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 131 | {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 132 | {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 133 | {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, |
jacobjohnson | 0:e14364aac2ca | 134 | {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} |
jacobjohnson | 0:e14364aac2ca | 135 | }; |
jacobjohnson | 0:e14364aac2ca | 136 | |
jacobjohnson | 0:e14364aac2ca | 137 | |
jacobjohnson | 0:e14364aac2ca | 138 | SeeedGrayOLED::SeeedGrayOLED(PinName sda, PinName scl): |
jacobjohnson | 0:e14364aac2ca | 139 | _device(sda, scl) |
jacobjohnson | 0:e14364aac2ca | 140 | { |
jacobjohnson | 0:e14364aac2ca | 141 | } |
jacobjohnson | 0:e14364aac2ca | 142 | |
jacobjohnson | 0:e14364aac2ca | 143 | |
jacobjohnson | 0:e14364aac2ca | 144 | void SeeedGrayOLED::init(void) |
jacobjohnson | 0:e14364aac2ca | 145 | { |
jacobjohnson | 0:e14364aac2ca | 146 | sendCommand(0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands |
jacobjohnson | 0:e14364aac2ca | 147 | sendCommand(0x12); |
jacobjohnson | 0:e14364aac2ca | 148 | sendCommand(0xAE); // Set display off |
jacobjohnson | 0:e14364aac2ca | 149 | sendCommand(0xA8); // set multiplex ratio |
jacobjohnson | 0:e14364aac2ca | 150 | sendCommand(0x5F); // 96 |
jacobjohnson | 0:e14364aac2ca | 151 | sendCommand(0xA1); // set display start line |
jacobjohnson | 0:e14364aac2ca | 152 | sendCommand(0x00); |
jacobjohnson | 0:e14364aac2ca | 153 | sendCommand(0xA2); // set display offset |
jacobjohnson | 0:e14364aac2ca | 154 | sendCommand(0x60); |
jacobjohnson | 0:e14364aac2ca | 155 | sendCommand(0xA0); // set remap |
jacobjohnson | 0:e14364aac2ca | 156 | sendCommand(0x46); |
jacobjohnson | 0:e14364aac2ca | 157 | sendCommand(0xAB); // set vdd internal |
jacobjohnson | 0:e14364aac2ca | 158 | sendCommand(0x01); // |
jacobjohnson | 0:e14364aac2ca | 159 | sendCommand(0x81); // set contrasr |
jacobjohnson | 0:e14364aac2ca | 160 | sendCommand(0x53); // 100 nit |
jacobjohnson | 0:e14364aac2ca | 161 | sendCommand(0xB1); // Set Phase Length |
jacobjohnson | 0:e14364aac2ca | 162 | sendCommand(0X51); // |
jacobjohnson | 0:e14364aac2ca | 163 | sendCommand(0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency |
jacobjohnson | 0:e14364aac2ca | 164 | sendCommand(0x01); |
jacobjohnson | 0:e14364aac2ca | 165 | sendCommand(0xB9); // |
jacobjohnson | 0:e14364aac2ca | 166 | sendCommand(0xBC); // set pre_charge voltage/VCOMH |
jacobjohnson | 0:e14364aac2ca | 167 | sendCommand(0x08); // (0x08); |
jacobjohnson | 0:e14364aac2ca | 168 | sendCommand(0xBE); // set VCOMH |
jacobjohnson | 0:e14364aac2ca | 169 | sendCommand(0X07); // (0x07); |
jacobjohnson | 0:e14364aac2ca | 170 | sendCommand(0xB6); // Set second pre-charge period |
jacobjohnson | 0:e14364aac2ca | 171 | sendCommand(0x01); // |
jacobjohnson | 0:e14364aac2ca | 172 | sendCommand(0xD5); // enable second precharge and enternal vsl |
jacobjohnson | 0:e14364aac2ca | 173 | sendCommand(0X62); // (0x62); |
jacobjohnson | 0:e14364aac2ca | 174 | sendCommand(0xA4); // Set Normal Display Mode |
jacobjohnson | 0:e14364aac2ca | 175 | sendCommand(0x2E); // Deactivate Scroll |
jacobjohnson | 0:e14364aac2ca | 176 | sendCommand(0xAF); // Switch on display |
jacobjohnson | 0:e14364aac2ca | 177 | wait_ms(100); |
jacobjohnson | 0:e14364aac2ca | 178 | |
jacobjohnson | 0:e14364aac2ca | 179 | // Row Address |
jacobjohnson | 0:e14364aac2ca | 180 | sendCommand(0x75); // Set Row Address |
jacobjohnson | 0:e14364aac2ca | 181 | sendCommand(0x00); // Start 0 |
jacobjohnson | 0:e14364aac2ca | 182 | sendCommand(0x5f); // End 95 |
jacobjohnson | 0:e14364aac2ca | 183 | |
jacobjohnson | 0:e14364aac2ca | 184 | |
jacobjohnson | 0:e14364aac2ca | 185 | // Column Address |
jacobjohnson | 0:e14364aac2ca | 186 | sendCommand(0x15); // Set Column Address |
jacobjohnson | 0:e14364aac2ca | 187 | sendCommand(0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED |
jacobjohnson | 0:e14364aac2ca | 188 | sendCommand(0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments) |
jacobjohnson | 0:e14364aac2ca | 189 | |
jacobjohnson | 0:e14364aac2ca | 190 | // Init gray level for text. Default:Brightest White |
jacobjohnson | 0:e14364aac2ca | 191 | grayH= 0xF0; |
jacobjohnson | 0:e14364aac2ca | 192 | grayL= 0x0F; |
jacobjohnson | 0:e14364aac2ca | 193 | } |
jacobjohnson | 0:e14364aac2ca | 194 | |
jacobjohnson | 0:e14364aac2ca | 195 | void SeeedGrayOLED::sendCommand(unsigned char command) |
jacobjohnson | 0:e14364aac2ca | 196 | { |
jacobjohnson | 0:e14364aac2ca | 197 | int transmissionSuccessful; |
jacobjohnson | 0:e14364aac2ca | 198 | _device.start(); |
jacobjohnson | 0:e14364aac2ca | 199 | transmissionSuccessful = _device.write(SeeedGrayOLED_Address << 1); |
jacobjohnson | 0:e14364aac2ca | 200 | Thread::wait(5); |
jacobjohnson | 0:e14364aac2ca | 201 | transmissionSuccessful |= _device.write(SeeedGrayOLED_Command_Mode); |
jacobjohnson | 0:e14364aac2ca | 202 | Thread::wait(5); |
jacobjohnson | 0:e14364aac2ca | 203 | transmissionSuccessful |= _device.write(command); |
jacobjohnson | 0:e14364aac2ca | 204 | Thread::wait(5); |
jacobjohnson | 0:e14364aac2ca | 205 | _device.stop(); |
jacobjohnson | 0:e14364aac2ca | 206 | Thread::wait(50); |
jacobjohnson | 0:e14364aac2ca | 207 | // return (transmissionSuccessful); |
jacobjohnson | 0:e14364aac2ca | 208 | } |
jacobjohnson | 0:e14364aac2ca | 209 | |
jacobjohnson | 0:e14364aac2ca | 210 | void SeeedGrayOLED::setContrastLevel(unsigned char ContrastLevel) |
jacobjohnson | 0:e14364aac2ca | 211 | { |
jacobjohnson | 0:e14364aac2ca | 212 | sendCommand(SeeedGrayOLED_Set_ContrastLevel_Cmd); |
jacobjohnson | 0:e14364aac2ca | 213 | sendCommand(ContrastLevel); |
jacobjohnson | 0:e14364aac2ca | 214 | } |
jacobjohnson | 0:e14364aac2ca | 215 | |
jacobjohnson | 0:e14364aac2ca | 216 | void SeeedGrayOLED::setHorizontalMode() |
jacobjohnson | 0:e14364aac2ca | 217 | { |
jacobjohnson | 0:e14364aac2ca | 218 | sendCommand(0xA0); // remap to |
jacobjohnson | 0:e14364aac2ca | 219 | sendCommand(0x42); // horizontal mode |
jacobjohnson | 0:e14364aac2ca | 220 | |
jacobjohnson | 0:e14364aac2ca | 221 | // Row Address |
jacobjohnson | 0:e14364aac2ca | 222 | sendCommand(0x75); // Set Row Address |
jacobjohnson | 0:e14364aac2ca | 223 | sendCommand(0x00); // Start 0 |
jacobjohnson | 0:e14364aac2ca | 224 | sendCommand(0x5f); // End 95 |
jacobjohnson | 0:e14364aac2ca | 225 | |
jacobjohnson | 0:e14364aac2ca | 226 | // Column Address |
jacobjohnson | 0:e14364aac2ca | 227 | sendCommand(0x15); // Set Column Address |
jacobjohnson | 0:e14364aac2ca | 228 | sendCommand(0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED |
jacobjohnson | 0:e14364aac2ca | 229 | sendCommand(0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments) |
jacobjohnson | 0:e14364aac2ca | 230 | } |
jacobjohnson | 0:e14364aac2ca | 231 | |
jacobjohnson | 0:e14364aac2ca | 232 | void SeeedGrayOLED::setVerticalMode() |
jacobjohnson | 0:e14364aac2ca | 233 | { |
jacobjohnson | 0:e14364aac2ca | 234 | sendCommand(0xA0); // remap to |
jacobjohnson | 0:e14364aac2ca | 235 | sendCommand(0x46); // Vertical mode |
jacobjohnson | 0:e14364aac2ca | 236 | } |
jacobjohnson | 0:e14364aac2ca | 237 | |
jacobjohnson | 0:e14364aac2ca | 238 | void SeeedGrayOLED::setTextXY(unsigned char Row, unsigned char Column) |
jacobjohnson | 0:e14364aac2ca | 239 | { |
jacobjohnson | 0:e14364aac2ca | 240 | //Column Address |
jacobjohnson | 0:e14364aac2ca | 241 | sendCommand(0x15); /* Set Column Address */ |
jacobjohnson | 0:e14364aac2ca | 242 | sendCommand(0x08+(Column*4)); /* Start Column: Start from 8 */ |
jacobjohnson | 0:e14364aac2ca | 243 | sendCommand(0x37); /* End Column */ |
jacobjohnson | 0:e14364aac2ca | 244 | // Row Address |
jacobjohnson | 0:e14364aac2ca | 245 | sendCommand(0x75); /* Set Row Address */ |
jacobjohnson | 0:e14364aac2ca | 246 | sendCommand(0x00+(Row*8)); /* Start Row*/ |
jacobjohnson | 0:e14364aac2ca | 247 | sendCommand(0x07+(Row*8)); /* End Row*/ |
jacobjohnson | 0:e14364aac2ca | 248 | } |
jacobjohnson | 0:e14364aac2ca | 249 | |
jacobjohnson | 0:e14364aac2ca | 250 | void SeeedGrayOLED::clearDisplay() |
jacobjohnson | 0:e14364aac2ca | 251 | { |
jacobjohnson | 0:e14364aac2ca | 252 | unsigned char i,j; |
jacobjohnson | 0:e14364aac2ca | 253 | for(j=0;j<48;j++) |
jacobjohnson | 0:e14364aac2ca | 254 | { |
jacobjohnson | 0:e14364aac2ca | 255 | for(i=0;i<96;i++) //clear all columns |
jacobjohnson | 0:e14364aac2ca | 256 | { |
jacobjohnson | 0:e14364aac2ca | 257 | sendData(0x00); |
jacobjohnson | 0:e14364aac2ca | 258 | } |
jacobjohnson | 0:e14364aac2ca | 259 | } |
jacobjohnson | 0:e14364aac2ca | 260 | |
jacobjohnson | 0:e14364aac2ca | 261 | } |
jacobjohnson | 0:e14364aac2ca | 262 | |
jacobjohnson | 0:e14364aac2ca | 263 | void SeeedGrayOLED::sendData(unsigned char Data) |
jacobjohnson | 0:e14364aac2ca | 264 | { |
jacobjohnson | 0:e14364aac2ca | 265 | int transmissionSuccessful; |
jacobjohnson | 0:e14364aac2ca | 266 | _device.start(); |
jacobjohnson | 0:e14364aac2ca | 267 | transmissionSuccessful = _device.write(SeeedGrayOLED_Address << 1); |
jacobjohnson | 0:e14364aac2ca | 268 | transmissionSuccessful |= _device.write(SeeedGrayOLED_Data_Mode); |
jacobjohnson | 0:e14364aac2ca | 269 | transmissionSuccessful |= _device.write(Data); |
jacobjohnson | 0:e14364aac2ca | 270 | _device.stop(); |
jacobjohnson | 0:e14364aac2ca | 271 | // return (transmissionSuccessful); |
jacobjohnson | 0:e14364aac2ca | 272 | } |
jacobjohnson | 0:e14364aac2ca | 273 | |
jacobjohnson | 0:e14364aac2ca | 274 | void SeeedGrayOLED::setGrayLevel(unsigned char grayLevel) |
jacobjohnson | 0:e14364aac2ca | 275 | { |
jacobjohnson | 0:e14364aac2ca | 276 | grayH = (grayLevel << 4) & 0xF0; |
jacobjohnson | 0:e14364aac2ca | 277 | grayL = grayLevel & 0x0F; |
jacobjohnson | 0:e14364aac2ca | 278 | } |
jacobjohnson | 0:e14364aac2ca | 279 | |
jacobjohnson | 0:e14364aac2ca | 280 | void SeeedGrayOLED::putChar(unsigned char C) |
jacobjohnson | 0:e14364aac2ca | 281 | { |
jacobjohnson | 0:e14364aac2ca | 282 | if(C < 32 || C > 127) //Ignore non-printable ASCII characters. This can be modified for multilingual font. |
jacobjohnson | 0:e14364aac2ca | 283 | { |
jacobjohnson | 0:e14364aac2ca | 284 | C=' '; //Space |
jacobjohnson | 0:e14364aac2ca | 285 | } |
jacobjohnson | 0:e14364aac2ca | 286 | |
jacobjohnson | 0:e14364aac2ca | 287 | |
jacobjohnson | 0:e14364aac2ca | 288 | for(char i=0;i<8;i=i+2) |
jacobjohnson | 0:e14364aac2ca | 289 | { |
jacobjohnson | 0:e14364aac2ca | 290 | for(char j=0;j<8;j++) |
jacobjohnson | 0:e14364aac2ca | 291 | { |
jacobjohnson | 0:e14364aac2ca | 292 | // Character is constructed two pixel at a time using vertical mode from the default 8x8 font |
jacobjohnson | 0:e14364aac2ca | 293 | char c=0x00; |
jacobjohnson | 0:e14364aac2ca | 294 | char bit1=(BasicFont[C-32][i] >> j) & 0x01; |
jacobjohnson | 0:e14364aac2ca | 295 | char bit2=(BasicFont[C-32][i+1] >> j) & 0x01; |
jacobjohnson | 0:e14364aac2ca | 296 | // Each bit is changed to a nibble |
jacobjohnson | 0:e14364aac2ca | 297 | c|=(bit1)?grayH:0x00; |
jacobjohnson | 0:e14364aac2ca | 298 | c|=(bit2)?grayL:0x00; |
jacobjohnson | 0:e14364aac2ca | 299 | sendData(c); |
jacobjohnson | 0:e14364aac2ca | 300 | } |
jacobjohnson | 0:e14364aac2ca | 301 | } |
jacobjohnson | 0:e14364aac2ca | 302 | } |
jacobjohnson | 0:e14364aac2ca | 303 | |
jacobjohnson | 0:e14364aac2ca | 304 | void SeeedGrayOLED::putString(const char *String) |
jacobjohnson | 0:e14364aac2ca | 305 | { |
jacobjohnson | 0:e14364aac2ca | 306 | unsigned char i=0; |
jacobjohnson | 0:e14364aac2ca | 307 | while(String[i]) |
jacobjohnson | 0:e14364aac2ca | 308 | { |
jacobjohnson | 0:e14364aac2ca | 309 | putChar(String[i]); |
jacobjohnson | 0:e14364aac2ca | 310 | i++; |
jacobjohnson | 0:e14364aac2ca | 311 | } |
jacobjohnson | 0:e14364aac2ca | 312 | } |
jacobjohnson | 0:e14364aac2ca | 313 | |
jacobjohnson | 0:e14364aac2ca | 314 | unsigned char SeeedGrayOLED::putNumber(long long_num) |
jacobjohnson | 0:e14364aac2ca | 315 | { |
jacobjohnson | 0:e14364aac2ca | 316 | unsigned char char_buffer[10]=""; |
jacobjohnson | 0:e14364aac2ca | 317 | unsigned char i = 0; |
jacobjohnson | 0:e14364aac2ca | 318 | unsigned char f = 0; |
jacobjohnson | 0:e14364aac2ca | 319 | |
jacobjohnson | 0:e14364aac2ca | 320 | if (long_num < 0) |
jacobjohnson | 0:e14364aac2ca | 321 | { |
jacobjohnson | 0:e14364aac2ca | 322 | f=1; |
jacobjohnson | 0:e14364aac2ca | 323 | putChar('-'); |
jacobjohnson | 0:e14364aac2ca | 324 | long_num = -long_num; |
jacobjohnson | 0:e14364aac2ca | 325 | } |
jacobjohnson | 0:e14364aac2ca | 326 | else if (long_num == 0) |
jacobjohnson | 0:e14364aac2ca | 327 | { |
jacobjohnson | 0:e14364aac2ca | 328 | f=1; |
jacobjohnson | 0:e14364aac2ca | 329 | putChar('0'); |
jacobjohnson | 0:e14364aac2ca | 330 | return f; |
jacobjohnson | 0:e14364aac2ca | 331 | } |
jacobjohnson | 0:e14364aac2ca | 332 | |
jacobjohnson | 0:e14364aac2ca | 333 | while (long_num > 0) |
jacobjohnson | 0:e14364aac2ca | 334 | { |
jacobjohnson | 0:e14364aac2ca | 335 | char_buffer[i++] = long_num % 10; |
jacobjohnson | 0:e14364aac2ca | 336 | long_num /= 10; |
jacobjohnson | 0:e14364aac2ca | 337 | } |
jacobjohnson | 0:e14364aac2ca | 338 | |
jacobjohnson | 0:e14364aac2ca | 339 | f=f+i; |
jacobjohnson | 0:e14364aac2ca | 340 | for(; i > 0; i--) |
jacobjohnson | 0:e14364aac2ca | 341 | { |
jacobjohnson | 0:e14364aac2ca | 342 | putChar('0'+ char_buffer[i - 1]); |
jacobjohnson | 0:e14364aac2ca | 343 | } |
jacobjohnson | 0:e14364aac2ca | 344 | return f; |
jacobjohnson | 0:e14364aac2ca | 345 | |
jacobjohnson | 0:e14364aac2ca | 346 | } |
jacobjohnson | 0:e14364aac2ca | 347 | |
jacobjohnson | 0:e14364aac2ca | 348 | |
jacobjohnson | 0:e14364aac2ca | 349 | |
jacobjohnson | 0:e14364aac2ca | 350 | void SeeedGrayOLED::drawBitmap(unsigned char *bitmaparray,int bytes) |
jacobjohnson | 0:e14364aac2ca | 351 | { |
jacobjohnson | 0:e14364aac2ca | 352 | char localAddressMode = addressingMode; |
jacobjohnson | 0:e14364aac2ca | 353 | if(addressingMode != HORIZONTAL_MODE) |
jacobjohnson | 0:e14364aac2ca | 354 | { |
jacobjohnson | 0:e14364aac2ca | 355 | //Bitmap is drawn in horizontal mode |
jacobjohnson | 0:e14364aac2ca | 356 | setHorizontalMode(); |
jacobjohnson | 0:e14364aac2ca | 357 | } |
jacobjohnson | 0:e14364aac2ca | 358 | |
jacobjohnson | 0:e14364aac2ca | 359 | for(int i=0;i<bytes;i++) |
jacobjohnson | 0:e14364aac2ca | 360 | { |
jacobjohnson | 0:e14364aac2ca | 361 | |
jacobjohnson | 0:e14364aac2ca | 362 | for(int j=0;j<8;j=j+2) |
jacobjohnson | 0:e14364aac2ca | 363 | { |
jacobjohnson | 0:e14364aac2ca | 364 | char c=0x00; |
jacobjohnson | 0:e14364aac2ca | 365 | char bit1=bitmaparray[i] << j & 0x80; |
jacobjohnson | 0:e14364aac2ca | 366 | char bit2=bitmaparray[i] << (j+1) & 0x80; |
jacobjohnson | 0:e14364aac2ca | 367 | |
jacobjohnson | 0:e14364aac2ca | 368 | // Each bit is changed to a nibble |
jacobjohnson | 0:e14364aac2ca | 369 | c|=(bit1)?grayH:0x00; |
jacobjohnson | 0:e14364aac2ca | 370 | // Each bit is changed to a nibble |
jacobjohnson | 0:e14364aac2ca | 371 | c|=(bit2)?grayL:0x00; |
jacobjohnson | 0:e14364aac2ca | 372 | sendData(c); |
jacobjohnson | 0:e14364aac2ca | 373 | } |
jacobjohnson | 0:e14364aac2ca | 374 | } |
jacobjohnson | 0:e14364aac2ca | 375 | if(localAddressMode == VERTICAL_MODE) |
jacobjohnson | 0:e14364aac2ca | 376 | { |
jacobjohnson | 0:e14364aac2ca | 377 | //If Vertical Mode was used earlier, restore it. |
jacobjohnson | 0:e14364aac2ca | 378 | setVerticalMode(); |
jacobjohnson | 0:e14364aac2ca | 379 | } |
jacobjohnson | 0:e14364aac2ca | 380 | |
jacobjohnson | 0:e14364aac2ca | 381 | } |
jacobjohnson | 0:e14364aac2ca | 382 | |
jacobjohnson | 0:e14364aac2ca | 383 | void SeeedGrayOLED::setHorizontalScrollProperties(bool direction,unsigned char startRow, unsigned char endRow,unsigned char startColumn, unsigned char endColumn, unsigned char scrollSpeed) |
jacobjohnson | 0:e14364aac2ca | 384 | { |
jacobjohnson | 0:e14364aac2ca | 385 | /* |
jacobjohnson | 0:e14364aac2ca | 386 | Use the following defines for 'direction' : |
jacobjohnson | 0:e14364aac2ca | 387 | |
jacobjohnson | 0:e14364aac2ca | 388 | Scroll_Left |
jacobjohnson | 0:e14364aac2ca | 389 | Scroll_Right |
jacobjohnson | 0:e14364aac2ca | 390 | |
jacobjohnson | 0:e14364aac2ca | 391 | Use the following defines for 'scrollSpeed' : |
jacobjohnson | 0:e14364aac2ca | 392 | |
jacobjohnson | 0:e14364aac2ca | 393 | Scroll_2Frames |
jacobjohnson | 0:e14364aac2ca | 394 | Scroll_3Frames |
jacobjohnson | 0:e14364aac2ca | 395 | Scroll_4Frames |
jacobjohnson | 0:e14364aac2ca | 396 | Scroll_5Frames |
jacobjohnson | 0:e14364aac2ca | 397 | Scroll_25Frames |
jacobjohnson | 0:e14364aac2ca | 398 | Scroll_64Frames |
jacobjohnson | 0:e14364aac2ca | 399 | Scroll_128Frames |
jacobjohnson | 0:e14364aac2ca | 400 | Scroll_256Frames |
jacobjohnson | 0:e14364aac2ca | 401 | |
jacobjohnson | 0:e14364aac2ca | 402 | */ |
jacobjohnson | 0:e14364aac2ca | 403 | |
jacobjohnson | 0:e14364aac2ca | 404 | if(Scroll_Right == direction) |
jacobjohnson | 0:e14364aac2ca | 405 | { |
jacobjohnson | 0:e14364aac2ca | 406 | //Scroll Right |
jacobjohnson | 0:e14364aac2ca | 407 | sendCommand(0x27); |
jacobjohnson | 0:e14364aac2ca | 408 | } |
jacobjohnson | 0:e14364aac2ca | 409 | else |
jacobjohnson | 0:e14364aac2ca | 410 | { |
jacobjohnson | 0:e14364aac2ca | 411 | //Scroll Left |
jacobjohnson | 0:e14364aac2ca | 412 | sendCommand(0x26); |
jacobjohnson | 0:e14364aac2ca | 413 | } |
jacobjohnson | 0:e14364aac2ca | 414 | sendCommand(0x00); //Dummmy byte |
jacobjohnson | 0:e14364aac2ca | 415 | sendCommand(startRow); |
jacobjohnson | 0:e14364aac2ca | 416 | sendCommand(scrollSpeed); |
jacobjohnson | 0:e14364aac2ca | 417 | sendCommand(endRow); |
jacobjohnson | 0:e14364aac2ca | 418 | sendCommand(startColumn+8); |
jacobjohnson | 0:e14364aac2ca | 419 | sendCommand(endColumn+8); |
jacobjohnson | 0:e14364aac2ca | 420 | sendCommand(0x00); //Dummmy byte |
jacobjohnson | 0:e14364aac2ca | 421 | |
jacobjohnson | 0:e14364aac2ca | 422 | } |
jacobjohnson | 0:e14364aac2ca | 423 | |
jacobjohnson | 0:e14364aac2ca | 424 | void SeeedGrayOLED::activateScroll() |
jacobjohnson | 0:e14364aac2ca | 425 | { |
jacobjohnson | 0:e14364aac2ca | 426 | sendCommand(SeeedGrayOLED_Activate_Scroll_Cmd); |
jacobjohnson | 0:e14364aac2ca | 427 | } |
jacobjohnson | 0:e14364aac2ca | 428 | |
jacobjohnson | 0:e14364aac2ca | 429 | void SeeedGrayOLED::deactivateScroll() |
jacobjohnson | 0:e14364aac2ca | 430 | { |
jacobjohnson | 0:e14364aac2ca | 431 | sendCommand(SeeedGrayOLED_Dectivate_Scroll_Cmd); |
jacobjohnson | 0:e14364aac2ca | 432 | } |
jacobjohnson | 0:e14364aac2ca | 433 | |
jacobjohnson | 0:e14364aac2ca | 434 | void SeeedGrayOLED::setNormalDisplay() |
jacobjohnson | 0:e14364aac2ca | 435 | { |
jacobjohnson | 0:e14364aac2ca | 436 | sendCommand(SeeedGrayOLED_Normal_Display_Cmd); |
jacobjohnson | 0:e14364aac2ca | 437 | } |
jacobjohnson | 0:e14364aac2ca | 438 | |
jacobjohnson | 0:e14364aac2ca | 439 | void SeeedGrayOLED::setInverseDisplay() |
jacobjohnson | 0:e14364aac2ca | 440 | { |
jacobjohnson | 0:e14364aac2ca | 441 | sendCommand(SeeedGrayOLED_Inverse_Display_Cmd); |
jacobjohnson | 0:e14364aac2ca | 442 | } |
jacobjohnson | 0:e14364aac2ca | 443 | |
jacobjohnson | 0:e14364aac2ca | 444 |