Adafruit_SPITFT.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef _ADAFRUIT_SPITFT_
  2. #define _ADAFRUIT_SPITFT_
  3. #if ARDUINO >= 100
  4. #include "Arduino.h"
  5. #include "Print.h"
  6. #else
  7. #include "WProgram.h"
  8. #endif
  9. #include <SPI.h>
  10. #include "Adafruit_GFX.h"
  11. #if defined(ARDUINO_STM32_FEATHER)
  12. typedef volatile uint32 RwReg;
  13. #endif
  14. #if defined(ARDUINO_FEATHER52)
  15. typedef volatile uint32_t RwReg;
  16. #endif
  17. class Adafruit_SPITFT : public Adafruit_GFX {
  18. protected:
  19. public:
  20. Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
  21. Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _RST = -1);
  22. virtual void begin(uint32_t freq) = 0;
  23. void initSPI(uint32_t freq);
  24. // Required Non-Transaction
  25. void drawPixel(int16_t x, int16_t y, uint16_t color);
  26. // Transaction API
  27. void startWrite(void);
  28. void endWrite(void);
  29. void writePixel(int16_t x, int16_t y, uint16_t color);
  30. void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
  31. void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
  32. void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
  33. // Transaction API not used by GFX
  34. virtual void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) = 0;
  35. void writePixel(uint16_t color);
  36. void writePixels(uint16_t * colors, uint32_t len);
  37. void writeColor(uint16_t color, uint32_t len);
  38. void pushColor(uint16_t color);
  39. // Recommended Non-Transaction
  40. void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
  41. void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
  42. void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
  43. using Adafruit_GFX::drawRGBBitmap; // Check base class first
  44. void drawRGBBitmap(int16_t x, int16_t y,
  45. uint16_t *pcolors, int16_t w, int16_t h);
  46. uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
  47. protected:
  48. uint32_t _freq;
  49. #if defined (__AVR__) || defined(TEENSYDUINO) || defined (ESP8266) || defined (ESP32)
  50. int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
  51. #else
  52. int32_t _cs, _dc, _rst, _sclk, _mosi, _miso;
  53. #endif
  54. #ifdef USE_FAST_PINIO
  55. volatile RwReg *mosiport, *misoport, *clkport, *dcport, *csport;
  56. RwReg mosipinmask, misopinmask, clkpinmask, cspinmask, dcpinmask;
  57. #endif
  58. void writeCommand(uint8_t cmd);
  59. void spiWrite(uint8_t v);
  60. uint8_t spiRead(void);
  61. };
  62. #endif