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_pb16h1.c
00001 /* 00002 00003 u8g_pb16h1.c 00004 00005 2x 8bit height monochrom (1 bit) page buffer 00006 byte has horizontal orientation 00007 00008 Universal 8bit Graphics Library 00009 00010 Copyright (c) 2012, olikraus@gmail.com 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without modification, 00014 are permitted provided that the following conditions are met: 00015 00016 * Redistributions of source code must retain the above copyright notice, this list 00017 of conditions and the following disclaimer. 00018 00019 * Redistributions in binary form must reproduce the above copyright notice, this 00020 list of conditions and the following disclaimer in the documentation and/or other 00021 materials provided with the distribution. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00024 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00025 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00026 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00028 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00029 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00030 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00033 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00034 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00035 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 00037 00038 total buffer size is limited to 2*256 bytes because of the calculation inside the set pixel procedure 00039 00040 00041 */ 00042 00043 #include "u8g.h" 00044 #include <string.h> 00045 00046 00047 void u8g_pb16h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; 00048 void u8g_pb16h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 00049 void u8g_pb16h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ; 00050 void u8g_pb16h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE; 00051 uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 00052 00053 void u8g_pb16h1_Clear(u8g_pb_t *b) 00054 { 00055 uint8_t *ptr = (uint8_t *)b->buf; 00056 uint8_t *end_ptr = ptr; 00057 end_ptr += b->width*2; 00058 do 00059 { 00060 *ptr++ = 0; 00061 } while( ptr != end_ptr ); 00062 } 00063 00064 00065 00066 void u8g_pb16h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 00067 { 00068 b->buf = buf; 00069 b->width = width; 00070 u8g_pb16h1_Clear(b); 00071 } 00072 00073 00074 /* limitation: total buffer must not exceed 2*256 bytes */ 00075 void u8g_pb16h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 00076 { 00077 register uint8_t mask; 00078 u8g_uint_t tmp; 00079 uint8_t *ptr = b->buf; 00080 00081 y -= b->p.page_y0; 00082 if ( y >= 8 ) 00083 { 00084 ptr += b->width; 00085 y &= 0x07; 00086 } 00087 tmp = b->width; 00088 tmp >>= 3; 00089 tmp *= (uint8_t)y; 00090 ptr += tmp; 00091 00092 mask = 0x080; 00093 mask >>= x & 7; 00094 x >>= 3; 00095 ptr += x; 00096 if ( color_index ) 00097 { 00098 *ptr |= mask; 00099 } 00100 else 00101 { 00102 mask ^=0xff; 00103 *ptr &= mask; 00104 } 00105 00106 } 00107 00108 00109 void u8g_pb16h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 00110 { 00111 if ( arg_pixel->y < b->p.page_y0 ) 00112 return; 00113 if ( arg_pixel->y > b->p.page_y1 ) 00114 return; 00115 if ( arg_pixel->x >= b->width ) 00116 return; 00117 u8g_pb16h1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 00118 } 00119 00120 void u8g_pb16h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00121 { 00122 register uint8_t pixel = arg_pixel->pixel; 00123 do 00124 { 00125 if ( pixel & 128 ) 00126 { 00127 u8g_pb16h1_SetPixel(b, arg_pixel); 00128 } 00129 switch( arg_pixel->dir ) 00130 { 00131 case 0: arg_pixel->x++; break; 00132 case 1: arg_pixel->y++; break; 00133 case 2: arg_pixel->x--; break; 00134 case 3: arg_pixel->y--; break; 00135 } 00136 pixel <<= 1; 00137 } while( pixel != 0 ); 00138 } 00139 00140 void u8g_pb16h1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 00141 { 00142 register uint8_t pixel = arg_pixel->pixel; 00143 u8g_uint_t dx = 0; 00144 u8g_uint_t dy = 0; 00145 00146 switch( arg_pixel->dir ) 00147 { 00148 case 0: dx++; break; 00149 case 1: dy++; break; 00150 case 2: dx--; break; 00151 case 3: dy--; break; 00152 } 00153 00154 do 00155 { 00156 if ( pixel & 128 ) 00157 u8g_pb16h1_SetPixel(b, arg_pixel); 00158 arg_pixel->x += dx; 00159 arg_pixel->y += dy; 00160 pixel <<= 1; 00161 } while( pixel != 0 ); 00162 } 00163 00164 00165 uint8_t u8g_dev_pb16h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00166 { 00167 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00168 switch(msg) 00169 { 00170 case U8G_DEV_MSG_SET_8PIXEL: 00171 if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 00172 u8g_pb16h1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 00173 break; 00174 case U8G_DEV_MSG_SET_PIXEL: 00175 u8g_pb16h1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 00176 break; 00177 case U8G_DEV_MSG_INIT: 00178 break; 00179 case U8G_DEV_MSG_STOP: 00180 break; 00181 case U8G_DEV_MSG_PAGE_FIRST: 00182 u8g_pb16h1_Clear(pb); 00183 u8g_page_First(&(pb->p)); 00184 break; 00185 case U8G_DEV_MSG_PAGE_NEXT: 00186 if ( u8g_page_Next(&(pb->p)) == 0 ) 00187 return 0; 00188 u8g_pb16h1_Clear(pb); 00189 break; 00190 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 00191 case U8G_DEV_MSG_IS_BBX_INTERSECTION: 00192 return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 00193 #endif 00194 case U8G_DEV_MSG_GET_PAGE_BOX: 00195 u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 00196 break; 00197 case U8G_DEV_MSG_GET_WIDTH: 00198 *((u8g_uint_t *)arg) = pb->width; 00199 break; 00200 case U8G_DEV_MSG_GET_HEIGHT: 00201 *((u8g_uint_t *)arg) = pb->p.total_height; 00202 break; 00203 case U8G_DEV_MSG_SET_COLOR_ENTRY: 00204 break; 00205 case U8G_DEV_MSG_SET_XY_CB: 00206 break; 00207 case U8G_DEV_MSG_GET_MODE: 00208 return U8G_MODE_BW; 00209 } 00210 return 1; 00211 } 00212 00213 00214
Generated on Tue Jul 12 2022 17:30:58 by
1.7.2