iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_pb16v1.c Source File

u8g_pb16v1.c

00001 /*
00002 
00003   u8g_pb16v1.c
00004   
00005   16bit height monochrom (1 bit) page buffer
00006   byte has vertical orientation
00007 
00008   Universal 8bit Graphics Library
00009   
00010   Copyright (c) 2011, 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 */
00039 
00040 #include "u8g.h"
00041 #include <string.h>
00042 
00043 
00044 void u8g_pb16v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
00045 void u8g_pb16v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
00046 void u8g_pb16v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
00047 void u8g_pb16v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
00048 
00049 
00050 void u8g_pb16v1_Clear(u8g_pb_t *b)
00051 {
00052   uint8_t *ptr = (uint8_t *)b->buf;
00053   uint8_t *end_ptr = ptr;
00054   end_ptr += b->width*2;
00055   do
00056   {
00057     *ptr++ = 0;
00058   } while( ptr != end_ptr );
00059 }
00060 
00061 /* Obsolete, usually set by the init of the structure */
00062 void u8g_pb16v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
00063 {
00064   b->buf = buf;
00065   b->width = width;
00066   u8g_pb16v1_Clear(b);
00067 }
00068 
00069 void u8g_pb16v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
00070 {
00071   register uint8_t mask;
00072   uint8_t *ptr = b->buf;
00073   
00074   y -= b->p.page_y0;
00075   if ( y >= 8 )
00076   {
00077     ptr += b->width;
00078     y &= 0x07;
00079   }
00080   mask = 1;
00081   mask <<= y;
00082   ptr += x;
00083   if ( color_index )
00084   {
00085     *ptr |= mask;
00086   }
00087   else
00088   {
00089     mask ^=0xff;
00090     *ptr &= mask;
00091   }
00092 }
00093 
00094 
00095 void u8g_pb16v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
00096 {
00097   if ( arg_pixel->y < b->p.page_y0 )
00098     return;
00099   if ( arg_pixel->y > b->p.page_y1 )
00100     return;
00101   if ( arg_pixel->x >= b->width )
00102     return;
00103   u8g_pb16v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
00104 }
00105 
00106 void u8g_pb16v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
00107 {
00108   register uint8_t pixel = arg_pixel->pixel;
00109   do
00110   {
00111     if ( pixel & 128 )
00112     {
00113       u8g_pb16v1_SetPixel(b, arg_pixel);
00114     }
00115     switch( arg_pixel->dir )
00116     {
00117       case 0: arg_pixel->x++; break;
00118       case 1: arg_pixel->y++; break;
00119       case 2: arg_pixel->x--; break;
00120       case 3: arg_pixel->y--; break;
00121     }
00122     pixel <<= 1;
00123   } while( pixel != 0  );
00124 }
00125 
00126 
00127 void u8g_pb16v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
00128 {
00129   register uint8_t pixel = arg_pixel->pixel;
00130   u8g_uint_t dx = 0;
00131   u8g_uint_t dy = 0;
00132   
00133   switch( arg_pixel->dir )
00134   {
00135     case 0: dx++; break;
00136     case 1: dy++; break;
00137     case 2: dx--; break;
00138     case 3: dy--; break;
00139   }
00140   
00141   do
00142   {
00143     if ( pixel & 128 )
00144       u8g_pb16v1_SetPixel(b, arg_pixel);
00145     arg_pixel->x += dx;
00146     arg_pixel->y += dy;
00147     pixel <<= 1;
00148   } while( pixel != 0  );
00149   
00150 }
00151 
00152 uint8_t u8g_dev_pb16v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00153 {
00154   u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
00155   switch(msg)
00156   {
00157     case U8G_DEV_MSG_SET_8PIXEL:
00158       if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
00159         u8g_pb16v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
00160       break;
00161     case U8G_DEV_MSG_SET_PIXEL:
00162         u8g_pb16v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
00163       break;
00164     case U8G_DEV_MSG_INIT:
00165       break;
00166     case U8G_DEV_MSG_STOP:
00167       break;
00168     case U8G_DEV_MSG_PAGE_FIRST:
00169       u8g_pb16v1_Clear(pb);
00170       u8g_page_First(&(pb->p));
00171       break;
00172     case U8G_DEV_MSG_PAGE_NEXT:
00173       if ( u8g_page_Next(&(pb->p)) == 0 )
00174         return 0;
00175       u8g_pb16v1_Clear(pb);
00176       break;
00177 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
00178     case U8G_DEV_MSG_IS_BBX_INTERSECTION:
00179       return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
00180 #endif
00181     case U8G_DEV_MSG_GET_PAGE_BOX:
00182       u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
00183       break;
00184     case U8G_DEV_MSG_GET_WIDTH:
00185       *((u8g_uint_t *)arg) = pb->width;
00186       break;
00187     case U8G_DEV_MSG_GET_HEIGHT:
00188       *((u8g_uint_t *)arg) = pb->p.total_height;
00189       break;
00190     case U8G_DEV_MSG_SET_COLOR_ENTRY:
00191       break;
00192     case U8G_DEV_MSG_SET_XY_CB:
00193       break;
00194     case U8G_DEV_MSG_GET_MODE:
00195       return U8G_MODE_BW;
00196   }
00197   return 1;
00198 }
00199  
00200   
00201