iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_com_api_16gr.c Source File

u8g_com_api_16gr.c

00001 /*
00002 
00003   u8g_com_api_16gr.c
00004   
00005   Extension of the com api for devices with 16 graylevels (4 bit per pixel).
00006   This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2), 
00007   mainly intended for SSD OLEDs
00008 
00009   Universal 8bit Graphics Library
00010   
00011   Copyright (c) 2011, olikraus@gmail.com
00012   All rights reserved.
00013 
00014   Redistribution and use in source and binary forms, with or without modification, 
00015   are permitted provided that the following conditions are met:
00016 
00017   * Redistributions of source code must retain the above copyright notice, this list 
00018     of conditions and the following disclaimer.
00019     
00020   * Redistributions in binary form must reproduce the above copyright notice, this 
00021     list of conditions and the following disclaimer in the documentation and/or other 
00022     materials provided with the distribution.
00023 
00024   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00025   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00026   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00027   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00028   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00029   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00030   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00031   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00032   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00033   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00034   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00035   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00036   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00037   
00038   
00039 */
00040 
00041 #include "u8g.h"
00042 
00043 /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */
00044 /* topbit (msb) is sent last */
00045 /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */
00046 uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
00047 {
00048   static uint8_t buf[4];
00049   static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff };
00050   buf [3] = map[b & 3];
00051   b>>=2;
00052   buf [2] = map[b & 3];
00053   b>>=2;
00054   buf [1] = map[b & 3];
00055   b>>=2;
00056   buf [0] = map[b & 3];
00057   return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf);
00058 }
00059 
00060 uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
00061 {
00062   do
00063   {
00064     if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 )
00065       return 0;
00066     cnt--;
00067   } while( cnt != 0 );
00068   return 1;
00069 }
00070 
00071 /* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */
00072 uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
00073 {
00074   //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc};
00075   //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff};
00076   static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff};
00077   uint8_t bb;
00078   bb = b;
00079   bb &= 15;
00080   b>>=4;
00081   dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL);
00082   return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL);
00083 }
00084 
00085 uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
00086 {
00087   do
00088   {
00089     if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 )
00090       return 0;
00091     cnt--;
00092   } while( cnt != 0 );
00093   return 1;
00094 }
00095