iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_com_arduino_st7920_custom.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_com_arduino_st7920_custom.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Additional COM device, initially introduced for 3D Printer community |
iforce2d | 0:972874f31c98 | 6 | Implements a fast SW SPI com subsystem |
iforce2d | 0:972874f31c98 | 7 | |
iforce2d | 0:972874f31c98 | 8 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Copyright (c) 2011, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 11 | All rights reserved. |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 14 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 17 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 18 | |
iforce2d | 0:972874f31c98 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 20 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 21 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 22 | |
iforce2d | 0:972874f31c98 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | A special SPI interface for ST7920 controller |
iforce2d | 0:972874f31c98 | 38 | |
iforce2d | 0:972874f31c98 | 39 | Update for ATOMIC operation done (01 Jun 2013) |
iforce2d | 0:972874f31c98 | 40 | U8G_ATOMIC_OR(ptr, val) |
iforce2d | 0:972874f31c98 | 41 | U8G_ATOMIC_AND(ptr, val) |
iforce2d | 0:972874f31c98 | 42 | U8G_ATOMIC_START(); |
iforce2d | 0:972874f31c98 | 43 | U8G_ATOMIC_END(); |
iforce2d | 0:972874f31c98 | 44 | |
iforce2d | 0:972874f31c98 | 45 | |
iforce2d | 0:972874f31c98 | 46 | */ |
iforce2d | 0:972874f31c98 | 47 | |
iforce2d | 0:972874f31c98 | 48 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 49 | |
iforce2d | 0:972874f31c98 | 50 | #if defined(ARDUINO) |
iforce2d | 0:972874f31c98 | 51 | |
iforce2d | 0:972874f31c98 | 52 | #if ARDUINO < 100 |
iforce2d | 0:972874f31c98 | 53 | #include <WProgram.h> |
iforce2d | 0:972874f31c98 | 54 | #include "wiring_private.h" |
iforce2d | 0:972874f31c98 | 55 | #include "pins_arduino.h" |
iforce2d | 0:972874f31c98 | 56 | |
iforce2d | 0:972874f31c98 | 57 | #else |
iforce2d | 0:972874f31c98 | 58 | #include <Arduino.h> |
iforce2d | 0:972874f31c98 | 59 | #include "wiring_private.h" |
iforce2d | 0:972874f31c98 | 60 | #endif |
iforce2d | 0:972874f31c98 | 61 | |
iforce2d | 0:972874f31c98 | 62 | #if defined(__AVR__) |
iforce2d | 0:972874f31c98 | 63 | |
iforce2d | 0:972874f31c98 | 64 | uint8_t u8g_bitData, u8g_bitNotData; |
iforce2d | 0:972874f31c98 | 65 | uint8_t u8g_bitClock, u8g_bitNotClock; |
iforce2d | 0:972874f31c98 | 66 | volatile uint8_t *u8g_outData; |
iforce2d | 0:972874f31c98 | 67 | volatile uint8_t *u8g_outClock; |
iforce2d | 0:972874f31c98 | 68 | |
iforce2d | 0:972874f31c98 | 69 | static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin) |
iforce2d | 0:972874f31c98 | 70 | { |
iforce2d | 0:972874f31c98 | 71 | u8g_outData = portOutputRegister(digitalPinToPort(dataPin)); |
iforce2d | 0:972874f31c98 | 72 | u8g_outClock = portOutputRegister(digitalPinToPort(clockPin)); |
iforce2d | 0:972874f31c98 | 73 | u8g_bitData = digitalPinToBitMask(dataPin); |
iforce2d | 0:972874f31c98 | 74 | u8g_bitClock = digitalPinToBitMask(clockPin); |
iforce2d | 0:972874f31c98 | 75 | |
iforce2d | 0:972874f31c98 | 76 | u8g_bitNotClock = u8g_bitClock; |
iforce2d | 0:972874f31c98 | 77 | u8g_bitNotClock ^= 0x0ff; |
iforce2d | 0:972874f31c98 | 78 | |
iforce2d | 0:972874f31c98 | 79 | u8g_bitNotData = u8g_bitData; |
iforce2d | 0:972874f31c98 | 80 | u8g_bitNotData ^= 0x0ff; |
iforce2d | 0:972874f31c98 | 81 | } |
iforce2d | 0:972874f31c98 | 82 | |
iforce2d | 0:972874f31c98 | 83 | static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 84 | static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) |
iforce2d | 0:972874f31c98 | 85 | { |
iforce2d | 0:972874f31c98 | 86 | uint8_t cnt = 8; |
iforce2d | 0:972874f31c98 | 87 | uint8_t bitData = u8g_bitData; |
iforce2d | 0:972874f31c98 | 88 | uint8_t bitNotData = u8g_bitNotData; |
iforce2d | 0:972874f31c98 | 89 | uint8_t bitClock = u8g_bitClock; |
iforce2d | 0:972874f31c98 | 90 | uint8_t bitNotClock = u8g_bitNotClock; |
iforce2d | 0:972874f31c98 | 91 | volatile uint8_t *outData = u8g_outData; |
iforce2d | 0:972874f31c98 | 92 | volatile uint8_t *outClock = u8g_outClock; |
iforce2d | 0:972874f31c98 | 93 | |
iforce2d | 0:972874f31c98 | 94 | |
iforce2d | 0:972874f31c98 | 95 | U8G_ATOMIC_START(); |
iforce2d | 0:972874f31c98 | 96 | bitData |= *outData; |
iforce2d | 0:972874f31c98 | 97 | bitNotData &= *outData; |
iforce2d | 0:972874f31c98 | 98 | do |
iforce2d | 0:972874f31c98 | 99 | { |
iforce2d | 0:972874f31c98 | 100 | if ( val & 128 ) |
iforce2d | 0:972874f31c98 | 101 | *outData = bitData; |
iforce2d | 0:972874f31c98 | 102 | else |
iforce2d | 0:972874f31c98 | 103 | *outData = bitNotData; |
iforce2d | 0:972874f31c98 | 104 | |
iforce2d | 0:972874f31c98 | 105 | /* |
iforce2d | 0:972874f31c98 | 106 | *outClock |= bitClock; |
iforce2d | 0:972874f31c98 | 107 | val <<= 1; |
iforce2d | 0:972874f31c98 | 108 | cnt--; |
iforce2d | 0:972874f31c98 | 109 | *outClock &= bitNotClock; |
iforce2d | 0:972874f31c98 | 110 | */ |
iforce2d | 0:972874f31c98 | 111 | |
iforce2d | 0:972874f31c98 | 112 | val <<= 1; |
iforce2d | 0:972874f31c98 | 113 | *outClock &= bitNotClock; |
iforce2d | 0:972874f31c98 | 114 | cnt--; |
iforce2d | 0:972874f31c98 | 115 | // removed micro delays, because AVRs are too slow and the delay is not required |
iforce2d | 0:972874f31c98 | 116 | //u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 117 | *outClock |= bitClock; |
iforce2d | 0:972874f31c98 | 118 | //u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 119 | } while( cnt != 0 ); |
iforce2d | 0:972874f31c98 | 120 | U8G_ATOMIC_END(); |
iforce2d | 0:972874f31c98 | 121 | } |
iforce2d | 0:972874f31c98 | 122 | |
iforce2d | 0:972874f31c98 | 123 | #elif defined(__18CXX) || defined(__PIC32MX) |
iforce2d | 0:972874f31c98 | 124 | |
iforce2d | 0:972874f31c98 | 125 | uint16_t dog_bitData, dog_bitNotData; |
iforce2d | 0:972874f31c98 | 126 | uint16_t dog_bitClock, dog_bitNotClock; |
iforce2d | 0:972874f31c98 | 127 | volatile uint32_t *dog_outData; |
iforce2d | 0:972874f31c98 | 128 | volatile uint32_t *dog_outClock; |
iforce2d | 0:972874f31c98 | 129 | volatile uint32_t dog_pic32_spi_tmp; |
iforce2d | 0:972874f31c98 | 130 | |
iforce2d | 0:972874f31c98 | 131 | static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin) |
iforce2d | 0:972874f31c98 | 132 | { |
iforce2d | 0:972874f31c98 | 133 | dog_outData = portOutputRegister(digitalPinToPort(dataPin)); |
iforce2d | 0:972874f31c98 | 134 | dog_outClock = portOutputRegister(digitalPinToPort(clockPin)); |
iforce2d | 0:972874f31c98 | 135 | dog_bitData = digitalPinToBitMask(dataPin); |
iforce2d | 0:972874f31c98 | 136 | dog_bitClock = digitalPinToBitMask(clockPin); |
iforce2d | 0:972874f31c98 | 137 | |
iforce2d | 0:972874f31c98 | 138 | dog_bitNotClock = dog_bitClock; |
iforce2d | 0:972874f31c98 | 139 | dog_bitNotClock ^= 0x0ffff; |
iforce2d | 0:972874f31c98 | 140 | |
iforce2d | 0:972874f31c98 | 141 | dog_bitNotData = dog_bitData; |
iforce2d | 0:972874f31c98 | 142 | dog_bitNotData ^= 0x0ffff; |
iforce2d | 0:972874f31c98 | 143 | } |
iforce2d | 0:972874f31c98 | 144 | |
iforce2d | 0:972874f31c98 | 145 | static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) |
iforce2d | 0:972874f31c98 | 146 | { |
iforce2d | 0:972874f31c98 | 147 | uint8_t cnt = 8; |
iforce2d | 0:972874f31c98 | 148 | U8G_ATOMIC_START(); |
iforce2d | 0:972874f31c98 | 149 | do |
iforce2d | 0:972874f31c98 | 150 | { |
iforce2d | 0:972874f31c98 | 151 | if ( val & 128 ) |
iforce2d | 0:972874f31c98 | 152 | *dog_outData |= dog_bitData; |
iforce2d | 0:972874f31c98 | 153 | else |
iforce2d | 0:972874f31c98 | 154 | *dog_outData &= dog_bitNotData; |
iforce2d | 0:972874f31c98 | 155 | val <<= 1; |
iforce2d | 0:972874f31c98 | 156 | //u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 157 | //*dog_outClock |= dog_bitClock; |
iforce2d | 0:972874f31c98 | 158 | *dog_outClock &= dog_bitNotClock; |
iforce2d | 0:972874f31c98 | 159 | cnt--; |
iforce2d | 0:972874f31c98 | 160 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 161 | //*dog_outClock &= dog_bitNotClock; |
iforce2d | 0:972874f31c98 | 162 | *dog_outClock |= dog_bitClock; |
iforce2d | 0:972874f31c98 | 163 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 164 | |
iforce2d | 0:972874f31c98 | 165 | } while( cnt != 0 ); |
iforce2d | 0:972874f31c98 | 166 | U8G_ATOMIC_END(); |
iforce2d | 0:972874f31c98 | 167 | } |
iforce2d | 0:972874f31c98 | 168 | |
iforce2d | 0:972874f31c98 | 169 | #else |
iforce2d | 0:972874f31c98 | 170 | |
iforce2d | 0:972874f31c98 | 171 | /* default interface, Arduino DUE (__arm__) */ |
iforce2d | 0:972874f31c98 | 172 | |
iforce2d | 0:972874f31c98 | 173 | uint8_t u8g_data_pin; |
iforce2d | 0:972874f31c98 | 174 | uint8_t u8g_clock_pin; |
iforce2d | 0:972874f31c98 | 175 | |
iforce2d | 0:972874f31c98 | 176 | static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin) |
iforce2d | 0:972874f31c98 | 177 | { |
iforce2d | 0:972874f31c98 | 178 | u8g_data_pin = dataPin; |
iforce2d | 0:972874f31c98 | 179 | u8g_clock_pin = clockPin; |
iforce2d | 0:972874f31c98 | 180 | } |
iforce2d | 0:972874f31c98 | 181 | |
iforce2d | 0:972874f31c98 | 182 | static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) |
iforce2d | 0:972874f31c98 | 183 | { |
iforce2d | 0:972874f31c98 | 184 | uint8_t cnt = 8; |
iforce2d | 0:972874f31c98 | 185 | do |
iforce2d | 0:972874f31c98 | 186 | { |
iforce2d | 0:972874f31c98 | 187 | if ( val & 128 ) |
iforce2d | 0:972874f31c98 | 188 | digitalWrite(u8g_data_pin, HIGH); |
iforce2d | 0:972874f31c98 | 189 | else |
iforce2d | 0:972874f31c98 | 190 | digitalWrite(u8g_data_pin, LOW); |
iforce2d | 0:972874f31c98 | 191 | val <<= 1; |
iforce2d | 0:972874f31c98 | 192 | //u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 193 | digitalWrite(u8g_clock_pin, LOW); |
iforce2d | 0:972874f31c98 | 194 | cnt--; |
iforce2d | 0:972874f31c98 | 195 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 196 | digitalWrite(u8g_clock_pin, HIGH); |
iforce2d | 0:972874f31c98 | 197 | u8g_MicroDelay(); |
iforce2d | 0:972874f31c98 | 198 | } while( cnt != 0 ); |
iforce2d | 0:972874f31c98 | 199 | } |
iforce2d | 0:972874f31c98 | 200 | |
iforce2d | 0:972874f31c98 | 201 | #endif |
iforce2d | 0:972874f31c98 | 202 | |
iforce2d | 0:972874f31c98 | 203 | |
iforce2d | 0:972874f31c98 | 204 | static void u8g_com_arduino_st7920_write_byte_seq(uint8_t rs, uint8_t *ptr, uint8_t len) |
iforce2d | 0:972874f31c98 | 205 | { |
iforce2d | 0:972874f31c98 | 206 | uint8_t i; |
iforce2d | 0:972874f31c98 | 207 | |
iforce2d | 0:972874f31c98 | 208 | if ( rs == 0 ) |
iforce2d | 0:972874f31c98 | 209 | { |
iforce2d | 0:972874f31c98 | 210 | /* command */ |
iforce2d | 0:972874f31c98 | 211 | u8g_com_arduino_do_shift_out_msb_first(0x0f8); |
iforce2d | 0:972874f31c98 | 212 | } |
iforce2d | 0:972874f31c98 | 213 | else if ( rs == 1 ) |
iforce2d | 0:972874f31c98 | 214 | { |
iforce2d | 0:972874f31c98 | 215 | /* data */ |
iforce2d | 0:972874f31c98 | 216 | u8g_com_arduino_do_shift_out_msb_first(0x0fa); |
iforce2d | 0:972874f31c98 | 217 | } |
iforce2d | 0:972874f31c98 | 218 | |
iforce2d | 0:972874f31c98 | 219 | while( len > 0 ) |
iforce2d | 0:972874f31c98 | 220 | { |
iforce2d | 0:972874f31c98 | 221 | u8g_com_arduino_do_shift_out_msb_first(*ptr & 0x0f0); |
iforce2d | 0:972874f31c98 | 222 | u8g_com_arduino_do_shift_out_msb_first(*ptr << 4); |
iforce2d | 0:972874f31c98 | 223 | ptr++; |
iforce2d | 0:972874f31c98 | 224 | len--; |
iforce2d | 0:972874f31c98 | 225 | u8g_10MicroDelay(); |
iforce2d | 0:972874f31c98 | 226 | } |
iforce2d | 0:972874f31c98 | 227 | |
iforce2d | 0:972874f31c98 | 228 | for( i = 0; i < 4; i++ ) |
iforce2d | 0:972874f31c98 | 229 | u8g_10MicroDelay(); |
iforce2d | 0:972874f31c98 | 230 | } |
iforce2d | 0:972874f31c98 | 231 | |
iforce2d | 0:972874f31c98 | 232 | static void u8g_com_arduino_st7920_write_byte(uint8_t rs, uint8_t val) |
iforce2d | 0:972874f31c98 | 233 | { |
iforce2d | 0:972874f31c98 | 234 | uint8_t i; |
iforce2d | 0:972874f31c98 | 235 | |
iforce2d | 0:972874f31c98 | 236 | if ( rs == 0 ) |
iforce2d | 0:972874f31c98 | 237 | { |
iforce2d | 0:972874f31c98 | 238 | /* command */ |
iforce2d | 0:972874f31c98 | 239 | u8g_com_arduino_do_shift_out_msb_first(0x0f8); |
iforce2d | 0:972874f31c98 | 240 | } |
iforce2d | 0:972874f31c98 | 241 | else if ( rs == 1 ) |
iforce2d | 0:972874f31c98 | 242 | { |
iforce2d | 0:972874f31c98 | 243 | /* data */ |
iforce2d | 0:972874f31c98 | 244 | u8g_com_arduino_do_shift_out_msb_first(0x0fa); |
iforce2d | 0:972874f31c98 | 245 | } |
iforce2d | 0:972874f31c98 | 246 | |
iforce2d | 0:972874f31c98 | 247 | u8g_com_arduino_do_shift_out_msb_first(val & 0x0f0); |
iforce2d | 0:972874f31c98 | 248 | u8g_com_arduino_do_shift_out_msb_first(val << 4); |
iforce2d | 0:972874f31c98 | 249 | |
iforce2d | 0:972874f31c98 | 250 | for( i = 0; i < 4; i++ ) |
iforce2d | 0:972874f31c98 | 251 | u8g_10MicroDelay(); |
iforce2d | 0:972874f31c98 | 252 | |
iforce2d | 0:972874f31c98 | 253 | } |
iforce2d | 0:972874f31c98 | 254 | |
iforce2d | 0:972874f31c98 | 255 | |
iforce2d | 0:972874f31c98 | 256 | uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) |
iforce2d | 0:972874f31c98 | 257 | { |
iforce2d | 0:972874f31c98 | 258 | switch(msg) |
iforce2d | 0:972874f31c98 | 259 | { |
iforce2d | 0:972874f31c98 | 260 | case U8G_COM_MSG_INIT: |
iforce2d | 0:972874f31c98 | 261 | u8g_com_arduino_assign_pin_output_high(u8g); |
iforce2d | 0:972874f31c98 | 262 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); |
iforce2d | 0:972874f31c98 | 263 | // u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); |
iforce2d | 0:972874f31c98 | 264 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH); |
iforce2d | 0:972874f31c98 | 265 | u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW); |
iforce2d | 0:972874f31c98 | 266 | u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]); |
iforce2d | 0:972874f31c98 | 267 | u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */ |
iforce2d | 0:972874f31c98 | 268 | break; |
iforce2d | 0:972874f31c98 | 269 | |
iforce2d | 0:972874f31c98 | 270 | case U8G_COM_MSG_STOP: |
iforce2d | 0:972874f31c98 | 271 | break; |
iforce2d | 0:972874f31c98 | 272 | |
iforce2d | 0:972874f31c98 | 273 | case U8G_COM_MSG_RESET: |
iforce2d | 0:972874f31c98 | 274 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) |
iforce2d | 0:972874f31c98 | 275 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); |
iforce2d | 0:972874f31c98 | 276 | break; |
iforce2d | 0:972874f31c98 | 277 | |
iforce2d | 0:972874f31c98 | 278 | case U8G_COM_MSG_CHIP_SELECT: |
iforce2d | 0:972874f31c98 | 279 | if ( arg_val == 0 ) |
iforce2d | 0:972874f31c98 | 280 | { |
iforce2d | 0:972874f31c98 | 281 | /* disable, note: the st7920 has an active high chip select */ |
iforce2d | 0:972874f31c98 | 282 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); |
iforce2d | 0:972874f31c98 | 283 | } |
iforce2d | 0:972874f31c98 | 284 | else |
iforce2d | 0:972874f31c98 | 285 | { |
iforce2d | 0:972874f31c98 | 286 | /* enable */ |
iforce2d | 0:972874f31c98 | 287 | //u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH); |
iforce2d | 0:972874f31c98 | 288 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); |
iforce2d | 0:972874f31c98 | 289 | } |
iforce2d | 0:972874f31c98 | 290 | break; |
iforce2d | 0:972874f31c98 | 291 | |
iforce2d | 0:972874f31c98 | 292 | case U8G_COM_MSG_WRITE_BYTE: |
iforce2d | 0:972874f31c98 | 293 | u8g_com_arduino_st7920_write_byte( u8g->pin_list[U8G_PI_A0_STATE], arg_val); |
iforce2d | 0:972874f31c98 | 294 | //u8g->pin_list[U8G_PI_A0_STATE] = 2; |
iforce2d | 0:972874f31c98 | 295 | //u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val); |
iforce2d | 0:972874f31c98 | 296 | break; |
iforce2d | 0:972874f31c98 | 297 | |
iforce2d | 0:972874f31c98 | 298 | case U8G_COM_MSG_WRITE_SEQ: |
iforce2d | 0:972874f31c98 | 299 | u8g_com_arduino_st7920_write_byte_seq(u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val); |
iforce2d | 0:972874f31c98 | 300 | break; |
iforce2d | 0:972874f31c98 | 301 | |
iforce2d | 0:972874f31c98 | 302 | case U8G_COM_MSG_WRITE_SEQ_P: |
iforce2d | 0:972874f31c98 | 303 | { |
iforce2d | 0:972874f31c98 | 304 | register uint8_t *ptr = arg_ptr; |
iforce2d | 0:972874f31c98 | 305 | while( arg_val > 0 ) |
iforce2d | 0:972874f31c98 | 306 | { |
iforce2d | 0:972874f31c98 | 307 | u8g_com_arduino_st7920_write_byte(u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr) ); |
iforce2d | 0:972874f31c98 | 308 | //u8g->pin_list[U8G_PI_A0_STATE] = 2; |
iforce2d | 0:972874f31c98 | 309 | ptr++; |
iforce2d | 0:972874f31c98 | 310 | arg_val--; |
iforce2d | 0:972874f31c98 | 311 | } |
iforce2d | 0:972874f31c98 | 312 | } |
iforce2d | 0:972874f31c98 | 313 | break; |
iforce2d | 0:972874f31c98 | 314 | |
iforce2d | 0:972874f31c98 | 315 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ |
iforce2d | 0:972874f31c98 | 316 | u8g->pin_list[U8G_PI_A0_STATE] = arg_val; |
iforce2d | 0:972874f31c98 | 317 | break; |
iforce2d | 0:972874f31c98 | 318 | } |
iforce2d | 0:972874f31c98 | 319 | return 1; |
iforce2d | 0:972874f31c98 | 320 | } |
iforce2d | 0:972874f31c98 | 321 | |
iforce2d | 0:972874f31c98 | 322 | #else /* ARDUINO */ |
iforce2d | 0:972874f31c98 | 323 | |
iforce2d | 0:972874f31c98 | 324 | uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) |
iforce2d | 0:972874f31c98 | 325 | { |
iforce2d | 0:972874f31c98 | 326 | return 1; |
iforce2d | 0:972874f31c98 | 327 | } |
iforce2d | 0:972874f31c98 | 328 | |
iforce2d | 0:972874f31c98 | 329 | #endif /* ARDUINO */ |
iforce2d | 0:972874f31c98 | 330 | |
iforce2d | 0:972874f31c98 | 331 |