iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_pb8v1.c Source File

u8g_pb8v1.c

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