hadif azli / Mbed 2 deprecated TEST123

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Mon Jun 13 02:21:11 2016 +0000
Revision:
1:0e75de2a5d21
Parent:
0:d8f4c441e032
u8glib???????????????????????????Adafruit_GFX????OLED????????bitmap??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:d8f4c441e032 1 /*
lixianyu 0:d8f4c441e032 2
lixianyu 0:d8f4c441e032 3 u8g_dev_ssd1306_128x64.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 6
lixianyu 0:d8f4c441e032 7 Copyright (c) 2011, olikraus@gmail.com
lixianyu 0:d8f4c441e032 8 All rights reserved.
lixianyu 0:d8f4c441e032 9
lixianyu 0:d8f4c441e032 10 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 11 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 12
lixianyu 0:d8f4c441e032 13 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 14 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 15
lixianyu 0:d8f4c441e032 16 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 17 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 18 materials provided with the distribution.
lixianyu 0:d8f4c441e032 19
lixianyu 0:d8f4c441e032 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 33
lixianyu 0:d8f4c441e032 34
lixianyu 0:d8f4c441e032 35 */
lixianyu 0:d8f4c441e032 36
lixianyu 0:d8f4c441e032 37 #include "u8g.h"
lixianyu 1:0e75de2a5d21 38 #include "gpio_api.h"
lixianyu 0:d8f4c441e032 39
lixianyu 0:d8f4c441e032 40 #define WIDTH 128
lixianyu 0:d8f4c441e032 41 #define HEIGHT 64
lixianyu 0:d8f4c441e032 42 #define PAGE_HEIGHT 8
lixianyu 0:d8f4c441e032 43
lixianyu 1:0e75de2a5d21 44 //extern gpio_t g_LED;
lixianyu 0:d8f4c441e032 45 /* init sequence adafruit 128x64 OLED (NOT TESTED) */
lixianyu 0:d8f4c441e032 46 static const uint8_t u8g_dev_ssd1306_128x64_adafruit1_init_seq[] PROGMEM = {
lixianyu 0:d8f4c441e032 47 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 48 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 49 U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
lixianyu 0:d8f4c441e032 50 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 51
lixianyu 0:d8f4c441e032 52 0x0ae, /* display off, sleep mode */
lixianyu 0:d8f4c441e032 53 0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
lixianyu 0:d8f4c441e032 54 0x0a8, 0x03f, /* */
lixianyu 0:d8f4c441e032 55
lixianyu 0:d8f4c441e032 56 0x0d3, 0x000, /* */
lixianyu 0:d8f4c441e032 57
lixianyu 0:d8f4c441e032 58 0x040, /* start line */
lixianyu 0:d8f4c441e032 59
lixianyu 0:d8f4c441e032 60 0x08d, 0x010, /* [1] charge pump setting (p62): 0x014 enable, 0x010 disable */
lixianyu 0:d8f4c441e032 61
lixianyu 0:d8f4c441e032 62 0x020, 0x000, /* */
lixianyu 0:d8f4c441e032 63 0x0a1, /* segment remap a0/a1*/
lixianyu 0:d8f4c441e032 64 0x0c8, /* c0: scan dir normal, c8: reverse */
lixianyu 0:d8f4c441e032 65 0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
lixianyu 0:d8f4c441e032 66 0x081, 0x09f, /* [1] set contrast control */
lixianyu 0:d8f4c441e032 67 0x0d9, 0x022, /* [1] pre-charge period 0x022/f1*/
lixianyu 0:d8f4c441e032 68 0x0db, 0x040, /* vcomh deselect level */
lixianyu 0:d8f4c441e032 69
lixianyu 0:d8f4c441e032 70 0x02e, /* 2012-05-27: Deactivate scroll */
lixianyu 0:d8f4c441e032 71 0x0a4, /* output ram to display */
lixianyu 0:d8f4c441e032 72 0x0a6, /* none inverted normal display mode */
lixianyu 0:d8f4c441e032 73 0x0af, /* display on */
lixianyu 0:d8f4c441e032 74
lixianyu 0:d8f4c441e032 75 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 76 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 77 };
lixianyu 0:d8f4c441e032 78
lixianyu 0:d8f4c441e032 79 /* init sequence adafruit 128x64 OLED (NOT TESTED) */
lixianyu 0:d8f4c441e032 80 static const uint8_t u8g_dev_ssd1306_128x64_adafruit2_init_seq[] PROGMEM = {
lixianyu 1:0e75de2a5d21 81 #if 0
lixianyu 0:d8f4c441e032 82 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 83 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 84 U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
lixianyu 0:d8f4c441e032 85 U8G_ESC_CS(1), /* enable chip */
lixianyu 1:0e75de2a5d21 86 #endif
lixianyu 0:d8f4c441e032 87 0x0ae, /* display off, sleep mode */
lixianyu 0:d8f4c441e032 88 0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
lixianyu 0:d8f4c441e032 89 0x0a8, 0x03f, /* */
lixianyu 0:d8f4c441e032 90
lixianyu 0:d8f4c441e032 91 0x0d3, 0x000, /* */
lixianyu 0:d8f4c441e032 92
lixianyu 0:d8f4c441e032 93 0x040, /* start line */
lixianyu 0:d8f4c441e032 94
lixianyu 0:d8f4c441e032 95 0x08d, 0x014, /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
lixianyu 0:d8f4c441e032 96
lixianyu 0:d8f4c441e032 97 0x020, 0x000, /* */
lixianyu 0:d8f4c441e032 98 0x0a1, /* segment remap a0/a1*/
lixianyu 0:d8f4c441e032 99 0x0c8, /* c0: scan dir normal, c8: reverse */
lixianyu 0:d8f4c441e032 100 0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
lixianyu 0:d8f4c441e032 101 0x081, 0x0cf, /* [2] set contrast control */
lixianyu 0:d8f4c441e032 102 0x0d9, 0x0f1, /* [2] pre-charge period 0x022/f1*/
lixianyu 0:d8f4c441e032 103 0x0db, 0x040, /* vcomh deselect level */
lixianyu 0:d8f4c441e032 104
lixianyu 0:d8f4c441e032 105 0x02e, /* 2012-05-27: Deactivate scroll */
lixianyu 0:d8f4c441e032 106 0x0a4, /* output ram to display */
lixianyu 0:d8f4c441e032 107 0x0a6, /* none inverted normal display mode */
lixianyu 0:d8f4c441e032 108 0x0af, /* display on */
lixianyu 1:0e75de2a5d21 109 #if 1
lixianyu 0:d8f4c441e032 110 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 111 U8G_ESC_END /* end of sequence */
lixianyu 1:0e75de2a5d21 112 #endif
lixianyu 0:d8f4c441e032 113 };
lixianyu 0:d8f4c441e032 114
lixianyu 0:d8f4c441e032 115 /* init sequence adafruit 128x64 OLED (NOT TESTED), like adafruit3, but with page addressing mode */
lixianyu 0:d8f4c441e032 116 static const uint8_t u8g_dev_ssd1306_128x64_adafruit3_init_seq[] PROGMEM = {
lixianyu 0:d8f4c441e032 117 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 118 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 119 U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
lixianyu 0:d8f4c441e032 120 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 121
lixianyu 0:d8f4c441e032 122 0x0ae, /* display off, sleep mode */
lixianyu 0:d8f4c441e032 123 0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
lixianyu 0:d8f4c441e032 124 0x0a8, 0x03f, /* */
lixianyu 0:d8f4c441e032 125
lixianyu 0:d8f4c441e032 126 0x0d3, 0x000, /* */
lixianyu 0:d8f4c441e032 127
lixianyu 0:d8f4c441e032 128 0x040, /* start line */
lixianyu 0:d8f4c441e032 129
lixianyu 0:d8f4c441e032 130 0x08d, 0x014, /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
lixianyu 0:d8f4c441e032 131
lixianyu 0:d8f4c441e032 132 0x020, 0x002, /* 2012-05-27: page addressing mode */
lixianyu 0:d8f4c441e032 133 0x0a1, /* segment remap a0/a1*/
lixianyu 0:d8f4c441e032 134 0x0c8, /* c0: scan dir normal, c8: reverse */
lixianyu 0:d8f4c441e032 135 0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
lixianyu 0:d8f4c441e032 136 0x081, 0x0cf, /* [2] set contrast control */
lixianyu 0:d8f4c441e032 137 0x0d9, 0x0f1, /* [2] pre-charge period 0x022/f1*/
lixianyu 0:d8f4c441e032 138 0x0db, 0x040, /* vcomh deselect level */
lixianyu 0:d8f4c441e032 139
lixianyu 0:d8f4c441e032 140 0x02e, /* 2012-05-27: Deactivate scroll */
lixianyu 0:d8f4c441e032 141 0x0a4, /* output ram to display */
lixianyu 0:d8f4c441e032 142 0x0a6, /* none inverted normal display mode */
lixianyu 0:d8f4c441e032 143 0x0af, /* display on */
lixianyu 0:d8f4c441e032 144
lixianyu 0:d8f4c441e032 145 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 146 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 147 };
lixianyu 0:d8f4c441e032 148
lixianyu 0:d8f4c441e032 149 /* init sequence Univision datasheet (NOT TESTED) */
lixianyu 0:d8f4c441e032 150 static const uint8_t u8g_dev_ssd1306_128x64_univision_init_seq[] PROGMEM = {
lixianyu 0:d8f4c441e032 151 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 152 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 153 U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
lixianyu 0:d8f4c441e032 154 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 155
lixianyu 0:d8f4c441e032 156 0x0ae, /* display off, sleep mode */
lixianyu 0:d8f4c441e032 157 0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
lixianyu 0:d8f4c441e032 158 0x0a8, 0x03f, /* multiplex ratio */
lixianyu 0:d8f4c441e032 159 0x0d3, 0x000, /* display offset */
lixianyu 0:d8f4c441e032 160 0x040, /* start line */
lixianyu 0:d8f4c441e032 161 0x08d, 0x010, /* charge pump setting (p62): 0x014 enable, 0x010 disable */
lixianyu 0:d8f4c441e032 162 0x0a1, /* segment remap a0/a1*/
lixianyu 0:d8f4c441e032 163 0x0c8, /* c0: scan dir normal, c8: reverse */
lixianyu 0:d8f4c441e032 164 0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
lixianyu 0:d8f4c441e032 165 0x081, 0x09f, /* set contrast control */
lixianyu 0:d8f4c441e032 166 0x0d9, 0x022, /* pre-charge period */
lixianyu 0:d8f4c441e032 167 0x0db, 0x040, /* vcomh deselect level */
lixianyu 0:d8f4c441e032 168 0x022, 0x000, /* page addressing mode WRONG: 3 byte cmd! */
lixianyu 0:d8f4c441e032 169 0x0a4, /* output ram to display */
lixianyu 0:d8f4c441e032 170 0x0a6, /* none inverted normal display mode */
lixianyu 0:d8f4c441e032 171 0x0af, /* display on */
lixianyu 0:d8f4c441e032 172 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 173 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 174 };
lixianyu 0:d8f4c441e032 175
lixianyu 0:d8f4c441e032 176 /* select one init sequence here */
lixianyu 0:d8f4c441e032 177 //#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_univision_init_seq
lixianyu 0:d8f4c441e032 178 //#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit1_init_seq
lixianyu 0:d8f4c441e032 179 // 26. Apr 2014: in this thead: http://forum.arduino.cc/index.php?topic=234930.msg1696754;topicseen#msg1696754
lixianyu 0:d8f4c441e032 180 // it is mentiond, that adafruit2_init_seq works better --> this will be used by the ssd1306_adafruit device
lixianyu 0:d8f4c441e032 181 //#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit2_init_seq
lixianyu 0:d8f4c441e032 182
lixianyu 0:d8f4c441e032 183 #define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit3_init_seq
lixianyu 0:d8f4c441e032 184
lixianyu 0:d8f4c441e032 185
lixianyu 0:d8f4c441e032 186 static const uint8_t u8g_dev_ssd1306_128x64_data_start[] PROGMEM = {
lixianyu 0:d8f4c441e032 187 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 188 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 189 0x010, /* set upper 4 bit of the col adr to 0 */
lixianyu 0:d8f4c441e032 190 0x000, /* set lower 4 bit of the col adr to 0 */
lixianyu 0:d8f4c441e032 191 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 192 };
lixianyu 0:d8f4c441e032 193
lixianyu 0:d8f4c441e032 194 /* the sh1106 is compatible to the ssd1306, but is 132x64. display seems to be centered */
lixianyu 0:d8f4c441e032 195 static const uint8_t u8g_dev_sh1106_128x64_data_start[] PROGMEM = {
lixianyu 0:d8f4c441e032 196 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 197 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 198 0x010, /* set upper 4 bit of the col adr to 0 */
lixianyu 0:d8f4c441e032 199 0x002, /* set lower 4 bit of the col adr to 2 (centered display with sh1106) */
lixianyu 0:d8f4c441e032 200 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 201 };
lixianyu 0:d8f4c441e032 202
lixianyu 0:d8f4c441e032 203 static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
lixianyu 0:d8f4c441e032 204 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 205 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 206 0x0ae, /* display off */
lixianyu 0:d8f4c441e032 207 U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
lixianyu 0:d8f4c441e032 208 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 209 };
lixianyu 0:d8f4c441e032 210
lixianyu 0:d8f4c441e032 211 static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
lixianyu 0:d8f4c441e032 212 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 213 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 214 0x0af, /* display on */
lixianyu 0:d8f4c441e032 215 U8G_ESC_DLY(50), /* delay 50 ms */
lixianyu 0:d8f4c441e032 216 U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
lixianyu 0:d8f4c441e032 217 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 218 };
lixianyu 0:d8f4c441e032 219
lixianyu 0:d8f4c441e032 220 uint8_t u8g_dev_ssd1306_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 221 {
lixianyu 1:0e75de2a5d21 222 //printf("msg = %d\r\n", msg);
lixianyu 0:d8f4c441e032 223 switch(msg) {
lixianyu 0:d8f4c441e032 224 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 225 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
lixianyu 0:d8f4c441e032 226 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_adafruit2_init_seq);
lixianyu 0:d8f4c441e032 227 break;
lixianyu 0:d8f4c441e032 228 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 229 break;
lixianyu 0:d8f4c441e032 230 case U8G_DEV_MSG_PAGE_NEXT: {
lixianyu 1:0e75de2a5d21 231 //printf("U8G_DEV_MSG_PAGE_NEXT\r\n");
lixianyu 0:d8f4c441e032 232 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 233 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
lixianyu 0:d8f4c441e032 234 u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
lixianyu 0:d8f4c441e032 235 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 236 if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
lixianyu 0:d8f4c441e032 237 return 0;
lixianyu 0:d8f4c441e032 238 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 239 }
lixianyu 0:d8f4c441e032 240 break;
lixianyu 0:d8f4c441e032 241 case U8G_DEV_MSG_SLEEP_ON:
lixianyu 0:d8f4c441e032 242 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
lixianyu 0:d8f4c441e032 243 return 1;
lixianyu 0:d8f4c441e032 244 case U8G_DEV_MSG_SLEEP_OFF:
lixianyu 0:d8f4c441e032 245 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
lixianyu 0:d8f4c441e032 246 return 1;
lixianyu 0:d8f4c441e032 247 }
lixianyu 0:d8f4c441e032 248 return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
lixianyu 1:0e75de2a5d21 249 //return u8g_dev_pb8v2_base_fn(u8g, dev, msg, arg);
lixianyu 0:d8f4c441e032 250 }
lixianyu 0:d8f4c441e032 251
lixianyu 0:d8f4c441e032 252 uint8_t u8g_dev_ssd1306_adafruit_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 253 {
lixianyu 0:d8f4c441e032 254 switch(msg) {
lixianyu 0:d8f4c441e032 255 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 256 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
lixianyu 0:d8f4c441e032 257 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
lixianyu 0:d8f4c441e032 258 break;
lixianyu 0:d8f4c441e032 259 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 260 break;
lixianyu 0:d8f4c441e032 261 case U8G_DEV_MSG_PAGE_NEXT: {
lixianyu 0:d8f4c441e032 262 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 263 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
lixianyu 0:d8f4c441e032 264 u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
lixianyu 0:d8f4c441e032 265 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 266 if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
lixianyu 0:d8f4c441e032 267 return 0;
lixianyu 0:d8f4c441e032 268 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 269 }
lixianyu 0:d8f4c441e032 270 break;
lixianyu 0:d8f4c441e032 271 case U8G_DEV_MSG_SLEEP_ON:
lixianyu 0:d8f4c441e032 272 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
lixianyu 0:d8f4c441e032 273 return 1;
lixianyu 0:d8f4c441e032 274 case U8G_DEV_MSG_SLEEP_OFF:
lixianyu 0:d8f4c441e032 275 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
lixianyu 0:d8f4c441e032 276 return 1;
lixianyu 0:d8f4c441e032 277 }
lixianyu 0:d8f4c441e032 278 return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
lixianyu 0:d8f4c441e032 279 }
lixianyu 0:d8f4c441e032 280
lixianyu 0:d8f4c441e032 281 uint8_t u8g_dev_sh1106_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 282 {
lixianyu 0:d8f4c441e032 283 switch(msg) {
lixianyu 0:d8f4c441e032 284 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 285 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
lixianyu 0:d8f4c441e032 286 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
lixianyu 0:d8f4c441e032 287 break;
lixianyu 0:d8f4c441e032 288 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 289 break;
lixianyu 0:d8f4c441e032 290 case U8G_DEV_MSG_PAGE_NEXT: {
lixianyu 0:d8f4c441e032 291 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 292 u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
lixianyu 0:d8f4c441e032 293 u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
lixianyu 0:d8f4c441e032 294 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 295 if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
lixianyu 0:d8f4c441e032 296 return 0;
lixianyu 0:d8f4c441e032 297 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 298 }
lixianyu 0:d8f4c441e032 299 break;
lixianyu 0:d8f4c441e032 300 case U8G_DEV_MSG_SLEEP_ON:
lixianyu 0:d8f4c441e032 301 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
lixianyu 0:d8f4c441e032 302 return 1;
lixianyu 0:d8f4c441e032 303 case U8G_DEV_MSG_SLEEP_OFF:
lixianyu 0:d8f4c441e032 304 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
lixianyu 0:d8f4c441e032 305 return 1;
lixianyu 0:d8f4c441e032 306 }
lixianyu 0:d8f4c441e032 307 return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
lixianyu 0:d8f4c441e032 308 }
lixianyu 0:d8f4c441e032 309
lixianyu 0:d8f4c441e032 310
lixianyu 0:d8f4c441e032 311 uint8_t u8g_dev_ssd1306_128x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 312 {
lixianyu 0:d8f4c441e032 313 switch(msg) {
lixianyu 0:d8f4c441e032 314 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 315 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
lixianyu 0:d8f4c441e032 316 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
lixianyu 0:d8f4c441e032 317 break;
lixianyu 0:d8f4c441e032 318 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 319 break;
lixianyu 0:d8f4c441e032 320 case U8G_DEV_MSG_PAGE_NEXT: {
lixianyu 0:d8f4c441e032 321 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 322
lixianyu 0:d8f4c441e032 323 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
lixianyu 0:d8f4c441e032 324 u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
lixianyu 0:d8f4c441e032 325 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 326 u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
lixianyu 0:d8f4c441e032 327 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 328
lixianyu 0:d8f4c441e032 329 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
lixianyu 0:d8f4c441e032 330 u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
lixianyu 0:d8f4c441e032 331 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 332 u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
lixianyu 0:d8f4c441e032 333 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 334 }
lixianyu 0:d8f4c441e032 335 break;
lixianyu 0:d8f4c441e032 336 case U8G_DEV_MSG_SLEEP_ON:
lixianyu 0:d8f4c441e032 337 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
lixianyu 0:d8f4c441e032 338 return 1;
lixianyu 0:d8f4c441e032 339 case U8G_DEV_MSG_SLEEP_OFF:
lixianyu 0:d8f4c441e032 340 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
lixianyu 0:d8f4c441e032 341 return 1;
lixianyu 0:d8f4c441e032 342 }
lixianyu 0:d8f4c441e032 343 return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
lixianyu 0:d8f4c441e032 344 }
lixianyu 0:d8f4c441e032 345
lixianyu 0:d8f4c441e032 346 uint8_t u8g_dev_sh1106_128x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 347 {
lixianyu 0:d8f4c441e032 348 switch(msg) {
lixianyu 0:d8f4c441e032 349 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 350 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
lixianyu 0:d8f4c441e032 351 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
lixianyu 0:d8f4c441e032 352 break;
lixianyu 0:d8f4c441e032 353 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 354 break;
lixianyu 0:d8f4c441e032 355 case U8G_DEV_MSG_PAGE_NEXT: {
lixianyu 0:d8f4c441e032 356 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 357
lixianyu 0:d8f4c441e032 358 u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
lixianyu 0:d8f4c441e032 359 u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
lixianyu 0:d8f4c441e032 360 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 361 u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
lixianyu 0:d8f4c441e032 362 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 363
lixianyu 0:d8f4c441e032 364 u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
lixianyu 0:d8f4c441e032 365 u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
lixianyu 0:d8f4c441e032 366 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 367 u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
lixianyu 0:d8f4c441e032 368 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 369 }
lixianyu 0:d8f4c441e032 370 break;
lixianyu 0:d8f4c441e032 371 case U8G_DEV_MSG_SLEEP_ON:
lixianyu 0:d8f4c441e032 372 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
lixianyu 0:d8f4c441e032 373 return 1;
lixianyu 0:d8f4c441e032 374 case U8G_DEV_MSG_SLEEP_OFF:
lixianyu 0:d8f4c441e032 375 u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
lixianyu 0:d8f4c441e032 376 return 1;
lixianyu 0:d8f4c441e032 377 }
lixianyu 0:d8f4c441e032 378 return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
lixianyu 0:d8f4c441e032 379 }
lixianyu 0:d8f4c441e032 380
lixianyu 0:d8f4c441e032 381 U8G_PB_DEV(u8g_dev_ssd1306_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SW_SPI);
lixianyu 0:d8f4c441e032 382 U8G_PB_DEV(u8g_dev_ssd1306_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_HW_SPI);
lixianyu 0:d8f4c441e032 383 U8G_PB_DEV(u8g_dev_ssd1306_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SSD_I2C);
lixianyu 0:d8f4c441e032 384
lixianyu 0:d8f4c441e032 385 U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_SW_SPI);
lixianyu 0:d8f4c441e032 386 U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_HW_SPI);
lixianyu 0:d8f4c441e032 387 U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_SSD_I2C);
lixianyu 0:d8f4c441e032 388
lixianyu 0:d8f4c441e032 389 U8G_PB_DEV(u8g_dev_ssd1306_microduino_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SW_SPI);
lixianyu 0:d8f4c441e032 390 U8G_PB_DEV(u8g_dev_ssd1306_microduino_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_HW_SPI);
lixianyu 0:d8f4c441e032 391 U8G_PB_DEV(u8g_dev_ssd1306_microduino_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SSD_I2C);
lixianyu 0:d8f4c441e032 392
lixianyu 0:d8f4c441e032 393 uint8_t u8g_dev_ssd1306_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
lixianyu 0:d8f4c441e032 394 u8g_pb_t u8g_dev_ssd1306_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_128x64_2x_buf};
lixianyu 0:d8f4c441e032 395 u8g_dev_t u8g_dev_ssd1306_128x64_2x_sw_spi = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SW_SPI };
lixianyu 0:d8f4c441e032 396 u8g_dev_t u8g_dev_ssd1306_128x64_2x_hw_spi = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_HW_SPI };
lixianyu 0:d8f4c441e032 397 u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SSD_I2C };
lixianyu 0:d8f4c441e032 398
lixianyu 0:d8f4c441e032 399
lixianyu 0:d8f4c441e032 400 U8G_PB_DEV(u8g_dev_sh1106_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_SW_SPI);
lixianyu 0:d8f4c441e032 401 U8G_PB_DEV(u8g_dev_sh1106_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_HW_SPI);
lixianyu 0:d8f4c441e032 402 U8G_PB_DEV(u8g_dev_sh1106_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_SSD_I2C);
lixianyu 0:d8f4c441e032 403
lixianyu 0:d8f4c441e032 404 uint8_t u8g_dev_sh1106_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
lixianyu 0:d8f4c441e032 405 u8g_pb_t u8g_dev_sh1106_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_sh1106_128x64_2x_buf};
lixianyu 0:d8f4c441e032 406 u8g_dev_t u8g_dev_sh1106_128x64_2x_sw_spi = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_SW_SPI };
lixianyu 0:d8f4c441e032 407 u8g_dev_t u8g_dev_sh1106_128x64_2x_hw_spi = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_HW_SPI };
lixianyu 0:d8f4c441e032 408 u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_SSD_I2C };
lixianyu 0:d8f4c441e032 409
lixianyu 0:d8f4c441e032 410