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_com_api_16gr.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 Extension of the com api for devices with 16 graylevels (4 bit per pixel).
lixianyu 0:d8f4c441e032 6 This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2),
lixianyu 0:d8f4c441e032 7 mainly intended for SSD OLEDs
lixianyu 0:d8f4c441e032 8
lixianyu 0:d8f4c441e032 9 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 10
lixianyu 0:d8f4c441e032 11 Copyright (c) 2011, olikraus@gmail.com
lixianyu 0:d8f4c441e032 12 All rights reserved.
lixianyu 0:d8f4c441e032 13
lixianyu 0:d8f4c441e032 14 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 15 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 16
lixianyu 0:d8f4c441e032 17 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 18 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 19
lixianyu 0:d8f4c441e032 20 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 21 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 22 materials provided with the distribution.
lixianyu 0:d8f4c441e032 23
lixianyu 0:d8f4c441e032 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 25 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 26 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 27 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 29 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 30 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 31 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 34 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 36 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 37
lixianyu 0:d8f4c441e032 38
lixianyu 0:d8f4c441e032 39 */
lixianyu 0:d8f4c441e032 40
lixianyu 0:d8f4c441e032 41 #include "u8g.h"
lixianyu 0:d8f4c441e032 42
lixianyu 0:d8f4c441e032 43 /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */
lixianyu 0:d8f4c441e032 44 /* topbit (msb) is sent last */
lixianyu 0:d8f4c441e032 45 /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */
lixianyu 0:d8f4c441e032 46 uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
lixianyu 0:d8f4c441e032 47 {
lixianyu 0:d8f4c441e032 48 static uint8_t buf[4];
lixianyu 0:d8f4c441e032 49 static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff };
lixianyu 0:d8f4c441e032 50 buf [3] = map[b & 3];
lixianyu 0:d8f4c441e032 51 b>>=2;
lixianyu 0:d8f4c441e032 52 buf [2] = map[b & 3];
lixianyu 0:d8f4c441e032 53 b>>=2;
lixianyu 0:d8f4c441e032 54 buf [1] = map[b & 3];
lixianyu 0:d8f4c441e032 55 b>>=2;
lixianyu 0:d8f4c441e032 56 buf [0] = map[b & 3];
lixianyu 0:d8f4c441e032 57 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf);
lixianyu 0:d8f4c441e032 58 }
lixianyu 0:d8f4c441e032 59
lixianyu 0:d8f4c441e032 60 uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
lixianyu 0:d8f4c441e032 61 {
lixianyu 0:d8f4c441e032 62 do
lixianyu 0:d8f4c441e032 63 {
lixianyu 0:d8f4c441e032 64 if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 )
lixianyu 0:d8f4c441e032 65 return 0;
lixianyu 0:d8f4c441e032 66 cnt--;
lixianyu 0:d8f4c441e032 67 } while( cnt != 0 );
lixianyu 0:d8f4c441e032 68 return 1;
lixianyu 0:d8f4c441e032 69 }
lixianyu 0:d8f4c441e032 70
lixianyu 0:d8f4c441e032 71 /* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */
lixianyu 0:d8f4c441e032 72 uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
lixianyu 0:d8f4c441e032 73 {
lixianyu 0:d8f4c441e032 74 //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc};
lixianyu 0:d8f4c441e032 75 //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff};
lixianyu 0:d8f4c441e032 76 static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff};
lixianyu 0:d8f4c441e032 77 uint8_t bb;
lixianyu 0:d8f4c441e032 78 bb = b;
lixianyu 0:d8f4c441e032 79 bb &= 15;
lixianyu 0:d8f4c441e032 80 b>>=4;
lixianyu 0:d8f4c441e032 81 dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL);
lixianyu 0:d8f4c441e032 82 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL);
lixianyu 0:d8f4c441e032 83 }
lixianyu 0:d8f4c441e032 84
lixianyu 0:d8f4c441e032 85 uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
lixianyu 0:d8f4c441e032 86 {
lixianyu 0:d8f4c441e032 87 do
lixianyu 0:d8f4c441e032 88 {
lixianyu 0:d8f4c441e032 89 if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 )
lixianyu 0:d8f4c441e032 90 return 0;
lixianyu 0:d8f4c441e032 91 cnt--;
lixianyu 0:d8f4c441e032 92 } while( cnt != 0 );
lixianyu 0:d8f4c441e032 93 return 1;
lixianyu 0:d8f4c441e032 94 }
lixianyu 0:d8f4c441e032 95