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
12 #else
14 #endif
15 
16 namespace
17 {
18 #ifdef ENABLE_VIRTUAL_SCREEN
20 #else
23 
24 #if defined(ARCH_ESP32)
25 constexpr HSPI::SpiBus spiBus{HSPI::SpiBus::DEFAULT};
26 constexpr HSPI::PinSet TFT_PINSET{HSPI::PinSet::normal};
27 constexpr uint8_t TFT_CS{2};
28 constexpr uint8_t TFT_RESET_PIN{4};
29 constexpr uint8_t TFT_DC_PIN{5};
30 constexpr uint8_t TOUCH_CS_PIN{15};
31 #elif defined(ARCH_RP2040)
32 constexpr HSPI::SpiBus spiBus{HSPI::SpiBus::DEFAULT};
33 constexpr HSPI::PinSet TFT_PINSET{HSPI::PinSet::normal};
34 constexpr uint8_t TFT_CS{20};
35 constexpr uint8_t TFT_RESET_PIN{4};
36 constexpr uint8_t TFT_DC_PIN{5};
37 constexpr uint8_t TOUCH_CS_PIN{15};
38 #else
39 // Pin setup
40 constexpr HSPI::PinSet TFT_PINSET{HSPI::PinSet::overlap};
41 constexpr uint8_t TFT_CS{2};
42 constexpr uint8_t TFT_RESET_PIN{4};
43 constexpr uint8_t TFT_DC_PIN{5};
44 // Not used in this sample, but needs to be kept high
45 constexpr uint8_t TOUCH_CS_PIN{15};
46 #endif
47 #endif
48 
49 bool initDisplay()
50 {
51 #ifdef ENABLE_VIRTUAL_SCREEN
52  if(!tft.begin()) {
53  return false;
54  }
55  // tft.setMode(Display::Virtual::Mode::Debug);
56  return true;
57 #else
58  // Touch CS
59  pinMode(TOUCH_CS_PIN, OUTPUT);
60  digitalWrite(TOUCH_CS_PIN, HIGH);
61 
62  if(!spi.begin()) {
63  return false;
64  }
65 
66  /*
67  * ILI9341 min. clock cycle is 100ns write, 150ns read.
68  * In practice, writes work at 40MHz, reads at 27MHz.
69  * Attempting to read at 40MHz results in colour corruption.
70  */
71  return tft.begin(TFT_PINSET, TFT_CS, TFT_DC_PIN, TFT_RESET_PIN, 27000000);
72 #endif
73 }
74 
75 } // namespace
PinSet
How SPI hardware pins are connected.
Definition: Common.h:108
Definition: ILI9341.h:30
void digitalWrite(uint16_t pin, uint8_t val)
Set a digital output.
Virtual display device for Host.
Definition: Virtual.h:41
#define HIGH
Definition: WConstants.h:38
#define OUTPUT
Definition: WConstants.h:46
SpiBus
Identifies bus selection.
Definition: Esp32/spi_arch.h:23
Standard HSPI pins.
void pinMode(uint16_t pin, uint8_t mode)
Set the mode of a GPIO pin.
bool begin(uint16_t width=240, uint16_t height=320)
Overlapped with SPI 0.
Manages access to SPI hardware.
Definition: HardwareSPI/src/include/HSPI/Controller.h:51