hadif azli / Mbed 2 deprecated TEST123

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Fri Jun 10 15:20:20 2016 +0000
Revision:
0:d8f4c441e032
Child:
1:0e75de2a5d21
u8glib???????????i2c???

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:d8f4c441e032 1 /*
lixianyu 0:d8f4c441e032 2
lixianyu 0:d8f4c441e032 3 u8g_com_api.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 0:d8f4c441e032 38
lixianyu 0:d8f4c441e032 39 uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time)
lixianyu 0:d8f4c441e032 40 {
lixianyu 0:d8f4c441e032 41 return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL);
lixianyu 0:d8f4c441e032 42 }
lixianyu 0:d8f4c441e032 43
lixianyu 0:d8f4c441e032 44 void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev)
lixianyu 0:d8f4c441e032 45 {
lixianyu 0:d8f4c441e032 46 dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL);
lixianyu 0:d8f4c441e032 47 }
lixianyu 0:d8f4c441e032 48
lixianyu 0:d8f4c441e032 49 /* cs contains the chip number, which should be enabled */
lixianyu 0:d8f4c441e032 50 void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs)
lixianyu 0:d8f4c441e032 51 {
lixianyu 0:d8f4c441e032 52 dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL);
lixianyu 0:d8f4c441e032 53 }
lixianyu 0:d8f4c441e032 54
lixianyu 0:d8f4c441e032 55 void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev)
lixianyu 0:d8f4c441e032 56 {
lixianyu 0:d8f4c441e032 57 dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL);
lixianyu 0:d8f4c441e032 58 }
lixianyu 0:d8f4c441e032 59
lixianyu 0:d8f4c441e032 60 void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev)
lixianyu 0:d8f4c441e032 61 {
lixianyu 0:d8f4c441e032 62 dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL);
lixianyu 0:d8f4c441e032 63 }
lixianyu 0:d8f4c441e032 64
lixianyu 0:d8f4c441e032 65
lixianyu 0:d8f4c441e032 66 void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address)
lixianyu 0:d8f4c441e032 67 {
lixianyu 0:d8f4c441e032 68 dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL);
lixianyu 0:d8f4c441e032 69 }
lixianyu 0:d8f4c441e032 70
lixianyu 0:d8f4c441e032 71 uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val)
lixianyu 0:d8f4c441e032 72 {
lixianyu 0:d8f4c441e032 73 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL);
lixianyu 0:d8f4c441e032 74 }
lixianyu 0:d8f4c441e032 75
lixianyu 0:d8f4c441e032 76 uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq)
lixianyu 0:d8f4c441e032 77 {
lixianyu 0:d8f4c441e032 78 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq);
lixianyu 0:d8f4c441e032 79 }
lixianyu 0:d8f4c441e032 80
lixianyu 0:d8f4c441e032 81 uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq)
lixianyu 0:d8f4c441e032 82 {
lixianyu 0:d8f4c441e032 83 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq);
lixianyu 0:d8f4c441e032 84 }
lixianyu 0:d8f4c441e032 85
lixianyu 0:d8f4c441e032 86 /*
lixianyu 0:d8f4c441e032 87 sequence := { direct_value | escape_sequence }
lixianyu 0:d8f4c441e032 88 direct_value := 0..254
lixianyu 0:d8f4c441e032 89 escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used
lixianyu 0:d8f4c441e032 90 value_255 := 255 255
lixianyu 0:d8f4c441e032 91 sequence_end = 255 254
lixianyu 0:d8f4c441e032 92 delay := 255 0..127
lixianyu 0:d8f4c441e032 93 adr := 255 0x0e0 .. 0x0ef
lixianyu 0:d8f4c441e032 94 cs := 255 0x0d0 .. 0x0df
lixianyu 0:d8f4c441e032 95 not_used := 255 101..254
lixianyu 0:d8f4c441e032 96
lixianyu 0:d8f4c441e032 97 #define U8G_ESC_DLY(x) 255, ((x) & 0x7f)
lixianyu 0:d8f4c441e032 98 #define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f))
lixianyu 0:d8f4c441e032 99 #define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f))
lixianyu 0:d8f4c441e032 100 #define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01))
lixianyu 0:d8f4c441e032 101 #define U8G_ESC_END 255, 254
lixianyu 0:d8f4c441e032 102 #define U8G_ESC_255 255, 255
lixianyu 0:d8f4c441e032 103 #define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f))
lixianyu 0:d8f4c441e032 104
lixianyu 0:d8f4c441e032 105 */
lixianyu 0:d8f4c441e032 106 uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq)
lixianyu 0:d8f4c441e032 107 {
lixianyu 0:d8f4c441e032 108 uint8_t is_escape = 0;
lixianyu 0:d8f4c441e032 109 uint8_t value;
lixianyu 0:d8f4c441e032 110 for(;;)
lixianyu 0:d8f4c441e032 111 {
lixianyu 0:d8f4c441e032 112 value = u8g_pgm_read(esc_seq);
lixianyu 0:d8f4c441e032 113 if ( is_escape == 0 )
lixianyu 0:d8f4c441e032 114 {
lixianyu 0:d8f4c441e032 115 if ( value != 255 )
lixianyu 0:d8f4c441e032 116 {
lixianyu 0:d8f4c441e032 117 if ( u8g_WriteByte(u8g, dev, value) == 0 )
lixianyu 0:d8f4c441e032 118 return 0;
lixianyu 0:d8f4c441e032 119 }
lixianyu 0:d8f4c441e032 120 else
lixianyu 0:d8f4c441e032 121 {
lixianyu 0:d8f4c441e032 122 is_escape = 1;
lixianyu 0:d8f4c441e032 123 }
lixianyu 0:d8f4c441e032 124 }
lixianyu 0:d8f4c441e032 125 else
lixianyu 0:d8f4c441e032 126 {
lixianyu 0:d8f4c441e032 127 if ( value == 255 )
lixianyu 0:d8f4c441e032 128 {
lixianyu 0:d8f4c441e032 129 if ( u8g_WriteByte(u8g, dev, value) == 0 )
lixianyu 0:d8f4c441e032 130 return 0;
lixianyu 0:d8f4c441e032 131 }
lixianyu 0:d8f4c441e032 132 else if ( value == 254 )
lixianyu 0:d8f4c441e032 133 {
lixianyu 0:d8f4c441e032 134 break;
lixianyu 0:d8f4c441e032 135 }
lixianyu 0:d8f4c441e032 136 else if ( value >= 0x0f0 )
lixianyu 0:d8f4c441e032 137 {
lixianyu 0:d8f4c441e032 138 /* not yet used, do nothing */
lixianyu 0:d8f4c441e032 139 }
lixianyu 0:d8f4c441e032 140 else if ( value >= 0xe0 )
lixianyu 0:d8f4c441e032 141 {
lixianyu 0:d8f4c441e032 142 u8g_SetAddress(u8g, dev, value & 0x0f);
lixianyu 0:d8f4c441e032 143 }
lixianyu 0:d8f4c441e032 144 else if ( value >= 0xd0 )
lixianyu 0:d8f4c441e032 145 {
lixianyu 0:d8f4c441e032 146 u8g_SetChipSelect(u8g, dev, value & 0x0f);
lixianyu 0:d8f4c441e032 147 }
lixianyu 0:d8f4c441e032 148 else if ( value >= 0xc0 )
lixianyu 0:d8f4c441e032 149 {
lixianyu 0:d8f4c441e032 150 u8g_SetResetLow(u8g, dev);
lixianyu 0:d8f4c441e032 151 value &= 0x0f;
lixianyu 0:d8f4c441e032 152 value <<= 4;
lixianyu 0:d8f4c441e032 153 value+=2;
lixianyu 0:d8f4c441e032 154 u8g_Delay(value);
lixianyu 0:d8f4c441e032 155 u8g_SetResetHigh(u8g, dev);
lixianyu 0:d8f4c441e032 156 u8g_Delay(value);
lixianyu 0:d8f4c441e032 157 }
lixianyu 0:d8f4c441e032 158 else if ( value >= 0xbe )
lixianyu 0:d8f4c441e032 159 {
lixianyu 0:d8f4c441e032 160 /* not yet implemented */
lixianyu 0:d8f4c441e032 161 /* u8g_SetVCC(u8g, dev, value & 0x01); */
lixianyu 0:d8f4c441e032 162 }
lixianyu 0:d8f4c441e032 163 else if ( value <= 127 )
lixianyu 0:d8f4c441e032 164 {
lixianyu 0:d8f4c441e032 165 u8g_Delay(value);
lixianyu 0:d8f4c441e032 166 }
lixianyu 0:d8f4c441e032 167 is_escape = 0;
lixianyu 0:d8f4c441e032 168 }
lixianyu 0:d8f4c441e032 169 esc_seq++;
lixianyu 0:d8f4c441e032 170 }
lixianyu 0:d8f4c441e032 171 return 1;
lixianyu 0:d8f4c441e032 172 }
lixianyu 0:d8f4c441e032 173
lixianyu 0:d8f4c441e032 174