Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
u8g_pbxh16.c
00001 /* 00002 00003 u8g_pbxh16.c 00004 00005 x lines per page, horizontal, 16 bits per pixel (hi color modes) 00006 00007 Universal 8bit Graphics Library 00008 00009 Copyright (c) 2013, olikraus@gmail.com 00010 All rights reserved. 00011 00012 Redistribution and use in source and binary forms, with or without modification, 00013 are permitted provided that the following conditions are met: 00014 00015 * Redistributions of source code must retain the above copyright notice, this list 00016 of conditions and the following disclaimer. 00017 00018 * Redistributions in binary form must reproduce the above copyright notice, this 00019 list of conditions and the following disclaimer in the documentation and/or other 00020 materials provided with the distribution. 00021 00022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00023 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00024 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00025 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00027 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00029 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00032 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00033 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00034 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 00036 00037 struct _u8g_pb_t 00038 { 00039 u8g_page_t p; 00040 u8g_uint_t width; 00041 void *buf; 00042 }; 00043 typedef struct _u8g_pb_t u8g_pb_t; 00044 00045 00046 uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 00047 u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf}; 00048 u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn } 00049 00050 */ 00051 00052 #include "u8g.h" 00053 00054 /* 00055 #define WIDTH_BITS 7 00056 #define WIDTH (1<<WIDTH_BITS) 00057 #define PAGE_HEIGHT_BITS 3 00058 #define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS) 00059 */ 00060 00061 void u8g_pbxh16_Clear(u8g_pb_t *b) 00062 { 00063 uint8_t *ptr = (uint8_t *)b->buf; 00064 uint8_t *end_ptr = ptr; 00065 uint8_t cnt = b->p.page_height; 00066 do 00067 { 00068 end_ptr += b->width*2; 00069 cnt--; 00070 } while( cnt > 0 ); 00071 do 00072 { 00073 *ptr++ = 0; 00074 } while( ptr != end_ptr ); 00075 } 00076 00077 00078 void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 00079 { 00080 b->buf = buf; 00081 b->width = width; 00082 u8g_pbxh16_Clear(b); 00083 } 00084 00085 static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high) 00086 { 00087 uint16_t tmp; 00088 uint8_t *ptr = b->buf; 00089 y -= b->p.page_y0; 00090 tmp = y; 00091 tmp *= b->width; 00092 tmp += x; 00093 tmp <<= 1; 00094 ptr += tmp; 00095 *ptr = low; 00096 ptr++; 00097 *ptr = high; 00098 } 00099 00100 void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 00101 { 00102 if ( arg_pixel->y < b->p.page_y0 ) 00103 return; 00104 if ( arg_pixel->y > b->p.page_y1 ) 00105 return; 00106 if ( arg_pixel->x >= b->width ) 00107 return; 00108 u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color); 00109 } 00110 00111 00112 void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00113 { 00114 register uint8_t pixel = arg_pixel->pixel; 00115 u8g_uint_t dx = 0; 00116 u8g_uint_t dy = 0; 00117 00118 switch( arg_pixel->dir ) 00119 { 00120 case 0: dx++; break; 00121 case 1: dy++; break; 00122 case 2: dx--; break; 00123 case 3: dy--; break; 00124 } 00125 00126 do 00127 { 00128 if ( pixel & 128 ) 00129 u8g_pbxh16_SetPixel(b, arg_pixel); 00130 arg_pixel->x += dx; 00131 arg_pixel->y += dy; 00132 pixel <<= 1; 00133 } while( pixel != 0 ); 00134 } 00135 00136 00137 uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00138 { 00139 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00140 switch(msg) 00141 { 00142 case U8G_DEV_MSG_SET_8PIXEL: 00143 if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 00144 u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 00145 break; 00146 case U8G_DEV_MSG_SET_PIXEL: 00147 u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 00148 break; 00149 case U8G_DEV_MSG_INIT: 00150 break; 00151 case U8G_DEV_MSG_STOP: 00152 break; 00153 case U8G_DEV_MSG_PAGE_FIRST: 00154 u8g_pbxh16_Clear(pb); 00155 u8g_page_First(&(pb->p)); 00156 break; 00157 case U8G_DEV_MSG_PAGE_NEXT: 00158 if ( u8g_page_Next(&(pb->p)) == 0 ) 00159 return 0; 00160 u8g_pbxh16_Clear(pb); 00161 break; 00162 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 00163 case U8G_DEV_MSG_IS_BBX_INTERSECTION: 00164 return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 00165 #endif 00166 case U8G_DEV_MSG_GET_PAGE_BOX: 00167 u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 00168 break; 00169 case U8G_DEV_MSG_GET_WIDTH: 00170 *((u8g_uint_t *)arg) = pb->width; 00171 break; 00172 case U8G_DEV_MSG_GET_HEIGHT: 00173 *((u8g_uint_t *)arg) = pb->p.total_height; 00174 break; 00175 case U8G_DEV_MSG_SET_COLOR_ENTRY: 00176 break; 00177 case U8G_DEV_MSG_SET_XY_CB: 00178 break; 00179 case U8G_DEV_MSG_GET_MODE: 00180 return U8G_MODE_HICOLOR; 00181 } 00182 return 1; 00183 } 00184 00185
Generated on Tue Jul 12 2022 17:30:58 by
1.7.2