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_arduino_parallel.c
00001 /* 00002 00003 u8g_com_arduino_parallel.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 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 00058 #if defined(ARDUINO) 00059 00060 #if ARDUINO < 100 00061 #include <WProgram.h> 00062 #else 00063 #include <Arduino.h> 00064 #endif 00065 00066 00067 00068 00069 00070 00071 void u8g_com_arduino_parallel_write(u8g_t *u8g, uint8_t val) 00072 { 00073 u8g_com_arduino_digital_write(u8g, U8G_PI_D0, val&1); 00074 val >>= 1; 00075 u8g_com_arduino_digital_write(u8g, U8G_PI_D1, val&1); 00076 val >>= 1; 00077 u8g_com_arduino_digital_write(u8g, U8G_PI_D2, val&1); 00078 val >>= 1; 00079 u8g_com_arduino_digital_write(u8g, U8G_PI_D3, val&1); 00080 val >>= 1; 00081 u8g_com_arduino_digital_write(u8g, U8G_PI_D4, val&1); 00082 val >>= 1; 00083 u8g_com_arduino_digital_write(u8g, U8G_PI_D5, val&1); 00084 val >>= 1; 00085 u8g_com_arduino_digital_write(u8g, U8G_PI_D6, val&1); 00086 val >>= 1; 00087 u8g_com_arduino_digital_write(u8g, U8G_PI_D7, val&1); 00088 00089 /* EN cycle time must be 1 micro second, digitalWrite is slow enough to do this */ 00090 u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH); 00091 u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */ 00092 u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW); 00093 u8g_10MicroDelay(); /* ST7920 commands: 72us */ 00094 } 00095 00096 00097 uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00098 { 00099 switch(msg) 00100 { 00101 case U8G_COM_MSG_INIT: 00102 /* setup the RW pin as output and force it to low */ 00103 if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE ) 00104 { 00105 pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT); 00106 u8g_com_arduino_digital_write(u8g, U8G_PI_RW, LOW); 00107 } 00108 /* set all pins (except RW pin) */ 00109 u8g_com_arduino_assign_pin_output_high(u8g); 00110 break; 00111 case U8G_COM_MSG_STOP: 00112 break; 00113 case U8G_COM_MSG_CHIP_SELECT: 00114 if ( arg_val == 0 ) 00115 { 00116 /* disable */ 00117 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 00118 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 00119 } 00120 else if ( arg_val == 1 ) 00121 { 00122 /* enable */ 00123 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 00124 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 00125 } 00126 else if ( arg_val == 2 ) 00127 { 00128 /* enable */ 00129 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 00130 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 00131 } 00132 else 00133 { 00134 /* enable */ 00135 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 00136 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 00137 } 00138 break; 00139 case U8G_COM_MSG_WRITE_BYTE: 00140 u8g_com_arduino_parallel_write(u8g, arg_val); 00141 break; 00142 case U8G_COM_MSG_WRITE_SEQ: 00143 { 00144 register uint8_t *ptr = arg_ptr; 00145 while( arg_val > 0 ) 00146 { 00147 u8g_com_arduino_parallel_write(u8g, *ptr++); 00148 arg_val--; 00149 } 00150 } 00151 break; 00152 case U8G_COM_MSG_WRITE_SEQ_P: 00153 { 00154 register uint8_t *ptr = arg_ptr; 00155 while( arg_val > 0 ) 00156 { 00157 u8g_com_arduino_parallel_write(u8g, u8g_pgm_read(ptr)); 00158 ptr++; 00159 arg_val--; 00160 } 00161 } 00162 break; 00163 case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 00164 u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val); 00165 break; 00166 case U8G_COM_MSG_RESET: 00167 if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 00168 u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 00169 break; 00170 00171 } 00172 return 1; 00173 } 00174 00175 #else 00176 00177 00178 uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00179 { 00180 return 1; 00181 } 00182 00183 #endif /* ARDUINO */ 00184 00185
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2