Graphics/src/include/Graphics/SampleConfig.h
Go to the documentation of this file.
1 /****
2  * SampleConfig.h
3  *
4  * Common definitions for sample applications
5  *
6  ****/
7 
8 #pragma once
9 
10 #ifdef ENABLE_VIRTUAL_SCREEN
13 #else
15 #include <Graphics/Touch/XPT2046.h>
16 #endif
17 
18 namespace
19 {
20 #ifdef ENABLE_VIRTUAL_SCREEN
22 Graphics::VirtualTouch touch(tft);
23 #else
24 #if defined(ARCH_ESP32)
25 HSPI::SpiPins spiPins{};
26 constexpr HSPI::SpiBus spiBus{HSPI::SpiBus::DEFAULT};
27 constexpr HSPI::PinSet TFT_PINSET{HSPI::PinSet::normal};
28 constexpr uint8_t TFT_CS{2};
29 constexpr uint8_t TFT_RESET_PIN{4};
30 constexpr uint8_t TFT_DC_PIN{5};
31 constexpr uint8_t TOUCH_CS{15};
32 constexpr uint8_t TOUCH_IRQ_PIN{10};
33 #elif defined(ARCH_RP2040)
34 HSPI::SpiPins spiPins{.sck = 18, .miso = 16, .mosi = 19};
35 constexpr HSPI::SpiBus spiBus{HSPI::SpiBus::DEFAULT};
36 constexpr HSPI::PinSet TFT_PINSET{HSPI::PinSet::normal};
37 constexpr uint8_t TFT_CS{9};
38 constexpr uint8_t TFT_RESET_PIN{6};
39 constexpr uint8_t TFT_DC_PIN{5};
40 constexpr uint8_t TOUCH_CS{13};
41 constexpr uint8_t TOUCH_IRQ_PIN{10};
42 constexpr uint8_t TFT_LED_PIN{14};
43 #elif defined(ARCH_ESP8266) || defined(ARCH_HOST)
44 HSPI::SpiPins spiPins{};
45 constexpr HSPI::SpiBus spiBus{HSPI::SpiBus::DEFAULT};
46 constexpr HSPI::PinSet TFT_PINSET{HSPI::PinSet::overlap};
47 constexpr uint8_t TFT_CS{2};
48 constexpr uint8_t TFT_RESET_PIN{4};
49 constexpr uint8_t TFT_DC_PIN{5};
50 constexpr uint8_t TOUCH_CS{0};
51 constexpr uint8_t TOUCH_IRQ_PIN{2};
52 #else
53 #error "Unsupported SOC"
54 #endif
55 
56 HSPI::Controller spi(spiBus, spiPins);
58 Graphics::XPT2046 touch(spi, tft);
59 #endif
60 
61 bool initDisplay()
62 {
63 #ifdef ENABLE_VIRTUAL_SCREEN
64  if(!tft.begin()) {
65  return false;
66  }
67  // tft.setMode(Display::Virtual::Mode::Debug);
68  touch.begin();
69  return true;
70 #else
71  if(!spi.begin()) {
72  return false;
73  }
74 
75  /*
76  * ILI9341 min. clock cycle is 100ns write, 150ns read.
77  * In practice, writes work at 40MHz, reads at 27MHz.
78  * Attempting to read at 40MHz results in colour corruption.
79  */
80  if(!tft.begin(TFT_PINSET, TFT_CS, TFT_DC_PIN, TFT_RESET_PIN, 20000000)) {
81  return false;
82  }
83 
84  touch.begin(TFT_PINSET, TOUCH_CS, TOUCH_IRQ_PIN);
85 
86  return true;
87 #endif
88 }
89 
90 } // namespace
Definition: ILI9341.h:31
Virtual display device for Host.
Definition: Virtual.h:42
bool begin(uint16_t width=240, uint16_t height=320)
Definition: VirtualTouch.h:34
Definition: XPT2046.h:32
Manages access to SPI hardware.
Definition: HardwareSPI/src/include/HSPI/Controller.h:52
SpiBus
Identifies bus selection.
Definition: Esp32/spi_arch.h:23
PinSet
How SPI hardware pins are connected.
Definition: Common.h:108
@ overlap
Overlapped with SPI 0.
@ normal
Standard HSPI pins.
SPI pin connections.
Definition: HardwareSPI/src/include/HSPI/Controller.h:42
uint8_t sck
Definition: HardwareSPI/src/include/HSPI/Controller.h:43