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

TFT_eSPI_Generic.h (7461B)

      1         ////////////////////////////////////////////////////
      2         //       TFT_eSPI generic driver functions        //
      3         ////////////////////////////////////////////////////
      4 
      5 // This is a generic driver for Arduino boards, it supports SPI interface displays
      6 // 8 bit parallel interface to TFT is not supported for generic processors
      7 
      8 #ifndef _TFT_eSPI_GENERICH_
      9 #define _TFT_eSPI_GENERICH_
     10 
     11 // Processor ID reported by getSetup()
     12 #define PROCESSOR_ID 0x0000
     13 
     14 // Include processor specific header
     15 // None
     16 
     17 // Processor specific code used by SPI bus transaction startWrite and endWrite functions
     18 #define SET_BUS_WRITE_MODE // Not used
     19 #define SET_BUS_READ_MODE  // Not used
     20 
     21 // Code to check if DMA is busy, used by SPI bus transaction startWrite and endWrite functions
     22 #define DMA_BUSY_CHECK // Not used so leave blank
     23 
     24 // To be safe, SUPPORT_TRANSACTIONS is assumed mandatory
     25 #if !defined (SUPPORT_TRANSACTIONS)
     26   #define SUPPORT_TRANSACTIONS
     27 #endif
     28 
     29 // Initialise processor specific SPI functions, used by init()
     30 #define INIT_TFT_DATA_BUS
     31 
     32 // If smooth fonts are enabled the filing system may need to be loaded
     33 #ifdef SMOOTH_FONT
     34   // Call up the filing system for the anti-aliased fonts
     35   //#define FS_NO_GLOBALS
     36   //#include <FS.h>
     37 #endif
     38 
     39 ////////////////////////////////////////////////////////////////////////////////////////
     40 // Define the DC (TFT Data/Command or Register Select (RS))pin drive code
     41 ////////////////////////////////////////////////////////////////////////////////////////
     42 #ifndef TFT_DC
     43   #define DC_C // No macro allocated so it generates no code
     44   #define DC_D // No macro allocated so it generates no code
     45 #else
     46   #define DC_C digitalWrite(TFT_DC, LOW)
     47   #define DC_D digitalWrite(TFT_DC, HIGH)
     48 #endif
     49 
     50 ////////////////////////////////////////////////////////////////////////////////////////
     51 // Define the CS (TFT chip select) pin drive code
     52 ////////////////////////////////////////////////////////////////////////////////////////
     53 #ifndef TFT_CS
     54   #define CS_L // No macro allocated so it generates no code
     55   #define CS_H // No macro allocated so it generates no code
     56 #else
     57   #define CS_L digitalWrite(TFT_CS, LOW)
     58   #define CS_H digitalWrite(TFT_CS, HIGH)
     59 #endif
     60 
     61 ////////////////////////////////////////////////////////////////////////////////////////
     62 // Make sure TFT_RD is defined if not used to avoid an error message
     63 ////////////////////////////////////////////////////////////////////////////////////////
     64 #ifndef TFT_RD
     65   #define TFT_RD -1
     66 #endif
     67 
     68 ////////////////////////////////////////////////////////////////////////////////////////
     69 // Define the WR (TFT Write) pin drive code
     70 ////////////////////////////////////////////////////////////////////////////////////////
     71 #ifdef TFT_WR
     72   #define WR_L digitalWrite(TFT_WR, LOW)
     73   #define WR_H digitalWrite(TFT_WR, HIGH)
     74 #endif
     75 
     76 ////////////////////////////////////////////////////////////////////////////////////////
     77 // Define the touch screen chip select pin drive code
     78 ////////////////////////////////////////////////////////////////////////////////////////
     79 #if !defined TOUCH_CS || (TOUCH_CS < 0)
     80   #define T_CS_L // No macro allocated so it generates no code
     81   #define T_CS_H // No macro allocated so it generates no code
     82 #else
     83   #define T_CS_L digitalWrite(TOUCH_CS, LOW)
     84   #define T_CS_H digitalWrite(TOUCH_CS, HIGH)
     85 #endif
     86 
     87 ////////////////////////////////////////////////////////////////////////////////////////
     88 // Make sure TFT_MISO is defined if not used to avoid an error message
     89 ////////////////////////////////////////////////////////////////////////////////////////
     90 #ifndef TFT_MISO
     91   #define TFT_MISO -1
     92 #endif
     93 
     94 ////////////////////////////////////////////////////////////////////////////////////////
     95 // Macros to write commands/pixel colour data to a SPI ILI948x TFT
     96 ////////////////////////////////////////////////////////////////////////////////////////
     97 #if  defined (SPI_18BIT_DRIVER) // SPI 18 bit colour
     98 
     99   // Write 8 bits to TFT
    100   #define tft_Write_8(C)   spi.transfer(C)
    101 
    102   // Convert 16 bit colour to 18 bit and write in 3 bytes
    103   #define tft_Write_16(C)  spi.transfer(((C) & 0xF800)>>8); \
    104                            spi.transfer(((C) & 0x07E0)>>3); \
    105                            spi.transfer(((C) & 0x001F)<<3)
    106 
    107   // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes
    108   #define tft_Write_16S(C) spi.transfer((C) & 0xF8); \
    109                            spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \
    110                            spi.transfer(((C) & 0x1F00)>>5)
    111   // Write 32 bits to TFT
    112   #define tft_Write_32(C)  spi.transfer16((C)>>16); spi.transfer16((uint16_t)(C))
    113 
    114   // Write two address coordinates
    115   #define tft_Write_32C(C,D) spi.transfer16(C); spi.transfer16(D)
    116 
    117   // Write same value twice
    118   #define tft_Write_32D(C) spi.transfer16(C); spi.transfer16(C)
    119 
    120 ////////////////////////////////////////////////////////////////////////////////////////
    121 // Macros to write commands/pixel colour data to other displays
    122 ////////////////////////////////////////////////////////////////////////////////////////
    123 #else
    124   #if  defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers
    125     #define tft_Write_8(C)   spi.transfer(C); spi.transfer(C)
    126     #define tft_Write_16(C)  spi.transfer((uint8_t)((C)>>8));spi.transfer((uint8_t)((C)>>0))
    127     #define tft_Write_16S(C) spi.transfer((uint8_t)((C)>>0));spi.transfer((uint8_t)((C)>>8))
    128 
    129     #define tft_Write_32(C) \
    130       tft_Write_16((uint16_t) ((C)>>16)); \
    131       tft_Write_16((uint16_t) ((C)>>0))
    132 
    133     #define tft_Write_32C(C,D) \
    134       spi.transfer(0); spi.transfer((C)>>8); \
    135       spi.transfer(0); spi.transfer((C)>>0); \
    136       spi.transfer(0); spi.transfer((D)>>8); \
    137       spi.transfer(0); spi.transfer((D)>>0)
    138 
    139     #define tft_Write_32D(C) \
    140       spi.transfer(0); spi.transfer((C)>>8); \
    141       spi.transfer(0); spi.transfer((C)>>0); \
    142       spi.transfer(0); spi.transfer((C)>>8); \
    143       spi.transfer(0); spi.transfer((C)>>0)
    144 
    145   #else
    146     #ifdef __AVR__ // AVR processors do not have 16 bit transfer
    147       #define tft_Write_8(C)   {SPDR=(C); while (!(SPSR&_BV(SPIF)));}
    148       #define tft_Write_16(C)  tft_Write_8((uint8_t)((C)>>8));tft_Write_8((uint8_t)((C)>>0))
    149       #define tft_Write_16S(C) tft_Write_8((uint8_t)((C)>>0));tft_Write_8((uint8_t)((C)>>8))
    150     #else
    151       #define tft_Write_8(C)   spi.transfer(C)
    152       #define tft_Write_16(C)  spi.transfer16(C)
    153       #define tft_Write_16S(C) spi.transfer16(((C)>>8) | ((C)<<8))
    154     #endif // AVR    
    155 
    156     #define tft_Write_32(C) \
    157     tft_Write_16((uint16_t) ((C)>>16)); \
    158     tft_Write_16((uint16_t) ((C)>>0))
    159 
    160     #define tft_Write_32C(C,D) \
    161     tft_Write_16((uint16_t) (C)); \
    162     tft_Write_16((uint16_t) (D))
    163 
    164     #define tft_Write_32D(C) \
    165     tft_Write_16((uint16_t) (C)); \
    166     tft_Write_16((uint16_t) (C))
    167   #endif // RPI_DISPLAY_TYPE
    168 #endif
    169 
    170 #ifndef tft_Write_16N
    171   #define tft_Write_16N tft_Write_16
    172 #endif
    173 
    174 ////////////////////////////////////////////////////////////////////////////////////////
    175 // Macros to read from display using SPI or software SPI
    176 ////////////////////////////////////////////////////////////////////////////////////////
    177 #if defined (TFT_SDA_READ)
    178   // Use a bit banged function call for STM32 and bi-directional SDA pin
    179   #define TFT_eSPI_ENABLE_8_BIT_READ // Enable tft_Read_8(void);
    180   #define SCLK_L digitalWrite(TFT_SCLK, LOW)
    181   #define SCLK_H digitalWrite(TFT_SCLK, LOW)
    182 #else
    183   // Use a SPI read transfer
    184   #define tft_Read_8() spi.transfer(0)
    185 #endif
    186 
    187 
    188 #endif // Header end