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_com_api.c
00001 /* 00002 00003 u8g_com_api.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 uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time) 00040 { 00041 return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL); 00042 } 00043 00044 void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev) 00045 { 00046 dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL); 00047 } 00048 00049 /* cs contains the chip number, which should be enabled */ 00050 void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs) 00051 { 00052 dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL); 00053 } 00054 00055 void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev) 00056 { 00057 dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL); 00058 } 00059 00060 void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev) 00061 { 00062 dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL); 00063 } 00064 00065 00066 void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address) 00067 { 00068 dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL); 00069 } 00070 00071 uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val) 00072 { 00073 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL); 00074 } 00075 00076 uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq) 00077 { 00078 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq); 00079 } 00080 00081 uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq) 00082 { 00083 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq); 00084 } 00085 00086 /* 00087 sequence := { direct_value | escape_sequence } 00088 direct_value := 0..254 00089 escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used 00090 value_255 := 255 255 00091 sequence_end = 255 254 00092 delay := 255 0..127 00093 adr := 255 0x0e0 .. 0x0ef 00094 cs := 255 0x0d0 .. 0x0df 00095 not_used := 255 101..254 00096 00097 #define U8G_ESC_DLY(x) 255, ((x) & 0x7f) 00098 #define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f)) 00099 #define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f)) 00100 #define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01)) 00101 #define U8G_ESC_END 255, 254 00102 #define U8G_ESC_255 255, 255 00103 #define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f)) 00104 00105 */ 00106 uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq) 00107 { 00108 uint8_t is_escape = 0; 00109 uint8_t value; 00110 for(;;) 00111 { 00112 value = u8g_pgm_read(esc_seq); 00113 if ( is_escape == 0 ) 00114 { 00115 if ( value != 255 ) 00116 { 00117 if ( u8g_WriteByte(u8g, dev, value) == 0 ) 00118 return 0; 00119 } 00120 else 00121 { 00122 is_escape = 1; 00123 } 00124 } 00125 else 00126 { 00127 if ( value == 255 ) 00128 { 00129 if ( u8g_WriteByte(u8g, dev, value) == 0 ) 00130 return 0; 00131 } 00132 else if ( value == 254 ) 00133 { 00134 break; 00135 } 00136 else if ( value >= 0x0f0 ) 00137 { 00138 /* not yet used, do nothing */ 00139 } 00140 else if ( value >= 0xe0 ) 00141 { 00142 u8g_SetAddress(u8g, dev, value & 0x0f); 00143 } 00144 else if ( value >= 0xd0 ) 00145 { 00146 u8g_SetChipSelect(u8g, dev, value & 0x0f); 00147 } 00148 else if ( value >= 0xc0 ) 00149 { 00150 u8g_SetResetLow(u8g, dev); 00151 value &= 0x0f; 00152 value <<= 4; 00153 value+=2; 00154 u8g_Delay(value); 00155 u8g_SetResetHigh(u8g, dev); 00156 u8g_Delay(value); 00157 } 00158 else if ( value >= 0xbe ) 00159 { 00160 /* not yet implemented */ 00161 /* u8g_SetVCC(u8g, dev, value & 0x01); */ 00162 } 00163 else if ( value <= 127 ) 00164 { 00165 u8g_Delay(value); 00166 } 00167 is_escape = 0; 00168 } 00169 esc_seq++; 00170 } 00171 return 1; 00172 } 00173 00174
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2