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@0:e760d4cfabe4, 2016-05-07 (annotated)
- Committer:
- oliverb
- Date:
- Sat May 07 12:53:09 2016 +0000
- Revision:
- 0:e760d4cfabe4
- Child:
- 1:09dc95ba8711
Converted to Library, moved the examples 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 | 0:e760d4cfabe4 | 8 | |
oliverb | 0:e760d4cfabe4 | 9 | extern const unsigned char BitReverseTable256[] = |
oliverb | 0:e760d4cfabe4 | 10 | { |
oliverb | 0:e760d4cfabe4 | 11 | 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, |
oliverb | 0:e760d4cfabe4 | 12 | 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, |
oliverb | 0:e760d4cfabe4 | 13 | 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, |
oliverb | 0:e760d4cfabe4 | 14 | 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, |
oliverb | 0:e760d4cfabe4 | 15 | 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, |
oliverb | 0:e760d4cfabe4 | 16 | 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, |
oliverb | 0:e760d4cfabe4 | 17 | 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, |
oliverb | 0:e760d4cfabe4 | 18 | 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, |
oliverb | 0:e760d4cfabe4 | 19 | 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, |
oliverb | 0:e760d4cfabe4 | 20 | 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, |
oliverb | 0:e760d4cfabe4 | 21 | 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, |
oliverb | 0:e760d4cfabe4 | 22 | 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, |
oliverb | 0:e760d4cfabe4 | 23 | 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, |
oliverb | 0:e760d4cfabe4 | 24 | 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, |
oliverb | 0:e760d4cfabe4 | 25 | 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, |
oliverb | 0:e760d4cfabe4 | 26 | 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF |
oliverb | 0:e760d4cfabe4 | 27 | }; |
oliverb | 0:e760d4cfabe4 | 28 | |
oliverb | 0:e760d4cfabe4 | 29 | |
oliverb | 0:e760d4cfabe4 | 30 | /* |
oliverb | 0:e760d4cfabe4 | 31 | Adafruit_GP9002::Adafruit_GP9002(int8_t SCLK, int8_t MISO, int8_t MOSI, |
oliverb | 0:e760d4cfabe4 | 32 | int8_t CS, int8_t DC) : Adafruit_GFX(128, 64) { |
oliverb | 0:e760d4cfabe4 | 33 | _sclk = SCLK; |
oliverb | 0:e760d4cfabe4 | 34 | _miso = MISO; |
oliverb | 0:e760d4cfabe4 | 35 | _mosi = MOSI; |
oliverb | 0:e760d4cfabe4 | 36 | _cs = CS; |
oliverb | 0:e760d4cfabe4 | 37 | _dc = DC; |
oliverb | 0:e760d4cfabe4 | 38 | hwSPI = false; |
oliverb | 0:e760d4cfabe4 | 39 | } |
oliverb | 0:e760d4cfabe4 | 40 | |
oliverb | 0:e760d4cfabe4 | 41 | Adafruit_GP9002::Adafruit_GP9002(int8_t CS, int8_t DC) : |
oliverb | 0:e760d4cfabe4 | 42 | Adafruit_GFX(128, 64) { |
oliverb | 0:e760d4cfabe4 | 43 | _sclk = -1; |
oliverb | 0:e760d4cfabe4 | 44 | _miso = -1; |
oliverb | 0:e760d4cfabe4 | 45 | _mosi = -1; |
oliverb | 0:e760d4cfabe4 | 46 | _cs = CS; |
oliverb | 0:e760d4cfabe4 | 47 | _dc = DC; |
oliverb | 0:e760d4cfabe4 | 48 | hwSPI = true; |
oliverb | 0:e760d4cfabe4 | 49 | } |
oliverb | 0:e760d4cfabe4 | 50 | */ |
oliverb | 0:e760d4cfabe4 | 51 | Adafruit_GP9002::Adafruit_GP9002(SPI &SPIport, PinName CS, PinName DC): Adafruit_GFX(128, 64), _spi(SPIport), _dc(DC), _cs(CS,1){} ; |
oliverb | 0:e760d4cfabe4 | 52 | |
oliverb | 0:e760d4cfabe4 | 53 | |
oliverb | 0:e760d4cfabe4 | 54 | void Adafruit_GP9002::begin(void) { |
oliverb | 0:e760d4cfabe4 | 55 | // set pin directions |
oliverb | 0:e760d4cfabe4 | 56 | // pinMode(_dc, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 57 | // pinMode(_cs, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 58 | |
oliverb | 0:e760d4cfabe4 | 59 | /* if (! hwSPI) { |
oliverb | 0:e760d4cfabe4 | 60 | pinMode(_mosi, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 61 | pinMode(_miso, INPUT); |
oliverb | 0:e760d4cfabe4 | 62 | pinMode(_sclk, OUTPUT); |
oliverb | 0:e760d4cfabe4 | 63 | |
oliverb | 0:e760d4cfabe4 | 64 | clkport = portOutputRegister(digitalPinToPort(_sclk)); |
oliverb | 0:e760d4cfabe4 | 65 | clkpinmask = digitalPinToBitMask(_sclk); |
oliverb | 0:e760d4cfabe4 | 66 | mosiport = portOutputRegister(digitalPinToPort(_mosi)); |
oliverb | 0:e760d4cfabe4 | 67 | mosipinmask = digitalPinToBitMask(_mosi); |
oliverb | 0:e760d4cfabe4 | 68 | misopin = portInputRegister(digitalPinToPort(_miso)); |
oliverb | 0:e760d4cfabe4 | 69 | misopinmask = digitalPinToBitMask(_miso); |
oliverb | 0:e760d4cfabe4 | 70 | } else { |
oliverb | 0:e760d4cfabe4 | 71 | */ |
oliverb | 0:e760d4cfabe4 | 72 | //SPI.begin(); |
oliverb | 0:e760d4cfabe4 | 73 | // SPI.setClockDivider(SPI_CLOCK_DIV4); |
oliverb | 0:e760d4cfabe4 | 74 | // SPI.setBitOrder(MSBFIRST); |
oliverb | 0:e760d4cfabe4 | 75 | //SPI.setDataMode(SPI_MODE0); |
oliverb | 0:e760d4cfabe4 | 76 | _spi.format(8,3); // I'm sure this is a mode 3 device |
oliverb | 0:e760d4cfabe4 | 77 | _spi.frequency(2000000); // |
oliverb | 0:e760d4cfabe4 | 78 | // } |
oliverb | 0:e760d4cfabe4 | 79 | /* |
oliverb | 0:e760d4cfabe4 | 80 | csport = portOutputRegister(digitalPinToPort(_cs)); |
oliverb | 0:e760d4cfabe4 | 81 | cspinmask = digitalPinToBitMask(_cs); |
oliverb | 0:e760d4cfabe4 | 82 | dcport = portOutputRegister(digitalPinToPort(_dc)); |
oliverb | 0:e760d4cfabe4 | 83 | dcpinmask = digitalPinToBitMask(_dc); |
oliverb | 0:e760d4cfabe4 | 84 | */ |
oliverb | 0:e760d4cfabe4 | 85 | |
oliverb | 0:e760d4cfabe4 | 86 | command(GP9002_DISPLAY); |
oliverb | 0:e760d4cfabe4 | 87 | dataWrite(GP9002_DISPLAY_MONOCHROME); |
oliverb | 0:e760d4cfabe4 | 88 | command(GP9002_LOWERADDR1); |
oliverb | 0:e760d4cfabe4 | 89 | dataWrite(0x0); |
oliverb | 0:e760d4cfabe4 | 90 | command(GP9002_HIGHERADDR1); |
oliverb | 0:e760d4cfabe4 | 91 | dataWrite(0x0); |
oliverb | 0:e760d4cfabe4 | 92 | command(GP9002_LOWERADDR2); |
oliverb | 0:e760d4cfabe4 | 93 | dataWrite(0x0); |
oliverb | 0:e760d4cfabe4 | 94 | command(GP9002_HIGHERADDR2); |
oliverb | 0:e760d4cfabe4 | 95 | dataWrite(0x4); |
oliverb | 0:e760d4cfabe4 | 96 | command(GP9002_OR); |
oliverb | 0:e760d4cfabe4 | 97 | command(GP9002_CLEARSCREEN); |
oliverb | 0:e760d4cfabe4 | 98 | command(GP9002_DISPLAY1ON); |
oliverb | 0:e760d4cfabe4 | 99 | |
oliverb | 0:e760d4cfabe4 | 100 | // hold the address so we can read and then write |
oliverb | 0:e760d4cfabe4 | 101 | command(GP9002_ADDRHELD); |
oliverb | 0:e760d4cfabe4 | 102 | } |
oliverb | 0:e760d4cfabe4 | 103 | |
oliverb | 0:e760d4cfabe4 | 104 | |
oliverb | 0:e760d4cfabe4 | 105 | |
oliverb | 0:e760d4cfabe4 | 106 | // updated high speed drawing! |
oliverb | 0:e760d4cfabe4 | 107 | void Adafruit_GP9002::drawFastVLine(int16_t x, int16_t orig_y, int16_t h, uint16_t color) { |
oliverb | 0:e760d4cfabe4 | 108 | if ((x < 0) || (x >= width()) || (orig_y >= height())) return; |
oliverb | 0:e760d4cfabe4 | 109 | //if ((orig_y+h) >= height()) |
oliverb | 0:e760d4cfabe4 | 110 | // h = height() - orig_y -1; |
oliverb | 0:e760d4cfabe4 | 111 | |
oliverb | 0:e760d4cfabe4 | 112 | //drawLine(x, orig_y, x, orig_y+h, color); return; |
oliverb | 0:e760d4cfabe4 | 113 | |
oliverb | 0:e760d4cfabe4 | 114 | while (h) { |
oliverb | 0:e760d4cfabe4 | 115 | if ((h >= 8) && ((orig_y) % 8 == 0)) |
oliverb | 0:e760d4cfabe4 | 116 | break; |
oliverb | 0:e760d4cfabe4 | 117 | drawPixel(x, orig_y, color); |
oliverb | 0:e760d4cfabe4 | 118 | orig_y++; |
oliverb | 0:e760d4cfabe4 | 119 | h--; |
oliverb | 0:e760d4cfabe4 | 120 | } |
oliverb | 0:e760d4cfabe4 | 121 | |
oliverb | 0:e760d4cfabe4 | 122 | if (h >= 8) { |
oliverb | 0:e760d4cfabe4 | 123 | // calculate addr |
oliverb | 0:e760d4cfabe4 | 124 | uint16_t addr = 0; |
oliverb | 0:e760d4cfabe4 | 125 | addr = x*8; |
oliverb | 0:e760d4cfabe4 | 126 | // uint16_t y = orig_y+h-8; |
oliverb | 0:e760d4cfabe4 | 127 | uint16_t y=orig_y; |
oliverb | 0:e760d4cfabe4 | 128 | // y = 63 - y; //why? |
oliverb | 0:e760d4cfabe4 | 129 | addr += y/8; |
oliverb | 0:e760d4cfabe4 | 130 | |
oliverb | 0:e760d4cfabe4 | 131 | // Serial.println(addr, HEX); ///debug line ? |
oliverb | 0:e760d4cfabe4 | 132 | command(GP9002_ADDRINCR); |
oliverb | 0:e760d4cfabe4 | 133 | command(GP9002_ADDRL); |
oliverb | 0:e760d4cfabe4 | 134 | dataWrite(addr & 0xFF); |
oliverb | 0:e760d4cfabe4 | 135 | command(GP9002_ADDRH); |
oliverb | 0:e760d4cfabe4 | 136 | dataWrite(addr >> 8); |
oliverb | 0:e760d4cfabe4 | 137 | command(GP9002_DATAWRITE); |
oliverb | 0:e760d4cfabe4 | 138 | |
oliverb | 0:e760d4cfabe4 | 139 | while (h >= 8) { |
oliverb | 0:e760d4cfabe4 | 140 | // draw 8 pixels at once! |
oliverb | 0:e760d4cfabe4 | 141 | if (color) |
oliverb | 0:e760d4cfabe4 | 142 | dataWrite(0xFF); |
oliverb | 0:e760d4cfabe4 | 143 | else |
oliverb | 0:e760d4cfabe4 | 144 | dataWrite(0x00); |
oliverb | 0:e760d4cfabe4 | 145 | h -= 8; |
oliverb | 0:e760d4cfabe4 | 146 | orig_y += 8; |
oliverb | 0:e760d4cfabe4 | 147 | } |
oliverb | 0:e760d4cfabe4 | 148 | } |
oliverb | 0:e760d4cfabe4 | 149 | while (h+1) { |
oliverb | 0:e760d4cfabe4 | 150 | drawPixel(x, orig_y-1, color); |
oliverb | 0:e760d4cfabe4 | 151 | orig_y++; |
oliverb | 0:e760d4cfabe4 | 152 | h--; |
oliverb | 0:e760d4cfabe4 | 153 | } |
oliverb | 0:e760d4cfabe4 | 154 | |
oliverb | 0:e760d4cfabe4 | 155 | } |
oliverb | 0:e760d4cfabe4 | 156 | |
oliverb | 0:e760d4cfabe4 | 157 | // the most basic function, set a single pixel |
oliverb | 0:e760d4cfabe4 | 158 | void Adafruit_GP9002::drawPixel(int16_t x, int16_t y, uint16_t color) { |
oliverb | 0:e760d4cfabe4 | 159 | if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) |
oliverb | 0:e760d4cfabe4 | 160 | return; |
oliverb | 0:e760d4cfabe4 | 161 | |
oliverb | 0:e760d4cfabe4 | 162 | uint8_t p; |
oliverb | 0:e760d4cfabe4 | 163 | |
oliverb | 0:e760d4cfabe4 | 164 | // calculate addr |
oliverb | 0:e760d4cfabe4 | 165 | uint16_t addr = 0; |
oliverb | 0:e760d4cfabe4 | 166 | addr = x*8; |
oliverb | 0:e760d4cfabe4 | 167 | // y = 63 - y; //why |
oliverb | 0:e760d4cfabe4 | 168 | addr += y/8; |
oliverb | 0:e760d4cfabe4 | 169 | |
oliverb | 0:e760d4cfabe4 | 170 | command(GP9002_ADDRHELD); |
oliverb | 0:e760d4cfabe4 | 171 | command(GP9002_ADDRL); |
oliverb | 0:e760d4cfabe4 | 172 | dataWrite(addr & 0xFF); |
oliverb | 0:e760d4cfabe4 | 173 | command(GP9002_ADDRH); |
oliverb | 0:e760d4cfabe4 | 174 | dataWrite(addr >> 8); |
oliverb | 0:e760d4cfabe4 | 175 | command(GP9002_DATAREAD); |
oliverb | 0:e760d4cfabe4 | 176 | dataRead(); |
oliverb | 0:e760d4cfabe4 | 177 | p = dataRead(); |
oliverb | 0:e760d4cfabe4 | 178 | |
oliverb | 0:e760d4cfabe4 | 179 | //Serial.println(p, HEX); |
oliverb | 0:e760d4cfabe4 | 180 | |
oliverb | 0:e760d4cfabe4 | 181 | if (color) |
oliverb | 0:e760d4cfabe4 | 182 | p |= (1 << (7-(y % 8))); |
oliverb | 0:e760d4cfabe4 | 183 | else |
oliverb | 0:e760d4cfabe4 | 184 | p &= ~(1 << (7-(y % 8))); |
oliverb | 0:e760d4cfabe4 | 185 | command(GP9002_DATAWRITE); |
oliverb | 0:e760d4cfabe4 | 186 | dataWrite(p); |
oliverb | 0:e760d4cfabe4 | 187 | } |
oliverb | 0:e760d4cfabe4 | 188 | |
oliverb | 0:e760d4cfabe4 | 189 | |
oliverb | 0:e760d4cfabe4 | 190 | |
oliverb | 0:e760d4cfabe4 | 191 | void Adafruit_GP9002::invert(bool i) { |
oliverb | 0:e760d4cfabe4 | 192 | // This is kinda clumsy but it does work |
oliverb | 0:e760d4cfabe4 | 193 | // fill the opposite screen with all on pixels so we can invert! |
oliverb | 0:e760d4cfabe4 | 194 | uint16_t addr = 0x400; |
oliverb | 0:e760d4cfabe4 | 195 | |
oliverb | 0:e760d4cfabe4 | 196 | command(GP9002_ADDRINCR); |
oliverb | 0:e760d4cfabe4 | 197 | command(GP9002_ADDRL); |
oliverb | 0:e760d4cfabe4 | 198 | dataWrite(addr & 0xFF); |
oliverb | 0:e760d4cfabe4 | 199 | command(GP9002_ADDRH); |
oliverb | 0:e760d4cfabe4 | 200 | dataWrite(addr >> 8); |
oliverb | 0:e760d4cfabe4 | 201 | command(GP9002_DATAWRITE); |
oliverb | 0:e760d4cfabe4 | 202 | |
oliverb | 0:e760d4cfabe4 | 203 | if (i) { |
oliverb | 0:e760d4cfabe4 | 204 | while (addr < 0x0800) { |
oliverb | 0:e760d4cfabe4 | 205 | dataWrite(0xFF); |
oliverb | 0:e760d4cfabe4 | 206 | addr++; |
oliverb | 0:e760d4cfabe4 | 207 | } |
oliverb | 0:e760d4cfabe4 | 208 | command(GP9002_XOR); |
oliverb | 0:e760d4cfabe4 | 209 | } else { |
oliverb | 0:e760d4cfabe4 | 210 | while (addr < 0x0800) { |
oliverb | 0:e760d4cfabe4 | 211 | dataWrite(0x00); |
oliverb | 0:e760d4cfabe4 | 212 | addr++; |
oliverb | 0:e760d4cfabe4 | 213 | } |
oliverb | 0:e760d4cfabe4 | 214 | command(GP9002_OR); |
oliverb | 0:e760d4cfabe4 | 215 | } |
oliverb | 0:e760d4cfabe4 | 216 | command(GP9002_ADDRHELD); |
oliverb | 0:e760d4cfabe4 | 217 | |
oliverb | 0:e760d4cfabe4 | 218 | } |
oliverb | 0:e760d4cfabe4 | 219 | /* |
oliverb | 0:e760d4cfabe4 | 220 | void Adafruit_GP9002::slowSPIwrite(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 221 | for (uint8_t i=0; i<8; i++) { |
oliverb | 0:e760d4cfabe4 | 222 | digitalWrite(_sclk, LOW); |
oliverb | 0:e760d4cfabe4 | 223 | if (d & _BV(i)) { |
oliverb | 0:e760d4cfabe4 | 224 | digitalWrite(_mosi, HIGH); |
oliverb | 0:e760d4cfabe4 | 225 | } else { |
oliverb | 0:e760d4cfabe4 | 226 | digitalWrite(_mosi, LOW); |
oliverb | 0:e760d4cfabe4 | 227 | } |
oliverb | 0:e760d4cfabe4 | 228 | digitalWrite(_sclk, HIGH); |
oliverb | 0:e760d4cfabe4 | 229 | } |
oliverb | 0:e760d4cfabe4 | 230 | } |
oliverb | 0:e760d4cfabe4 | 231 | */ |
oliverb | 0:e760d4cfabe4 | 232 | /* |
oliverb | 0:e760d4cfabe4 | 233 | inline void Adafruit_GP9002::fastSPIwrite(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 234 | if (hwSPI) { |
oliverb | 0:e760d4cfabe4 | 235 | SPDR = d; |
oliverb | 0:e760d4cfabe4 | 236 | while(!(SPSR & _BV(SPIF))); |
oliverb | 0:e760d4cfabe4 | 237 | return; |
oliverb | 0:e760d4cfabe4 | 238 | } |
oliverb | 0:e760d4cfabe4 | 239 | for(uint8_t bit = 0x1; bit != 0x00; bit <<= 1) { |
oliverb | 0:e760d4cfabe4 | 240 | *clkport &= ~clkpinmask; |
oliverb | 0:e760d4cfabe4 | 241 | if(d & bit) *mosiport |= mosipinmask; |
oliverb | 0:e760d4cfabe4 | 242 | else *mosiport &= ~mosipinmask; |
oliverb | 0:e760d4cfabe4 | 243 | *clkport |= clkpinmask; |
oliverb | 0:e760d4cfabe4 | 244 | } |
oliverb | 0:e760d4cfabe4 | 245 | } |
oliverb | 0:e760d4cfabe4 | 246 | */ |
oliverb | 0:e760d4cfabe4 | 247 | /* |
oliverb | 0:e760d4cfabe4 | 248 | uint8_t Adafruit_GP9002::slowSPIread(void) { |
oliverb | 0:e760d4cfabe4 | 249 | uint8_t reply = 0; |
oliverb | 0:e760d4cfabe4 | 250 | for (uint8_t i=0; i<8; i++) { |
oliverb | 0:e760d4cfabe4 | 251 | digitalWrite(_sclk, LOW); |
oliverb | 0:e760d4cfabe4 | 252 | |
oliverb | 0:e760d4cfabe4 | 253 | digitalWrite(_sclk, HIGH); |
oliverb | 0:e760d4cfabe4 | 254 | if (digitalRead(_miso)) |
oliverb | 0:e760d4cfabe4 | 255 | reply |= _BV(i); |
oliverb | 0:e760d4cfabe4 | 256 | } |
oliverb | 0:e760d4cfabe4 | 257 | return reply; |
oliverb | 0:e760d4cfabe4 | 258 | } |
oliverb | 0:e760d4cfabe4 | 259 | |
oliverb | 0:e760d4cfabe4 | 260 | inline uint8_t Adafruit_GP9002::fastSPIread(void) { |
oliverb | 0:e760d4cfabe4 | 261 | uint8_t reply = 0; |
oliverb | 0:e760d4cfabe4 | 262 | for (uint8_t i=0; i<8; i++) { |
oliverb | 0:e760d4cfabe4 | 263 | *clkport &= ~clkpinmask; |
oliverb | 0:e760d4cfabe4 | 264 | |
oliverb | 0:e760d4cfabe4 | 265 | *clkport |= clkpinmask; |
oliverb | 0:e760d4cfabe4 | 266 | if ((*misopin) & misopinmask) |
oliverb | 0:e760d4cfabe4 | 267 | reply |= _BV(i); |
oliverb | 0:e760d4cfabe4 | 268 | } |
oliverb | 0:e760d4cfabe4 | 269 | return reply; |
oliverb | 0:e760d4cfabe4 | 270 | } |
oliverb | 0:e760d4cfabe4 | 271 | */ |
oliverb | 0:e760d4cfabe4 | 272 | |
oliverb | 0:e760d4cfabe4 | 273 | void Adafruit_GP9002::command(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 274 | /* |
oliverb | 0:e760d4cfabe4 | 275 | *dcport |= dcpinmask; |
oliverb | 0:e760d4cfabe4 | 276 | *csport &= ~cspinmask; |
oliverb | 0:e760d4cfabe4 | 277 | fastSPIwrite(d); |
oliverb | 0:e760d4cfabe4 | 278 | *csport |= cspinmask; |
oliverb | 0:e760d4cfabe4 | 279 | delayMicroseconds(1); // should be 400ns actually |
oliverb | 0:e760d4cfabe4 | 280 | */ |
oliverb | 0:e760d4cfabe4 | 281 | _dc=1; |
oliverb | 0:e760d4cfabe4 | 282 | _cs=0; |
oliverb | 0:e760d4cfabe4 | 283 | _spi.write(BitReverseTable256[d]); |
oliverb | 0:e760d4cfabe4 | 284 | _cs=1; |
oliverb | 0:e760d4cfabe4 | 285 | wait_us(1); |
oliverb | 0:e760d4cfabe4 | 286 | } |
oliverb | 0:e760d4cfabe4 | 287 | |
oliverb | 0:e760d4cfabe4 | 288 | inline void Adafruit_GP9002::dataWrite(uint8_t d) { |
oliverb | 0:e760d4cfabe4 | 289 | /* |
oliverb | 0:e760d4cfabe4 | 290 | *dcport &= ~dcpinmask; |
oliverb | 0:e760d4cfabe4 | 291 | *csport &= ~cspinmask; |
oliverb | 0:e760d4cfabe4 | 292 | |
oliverb | 0:e760d4cfabe4 | 293 | fastSPIwrite(d); |
oliverb | 0:e760d4cfabe4 | 294 | |
oliverb | 0:e760d4cfabe4 | 295 | *csport |= cspinmask; |
oliverb | 0:e760d4cfabe4 | 296 | delayMicroseconds(1); // should be 600ns actually |
oliverb | 0:e760d4cfabe4 | 297 | */ |
oliverb | 0:e760d4cfabe4 | 298 | _dc=0; |
oliverb | 0:e760d4cfabe4 | 299 | _cs=0; |
oliverb | 0:e760d4cfabe4 | 300 | _spi.write(BitReverseTable256[d]); |
oliverb | 0:e760d4cfabe4 | 301 | _cs=1; |
oliverb | 0:e760d4cfabe4 | 302 | wait_us(1); |
oliverb | 0:e760d4cfabe4 | 303 | } |
oliverb | 0:e760d4cfabe4 | 304 | |
oliverb | 0:e760d4cfabe4 | 305 | inline uint8_t Adafruit_GP9002::dataRead() { |
oliverb | 0:e760d4cfabe4 | 306 | uint8_t r; |
oliverb | 0:e760d4cfabe4 | 307 | /* |
oliverb | 0:e760d4cfabe4 | 308 | *dcport &= ~dcpinmask; |
oliverb | 0:e760d4cfabe4 | 309 | *csport &= ~cspinmask; |
oliverb | 0:e760d4cfabe4 | 310 | |
oliverb | 0:e760d4cfabe4 | 311 | r = fastSPIread(); |
oliverb | 0:e760d4cfabe4 | 312 | |
oliverb | 0:e760d4cfabe4 | 313 | *csport |= cspinmask; |
oliverb | 0:e760d4cfabe4 | 314 | delayMicroseconds(1); |
oliverb | 0:e760d4cfabe4 | 315 | */ |
oliverb | 0:e760d4cfabe4 | 316 | |
oliverb | 0:e760d4cfabe4 | 317 | _dc=0; |
oliverb | 0:e760d4cfabe4 | 318 | _cs=0; |
oliverb | 0:e760d4cfabe4 | 319 | r=BitReverseTable256[_spi.write(0)&0xFF]; |
oliverb | 0:e760d4cfabe4 | 320 | _cs=1; |
oliverb | 0:e760d4cfabe4 | 321 | wait_us(1); |
oliverb | 0:e760d4cfabe4 | 322 | |
oliverb | 0:e760d4cfabe4 | 323 | |
oliverb | 0:e760d4cfabe4 | 324 | return r; |
oliverb | 0:e760d4cfabe4 | 325 | } |
oliverb | 0:e760d4cfabe4 | 326 | |
oliverb | 0:e760d4cfabe4 | 327 | void Adafruit_GP9002::setBrightness(uint8_t val) { |
oliverb | 0:e760d4cfabe4 | 328 | |
oliverb | 0:e760d4cfabe4 | 329 | } |
oliverb | 0:e760d4cfabe4 | 330 | |
oliverb | 0:e760d4cfabe4 | 331 | // clear everything |
oliverb | 0:e760d4cfabe4 | 332 | void Adafruit_GP9002::clearDisplay(void) { |
oliverb | 0:e760d4cfabe4 | 333 | command(GP9002_CLEARSCREEN); |
oliverb | 0:e760d4cfabe4 | 334 | |
oliverb | 0:e760d4cfabe4 | 335 | wait_ms(1); |
oliverb | 0:e760d4cfabe4 | 336 | } |
oliverb | 0:e760d4cfabe4 | 337 | |
oliverb | 0:e760d4cfabe4 | 338 | void Adafruit_GP9002::displayOff(void) { |
oliverb | 0:e760d4cfabe4 | 339 | command(GP9002_DISPLAYSOFF); |
oliverb | 0:e760d4cfabe4 | 340 | } |
oliverb | 0:e760d4cfabe4 | 341 | void Adafruit_GP9002::displayOn(void) { |
oliverb | 0:e760d4cfabe4 | 342 | command(GP9002_DISPLAY1ON); |
oliverb | 0:e760d4cfabe4 | 343 | } |
oliverb | 0:e760d4cfabe4 | 344 | |
oliverb | 0:e760d4cfabe4 | 345 |