Description dans le rapport.

Dependencies:   mbed

Committer:
Damien75
Date:
Sun Apr 02 09:48:30 2017 +0000
Revision:
0:34945468db9f
Projet C++ embarqu? MBED; Damien et Nicolas

Who changed what in which revision?

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