@@ -592,7 +592,6 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) {
592592 }
593593
594594 } else { // TFT_PARALLEL
595-
596595 // Initialize data pins. We were only passed d0, so scan
597596 // the pin description list looking for the other pins.
598597 // They'll be on the same PORT, and within the next 7 (or 15) bits
@@ -1768,7 +1767,7 @@ uint16_t Adafruit_SPITFT::color565(uint8_t red, uint8_t green, uint8_t blue) {
17681767 @param dataBytes A pointer to the Data bytes to send
17691768 @param numDataBytes The number of bytes we should send
17701769 */
1771- void Adafruit_SPITFT::sendCommand (uint8_t commandByte, uint8_t *dataBytes, uint8_t numDataBytes) {
1770+ void Adafruit_SPITFT::sendCommand (uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes) {
17721771 SPI_BEGIN_TRANSACTION ();
17731772 if (_cs >= 0 ) SPI_CS_LOW ();
17741773
@@ -1777,30 +1776,46 @@ void Adafruit_SPITFT::sendCommand(uint8_t commandByte, uint8_t *dataBytes, uint8
17771776
17781777 SPI_DC_HIGH ();
17791778 for (int i=0 ; i<numDataBytes; i++) {
1780- spiWrite (*dataBytes); // Send the data bytes
1781- dataBytes++;
1779+ if ((connection == TFT_PARALLEL) && tft8.wide ) {
1780+ SPI_WRITE16 (*(uint16_t *)dataBytes);
1781+ dataBytes += 2 ;
1782+ } else {
1783+ spiWrite (*dataBytes); // Send the data bytes
1784+ dataBytes++;
1785+ }
17821786 }
17831787
17841788 if (_cs >= 0 ) SPI_CS_HIGH ();
17851789 SPI_END_TRANSACTION ();
17861790}
17871791
17881792/* !
1789- @brief Adafruit_SPITFT Send Command handles complete sending of commands and const data
1790- @param commandByte The Command Byte
1791- @param dataBytes A pointer to the Data bytes to send
1792- @param numDataBytes The number of bytes we should send
1793+ @brief Adafruit_SPITFT sendCommand16 handles complete sending of
1794+ commands and data for 16-bit parallel displays. Currently somewhat
1795+ rigged for the NT35510, which has the odd behavior of wanting
1796+ commands 16-bit, but subsequent data as 8-bit values, despite
1797+ the 16-bit bus (high byte is always 0). Also seems to require
1798+ issuing and incrementing address with each transfer.
1799+ @param commandWord The command word (16 bits)
1800+ @param dataBytes A pointer to the data bytes to send
1801+ @param numDataBytes The number of bytes we should send
17931802 */
1794- void Adafruit_SPITFT::sendCommand (uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes) {
1803+ void Adafruit_SPITFT::sendCommand16 (uint16_t commandWord,
1804+ const uint8_t *dataBytes, uint8_t numDataBytes) {
17951805 SPI_BEGIN_TRANSACTION ();
17961806 if (_cs >= 0 ) SPI_CS_LOW ();
17971807
1798- SPI_DC_LOW (); // Command mode
1799- spiWrite (commandByte); // Send the command byte
1800-
1801- SPI_DC_HIGH ();
1802- for (int i=0 ; i<numDataBytes; i++) {
1803- spiWrite (pgm_read_byte (dataBytes++)); // Send the data bytes
1808+ if (numDataBytes == 0 ) {
1809+ SPI_DC_LOW (); // Command mode
1810+ SPI_WRITE16 (commandWord); // Send the command word
1811+ SPI_DC_HIGH (); // Data mode
1812+ }
1813+ for (int i=0 ; i<numDataBytes; i++) {
1814+ SPI_DC_LOW (); // Command mode
1815+ SPI_WRITE16 (commandWord); // Send the command word
1816+ SPI_DC_HIGH (); // Data mode
1817+ commandWord++;
1818+ SPI_WRITE16 ((uint16_t )pgm_read_byte (dataBytes++));
18041819 }
18051820
18061821 if (_cs >= 0 ) SPI_CS_HIGH ();
@@ -1831,6 +1846,39 @@ uint8_t Adafruit_SPITFT::readcommand8(uint8_t commandByte, uint8_t index) {
18311846 return result;
18321847}
18331848
1849+ /* !
1850+ @brief Read 16 bits of data from display register.
1851+ For 16-bit parallel displays only.
1852+ @param addr Command/register to access.
1853+ @return Unsigned 16-bit data.
1854+ */
1855+ uint16_t Adafruit_SPITFT::readcommand16 (uint16_t addr) {
1856+ #if defined(USE_FAST_PINIO) // NOT SUPPORTED without USE_FAST_PINIO
1857+ uint16_t result = 0 ;
1858+ if ((connection == TFT_PARALLEL) && tft8.wide ) {
1859+ startWrite ();
1860+ SPI_DC_LOW (); // Command mode
1861+ SPI_WRITE16 (addr);
1862+ SPI_DC_HIGH (); // Data mode
1863+ TFT_RD_LOW (); // Read line LOW
1864+ #if defined(HAS_PORT_SET_CLR)
1865+ *(volatile uint16_t *)tft8.dirClr = 0xFFFF ; // Input state
1866+ result = *(volatile uint16_t *)tft8.readPort ; // 16-bit read
1867+ *(volatile uint16_t *)tft8.dirSet = 0xFFFF ; // Output state
1868+ #else // !HAS_PORT_SET_CLR
1869+ *(volatile uint16_t *)tft8.portDir = 0x0000 ; // Input state
1870+ result = *(volatile uint16_t *)tft8.readPort ; // 16-bit read
1871+ *(volatile uint16_t *)tft8.portDir = 0xFFFF ; // Output state
1872+ #endif // end !HAS_PORT_SET_CLR
1873+ TFT_RD_HIGH (); // Read line HIGH
1874+ endWrite ();
1875+ }
1876+ return result;
1877+ #else
1878+ return 0 ;
1879+ #endif // end !USE_FAST_PINIO
1880+ }
1881+
18341882// -------------------------------------------------------------------------
18351883// Lowest-level hardware-interfacing functions. Many of these are inline and
18361884// compile to different things based on #defines -- typically just a few
@@ -1997,6 +2045,71 @@ uint8_t Adafruit_SPITFT::spiRead(void) {
19972045 }
19982046}
19992047
2048+ /* !
2049+ @brief Issue a single 16-bit value to the display. Chip-select,
2050+ transaction and data/command selection must have been
2051+ previously set -- this ONLY issues the word.
2052+ Thus operates ONLY on 'wide' (16-bit) parallel displays!
2053+ @param w 16-bit value to write.
2054+ */
2055+ void Adafruit_SPITFT::write16 (uint16_t w) {
2056+ if (connection == TFT_PARALLEL) {
2057+ #if defined(USE_FAST_PINIO)
2058+ if (tft8.wide ) *(volatile uint16_t *)tft8.writePort = w;
2059+ #endif
2060+ TFT_WR_STROBE ();
2061+ }
2062+ }
2063+
2064+ /* !
2065+ @brief Write a single command word to the display. Chip-select and
2066+ transaction must have been previously set -- this ONLY sets
2067+ the device to COMMAND mode, issues the byte and then restores
2068+ DATA mode. This operates ONLY on 'wide' (16-bit) parallel
2069+ displays!
2070+ @param cmd 16-bit command to write.
2071+ */
2072+ void Adafruit_SPITFT::writeCommand16 (uint16_t cmd) {
2073+ SPI_DC_LOW ();
2074+ write16 (cmd);
2075+ SPI_DC_HIGH ();
2076+ }
2077+
2078+ /* !
2079+ @brief Read a single 16-bit value from the display. Chip-select and
2080+ transaction must have been previously set -- this ONLY reads
2081+ the byte. This operates ONLY on 'wide' (16-bit) parallel
2082+ displays!
2083+ @return Unsigned 16-bit value read (always zero if USE_FAST_PINIO is
2084+ not supported by the MCU architecture).
2085+ */
2086+ uint16_t Adafruit_SPITFT::read16 (void ) {
2087+ uint8_t b = 0 ;
2088+ uint16_t w = 0 ;
2089+ if (connection == TFT_PARALLEL) {
2090+ if (tft8._rd >= 0 ) {
2091+ #if defined(USE_FAST_PINIO)
2092+ TFT_RD_LOW (); // Read line LOW
2093+ if (tft8.wide ) { // 16-bit TFT connection
2094+ #if defined(HAS_PORT_SET_CLR)
2095+ *(volatile uint16_t *)tft8.dirClr = 0xFFFF ; // Input state
2096+ w = *(volatile uint16_t *)tft8.readPort ; // 16-bit read
2097+ *(volatile uint16_t *)tft8.dirSet = 0xFFFF ; // Output state
2098+ #else // !HAS_PORT_SET_CLR
2099+ *(volatile uint16_t *)tft8.portDir = 0x0000 ; // Input state
2100+ w = *(volatile uint16_t *)tft8.readPort ; // 16-bit read
2101+ *(volatile uint16_t *)tft8.portDir = 0xFFFF ; // Output state
2102+ #endif // end !HAS_PORT_SET_CLR
2103+ }
2104+ TFT_RD_HIGH (); // Read line HIGH
2105+ #else // !USE_FAST_PINIO
2106+ w = 0 ; // Parallel TFT is NOT SUPPORTED without USE_FAST_PINIO
2107+ #endif // end !USE_FAST_PINIO
2108+ }
2109+ }
2110+ return w;
2111+ }
2112+
20002113/* !
20012114 @brief Set the software (bitbang) SPI MOSI line HIGH.
20022115*/
0 commit comments