iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_com_arduino_no_en_parallel.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_arduino_no_en_parallel.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 6 | |
iforce2d | 0:972874f31c98 | 7 | Copyright (c) 2012, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 8 | All rights reserved. |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 11 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 14 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 17 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 18 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 19 | |
iforce2d | 0:972874f31c98 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 33 | |
iforce2d | 0:972874f31c98 | 34 | PIN_D0 8 |
iforce2d | 0:972874f31c98 | 35 | PIN_D1 9 |
iforce2d | 0:972874f31c98 | 36 | PIN_D2 10 |
iforce2d | 0:972874f31c98 | 37 | PIN_D3 11 |
iforce2d | 0:972874f31c98 | 38 | PIN_D4 4 |
iforce2d | 0:972874f31c98 | 39 | PIN_D5 5 |
iforce2d | 0:972874f31c98 | 40 | PIN_D6 6 |
iforce2d | 0:972874f31c98 | 41 | PIN_D7 7 |
iforce2d | 0:972874f31c98 | 42 | |
iforce2d | 0:972874f31c98 | 43 | PIN_CS1 14 |
iforce2d | 0:972874f31c98 | 44 | PIN_CS2 15 |
iforce2d | 0:972874f31c98 | 45 | PIN_RW 16 |
iforce2d | 0:972874f31c98 | 46 | PIN_DI 17 |
iforce2d | 0:972874f31c98 | 47 | PIN_EN 18 |
iforce2d | 0:972874f31c98 | 48 | |
iforce2d | 0:972874f31c98 | 49 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) |
iforce2d | 0:972874f31c98 | 50 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) |
iforce2d | 0:972874f31c98 | 51 | Update for ATOMIC operation done (01 Jun 2013) |
iforce2d | 0:972874f31c98 | 52 | |
iforce2d | 0:972874f31c98 | 53 | U8G_ATOMIC_OR(ptr, val) |
iforce2d | 0:972874f31c98 | 54 | U8G_ATOMIC_AND(ptr, val) |
iforce2d | 0:972874f31c98 | 55 | U8G_ATOMIC_START(); |
iforce2d | 0:972874f31c98 | 56 | U8G_ATOMIC_END(); |
iforce2d | 0:972874f31c98 | 57 | |
iforce2d | 0:972874f31c98 | 58 | */ |
iforce2d | 0:972874f31c98 | 59 | |
iforce2d | 0:972874f31c98 | 60 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 61 | |
iforce2d | 0:972874f31c98 | 62 | #if defined(ARDUINO) |
iforce2d | 0:972874f31c98 | 63 | |
iforce2d | 0:972874f31c98 | 64 | #if ARDUINO < 100 |
iforce2d | 0:972874f31c98 | 65 | //#include <WProgram.h> |
iforce2d | 0:972874f31c98 | 66 | #include <wiring_private.h> |
iforce2d | 0:972874f31c98 | 67 | #include <pins_arduino.h> |
iforce2d | 0:972874f31c98 | 68 | #else |
iforce2d | 0:972874f31c98 | 69 | #include <Arduino.h> |
iforce2d | 0:972874f31c98 | 70 | #endif |
iforce2d | 0:972874f31c98 | 71 | |
iforce2d | 0:972874f31c98 | 72 | //#define PIN_RESET |
iforce2d | 0:972874f31c98 | 73 | |
iforce2d | 0:972874f31c98 | 74 | #if defined(__PIC32MX) |
iforce2d | 0:972874f31c98 | 75 | /* CHIPKIT PIC32 */ |
iforce2d | 0:972874f31c98 | 76 | static volatile uint32_t *u8g_data_port[8]; |
iforce2d | 0:972874f31c98 | 77 | static uint32_t u8g_data_mask[8]; |
iforce2d | 0:972874f31c98 | 78 | #else |
iforce2d | 0:972874f31c98 | 79 | static volatile uint8_t *u8g_data_port[8]; |
iforce2d | 0:972874f31c98 | 80 | static uint8_t u8g_data_mask[8]; |
iforce2d | 0:972874f31c98 | 81 | #endif |
iforce2d | 0:972874f31c98 | 82 | |
iforce2d | 0:972874f31c98 | 83 | |
iforce2d | 0:972874f31c98 | 84 | |
iforce2d | 0:972874f31c98 | 85 | static void u8g_com_arduino_no_en_parallel_init(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 86 | { |
iforce2d | 0:972874f31c98 | 87 | u8g_data_port[0] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D0])); |
iforce2d | 0:972874f31c98 | 88 | u8g_data_mask[0] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D0]); |
iforce2d | 0:972874f31c98 | 89 | u8g_data_port[1] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D1])); |
iforce2d | 0:972874f31c98 | 90 | u8g_data_mask[1] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D1]); |
iforce2d | 0:972874f31c98 | 91 | u8g_data_port[2] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D2])); |
iforce2d | 0:972874f31c98 | 92 | u8g_data_mask[2] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D2]); |
iforce2d | 0:972874f31c98 | 93 | u8g_data_port[3] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D3])); |
iforce2d | 0:972874f31c98 | 94 | u8g_data_mask[3] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D3]); |
iforce2d | 0:972874f31c98 | 95 | |
iforce2d | 0:972874f31c98 | 96 | u8g_data_port[4] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D4])); |
iforce2d | 0:972874f31c98 | 97 | u8g_data_mask[4] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D4]); |
iforce2d | 0:972874f31c98 | 98 | u8g_data_port[5] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D5])); |
iforce2d | 0:972874f31c98 | 99 | u8g_data_mask[5] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D5]); |
iforce2d | 0:972874f31c98 | 100 | u8g_data_port[6] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D6])); |
iforce2d | 0:972874f31c98 | 101 | u8g_data_mask[6] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D6]); |
iforce2d | 0:972874f31c98 | 102 | u8g_data_port[7] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D7])); |
iforce2d | 0:972874f31c98 | 103 | u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]); |
iforce2d | 0:972874f31c98 | 104 | } |
iforce2d | 0:972874f31c98 | 105 | |
iforce2d | 0:972874f31c98 | 106 | /* No atomic protcetion. This is done by caller */ |
iforce2d | 0:972874f31c98 | 107 | static void u8g_com_arduino_no_en_write_data_pin(uint8_t pin, uint8_t val) |
iforce2d | 0:972874f31c98 | 108 | { |
iforce2d | 0:972874f31c98 | 109 | if ( val != 0 ) |
iforce2d | 0:972874f31c98 | 110 | { |
iforce2d | 0:972874f31c98 | 111 | *u8g_data_port[pin] |= u8g_data_mask[pin]; |
iforce2d | 0:972874f31c98 | 112 | } |
iforce2d | 0:972874f31c98 | 113 | else |
iforce2d | 0:972874f31c98 | 114 | { |
iforce2d | 0:972874f31c98 | 115 | *u8g_data_port[pin] &= ~u8g_data_mask[pin]; |
iforce2d | 0:972874f31c98 | 116 | } |
iforce2d | 0:972874f31c98 | 117 | } |
iforce2d | 0:972874f31c98 | 118 | |
iforce2d | 0:972874f31c98 | 119 | |
iforce2d | 0:972874f31c98 | 120 | void u8g_com_arduino_no_en_parallel_write(u8g_t *u8g, uint8_t val) |
iforce2d | 0:972874f31c98 | 121 | { |
iforce2d | 0:972874f31c98 | 122 | U8G_ATOMIC_START(); |
iforce2d | 0:972874f31c98 | 123 | u8g_com_arduino_no_en_write_data_pin( 0, val&1 ); |
iforce2d | 0:972874f31c98 | 124 | val >>= 1; |
iforce2d | 0:972874f31c98 | 125 | u8g_com_arduino_no_en_write_data_pin( 1, val&1 ); |
iforce2d | 0:972874f31c98 | 126 | val >>= 1; |
iforce2d | 0:972874f31c98 | 127 | u8g_com_arduino_no_en_write_data_pin( 2, val&1 ); |
iforce2d | 0:972874f31c98 | 128 | val >>= 1; |
iforce2d | 0:972874f31c98 | 129 | u8g_com_arduino_no_en_write_data_pin( 3, val&1 ); |
iforce2d | 0:972874f31c98 | 130 | val >>= 1; |
iforce2d | 0:972874f31c98 | 131 | |
iforce2d | 0:972874f31c98 | 132 | u8g_com_arduino_no_en_write_data_pin( 4, val&1 ); |
iforce2d | 0:972874f31c98 | 133 | val >>= 1; |
iforce2d | 0:972874f31c98 | 134 | u8g_com_arduino_no_en_write_data_pin( 5, val&1 ); |
iforce2d | 0:972874f31c98 | 135 | val >>= 1; |
iforce2d | 0:972874f31c98 | 136 | u8g_com_arduino_no_en_write_data_pin( 6, val&1 ); |
iforce2d | 0:972874f31c98 | 137 | val >>= 1; |
iforce2d | 0:972874f31c98 | 138 | u8g_com_arduino_no_en_write_data_pin( 7, val&1 ); |
iforce2d | 0:972874f31c98 | 139 | val >>= 1; |
iforce2d | 0:972874f31c98 | 140 | U8G_ATOMIC_END(); |
iforce2d | 0:972874f31c98 | 141 | |
iforce2d | 0:972874f31c98 | 142 | /* EN cycle time must be 1 micro second, digitalWrite is slow enough to do this */ |
iforce2d | 0:972874f31c98 | 143 | if ( u8g->pin_list[U8G_PI_CS_STATE] == 1 ) |
iforce2d | 0:972874f31c98 | 144 | { |
iforce2d | 0:972874f31c98 | 145 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 146 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); |
iforce2d | 0:972874f31c98 | 147 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 148 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); |
iforce2d | 0:972874f31c98 | 149 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 150 | } |
iforce2d | 0:972874f31c98 | 151 | else if ( u8g->pin_list[U8G_PI_CS_STATE] == 2 ) |
iforce2d | 0:972874f31c98 | 152 | { |
iforce2d | 0:972874f31c98 | 153 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 154 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); |
iforce2d | 0:972874f31c98 | 155 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 156 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); |
iforce2d | 0:972874f31c98 | 157 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 158 | } |
iforce2d | 0:972874f31c98 | 159 | } |
iforce2d | 0:972874f31c98 | 160 | |
iforce2d | 0:972874f31c98 | 161 | |
iforce2d | 0:972874f31c98 | 162 | uint8_t u8g_com_arduino_no_en_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) |
iforce2d | 0:972874f31c98 | 163 | { |
iforce2d | 0:972874f31c98 | 164 | switch(msg) |
iforce2d | 0:972874f31c98 | 165 | { |
iforce2d | 0:972874f31c98 | 166 | case U8G_COM_MSG_INIT: |
iforce2d | 0:972874f31c98 | 167 | u8g_com_arduino_no_en_parallel_init(u8g); |
iforce2d | 0:972874f31c98 | 168 | /* setup the RW pin as output and force it to low */ |
iforce2d | 0:972874f31c98 | 169 | if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE ) |
iforce2d | 0:972874f31c98 | 170 | { |
iforce2d | 0:972874f31c98 | 171 | pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT); |
iforce2d | 0:972874f31c98 | 172 | u8g_com_arduino_digital_write(u8g, U8G_PI_RW, LOW); |
iforce2d | 0:972874f31c98 | 173 | } |
iforce2d | 0:972874f31c98 | 174 | /* set all pins (except RW pin) */ |
iforce2d | 0:972874f31c98 | 175 | u8g_com_arduino_assign_pin_output_high(u8g); |
iforce2d | 0:972874f31c98 | 176 | break; |
iforce2d | 0:972874f31c98 | 177 | case U8G_COM_MSG_STOP: |
iforce2d | 0:972874f31c98 | 178 | break; |
iforce2d | 0:972874f31c98 | 179 | |
iforce2d | 0:972874f31c98 | 180 | case U8G_COM_MSG_CHIP_SELECT: |
iforce2d | 0:972874f31c98 | 181 | /* |
iforce2d | 0:972874f31c98 | 182 | 0: nothing selected |
iforce2d | 0:972874f31c98 | 183 | 1: CS1 will be used as enable line |
iforce2d | 0:972874f31c98 | 184 | 2: CS2 will be used as enable line |
iforce2d | 0:972874f31c98 | 185 | this will be used in the u8g_com_arduino_no_en_parallel_write() procedure |
iforce2d | 0:972874f31c98 | 186 | */ |
iforce2d | 0:972874f31c98 | 187 | u8g->pin_list[U8G_PI_CS_STATE] = arg_val; |
iforce2d | 0:972874f31c98 | 188 | break; |
iforce2d | 0:972874f31c98 | 189 | case U8G_COM_MSG_WRITE_BYTE: |
iforce2d | 0:972874f31c98 | 190 | u8g_com_arduino_no_en_parallel_write(u8g, arg_val); |
iforce2d | 0:972874f31c98 | 191 | break; |
iforce2d | 0:972874f31c98 | 192 | case U8G_COM_MSG_WRITE_SEQ: |
iforce2d | 0:972874f31c98 | 193 | { |
iforce2d | 0:972874f31c98 | 194 | register uint8_t *ptr = arg_ptr; |
iforce2d | 0:972874f31c98 | 195 | while( arg_val > 0 ) |
iforce2d | 0:972874f31c98 | 196 | { |
iforce2d | 0:972874f31c98 | 197 | u8g_com_arduino_no_en_parallel_write(u8g, *ptr++); |
iforce2d | 0:972874f31c98 | 198 | arg_val--; |
iforce2d | 0:972874f31c98 | 199 | } |
iforce2d | 0:972874f31c98 | 200 | } |
iforce2d | 0:972874f31c98 | 201 | break; |
iforce2d | 0:972874f31c98 | 202 | case U8G_COM_MSG_WRITE_SEQ_P: |
iforce2d | 0:972874f31c98 | 203 | { |
iforce2d | 0:972874f31c98 | 204 | register uint8_t *ptr = arg_ptr; |
iforce2d | 0:972874f31c98 | 205 | while( arg_val > 0 ) |
iforce2d | 0:972874f31c98 | 206 | { |
iforce2d | 0:972874f31c98 | 207 | u8g_com_arduino_no_en_parallel_write(u8g, u8g_pgm_read(ptr)); |
iforce2d | 0:972874f31c98 | 208 | ptr++; |
iforce2d | 0:972874f31c98 | 209 | arg_val--; |
iforce2d | 0:972874f31c98 | 210 | } |
iforce2d | 0:972874f31c98 | 211 | } |
iforce2d | 0:972874f31c98 | 212 | break; |
iforce2d | 0:972874f31c98 | 213 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ |
iforce2d | 0:972874f31c98 | 214 | u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val); |
iforce2d | 0:972874f31c98 | 215 | break; |
iforce2d | 0:972874f31c98 | 216 | case U8G_COM_MSG_RESET: |
iforce2d | 0:972874f31c98 | 217 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) |
iforce2d | 0:972874f31c98 | 218 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); |
iforce2d | 0:972874f31c98 | 219 | break; |
iforce2d | 0:972874f31c98 | 220 | } |
iforce2d | 0:972874f31c98 | 221 | return 1; |
iforce2d | 0:972874f31c98 | 222 | } |
iforce2d | 0:972874f31c98 | 223 | |
iforce2d | 0:972874f31c98 | 224 | #else |
iforce2d | 0:972874f31c98 | 225 | |
iforce2d | 0:972874f31c98 | 226 | |
iforce2d | 0:972874f31c98 | 227 | uint8_t u8g_com_arduino_no_en_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) |
iforce2d | 0:972874f31c98 | 228 | { |
iforce2d | 0:972874f31c98 | 229 | return 1; |
iforce2d | 0:972874f31c98 | 230 | } |
iforce2d | 0:972874f31c98 | 231 | |
iforce2d | 0:972874f31c98 | 232 | |
iforce2d | 0:972874f31c98 | 233 | #endif /* ARDUINO */ |
iforce2d | 0:972874f31c98 | 234 | |
iforce2d | 0:972874f31c98 | 235 |