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_atmega_parallel.c
00001 /* 00002 00003 u8g_com_atmega_parallel.c 00004 00005 Universal 8bit Graphics Library 00006 00007 Copyright (c) 2012, 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 PIN_D0 8 00036 PIN_D1 9 00037 PIN_D2 10 00038 PIN_D3 11 00039 PIN_D4 4 00040 PIN_D5 5 00041 PIN_D6 6 00042 PIN_D7 7 00043 00044 PIN_CS1 14 00045 PIN_CS2 15 00046 PIN_RW 16 00047 PIN_DI 17 00048 PIN_EN 18 00049 00050 u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 00051 u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 00052 00053 */ 00054 00055 #include "u8g.h" 00056 00057 #if defined(__AVR__) 00058 00059 static void u8g_com_atmega_parallel_write(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 00060 static void u8g_com_atmega_parallel_write(u8g_t *u8g, uint8_t val) 00061 { 00062 00063 u8g_SetPILevel(u8g, U8G_PI_D0, val&1); 00064 val >>= 1; 00065 u8g_SetPILevel(u8g, U8G_PI_D1, val&1); 00066 val >>= 1; 00067 u8g_SetPILevel(u8g, U8G_PI_D2, val&1); 00068 val >>= 1; 00069 u8g_SetPILevel(u8g, U8G_PI_D3, val&1); 00070 val >>= 1; 00071 u8g_SetPILevel(u8g, U8G_PI_D4, val&1); 00072 val >>= 1; 00073 u8g_SetPILevel(u8g, U8G_PI_D5, val&1); 00074 val >>= 1; 00075 u8g_SetPILevel(u8g, U8G_PI_D6, val&1); 00076 val >>= 1; 00077 u8g_SetPILevel(u8g, U8G_PI_D7, val&1); 00078 00079 /* EN cycle time must be 1 micro second */ 00080 u8g_SetPILevel(u8g, U8G_PI_EN, 1); 00081 u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */ 00082 u8g_SetPILevel(u8g, U8G_PI_EN, 0); 00083 u8g_10MicroDelay(); /* ST7920 commands: 72us */ 00084 u8g_10MicroDelay(); /* ST7920 commands: 72us */ 00085 } 00086 00087 00088 uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00089 { 00090 switch(msg) 00091 { 00092 case U8G_COM_MSG_INIT: 00093 /* setup the RW pin as output and force it to low */ 00094 u8g_SetPIOutput(u8g, U8G_PI_RW); 00095 u8g_SetPILevel(u8g, U8G_PI_RW, 0); 00096 00097 u8g_SetPIOutput(u8g, U8G_PI_D0); 00098 u8g_SetPIOutput(u8g, U8G_PI_D1); 00099 u8g_SetPIOutput(u8g, U8G_PI_D2); 00100 u8g_SetPIOutput(u8g, U8G_PI_D3); 00101 u8g_SetPIOutput(u8g, U8G_PI_D4); 00102 u8g_SetPIOutput(u8g, U8G_PI_D5); 00103 u8g_SetPIOutput(u8g, U8G_PI_D6); 00104 u8g_SetPIOutput(u8g, U8G_PI_D7); 00105 u8g_SetPIOutput(u8g, U8G_PI_EN); 00106 u8g_SetPIOutput(u8g, U8G_PI_CS1); 00107 u8g_SetPIOutput(u8g, U8G_PI_CS2); 00108 u8g_SetPIOutput(u8g, U8G_PI_DI); 00109 u8g_SetPILevel(u8g, U8G_PI_CS1, 1); 00110 u8g_SetPILevel(u8g, U8G_PI_CS2, 1); 00111 00112 break; 00113 case U8G_COM_MSG_STOP: 00114 break; 00115 case U8G_COM_MSG_CHIP_SELECT: 00116 if ( arg_val == 0 ) 00117 { 00118 /* disable */ 00119 u8g_SetPILevel(u8g, U8G_PI_CS1, 1); 00120 u8g_SetPILevel(u8g, U8G_PI_CS2, 1); 00121 } 00122 else if ( arg_val == 1 ) 00123 { 00124 /* enable */ 00125 u8g_SetPILevel(u8g, U8G_PI_CS1, 0); 00126 u8g_SetPILevel(u8g, U8G_PI_CS2, 1); 00127 } 00128 else if ( arg_val == 2 ) 00129 { 00130 /* enable */ 00131 u8g_SetPILevel(u8g, U8G_PI_CS1, 1); 00132 u8g_SetPILevel(u8g, U8G_PI_CS2, 0); 00133 } 00134 else 00135 { 00136 /* enable */ 00137 u8g_SetPILevel(u8g, U8G_PI_CS1, 0); 00138 u8g_SetPILevel(u8g, U8G_PI_CS2, 0); 00139 } 00140 break; 00141 case U8G_COM_MSG_WRITE_BYTE: 00142 u8g_com_atmega_parallel_write(u8g, arg_val); 00143 break; 00144 case U8G_COM_MSG_WRITE_SEQ: 00145 { 00146 register uint8_t *ptr = arg_ptr; 00147 while( arg_val > 0 ) 00148 { 00149 u8g_com_atmega_parallel_write(u8g, *ptr++); 00150 arg_val--; 00151 } 00152 } 00153 break; 00154 case U8G_COM_MSG_WRITE_SEQ_P: 00155 { 00156 register uint8_t *ptr = arg_ptr; 00157 while( arg_val > 0 ) 00158 { 00159 u8g_com_atmega_parallel_write(u8g, u8g_pgm_read(ptr)); 00160 ptr++; 00161 arg_val--; 00162 } 00163 } 00164 break; 00165 case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 00166 u8g_SetPILevel(u8g, U8G_PI_DI, arg_val); 00167 break; 00168 case U8G_COM_MSG_RESET: 00169 u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 00170 break; 00171 } 00172 return 1; 00173 } 00174 00175 #else 00176 00177 uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00178 { 00179 return 1; 00180 } 00181 00182 #endif /* ARDUINO */ 00183 00184
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2