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_NRFXSPI.h (2189B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/arduino/ArduinoCore-mbed/blob/master/libraries/SPI/SPI.cpp
      4  */
      5 #ifdef ARDUINO_ARCH_NRF52840
      6 
      7 #ifndef _ARDUINO_NRFXSPI_H_
      8 #define _ARDUINO_NRFXSPI_H_
      9 
     10 #include <SPI.h>
     11 
     12 #include "Arduino_DataBus.h"
     13 
     14 #define SPI_MAX_PIXELS_AT_ONCE 32
     15 
     16 class Arduino_NRFXSPI : public Arduino_DataBus
     17 {
     18 public:
     19   Arduino_NRFXSPI(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); // Constructor
     20 
     21   bool begin(int32_t speed = GFX_NOT_DEFINED, int8_t dataMode = GFX_NOT_DEFINED) override;
     22   void beginWrite() override;
     23   void endWrite() override;
     24   void writeCommand(uint8_t) override;
     25   void writeCommand16(uint16_t) override;
     26   void write(uint8_t) override;
     27   void write16(uint16_t) override;
     28   void writeRepeat(uint16_t p, uint32_t len) override;
     29   void writePixels(uint16_t *data, uint32_t len) override;
     30 
     31   void writeC8D8(uint8_t c, uint8_t d) override;
     32   void writeC8D16(uint8_t c, uint16_t d) override;
     33   void writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2) override;
     34   void writeBytes(uint8_t *data, uint32_t len) override;
     35   void writePattern(uint8_t *data, uint8_t len, uint32_t repeat) override;
     36 
     37 private:
     38   INLINE void WRITE(uint8_t d);
     39   INLINE void WRITE16(uint16_t d);
     40   INLINE void WRITEBUF(uint8_t *buf, size_t count);
     41   INLINE void DC_HIGH(void);
     42   INLINE void DC_LOW(void);
     43   INLINE void CS_HIGH(void);
     44   INLINE void CS_LOW(void);
     45 
     46   int8_t _dc, _cs;
     47   int8_t _sck, _mosi, _miso;
     48 
     49   PORTreg_t _csPortSet; ///< PORT register for chip select SET
     50   PORTreg_t _csPortClr; ///< PORT register for chip select CLEAR
     51   PORTreg_t _dcPortSet; ///< PORT register for data/command SET
     52   PORTreg_t _dcPortClr; ///< PORT register for data/command CLEAR
     53   ARDUINOGFX_PORT_t _csPinMask; ///< Bitmask for chip select
     54   ARDUINOGFX_PORT_t _dcPinMask; ///< Bitmask for data/command
     55 
     56   nrfx_spi_config_t _nrfxSpiConfig = NRFX_SPI_DEFAULT_CONFIG;
     57   nrfx_spi_t _nrfxSpi = NRFX_SPI_INSTANCE(0);
     58 
     59   union
     60   {
     61     uint8_t _buffer[SPI_MAX_PIXELS_AT_ONCE * 2];
     62     uint16_t _buffer16[SPI_MAX_PIXELS_AT_ONCE];
     63   };
     64 };
     65 
     66 #endif // _ARDUINO_NRFXSPI_H_
     67 
     68 #endif // #ifdef ARDUINO_ARCH_NRF52840