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 |
Read_ID_bitbash.ino (4305B)
1 // Read the ID from the TFT controller 2 // The sketch only supports displays with a bi-directional SPI data line (often labelled SDA) 3 4 // Bit bashes SPI so it does NOT assume hardware SPI wired up 5 // No other libraries are needed 6 7 // NOTE: This sketch does not work with parallel displays! 8 9 // Original author unknown 10 // Adapted by Bodmer 22/5/16, updated 16/9/16 11 12 // Change the pin settings to suit your hardware 13 14 // UNO etc 15 //#define TFT_MOSI 11 16 //#define TFT_SCK 13 17 //#define TFT_CS 9 18 //#define TFT_DC 8 19 //#define TFT_RESET 7 20 21 //Mega 22 //#define TFT_MOSI 51 23 //#define TFT_SCK 52 24 //#define TFT_CS 47 25 //#define TFT_DC 48 26 //#define TFT_RESET 44 27 28 //Micro 29 //#define TFT_MOSI MOSI 30 //#define TFT_SCK SCK 31 //#define TFT_CS 10 32 //#define TFT_DC 9 33 //#define TFT_RESET 8 34 35 //NodeMCU 36 #define TFT_MOSI D7 37 #define TFT_SCK D5 38 #define TFT_CS D8 39 #define TFT_DC D3 40 #define TFT_RESET D4 41 42 /* Example Serial Monitor output: 43 44 TFT driver register values: 45 =========================== 46 Register 0x01: 0x00 47 Register 0x04: 0x548066 48 Register 0x09: 0x610000 49 Register 0x0A: 0x08 50 Register 0x0B: 0x00 51 Register 0x0C: 0x06 52 Register 0x0D: 0x00 53 Register 0x0E: 0x00 54 Register 0x0F: 0x00 55 Register 0x2E: 0x1834B4 56 Register 0xDA: 0x54 57 Register 0xDB: 0x80 58 Register 0xDC: 0x66 59 =========================== 60 61 Looks like driver chip is: ILI9163 (based on datasheet ID) 62 63 */ 64 65 char *chip = "Unknown "; 66 67 uint32_t readwrite8(uint8_t cmd, uint8_t bits, uint8_t dummy) 68 { 69 uint32_t ret = 0; 70 uint8_t val = cmd; 71 int cnt = 8; 72 digitalWrite(TFT_CS, LOW); 73 digitalWrite(TFT_DC, LOW); 74 pinMode(TFT_MOSI, OUTPUT); 75 for (int i = 0; i < 8; i++) { //send command 76 digitalWrite(TFT_MOSI, (val & 0x80) != 0); 77 digitalWrite(TFT_SCK, HIGH); 78 digitalWrite(TFT_SCK, LOW); 79 val <<= 1; 80 } 81 if (bits == 0) { 82 digitalWrite(TFT_CS, HIGH); 83 return 0; 84 } 85 pinMode(TFT_MOSI, INPUT_PULLUP); 86 digitalWrite(TFT_DC, HIGH); 87 for (int i = 0; i < dummy; i++) { //any dummy clocks 88 digitalWrite(TFT_SCK, HIGH); 89 digitalWrite(TFT_SCK, LOW); 90 } 91 for (int i = 0; i < bits; i++) { // read results 92 ret <<= 1; 93 if (digitalRead(TFT_MOSI)) ret |= 1;; 94 digitalWrite(TFT_SCK, HIGH); 95 digitalWrite(TFT_SCK, LOW); 96 } 97 digitalWrite(TFT_CS, HIGH); 98 return ret; 99 } 100 101 void showreg(uint8_t reg, uint8_t bits, uint8_t dummy) 102 { 103 uint32_t val; 104 val = readwrite8(reg, bits, dummy); 105 106 Serial.print("Register 0x"); 107 if (reg < 0x10) Serial.print("0"); 108 Serial.print(reg , HEX); 109 Serial.print(": 0x"); 110 if (val < 0x10) Serial.print("0"); 111 Serial.println(val, HEX); 112 } 113 114 void setup() { 115 // put your setup code here, to run once: 116 uint32_t ID = 0; 117 Serial.begin(115200); 118 119 delay(4000); // Delay to allow USB to connect to a Leonardo etc 120 121 Serial.println("TFT driver register values:"); 122 Serial.println("==========================="); 123 digitalWrite(TFT_CS, HIGH); 124 // digitalWrite(TFT_SCK, HIGH); 125 pinMode(TFT_CS, OUTPUT); 126 pinMode(TFT_SCK, OUTPUT); 127 pinMode(TFT_MOSI, OUTPUT); 128 pinMode(MISO, INPUT_PULLUP); 129 pinMode(TFT_DC, OUTPUT); 130 pinMode(TFT_RESET, OUTPUT); 131 digitalWrite(TFT_RESET, HIGH); 132 digitalWrite(TFT_RESET, LOW); //Hardware Reset 133 delay(50); 134 digitalWrite(TFT_RESET, HIGH); 135 showreg(0x01, 0, 0); //Software Reset 136 delay(100); 137 ID = readwrite8(0x04, 24, 1); 138 139 if ((ID & 0xFF8000) == 0x5C8000uL) chip = "ST7735 (based on datasheet ID)"; 140 if (ID == 0x7C89F0uL) chip = "ST7735S (empirical value)"; 141 if (ID == 0x548066uL) chip = "ILI9163C (based on datasheet ID)"; 142 if (ID == 0x5C0000uL) chip = "S6D02A1 (based on datasheet ID)"; 143 144 showreg(0x04, 24, 1); //RDDID 145 showreg(0x09, 32, 1); //RDSTATUS 146 showreg(0x0A, 8, 0); 147 showreg(0x0B, 8, 0); 148 showreg(0x0C, 8, 0); 149 showreg(0x0D, 8, 0); 150 showreg(0x0E, 8, 0); 151 showreg(0x0F, 8, 0); 152 showreg(0x2E, 24, 8); //readGRAM 153 showreg(0x3F, 32, 1); //readGRAM 154 showreg(0xDA, 8, 0); 155 showreg(0xDB, 8, 0); 156 showreg(0xDC, 8, 0); 157 158 Serial.println("==========================="); 159 Serial.println(); 160 Serial.print("Looks like driver chip is: " );Serial.println(chip); 161 } 162 163 void loop() { 164 165 } 166 167 168