iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_dev_tls8204_84x48.c Source File

u8g_dev_tls8204_84x48.c

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