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_ST7796.h (3048B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  */
      5 #ifndef _ARDUINO_ST7796_H_
      6 #define _ARDUINO_ST7796_H_
      7 
      8 #include <Arduino.h>
      9 #include <Print.h>
     10 #include "../Arduino_GFX.h"
     11 #include "../Arduino_TFT.h"
     12 
     13 #define ST7796_TFTWIDTH 320
     14 #define ST7796_TFTHEIGHT 480
     15 
     16 #define ST7796_RST_DELAY 120    ///< delay ms wait for reset finish
     17 #define ST7796_SLPIN_DELAY 120  ///< delay ms wait for sleep in finish
     18 #define ST7796_SLPOUT_DELAY 120 ///< delay ms wait for sleep out finish
     19 
     20 #define ST7796_NOP 0x00
     21 #define ST7796_SWRESET 0x01
     22 #define ST7796_RDDID 0x04
     23 #define ST7796_RDDST 0x09
     24 
     25 #define ST7796_SLPIN 0x10
     26 #define ST7796_SLPOUT 0x11
     27 #define ST7796_PTLON 0x12
     28 #define ST7796_NORON 0x13
     29 
     30 #define ST7796_INVOFF 0x20
     31 #define ST7796_INVON 0x21
     32 #define ST7796_DISPOFF 0x28
     33 #define ST7796_DISPON 0x29
     34 
     35 #define ST7796_CASET 0x2A
     36 #define ST7796_RASET 0x2B
     37 #define ST7796_RAMWR 0x2C
     38 #define ST7796_RAMRD 0x2E
     39 
     40 #define ST7796_PTLAR 0x30
     41 #define ST7796_COLMOD 0x3A
     42 #define ST7796_MADCTL 0x36
     43 
     44 #define ST7796_MADCTL_MY 0x80
     45 #define ST7796_MADCTL_MX 0x40
     46 #define ST7796_MADCTL_MV 0x20
     47 #define ST7796_MADCTL_ML 0x10
     48 #define ST7796_MADCTL_RGB 0x00
     49 #define ST7796_MADCTL_BGR 0x08
     50 #define ST7796_MADCTL_MH 0x04
     51 
     52 #define ST7796_RDID1 0xDA
     53 #define ST7796_RDID2 0xDB
     54 #define ST7796_RDID3 0xDC
     55 #define ST7796_RDID4 0xDD
     56 
     57 static const uint8_t st7796_init_operations[] = {
     58     BEGIN_WRITE,
     59     WRITE_C8_D8, ST7796_COLMOD, 0x55, // 0x66,
     60 
     61     WRITE_C8_D8, 0xF0, 0xC3, // Command Set Control
     62     WRITE_C8_D8, 0xF0, 0x96,
     63 
     64     WRITE_C8_D8, 0xB4, 0x01,
     65 
     66     WRITE_COMMAND_8, 0xB6,
     67     WRITE_BYTES, 3, 0x80, 0x22, 0x3B,
     68 
     69     WRITE_COMMAND_8, 0xE8,
     70     WRITE_BYTES, 8,
     71     0x40, 0x8A, 0x00, 0x00, 0x29,
     72     0x19, 0xA5, 0x33,
     73 
     74     WRITE_C8_D8, 0xC1, 0x06,
     75     WRITE_C8_D8, 0xC2, 0xA7,
     76     WRITE_C8_D8, 0xC5, 0x18,
     77 
     78     WRITE_COMMAND_8, 0xE0,
     79     WRITE_BYTES, 14,
     80     0xF0, 0x09, 0x0B, 0x06, 0x04,
     81     0x15, 0x2F, 0x54, 0x42, 0x3C,
     82     0x17, 0x14, 0x18, 0x1B,
     83 
     84     WRITE_COMMAND_8, 0xE1,
     85     WRITE_BYTES, 14,
     86     0xE0, 0x09, 0x0B, 0x06, 0x04,
     87     0x03, 0x2B, 0x43, 0x42, 0x3B,
     88     0x16, 0x14, 0x17, 0x1B,
     89 
     90     WRITE_C8_D8, 0xF0, 0x3C,
     91     WRITE_C8_D8, 0xF0, 0x69,
     92     WRITE_COMMAND_8, ST7796_SLPOUT,
     93     END_WRITE,
     94 
     95     DELAY, ST7796_SLPOUT_DELAY,
     96 
     97     BEGIN_WRITE,
     98     WRITE_COMMAND_8, 0x38,
     99     WRITE_COMMAND_8, ST7796_DISPON,
    100     END_WRITE,
    101 
    102     DELAY, ST7796_SLPOUT_DELAY};
    103 
    104 class Arduino_ST7796 : public Arduino_TFT
    105 {
    106 public:
    107   Arduino_ST7796(
    108       Arduino_DataBus *bus, int8_t rst = GFX_NOT_DEFINED, uint8_t r = 0,
    109       bool ips = false, int16_t w = ST7796_TFTWIDTH, int16_t h = ST7796_TFTHEIGHT,
    110       uint8_t col_offset1 = 0, uint8_t row_offset1 = 0, uint8_t col_offset2 = 0, uint8_t row_offset2 = 0);
    111 
    112   bool begin(int32_t speed = GFX_NOT_DEFINED) override;
    113 
    114   void setRotation(uint8_t r) override;
    115 
    116   void writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) override;
    117 
    118   void invertDisplay(bool) override;
    119   void displayOn() override;
    120   void displayOff() override;
    121 
    122 protected:
    123   void tftInit() override;
    124 
    125 private:
    126 };
    127 
    128 #endif