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_User_Setup.ino (8453B)
1 /* 2 This sketch reads the user setup information from the processor via the Serial Port 3 4 It is a support and diagnostic sketch for the TFT_eSPI library: 5 https://github.com/Bodmer/TFT_eSPI 6 7 The output is essentially a copy of the User_Setep configuration so can be used to 8 verify the correct settings are being picked up by the compiler. 9 10 If support is needed the output can be cut and pasted into an Arduino Forum post and 11 already includes the formatting [code]...[/code] markups. 12 13 Written by Bodmer 9/4/18 14 */ 15 //>>>>> Note: STM32 pin references above D15 may not reflect board markings <<<<< 16 17 #include <SPI.h> 18 #include <TFT_eSPI.h> // Graphics library 19 20 TFT_eSPI tft = TFT_eSPI(); // Invoke library 21 22 #ifdef ARDUINO_ARCH_ESP8266 23 ADC_MODE(ADC_VCC); // Read the supply voltage 24 #endif 25 26 setup_t user; // The library defines the type "setup_t" as a struct 27 // Calling tft.getSetup(user) populates it with the settings 28 //------------------------------------------------------------------------------------------ 29 30 void setup() { 31 // Use serial port 32 Serial.begin(115200); 33 34 // Initialise the TFT screen 35 tft.init(); 36 } 37 38 //------------------------------------------------------------------------------------------ 39 40 void loop(void) { 41 42 tft.getSetup(user); // 43 44 Serial.print("\n[code]\n"); 45 46 Serial.print ("TFT_eSPI ver = "); Serial.println(user.version); 47 printProcessorName(); 48 #if defined (ESP32) || defined (ARDUINO_ARCH_ESP8266) 49 if (user.esp < 0x32F000 || user.esp > 0x32FFFF) { Serial.print("Frequency = "); Serial.print(ESP.getCpuFreqMHz());Serial.println("MHz"); } 50 #endif 51 #ifdef ARDUINO_ARCH_ESP8266 52 Serial.print("Voltage = "); Serial.print(ESP.getVcc() / 918.0); Serial.println("V"); // 918 empirically determined 53 #endif 54 Serial.print("Transactions = "); Serial.println((user.trans == 1) ? "Yes" : "No"); 55 Serial.print("Interface = "); Serial.println((user.serial == 1) ? "SPI" : "Parallel"); 56 #ifdef ARDUINO_ARCH_ESP8266 57 if (user.serial == 1){ Serial.print("SPI overlap = "); Serial.println((user.overlap == 1) ? "Yes\n" : "No\n"); } 58 #endif 59 if (user.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch 60 { 61 Serial.print("Display driver = "); Serial.println(user.tft_driver, HEX); // Hexadecimal code 62 Serial.print("Display width = "); Serial.println(user.tft_width); // Rotation 0 width and height 63 Serial.print("Display height = "); Serial.println(user.tft_height); 64 Serial.println(); 65 } 66 else if (user.tft_driver == 0xE9D) Serial.println("Display driver = ePaper\n"); 67 68 if (user.r0_x_offset != 0) { Serial.print("R0 x offset = "); Serial.println(user.r0_x_offset); } // Offsets, not all used yet 69 if (user.r0_y_offset != 0) { Serial.print("R0 y offset = "); Serial.println(user.r0_y_offset); } 70 if (user.r1_x_offset != 0) { Serial.print("R1 x offset = "); Serial.println(user.r1_x_offset); } 71 if (user.r1_y_offset != 0) { Serial.print("R1 y offset = "); Serial.println(user.r1_y_offset); } 72 if (user.r2_x_offset != 0) { Serial.print("R2 x offset = "); Serial.println(user.r2_x_offset); } 73 if (user.r2_y_offset != 0) { Serial.print("R2 y offset = "); Serial.println(user.r2_y_offset); } 74 if (user.r3_x_offset != 0) { Serial.print("R3 x offset = "); Serial.println(user.r3_x_offset); } 75 if (user.r3_y_offset != 0) { Serial.print("R3 y offset = "); Serial.println(user.r3_y_offset); } 76 77 if (user.pin_tft_mosi != -1) { Serial.print("MOSI = "); Serial.print("GPIO "); Serial.println(getPinName(user.pin_tft_mosi)); } 78 if (user.pin_tft_miso != -1) { Serial.print("MISO = "); Serial.print("GPIO "); Serial.println(getPinName(user.pin_tft_miso)); } 79 if (user.pin_tft_clk != -1) { Serial.print("SCK = "); Serial.print("GPIO "); Serial.println(getPinName(user.pin_tft_clk)); } 80 81 #ifdef ARDUINO_ARCH_ESP8266 82 if (user.overlap == true) 83 { 84 Serial.println("Overlap selected, following pins MUST be used:"); 85 86 Serial.println("MOSI = SD1 (GPIO 8)"); 87 Serial.println("MISO = SD0 (GPIO 7)"); 88 Serial.println("SCK = CLK (GPIO 6)"); 89 Serial.println("TFT_CS = D3 (GPIO 0)\n"); 90 91 Serial.println("TFT_DC and TFT_RST pins can be user defined"); 92 } 93 #endif 94 String pinNameRef = "GPIO "; 95 #ifdef ARDUINO_ARCH_ESP8266 96 pinNameRef = "PIN_D"; 97 #endif 98 99 if (user.esp == 0x32F) { 100 Serial.println("\n>>>>> Note: STM32 pin references above D15 may not reflect board markings <<<<<"); 101 pinNameRef = "D"; 102 } 103 if (user.pin_tft_cs != -1) { Serial.print("TFT_CS = " + pinNameRef); Serial.println(getPinName(user.pin_tft_cs)); } 104 if (user.pin_tft_dc != -1) { Serial.print("TFT_DC = " + pinNameRef); Serial.println(getPinName(user.pin_tft_dc)); } 105 if (user.pin_tft_rst!= -1) { Serial.print("TFT_RST = " + pinNameRef); Serial.println(getPinName(user.pin_tft_rst)); } 106 107 if (user.pin_tch_cs != -1) { Serial.print("TOUCH_CS = " + pinNameRef); Serial.println(getPinName(user.pin_tch_cs)); } 108 109 if (user.pin_tft_wr != -1) { Serial.print("TFT_WR = " + pinNameRef); Serial.println(getPinName(user.pin_tft_wr)); } 110 if (user.pin_tft_rd != -1) { Serial.print("TFT_RD = " + pinNameRef); Serial.println(getPinName(user.pin_tft_rd)); } 111 112 if (user.pin_tft_d0 != -1) { Serial.print("\nTFT_D0 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d0)); } 113 if (user.pin_tft_d1 != -1) { Serial.print("TFT_D1 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d1)); } 114 if (user.pin_tft_d2 != -1) { Serial.print("TFT_D2 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d2)); } 115 if (user.pin_tft_d3 != -1) { Serial.print("TFT_D3 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d3)); } 116 if (user.pin_tft_d4 != -1) { Serial.print("TFT_D4 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d4)); } 117 if (user.pin_tft_d5 != -1) { Serial.print("TFT_D5 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d5)); } 118 if (user.pin_tft_d6 != -1) { Serial.print("TFT_D6 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d6)); } 119 if (user.pin_tft_d7 != -1) { Serial.print("TFT_D7 = " + pinNameRef); Serial.println(getPinName(user.pin_tft_d7)); } 120 121 #if defined (TFT_BL) 122 Serial.print("\nTFT_BL = " + pinNameRef); Serial.println(getPinName(user.pin_tft_led)); 123 #if defined (TFT_BACKLIGHT_ON) 124 Serial.print("TFT_BACKLIGHT_ON = "); Serial.println(user.pin_tft_led_on == HIGH ? "HIGH" : "LOW"); 125 #endif 126 #endif 127 128 Serial.println(); 129 130 uint16_t fonts = tft.fontsLoaded(); 131 if (fonts & (1 << 1)) Serial.print("Font GLCD loaded\n"); 132 if (fonts & (1 << 2)) Serial.print("Font 2 loaded\n"); 133 if (fonts & (1 << 4)) Serial.print("Font 4 loaded\n"); 134 if (fonts & (1 << 6)) Serial.print("Font 6 loaded\n"); 135 if (fonts & (1 << 7)) Serial.print("Font 7 loaded\n"); 136 if (fonts & (1 << 9)) Serial.print("Font 8N loaded\n"); 137 else 138 if (fonts & (1 << 8)) Serial.print("Font 8 loaded\n"); 139 if (fonts & (1 << 15)) Serial.print("Smooth font enabled\n"); 140 Serial.print("\n"); 141 142 if (user.serial==1) { Serial.print("Display SPI frequency = "); Serial.println(user.tft_spi_freq/10.0); } 143 if (user.pin_tch_cs != -1) { Serial.print("Touch SPI frequency = "); Serial.println(user.tch_spi_freq/10.0); } 144 145 Serial.println("[/code]"); 146 147 delay(3000); 148 } 149 150 void printProcessorName(void) 151 { 152 Serial.print("Processor = "); 153 if ( user.esp == 0x8266) Serial.println("ESP8266"); 154 if ( user.esp == 0x32) Serial.println("ESP32"); 155 if ( user.esp == 0x32F) Serial.println("STM32"); 156 if ( user.esp == 0x2040) Serial.println("RP2040"); 157 if ( user.esp == 0x0000) Serial.println("Generic"); 158 } 159 160 // Get pin name 161 int8_t getPinName(int8_t pin) 162 { 163 // For ESP32 and RP2040 pin labels on boards use the GPIO number 164 if (user.esp == 0x32 || user.esp == 0x2040) return pin; 165 166 if (user.esp == 0x8266) { 167 // For ESP8266 the pin labels are not the same as the GPIO number 168 // These are for the NodeMCU pin definitions: 169 // GPIO Dxx 170 if (pin == 16) return 0; 171 if (pin == 5) return 1; 172 if (pin == 4) return 2; 173 if (pin == 0) return 3; 174 if (pin == 2) return 4; 175 if (pin == 14) return 5; 176 if (pin == 12) return 6; 177 if (pin == 13) return 7; 178 if (pin == 15) return 8; 179 if (pin == 3) return 9; 180 if (pin == 1) return 10; 181 if (pin == 9) return 11; 182 if (pin == 10) return 12; 183 } 184 185 if (user.esp == 0x32F) return pin; 186 187 return pin; // Invalid pin 188 }