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_pbxh16.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 x lines per page, horizontal, 16 bits per pixel (hi color modes)
lixianyu 0:d8f4c441e032 6
lixianyu 0:d8f4c441e032 7 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 8
lixianyu 0:d8f4c441e032 9 Copyright (c) 2013, olikraus@gmail.com
lixianyu 0:d8f4c441e032 10 All rights reserved.
lixianyu 0:d8f4c441e032 11
lixianyu 0:d8f4c441e032 12 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 13 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 14
lixianyu 0:d8f4c441e032 15 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 16 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 17
lixianyu 0:d8f4c441e032 18 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 19 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 20 materials provided with the distribution.
lixianyu 0:d8f4c441e032 21
lixianyu 0:d8f4c441e032 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 35
lixianyu 0:d8f4c441e032 36
lixianyu 0:d8f4c441e032 37 struct _u8g_pb_t
lixianyu 0:d8f4c441e032 38 {
lixianyu 0:d8f4c441e032 39 u8g_page_t p;
lixianyu 0:d8f4c441e032 40 u8g_uint_t width;
lixianyu 0:d8f4c441e032 41 void *buf;
lixianyu 0:d8f4c441e032 42 };
lixianyu 0:d8f4c441e032 43 typedef struct _u8g_pb_t u8g_pb_t;
lixianyu 0:d8f4c441e032 44
lixianyu 0:d8f4c441e032 45
lixianyu 0:d8f4c441e032 46 uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
lixianyu 0:d8f4c441e032 47 u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
lixianyu 0:d8f4c441e032 48 u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
lixianyu 0:d8f4c441e032 49
lixianyu 0:d8f4c441e032 50 */
lixianyu 0:d8f4c441e032 51
lixianyu 0:d8f4c441e032 52 #include "u8g.h"
lixianyu 0:d8f4c441e032 53
lixianyu 0:d8f4c441e032 54 /*
lixianyu 0:d8f4c441e032 55 #define WIDTH_BITS 7
lixianyu 0:d8f4c441e032 56 #define WIDTH (1<<WIDTH_BITS)
lixianyu 0:d8f4c441e032 57 #define PAGE_HEIGHT_BITS 3
lixianyu 0:d8f4c441e032 58 #define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
lixianyu 0:d8f4c441e032 59 */
lixianyu 0:d8f4c441e032 60
lixianyu 0:d8f4c441e032 61 void u8g_pbxh16_Clear(u8g_pb_t *b)
lixianyu 0:d8f4c441e032 62 {
lixianyu 0:d8f4c441e032 63 uint8_t *ptr = (uint8_t *)b->buf;
lixianyu 0:d8f4c441e032 64 uint8_t *end_ptr = ptr;
lixianyu 0:d8f4c441e032 65 uint8_t cnt = b->p.page_height;
lixianyu 0:d8f4c441e032 66 do
lixianyu 0:d8f4c441e032 67 {
lixianyu 0:d8f4c441e032 68 end_ptr += b->width*2;
lixianyu 0:d8f4c441e032 69 cnt--;
lixianyu 0:d8f4c441e032 70 } while( cnt > 0 );
lixianyu 0:d8f4c441e032 71 do
lixianyu 0:d8f4c441e032 72 {
lixianyu 0:d8f4c441e032 73 *ptr++ = 0;
lixianyu 0:d8f4c441e032 74 } while( ptr != end_ptr );
lixianyu 0:d8f4c441e032 75 }
lixianyu 0:d8f4c441e032 76
lixianyu 0:d8f4c441e032 77
lixianyu 0:d8f4c441e032 78 void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
lixianyu 0:d8f4c441e032 79 {
lixianyu 0:d8f4c441e032 80 b->buf = buf;
lixianyu 0:d8f4c441e032 81 b->width = width;
lixianyu 0:d8f4c441e032 82 u8g_pbxh16_Clear(b);
lixianyu 0:d8f4c441e032 83 }
lixianyu 0:d8f4c441e032 84
lixianyu 0:d8f4c441e032 85 static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high)
lixianyu 0:d8f4c441e032 86 {
lixianyu 0:d8f4c441e032 87 uint16_t tmp;
lixianyu 0:d8f4c441e032 88 uint8_t *ptr = b->buf;
lixianyu 0:d8f4c441e032 89 y -= b->p.page_y0;
lixianyu 0:d8f4c441e032 90 tmp = y;
lixianyu 0:d8f4c441e032 91 tmp *= b->width;
lixianyu 0:d8f4c441e032 92 tmp += x;
lixianyu 0:d8f4c441e032 93 tmp <<= 1;
lixianyu 0:d8f4c441e032 94 ptr += tmp;
lixianyu 0:d8f4c441e032 95 *ptr = low;
lixianyu 0:d8f4c441e032 96 ptr++;
lixianyu 0:d8f4c441e032 97 *ptr = high;
lixianyu 0:d8f4c441e032 98 }
lixianyu 0:d8f4c441e032 99
lixianyu 0:d8f4c441e032 100 void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
lixianyu 0:d8f4c441e032 101 {
lixianyu 0:d8f4c441e032 102 if ( arg_pixel->y < b->p.page_y0 )
lixianyu 0:d8f4c441e032 103 return;
lixianyu 0:d8f4c441e032 104 if ( arg_pixel->y > b->p.page_y1 )
lixianyu 0:d8f4c441e032 105 return;
lixianyu 0:d8f4c441e032 106 if ( arg_pixel->x >= b->width )
lixianyu 0:d8f4c441e032 107 return;
lixianyu 0:d8f4c441e032 108 u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color);
lixianyu 0:d8f4c441e032 109 }
lixianyu 0:d8f4c441e032 110
lixianyu 0:d8f4c441e032 111
lixianyu 0:d8f4c441e032 112 void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
lixianyu 0:d8f4c441e032 113 {
lixianyu 0:d8f4c441e032 114 register uint8_t pixel = arg_pixel->pixel;
lixianyu 0:d8f4c441e032 115 u8g_uint_t dx = 0;
lixianyu 0:d8f4c441e032 116 u8g_uint_t dy = 0;
lixianyu 0:d8f4c441e032 117
lixianyu 0:d8f4c441e032 118 switch( arg_pixel->dir )
lixianyu 0:d8f4c441e032 119 {
lixianyu 0:d8f4c441e032 120 case 0: dx++; break;
lixianyu 0:d8f4c441e032 121 case 1: dy++; break;
lixianyu 0:d8f4c441e032 122 case 2: dx--; break;
lixianyu 0:d8f4c441e032 123 case 3: dy--; break;
lixianyu 0:d8f4c441e032 124 }
lixianyu 0:d8f4c441e032 125
lixianyu 0:d8f4c441e032 126 do
lixianyu 0:d8f4c441e032 127 {
lixianyu 0:d8f4c441e032 128 if ( pixel & 128 )
lixianyu 0:d8f4c441e032 129 u8g_pbxh16_SetPixel(b, arg_pixel);
lixianyu 0:d8f4c441e032 130 arg_pixel->x += dx;
lixianyu 0:d8f4c441e032 131 arg_pixel->y += dy;
lixianyu 0:d8f4c441e032 132 pixel <<= 1;
lixianyu 0:d8f4c441e032 133 } while( pixel != 0 );
lixianyu 0:d8f4c441e032 134 }
lixianyu 0:d8f4c441e032 135
lixianyu 0:d8f4c441e032 136
lixianyu 0:d8f4c441e032 137 uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
lixianyu 0:d8f4c441e032 138 {
lixianyu 0:d8f4c441e032 139 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
lixianyu 0:d8f4c441e032 140 switch(msg)
lixianyu 0:d8f4c441e032 141 {
lixianyu 0:d8f4c441e032 142 case U8G_DEV_MSG_SET_8PIXEL:
lixianyu 0:d8f4c441e032 143 if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
lixianyu 0:d8f4c441e032 144 u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
lixianyu 0:d8f4c441e032 145 break;
lixianyu 0:d8f4c441e032 146 case U8G_DEV_MSG_SET_PIXEL:
lixianyu 0:d8f4c441e032 147 u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
lixianyu 0:d8f4c441e032 148 break;
lixianyu 0:d8f4c441e032 149 case U8G_DEV_MSG_INIT:
lixianyu 0:d8f4c441e032 150 break;
lixianyu 0:d8f4c441e032 151 case U8G_DEV_MSG_STOP:
lixianyu 0:d8f4c441e032 152 break;
lixianyu 0:d8f4c441e032 153 case U8G_DEV_MSG_PAGE_FIRST:
lixianyu 0:d8f4c441e032 154 u8g_pbxh16_Clear(pb);
lixianyu 0:d8f4c441e032 155 u8g_page_First(&(pb->p));
lixianyu 0:d8f4c441e032 156 break;
lixianyu 0:d8f4c441e032 157 case U8G_DEV_MSG_PAGE_NEXT:
lixianyu 0:d8f4c441e032 158 if ( u8g_page_Next(&(pb->p)) == 0 )
lixianyu 0:d8f4c441e032 159 return 0;
lixianyu 0:d8f4c441e032 160 u8g_pbxh16_Clear(pb);
lixianyu 0:d8f4c441e032 161 break;
lixianyu 0:d8f4c441e032 162 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
lixianyu 0:d8f4c441e032 163 case U8G_DEV_MSG_IS_BBX_INTERSECTION:
lixianyu 0:d8f4c441e032 164 return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
lixianyu 0:d8f4c441e032 165 #endif
lixianyu 0:d8f4c441e032 166 case U8G_DEV_MSG_GET_PAGE_BOX:
lixianyu 0:d8f4c441e032 167 u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
lixianyu 0:d8f4c441e032 168 break;
lixianyu 0:d8f4c441e032 169 case U8G_DEV_MSG_GET_WIDTH:
lixianyu 0:d8f4c441e032 170 *((u8g_uint_t *)arg) = pb->width;
lixianyu 0:d8f4c441e032 171 break;
lixianyu 0:d8f4c441e032 172 case U8G_DEV_MSG_GET_HEIGHT:
lixianyu 0:d8f4c441e032 173 *((u8g_uint_t *)arg) = pb->p.total_height;
lixianyu 0:d8f4c441e032 174 break;
lixianyu 0:d8f4c441e032 175 case U8G_DEV_MSG_SET_COLOR_ENTRY:
lixianyu 0:d8f4c441e032 176 break;
lixianyu 0:d8f4c441e032 177 case U8G_DEV_MSG_SET_XY_CB:
lixianyu 0:d8f4c441e032 178 break;
lixianyu 0:d8f4c441e032 179 case U8G_DEV_MSG_GET_MODE:
lixianyu 0:d8f4c441e032 180 return U8G_MODE_HICOLOR;
lixianyu 0:d8f4c441e032 181 }
lixianyu 0:d8f4c441e032 182 return 1;
lixianyu 0:d8f4c441e032 183 }
lixianyu 0:d8f4c441e032 184
lixianyu 0:d8f4c441e032 185