chris stevens / 4spi_oled_ssd1305

Dependents:   univision_oled

Fork of spk_oled_ssd1305 by Toby Harris

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers 4spi_oled_ssd1305.cpp Source File

4spi_oled_ssd1305.cpp

00001 // OLED display using SSD1305 driver
00002 // A library by *spark audio-visual
00003 
00004 /* Copyright (c) 2011 Toby Harris, MIT License
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00007  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00008  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00009  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in all copies or
00013  * substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00016  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00017  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020  */
00021 
00022 #include "4spi_oled_ssd1305.h"
00023 #include "mbed.h"
00024 
00025 // re written to handle page mode on ssd1305 128x64 unit CJS 2013
00026 
00027 // nice logo - note the typo....
00028 static unsigned char logo_bits[] = {
00029 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00030 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00031 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00032 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00033 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00034 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00035 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00036 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00037 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00038 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00,
00039 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00040 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
00041 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00042 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00043 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00044 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00045 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x04, 0x06,
00046 0x06, 0xFC, 0xF8, 0x00, 0x04, 0x06, 0x06, 0xFC, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00,
00047 0x04, 0x06, 0x06, 0x04, 0xFC, 0x60, 0x00, 0x60, 0xF8, 0x6C, 0x64, 0x66, 0x66, 0x64, 0x64, 0x78,
00048 0x60, 0x00, 0x60, 0xFC, 0x04, 0x06, 0x06, 0x04, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
00049 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00050 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00051 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00052 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00053 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x00,
00054 0x00, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00,
00055 0x02, 0x06, 0x06, 0x02, 0x03, 0x00, 0x00, 0x00, 0x01, 0x03, 0x02, 0x06, 0x06, 0x06, 0x02, 0x02,
00056 0x02, 0x00, 0x00, 0x03, 0x02, 0x06, 0x06, 0x02, 0x00, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
00057 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00058 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00059 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00060 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00061 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0xF0, 0xF0,
00062 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x30, 0x20, 0x20, 0xE0, 0x80, 0x00, 0x00, 0x00,
00063 0x80, 0xE0, 0x20, 0x30, 0x30, 0x20, 0x20, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
00064 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xC0, 0x60, 0x20, 0x30, 0x30, 0x20, 0x20, 0x00, 0x00,
00065 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00066 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
00067 0x40, 0x60, 0x20, 0x30, 0x30, 0x30, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00,
00068 0x80, 0xE0, 0x20, 0x20, 0x30, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00069 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0xFF, 0xFF,
00070 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xB0, 0x98, 0x8C, 0x87, 0x81, 0x00, 0x00, 0x00,
00071 0x01, 0x87, 0x84, 0x8C, 0x8C, 0x84, 0xC0, 0x7F, 0x0E, 0x00, 0x00, 0x00, 0x81, 0xC3, 0x34, 0x00,
00072 0x10, 0x34, 0xC3, 0x80, 0x00, 0x00, 0x0E, 0x7F, 0x80, 0x84, 0x86, 0x86, 0x84, 0xFC, 0x30, 0x00,
00073 0x00, 0x30, 0x38, 0x32, 0x31, 0x30, 0x30, 0xFF, 0xFF, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
00074 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x3F,
00075 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
00076 0x80, 0x83, 0x82, 0x86, 0x84, 0x84, 0x84, 0xF8, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00077 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
00078 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
00079 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
00080 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
00081 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00082 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00083 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x0F, 0x01, 0x00, 0x00,
00084 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00085 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00086 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00087 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00088 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00089 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00090 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00091 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00092 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
00093 };
00094 
00095 
00096 static unsigned char font[]= {
00097     0x00, 0x00, 0x00, 0x00, 0x00,
00098     0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
00099     0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
00100     0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
00101     0x18, 0x3C, 0x7E, 0x3C, 0x18,
00102     0x1C, 0x57, 0x7D, 0x57, 0x1C,
00103     0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
00104     0x00, 0x18, 0x3C, 0x18, 0x00,
00105     0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
00106     0x00, 0x18, 0x24, 0x18, 0x00,
00107     0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
00108     0x30, 0x48, 0x3A, 0x06, 0x0E,
00109     0x26, 0x29, 0x79, 0x29, 0x26,
00110     0x40, 0x7F, 0x05, 0x05, 0x07,
00111     0x40, 0x7F, 0x05, 0x25, 0x3F,
00112     0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
00113     0x7F, 0x3E, 0x1C, 0x1C, 0x08,
00114     0x08, 0x1C, 0x1C, 0x3E, 0x7F,
00115     0x14, 0x22, 0x7F, 0x22, 0x14,
00116     0x5F, 0x5F, 0x00, 0x5F, 0x5F,
00117     0x06, 0x09, 0x7F, 0x01, 0x7F,
00118     0x00, 0x66, 0x89, 0x95, 0x6A,
00119     0x60, 0x60, 0x60, 0x60, 0x60,
00120     0x94, 0xA2, 0xFF, 0xA2, 0x94,
00121     0x08, 0x04, 0x7E, 0x04, 0x08,
00122     0x10, 0x20, 0x7E, 0x20, 0x10,
00123     0x08, 0x08, 0x2A, 0x1C, 0x08,
00124     0x08, 0x1C, 0x2A, 0x08, 0x08,
00125     0x1E, 0x10, 0x10, 0x10, 0x10,
00126     0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
00127     0x30, 0x38, 0x3E, 0x38, 0x30,
00128     0x06, 0x0E, 0x3E, 0x0E, 0x06,
00129     0x00, 0x00, 0x00, 0x00, 0x00,
00130     0x00, 0x00, 0x5F, 0x00, 0x00,
00131     0x00, 0x07, 0x00, 0x07, 0x00,
00132     0x14, 0x7F, 0x14, 0x7F, 0x14,
00133     0x24, 0x2A, 0x7F, 0x2A, 0x12,
00134     0x23, 0x13, 0x08, 0x64, 0x62,
00135     0x36, 0x49, 0x56, 0x20, 0x50,
00136     0x00, 0x08, 0x07, 0x03, 0x00,
00137     0x00, 0x1C, 0x22, 0x41, 0x00,
00138     0x00, 0x41, 0x22, 0x1C, 0x00,
00139     0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
00140     0x08, 0x08, 0x3E, 0x08, 0x08,
00141     0x00, 0x80, 0x70, 0x30, 0x00,
00142     0x08, 0x08, 0x08, 0x08, 0x08,
00143     0x00, 0x00, 0x60, 0x60, 0x00,
00144     0x20, 0x10, 0x08, 0x04, 0x02,
00145     0x3E, 0x51, 0x49, 0x45, 0x3E,
00146     0x00, 0x42, 0x7F, 0x40, 0x00,
00147     0x72, 0x49, 0x49, 0x49, 0x46,
00148     0x21, 0x41, 0x49, 0x4D, 0x33,
00149     0x18, 0x14, 0x12, 0x7F, 0x10,
00150     0x27, 0x45, 0x45, 0x45, 0x39,
00151     0x3C, 0x4A, 0x49, 0x49, 0x31,
00152     0x41, 0x21, 0x11, 0x09, 0x07,
00153     0x36, 0x49, 0x49, 0x49, 0x36,
00154     0x46, 0x49, 0x49, 0x29, 0x1E,
00155     0x00, 0x00, 0x14, 0x00, 0x00,
00156     0x00, 0x40, 0x34, 0x00, 0x00,
00157     0x00, 0x08, 0x14, 0x22, 0x41,
00158     0x14, 0x14, 0x14, 0x14, 0x14,
00159     0x00, 0x41, 0x22, 0x14, 0x08,
00160     0x02, 0x01, 0x59, 0x09, 0x06,
00161     0x3E, 0x41, 0x5D, 0x59, 0x4E,
00162     0x7C, 0x12, 0x11, 0x12, 0x7C,
00163     0x7F, 0x49, 0x49, 0x49, 0x36,
00164     0x3E, 0x41, 0x41, 0x41, 0x22,
00165     0x7F, 0x41, 0x41, 0x41, 0x3E,
00166     0x7F, 0x49, 0x49, 0x49, 0x41,
00167     0x7F, 0x09, 0x09, 0x09, 0x01,
00168     0x3E, 0x41, 0x41, 0x51, 0x73,
00169     0x7F, 0x08, 0x08, 0x08, 0x7F,
00170     0x00, 0x41, 0x7F, 0x41, 0x00,
00171     0x20, 0x40, 0x41, 0x3F, 0x01,
00172     0x7F, 0x08, 0x14, 0x22, 0x41,
00173     0x7F, 0x40, 0x40, 0x40, 0x40,
00174     0x7F, 0x02, 0x1C, 0x02, 0x7F,
00175     0x7F, 0x04, 0x08, 0x10, 0x7F,
00176     0x3E, 0x41, 0x41, 0x41, 0x3E,
00177     0x7F, 0x09, 0x09, 0x09, 0x06,
00178     0x3E, 0x41, 0x51, 0x21, 0x5E,
00179     0x7F, 0x09, 0x19, 0x29, 0x46,
00180     0x26, 0x49, 0x49, 0x49, 0x32,
00181     0x03, 0x01, 0x7F, 0x01, 0x03,
00182     0x3F, 0x40, 0x40, 0x40, 0x3F,
00183     0x1F, 0x20, 0x40, 0x20, 0x1F,
00184     0x3F, 0x40, 0x38, 0x40, 0x3F,
00185     0x63, 0x14, 0x08, 0x14, 0x63,
00186     0x03, 0x04, 0x78, 0x04, 0x03,
00187     0x61, 0x59, 0x49, 0x4D, 0x43,
00188     0x00, 0x7F, 0x41, 0x41, 0x41,
00189     0x02, 0x04, 0x08, 0x10, 0x20,
00190     0x00, 0x41, 0x41, 0x41, 0x7F,
00191     0x04, 0x02, 0x01, 0x02, 0x04,
00192     0x40, 0x40, 0x40, 0x40, 0x40,
00193     0x00, 0x03, 0x07, 0x08, 0x00,
00194     0x20, 0x54, 0x54, 0x78, 0x40,
00195     0x7F, 0x28, 0x44, 0x44, 0x38,
00196     0x38, 0x44, 0x44, 0x44, 0x28,
00197     0x38, 0x44, 0x44, 0x28, 0x7F,
00198     0x38, 0x54, 0x54, 0x54, 0x18,
00199     0x00, 0x08, 0x7E, 0x09, 0x02,
00200     0x18, 0xA4, 0xA4, 0x9C, 0x78,
00201     0x7F, 0x08, 0x04, 0x04, 0x78,
00202     0x00, 0x44, 0x7D, 0x40, 0x00,
00203     0x20, 0x40, 0x40, 0x3D, 0x00,
00204     0x7F, 0x10, 0x28, 0x44, 0x00,
00205     0x00, 0x41, 0x7F, 0x40, 0x00,
00206     0x7C, 0x04, 0x78, 0x04, 0x78,
00207     0x7C, 0x08, 0x04, 0x04, 0x78,
00208     0x38, 0x44, 0x44, 0x44, 0x38,
00209     0xFC, 0x18, 0x24, 0x24, 0x18,
00210     0x18, 0x24, 0x24, 0x18, 0xFC,
00211     0x7C, 0x08, 0x04, 0x04, 0x08,
00212     0x48, 0x54, 0x54, 0x54, 0x24,
00213     0x04, 0x04, 0x3F, 0x44, 0x24,
00214     0x3C, 0x40, 0x40, 0x20, 0x7C,
00215     0x1C, 0x20, 0x40, 0x20, 0x1C,
00216     0x3C, 0x40, 0x30, 0x40, 0x3C,
00217     0x44, 0x28, 0x10, 0x28, 0x44,
00218     0x4C, 0x90, 0x90, 0x90, 0x7C,
00219     0x44, 0x64, 0x54, 0x4C, 0x44,
00220     0x00, 0x08, 0x36, 0x41, 0x00,
00221     0x00, 0x00, 0x77, 0x00, 0x00,
00222     0x00, 0x41, 0x36, 0x08, 0x00,
00223     0x02, 0x01, 0x02, 0x04, 0x02,
00224     0x3C, 0x26, 0x23, 0x26, 0x3C,
00225     0x1E, 0xA1, 0xA1, 0x61, 0x12,
00226     0x3A, 0x40, 0x40, 0x20, 0x7A,
00227     0x38, 0x54, 0x54, 0x55, 0x59,
00228     0x21, 0x55, 0x55, 0x79, 0x41,
00229     0x21, 0x54, 0x54, 0x78, 0x41,
00230     0x21, 0x55, 0x54, 0x78, 0x40,
00231     0x20, 0x54, 0x55, 0x79, 0x40,
00232     0x0C, 0x1E, 0x52, 0x72, 0x12,
00233     0x39, 0x55, 0x55, 0x55, 0x59,
00234     0x39, 0x54, 0x54, 0x54, 0x59,
00235     0x39, 0x55, 0x54, 0x54, 0x58,
00236     0x00, 0x00, 0x45, 0x7C, 0x41,
00237     0x00, 0x02, 0x45, 0x7D, 0x42,
00238     0x00, 0x01, 0x45, 0x7C, 0x40,
00239     0xF0, 0x29, 0x24, 0x29, 0xF0,
00240     0xF0, 0x28, 0x25, 0x28, 0xF0,
00241     0x7C, 0x54, 0x55, 0x45, 0x00,
00242     0x20, 0x54, 0x54, 0x7C, 0x54,
00243     0x7C, 0x0A, 0x09, 0x7F, 0x49,
00244     0x32, 0x49, 0x49, 0x49, 0x32,
00245     0x32, 0x48, 0x48, 0x48, 0x32,
00246     0x32, 0x4A, 0x48, 0x48, 0x30,
00247     0x3A, 0x41, 0x41, 0x21, 0x7A,
00248     0x3A, 0x42, 0x40, 0x20, 0x78,
00249     0x00, 0x9D, 0xA0, 0xA0, 0x7D,
00250     0x39, 0x44, 0x44, 0x44, 0x39,
00251     0x3D, 0x40, 0x40, 0x40, 0x3D,
00252     0x3C, 0x24, 0xFF, 0x24, 0x24,
00253     0x48, 0x7E, 0x49, 0x43, 0x66,
00254     0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
00255     0xFF, 0x09, 0x29, 0xF6, 0x20,
00256     0xC0, 0x88, 0x7E, 0x09, 0x03,
00257     0x20, 0x54, 0x54, 0x79, 0x41,
00258     0x00, 0x00, 0x44, 0x7D, 0x41,
00259     0x30, 0x48, 0x48, 0x4A, 0x32,
00260     0x38, 0x40, 0x40, 0x22, 0x7A,
00261     0x00, 0x7A, 0x0A, 0x0A, 0x72,
00262     0x7D, 0x0D, 0x19, 0x31, 0x7D,
00263     0x26, 0x29, 0x29, 0x2F, 0x28,
00264     0x26, 0x29, 0x29, 0x29, 0x26,
00265     0x30, 0x48, 0x4D, 0x40, 0x20,
00266     0x38, 0x08, 0x08, 0x08, 0x08,
00267     0x08, 0x08, 0x08, 0x08, 0x38,
00268     0x2F, 0x10, 0xC8, 0xAC, 0xBA,
00269     0x2F, 0x10, 0x28, 0x34, 0xFA,
00270     0x00, 0x00, 0x7B, 0x00, 0x00,
00271     0x08, 0x14, 0x2A, 0x14, 0x22,
00272     0x22, 0x14, 0x2A, 0x14, 0x08,
00273     0xAA, 0x00, 0x55, 0x00, 0xAA,
00274     0xAA, 0x55, 0xAA, 0x55, 0xAA,
00275     0x00, 0x00, 0x00, 0xFF, 0x00,
00276     0x10, 0x10, 0x10, 0xFF, 0x00,
00277     0x14, 0x14, 0x14, 0xFF, 0x00,
00278     0x10, 0x10, 0xFF, 0x00, 0xFF,
00279     0x10, 0x10, 0xF0, 0x10, 0xF0,
00280     0x14, 0x14, 0x14, 0xFC, 0x00,
00281     0x14, 0x14, 0xF7, 0x00, 0xFF,
00282     0x00, 0x00, 0xFF, 0x00, 0xFF,
00283     0x14, 0x14, 0xF4, 0x04, 0xFC,
00284     0x14, 0x14, 0x17, 0x10, 0x1F,
00285     0x10, 0x10, 0x1F, 0x10, 0x1F,
00286     0x14, 0x14, 0x14, 0x1F, 0x00,
00287     0x10, 0x10, 0x10, 0xF0, 0x00,
00288     0x00, 0x00, 0x00, 0x1F, 0x10,
00289     0x10, 0x10, 0x10, 0x1F, 0x10,
00290     0x10, 0x10, 0x10, 0xF0, 0x10,
00291     0x00, 0x00, 0x00, 0xFF, 0x10,
00292     0x10, 0x10, 0x10, 0x10, 0x10,
00293     0x10, 0x10, 0x10, 0xFF, 0x10,
00294     0x00, 0x00, 0x00, 0xFF, 0x14,
00295     0x00, 0x00, 0xFF, 0x00, 0xFF,
00296     0x00, 0x00, 0x1F, 0x10, 0x17,
00297     0x00, 0x00, 0xFC, 0x04, 0xF4,
00298     0x14, 0x14, 0x17, 0x10, 0x17,
00299     0x14, 0x14, 0xF4, 0x04, 0xF4,
00300     0x00, 0x00, 0xFF, 0x00, 0xF7,
00301     0x14, 0x14, 0x14, 0x14, 0x14,
00302     0x14, 0x14, 0xF7, 0x00, 0xF7,
00303     0x14, 0x14, 0x14, 0x17, 0x14,
00304     0x10, 0x10, 0x1F, 0x10, 0x1F,
00305     0x14, 0x14, 0x14, 0xF4, 0x14,
00306     0x10, 0x10, 0xF0, 0x10, 0xF0,
00307     0x00, 0x00, 0x1F, 0x10, 0x1F,
00308     0x00, 0x00, 0x00, 0x1F, 0x14,
00309     0x00, 0x00, 0x00, 0xFC, 0x14,
00310     0x00, 0x00, 0xF0, 0x10, 0xF0,
00311     0x10, 0x10, 0xFF, 0x10, 0xFF,
00312     0x14, 0x14, 0x14, 0xFF, 0x14,
00313     0x10, 0x10, 0x10, 0x1F, 0x00,
00314     0x00, 0x00, 0x00, 0xF0, 0x10,
00315     0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
00316     0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
00317     0xFF, 0xFF, 0xFF, 0x00, 0x00,
00318     0x00, 0x00, 0x00, 0xFF, 0xFF,
00319     0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
00320     0x38, 0x44, 0x44, 0x38, 0x44,
00321     0x7C, 0x2A, 0x2A, 0x3E, 0x14,
00322     0x7E, 0x02, 0x02, 0x06, 0x06,
00323     0x02, 0x7E, 0x02, 0x7E, 0x02,
00324     0x63, 0x55, 0x49, 0x41, 0x63,
00325     0x38, 0x44, 0x44, 0x3C, 0x04,
00326     0x40, 0x7E, 0x20, 0x1E, 0x20,
00327     0x06, 0x02, 0x7E, 0x02, 0x02,
00328     0x99, 0xA5, 0xE7, 0xA5, 0x99,
00329     0x1C, 0x2A, 0x49, 0x2A, 0x1C,
00330     0x4C, 0x72, 0x01, 0x72, 0x4C,
00331     0x30, 0x4A, 0x4D, 0x4D, 0x30,
00332     0x30, 0x48, 0x78, 0x48, 0x30,
00333     0xBC, 0x62, 0x5A, 0x46, 0x3D,
00334     0x3E, 0x49, 0x49, 0x49, 0x00,
00335     0x7E, 0x01, 0x01, 0x01, 0x7E,
00336     0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
00337     0x44, 0x44, 0x5F, 0x44, 0x44,
00338     0x40, 0x51, 0x4A, 0x44, 0x40,
00339     0x40, 0x44, 0x4A, 0x51, 0x40,
00340     0x00, 0x00, 0xFF, 0x01, 0x03,
00341     0xE0, 0x80, 0xFF, 0x00, 0x00,
00342     0x08, 0x08, 0x6B, 0x6B, 0x08,
00343     0x36, 0x12, 0x36, 0x24, 0x36,
00344     0x06, 0x0F, 0x09, 0x0F, 0x06,
00345     0x00, 0x00, 0x18, 0x18, 0x00,
00346     0x00, 0x00, 0x10, 0x10, 0x00,
00347     0x30, 0x40, 0xFF, 0x01, 0x01,
00348     0x00, 0x1F, 0x01, 0x01, 0x1E,
00349     0x00, 0x19, 0x1D, 0x17, 0x12,
00350     0x00, 0x3C, 0x3C, 0x3C, 0x3C,
00351     0x00, 0x00, 0x00, 0x00, 0x00,
00352 };
00353 
00354 
00355 SPKDisplay::SPKDisplay(PinName mosiPin, PinName clkPin, PinName csPin, PinName dcPin, PinName resPin, Serial *debugSerial)
00356 {
00357     bufferHasChanged = false;
00358 
00359     fontStartCharacter = NULL;
00360     fontEndCharacter = NULL;
00361     fontCharacters = NULL;
00362 
00363     spi = new SPI(mosiPin, NC, clkPin);
00364     spi->format(8,3);
00365     // changed to 9600 to test
00366     spi->frequency(1000000);
00367 
00368     cs = new DigitalOut(csPin);
00369     dc = new DigitalOut(dcPin);
00370     res = new DigitalOut(resPin);
00371 
00372     // Link up debug Serial object
00373     // Passing in shared object as debugging is shared between all DVI mixer functions
00374     debug = debugSerial;
00375 
00376     setup();
00377 
00378     clearBuffer();
00379 
00380     if (debug) debug->printf("SPKDisplay loaded\n\r");
00381 }
00382 
00383 // set display for black on white
00384 void SPKDisplay::inverse()
00385 {
00386     *dc=0;
00387     *cs=0;
00388     spi->write(0xA7);
00389     *dc=1;
00390     *cs=1;
00391 }
00392 
00393 //set display for white on black (normal state after reset)
00394 void SPKDisplay::normal()
00395 {
00396     *dc=0;
00397     *cs=0;
00398     spi->write(0xA6);
00399     *dc=1;
00400     *cs=1;
00401 }
00402 
00403 void SPKDisplay::displayPower(int P)
00404 {
00405     *dc=0;
00406     *cs=0;
00407     if(P==0) spi->write(0xAE);
00408     else spi->write(0xAF);
00409     *dc=1;
00410     *cs=1;
00411 
00412 }
00413 
00414 
00415 void SPKDisplay::clearBuffer()
00416 {
00417     memset(buffer, 0, bufferCount);
00418     bufferHasChanged = true;
00419 }
00420 
00421 void SPKDisplay::imageToBuffer(const uint8_t* image)
00422 {
00423     memcpy(buffer, image, bufferCount);
00424     bufferHasChanged = true;
00425 }
00426 
00427 void SPKDisplay::clearBufferRow(int row)
00428 {
00429     // Range check
00430     if (row >= 8) {
00431         if (debug) debug->printf("SPKDisplay::clearBufferRow sent out of bounds row");
00432         return;
00433     }
00434     int bStart = row*bufferWidth;
00435     int bEnd = bStart + pixelWidth;
00436 
00437     for (int bPos = bStart; bPos <= bEnd; bPos++) {
00438         buffer[bPos] = 0x00;
00439     }
00440 
00441     bufferHasChanged = true;
00442 }
00443 
00444 void SPKDisplay::horizLineToBuffer(int y)
00445 {
00446     if (y >= pixelHeight) {
00447         if (debug) debug->printf("SPKDisplay::clearBufferRow sent out of bounds y");
00448         return;
00449     }
00450 
00451     int row = (y*pixInPage) / pixelHeight;
00452     int posInRow = y % pixInPage;
00453 
00454     int bStart = row*bufferWidth;
00455     int bEnd = bStart + pixelWidth;
00456 
00457     for (int bPos = bStart; bPos <= bEnd; bPos++) {
00458         // Need to bitwise OR as setting single bit (the line) in byte (the row)
00459         buffer[bPos] = buffer[bPos] | 0x01 << posInRow;
00460     }
00461 
00462     bufferHasChanged = true;
00463 }
00464 
00465 
00466 void SPKDisplay::textToBuffer(char *message, int row)
00467 {
00468    char character;
00469     // Range check
00470     if (row >= 8) row = 7;
00471     int bStart = row*bufferWidth;
00472     int bEnd = bStart + pixelWidth;
00473  
00474     int bPos = bStart;
00475     for (int i = 0; i < 21; i++)
00476     {
00477        character=message[i];
00478          
00479             // Shift into our array's indexing
00480       //      character -= *fontStartCharacter;
00481             
00482             // Write each byte's vertical column of 8bits into the buffer.
00483             for (int j = 0; j < 5;j++)
00484             {
00485                 if (bPos >= bEnd) break;
00486                 buffer[bPos++] = font[character*5+j];
00487             }
00488             
00489             // Put 1px letter spacing at end
00490             if (bPos >= bEnd) break;
00491             buffer[bPos++] = 0x00; // 1 px letter spacing
00492         
00493     }
00494     
00495     bufferHasChanged = true;
00496 }
00497 
00498 
00499 // rewritten to cope with the paging
00500 void SPKDisplay::sendBuffer()
00501 {
00502     if (bufferHasChanged) {
00503         // Select the device by seting chip select low
00504         *cs = 0; // select chip
00505         *dc = 0; // comand mode
00506 
00507 
00508         unsigned char i=0,j=0;
00509         for(i=0; i<8; i++) {
00510             *dc=0; // command mode
00511             spi->write(0xB0+i); //Set display position - paged display
00512             spi->write(0x00); //Set display position - low column address
00513             spi->write(0x10);//Set the display position - high column address
00514 
00515             *dc=1; // data mode
00516             for(j=0; j<128; j++) {
00517                 spi->write(buffer[i*128+j]); //copy buffer into ram
00518 
00519             }
00520 
00521         }
00522 
00523         *cs = 1;
00524 
00525         bufferHasChanged = false;
00526     }
00527 }
00528 
00529 // display a welcome message encoded in tab0 in  spk_ole_ssd1305.h
00530 void SPKDisplay::welcome()
00531 {
00532 // Select the device by seting chip select low
00533     *cs = 0; // select chip
00534     *dc = 0; // comand mode
00535 
00536 
00537     unsigned char i=0,j=0;
00538     for(i=0; i<8; i++) {
00539         *dc=0; // command mode
00540         spi->write(0xB0+i); //Set display position - paged display
00541         spi->write(0x00); //Set display position - low column address
00542         spi->write(0x10);//Set the display position - high column address
00543 
00544         *dc=1; // data mode
00545         for(j=0; j<128; j++) {
00546             // spi->write(tab0[i*128+j]); //copy buffer into ram
00547             spi->write(logo_bits[i*128+j]); //copy buffer into ram
00548         }
00549 
00550     }
00551 
00552     *cs = 1;
00553 
00554 }
00555 
00556 
00557 
00558 //================
00559 // display a welcome message encoded in tab0 in  spk_ole_ssd1305.h
00560 void SPKDisplay::fontdemo()
00561 {
00562 // Select the device by seting chip select low
00563     *cs = 0; // select chip
00564     *dc = 0; // comand mode
00565 
00566 
00567     unsigned char i=0,j=0;
00568     for(i=0; i<8; i++) {
00569         *dc=0; // command mode
00570         spi->write(0xB0+i); //Set display position - paged display
00571         spi->write(0x00); //Set display position - low column address
00572         spi->write(0x10);//Set the display position - high column address
00573 
00574         *dc=1; // data mode
00575         for(j=0; j<128; j++) {
00576             // spi->write(tab0[i*128+j]); //copy buffer into ram
00577             spi->write(font[i*128+j]); //copy buffer into ram
00578         }
00579 
00580     }
00581 
00582     *cs = 1;
00583 
00584 }
00585 //=================
00586 
00587 void SPKDisplay::setup()
00588 {
00589     // TASK: SCREEN OFF, Run pre-flight
00590 
00591     // Hard reset the OLED
00592     *res=1;
00593     wait_ms(1);
00594     *res = 0;
00595     wait_ms(1);
00596     *res = 1;
00597 
00598     // Select the device by seting chip select low
00599     *cs = 0;
00600 
00601     // Set to receive COMMANDS not data
00602     *dc = 0;
00603 //=======ALL THESE TAKEN FROM THE UNIVISION DATASHEET UNCHANGED==========
00604 
00605     spi->write(0x20); // set addressing mode
00606     spi->write(0x10); // paged adressign mode
00607 
00608     spi->write(0x00); // set lower nyble column address
00609     spi->write(0x10); // set higher column adress
00610     spi->write(0x40);  //set display start line to 0
00611     spi->write(0x81); // set contrast control register
00612     spi->write(0xFF); // set contrast to maximum
00613 
00614     spi->write(0xA0); // [A0]:column address 0 is map to SEG0 ,
00615     //[A1]: columnaddress 131 is map to SEG0*/
00616 
00617     spi->write(0xA4); // entire display ON - means that dispaly constaly matched to RAM content
00618 
00619     spi->write(0xA6); //normal display - white on black
00620 
00621     spi->write(0xA8); // set MUX ratio command
00622     spi->write(0x3F); // MUX set to 36
00623 
00624     spi->write(0x8D); //set DC-DC
00625     spi->write(0x14);   // 0x14=ON
00626 
00627     spi->write(0xAE); // set display off - sleep mode
00628 
00629     spi->write(0xD3); // set display offset
00630     spi->write(0x00); // to no offset
00631 
00632     spi->write(0xD5); //set clock divide
00633     spi->write(0x20); // to get clock at 80Hz
00634 
00635 //spi->write(0xD8); // set area color
00636 //spi->write(0x00);
00637 
00638     spi->write(0xDA); // set pins configuration
00639     spi->write(0x12); // com left - right remap , alternaitve com config - realtes to hardware settings on board
00640 
00641     spi->write(0xDB); // set VCOMHH level
00642     spi->write(0x00); // to 0.65*Vcc
00643 
00644     spi->write(0xD9); // set pre charge period
00645     spi->write(0x22); // P1=2, P2=2
00646 
00647     spi->write(0xC0); // set COM ouptut scan normal
00648 
00649 //INI_DIS - initialise the display as per manufacturers example prog
00650 
00651     unsigned char i=0,j=0;
00652     for(i=0; i<8; i++) {
00653         *dc=0; // command mode
00654         spi->write(0xB0+i); //Set display position - paged display
00655         spi->write(0x02); //Set display position - low column address
00656         spi->write(0x10);//Set the display position - high column address
00657 
00658         *dc=1; // set to receive data no commands
00659 
00660         for(j=0; j<128; j++) {
00661             spi->write(0x00); //Screen display initial setting
00662 
00663         }
00664         *dc=0;
00665         spi->write(0xaf); // screen on
00666     }
00667 
00668 
00669 
00670 }