inline void Adafruit_PCD8544::spiWrite(uint8_t d) { if (isHardwareSPI()) { // Hardware SPI write. SPI.transfer(d); } else { printf ("Software SPI is not supported\n"); } }
inline void Adafruit_PCD8544::spiWrite(uint8_t d) { if (isHardwareSPI()) { // Hardware SPI write. SPI.transfer(d); } else { // Software SPI write with bit banging. for(uint8_t bit = 0x80; bit; bit >>= 1) { *clkport &= ~clkpinmask; if(d & bit) *mosiport |= mosipinmask; else *mosiport &= ~mosipinmask; *clkport |= clkpinmask; } } }
void Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) { if (isHardwareSPI()) { // Setup hardware SPI. SPI.begin(); SPI.setClockDivider(PCD8544_SPI_CLOCK_DIV); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); } else { // Setup software SPI. // Set software SPI specific pin outputs. pinMode(_din, OUTPUT); pinMode(_sclk, OUTPUT); // Set software SPI ports and masks. clkport = portOutputRegister(digitalPinToPort(_sclk)); clkpinmask = digitalPinToBitMask(_sclk); mosiport = portOutputRegister(digitalPinToPort(_din)); mosipinmask = digitalPinToBitMask(_din); } // Set common pin outputs. pinMode(_dc, OUTPUT); if (_rst > 0) pinMode(_rst, OUTPUT); if (_cs > 0) pinMode(_cs, OUTPUT); // toggle RST low to reset if (_rst > 0) { digitalWrite(_rst, LOW); delay(500); digitalWrite(_rst, HIGH); } // get into the EXTENDED mode! command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION ); // LCD bias select (4 is optimal?) command(PCD8544_SETBIAS | bias); // set VOP if (contrast > 0x7f) contrast = 0x7f; command( PCD8544_SETVOP | contrast); // Experimentally determined // normal mode command(PCD8544_FUNCTIONSET); // Set display to Normal command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); // initial display line // set page address // set column address // write display data // set up a bounding box for screen updates updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1); // Push out pcd8544_buffer to the Display (will show the AFI logo) display(); }