iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_pb8v2.c Source File

u8g_pb8v2.c

00001 /*
00002 
00003   u8g_pb8v2.c
00004   
00005   8bit height 2 bit per pixel 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 void u8g_pb8v2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
00044 {
00045   b->buf = buf;
00046   b->width = width;
00047   u8g_pb_Clear(b);
00048 }
00049 
00050 void u8g_pb8v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
00051 {
00052   register uint8_t mask;
00053   uint8_t *ptr = b->buf;
00054   y -= b->p.page_y0;
00055   mask = 0x03;
00056   y &= 0x03;
00057   y <<= 1;
00058   mask <<= y;
00059   mask ^=0xff;
00060   color_index &= 3;
00061   color_index <<= y;
00062   ptr += x;
00063   *ptr &= mask;
00064   *ptr |= color_index;
00065 }
00066 
00067 
00068 void u8g_pb8v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
00069 {
00070   if ( arg_pixel->y < b->p.page_y0 )
00071     return;
00072   if ( arg_pixel->y > b->p.page_y1 )
00073     return;
00074   if ( arg_pixel->x >= b->width )
00075     return;
00076   u8g_pb8v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
00077 }
00078 
00079 
00080 void u8g_pb8v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
00081 {
00082   register uint8_t pixel = arg_pixel->pixel;
00083   do
00084   {
00085     if ( pixel & 128 )
00086     {
00087       u8g_pb8v2_SetPixel(b, arg_pixel);
00088     }
00089     switch( arg_pixel->dir )
00090     {
00091       case 0: arg_pixel->x++; break;
00092       case 1: arg_pixel->y++; break;
00093       case 2: arg_pixel->x--; break;
00094       case 3: arg_pixel->y--; break;
00095     }
00096     pixel <<= 1;
00097   } while( pixel != 0  );
00098 
00099 }
00100 
00101 
00102 
00103 uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00104 {
00105   u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
00106   switch(msg)
00107   {
00108     case U8G_DEV_MSG_SET_8PIXEL:
00109       if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
00110       {
00111         u8g_pb8v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg);
00112       }
00113       break;
00114     case U8G_DEV_MSG_SET_PIXEL:
00115       u8g_pb8v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
00116       break;
00117     case U8G_DEV_MSG_INIT:
00118       break;
00119     case U8G_DEV_MSG_STOP:
00120       break;
00121     case U8G_DEV_MSG_PAGE_FIRST:
00122       u8g_pb_Clear(pb);
00123       u8g_page_First(&(pb->p));
00124       break;
00125     case U8G_DEV_MSG_PAGE_NEXT:
00126       if ( u8g_page_Next(&(pb->p)) == 0 )
00127         return 0;
00128       u8g_pb_Clear(pb);
00129       break;
00130 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
00131     case U8G_DEV_MSG_IS_BBX_INTERSECTION:
00132       return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
00133 #endif
00134     case U8G_DEV_MSG_GET_PAGE_BOX:
00135       u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
00136       break;
00137     case U8G_DEV_MSG_GET_WIDTH:
00138       *((u8g_uint_t *)arg) = pb->width;
00139       break;
00140     case U8G_DEV_MSG_GET_HEIGHT:
00141       *((u8g_uint_t *)arg) = pb->p.total_height;
00142       break;
00143     case U8G_DEV_MSG_SET_COLOR_ENTRY:
00144       break;
00145     case U8G_DEV_MSG_SET_XY_CB:
00146       break;
00147     case U8G_DEV_MSG_GET_MODE:
00148       return U8G_MODE_GRAY2BIT;
00149   }
00150   return 1;
00151 }
00152  
00153   
00154