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_fast_parallel.c
00001 /* 00002 00003 u8g_arduino_fast_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 PIN_D0 8 00035 PIN_D1 9 00036 PIN_D2 10 00037 PIN_D3 11 00038 PIN_D4 4 00039 PIN_D5 5 00040 PIN_D6 6 00041 PIN_D7 7 00042 00043 PIN_CS1 14 00044 PIN_CS2 15 00045 PIN_RW 16 00046 PIN_DI 17 00047 PIN_EN 18 00048 00049 u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 00050 u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 00051 00052 Update for ATOMIC operation done (01 Jun 2013) 00053 U8G_ATOMIC_OR(ptr, val) 00054 U8G_ATOMIC_AND(ptr, val) 00055 U8G_ATOMIC_START(); 00056 U8G_ATOMIC_END(); 00057 00058 */ 00059 00060 #include "u8g.h" 00061 00062 #if defined(ARDUINO) 00063 00064 #if ARDUINO < 100 00065 //#include <WProgram.h> 00066 #include <wiring_private.h> 00067 #include <pins_arduino.h> 00068 #else 00069 #include <Arduino.h> 00070 #endif 00071 00072 00073 #define PIN_D0 8 00074 #define PIN_D1 9 00075 #define PIN_D2 10 00076 #define PIN_D3 11 00077 #define PIN_D4 4 00078 #define PIN_D5 5 00079 #define PIN_D6 6 00080 #define PIN_D7 7 00081 00082 #define PIN_CS1 14 00083 #define PIN_CS2 15 00084 #define PIN_RW 16 00085 #define PIN_DI 17 00086 #define PIN_EN 18 00087 00088 //#define PIN_RESET 00089 00090 00091 #if defined(__PIC32MX) 00092 /* CHIPKIT PIC32 */ 00093 static volatile uint32_t *u8g_data_port[8]; 00094 static uint32_t u8g_data_mask[8]; 00095 #else 00096 static volatile uint8_t *u8g_data_port[8]; 00097 static uint8_t u8g_data_mask[8]; 00098 #endif 00099 00100 00101 00102 static void u8g_com_arduino_fast_parallel_init(u8g_t *u8g) 00103 { 00104 u8g_data_port[0] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D0])); 00105 u8g_data_mask[0] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D0]); 00106 u8g_data_port[1] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D1])); 00107 u8g_data_mask[1] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D1]); 00108 u8g_data_port[2] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D2])); 00109 u8g_data_mask[2] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D2]); 00110 u8g_data_port[3] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D3])); 00111 u8g_data_mask[3] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D3]); 00112 00113 u8g_data_port[4] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D4])); 00114 u8g_data_mask[4] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D4]); 00115 u8g_data_port[5] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D5])); 00116 u8g_data_mask[5] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D5]); 00117 u8g_data_port[6] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D6])); 00118 u8g_data_mask[6] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D6]); 00119 u8g_data_port[7] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D7])); 00120 u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]); 00121 } 00122 00123 /* atomic protection must be done by calling function */ 00124 static void u8g_com_arduino_fast_write_data_pin(uint8_t pin, uint8_t val) 00125 { 00126 if ( val != 0 ) 00127 *u8g_data_port[pin] |= u8g_data_mask[pin]; 00128 else 00129 *u8g_data_port[pin] &= ~u8g_data_mask[pin]; 00130 } 00131 00132 00133 void u8g_com_arduino_fast_parallel_write(u8g_t *u8g, uint8_t val) 00134 { 00135 U8G_ATOMIC_START(); 00136 u8g_com_arduino_fast_write_data_pin( 0, val&1 ); 00137 val >>= 1; 00138 u8g_com_arduino_fast_write_data_pin( 1, val&1 ); 00139 val >>= 1; 00140 u8g_com_arduino_fast_write_data_pin( 2, val&1 ); 00141 val >>= 1; 00142 u8g_com_arduino_fast_write_data_pin( 3, val&1 ); 00143 val >>= 1; 00144 00145 u8g_com_arduino_fast_write_data_pin( 4, val&1 ); 00146 val >>= 1; 00147 u8g_com_arduino_fast_write_data_pin( 5, val&1 ); 00148 val >>= 1; 00149 u8g_com_arduino_fast_write_data_pin( 6, val&1 ); 00150 val >>= 1; 00151 u8g_com_arduino_fast_write_data_pin( 7, val&1 ); 00152 val >>= 1; 00153 U8G_ATOMIC_END(); 00154 00155 /* EN cycle time must be 1 micro second */ 00156 u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH); 00157 u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */ 00158 u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW); 00159 u8g_10MicroDelay(); /* ST7920 commands: 72us */ 00160 u8g_10MicroDelay(); /* ST7920 commands: 72us */ 00161 } 00162 00163 00164 uint8_t u8g_com_arduino_fast_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00165 { 00166 switch(msg) 00167 { 00168 case U8G_COM_MSG_INIT: 00169 u8g_com_arduino_fast_parallel_init(u8g); 00170 /* setup the RW pin as output and force it to low */ 00171 if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE ) 00172 { 00173 pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT); 00174 u8g_com_arduino_digital_write(u8g, U8G_PI_RW, LOW); 00175 } 00176 /* set all pins (except RW pin) */ 00177 u8g_com_arduino_assign_pin_output_high(u8g); 00178 break; 00179 case U8G_COM_MSG_STOP: 00180 break; 00181 00182 case U8G_COM_MSG_CHIP_SELECT: 00183 if ( arg_val == 0 ) 00184 { 00185 /* disable */ 00186 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 00187 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 00188 } 00189 else if ( arg_val == 1 ) 00190 { 00191 /* enable */ 00192 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 00193 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 00194 } 00195 else if ( arg_val == 2 ) 00196 { 00197 /* enable */ 00198 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 00199 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 00200 } 00201 else 00202 { 00203 /* enable */ 00204 u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 00205 u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 00206 } 00207 break; 00208 case U8G_COM_MSG_WRITE_BYTE: 00209 u8g_com_arduino_fast_parallel_write(u8g, arg_val); 00210 break; 00211 case U8G_COM_MSG_WRITE_SEQ: 00212 { 00213 register uint8_t *ptr = arg_ptr; 00214 while( arg_val > 0 ) 00215 { 00216 u8g_com_arduino_fast_parallel_write(u8g, *ptr++); 00217 arg_val--; 00218 } 00219 } 00220 break; 00221 case U8G_COM_MSG_WRITE_SEQ_P: 00222 { 00223 register uint8_t *ptr = arg_ptr; 00224 while( arg_val > 0 ) 00225 { 00226 u8g_com_arduino_fast_parallel_write(u8g, u8g_pgm_read(ptr)); 00227 ptr++; 00228 arg_val--; 00229 } 00230 } 00231 break; 00232 case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 00233 u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val); 00234 break; 00235 case U8G_COM_MSG_RESET: 00236 if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 00237 u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 00238 break; 00239 00240 } 00241 return 1; 00242 } 00243 00244 #else 00245 00246 00247 uint8_t u8g_com_arduino_fast_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00248 { 00249 return 1; 00250 } 00251 00252 00253 #endif /* ARDUINO */ 00254 00255
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2