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_ILI9342.h (4691B)

      1 #ifndef _ARDUINO_ILI9342_H_
      2 #define _ARDUINO_ILI9342_H_
      3 
      4 #include <Arduino.h>
      5 #include <Print.h>
      6 #include "../Arduino_GFX.h"
      7 #include "../Arduino_TFT.h"
      8 
      9 #define ILI9342_TFTWIDTH 320  ///< ILI9342 max TFT width
     10 #define ILI9342_TFTHEIGHT 240 ///< ILI9342 max TFT height
     11 
     12 #define ILI9342_RST_DELAY 150    ///< delay ms wait for reset finish
     13 #define ILI9342_SLPIN_DELAY 150  ///< delay ms wait for sleep in finish
     14 #define ILI9342_SLPOUT_DELAY 150 ///< delay ms wait for sleep out finish
     15 
     16 #define ILI9342_NOP 0x00     ///< No-op register
     17 #define ILI9342_SWRESET 0x01 ///< Software reset register
     18 #define ILI9342_RDDID 0x04   ///< Read display identification information
     19 #define ILI9342_RDDST 0x09   ///< Read Display Status
     20 
     21 #define ILI9342_SLPIN 0x10  ///< Enter Sleep Mode
     22 #define ILI9342_SLPOUT 0x11 ///< Sleep Out
     23 #define ILI9342_PTLON 0x12  ///< Partial Mode ON
     24 #define ILI9342_NORON 0x13  ///< Normal Display Mode ON
     25 
     26 #define ILI9342_RDMODE 0x0A     ///< Read Display Power Mode
     27 #define ILI9342_RDMADCTL 0x0B   ///< Read Display MADCTL
     28 #define ILI9342_RDPIXFMT 0x0C   ///< Read Display Pixel Format
     29 #define ILI9342_RDIMGFMT 0x0D   ///< Read Display Image Format
     30 #define ILI9342_RDSELFDIAG 0x0F ///< Read Display Self-Diagnostic Result
     31 
     32 #define ILI9342_INVOFF 0x20   ///< Display Inversion OFF
     33 #define ILI9342_INVON 0x21    ///< Display Inversion ON
     34 #define ILI9342_GAMMASET 0x26 ///< Gamma Set
     35 #define ILI9342_DISPOFF 0x28  ///< Display OFF
     36 #define ILI9342_DISPON 0x29   ///< Display ON
     37 
     38 #define ILI9342_CASET 0x2A ///< Column Address Set
     39 #define ILI9342_PASET 0x2B ///< Page Address Set
     40 #define ILI9342_RAMWR 0x2C ///< Memory Write
     41 #define ILI9342_RAMRD 0x2E ///< Memory Read
     42 
     43 #define ILI9342_PTLAR 0x30    ///< Partial Area
     44 #define ILI9342_VSCRDEF 0x33  ///< Vertical Scrolling Definition
     45 #define ILI9342_MADCTL 0x36   ///< Memory Access Control
     46 #define ILI9342_VSCRSADD 0x37 ///< Vertical Scrolling Start Address
     47 #define ILI9342_PIXFMT 0x3A   ///< COLMOD: Pixel Format Set
     48 
     49 #define ILI9342_FRMCTR1 0xB1 ///< Frame Rate Control (In Normal Mode/Full Colors)
     50 #define ILI9342_FRMCTR2 0xB2 ///< Frame Rate Control (In Idle Mode/8 colors)
     51 #define ILI9342_FRMCTR3 0xB3 ///< Frame Rate control (In Partial Mode/Full Colors)
     52 #define ILI9342_INVCTR 0xB4  ///< Display Inversion Control
     53 #define ILI9342_DFUNCTR 0xB6 ///< Display Function Control
     54 
     55 #define ILI9342_PWCTR1 0xC0 ///< Power Control 1
     56 #define ILI9342_PWCTR2 0xC1 ///< Power Control 2
     57 #define ILI9342_PWCTR3 0xC2 ///< Power Control 3
     58 #define ILI9342_PWCTR4 0xC3 ///< Power Control 4
     59 #define ILI9342_PWCTR5 0xC4 ///< Power Control 5
     60 #define ILI9342_VMCTR1 0xC5 ///< VCOM Control 1
     61 #define ILI9342_VMCTR2 0xC7 ///< VCOM Control 2
     62 
     63 #define ILI9342_RDID1 0xDA ///< Read ID 1
     64 #define ILI9342_RDID2 0xDB ///< Read ID 2
     65 #define ILI9342_RDID3 0xDC ///< Read ID 3
     66 #define ILI9342_RDID4 0xDD ///< Read ID 4
     67 
     68 #define ILI9342_GMCTRP1 0xE0 ///< Positive Gamma Correction
     69 #define ILI9342_GMCTRN1 0xE1 ///< Negative Gamma Correction
     70 #define ILI9342_PWCTR6 0xFC
     71 
     72 #define ILI9342_MADCTL_MY 0x80  ///< Bottom to top
     73 #define ILI9342_MADCTL_MX 0x40  ///< Right to left
     74 #define ILI9342_MADCTL_MV 0x20  ///< Reverse Mode
     75 #define ILI9342_MADCTL_ML 0x10  ///< LCD refresh Bottom to top
     76 #define ILI9342_MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order
     77 #define ILI9342_MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order
     78 #define ILI9342_MADCTL_MH 0x04  ///< LCD refresh right to left
     79 
     80 static const uint8_t ILI9342_init_operations[] = {
     81     BEGIN_WRITE,
     82     WRITE_C8_D8, ILI9342_PWCTR1, 0x23,        // Power control VRH[5:0]
     83     WRITE_C8_D8, ILI9342_PWCTR2, 0x10,        // Power control SAP[2:0];BT[3:0]
     84     WRITE_C8_D16, ILI9342_VMCTR1, 0x3e, 0x28, // VCM control
     85     WRITE_C8_D8, ILI9342_VMCTR2, 0x86,        // VCM control2
     86     WRITE_C8_D8, ILI9342_VSCRSADD, 0x00,      // Vertical scroll zero
     87     WRITE_C8_D8, ILI9342_PIXFMT, 0x55,
     88     WRITE_C8_D16, ILI9342_FRMCTR1, 0x00, 0x18,
     89 
     90     WRITE_COMMAND_8, ILI9342_DFUNCTR, // Display Function Control
     91     WRITE_BYTES, 3, 0x08, 0x82, 0x27,
     92 
     93     WRITE_COMMAND_8, ILI9342_SLPOUT, // Exit Sleep
     94     END_WRITE,
     95 
     96     DELAY, ILI9342_SLPOUT_DELAY,
     97 
     98     BEGIN_WRITE,
     99     WRITE_COMMAND_8, ILI9342_DISPON, // Display on
    100     END_WRITE};
    101 
    102 class Arduino_ILI9342 : public Arduino_TFT
    103 {
    104 public:
    105   Arduino_ILI9342(Arduino_DataBus *bus, int8_t rst = GFX_NOT_DEFINED, uint8_t r = 0, bool ips = false);
    106 
    107   bool begin(int32_t speed = GFX_NOT_DEFINED) override;
    108 
    109   void setRotation(uint8_t r) override;
    110 
    111   void writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) override;
    112 
    113   void invertDisplay(bool) override;
    114   void displayOn() override;
    115   void displayOff() override;
    116 
    117 protected:
    118   void tftInit() override;
    119 
    120 private:
    121 };
    122 
    123 #endif