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_RPiPicoSPI.h (2141B)

      1 #if defined(TARGET_RP2040)
      2 
      3 #ifndef _ARDUINO_RPIPICOSPI_H_
      4 #define _ARDUINO_RPIPICOSPI_H_
      5 
      6 #include <api/HardwareSPI.h>
      7 #include <hardware/spi.h>
      8 
      9 #include "Arduino_DataBus.h"
     10 
     11 #define SPI_MAX_PIXELS_AT_ONCE 32
     12 
     13 class Arduino_RPiPicoSPI : public Arduino_DataBus
     14 {
     15 public:
     16   Arduino_RPiPicoSPI(int8_t dc = GFX_NOT_DEFINED, int8_t cs = GFX_NOT_DEFINED, int8_t sck = PIN_SPI0_SCK, int8_t mosi = PIN_SPI0_MOSI, int8_t miso = PIN_SPI0_MISO, spi_inst_t *spi = spi0); // Constructor
     17 
     18   bool begin(int32_t speed = GFX_NOT_DEFINED, int8_t dataMode = GFX_NOT_DEFINED) override;
     19   void beginWrite() override;
     20   void endWrite() override;
     21   void writeCommand(uint8_t) override;
     22   void writeCommand16(uint16_t) override;
     23   void write(uint8_t) override;
     24   void write16(uint16_t) override;
     25   void writeRepeat(uint16_t p, uint32_t len) override;
     26   void writePixels(uint16_t *data, uint32_t len) override;
     27 
     28   void writeC8D8(uint8_t c, uint8_t d) override;
     29   void writeC8D16(uint8_t c, uint16_t d) override;
     30   void writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2) override;
     31   void writeBytes(uint8_t *data, uint32_t len) override;
     32   void writePattern(uint8_t *data, uint8_t len, uint32_t repeat) override;
     33 
     34 protected:
     35 
     36 private:
     37   INLINE void WRITE(uint8_t d);
     38   INLINE void WRITE16(uint16_t d);
     39   INLINE void WRITEBUF(uint8_t *buf, size_t count);
     40   INLINE void DC_HIGH(void);
     41   INLINE void DC_LOW(void);
     42   INLINE void CS_HIGH(void);
     43   INLINE void CS_LOW(void);
     44 
     45   int8_t _dc, _cs;
     46   int8_t _sck, _mosi, _miso;
     47   int32_t _speed;
     48 
     49   PORTreg_t _dcPortSet; ///< PORT register for data/command SET
     50   PORTreg_t _dcPortClr; ///< PORT register for data/command CLEAR
     51   PORTreg_t _csPortSet; ///< PORT register for chip select SET
     52   PORTreg_t _csPortClr; ///< PORT register for chip select CLEAR
     53   uint32_t _dcPinMask;  ///< Bitmask for data/command
     54   uint32_t _csPinMask;  ///< Bitmask for chip select
     55 
     56   spi_inst_t *_spi;
     57   SPISettings _spis;
     58   BitOrder _bitOrder = MSBFIRST;
     59 
     60   union
     61   {
     62     uint8_t _buffer[SPI_MAX_PIXELS_AT_ONCE * 2];
     63     uint16_t _buffer16[SPI_MAX_PIXELS_AT_ONCE];
     64   };
     65 };
     66 
     67 #endif // _ARDUINO_RPIPICOSPI_H_
     68 #endif // #if defined(TARGET_RP2040)