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_st7565_lm6063.c
00001 /* 00002 00003 u8g_dev_st7565_lm6063.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 #ifdef OLD_ADAFRUIT_CODE 00044 static const uint8_t OLD_u8g_dev_st7565_lm6063_init_seq[] PROGMEM = { 00045 U8G_ESC_CS(0), /* disable chip */ 00046 U8G_ESC_ADR(0), /* instruction mode */ 00047 U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 00048 U8G_ESC_CS(1), /* enable chip */ 00049 00050 0x040, /* set display start line */ 00051 0x0a1, /* ADC set to reverse */ 00052 0x0c8, /* common output mode: set scan direction normal operation/SHL Select / 17 Jan: seems to be a bug, must be 0x0c0 */ 00053 0x0a6, /* display normal, bit val 0: LCD pixel off. */ 00054 0x0a2, /* LCD bias 1/9 */ 00055 0x02f, /* all power control circuits on */ 00056 /*0x0f8,*/ /* set booster ratio to */ 00057 /*0x000, */ /* 4x */ 00058 /*0x027,*/ /* set V0 voltage resistor ratio to large */ 00059 0x081, /* set contrast */ 00060 0x018, /* contrast value*/ 00061 0x0ac, /* indicator */ 00062 0x000, /* disable */ 00063 0x0af, /* display on */ 00064 00065 U8G_ESC_DLY(100), /* delay 100 ms */ 00066 0x0a5, /* display all points, ST7565 */ 00067 U8G_ESC_DLY(100), /* delay 100 ms */ 00068 U8G_ESC_DLY(100), /* delay 100 ms */ 00069 0x0a4, /* normal display */ 00070 U8G_ESC_CS(0), /* disable chip */ 00071 U8G_ESC_END /* end of sequence */ 00072 }; 00073 #endif 00074 00075 /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */ 00076 static const uint8_t u8g_dev_st7565_lm6063_init_seq[] PROGMEM = { 00077 U8G_ESC_CS(0), /* disable chip */ 00078 U8G_ESC_ADR(0), /* instruction mode */ 00079 U8G_ESC_CS(1), /* enable chip */ 00080 U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/ 00081 00082 0x0a3, /* 0x0a2: LCD bias 1/9 (suggested for the LM6063), 0x0a3: Used by Adafruit */ 00083 0x0a1, /* 0x0a1: ADC set to reverse (suggested for the LM6063), 0x0a0: Used by Adafruit -> normal mode */ 00084 0x0c0, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */ 00085 0x040, /* set display start line */ 00086 00087 0x028 | 0x04, /* power control: turn on voltage converter */ 00088 U8G_ESC_DLY(50), /* delay 50 ms */ 00089 00090 0x028 | 0x06, /* power control: turn on voltage regulator */ 00091 U8G_ESC_DLY(50), /* delay 50 ms */ 00092 00093 0x028 | 0x07, /* power control: turn on voltage follower */ 00094 U8G_ESC_DLY(50), /* delay 50 ms */ 00095 00096 0x026, /* set V0 voltage resistor ratio to 6 (Adafruit Value, no info from LM6063 Manual) */ 00097 00098 0x0a6, /* display normal, bit val 0: LCD pixel off. */ 00099 00100 0x081, /* set contrast */ 00101 0x018, /* contrast value*/ 00102 00103 /*0x0ac,*/ /* indicator */ 00104 /*0x000,*/ /* disable */ 00105 00106 0x0af, /* display on */ 00107 00108 U8G_ESC_DLY(100), /* delay 100 ms */ 00109 0x0a5, /* display all points, ST7565 */ 00110 U8G_ESC_DLY(100), /* delay 100 ms */ 00111 U8G_ESC_DLY(100), /* delay 100 ms */ 00112 0x0a4, /* normal display */ 00113 U8G_ESC_CS(0), /* disable chip */ 00114 U8G_ESC_END /* end of sequence */ 00115 }; 00116 00117 static const uint8_t u8g_dev_st7565_lm6063_data_start[] PROGMEM = { 00118 U8G_ESC_ADR(0), /* instruction mode */ 00119 U8G_ESC_CS(1), /* enable chip */ 00120 0x010, /* set upper 4 bit of the col adr to 0 */ 00121 0x000, /* set lower 4 bit of the col adr to 0 */ 00122 U8G_ESC_END /* end of sequence */ 00123 }; 00124 00125 static const uint8_t u8g_dev_st7565_st7565_sleep_on[] PROGMEM = { 00126 U8G_ESC_ADR(0), /* instruction mode */ 00127 U8G_ESC_CS(1), /* enable chip */ 00128 0x0ac, /* static indicator off */ 00129 0x000, /* indicator register set (not sure if this is required) */ 00130 0x0ae, /* display off */ 00131 0x0a5, /* all points on */ 00132 U8G_ESC_CS(1), /* disable chip */ 00133 U8G_ESC_END /* end of sequence */ 00134 }; 00135 00136 static const uint8_t u8g_dev_st7565_st7565_sleep_off[] PROGMEM = { 00137 U8G_ESC_ADR(0), /* instruction mode */ 00138 U8G_ESC_CS(1), /* enable chip */ 00139 0x0a4, /* all points off */ 00140 0x0af, /* display on */ 00141 U8G_ESC_DLY(50), /* delay 50 ms */ 00142 U8G_ESC_CS(1), /* disable chip */ 00143 U8G_ESC_END /* end of sequence */ 00144 }; 00145 00146 00147 uint8_t u8g_dev_st7565_lm6063_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00148 { 00149 switch(msg) 00150 { 00151 case U8G_DEV_MSG_INIT: 00152 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 00153 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_init_seq); 00154 break; 00155 case U8G_DEV_MSG_STOP: 00156 break; 00157 case U8G_DEV_MSG_PAGE_NEXT: 00158 { 00159 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00160 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start); 00161 u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */ 00162 u8g_SetAddress(u8g, dev, 1); /* data mode */ 00163 if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 00164 return 0; 00165 u8g_SetChipSelect(u8g, dev, 0); 00166 } 00167 break; 00168 case U8G_DEV_MSG_CONTRAST: 00169 u8g_SetChipSelect(u8g, dev, 1); 00170 u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 00171 u8g_WriteByte(u8g, dev, 0x081); 00172 u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); 00173 u8g_SetChipSelect(u8g, dev, 0); 00174 return 1; 00175 case U8G_DEV_MSG_SLEEP_ON: 00176 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_on); 00177 return 1; 00178 case U8G_DEV_MSG_SLEEP_OFF: 00179 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_off); 00180 return 1; 00181 } 00182 return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 00183 } 00184 00185 uint8_t u8g_dev_st7565_lm6063_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 00186 { 00187 switch(msg) 00188 { 00189 case U8G_DEV_MSG_INIT: 00190 u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 00191 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_init_seq); 00192 break; 00193 case U8G_DEV_MSG_STOP: 00194 break; 00195 case U8G_DEV_MSG_PAGE_NEXT: 00196 { 00197 u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 00198 00199 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start); 00200 u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */ 00201 u8g_SetAddress(u8g, dev, 1); /* data mode */ 00202 u8g_WriteSequence(u8g, dev, pb->width, pb->buf); 00203 u8g_SetChipSelect(u8g, dev, 0); 00204 00205 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start); 00206 u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */ 00207 u8g_SetAddress(u8g, dev, 1); /* data mode */ 00208 u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width); 00209 u8g_SetChipSelect(u8g, dev, 0); 00210 } 00211 break; 00212 case U8G_DEV_MSG_CONTRAST: 00213 u8g_SetChipSelect(u8g, dev, 1); 00214 u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 00215 u8g_WriteByte(u8g, dev, 0x081); 00216 u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); 00217 u8g_SetChipSelect(u8g, dev, 0); 00218 return 1; 00219 case U8G_DEV_MSG_SLEEP_ON: 00220 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_on); 00221 return 1; 00222 case U8G_DEV_MSG_SLEEP_OFF: 00223 u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_off); 00224 return 1; 00225 } 00226 return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg); 00227 } 00228 00229 U8G_PB_DEV(u8g_dev_st7565_lm6063_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6063_fn, U8G_COM_SW_SPI); 00230 U8G_PB_DEV(u8g_dev_st7565_lm6063_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6063_fn, U8G_COM_HW_SPI); 00231 00232 uint8_t u8g_dev_st7565_lm6063_2x_buf[WIDTH*2] U8G_NOCOMMON ; 00233 u8g_pb_t u8g_dev_st7565_lm6063_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_lm6063_2x_buf}; 00234 u8g_dev_t u8g_dev_st7565_lm6063_2x_sw_spi = { u8g_dev_st7565_lm6063_2x_fn, &u8g_dev_st7565_lm6063_2x_pb, U8G_COM_SW_SPI }; 00235 u8g_dev_t u8g_dev_st7565_lm6063_2x_hw_spi = { u8g_dev_st7565_lm6063_2x_fn, &u8g_dev_st7565_lm6063_2x_pb, U8G_COM_HW_SPI }; 00236 00237
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2