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_st7565_lm6059.c (Adafruit display)
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 0:d8f4c441e032 38
lixianyu 0:d8f4c441e032 39 #define WIDTH 128
lixianyu 0:d8f4c441e032 40 #define HEIGHT 64
lixianyu 0:d8f4c441e032 41 #define PAGE_HEIGHT 8
lixianyu 0:d8f4c441e032 42
lixianyu 0:d8f4c441e032 43 /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
lixianyu 0:d8f4c441e032 44 static const uint8_t u8g_dev_st7565_lm6059_init_seq[] PROGMEM = {
lixianyu 0:d8f4c441e032 45 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 46 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 47 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 48 U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
lixianyu 0:d8f4c441e032 49
lixianyu 0:d8f4c441e032 50 0x0a3, /* 0x0a2: LCD bias 1/9 (suggested for the LM6063), 0x0a3: Used by Adafruit, 0x0a2 does not work */
lixianyu 0:d8f4c441e032 51 /* the LM6059 vs LM6063, ADC and SHL have inverted settings */
lixianyu 0:d8f4c441e032 52 0x0a0, /* 0x0a1: ADC set to normal (suggested for the LM6059), 0x0a0: Used by Adafruit -> normal mode */
lixianyu 0:d8f4c441e032 53 0x0c8, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
lixianyu 0:d8f4c441e032 54 0x060, /* set display start line */
lixianyu 0:d8f4c441e032 55
lixianyu 0:d8f4c441e032 56 0x028 | 0x04, /* power control: turn on voltage converter */
lixianyu 0:d8f4c441e032 57 U8G_ESC_DLY(50), /* delay 50 ms */
lixianyu 0:d8f4c441e032 58
lixianyu 0:d8f4c441e032 59 0x028 | 0x06, /* power control: turn on voltage regulator */
lixianyu 0:d8f4c441e032 60 U8G_ESC_DLY(50), /* delay 50 ms */
lixianyu 0:d8f4c441e032 61
lixianyu 0:d8f4c441e032 62 0x028 | 0x07, /* power control: turn on voltage follower */
lixianyu 0:d8f4c441e032 63 U8G_ESC_DLY(50), /* delay 50 ms */
lixianyu 0:d8f4c441e032 64
lixianyu 0:d8f4c441e032 65 0x026, /* set V0 voltage resistor ratio to 6 (Adafruit Value, no info from LM6063 Manual) */
lixianyu 0:d8f4c441e032 66
lixianyu 0:d8f4c441e032 67 0x0a6, /* display normal, bit val 0: LCD pixel off. */
lixianyu 0:d8f4c441e032 68
lixianyu 0:d8f4c441e032 69 0x081, /* set contrast */
lixianyu 0:d8f4c441e032 70 0x018, /* contrast value*/
lixianyu 0:d8f4c441e032 71
lixianyu 0:d8f4c441e032 72 /*0x0ac,*/ /* indicator */
lixianyu 0:d8f4c441e032 73 /*0x000,*/ /* disable */
lixianyu 0:d8f4c441e032 74
lixianyu 0:d8f4c441e032 75 0x0af, /* display on */
lixianyu 0:d8f4c441e032 76
lixianyu 0:d8f4c441e032 77 U8G_ESC_DLY(100), /* delay 100 ms */
lixianyu 0:d8f4c441e032 78 0x0a5, /* display all points, ST7565 */
lixianyu 0:d8f4c441e032 79 U8G_ESC_DLY(100), /* delay 100 ms */
lixianyu 0:d8f4c441e032 80 U8G_ESC_DLY(100), /* delay 100 ms */
lixianyu 0:d8f4c441e032 81 0x0a4, /* normal display */
lixianyu 0:d8f4c441e032 82 U8G_ESC_CS(0), /* disable chip */
lixianyu 0:d8f4c441e032 83 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 84 };
lixianyu 0:d8f4c441e032 85
lixianyu 0:d8f4c441e032 86 static const uint8_t u8g_dev_st7565_lm6059_data_start[] PROGMEM = {
lixianyu 0:d8f4c441e032 87 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 88 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 89 0x010, /* set upper 4 bit of the col adr to 0 */
lixianyu 0:d8f4c441e032 90 0x001, /* set lower 4 bit of the col adr */
lixianyu 0:d8f4c441e032 91 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 92 };
lixianyu 0:d8f4c441e032 93
lixianyu 0:d8f4c441e032 94 static const uint8_t u8g_dev_st7565_lm6059_sleep_on[] PROGMEM = {
lixianyu 0:d8f4c441e032 95 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 96 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 97 0x0ac, /* static indicator off */
lixianyu 0:d8f4c441e032 98 0x000, /* indicator register set (not sure if this is required) */
lixianyu 0:d8f4c441e032 99 0x0ae, /* display off */
lixianyu 0:d8f4c441e032 100 0x0a5, /* all points on */
lixianyu 0:d8f4c441e032 101 U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
lixianyu 0:d8f4c441e032 102 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 103 };
lixianyu 0:d8f4c441e032 104
lixianyu 0:d8f4c441e032 105 static const uint8_t u8g_dev_st7565_lm6059_sleep_off[] PROGMEM = {
lixianyu 0:d8f4c441e032 106 U8G_ESC_ADR(0), /* instruction mode */
lixianyu 0:d8f4c441e032 107 U8G_ESC_CS(1), /* enable chip */
lixianyu 0:d8f4c441e032 108 0x0a4, /* all points off */
lixianyu 0:d8f4c441e032 109 0x0af, /* display on */
lixianyu 0:d8f4c441e032 110 U8G_ESC_DLY(50), /* delay 50 ms */
lixianyu 0:d8f4c441e032 111 U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
lixianyu 0:d8f4c441e032 112 U8G_ESC_END /* end of sequence */
lixianyu 0:d8f4c441e032 113 };
lixianyu 0:d8f4c441e032 114
lixianyu 0:d8f4c441e032 115
lixianyu 0:d8f4c441e032 116 uint8_t u8g_dev_st7565_lm6059_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 117 {
lixianyu 0:d8f4c441e032 118 switch(msg)
lixianyu 0:d8f4c441e032 119 {
lixianyu 0:d8f4c441e032 120 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 121 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
lixianyu 0:d8f4c441e032 122 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_init_seq);
lixianyu 0:d8f4c441e032 123 break;
lixianyu 0:d8f4c441e032 124 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 125 break;
lixianyu 0:d8f4c441e032 126 case U8G_DEV_MSG_PAGE_NEXT:
lixianyu 0:d8f4c441e032 127 {
lixianyu 0:d8f4c441e032 128 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 129 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
lixianyu 0:d8f4c441e032 130 u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
lixianyu 0:d8f4c441e032 131 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 132 if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
lixianyu 0:d8f4c441e032 133 return 0;
lixianyu 0:d8f4c441e032 134 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 135 }
lixianyu 0:d8f4c441e032 136 break;
lixianyu 0:d8f4c441e032 137 case U8G_DEV_MSG_CONTRAST:
lixianyu 0:d8f4c441e032 138 u8g_SetChipSelect(u8g, dev, 1);
lixianyu 0:d8f4c441e032 139 u8g_SetAddress(u8g, dev, 0); /* instruction mode */
lixianyu 0:d8f4c441e032 140 u8g_WriteByte(u8g, dev, 0x081);
lixianyu 0:d8f4c441e032 141 u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
lixianyu 0:d8f4c441e032 142 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 143 return 1;
lixianyu 0:d8f4c441e032 144 case U8G_DEV_MSG_SLEEP_ON:
lixianyu 0:d8f4c441e032 145 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_on);
lixianyu 0:d8f4c441e032 146 return 1;
lixianyu 0:d8f4c441e032 147 case U8G_DEV_MSG_SLEEP_OFF:
lixianyu 0:d8f4c441e032 148 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_off);
lixianyu 0:d8f4c441e032 149 return 1;
lixianyu 0:d8f4c441e032 150 }
lixianyu 0:d8f4c441e032 151 return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
lixianyu 0:d8f4c441e032 152 }
lixianyu 0:d8f4c441e032 153
lixianyu 0:d8f4c441e032 154 uint8_t u8g_dev_st7565_lm6059_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 155 {
lixianyu 0:d8f4c441e032 156 switch(msg)
lixianyu 0:d8f4c441e032 157 {
lixianyu 0:d8f4c441e032 158 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 159 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
lixianyu 0:d8f4c441e032 160 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_init_seq);
lixianyu 0:d8f4c441e032 161 break;
lixianyu 0:d8f4c441e032 162 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 163 break;
lixianyu 0:d8f4c441e032 164 case U8G_DEV_MSG_PAGE_NEXT:
lixianyu 0:d8f4c441e032 165 {
lixianyu 0:d8f4c441e032 166 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 167
lixianyu 0:d8f4c441e032 168 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
lixianyu 0:d8f4c441e032 169 u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
lixianyu 0:d8f4c441e032 170 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 171 u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
lixianyu 0:d8f4c441e032 172 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 173
lixianyu 0:d8f4c441e032 174 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
lixianyu 0:d8f4c441e032 175 u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
lixianyu 0:d8f4c441e032 176 u8g_SetAddress(u8g, dev, 1); /* data mode */
lixianyu 0:d8f4c441e032 177 u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
lixianyu 0:d8f4c441e032 178 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 179 }
lixianyu 0:d8f4c441e032 180 break;
lixianyu 0:d8f4c441e032 181 case U8G_DEV_MSG_CONTRAST:
lixianyu 0:d8f4c441e032 182 u8g_SetChipSelect(u8g, dev, 1);
lixianyu 0:d8f4c441e032 183 u8g_SetAddress(u8g, dev, 0); /* instruction mode */
lixianyu 0:d8f4c441e032 184 u8g_WriteByte(u8g, dev, 0x081);
lixianyu 0:d8f4c441e032 185 u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
lixianyu 0:d8f4c441e032 186 u8g_SetChipSelect(u8g, dev, 0);
lixianyu 0:d8f4c441e032 187 return 1;
lixianyu 0:d8f4c441e032 188 case U8G_DEV_MSG_SLEEP_ON:
lixianyu 0:d8f4c441e032 189 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_on);
lixianyu 0:d8f4c441e032 190 return 1;
lixianyu 0:d8f4c441e032 191 case U8G_DEV_MSG_SLEEP_OFF:
lixianyu 0:d8f4c441e032 192 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_off);
lixianyu 0:d8f4c441e032 193 return 1;
lixianyu 0:d8f4c441e032 194 }
lixianyu 0:d8f4c441e032 195 return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
lixianyu 0:d8f4c441e032 196 }
lixianyu 0:d8f4c441e032 197
lixianyu 0:d8f4c441e032 198 U8G_PB_DEV(u8g_dev_st7565_lm6059_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6059_fn, U8G_COM_SW_SPI);
lixianyu 0:d8f4c441e032 199 U8G_PB_DEV(u8g_dev_st7565_lm6059_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6059_fn, U8G_COM_HW_SPI);
lixianyu 0:d8f4c441e032 200
lixianyu 0:d8f4c441e032 201
lixianyu 0:d8f4c441e032 202 uint8_t u8g_dev_st7565_lm6059_2x_buf[WIDTH*2] U8G_NOCOMMON ;
lixianyu 0:d8f4c441e032 203 u8g_pb_t u8g_dev_st7565_lm6059_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_lm6059_2x_buf};
lixianyu 0:d8f4c441e032 204 u8g_dev_t u8g_dev_st7565_lm6059_2x_sw_spi = { u8g_dev_st7565_lm6059_2x_fn, &u8g_dev_st7565_lm6059_2x_pb, U8G_COM_SW_SPI };
lixianyu 0:d8f4c441e032 205 u8g_dev_t u8g_dev_st7565_lm6059_2x_hw_spi = { u8g_dev_st7565_lm6059_2x_fn, &u8g_dev_st7565_lm6059_2x_pb, U8G_COM_HW_SPI };
lixianyu 0:d8f4c441e032 206