iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_dev_pcd8544_84x48.c Source File

u8g_dev_pcd8544_84x48.c

00001 /*
00002 
00003   u8g_dev_pcd8544_84x48.c
00004   
00005   Display: Nokia 84x48
00006   
00007   Status: Tested with PCF8812 Display
00008   
00009 
00010   Universal 8bit Graphics Library
00011   
00012   Copyright (c) 2011, olikraus@gmail.com
00013   All rights reserved.
00014 
00015   Redistribution and use in source and binary forms, with or without modification, 
00016   are permitted provided that the following conditions are met:
00017 
00018   * Redistributions of source code must retain the above copyright notice, this list 
00019     of conditions and the following disclaimer.
00020     
00021   * Redistributions in binary form must reproduce the above copyright notice, this 
00022     list of conditions and the following disclaimer in the documentation and/or other 
00023     materials provided with the distribution.
00024 
00025   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00026   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00027   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00028   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00029   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00030   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00031   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00032   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00033   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00034   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00035   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00036   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00037   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00038   
00039   
00040 */
00041 
00042 #include "u8g.h"
00043 
00044 #define WIDTH 84
00045 #define HEIGHT 48
00046 #define PAGE_HEIGHT 8
00047 
00048 
00049 static const uint8_t u8g_dev_pcd8544_init_seq[] PROGMEM = {
00050   U8G_ESC_CS(0),             /* disable chip */
00051   U8G_ESC_ADR(0),           /* instruction mode */
00052   U8G_ESC_RST(1),           /* do reset low pulse with (1*16)+2 milliseconds */
00053   U8G_ESC_CS(1),             /* enable chip */
00054   0x021,        /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
00055   0x006,        /* temp. control: b10 = 2 */
00056   0x013,        /* bias system 1:48 */
00057   0x0c0,        /* medium Vop */
00058   0x020,        /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
00059   0x00c,        /* display on, normal operation */
00060   U8G_ESC_DLY(100),       /* delay 100 ms */
00061   0x020,                        /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
00062   0x00d,                        /* display on, invert */
00063   U8G_ESC_DLY(100),       /* delay 100 ms */
00064   U8G_ESC_DLY(100),       /* delay 100 ms */
00065   0x020,                        /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
00066   0x00c,                        /* display on, normal */
00067   U8G_ESC_DLY(100),       /* delay 100 ms */
00068   U8G_ESC_CS(0),             /* disable chip */
00069   U8G_ESC_END                /* end of sequence */
00070 };
00071 
00072 uint8_t u8g_dev_pcd8544_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00073 {
00074   switch(msg)
00075   {
00076     case U8G_DEV_MSG_INIT:
00077       u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
00078       u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_init_seq);
00079       break;
00080     case U8G_DEV_MSG_STOP:
00081       break;
00082     case U8G_DEV_MSG_PAGE_NEXT:
00083       {
00084         u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
00085         u8g_SetAddress(u8g, dev, 0);           /* command mode */
00086         u8g_SetChipSelect(u8g, dev, 1);
00087         u8g_WriteByte(u8g, dev, 0x020 );        /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
00088         u8g_WriteByte(u8g, dev, 0x080 );                        /* set X address */
00089         u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */
00090         u8g_SetAddress(u8g, dev, 1);           /* data mode */
00091         if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
00092           return 0;
00093         u8g_SetChipSelect(u8g, dev, 0);
00094       }
00095       break;
00096     case U8G_DEV_MSG_CONTRAST:
00097       /* the contrast adjustment does not work, needs to be analysed */
00098       u8g_SetAddress(u8g, dev, 0);          /* instruction mode */
00099       u8g_SetChipSelect(u8g, dev, 1);
00100       u8g_WriteByte(u8g, dev, 0x021);        /* command mode, extended function set */
00101       u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) );
00102       u8g_SetChipSelect(u8g, dev, 0);
00103       return 1;
00104   }
00105   return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
00106 }
00107 
00108 
00109 U8G_PB_DEV(u8g_dev_pcd8544_84x48_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_SW_SPI);
00110 U8G_PB_DEV(u8g_dev_pcd8544_84x48_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_HW_SPI);
00111 
00112