Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
u8g_dev_st7920_128x64.c
00001 /* 00002 00003 u8g_dev_st7920_128x64.c 00004 00005 Universal 8bit Graphics Library 00006 00007 Copyright (c) 2011, olikraus@gmail.com 00008 All rights reserved. 00009 00010 Redistribution and use in source and binary forms, with or without modification, 00011 are permitted provided that the following conditions are met: 00012 00013 * Redistributions of source code must retain the above copyright notice, this list 00014 of conditions and the following disclaimer. 00015 00016 * Redistributions in binary form must reproduce the above copyright notice, this 00017 list of conditions and the following disclaimer in the documentation and/or other 00018 materials provided with the distribution. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00021 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00022 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00025 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00027 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00030 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00031 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00032 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 00035 */ 00036 00037 #include "u8g.h" 00038 00039 #define WIDTH 128 00040 #define HEIGHT 64 00041 #define PAGE_HEIGHT 8 00042 00043 00044 /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */ 00045 static const uint8_t u8g_dev_st7920_128x64_init_seq[] PROGMEM = { 00046 U8G_ESC_CS(0), /* disable chip */ 00047 U8G_ESC_ADR(0), /* instruction mode */ 00048 U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/ 00049 U8G_ESC_DLY(100), /* 8 Dez 2012: additional delay 100 ms because of reset*/ 00050 U8G_ESC_CS(1), /* enable chip */ 00051 U8G_ESC_DLY(50), /* delay 50 ms */ 00052 00053 0x038, /* 8 Bit interface (DL=1), basic instruction set (RE=0) */ 00054 0x00c, /* display on, cursor & blink off; 0x08: all off */ 00055 0x006, /* Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift */ 00056 0x002, /* disable scroll, enable CGRAM adress */ 00057 0x001, /* clear RAM, needs 1.6 ms */ 00058 U8G_ESC_DLY(100), /* delay 100 ms */ 00059 00060 U8G_ESC_CS(0), /* disable chip */ 00061 U8G_ESC_END /* end of sequence */ 00062 }; 00063 00064 uint8_t u8g_dev_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00065 { 00066 switch(msg) 00067 { 00068 case U8G_DEV_MSG_INIT: 00069 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 00070 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_init_seq); 00071 break; 00072 case U8G_DEV_MSG_STOP: 00073 break; 00074 case U8G_DEV_MSG_PAGE_NEXT: 00075 { 00076 uint8_t y, i; 00077 uint8_t *ptr; 00078 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00079 00080 u8g_SetAddress(u8g, dev, 0); /* cmd mode */ 00081 u8g_SetChipSelect(u8g, dev, 1); 00082 y = pb->p.page_y0; 00083 ptr = pb->buf; 00084 for( i = 0; i < 8; i ++ ) 00085 { 00086 u8g_SetAddress(u8g, dev, 0); /* cmd mode */ 00087 u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */ 00088 00089 if ( y < 32 ) 00090 { 00091 u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */ 00092 u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/ 00093 } 00094 else 00095 { 00096 u8g_WriteByte(u8g, dev, 0x080 | (y-32) ); /* y pos */ 00097 u8g_WriteByte(u8g, dev, 0x080 | 8); /* set x pos to 64*/ 00098 } 00099 00100 u8g_SetAddress(u8g, dev, 1); /* data mode */ 00101 u8g_WriteSequence(u8g, dev, WIDTH/8, ptr); 00102 ptr += WIDTH/8; 00103 y++; 00104 } 00105 u8g_SetChipSelect(u8g, dev, 0); 00106 } 00107 break; 00108 } 00109 return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg); 00110 } 00111 00112 uint8_t u8g_dev_st7920_128x64_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00113 { 00114 switch(msg) 00115 { 00116 case U8G_DEV_MSG_INIT: 00117 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 00118 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_init_seq); 00119 break; 00120 case U8G_DEV_MSG_STOP: 00121 break; 00122 case U8G_DEV_MSG_PAGE_NEXT: 00123 { 00124 uint8_t y, i; 00125 uint8_t *ptr; 00126 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00127 00128 u8g_SetAddress(u8g, dev, 0); /* cmd mode */ 00129 u8g_SetChipSelect(u8g, dev, 1); 00130 y = pb->p.page_y0; 00131 ptr = pb->buf; 00132 for( i = 0; i < 32; i ++ ) 00133 { 00134 u8g_SetAddress(u8g, dev, 0); /* cmd mode */ 00135 u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */ 00136 00137 if ( y < 32 ) 00138 { 00139 u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */ 00140 u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/ 00141 } 00142 else 00143 { 00144 u8g_WriteByte(u8g, dev, 0x080 | (y-32) ); /* y pos */ 00145 u8g_WriteByte(u8g, dev, 0x080 | 8); /* set x pos to 64*/ 00146 } 00147 00148 u8g_SetAddress(u8g, dev, 1); /* data mode */ 00149 u8g_WriteSequence(u8g, dev, WIDTH/8, ptr); 00150 ptr += WIDTH/8; 00151 y++; 00152 } 00153 u8g_SetChipSelect(u8g, dev, 0); 00154 } 00155 break; 00156 } 00157 return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg); 00158 } 00159 00160 U8G_PB_DEV(u8g_dev_st7920_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_ST7920_SW_SPI); 00161 U8G_PB_DEV(u8g_dev_st7920_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_ST7920_HW_SPI); 00162 U8G_PB_DEV(u8g_dev_st7920_128x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_FAST_PARALLEL); 00163 U8G_PB_DEV(u8g_dev_st7920_128x64_custom, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, u8g_com_arduino_st7920_custom_fn); 00164 00165 00166 00167 #define QWIDTH (WIDTH*4) 00168 uint8_t u8g_dev_st7920_128x64_4x_buf[QWIDTH] U8G_NOCOMMON ; 00169 u8g_pb_t u8g_dev_st7920_128x64_4x_pb = { {32, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7920_128x64_4x_buf}; 00170 u8g_dev_t u8g_dev_st7920_128x64_4x_sw_spi = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_ST7920_SW_SPI }; 00171 u8g_dev_t u8g_dev_st7920_128x64_4x_hw_spi = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_ST7920_HW_SPI }; 00172 u8g_dev_t u8g_dev_st7920_128x64_4x_8bit = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_FAST_PARALLEL }; 00173 u8g_dev_t u8g_dev_st7920_128x64_4x_custom = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, u8g_com_arduino_st7920_custom_fn }; 00174 00175 00176
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2