uint16_t Adafruit_STMPE610::readRegister16(uint8_t reg) { uint16_t x; if (_CS == -1) { // use i2c Wire.beginTransmission(_i2caddr); Wire.write((byte)reg); Wire.endTransmission(); Wire.requestFrom(_i2caddr, (byte)2); x = Wire.read(); x<<=8; x |= Wire.read(); Wire.endTransmission(); } if (_CLK == -1) { // hardware SPI #if defined (SPI_HAS_TRANSACTION) if (_CLK == -1) SPI.beginTransaction(mySPISettings); #endif digitalWrite(_CS, LOW); spiOut(0x80 | reg); spiOut(0x00); x = spiIn(); x<<=8; x |= spiIn(); digitalWrite(_CS, HIGH); #if defined (SPI_HAS_TRANSACTION) if (_CLK == -1) SPI.endTransaction(); #endif } //Serial.print("$"); Serial.print(reg, HEX); //Serial.print(": 0x"); Serial.println(x, HEX); return x; }
void SpiLcd::pulseEnable(void) { bitSet(_spiByte, LCD_SHIFT_ENABLE); spiOut(); delayMicroseconds(1); // enable pulse must be >450ns bitClear(_spiByte, LCD_SHIFT_ENABLE); spiOut(); }
void Adafruit_STMPE610::writeRegister8(uint8_t reg, uint8_t val) { spi_begin(); CSLow(); spiOut(reg); spiOut(val); CSHigh(); spi_end(); }
uint8_t Adafruit_STMPE610::readRegister8(uint8_t reg) { uint8_t x ; spi_begin(); CSLow(); spiOut(0x80 | reg); spiOut(0x00); x = spiIn(); CSHigh(); spi_end(); return x; }
uint16_t Adafruit_STMPE610::readRegister16(uint8_t reg) { uint16_t x; spi_begin(); CSLow(); spiOut(0x80 | reg); spiOut(0x00); x = spiIn(); x<<=8; x |= spiIn(); CSHigh(); spi_end(); //Serial.print("$"); Serial.print(reg, HEX); //Serial.print(": 0x"); Serial.println(x, HEX); return x; }
void SpiLcd::begin(uint8_t cols, uint8_t lines) { _numlines = lines; _currline = 0; _currpos = 0; // Set all outputs of shift register to low, this turns the backlight ON. _spiByte = 0x00; spiOut(); // The following initialization sequence should be compatible with: // - Newhaven OLED displays // - Standard HD44780 or S6A0069 LCD displays delayMicroseconds(50000); // wait 50 ms just to be sure that the lcd is initialized write4bits(0x03); //set to 8-bit delayMicroseconds(50000); // wait > 4.1ms write4bits(0x03); //set to 8-bit delayMicroseconds(1000); // wait > 100us write4bits(0x03); //set to 8-bit delayMicroseconds(50000); // wait for execution write4bits(0x02); //set to 4-bit delayMicroseconds(50000); // wait for execution command(0x28); // set to 4-bit, 2-line clear(); // display clear // Entry Mode Set: leftToRight(); noAutoscroll(); home(); //noCursor(); display(); }
void Adafruit_STMPE610::writeRegister8(uint8_t reg, uint8_t val) { if (_CS == -1) { // use i2c Wire.beginTransmission(_i2caddr); Wire.write((byte)reg); Wire.write(val); Wire.endTransmission(); } else { #if defined (SPI_HAS_TRANSACTION) if (_CLK == -1) SPI.beginTransaction(mySPISettings); #endif digitalWrite(_CS, LOW); spiOut(reg); spiOut(val); digitalWrite(_CS, HIGH); #if defined (SPI_HAS_TRANSACTION) if (_CLK == -1) SPI.endTransaction(); #endif } }
// write either command or data void SpiLcd::send(uint8_t value, uint8_t mode) { if(mode){ bitSet(_spiByte, LCD_SHIFT_RS); } else{ bitClear(_spiByte, LCD_SHIFT_RS); } spiOut(); write4bits(value>>4); write4bits(value); }
void SpiLcd::write4bits(uint8_t value) { _spiByte = (_spiByte & ~LCD_SHIFT_DATA_MASK) | (value << 4); spiOut(); pulseEnable(); }