Adafruit_SPITFT.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*!
  2. * @file Adafruit_SPITFT.h
  3. *
  4. * Part of Adafruit's GFX graphics library. Originally this class was
  5. * written to handle a range of color TFT displays connected via SPI,
  6. * but over time this library and some display-specific subclasses have
  7. * mutated to include some color OLEDs as well as parallel-interfaced
  8. * displays. The name's been kept for the sake of older code.
  9. *
  10. * Adafruit invests time and resources providing this open source code,
  11. * please support Adafruit and open-source hardware by purchasing
  12. * products from Adafruit!
  13. *
  14. * Written by Limor "ladyada" Fried for Adafruit Industries,
  15. * with contributions from the open source community.
  16. *
  17. * BSD license, all text here must be included in any redistribution.
  18. */
  19. #ifndef _ADAFRUIT_SPITFT_H_
  20. #define _ADAFRUIT_SPITFT_H_
  21. #if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all
  22. #include "Adafruit_GFX.h"
  23. #include <SPI.h>
  24. // HARDWARE CONFIG ---------------------------------------------------------
  25. #if defined(__AVR__)
  26. typedef uint8_t ADAGFX_PORT_t; ///< PORT values are 8-bit
  27. #define USE_FAST_PINIO ///< Use direct PORT register access
  28. #elif defined(ARDUINO_STM32_FEATHER) // WICED
  29. typedef class HardwareSPI SPIClass; ///< SPI is a bit odd on WICED
  30. typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
  31. #elif defined(__arm__)
  32. #if defined(ARDUINO_ARCH_SAMD)
  33. // Adafruit M0, M4
  34. typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
  35. #define USE_FAST_PINIO ///< Use direct PORT register access
  36. #define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
  37. #elif defined(CORE_TEENSY)
  38. // PJRC Teensy 4.x
  39. #if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
  40. typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
  41. // PJRC Teensy 3.x
  42. #else
  43. typedef uint8_t ADAGFX_PORT_t; ///< PORT values are 8-bit
  44. #endif
  45. #define USE_FAST_PINIO ///< Use direct PORT register access
  46. #define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
  47. #else
  48. // Arduino Due?
  49. typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
  50. // USE_FAST_PINIO not available here (yet)...Due has a totally different
  51. // GPIO register set and will require some changes elsewhere (e.g. in
  52. // constructors especially).
  53. #endif
  54. #else // !ARM
  55. // Probably ESP8266 or ESP32. USE_FAST_PINIO is not available here (yet)
  56. // but don't worry about it too much...the digitalWrite() implementation
  57. // on these platforms is reasonably efficient and already RAM-resident,
  58. // only gotcha then is no parallel connection support for now.
  59. typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
  60. #endif // end !ARM
  61. typedef volatile ADAGFX_PORT_t *PORTreg_t; ///< PORT register type
  62. #if defined(__AVR__)
  63. #define DEFAULT_SPI_FREQ 8000000L ///< Hardware SPI default speed
  64. #else
  65. #define DEFAULT_SPI_FREQ 16000000L ///< Hardware SPI default speed
  66. #endif
  67. #if defined(ADAFRUIT_PYPORTAL) || defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || \
  68. defined(ADAFRUIT_PYGAMER_M4_EXPRESS) || \
  69. defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) || defined(NRF52_SERIES) || \
  70. defined(ADAFRUIT_CIRCUITPLAYGROUND_M0)
  71. #define USE_SPI_DMA ///< Auto DMA
  72. #else
  73. //#define USE_SPI_DMA ///< If set,
  74. // use DMA if available
  75. #endif
  76. // Another "oops" name -- this now also handles parallel DMA.
  77. // If DMA is enabled, Arduino sketch MUST #include <Adafruit_ZeroDMA.h>
  78. // Estimated RAM usage:
  79. // 4 bytes/pixel on display major axis + 8 bytes/pixel on minor axis,
  80. // e.g. 320x240 pixels = 320 * 4 + 240 * 8 = 3,200 bytes.
  81. #if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO))
  82. #include <Adafruit_ZeroDMA.h>
  83. #endif
  84. // This is kind of a kludge. Needed a way to disambiguate the software SPI
  85. // and parallel constructors via their argument lists. Originally tried a
  86. // bool as the first argument to the parallel constructor (specifying 8-bit
  87. // vs 16-bit interface) but the compiler regards this as equivalent to an
  88. // integer and thus still ambiguous. SO...the parallel constructor requires
  89. // an enumerated type as the first argument: tft8 (for 8-bit parallel) or
  90. // tft16 (for 16-bit)...even though 16-bit isn't fully implemented or tested
  91. // and might never be, still needed that disambiguation from soft SPI.
  92. /*! For first arg to parallel constructor */
  93. enum tftBusWidth { tft8bitbus, tft16bitbus };
  94. // CLASS DEFINITION --------------------------------------------------------
  95. /*!
  96. @brief Adafruit_SPITFT is an intermediary class between Adafruit_GFX
  97. and various hardware-specific subclasses for different displays.
  98. It handles certain operations that are common to a range of
  99. displays (address window, area fills, etc.). Originally these were
  100. all color TFT displays interfaced via SPI, but it's since expanded
  101. to include color OLEDs and parallel-interfaced TFTs. THE NAME HAS
  102. BEEN KEPT TO AVOID BREAKING A LOT OF SUBCLASSES AND EXAMPLE CODE.
  103. Many of the class member functions similarly live on with names
  104. that don't necessarily accurately describe what they're doing,
  105. again to avoid breaking a lot of other code. If in doubt, read
  106. the comments.
  107. */
  108. class Adafruit_SPITFT : public Adafruit_GFX {
  109. public:
  110. // CONSTRUCTORS --------------------------------------------------------
  111. // Software SPI constructor: expects width & height (at default rotation
  112. // setting 0), 4 signal pins (cs, dc, mosi, sclk), 2 optional pins
  113. // (reset, miso). cs argument is required but can be -1 if unused --
  114. // rather than moving it to the optional arguments, it was done this way
  115. // to avoid breaking existing code (-1 option was a later addition).
  116. Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc, int8_t mosi,
  117. int8_t sck, int8_t rst = -1, int8_t miso = -1);
  118. // Hardware SPI constructor using the default SPI port: expects width &
  119. // height (at default rotation setting 0), 2 signal pins (cs, dc),
  120. // optional reset pin. cs is required but can be -1 if unused -- rather
  121. // than moving it to the optional arguments, it was done this way to
  122. // avoid breaking existing code (-1 option was a later addition).
  123. Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc,
  124. int8_t rst = -1);
  125. #if !defined(ESP8266) // See notes in .cpp
  126. // Hardware SPI constructor using an arbitrary SPI peripheral: expects
  127. // width & height (rotation 0), SPIClass pointer, 2 signal pins (cs, dc)
  128. // and optional reset pin. cs is required but can be -1 if unused.
  129. Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs,
  130. int8_t dc, int8_t rst = -1);
  131. #endif // end !ESP8266
  132. // Parallel constructor: expects width & height (rotation 0), flag
  133. // indicating whether 16-bit (true) or 8-bit (false) interface, 3 signal
  134. // pins (d0, wr, dc), 3 optional pins (cs, rst, rd). 16-bit parallel
  135. // isn't even fully implemented but the 'wide' flag was added as a
  136. // required argument to avoid ambiguity with other constructors.
  137. Adafruit_SPITFT(uint16_t w, uint16_t h, tftBusWidth busWidth, int8_t d0,
  138. int8_t wr, int8_t dc, int8_t cs = -1, int8_t rst = -1,
  139. int8_t rd = -1);
  140. // CLASS MEMBER FUNCTIONS ----------------------------------------------
  141. // These first two functions MUST be declared by subclasses:
  142. /*!
  143. @brief Display-specific initialization function.
  144. @param freq SPI frequency, in hz (or 0 for default or unused).
  145. */
  146. virtual void begin(uint32_t freq) = 0;
  147. /*!
  148. @brief Set up the specific display hardware's "address window"
  149. for subsequent pixel-pushing operations.
  150. @param x Leftmost pixel of area to be drawn (MUST be within
  151. display bounds at current rotation setting).
  152. @param y Topmost pixel of area to be drawn (MUST be within
  153. display bounds at current rotation setting).
  154. @param w Width of area to be drawn, in pixels (MUST be >0 and,
  155. added to x, within display bounds at current rotation).
  156. @param h Height of area to be drawn, in pixels (MUST be >0 and,
  157. added to x, within display bounds at current rotation).
  158. */
  159. virtual void setAddrWindow(uint16_t x, uint16_t y, uint16_t w,
  160. uint16_t h) = 0;
  161. // Remaining functions do not need to be declared in subclasses
  162. // unless they wish to provide hardware-specific optimizations.
  163. // Brief comments here...documented more thoroughly in .cpp file.
  164. // Subclass' begin() function invokes this to initialize hardware.
  165. // freq=0 to use default SPI speed. spiMode must be one of the SPI_MODEn
  166. // values defined in SPI.h, which are NOT the same as 0 for SPI_MODE0,
  167. // 1 for SPI_MODE1, etc...use ONLY the SPI_MODEn defines! Only!
  168. // Name is outdated (interface may be parallel) but for compatibility:
  169. void initSPI(uint32_t freq = 0, uint8_t spiMode = SPI_MODE0);
  170. void setSPISpeed(uint32_t freq);
  171. // Chip select and/or hardware SPI transaction start as needed:
  172. void startWrite(void);
  173. // Chip deselect and/or hardware SPI transaction end as needed:
  174. void endWrite(void);
  175. void sendCommand(uint8_t commandByte, uint8_t *dataBytes,
  176. uint8_t numDataBytes);
  177. void sendCommand(uint8_t commandByte, const uint8_t *dataBytes = NULL,
  178. uint8_t numDataBytes = 0);
  179. void sendCommand16(uint16_t commandWord, const uint8_t *dataBytes = NULL,
  180. uint8_t numDataBytes = 0);
  181. uint8_t readcommand8(uint8_t commandByte, uint8_t index = 0);
  182. uint16_t readcommand16(uint16_t addr);
  183. // These functions require a chip-select and/or SPI transaction
  184. // around them. Higher-level graphics primitives might start a
  185. // single transaction and then make multiple calls to these functions
  186. // (e.g. circle or text rendering might make repeated lines or rects)
  187. // before ending the transaction. It's more efficient than starting a
  188. // transaction every time.
  189. void writePixel(int16_t x, int16_t y, uint16_t color);
  190. void writePixels(uint16_t *colors, uint32_t len, bool block = true,
  191. bool bigEndian = false);
  192. void writeColor(uint16_t color, uint32_t len);
  193. void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
  194. uint16_t color);
  195. void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
  196. void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
  197. // This is a new function, similar to writeFillRect() except that
  198. // all arguments MUST be onscreen, sorted and clipped. If higher-level
  199. // primitives can handle their own sorting/clipping, it avoids repeating
  200. // such operations in the low-level code, making it potentially faster.
  201. // CALLING THIS WITH UNCLIPPED OR NEGATIVE VALUES COULD BE DISASTROUS.
  202. inline void writeFillRectPreclipped(int16_t x, int16_t y, int16_t w,
  203. int16_t h, uint16_t color);
  204. // Another new function, companion to the new non-blocking
  205. // writePixels() variant.
  206. void dmaWait(void);
  207. // These functions are similar to the 'write' functions above, but with
  208. // a chip-select and/or SPI transaction built-in. They're typically used
  209. // solo -- that is, as graphics primitives in themselves, not invoked by
  210. // higher-level primitives (which should use the functions above).
  211. void drawPixel(int16_t x, int16_t y, uint16_t color);
  212. void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
  213. void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
  214. void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
  215. // A single-pixel push encapsulated in a transaction. I don't think
  216. // this is used anymore (BMP demos might've used it?) but is provided
  217. // for backward compatibility, consider it deprecated:
  218. void pushColor(uint16_t color);
  219. using Adafruit_GFX::drawRGBBitmap; // Check base class first
  220. void drawRGBBitmap(int16_t x, int16_t y, uint16_t *pcolors, int16_t w,
  221. int16_t h);
  222. void invertDisplay(bool i);
  223. uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
  224. // Despite parallel additions, function names kept for compatibility:
  225. void spiWrite(uint8_t b); // Write single byte as DATA
  226. void writeCommand(uint8_t cmd); // Write single byte as COMMAND
  227. uint8_t spiRead(void); // Read single byte of data
  228. void write16(uint16_t w); // Write 16-bit value as DATA
  229. void writeCommand16(uint16_t cmd); // Write 16-bit value as COMMAND
  230. uint16_t read16(void); // Read single 16-bit value
  231. // Most of these low-level functions were formerly macros in
  232. // Adafruit_SPITFT_Macros.h. Some have been made into inline functions
  233. // to avoid macro mishaps. Despite the addition of code for a parallel
  234. // display interface, the names have been kept for backward
  235. // compatibility (some subclasses may be invoking these):
  236. void SPI_WRITE16(uint16_t w); // Not inline
  237. void SPI_WRITE32(uint32_t l); // Not inline
  238. // Old code had both a spiWrite16() function and SPI_WRITE16 macro
  239. // in addition to the SPI_WRITE32 macro. The latter two have been
  240. // made into functions here, and spiWrite16() removed (use SPI_WRITE16()
  241. // instead). It looks like most subclasses had gotten comfortable with
  242. // SPI_WRITE16 and SPI_WRITE32 anyway so those names were kept rather
  243. // than the less-obnoxious camelcase variants, oh well.
  244. // Placing these functions entirely in the class definition inlines
  245. // them implicitly them while allowing their use in other code:
  246. /*!
  247. @brief Set the chip-select line HIGH. Does NOT check whether CS pin
  248. is set (>=0), that should be handled in calling function.
  249. Despite function name, this is used even if the display
  250. connection is parallel.
  251. */
  252. void SPI_CS_HIGH(void) {
  253. #if defined(USE_FAST_PINIO)
  254. #if defined(HAS_PORT_SET_CLR)
  255. #if defined(KINETISK)
  256. *csPortSet = 1;
  257. #else // !KINETISK
  258. *csPortSet = csPinMask;
  259. #endif // end !KINETISK
  260. #else // !HAS_PORT_SET_CLR
  261. *csPort |= csPinMaskSet;
  262. #endif // end !HAS_PORT_SET_CLR
  263. #else // !USE_FAST_PINIO
  264. digitalWrite(_cs, HIGH);
  265. #endif // end !USE_FAST_PINIO
  266. }
  267. /*!
  268. @brief Set the chip-select line LOW. Does NOT check whether CS pin
  269. is set (>=0), that should be handled in calling function.
  270. Despite function name, this is used even if the display
  271. connection is parallel.
  272. */
  273. void SPI_CS_LOW(void) {
  274. #if defined(USE_FAST_PINIO)
  275. #if defined(HAS_PORT_SET_CLR)
  276. #if defined(KINETISK)
  277. *csPortClr = 1;
  278. #else // !KINETISK
  279. *csPortClr = csPinMask;
  280. #endif // end !KINETISK
  281. #else // !HAS_PORT_SET_CLR
  282. *csPort &= csPinMaskClr;
  283. #endif // end !HAS_PORT_SET_CLR
  284. #else // !USE_FAST_PINIO
  285. digitalWrite(_cs, LOW);
  286. #endif // end !USE_FAST_PINIO
  287. }
  288. /*!
  289. @brief Set the data/command line HIGH (data mode).
  290. */
  291. void SPI_DC_HIGH(void) {
  292. #if defined(USE_FAST_PINIO)
  293. #if defined(HAS_PORT_SET_CLR)
  294. #if defined(KINETISK)
  295. *dcPortSet = 1;
  296. #else // !KINETISK
  297. *dcPortSet = dcPinMask;
  298. #endif // end !KINETISK
  299. #else // !HAS_PORT_SET_CLR
  300. *dcPort |= dcPinMaskSet;
  301. #endif // end !HAS_PORT_SET_CLR
  302. #else // !USE_FAST_PINIO
  303. digitalWrite(_dc, HIGH);
  304. #endif // end !USE_FAST_PINIO
  305. }
  306. /*!
  307. @brief Set the data/command line LOW (command mode).
  308. */
  309. void SPI_DC_LOW(void) {
  310. #if defined(USE_FAST_PINIO)
  311. #if defined(HAS_PORT_SET_CLR)
  312. #if defined(KINETISK)
  313. *dcPortClr = 1;
  314. #else // !KINETISK
  315. *dcPortClr = dcPinMask;
  316. #endif // end !KINETISK
  317. #else // !HAS_PORT_SET_CLR
  318. *dcPort &= dcPinMaskClr;
  319. #endif // end !HAS_PORT_SET_CLR
  320. #else // !USE_FAST_PINIO
  321. digitalWrite(_dc, LOW);
  322. #endif // end !USE_FAST_PINIO
  323. }
  324. protected:
  325. // A few more low-level member functions -- some may have previously
  326. // been macros. Shouldn't have a need to access these externally, so
  327. // they've been moved to the protected section. Additionally, they're
  328. // declared inline here and the code is in the .cpp file, since outside
  329. // code doesn't need to see these.
  330. inline void SPI_MOSI_HIGH(void);
  331. inline void SPI_MOSI_LOW(void);
  332. inline void SPI_SCK_HIGH(void);
  333. inline void SPI_SCK_LOW(void);
  334. inline bool SPI_MISO_READ(void);
  335. inline void SPI_BEGIN_TRANSACTION(void);
  336. inline void SPI_END_TRANSACTION(void);
  337. inline void TFT_WR_STROBE(void); // Parallel interface write strobe
  338. inline void TFT_RD_HIGH(void); // Parallel interface read high
  339. inline void TFT_RD_LOW(void); // Parallel interface read low
  340. // CLASS INSTANCE VARIABLES --------------------------------------------
  341. // Here be dragons! There's a big union of three structures here --
  342. // one each for hardware SPI, software (bitbang) SPI, and parallel
  343. // interfaces. This is to save some memory, since a display's connection
  344. // will be only one of these. The order of some things is a little weird
  345. // in an attempt to get values to align and pack better in RAM.
  346. #if defined(USE_FAST_PINIO)
  347. #if defined(HAS_PORT_SET_CLR)
  348. PORTreg_t csPortSet; ///< PORT register for chip select SET
  349. PORTreg_t csPortClr; ///< PORT register for chip select CLEAR
  350. PORTreg_t dcPortSet; ///< PORT register for data/command SET
  351. PORTreg_t dcPortClr; ///< PORT register for data/command CLEAR
  352. #else // !HAS_PORT_SET_CLR
  353. PORTreg_t csPort; ///< PORT register for chip select
  354. PORTreg_t dcPort; ///< PORT register for data/command
  355. #endif // end HAS_PORT_SET_CLR
  356. #endif // end USE_FAST_PINIO
  357. #if defined(__cplusplus) && (__cplusplus >= 201100)
  358. union {
  359. #endif
  360. struct { // Values specific to HARDWARE SPI:
  361. SPIClass *_spi; ///< SPI class pointer
  362. #if defined(SPI_HAS_TRANSACTION)
  363. SPISettings settings; ///< SPI transaction settings
  364. #else
  365. uint32_t _freq; ///< SPI bitrate (if no SPI transactions)
  366. #endif
  367. uint32_t _mode; ///< SPI data mode (transactions or no)
  368. } hwspi; ///< Hardware SPI values
  369. struct { // Values specific to SOFTWARE SPI:
  370. #if defined(USE_FAST_PINIO)
  371. PORTreg_t misoPort; ///< PORT (PIN) register for MISO
  372. #if defined(HAS_PORT_SET_CLR)
  373. PORTreg_t mosiPortSet; ///< PORT register for MOSI SET
  374. PORTreg_t mosiPortClr; ///< PORT register for MOSI CLEAR
  375. PORTreg_t sckPortSet; ///< PORT register for SCK SET
  376. PORTreg_t sckPortClr; ///< PORT register for SCK CLEAR
  377. #if !defined(KINETISK)
  378. ADAGFX_PORT_t mosiPinMask; ///< Bitmask for MOSI
  379. ADAGFX_PORT_t sckPinMask; ///< Bitmask for SCK
  380. #endif // end !KINETISK
  381. #else // !HAS_PORT_SET_CLR
  382. PORTreg_t mosiPort; ///< PORT register for MOSI
  383. PORTreg_t sckPort; ///< PORT register for SCK
  384. ADAGFX_PORT_t mosiPinMaskSet; ///< Bitmask for MOSI SET (OR)
  385. ADAGFX_PORT_t mosiPinMaskClr; ///< Bitmask for MOSI CLEAR (AND)
  386. ADAGFX_PORT_t sckPinMaskSet; ///< Bitmask for SCK SET (OR bitmask)
  387. ADAGFX_PORT_t sckPinMaskClr; ///< Bitmask for SCK CLEAR (AND)
  388. #endif // end HAS_PORT_SET_CLR
  389. #if !defined(KINETISK)
  390. ADAGFX_PORT_t misoPinMask; ///< Bitmask for MISO
  391. #endif // end !KINETISK
  392. #endif // end USE_FAST_PINIO
  393. int8_t _mosi; ///< MOSI pin #
  394. int8_t _miso; ///< MISO pin #
  395. int8_t _sck; ///< SCK pin #
  396. } swspi; ///< Software SPI values
  397. struct { // Values specific to 8-bit parallel:
  398. #if defined(USE_FAST_PINIO)
  399. #if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
  400. volatile uint32_t *writePort; ///< PORT register for DATA WRITE
  401. volatile uint32_t *readPort; ///< PORT (PIN) register for DATA READ
  402. #else
  403. volatile uint8_t *writePort; ///< PORT register for DATA WRITE
  404. volatile uint8_t *readPort; ///< PORT (PIN) register for DATA READ
  405. #endif
  406. #if defined(HAS_PORT_SET_CLR)
  407. // Port direction register pointers are always 8-bit regardless of
  408. // PORTreg_t -- even if 32-bit port, we modify a byte-aligned 8 bits.
  409. #if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
  410. volatile uint32_t *dirSet; ///< PORT byte data direction SET
  411. volatile uint32_t *dirClr; ///< PORT byte data direction CLEAR
  412. #else
  413. volatile uint8_t *dirSet; ///< PORT byte data direction SET
  414. volatile uint8_t *dirClr; ///< PORT byte data direction CLEAR
  415. #endif
  416. PORTreg_t wrPortSet; ///< PORT register for write strobe SET
  417. PORTreg_t wrPortClr; ///< PORT register for write strobe CLEAR
  418. PORTreg_t rdPortSet; ///< PORT register for read strobe SET
  419. PORTreg_t rdPortClr; ///< PORT register for read strobe CLEAR
  420. #if !defined(KINETISK)
  421. ADAGFX_PORT_t wrPinMask; ///< Bitmask for write strobe
  422. #endif // end !KINETISK
  423. ADAGFX_PORT_t rdPinMask; ///< Bitmask for read strobe
  424. #else // !HAS_PORT_SET_CLR
  425. // Port direction register pointer is always 8-bit regardless of
  426. // PORTreg_t -- even if 32-bit port, we modify a byte-aligned 8 bits.
  427. volatile uint8_t *portDir; ///< PORT direction register
  428. PORTreg_t wrPort; ///< PORT register for write strobe
  429. PORTreg_t rdPort; ///< PORT register for read strobe
  430. ADAGFX_PORT_t wrPinMaskSet; ///< Bitmask for write strobe SET (OR)
  431. ADAGFX_PORT_t wrPinMaskClr; ///< Bitmask for write strobe CLEAR (AND)
  432. ADAGFX_PORT_t rdPinMaskSet; ///< Bitmask for read strobe SET (OR)
  433. ADAGFX_PORT_t rdPinMaskClr; ///< Bitmask for read strobe CLEAR (AND)
  434. #endif // end HAS_PORT_SET_CLR
  435. #endif // end USE_FAST_PINIO
  436. int8_t _d0; ///< Data pin 0 #
  437. int8_t _wr; ///< Write strobe pin #
  438. int8_t _rd; ///< Read strobe pin # (or -1)
  439. bool wide = 0; ///< If true, is 16-bit interface
  440. } tft8; ///< Parallel interface settings
  441. #if defined(__cplusplus) && (__cplusplus >= 201100)
  442. }; ///< Only one interface is active
  443. #endif
  444. #if defined(USE_SPI_DMA) && \
  445. (defined(__SAMD51__) || \
  446. defined(ARDUINO_SAMD_ZERO)) // Used by hardware SPI and tft8
  447. Adafruit_ZeroDMA dma; ///< DMA instance
  448. DmacDescriptor *dptr = NULL; ///< 1st descriptor
  449. DmacDescriptor *descriptor = NULL; ///< Allocated descriptor list
  450. uint16_t *pixelBuf[2]; ///< Working buffers
  451. uint16_t maxFillLen; ///< Max pixels per DMA xfer
  452. uint16_t lastFillColor = 0; ///< Last color used w/fill
  453. uint32_t lastFillLen = 0; ///< # of pixels w/last fill
  454. uint8_t onePixelBuf; ///< For hi==lo fill
  455. #endif
  456. #if defined(USE_FAST_PINIO)
  457. #if defined(HAS_PORT_SET_CLR)
  458. #if !defined(KINETISK)
  459. ADAGFX_PORT_t csPinMask; ///< Bitmask for chip select
  460. ADAGFX_PORT_t dcPinMask; ///< Bitmask for data/command
  461. #endif // end !KINETISK
  462. #else // !HAS_PORT_SET_CLR
  463. ADAGFX_PORT_t csPinMaskSet; ///< Bitmask for chip select SET (OR)
  464. ADAGFX_PORT_t csPinMaskClr; ///< Bitmask for chip select CLEAR (AND)
  465. ADAGFX_PORT_t dcPinMaskSet; ///< Bitmask for data/command SET (OR)
  466. ADAGFX_PORT_t dcPinMaskClr; ///< Bitmask for data/command CLEAR (AND)
  467. #endif // end HAS_PORT_SET_CLR
  468. #endif // end USE_FAST_PINIO
  469. uint8_t connection; ///< TFT_HARD_SPI, TFT_SOFT_SPI, etc.
  470. int8_t _rst; ///< Reset pin # (or -1)
  471. int8_t _cs; ///< Chip select pin # (or -1)
  472. int8_t _dc; ///< Data/command pin #
  473. int16_t _xstart = 0; ///< Internal framebuffer X offset
  474. int16_t _ystart = 0; ///< Internal framebuffer Y offset
  475. uint8_t invertOnCommand = 0; ///< Command to enable invert mode
  476. uint8_t invertOffCommand = 0; ///< Command to disable invert mode
  477. uint32_t _freq = 0; ///< Dummy var to keep subclasses happy
  478. };
  479. #endif // end __AVR_ATtiny85__
  480. #endif // end _ADAFRUIT_SPITFT_H_