acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

Arduino_HWSPI.h (3969B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  */
      5 #ifndef _ARDUINO_HWSPI_H_
      6 #define _ARDUINO_HWSPI_H_
      7 
      8 #include <SPI.h>
      9 #include "Arduino_DataBus.h"
     10 
     11 #if !defined(LITTLE_FOOT_PRINT)
     12 #define SPI_MAX_PIXELS_AT_ONCE 32
     13 #endif
     14 
     15 // HARDWARE CONFIG ---------------------------------------------------------
     16 
     17 class Arduino_HWSPI : public Arduino_DataBus
     18 {
     19 public:
     20 #if defined(ESP32)
     21   Arduino_HWSPI(int8_t dc, int8_t cs = GFX_NOT_DEFINED, int8_t sck = GFX_NOT_DEFINED, int8_t mosi = GFX_NOT_DEFINED, int8_t miso = GFX_NOT_DEFINED, SPIClass *spi = &SPI, bool is_shared_interface = true); // Constructor
     22 #elif defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS)
     23   Arduino_HWSPI(int8_t dc, int8_t cs = GFX_NOT_DEFINED, SPIClass *spi = &LCD_SPI, bool is_shared_interface = true); // Constructor
     24 #elif defined(RTL8722DM) && defined(BOARD_RTL8722DM)
     25   Arduino_HWSPI(int8_t dc, int8_t cs = GFX_NOT_DEFINED, SPIClass *spi = &SPI1, bool is_shared_interface = true); // Constructor
     26 #else
     27   Arduino_HWSPI(int8_t dc, int8_t cs = GFX_NOT_DEFINED, SPIClass *spi = &SPI, bool is_shared_interface = true); // Constructor
     28 #endif
     29 
     30   bool begin(int32_t speed = GFX_NOT_DEFINED, int8_t dataMode = GFX_NOT_DEFINED) override;
     31   void beginWrite() override;
     32   void endWrite() override;
     33   void writeCommand(uint8_t) override;
     34   void writeCommand16(uint16_t) override;
     35   void write(uint8_t) override;
     36   void write16(uint16_t) override;
     37   void writeRepeat(uint16_t p, uint32_t len) override;
     38   void writePixels(uint16_t *data, uint32_t len) override;
     39 
     40 #if !defined(LITTLE_FOOT_PRINT)
     41   void writeBytes(uint8_t *data, uint32_t len) override;
     42   void writePattern(uint8_t *data, uint8_t len, uint32_t repeat) override;
     43 #endif // !defined(LITTLE_FOOT_PRINT)
     44 
     45 private:
     46   INLINE void WRITE(uint8_t d);
     47 #if !defined(LITTLE_FOOT_PRINT)
     48   INLINE void WRITE16(uint16_t d);
     49   INLINE void WRITEBUF(uint8_t *buf, size_t count);
     50 #endif // !defined(LITTLE_FOOT_PRINT)
     51   INLINE void DC_HIGH(void);
     52   INLINE void DC_LOW(void);
     53   INLINE void CS_HIGH(void);
     54   INLINE void CS_LOW(void);
     55 
     56 
     57   int8_t _dc, _cs;
     58 #if defined(ESP32)
     59   int8_t _sck, _mosi, _miso;
     60 #endif
     61   SPIClass *_spi;
     62   bool _is_shared_interface;
     63 
     64   // CLASS INSTANCE VARIABLES --------------------------------------------
     65 
     66   // Here be dragons! There's a big union of three structures here --
     67   // one each for hardware SPI, software (bitbang) SPI, and parallel
     68   // interfaces. This is to save some memory, since a display's connection
     69   // will be only one of these. The order of some things is a little weird
     70   // in an attempt to get values to align and pack better in RAM.
     71 
     72 #if defined(USE_FAST_PINIO)
     73 #if defined(HAS_PORT_SET_CLR)
     74   PORTreg_t _csPortSet; ///< PORT register for chip select SET
     75   PORTreg_t _csPortClr; ///< PORT register for chip select CLEAR
     76   PORTreg_t _dcPortSet; ///< PORT register for data/command SET
     77   PORTreg_t _dcPortClr; ///< PORT register for data/command CLEAR
     78 #if !defined(KINETISK)
     79   ARDUINOGFX_PORT_t _csPinMask; ///< Bitmask for chip select
     80   ARDUINOGFX_PORT_t _dcPinMask; ///< Bitmask for data/command
     81 #endif                          // !KINETISK
     82 #else                           // !HAS_PORT_SET_CLR
     83   PORTreg_t _csPort;               ///< PORT register for chip select
     84   PORTreg_t _dcPort;               ///< PORT register for data/command
     85   ARDUINOGFX_PORT_t _csPinMaskSet; ///< Bitmask for chip select SET (OR)
     86   ARDUINOGFX_PORT_t _csPinMaskClr; ///< Bitmask for chip select CLEAR (AND)
     87   ARDUINOGFX_PORT_t _dcPinMaskSet; ///< Bitmask for data/command SET (OR)
     88   ARDUINOGFX_PORT_t _dcPinMaskClr; ///< Bitmask for data/command CLEAR (AND)
     89 #endif                          // HAS_PORT_SET_CLR
     90 #endif                          // !defined(USE_FAST_PINIO)
     91 
     92 #if !defined(LITTLE_FOOT_PRINT)
     93   union
     94   {
     95     uint8_t v8[SPI_MAX_PIXELS_AT_ONCE * 2] = {0};
     96     uint16_t v16[SPI_MAX_PIXELS_AT_ONCE];
     97   } _buffer;
     98 #endif // !defined(LITTLE_FOOT_PRINT)
     99 };
    100 
    101 #endif // _ARDUINO_HWSPI_H_