ADAFRUIT GP9002 VFD Driver supporting grayscale display, requires GFX-Library Note no "invert" function, also fixed timing issue in "begin"
Dependencies: bitreversetable256
Fork of Adafruit-GP9002-Graphic-VFD-Library by
Adafruit_GP9002.cpp@3:0a38cff87d2e, 2016-05-09 (annotated)
- Committer:
- oliverb
- Date:
- Mon May 09 09:29:03 2016 +0000
- Revision:
- 3:0a38cff87d2e
- Parent:
- 2:ecf13e85f0fa
- Child:
- 4:dc3e19dfd45d
Moved the bit reverse LUT out
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oliverb | 0:e760d4cfabe4 | 1 | /*#include <avr/pgmspace.h> |
oliverb | 0:e760d4cfabe4 | 2 | #include <util/delay.h> |
oliverb | 0:e760d4cfabe4 | 3 | #include <stdlib.h>*/ |
oliverb | 0:e760d4cfabe4 | 4 | |
oliverb | 0:e760d4cfabe4 | 5 | #include "Adafruit_GFX.h" |
oliverb | 0:e760d4cfabe4 | 6 | #include "Adafruit_GP9002.h" |
oliverb | 0:e760d4cfabe4 | 7 | #include "glcdfont.c" |
oliverb | 3:0a38cff87d2e | 8 | #include "bitreversetable256.h" |
oliverb | 0:e760d4cfabe4 | 9 | |
oliverb | 0:e760d4cfabe4 | 10 | |
oliverb | 0:e760d4cfabe4 | 11 | |
oliverb | 0:e760d4cfabe4 | 12 | /* |
oliverb | 0:e760d4cfabe4 | 13 | Adafruit_GP9002::Adafruit_GP9002(int8_t SCLK, int8_t MISO, int8_t MOSI, |
oliverb | 0:e760d4cfabe4 | 14 | int8_t CS, int8_t DC) : Adafruit_GFX(128, 64) { |
oliverb | 0:e760d4cfabe4 | 15 | _sclk = SCLK; |
oliverb | 0:e760d4cfabe4 | 16 | _miso = MISO; |
oliverb | 0:e760d4cfabe4 | 17 | _mosi = MOSI; |
oliverb | 0:e760d4cfabe4 | 18 | _cs = CS; |
oliverb | 0:e760d4cfabe4 | 19 | _dc = DC; |
oliverb | 0:e760d4cfabe4 | 20 | hwSPI = false; |
oliverb | 0:e760d4cfabe4 | 21 | } |
oliverb | 0:e760d4cfabe4 | 22 | |
oliverb | 0:e760d4cfabe4 | 23 | Adafruit_GP9002::Adafruit_GP9002(int8_t CS, int8_t DC) : |
oliverb | 0:e760d4cfabe4 | 24 | Adafruit_GFX(128, 64) { |
oliverb | 0:e760d4cfabe4 | 25 | _sclk = -1; |
oliverb | 0:e760d4cfabe4 | 26 | _miso = -1; |
oliverb | 0:e760d4cfabe4 | 27 | _mosi = -1; |
oliverb | 0:e760d4cfabe4 | 28 | _cs = CS; |
oliverb | 0:e760d4cfabe4 | 29 | _dc = DC; |
oliverb | 0:e760d4cfabe4 | 30 | hwSPI = true; |
oliverb | 0:e760d4cfabe4 | 31 | } |
oliverb | 0:e760d4cfabe4 | 32 | */ |
oliverb | 0:e760d4cfabe4 | 33 | Adafruit_GP9002::Adafruit_GP9002(SPI &SPIport, PinName CS, PinName DC): Adafruit_GFX(128, 64), _spi(SPIport), _dc(DC), _cs(CS,1){} ; |
oliverb | 0:e760d4cfabe4 | 34 | |
oliverb | 0:e760d4cfabe4 | 35 | |
oliverb | 0:e760d4cfabe4 | 36 | void Adafruit_GP9002::begin(void) { |
oliverb | 0:e760d4cfabe4 | 37 | // set pin directions |
oliverb | 0:e760d4cfabe4 | 38 | // pinMode(_dc, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 39 | // pinMode(_cs, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 40 | |
oliverb | 0:e760d4cfabe4 | 41 | /* if (! hwSPI) { |
oliverb | 0:e760d4cfabe4 | 42 | pinMode(_mosi, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 43 | pinMode(_miso, INPUT); |
oliverb | 0:e760d4cfabe4 | 44 | pinMode(_sclk, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 45 | |
oliverb | 0:e760d4cfabe4 | 46 | clkport = portOutputRegister(digitalPinToPort(_sclk)); |
oliverb | 0:e760d4cfabe4 | 47 | clkpinmask = digitalPinToBitMask(_sclk); |
oliverb | 0:e760d4cfabe4 | 48 | mosiport = portOutputRegister(digitalPinToPort(_mosi)); |
oliverb | 0:e760d4cfabe4 | 49 | mosipinmask = digitalPinToBitMask(_mosi); |
oliverb | 0:e760d4cfabe4 | 50 | misopin = portInputRegister(digitalPinToPort(_miso)); |
oliverb | 0:e760d4cfabe4 | 51 | misopinmask = digitalPinToBitMask(_miso); |
oliverb | 0:e760d4cfabe4 | 52 | } else { |
oliverb | 0:e760d4cfabe4 | 53 | */ |
oliverb | 0:e760d4cfabe4 | 54 | //SPI.begin(); |
oliverb | 0:e760d4cfabe4 | 55 | // SPI.setClockDivider(SPI_CLOCK_DIV4); |
oliverb | 0:e760d4cfabe4 | 56 | // SPI.setBitOrder(MSBFIRST); |
oliverb | 0:e760d4cfabe4 | 57 | //SPI.setDataMode(SPI_MODE0); |
oliverb | 0:e760d4cfabe4 | 58 | _spi.format(8,3); // I'm sure this is a mode 3 device |
oliverb | 0:e760d4cfabe4 | 59 | _spi.frequency(2000000); // |
oliverb | 0:e760d4cfabe4 | 60 | // } |
oliverb | 0:e760d4cfabe4 | 61 | /* |
oliverb | 0:e760d4cfabe4 | 62 | csport = portOutputRegister(digitalPinToPort(_cs)); |
oliverb | 0:e760d4cfabe4 | 63 | cspinmask = digitalPinToBitMask(_cs); |
oliverb | 0:e760d4cfabe4 | 64 | dcport = portOutputRegister(digitalPinToPort(_dc)); |
oliverb | 0:e760d4cfabe4 | 65 | dcpinmask = digitalPinToBitMask(_dc); |
oliverb | 0:e760d4cfabe4 | 66 | */ |
oliverb | 0:e760d4cfabe4 | 67 | |
oliverb | 1:09dc95ba8711 | 68 | command(GP9002_DISPLAYSOFF); |
oliverb | 1:09dc95ba8711 | 69 | // command(GP9002_DISPLAY1ON); //defer till display clear |
oliverb | 0:e760d4cfabe4 | 70 | command(GP9002_DISPLAY); |
oliverb | 1:09dc95ba8711 | 71 | dataWrite(GP9002_DISPLAY_GRAYSCALE); |
oliverb | 0:e760d4cfabe4 | 72 | command(GP9002_LOWERADDR1); |
oliverb | 0:e760d4cfabe4 | 73 | dataWrite(0x0); |
oliverb | 0:e760d4cfabe4 | 74 | command(GP9002_HIGHERADDR1); |
oliverb | 0:e760d4cfabe4 | 75 | dataWrite(0x0); |
oliverb | 1:09dc95ba8711 | 76 | // command(GP9002_LOWERADDR2); |
oliverb | 1:09dc95ba8711 | 77 | // dataWrite(0x0); |
oliverb | 1:09dc95ba8711 | 78 | // command(GP9002_HIGHERADDR2); |
oliverb | 1:09dc95ba8711 | 79 | // dataWrite(0x4); |
oliverb | 1:09dc95ba8711 | 80 | // command(GP9002_OR); //contradicted by display1on, so no |
oliverb | 0:e760d4cfabe4 | 81 | command(GP9002_CLEARSCREEN); |
oliverb | 1:09dc95ba8711 | 82 | wait_us(500); |
oliverb | 0:e760d4cfabe4 | 83 | command(GP9002_DISPLAY1ON); |
oliverb | 0:e760d4cfabe4 | 84 | |
oliverb | 0:e760d4cfabe4 | 85 | // hold the address so we can read and then write |
oliverb | 0:e760d4cfabe4 | 86 | command(GP9002_ADDRHELD); |
oliverb | 2:ecf13e85f0fa | 87 | addrcache=0; //known because we just set the address |
oliverb | 2:ecf13e85f0fa | 88 | bytecache=0; //known because display cleared |
oliverb | 0:e760d4cfabe4 | 89 | } |
oliverb | 0:e760d4cfabe4 | 90 | |
oliverb | 0:e760d4cfabe4 | 91 | |
oliverb | 0:e760d4cfabe4 | 92 | |
oliverb | 0:e760d4cfabe4 | 93 | // updated high speed drawing! |
oliverb | 0:e760d4cfabe4 | 94 | void Adafruit_GP9002::drawFastVLine(int16_t x, int16_t orig_y, int16_t h, uint16_t color) { |
oliverb | 0:e760d4cfabe4 | 95 | if ((x < 0) || (x >= width()) || (orig_y >= height())) return; |
oliverb | 0:e760d4cfabe4 | 96 | //if ((orig_y+h) >= height()) |
oliverb | 0:e760d4cfabe4 | 97 | // h = height() - orig_y -1; |
oliverb | 0:e760d4cfabe4 | 98 | |
oliverb | 0:e760d4cfabe4 | 99 | //drawLine(x, orig_y, x, orig_y+h, color); return; |
oliverb | 0:e760d4cfabe4 | 100 | |
oliverb | 0:e760d4cfabe4 | 101 | while (h) { |
oliverb | 1:09dc95ba8711 | 102 | if ((h >= 4) && ((orig_y) % 4 == 0)) |
oliverb | 0:e760d4cfabe4 | 103 | break; |
oliverb | 0:e760d4cfabe4 | 104 | drawPixel(x, orig_y, color); |
oliverb | 0:e760d4cfabe4 | 105 | orig_y++; |
oliverb | 0:e760d4cfabe4 | 106 | h--; |
oliverb | 0:e760d4cfabe4 | 107 | } |
oliverb | 0:e760d4cfabe4 | 108 | |
oliverb | 1:09dc95ba8711 | 109 | if (h >= 4) { |
oliverb | 0:e760d4cfabe4 | 110 | // calculate addr |
oliverb | 0:e760d4cfabe4 | 111 | uint16_t addr = 0; |
oliverb | 1:09dc95ba8711 | 112 | addr = x*16; |
oliverb | 0:e760d4cfabe4 | 113 | // uint16_t y = orig_y+h-8; |
oliverb | 0:e760d4cfabe4 | 114 | uint16_t y=orig_y; |
oliverb | 0:e760d4cfabe4 | 115 | // y = 63 - y; //why? |
oliverb | 1:09dc95ba8711 | 116 | addr += y/4; |
oliverb | 0:e760d4cfabe4 | 117 | |
oliverb | 0:e760d4cfabe4 | 118 | // Serial.println(addr, HEX); ///debug line ? |
oliverb | 2:ecf13e85f0fa | 119 | addrcache=-1; //invalidate the cache |
oliverb | 0:e760d4cfabe4 | 120 | command(GP9002_ADDRINCR); |
oliverb | 0:e760d4cfabe4 | 121 | command(GP9002_ADDRL); |
oliverb | 0:e760d4cfabe4 | 122 | dataWrite(addr & 0xFF); |
oliverb | 0:e760d4cfabe4 | 123 | command(GP9002_ADDRH); |
oliverb | 0:e760d4cfabe4 | 124 | dataWrite(addr >> 8); |
oliverb | 0:e760d4cfabe4 | 125 | command(GP9002_DATAWRITE); |
oliverb | 0:e760d4cfabe4 | 126 | |
oliverb | 1:09dc95ba8711 | 127 | while (h >= 4) { |
oliverb | 0:e760d4cfabe4 | 128 | // draw 8 pixels at once! |
oliverb | 0:e760d4cfabe4 | 129 | if (color) |
oliverb | 1:09dc95ba8711 | 130 | dataWrite(0b01010101 * (color & 3)); |
oliverb | 0:e760d4cfabe4 | 131 | else |
oliverb | 0:e760d4cfabe4 | 132 | dataWrite(0x00); |
oliverb | 1:09dc95ba8711 | 133 | h -= 4; |
oliverb | 1:09dc95ba8711 | 134 | orig_y += 4; |
oliverb | 0:e760d4cfabe4 | 135 | } |
oliverb | 0:e760d4cfabe4 | 136 | } |
oliverb | 0:e760d4cfabe4 | 137 | while (h+1) { |
oliverb | 0:e760d4cfabe4 | 138 | drawPixel(x, orig_y-1, color); |
oliverb | 0:e760d4cfabe4 | 139 | orig_y++; |
oliverb | 0:e760d4cfabe4 | 140 | h--; |
oliverb | 0:e760d4cfabe4 | 141 | } |
oliverb | 0:e760d4cfabe4 | 142 | |
oliverb | 0:e760d4cfabe4 | 143 | } |
oliverb | 0:e760d4cfabe4 | 144 | |
oliverb | 0:e760d4cfabe4 | 145 | // the most basic function, set a single pixel |
oliverb | 0:e760d4cfabe4 | 146 | void Adafruit_GP9002::drawPixel(int16_t x, int16_t y, uint16_t color) { |
oliverb | 0:e760d4cfabe4 | 147 | if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) |
oliverb | 0:e760d4cfabe4 | 148 | return; |
oliverb | 0:e760d4cfabe4 | 149 | |
oliverb | 2:ecf13e85f0fa | 150 | //uint8_t p; |
oliverb | 0:e760d4cfabe4 | 151 | |
oliverb | 0:e760d4cfabe4 | 152 | // calculate addr |
oliverb | 0:e760d4cfabe4 | 153 | uint16_t addr = 0; |
oliverb | 1:09dc95ba8711 | 154 | addr = x*16; |
oliverb | 0:e760d4cfabe4 | 155 | // y = 63 - y; //why |
oliverb | 1:09dc95ba8711 | 156 | addr += y/4; |
oliverb | 2:ecf13e85f0fa | 157 | if (addr != addrcache) |
oliverb | 2:ecf13e85f0fa | 158 | { |
oliverb | 2:ecf13e85f0fa | 159 | addrcache=addr; |
oliverb | 2:ecf13e85f0fa | 160 | command(GP9002_ADDRHELD); |
oliverb | 2:ecf13e85f0fa | 161 | command(GP9002_ADDRL); |
oliverb | 2:ecf13e85f0fa | 162 | dataWrite(addr & 0xFF); |
oliverb | 2:ecf13e85f0fa | 163 | command(GP9002_ADDRH); |
oliverb | 2:ecf13e85f0fa | 164 | dataWrite(addr >> 8); |
oliverb | 2:ecf13e85f0fa | 165 | command(GP9002_DATAREAD); |
oliverb | 2:ecf13e85f0fa | 166 | dataRead(); |
oliverb | 2:ecf13e85f0fa | 167 | bytecache = dataRead(); |
oliverb | 2:ecf13e85f0fa | 168 | } |
oliverb | 1:09dc95ba8711 | 169 | y=0xc0>>((y & 3) <<1); |
oliverb | 1:09dc95ba8711 | 170 | color*=0b01010101; |
oliverb | 0:e760d4cfabe4 | 171 | //Serial.println(p, HEX); |
oliverb | 2:ecf13e85f0fa | 172 | bytecache &= ~y; |
oliverb | 0:e760d4cfabe4 | 173 | |
oliverb | 2:ecf13e85f0fa | 174 | bytecache |= color&y; |
oliverb | 1:09dc95ba8711 | 175 | |
oliverb | 0:e760d4cfabe4 | 176 | command(GP9002_DATAWRITE); |
oliverb | 2:ecf13e85f0fa | 177 | dataWrite(bytecache); |
oliverb | 0:e760d4cfabe4 | 178 | } |
oliverb | 0:e760d4cfabe4 | 179 | |
oliverb | 0:e760d4cfabe4 | 180 | |
oliverb | 1:09dc95ba8711 | 181 | /* forbidden |
oliverb | 0:e760d4cfabe4 | 182 | void Adafruit_GP9002::invert(bool i) { |
oliverb | 0:e760d4cfabe4 | 183 | // This is kinda clumsy but it does work |
oliverb | 0:e760d4cfabe4 | 184 | // fill the opposite screen with all on pixels so we can invert! |
oliverb | 0:e760d4cfabe4 | 185 | uint16_t addr = 0x400; |
oliverb | 0:e760d4cfabe4 | 186 | |
oliverb | 0:e760d4cfabe4 | 187 | command(GP9002_ADDRINCR); |
oliverb | 0:e760d4cfabe4 | 188 | command(GP9002_ADDRL); |
oliverb | 0:e760d4cfabe4 | 189 | dataWrite(addr & 0xFF); |
oliverb | 0:e760d4cfabe4 | 190 | command(GP9002_ADDRH); |
oliverb | 0:e760d4cfabe4 | 191 | dataWrite(addr >> 8); |
oliverb | 0:e760d4cfabe4 | 192 | command(GP9002_DATAWRITE); |
oliverb | 0:e760d4cfabe4 | 193 | |
oliverb | 0:e760d4cfabe4 | 194 | if (i) { |
oliverb | 0:e760d4cfabe4 | 195 | while (addr < 0x0800) { |
oliverb | 0:e760d4cfabe4 | 196 | dataWrite(0xFF); |
oliverb | 0:e760d4cfabe4 | 197 | addr++; |
oliverb | 0:e760d4cfabe4 | 198 | } |
oliverb | 0:e760d4cfabe4 | 199 | command(GP9002_XOR); |
oliverb | 0:e760d4cfabe4 | 200 | } else { |
oliverb | 0:e760d4cfabe4 | 201 | while (addr < 0x0800) { |
oliverb | 0:e760d4cfabe4 | 202 | dataWrite(0x00); |
oliverb | 0:e760d4cfabe4 | 203 | addr++; |
oliverb | 0:e760d4cfabe4 | 204 | } |
oliverb | 0:e760d4cfabe4 | 205 | command(GP9002_OR); |
oliverb | 0:e760d4cfabe4 | 206 | } |
oliverb | 0:e760d4cfabe4 | 207 | command(GP9002_ADDRHELD); |
oliverb | 0:e760d4cfabe4 | 208 | |
oliverb | 0:e760d4cfabe4 | 209 | } |
oliverb | 1:09dc95ba8711 | 210 | */ |
oliverb | 0:e760d4cfabe4 | 211 | /* |
oliverb | 0:e760d4cfabe4 | 212 | void Adafruit_GP9002::slowSPIwrite(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 213 | for (uint8_t i=0; i<8; i++) { |
oliverb | 0:e760d4cfabe4 | 214 | digitalWrite(_sclk, LOW); |
oliverb | 0:e760d4cfabe4 | 215 | if (d & _BV(i)) { |
oliverb | 0:e760d4cfabe4 | 216 | digitalWrite(_mosi, HIGH); |
oliverb | 0:e760d4cfabe4 | 217 | } else { |
oliverb | 0:e760d4cfabe4 | 218 | digitalWrite(_mosi, LOW); |
oliverb | 0:e760d4cfabe4 | 219 | } |
oliverb | 0:e760d4cfabe4 | 220 | digitalWrite(_sclk, HIGH); |
oliverb | 0:e760d4cfabe4 | 221 | } |
oliverb | 0:e760d4cfabe4 | 222 | } |
oliverb | 0:e760d4cfabe4 | 223 | */ |
oliverb | 0:e760d4cfabe4 | 224 | /* |
oliverb | 0:e760d4cfabe4 | 225 | inline void Adafruit_GP9002::fastSPIwrite(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 226 | if (hwSPI) { |
oliverb | 0:e760d4cfabe4 | 227 | SPDR = d; |
oliverb | 0:e760d4cfabe4 | 228 | while(!(SPSR & _BV(SPIF))); |
oliverb | 0:e760d4cfabe4 | 229 | return; |
oliverb | 0:e760d4cfabe4 | 230 | } |
oliverb | 0:e760d4cfabe4 | 231 | for(uint8_t bit = 0x1; bit != 0x00; bit <<= 1) { |
oliverb | 0:e760d4cfabe4 | 232 | *clkport &= ~clkpinmask; |
oliverb | 0:e760d4cfabe4 | 233 | if(d & bit) *mosiport |= mosipinmask; |
oliverb | 0:e760d4cfabe4 | 234 | else *mosiport &= ~mosipinmask; |
oliverb | 0:e760d4cfabe4 | 235 | *clkport |= clkpinmask; |
oliverb | 0:e760d4cfabe4 | 236 | } |
oliverb | 0:e760d4cfabe4 | 237 | } |
oliverb | 0:e760d4cfabe4 | 238 | */ |
oliverb | 0:e760d4cfabe4 | 239 | /* |
oliverb | 0:e760d4cfabe4 | 240 | uint8_t Adafruit_GP9002::slowSPIread(void) { |
oliverb | 0:e760d4cfabe4 | 241 | uint8_t reply = 0; |
oliverb | 0:e760d4cfabe4 | 242 | for (uint8_t i=0; i<8; i++) { |
oliverb | 0:e760d4cfabe4 | 243 | digitalWrite(_sclk, LOW); |
oliverb | 0:e760d4cfabe4 | 244 | |
oliverb | 0:e760d4cfabe4 | 245 | digitalWrite(_sclk, HIGH); |
oliverb | 0:e760d4cfabe4 | 246 | if (digitalRead(_miso)) |
oliverb | 0:e760d4cfabe4 | 247 | reply |= _BV(i); |
oliverb | 0:e760d4cfabe4 | 248 | } |
oliverb | 0:e760d4cfabe4 | 249 | return reply; |
oliverb | 0:e760d4cfabe4 | 250 | } |
oliverb | 0:e760d4cfabe4 | 251 | |
oliverb | 0:e760d4cfabe4 | 252 | inline uint8_t Adafruit_GP9002::fastSPIread(void) { |
oliverb | 0:e760d4cfabe4 | 253 | uint8_t reply = 0; |
oliverb | 0:e760d4cfabe4 | 254 | for (uint8_t i=0; i<8; i++) { |
oliverb | 0:e760d4cfabe4 | 255 | *clkport &= ~clkpinmask; |
oliverb | 0:e760d4cfabe4 | 256 | |
oliverb | 0:e760d4cfabe4 | 257 | *clkport |= clkpinmask; |
oliverb | 0:e760d4cfabe4 | 258 | if ((*misopin) & misopinmask) |
oliverb | 0:e760d4cfabe4 | 259 | reply |= _BV(i); |
oliverb | 0:e760d4cfabe4 | 260 | } |
oliverb | 0:e760d4cfabe4 | 261 | return reply; |
oliverb | 0:e760d4cfabe4 | 262 | } |
oliverb | 0:e760d4cfabe4 | 263 | */ |
oliverb | 0:e760d4cfabe4 | 264 | |
oliverb | 0:e760d4cfabe4 | 265 | void Adafruit_GP9002::command(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 266 | /* |
oliverb | 0:e760d4cfabe4 | 267 | *dcport |= dcpinmask; |
oliverb | 0:e760d4cfabe4 | 268 | *csport &= ~cspinmask; |
oliverb | 0:e760d4cfabe4 | 269 | fastSPIwrite(d); |
oliverb | 0:e760d4cfabe4 | 270 | *csport |= cspinmask; |
oliverb | 0:e760d4cfabe4 | 271 | delayMicroseconds(1); // should be 400ns actually |
oliverb | 0:e760d4cfabe4 | 272 | */ |
oliverb | 0:e760d4cfabe4 | 273 | _dc=1; |
oliverb | 0:e760d4cfabe4 | 274 | _cs=0; |
oliverb | 0:e760d4cfabe4 | 275 | _spi.write(BitReverseTable256[d]); |
oliverb | 0:e760d4cfabe4 | 276 | _cs=1; |
oliverb | 0:e760d4cfabe4 | 277 | wait_us(1); |
oliverb | 0:e760d4cfabe4 | 278 | } |
oliverb | 0:e760d4cfabe4 | 279 | |
oliverb | 0:e760d4cfabe4 | 280 | inline void Adafruit_GP9002::dataWrite(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 281 | /* |
oliverb | 0:e760d4cfabe4 | 282 | *dcport &= ~dcpinmask; |
oliverb | 0:e760d4cfabe4 | 283 | *csport &= ~cspinmask; |
oliverb | 0:e760d4cfabe4 | 284 | |
oliverb | 0:e760d4cfabe4 | 285 | fastSPIwrite(d); |
oliverb | 0:e760d4cfabe4 | 286 | |
oliverb | 0:e760d4cfabe4 | 287 | *csport |= cspinmask; |
oliverb | 0:e760d4cfabe4 | 288 | delayMicroseconds(1); // should be 600ns actually |
oliverb | 0:e760d4cfabe4 | 289 | */ |
oliverb | 0:e760d4cfabe4 | 290 | _dc=0; |
oliverb | 0:e760d4cfabe4 | 291 | _cs=0; |
oliverb | 0:e760d4cfabe4 | 292 | _spi.write(BitReverseTable256[d]); |
oliverb | 0:e760d4cfabe4 | 293 | _cs=1; |
oliverb | 0:e760d4cfabe4 | 294 | wait_us(1); |
oliverb | 0:e760d4cfabe4 | 295 | } |
oliverb | 0:e760d4cfabe4 | 296 | |
oliverb | 0:e760d4cfabe4 | 297 | inline uint8_t Adafruit_GP9002::dataRead() { |
oliverb | 0:e760d4cfabe4 | 298 | uint8_t r; |
oliverb | 0:e760d4cfabe4 | 299 | /* |
oliverb | 0:e760d4cfabe4 | 300 | *dcport &= ~dcpinmask; |
oliverb | 0:e760d4cfabe4 | 301 | *csport &= ~cspinmask; |
oliverb | 0:e760d4cfabe4 | 302 | |
oliverb | 0:e760d4cfabe4 | 303 | r = fastSPIread(); |
oliverb | 0:e760d4cfabe4 | 304 | |
oliverb | 0:e760d4cfabe4 | 305 | *csport |= cspinmask; |
oliverb | 0:e760d4cfabe4 | 306 | delayMicroseconds(1); |
oliverb | 0:e760d4cfabe4 | 307 | */ |
oliverb | 0:e760d4cfabe4 | 308 | |
oliverb | 0:e760d4cfabe4 | 309 | _dc=0; |
oliverb | 0:e760d4cfabe4 | 310 | _cs=0; |
oliverb | 0:e760d4cfabe4 | 311 | r=BitReverseTable256[_spi.write(0)&0xFF]; |
oliverb | 0:e760d4cfabe4 | 312 | _cs=1; |
oliverb | 0:e760d4cfabe4 | 313 | wait_us(1); |
oliverb | 0:e760d4cfabe4 | 314 | |
oliverb | 0:e760d4cfabe4 | 315 | |
oliverb | 0:e760d4cfabe4 | 316 | return r; |
oliverb | 0:e760d4cfabe4 | 317 | } |
oliverb | 0:e760d4cfabe4 | 318 | |
oliverb | 0:e760d4cfabe4 | 319 | void Adafruit_GP9002::setBrightness(uint8_t val) { |
oliverb | 0:e760d4cfabe4 | 320 | |
oliverb | 0:e760d4cfabe4 | 321 | } |
oliverb | 0:e760d4cfabe4 | 322 | |
oliverb | 0:e760d4cfabe4 | 323 | // clear everything |
oliverb | 0:e760d4cfabe4 | 324 | void Adafruit_GP9002::clearDisplay(void) { |
oliverb | 0:e760d4cfabe4 | 325 | command(GP9002_CLEARSCREEN); |
oliverb | 0:e760d4cfabe4 | 326 | |
oliverb | 1:09dc95ba8711 | 327 | wait_us(500); |
oliverb | 0:e760d4cfabe4 | 328 | } |
oliverb | 0:e760d4cfabe4 | 329 | |
oliverb | 0:e760d4cfabe4 | 330 | void Adafruit_GP9002::displayOff(void) { |
oliverb | 0:e760d4cfabe4 | 331 | command(GP9002_DISPLAYSOFF); |
oliverb | 0:e760d4cfabe4 | 332 | } |
oliverb | 0:e760d4cfabe4 | 333 | void Adafruit_GP9002::displayOn(void) { |
oliverb | 0:e760d4cfabe4 | 334 | command(GP9002_DISPLAY1ON); |
oliverb | 0:e760d4cfabe4 | 335 | } |
oliverb | 0:e760d4cfabe4 | 336 | |
oliverb | 0:e760d4cfabe4 | 337 |