Port of the Adafruit PCD8544 Driver @ https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library for use in MBED Inital version only supports hardware SPI, and has been tested on a Nucleo test board. BSD license

Requires http://developer.mbed.org/users/infotech1/code/Adafruit_GFX_MBED/ to provide drawing capabilities.

Committer:
infotech1
Date:
Sun Nov 02 07:10:44 2014 +0000
Revision:
0:4d2abaa4de64
Child:
1:03227e59446f
Initial commit, Hardware SPI only.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
infotech1 0:4d2abaa4de64 1 /*********************************************************************
infotech1 0:4d2abaa4de64 2 This is a library for our Monochrome Nokia 5110 LCD Displays
infotech1 0:4d2abaa4de64 3
infotech1 0:4d2abaa4de64 4 Pick one up today in the adafruit shop!
infotech1 0:4d2abaa4de64 5 ------> http://www.adafruit.com/products/338
infotech1 0:4d2abaa4de64 6
infotech1 0:4d2abaa4de64 7 These displays use SPI to communicate, 4 or 5 pins are required to
infotech1 0:4d2abaa4de64 8 interface
infotech1 0:4d2abaa4de64 9
infotech1 0:4d2abaa4de64 10 Adafruit invests time and resources providing this open source code,
infotech1 0:4d2abaa4de64 11 please support Adafruit and open-source hardware by purchasing
infotech1 0:4d2abaa4de64 12 products from Adafruit!
infotech1 0:4d2abaa4de64 13
infotech1 0:4d2abaa4de64 14 Written by Limor Fried/Ladyada for Adafruit Industries.
infotech1 0:4d2abaa4de64 15 BSD license, check license.txt for more information
infotech1 0:4d2abaa4de64 16 All text above, and the splash screen below must be included in any redistribution
infotech1 0:4d2abaa4de64 17
infotech1 0:4d2abaa4de64 18
infotech1 0:4d2abaa4de64 19 Modified for MBED usage and tested with STM32F411RE on a Nucleo board.
infotech1 0:4d2abaa4de64 20 Hardware SPI only, tested using default arduino pin out D11/D13 for MOSI/SCLK, Support provided for different pin layouts
infotech1 0:4d2abaa4de64 21 by James Kidd 2014
infotech1 0:4d2abaa4de64 22 *********************************************************************/
infotech1 0:4d2abaa4de64 23
infotech1 0:4d2abaa4de64 24 #ifndef _BV
infotech1 0:4d2abaa4de64 25 #define _BV( bit ) ( 1<<(bit) )
infotech1 0:4d2abaa4de64 26 #endif
infotech1 0:4d2abaa4de64 27 //#include <Wire.h>
infotech1 0:4d2abaa4de64 28 #include <stdint.h>
infotech1 0:4d2abaa4de64 29 //#include <Adafruit_GFX.h>
infotech1 0:4d2abaa4de64 30 #include "Adafruit_GFX.h"
infotech1 0:4d2abaa4de64 31 #include "Adafruit_PCD8544.h"
infotech1 0:4d2abaa4de64 32
infotech1 0:4d2abaa4de64 33 // the memory buffer for the LCD
infotech1 0:4d2abaa4de64 34 uint8_t pcd8544_buffer[LCDWIDTH * LCDHEIGHT / 8] = {
infotech1 0:4d2abaa4de64 35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0,
infotech1 0:4d2abaa4de64 38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 41 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,
infotech1 0:4d2abaa4de64 42 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F,
infotech1 0:4d2abaa4de64 43 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF,
infotech1 0:4d2abaa4de64 47 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 0xFF,
infotech1 0:4d2abaa4de64 48 0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE,
infotech1 0:4d2abaa4de64 49 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 52 0x00, 0x80, 0xC0, 0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87,
infotech1 0:4d2abaa4de64 53 0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF,
infotech1 0:4d2abaa4de64 54 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 57 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
infotech1 0:4d2abaa4de64 58 0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF,
infotech1 0:4d2abaa4de64 59 0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01,
infotech1 0:4d2abaa4de64 63 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F,
infotech1 0:4d2abaa4de64 64 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
infotech1 0:4d2abaa4de64 67 };
infotech1 0:4d2abaa4de64 68
infotech1 0:4d2abaa4de64 69
infotech1 0:4d2abaa4de64 70 // reduces how much is refreshed, which speeds it up!
infotech1 0:4d2abaa4de64 71 // originally derived from Steve Evans/JCW's mod but cleaned up and
infotech1 0:4d2abaa4de64 72 // optimized
infotech1 0:4d2abaa4de64 73 //#define enablePartialUpdate
infotech1 0:4d2abaa4de64 74
infotech1 0:4d2abaa4de64 75 #ifdef enablePartialUpdate
infotech1 0:4d2abaa4de64 76 static uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax;
infotech1 0:4d2abaa4de64 77 #endif
infotech1 0:4d2abaa4de64 78
infotech1 0:4d2abaa4de64 79
infotech1 0:4d2abaa4de64 80
infotech1 0:4d2abaa4de64 81 static void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) {
infotech1 0:4d2abaa4de64 82 #ifdef enablePartialUpdate
infotech1 0:4d2abaa4de64 83 if (xmin < xUpdateMin) xUpdateMin = xmin;
infotech1 0:4d2abaa4de64 84 if (xmax > xUpdateMax) xUpdateMax = xmax;
infotech1 0:4d2abaa4de64 85 if (ymin < yUpdateMin) yUpdateMin = ymin;
infotech1 0:4d2abaa4de64 86 if (ymax > yUpdateMax) yUpdateMax = ymax;
infotech1 0:4d2abaa4de64 87 #endif
infotech1 0:4d2abaa4de64 88 }
infotech1 0:4d2abaa4de64 89
infotech1 0:4d2abaa4de64 90
infotech1 0:4d2abaa4de64 91 /*
infotech1 0:4d2abaa4de64 92 * 3,4,5 by default with D13(sclk)/D11(mosi) used by default for SPI
infotech1 0:4d2abaa4de64 93 */
infotech1 0:4d2abaa4de64 94 Adafruit_PCD8544::Adafruit_PCD8544(PinName RST, PinName CS,PinName DC,PinName MOSI,PinName SCLK ): Adafruit_GFX(LCDWIDTH,LCDHEIGHT) {
infotech1 0:4d2abaa4de64 95 _din = -1;
infotech1 0:4d2abaa4de64 96 _sclk = -1;
infotech1 0:4d2abaa4de64 97 _dc = 1;
infotech1 0:4d2abaa4de64 98 _rst = 1;
infotech1 0:4d2abaa4de64 99 _cs = 1;
infotech1 0:4d2abaa4de64 100 myPins.rst = RST;
infotech1 0:4d2abaa4de64 101 myPins.sce = CS;
infotech1 0:4d2abaa4de64 102 myPins.dc = DC;
infotech1 0:4d2abaa4de64 103 myPins.mosi = MOSI;
infotech1 0:4d2abaa4de64 104 myPins.miso = NC;
infotech1 0:4d2abaa4de64 105 myPins.sclk = SCLK;
infotech1 0:4d2abaa4de64 106 }
infotech1 0:4d2abaa4de64 107 /*
infotech1 0:4d2abaa4de64 108 * 3,4,5 by default with D13(sclk)/D11(mosi) used by default for SPI
infotech1 0:4d2abaa4de64 109 */
infotech1 0:4d2abaa4de64 110 Adafruit_PCD8544::Adafruit_PCD8544(PinName RST, PinName CS,PinName DC ): Adafruit_GFX(LCDWIDTH,LCDHEIGHT) {
infotech1 0:4d2abaa4de64 111 _din = -1;
infotech1 0:4d2abaa4de64 112 _sclk = -1;
infotech1 0:4d2abaa4de64 113 _dc = 1;
infotech1 0:4d2abaa4de64 114 _rst = 1;
infotech1 0:4d2abaa4de64 115 _cs = 1;
infotech1 0:4d2abaa4de64 116 myPins.rst = RST;
infotech1 0:4d2abaa4de64 117 myPins.sce = CS;
infotech1 0:4d2abaa4de64 118 myPins.dc = DC;
infotech1 0:4d2abaa4de64 119 myPins.mosi = D11;
infotech1 0:4d2abaa4de64 120 myPins.miso = NC;
infotech1 0:4d2abaa4de64 121 myPins.sclk = D13;
infotech1 0:4d2abaa4de64 122 }
infotech1 0:4d2abaa4de64 123
infotech1 0:4d2abaa4de64 124
infotech1 0:4d2abaa4de64 125 // the most basic function, set a single pixel
infotech1 0:4d2abaa4de64 126 void Adafruit_PCD8544::drawPixel(int16_t x, int16_t y, uint16_t color) {
infotech1 0:4d2abaa4de64 127 if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height))
infotech1 0:4d2abaa4de64 128 return;
infotech1 0:4d2abaa4de64 129
infotech1 0:4d2abaa4de64 130 int16_t t;
infotech1 0:4d2abaa4de64 131 switch(rotation){
infotech1 0:4d2abaa4de64 132 case 1:
infotech1 0:4d2abaa4de64 133 t = x;
infotech1 0:4d2abaa4de64 134 x = y;
infotech1 0:4d2abaa4de64 135 y = LCDHEIGHT - 1 - t;
infotech1 0:4d2abaa4de64 136 break;
infotech1 0:4d2abaa4de64 137 case 2:
infotech1 0:4d2abaa4de64 138 x = LCDWIDTH - 1 - x;
infotech1 0:4d2abaa4de64 139 y = LCDHEIGHT - 1 - y;
infotech1 0:4d2abaa4de64 140 break;
infotech1 0:4d2abaa4de64 141 case 3:
infotech1 0:4d2abaa4de64 142 t = x;
infotech1 0:4d2abaa4de64 143 x = LCDWIDTH - 1 - y;
infotech1 0:4d2abaa4de64 144 y = t;
infotech1 0:4d2abaa4de64 145 break;
infotech1 0:4d2abaa4de64 146 }
infotech1 0:4d2abaa4de64 147
infotech1 0:4d2abaa4de64 148 if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT))
infotech1 0:4d2abaa4de64 149 return;
infotech1 0:4d2abaa4de64 150
infotech1 0:4d2abaa4de64 151 // x is which column
infotech1 0:4d2abaa4de64 152 if (color)
infotech1 0:4d2abaa4de64 153 pcd8544_buffer[x+ (y/8)*LCDWIDTH] |= _BV(y%8);
infotech1 0:4d2abaa4de64 154 else
infotech1 0:4d2abaa4de64 155 pcd8544_buffer[x+ (y/8)*LCDWIDTH] &= ~_BV(y%8);
infotech1 0:4d2abaa4de64 156
infotech1 0:4d2abaa4de64 157 updateBoundingBox(x,y,x,y);
infotech1 0:4d2abaa4de64 158 }
infotech1 0:4d2abaa4de64 159
infotech1 0:4d2abaa4de64 160
infotech1 0:4d2abaa4de64 161 // the most basic function, get a single pixel
infotech1 0:4d2abaa4de64 162 uint8_t Adafruit_PCD8544::getPixel(int8_t x, int8_t y) {
infotech1 0:4d2abaa4de64 163 if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT))
infotech1 0:4d2abaa4de64 164 return 0;
infotech1 0:4d2abaa4de64 165
infotech1 0:4d2abaa4de64 166 return (pcd8544_buffer[x+ (y/8)*LCDWIDTH] >> (y%8)) & 0x1;
infotech1 0:4d2abaa4de64 167 }
infotech1 0:4d2abaa4de64 168
infotech1 0:4d2abaa4de64 169
infotech1 0:4d2abaa4de64 170 void Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) {
infotech1 0:4d2abaa4de64 171
infotech1 0:4d2abaa4de64 172
infotech1 0:4d2abaa4de64 173 if (isHardwareSPI()) {
infotech1 0:4d2abaa4de64 174 // Setup hardware SPI.
infotech1 0:4d2abaa4de64 175 LcdSPI = new SPI(D11,NC,D13);
infotech1 0:4d2abaa4de64 176 LcdSPI->format(LCD_SPI_BITS, LCD_SPI_MODE);
infotech1 0:4d2abaa4de64 177 LcdSPI->frequency(LCD_FREQ);
infotech1 0:4d2abaa4de64 178 //SPI.begin();
infotech1 0:4d2abaa4de64 179 //SPI.setClockDivider(PCD8544_SPI_CLOCK_DIV);
infotech1 0:4d2abaa4de64 180 //SPI.setDataMode(SPI_MODE0);
infotech1 0:4d2abaa4de64 181 //SPI.setBitOrder(MSBFIRST);
infotech1 0:4d2abaa4de64 182 }
infotech1 0:4d2abaa4de64 183 else {
infotech1 0:4d2abaa4de64 184 // Setup software SPI.
infotech1 0:4d2abaa4de64 185
infotech1 0:4d2abaa4de64 186 // Set software SPI specific pin outputs.
infotech1 0:4d2abaa4de64 187 /* pinMode(_din, OUTPUT);
infotech1 0:4d2abaa4de64 188 pinMode(_sclk, OUTPUT);
infotech1 0:4d2abaa4de64 189
infotech1 0:4d2abaa4de64 190 // Set software SPI ports and masks.
infotech1 0:4d2abaa4de64 191 clkport = portOutputRegister(digitalPinToPort(_sclk));
infotech1 0:4d2abaa4de64 192 clkpinmask = digitalPinToBitMask(_sclk);
infotech1 0:4d2abaa4de64 193 mosiport = portOutputRegister(digitalPinToPort(_din));
infotech1 0:4d2abaa4de64 194 mosipinmask = digitalPinToBitMask(_din);*/
infotech1 0:4d2abaa4de64 195 }
infotech1 0:4d2abaa4de64 196 Pins = new DigitalOut*[3];
infotech1 0:4d2abaa4de64 197 Pins[PIN_RST] = new DigitalOut(myPins.rst);
infotech1 0:4d2abaa4de64 198 Pins[PIN_SCE] = new DigitalOut(myPins.sce);
infotech1 0:4d2abaa4de64 199 Pins[PIN_DC] = new DigitalOut(myPins.dc);
infotech1 0:4d2abaa4de64 200
infotech1 0:4d2abaa4de64 201
infotech1 0:4d2abaa4de64 202 // Set common pin outputs.
infotech1 0:4d2abaa4de64 203 /*pinMode(_dc, OUTPUT);
infotech1 0:4d2abaa4de64 204 if (_rst > 0)
infotech1 0:4d2abaa4de64 205 pinMode(_rst, OUTPUT);
infotech1 0:4d2abaa4de64 206 if (_cs > 0)
infotech1 0:4d2abaa4de64 207 pinMode(_cs, OUTPUT);*/
infotech1 0:4d2abaa4de64 208
infotech1 0:4d2abaa4de64 209 // toggle RST low to reset
infotech1 0:4d2abaa4de64 210 if (_rst > 0) {
infotech1 0:4d2abaa4de64 211 Pins[PIN_RST]->write(0);
infotech1 0:4d2abaa4de64 212 wait_ms(500);
infotech1 0:4d2abaa4de64 213 Pins[PIN_RST]->write(1);
infotech1 0:4d2abaa4de64 214 //digitalWrite(_rst, LOW);
infotech1 0:4d2abaa4de64 215 //_delay_ms(500);
infotech1 0:4d2abaa4de64 216 //digitalWrite(_rst, HIGH);
infotech1 0:4d2abaa4de64 217 }
infotech1 0:4d2abaa4de64 218
infotech1 0:4d2abaa4de64 219 // get into the EXTENDED mode!
infotech1 0:4d2abaa4de64 220 command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );
infotech1 0:4d2abaa4de64 221
infotech1 0:4d2abaa4de64 222 // LCD bias select (4 is optimal?)
infotech1 0:4d2abaa4de64 223 command(PCD8544_SETBIAS | bias);
infotech1 0:4d2abaa4de64 224
infotech1 0:4d2abaa4de64 225 // set VOP
infotech1 0:4d2abaa4de64 226 if (contrast > 0x7f)
infotech1 0:4d2abaa4de64 227 contrast = 0x7f;
infotech1 0:4d2abaa4de64 228
infotech1 0:4d2abaa4de64 229 command( PCD8544_SETVOP | contrast); // Experimentally determined
infotech1 0:4d2abaa4de64 230
infotech1 0:4d2abaa4de64 231
infotech1 0:4d2abaa4de64 232 // normal mode
infotech1 0:4d2abaa4de64 233 command(PCD8544_FUNCTIONSET);
infotech1 0:4d2abaa4de64 234
infotech1 0:4d2abaa4de64 235 // Set display to Normal
infotech1 0:4d2abaa4de64 236 command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
infotech1 0:4d2abaa4de64 237
infotech1 0:4d2abaa4de64 238 // initial display line
infotech1 0:4d2abaa4de64 239 // set page address
infotech1 0:4d2abaa4de64 240 // set column address
infotech1 0:4d2abaa4de64 241 // write display data
infotech1 0:4d2abaa4de64 242
infotech1 0:4d2abaa4de64 243 // set up a bounding box for screen updates
infotech1 0:4d2abaa4de64 244
infotech1 0:4d2abaa4de64 245 updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
infotech1 0:4d2abaa4de64 246 // Push out pcd8544_buffer to the Display (will show the AFI logo)
infotech1 0:4d2abaa4de64 247 display();
infotech1 0:4d2abaa4de64 248 }
infotech1 0:4d2abaa4de64 249
infotech1 0:4d2abaa4de64 250
infotech1 0:4d2abaa4de64 251 inline void Adafruit_PCD8544::spiWrite(uint8_t d) {
infotech1 0:4d2abaa4de64 252 if (isHardwareSPI()) {
infotech1 0:4d2abaa4de64 253 // Hardware SPI write.
infotech1 0:4d2abaa4de64 254 LcdSPI->write(d);
infotech1 0:4d2abaa4de64 255 //SPI.transfer(d);
infotech1 0:4d2abaa4de64 256 }
infotech1 0:4d2abaa4de64 257 else {
infotech1 0:4d2abaa4de64 258 // Software SPI write with bit banging.
infotech1 0:4d2abaa4de64 259 for(uint8_t bit = 0x80; bit; bit >>= 1) {
infotech1 0:4d2abaa4de64 260 *clkport &= ~clkpinmask;
infotech1 0:4d2abaa4de64 261 if(d & bit) *mosiport |= mosipinmask;
infotech1 0:4d2abaa4de64 262 else *mosiport &= ~mosipinmask;
infotech1 0:4d2abaa4de64 263 *clkport |= clkpinmask;
infotech1 0:4d2abaa4de64 264 }
infotech1 0:4d2abaa4de64 265 }
infotech1 0:4d2abaa4de64 266 }
infotech1 0:4d2abaa4de64 267
infotech1 0:4d2abaa4de64 268 bool Adafruit_PCD8544::isHardwareSPI() {
infotech1 0:4d2abaa4de64 269 return (_din == -1 && _sclk == -1);
infotech1 0:4d2abaa4de64 270 }
infotech1 0:4d2abaa4de64 271
infotech1 0:4d2abaa4de64 272 void Adafruit_PCD8544::command(uint8_t c) {
infotech1 0:4d2abaa4de64 273 Pins[PIN_DC]->write(0);
infotech1 0:4d2abaa4de64 274 //digitalWrite(_dc, LOW);
infotech1 0:4d2abaa4de64 275 if (_cs > 0)
infotech1 0:4d2abaa4de64 276 Pins[PIN_SCE]->write(0);
infotech1 0:4d2abaa4de64 277 //digitalWrite(_cs, LOW);
infotech1 0:4d2abaa4de64 278 spiWrite(c);
infotech1 0:4d2abaa4de64 279 if (_cs > 0)
infotech1 0:4d2abaa4de64 280 Pins[PIN_SCE]->write(1);
infotech1 0:4d2abaa4de64 281 //digitalWrite(_cs, HIGH);
infotech1 0:4d2abaa4de64 282 }
infotech1 0:4d2abaa4de64 283
infotech1 0:4d2abaa4de64 284 void Adafruit_PCD8544::data(uint8_t c) {
infotech1 0:4d2abaa4de64 285 Pins[PIN_DC]->write(1);
infotech1 0:4d2abaa4de64 286 //digitalWrite(_dc, HIGH);
infotech1 0:4d2abaa4de64 287 if (_cs > 0)
infotech1 0:4d2abaa4de64 288 Pins[PIN_SCE]->write(0);//digitalWrite(_cs, LOW);
infotech1 0:4d2abaa4de64 289 spiWrite(c);
infotech1 0:4d2abaa4de64 290 if (_cs > 0)
infotech1 0:4d2abaa4de64 291 Pins[PIN_SCE]->write(1);//digitalWrite(_cs, HIGH);
infotech1 0:4d2abaa4de64 292 }
infotech1 0:4d2abaa4de64 293
infotech1 0:4d2abaa4de64 294 void Adafruit_PCD8544::setContrast(uint8_t val) {
infotech1 0:4d2abaa4de64 295 if (val > 0x7f) {
infotech1 0:4d2abaa4de64 296 val = 0x7f;
infotech1 0:4d2abaa4de64 297 }
infotech1 0:4d2abaa4de64 298 command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );
infotech1 0:4d2abaa4de64 299 command( PCD8544_SETVOP | val);
infotech1 0:4d2abaa4de64 300 command(PCD8544_FUNCTIONSET);
infotech1 0:4d2abaa4de64 301
infotech1 0:4d2abaa4de64 302 }
infotech1 0:4d2abaa4de64 303
infotech1 0:4d2abaa4de64 304
infotech1 0:4d2abaa4de64 305
infotech1 0:4d2abaa4de64 306 void Adafruit_PCD8544::display(void) {
infotech1 0:4d2abaa4de64 307 uint8_t col, maxcol, p;
infotech1 0:4d2abaa4de64 308
infotech1 0:4d2abaa4de64 309 for(p = 0; p < 6; p++) {
infotech1 0:4d2abaa4de64 310 #ifdef enablePartialUpdate
infotech1 0:4d2abaa4de64 311 // check if this page is part of update
infotech1 0:4d2abaa4de64 312 if ( yUpdateMin >= ((p+1)*8) ) {
infotech1 0:4d2abaa4de64 313 continue; // nope, skip it!
infotech1 0:4d2abaa4de64 314 }
infotech1 0:4d2abaa4de64 315 if (yUpdateMax < p*8) {
infotech1 0:4d2abaa4de64 316 break;
infotech1 0:4d2abaa4de64 317 }
infotech1 0:4d2abaa4de64 318 #endif
infotech1 0:4d2abaa4de64 319
infotech1 0:4d2abaa4de64 320 command(PCD8544_SETYADDR | p);
infotech1 0:4d2abaa4de64 321
infotech1 0:4d2abaa4de64 322
infotech1 0:4d2abaa4de64 323 #ifdef enablePartialUpdate
infotech1 0:4d2abaa4de64 324 col = xUpdateMin;
infotech1 0:4d2abaa4de64 325 maxcol = xUpdateMax;
infotech1 0:4d2abaa4de64 326 #else
infotech1 0:4d2abaa4de64 327 // start at the beginning of the row
infotech1 0:4d2abaa4de64 328 col = 0;
infotech1 0:4d2abaa4de64 329 maxcol = LCDWIDTH-1;
infotech1 0:4d2abaa4de64 330 #endif
infotech1 0:4d2abaa4de64 331
infotech1 0:4d2abaa4de64 332 command(PCD8544_SETXADDR | col);
infotech1 0:4d2abaa4de64 333 Pins[PIN_DC]->write(1);
infotech1 0:4d2abaa4de64 334 //digitalWrite(_dc, HIGH);
infotech1 0:4d2abaa4de64 335 if (_cs > 0)
infotech1 0:4d2abaa4de64 336 Pins[PIN_SCE]->write(0);//digitalWrite(_cs, LOW);
infotech1 0:4d2abaa4de64 337 for(; col <= maxcol; col++) {
infotech1 0:4d2abaa4de64 338 spiWrite(pcd8544_buffer[(LCDWIDTH*p)+col]);
infotech1 0:4d2abaa4de64 339 }
infotech1 0:4d2abaa4de64 340 if (_cs > 0)
infotech1 0:4d2abaa4de64 341 Pins[PIN_SCE]->write(1);//digitalWrite(_cs, HIGH);
infotech1 0:4d2abaa4de64 342
infotech1 0:4d2abaa4de64 343 }
infotech1 0:4d2abaa4de64 344
infotech1 0:4d2abaa4de64 345 command(PCD8544_SETYADDR ); // no idea why this is necessary but it is to finish the last byte?
infotech1 0:4d2abaa4de64 346 #ifdef enablePartialUpdate
infotech1 0:4d2abaa4de64 347 xUpdateMin = LCDWIDTH - 1;
infotech1 0:4d2abaa4de64 348 xUpdateMax = 0;
infotech1 0:4d2abaa4de64 349 yUpdateMin = LCDHEIGHT-1;
infotech1 0:4d2abaa4de64 350 yUpdateMax = 0;
infotech1 0:4d2abaa4de64 351 #endif
infotech1 0:4d2abaa4de64 352
infotech1 0:4d2abaa4de64 353 }
infotech1 0:4d2abaa4de64 354
infotech1 0:4d2abaa4de64 355 // clear everything
infotech1 0:4d2abaa4de64 356 void Adafruit_PCD8544::clearDisplay(void) {
infotech1 0:4d2abaa4de64 357 memset(pcd8544_buffer, 0, LCDWIDTH*LCDHEIGHT/8);
infotech1 0:4d2abaa4de64 358 updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
infotech1 0:4d2abaa4de64 359 cursor_y = cursor_x = 0;
infotech1 0:4d2abaa4de64 360 }
infotech1 0:4d2abaa4de64 361
infotech1 0:4d2abaa4de64 362 /*
infotech1 0:4d2abaa4de64 363 // this doesnt touch the buffer, just clears the display RAM - might be handy
infotech1 0:4d2abaa4de64 364 void Adafruit_PCD8544::clearDisplay(void) {
infotech1 0:4d2abaa4de64 365
infotech1 0:4d2abaa4de64 366 uint8_t p, c;
infotech1 0:4d2abaa4de64 367
infotech1 0:4d2abaa4de64 368 for(p = 0; p < 8; p++) {
infotech1 0:4d2abaa4de64 369
infotech1 0:4d2abaa4de64 370 st7565_command(CMD_SET_PAGE | p);
infotech1 0:4d2abaa4de64 371 for(c = 0; c < 129; c++) {
infotech1 0:4d2abaa4de64 372 //uart_putw_dec(c);
infotech1 0:4d2abaa4de64 373 //uart_putchar(' ');
infotech1 0:4d2abaa4de64 374 st7565_command(CMD_SET_COLUMN_LOWER | (c & 0xf));
infotech1 0:4d2abaa4de64 375 st7565_command(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf));
infotech1 0:4d2abaa4de64 376 st7565_data(0x0);
infotech1 0:4d2abaa4de64 377 }
infotech1 0:4d2abaa4de64 378 }
infotech1 0:4d2abaa4de64 379
infotech1 0:4d2abaa4de64 380 }
infotech1 0:4d2abaa4de64 381
infotech1 0:4d2abaa4de64 382 */