void Adafruit_HX8357::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { // Rudimentary clipping if((x >= _width) || (y >= _height)) return; if((y+h-1) >= _height) h = _height-y; setAddrWindow(x, y, x, y+h-1); uint8_t hi = color >> 8, lo = color; //*dcport |= dcpinmask; digitalWrite(_dc, HIGH); //*csport &= ~cspinmask; digitalWrite(_cs, LOW); while (h--) { spiwrite(hi); spiwrite(lo); } //*csport |= cspinmask; digitalWrite(_cs, HIGH); }
void Adafruit_PN532::spiwritecommand(uint8_t* cmd, uint8_t cmdlen) { uint8_t checksum; cmdlen++; #ifdef PN532DEBUG puts("\nSending: "); #endif digitalWrite(_ss, LOW); delay(2); // or whatever the delay is for waking up the board spiwrite(PN532_SPI_DATAWRITE); checksum = PN532_PREAMBLE + PN532_PREAMBLE + PN532_STARTCODE2; spiwrite(PN532_PREAMBLE); spiwrite(PN532_PREAMBLE); spiwrite(PN532_STARTCODE2); spiwrite(cmdlen); spiwrite(~cmdlen + 1); spiwrite(PN532_HOSTTOPN532); checksum += PN532_HOSTTOPN532; #ifdef PN532DEBUG puts(" 0x"); puts("riga 964"); //puts(PN532_PREAMBLE, HEX); puts(" 0x"); puts("riga 965"); //puts(PN532_PREAMBLE, HEX); puts(" 0x"); puts("riga966"); //puts(PN532_STARTCODE2, HEX); puts(" 0x"); puts("riga 967"); //puts(cmdlen, HEX); puts(" 0x"); puts("riga 968"); //puts(~cmdlen + 1, HEX); puts(" 0x");puts("riga 969"); // puts(PN532_HOSTTOPN532, HEX); #endif for (uint8_t i=0; i<cmdlen-1; i++) { spiwrite(cmd[i]); checksum += cmd[i]; #ifdef PN532DEBUG puts(" 0x"); puts("riga 976"); #endif } spiwrite(~checksum); spiwrite(PN532_POSTAMBLE); digitalWrite(_ss, HIGH); #ifdef PN532DEBUG puts(" 0x"); puts("riga 985"); //puts(~checksum, HEX); puts(" 0x"); puts("riga 986"); //puts(PN532_POSTAMBLE, HEX); puts(); #endif }
void Adafruit_VS1053::sciWrite(uint8_t addr, uint16_t data) { #ifdef SPI_HAS_TRANSACTION if (useHardwareSPI) SPI.beginTransaction(VS1053_CONTROL_SPI_SETTING); #endif digitalWrite(_cs, LOW); spiwrite(VS1053_SCI_WRITE); spiwrite(addr); spiwrite(data >> 8); spiwrite(data & 0xFF); digitalWrite(_cs, HIGH); #ifdef SPI_HAS_TRANSACTION if (useHardwareSPI) SPI.endTransaction(); #endif }
void SPIFlash::GetManufacturerInfo (uint8_t *manufID, uint8_t *deviceID) { // W25Q16BV_CMD_MANUFDEVID (0x90) provides both the JEDEC manufacturer // ID and the device ID digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_MANUFDEVID); spiwrite(0x00); // Dummy write spiwrite(0x00); // Dummy write spiwrite(0x00); // Dummy write *manufID = spiread(); *deviceID = spiread(); digitalWrite(_ss, HIGH); }
void Adafruit_SSD1351::drawPixel(int16_t x, int16_t y, uint16_t color) { // Transform x and y based on current rotation. switch (getRotation()) { // Case 0: No rotation case 1: // Rotated 90 degrees clockwise. swap(x, y); x = WIDTH - x - 1; break; case 2: // Rotated 180 degrees clockwise. x = WIDTH - x - 1; y = HEIGHT - y - 1; break; case 3: // Rotated 270 degrees clockwise. swap(x, y); y = HEIGHT - y - 1; break; } // Bounds check. if ((x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT)) return; if ((x < 0) || (y < 0)) return; goTo(x, y); // setup for data *rsport |= rspinmask; *csport &= ~ cspinmask; spiwrite(color >> 8); spiwrite(color); *csport |= cspinmask; }
void SmallFS_class::seek_if_needed(unsigned address) { register_t spibasedata=&SPIDATA; if (address!=offset) { offset = address; spi_disable(); spi_enable(); #ifdef SMALLFSDEBUG Serial.print("Seeking to "); Serial.println(address); #endif /* spiwrite(spibasedata,0x0B); spiwrite(spibasedata,address>>16); spiwrite(spibasedata,address>>8); spiwrite(spibasedata,address); spiwrite(spibasedata,0); spiwrite(spibasedata,0); // Read ahead */ address+=0x0B000000; spiwrite(spibasedata+2,address>>16); /* 16-bit write */ address<<=16; spiwrite(spibasedata+6,address); /* 32-bit Includes read-ahead */ }
void TFT_ILI9163C::writedata16(uint16_t d){ rsport->PIO_SODR |= rspinmask;//HI csport->PIO_CODR |= cspinmask;//LO spiwrite(d >> 8); spiwrite(d); csport->PIO_SODR |= cspinmask;//HI }
void TFT_ILI9163C::writedata16(uint16_t d){ *rsport |= rspinmask; *csport &= ~cspinmask; spiwrite(d >> 8); spiwrite(d); *csport |= cspinmask; }
void SSD1306::ssd1306_command(uint8_t c) { digitalWrite(cs, HIGH); digitalWrite(dc, LOW); digitalWrite(cs, LOW); spiwrite(c); digitalWrite(cs, HIGH); }
void Adafruit_HX8357::drawPixel(int16_t x, int16_t y, uint16_t color) { if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; setAddrWindow(x,y,x+1,y+1); digitalWrite(_dc, HIGH); //*dcport |= dcpinmask; digitalWrite(_cs, LOW); //*csport &= ~cspinmask; /* 18 bit hack for testing */ /* uint8_t r = (color >> 10) & 0x1F, g = (color >> 5) & 0x3F, b = color & 0x1F; r <<= 3; g <<= 2; b <<= 3; spiwrite(r); spiwrite(g); spiwrite(b); */ spiwrite(color >> 8); spiwrite(color); //*csport |= cspinmask; digitalWrite(_cs, HIGH); }
void Adafruit_HX8357::writedata(uint8_t c) { digitalWrite(_dc, HIGH); digitalWrite(_sclk, LOW); digitalWrite(_cs, LOW); spiwrite(c); digitalWrite(_cs, HIGH); }
void Adafruit_SSD1331::drawPixel(int16_t x, int16_t y, uint16_t color) { if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return; // check rotation, move pixel around if necessary switch (getRotation()) { case 1: swap(x, y); x = WIDTH - x - 1; break; case 2: x = WIDTH - x - 1; y = HEIGHT - y - 1; break; case 3: swap(x, y); y = HEIGHT - y - 1; break; } goTo(x, y); // setup for data *portOutputRegister(rsport) |= rspin; *portOutputRegister(csport) &= ~ cspin; spiwrite(color >> 8); spiwrite(color); *portOutputRegister(csport) |= cspin; }
void st7565_data(uint8_t c) { A0_PORT |= _BV(A0); CSACTIVE; spiwrite(c); CSPASSIVE; }
uint32_t SPIFlash::EraseChip (void) { // Wait until the device is ready or a timeout occurs if (WaitForReady()) return 0; // Make sure the chip is write enabled WriteEnable (1); // Make sure the write enable latch is actually set uint8_t status; status = readstatus(); if (!(status & SPIFLASH_STAT_WRTEN)) { // Throw a write protection error (write enable latch not set) return 0; } // Send the erase chip command digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_CHIPERASE); digitalWrite(_ss, HIGH); // Wait until the busy bit is cleared before exiting // This can take up to 10 seconds according to the datasheet! while (readstatus() & SPIFLASH_STAT_BUSY); return 1; }
void SSD1306::ssd1306_data(uint8_t c) { digitalWrite(cs, HIGH); digitalWrite(dc, HIGH); digitalWrite(cs, LOW); spiwrite(c); digitalWrite(cs, HIGH); }
void Adafruit_HX8357::writecommand(uint8_t c) { // modified for SPI digitalWrite(_dc, LOW); digitalWrite(_sclk, LOW); digitalWrite(_cs, LOW); spiwrite(c); digitalWrite(_cs, HIGH); }
void SPIFlash::GetUniqueID(uint8_t *buffer) { uint8_t i; digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_READUNIQUEID); // Unique ID cmd spiwrite(0xFF); // Dummy write spiwrite(0xFF); // Dummy write spiwrite(0xFF); // Dummy write spiwrite(0xFF); // Dummy write // Read 8 bytes worth of data for (i = 0; i < 8; i++) { buffer[i] = spiread(); } digitalWrite(_ss, HIGH); }
void SPIFlash::WriteEnable (bool enable) { // ToDo: Put the WP pin in an appropriate state if required digitalWrite(_ss, LOW); spiwrite(enable ? W25Q16BV_CMD_WRITEENABLE : W25Q16BV_CMD_WRITEDISABLE); digitalWrite(_ss, HIGH); }
int main() { int k; DDRB = (1 << PB7) | (1 << PB5) | (1 << PB4) | (1 << PB3) | (1 << PB2) ; // SCK, MOSI, CE. D/C and RST outputs SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1); //Enable SPI, Master, set clock rate fck/16 PORTB &= ~RST; delay_100us(1); PORTB = RST; spiwrite(0x21); // extended instruction mode spiwrite(0x90); // Vop //spiwrite(0x14); // bias to 100b //spiwrite(0x20); // normal instruction mode spiwrite(0x0D); // normal mode PORTB |= DOC; // enter data mode for(;;) //k = 0; k < 5; ++k) { spiwrite(0x1f); spiwrite(0x5); spiwrite(0x7); spiwrite(0x0); } return 0; }
void GL_ST7735::pushColor(uint16_t color) { *portOutputRegister(rsport) |= rspin; *portOutputRegister(csport) &= ~ cspin; spiwrite(color >> 8); spiwrite(color); *portOutputRegister(csport) |= cspin; }
void Adafruit_SSD1351::writeData(uint8_t c) { digitalWrite(_rs, HIGH); digitalWrite(_cs, LOW); // Serial.print("D "); spiwrite(c); digitalWrite(_cs, HIGH); }
void Zpu_ILI9340::writedata(uint8_t c) { digitalWrite(_dc, HIGH); digitalWrite(_sclk, LOW); digitalWrite(_cs, LOW); spiwrite(c); digitalWrite(_cs, HIGH); }
void Adafruit_ST7735::writedata(uint8_t c) { *rsport |= rspinmask; *csport &= ~cspinmask; //Serial.print("D "); spiwrite(c); *csport |= cspinmask; }
void Adafruit_ST7735::writecommand(uint8_t c) { *rsport &= ~rspinmask; *csport &= ~cspinmask; //Serial.print("C "); spiwrite(c); *csport |= cspinmask; }
uint8_t Adafruit_PN532::readspistatus(void) { digitalWrite(_ss, LOW); delay(2); spiwrite(PN532_SPI_STATREAD); // read byte uint8_t x = spiread(); digitalWrite(_ss, HIGH); return x; }
void Adafruit_SSD1331::pushColor(uint16_t color) { // setup for data *portOutputRegister(rsport) |= rspin; *portOutputRegister(csport) &= ~ cspin; spiwrite(color >> 8); spiwrite(color); *portOutputRegister(csport) |= cspin; }
uint8_t SPIFlash::readstatus() { uint8_t status; digitalWrite(_ss, LOW); spiwrite(W25Q16BV_CMD_READSTAT1); // Send read status 1 cmd status = spiread(); // Dummy write digitalWrite(_ss, HIGH); return status & (SPIFLASH_STAT_BUSY | SPIFLASH_STAT_WRTEN); }
uint16_t Adafruit_VS1053::sciRead(uint8_t addr) { uint16_t data; #ifdef SPI_HAS_TRANSACTION if (useHardwareSPI) SPI.beginTransaction(VS1053_CONTROL_SPI_SETTING); #endif digitalWrite(_cs, LOW); spiwrite(VS1053_SCI_READ); spiwrite(addr); delayMicroseconds(10); data = spiread(); data <<= 8; data |= spiread(); digitalWrite(_cs, HIGH); #ifdef SPI_HAS_TRANSACTION if (useHardwareSPI) SPI.endTransaction(); #endif return data; }
void Adafruit_HX8357::pushColor(uint16_t color) { digitalWrite(_dc, HIGH); //*dcport |= dcpinmask; digitalWrite(_cs, LOW); //*csport &= ~cspinmask; spiwrite(color >> 8); spiwrite(color); //*csport |= cspinmask; digitalWrite(_cs, HIGH); }
void Adafruit_VS1053::playData(uint8_t *buffer, uint8_t buffsiz) { #ifdef SPI_HAS_TRANSACTION if (useHardwareSPI) SPI.beginTransaction(VS1053_DATA_SPI_SETTING); #endif digitalWrite(_dcs, LOW); for (uint8_t i=0; i<buffsiz; i++) { spiwrite(buffer[i]); } digitalWrite(_dcs, HIGH); #ifdef SPI_HAS_TRANSACTION if (useHardwareSPI) SPI.endTransaction(); #endif }