Skip to content

Commit c222304

Browse files
committed
Make all pins configurable.
1 parent 6167d6e commit c222304

File tree

3 files changed

+96
-19
lines changed

3 files changed

+96
-19
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ To run the demo, attach ILI9341, ILI9488 or ST7735 based display module to ESP32
162162
* DC: 26 (display DC)
163163
* TCS: 25 (touch screen CS)
164164

165+
**Custom PINS can be defined in `idf.py menuconfig` in Components -> TFT Display menu**
165166
---
166167

167168
#### Display Kits
@@ -179,8 +180,6 @@ Configurations are available for:
179180

180181
---
181182

182-
**If you want to use different pins, change them in** *tftspi.h*
183-
184183
**if you want to use the touch screen functions, set** `#define USE_TOUCH 1` in *tftspi.h*
185184

186185
Using *make menuconfig* **select tick rate 1000** ( → Component config → FreeRTOS → Tick rate (Hz) ) to get more accurate timings

components/tft/Kconfig

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,59 @@ config TFT_INVERT_ROTATION1
6161
help
6262
If text is backwards on your display, try enabling this.
6363

64+
config TFT_PIN_NUM_MOSI
65+
int "GPIO for MOSI (Master Out Slave In)"
66+
default 23
67+
help
68+
If not using a predefined display type, configure the MOSI pin here.
69+
70+
config TFT_PIN_NUM_MISO
71+
int "GPIO for MISO (Master In Slave Out)"
72+
default 19
73+
help
74+
If not using a predefined display type, configure the MISO pin here.
75+
76+
config TFT_PIN_NUM_SCK
77+
int "GPIO for SCK (Serial Clock)"
78+
default 18
79+
help
80+
If not using a predefined display type, configure the SCK pin here.
81+
82+
config TFT_PIN_NUM_CS
83+
int "GPIO for CS (Slave Select)"
84+
default 5
85+
help
86+
If not using a predefined display type, configure the CS pin here.
87+
88+
config TFT_PIN_NUM_DC
89+
int "GPIO for DC (Data \ Command)"
90+
default 26
91+
help
92+
If not using a predefined display type, configure the DC pin here.
93+
94+
config TFT_PIN_NUM_TCS
95+
int "GPIO for TCS (Touchscreen)"
96+
default 25
97+
help
98+
Optional. If not using a predefined display type, configure the TCS (touch screen) pin here.
99+
64100
config TFT_PIN_NUM_RST
65101
int "GPIO for Reset"
66102
default 0
67103
help
68-
If not using an EXAMPLE display type, configure the reset pin here.
104+
Optional. If not using a predefined display type, configure the reset pin here.
105+
106+
config TFT_PIN_NUM_BCKL
107+
int "GPIO for Back-light control"
108+
default 0
109+
help
110+
Optional. If not using a predefined display type, configure the blacklight pin here.
111+
112+
config TFT_ENABLE_TOUCH_SCREEN
113+
bool "Enable Touch Screen"
114+
default "n"
115+
help
116+
Enables touch screen features.
69117

70118
config TFT_DISPLAY_WIDTH
71119
int "TFT display width in pixels."

components/tft/tftspi.h

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,34 +185,64 @@
185185

186186
// The pins configured here are the native spi pins for HSPI interface
187187
// Any other valid pin combination can be used
188-
#define PIN_NUM_MISO 19 // SPI MISO
189-
#define PIN_NUM_MOSI 23 // SPI MOSI
190-
#define PIN_NUM_CLK 18 // SPI CLOCK pin
191-
#define PIN_NUM_CS 5 // Display CS pin
192-
#define PIN_NUM_DC 26 // Display command/data pin
193-
#define PIN_NUM_TCS 25 // Touch screen CS pin (NOT used if USE_TOUCH=0)
194188

195-
// --------------------------------------------------------------
196-
// ** Set Reset and Backlight pins to 0 if not used !
197-
// ** If you want to use them, set them to some valid GPIO number
189+
#if defined(CONFIG_TFT_PIN_NUM_MISO)
190+
#define PIN_NUM_MISO CONFIG_TFT_PIN_NUM_MISO
191+
#else
192+
#define PIN_NUM_MISO 19
193+
#endif
194+
195+
#if defined(CONFIG_TFT_PIN_NUM_MOSI)
196+
#define PIN_NUM_MOSI CONFIG_TFT_PIN_NUM_MOSI
197+
#else
198+
#define PIN_NUM_MOSI 23
199+
#endif
200+
201+
#if defined(CONFIG_TFT_PIN_NUM_CLK)
202+
#define PIN_NUM_CLK CONFIG_TFT_PIN_NUM_CLK
203+
#else
204+
#define PIN_NUM_CLK 18
205+
#endif
206+
207+
#if defined(CONFIG_TFT_PIN_NUM_CS)
208+
#define PIN_NUM_CS CONFIG_TFT_PIN_NUM_CS
209+
#else
210+
#define PIN_NUM_CS 5
211+
#endif
212+
213+
#if defined(CONFIG_TFT_PIN_NUM_DC)
214+
#define PIN_NUM_DC CONFIG_TFT_PIN_NUM_DC
215+
#else
216+
#define PIN_NUM_DC 26
217+
#endif
218+
219+
#if defined(CONFIG_TFT_PIN_NUM_TCS)
220+
#define PIN_NUM_TCS CONFIG_TFT_PIN_NUM_TCS
221+
#else
222+
#define PIN_NUM_TCS 25
223+
#endif
198224

199-
// GPIO used for RESET control
200225
#if defined(CONFIG_TFT_PIN_NUM_RST)
201226
#define PIN_NUM_RST CONFIG_TFT_PIN_NUM_RST
202227
#else
203228
#define PIN_NUM_RST 0
204229
#endif
205230

206-
#define PIN_NUM_BCKL 0 // GPIO used for backlight control
231+
#if defined(CONFIG_TFT_PIN_NUM_BCKL)
232+
#define PIN_NUM_BCKL CONFIG_TFT_PIN_NUM_BCKL
233+
#else
234+
#define PIN_NUM_BCKL 0
235+
#endif
236+
207237
#define PIN_BCKL_ON 0 // GPIO value for backlight ON
208238
#define PIN_BCKL_OFF 1 // GPIO value for backlight OFF
209239
// --------------------------------------------------------------
210240

211-
// #######################################################
212-
// Set this to 1 if you want to use touch screen functions
213-
// #######################################################
214-
#define USE_TOUCH TOUCH_TYPE_NONE
215-
// #######################################################
241+
#if defined(CONFIG_TFT_ENABLE_TOUCH_SCREEN)
242+
#define USE_TOUCH CONFIG_TFT_ENABLE_TOUCH_SCREEN
243+
#else
244+
#define USE_TOUCH TOUCH_TYPE_NONE
245+
#endif
216246

217247
// #######################################################################
218248
// Default display width (smaller dimension) and height (larger dimension)

0 commit comments

Comments
 (0)