Skip to content

Commit 7684a1a

Browse files
committed
Make hardware configurable using menuconfig, add support for ST7789V LCD controller, add preliminary analog audio support.
1 parent 99daea0 commit 7684a1a

File tree

5 files changed

+421
-76
lines changed

5 files changed

+421
-76
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
menu "Nofrendo ESP32-specific configuration"
2+
3+
choice NOFRENDO_HARDWARE
4+
prompt "Hardware to run on"
5+
default ESP_WROVER_KIT_V2_ILI
6+
help
7+
This emulator can run on various types of hardware. Select what you have here.
8+
9+
config HW_WROVERKIT_V1
10+
bool "ESP_Wrover_Kit v1 (red PCB)"
11+
12+
config HW_WROVERKIT_V2
13+
bool "ESP_Wrover_Kit v2 (black PCB)"
14+
15+
config HW_CUSTOM
16+
bool "Custom hardware"
17+
18+
endchoice
19+
20+
choice HW_LCD_TYPE_SEL
21+
prompt "LCD type"
22+
depends on HW_CUSTOM || HW_WROVERKIT_V2
23+
24+
config HW_LCD_TYPE_ILI
25+
bool "ILI9341 LCD"
26+
27+
config HW_LCD_TYPE_ST
28+
bool "ST7789V LCD"
29+
30+
endchoice
31+
32+
config HW_WROVERKIT
33+
bool
34+
default n if HW_CUSTOM
35+
default y if HW_WROVERKIT_V1
36+
default y if HW_WROVERKIT_V2
37+
38+
39+
config HW_LCD_TYPE
40+
int
41+
default 0 if HW_WROVERKIT_V1
42+
default 0 if HW_LCD_TYPE_ILI
43+
default 1 if HW_LCD_TYPE_ST
44+
45+
46+
config HW_LCD_MOSI_GPIO_CUST
47+
int "LCD MOSI pin"
48+
depends on HW_CUSTOM
49+
range 1 35
50+
default 25
51+
52+
config HW_LCD_CLK_GPIO_CUST
53+
int "LCD CLK pin"
54+
depends on HW_CUSTOM
55+
range 1 35
56+
default 23
57+
58+
config HW_LCD_CS_GPIO_CUST
59+
int "LCD CS pin"
60+
depends on HW_CUSTOM
61+
range 1 35
62+
default 19
63+
64+
config HW_LCD_DC_GPIO_CUST
65+
int "LCD DC pin"
66+
depends on HW_CUSTOM
67+
range 1 35
68+
default 22
69+
70+
config HW_LCD_RESET_GPIO_CUST
71+
int "LCD RESET pin"
72+
depends on HW_CUSTOM
73+
range 1 35
74+
default 21
75+
76+
config HW_LCD_BL_GPIO_CUST
77+
int "LCD Backlight Enable pin"
78+
depends on HW_CUSTOM
79+
range 1 35
80+
default 5
81+
82+
config HW_INV_BL_CUST
83+
bool "Invert backlight output"
84+
default n
85+
depends on HW_CUSTOM
86+
87+
88+
config HW_INV_BL
89+
bool
90+
default HW_INBV_BL_CUST if HW_CUSTOM
91+
default n if HW_WROVERKIT_V1
92+
default y if HW_WROVERKIT_V2
93+
94+
config HW_LCD_MISO_GPIO
95+
int
96+
default HW_LCD_MISO_GPIO_CUST if HW_CUSTOM
97+
default 25 if HW_WROVERKIT
98+
99+
config HW_LCD_MOSI_GPIO
100+
int
101+
default HW_LCD_MOSI_GPIO_CUST if HW_CUSTOM
102+
default 23 if HW_WROVERKIT
103+
104+
config HW_LCD_CLK_GPIO
105+
int
106+
default HW_LCD_CLK_GPIO_CUST if HW_CUSTOM
107+
default 19 if HW_WROVERKIT
108+
109+
config HW_LCD_CS_GPIO
110+
int
111+
default HW_LCD_CS_GPIO_CUST if HW_CUSTOM
112+
default 22 if HW_WROVERKIT
113+
114+
config HW_LCD_DC_GPIO
115+
int
116+
default HW_LCD_DC_GPIO_CUST if HW_CUSTOM
117+
default 21 if HW_WROVERKIT
118+
119+
config HW_LCD_RESET_GPIO
120+
int
121+
default HW_LCD_RESET_GPIO_CUST if HW_CUSTOM
122+
default 18 if HW_WROVERKIT
123+
124+
config HW_LCD_BL_GPIO
125+
int
126+
default HW_LCD_BL_GPIO_CUST if HW_CUSTOM
127+
default 5 if HW_WROVERKIT
128+
129+
130+
config SOUND_ENA
131+
bool "Analog audio on GPIO26"
132+
default n
133+
help
134+
ESP32 will output 0-3.3V analog audio signal on GPIO26.
135+
136+
137+
config HW_PSX_ENA
138+
bool "Enable PSX controller input"
139+
default y
140+
help
141+
If you connect a PSX/PS2 controller to the following GPIOs, you can control the NES.
142+
143+
144+
config HW_PSX_CLK
145+
int "PSX controller CLK GPIO pin"
146+
depends on HW_PSX_ENA
147+
range 1 35
148+
default 14
149+
150+
config HW_PSX_DAT
151+
int "PSX controller DATa GPIO pin"
152+
depends on HW_PSX_ENA
153+
range 1 35
154+
default 27
155+
156+
config HW_PSX_ATT
157+
int "PSX controller ATTention GPIO pin"
158+
depends on HW_PSX_ENA
159+
range 1 35
160+
default 16
161+
162+
config HW_PSX_CMD
163+
int "PSX controller CoMmanD GPIO pin"
164+
depends on HW_PSX_ENA
165+
range 1 35
166+
default 2
167+
168+
endmenu

components/nofrendo-esp32/psxcontroller.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222
#include "driver/gpio.h"
2323
#include "soc/gpio_struct.h"
2424
#include "psxcontroller.h"
25+
#include "sdkconfig.h"
2526

26-
#define PSX_CLK 14
27-
#define PSX_DAT 27
28-
#define PSX_ATT 16
29-
#define PSX_CMD 2
27+
#define PSX_CLK CONFIG_HW_PSX_CLK
28+
#define PSX_DAT CONFIG_HW_PSX_DAT
29+
#define PSX_ATT CONFIG_HW_PSX_ATT
30+
#define PSX_CMD CONFIG_HW_PSX_CMD
3031

3132
#define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;")
3233

3334

35+
#if CONFIG_HW_PSX_ENA
36+
3437
/* Sends and receives a byte from/to the PSX controller using SPI */
3538
static int psxSendRecv(int send) {
3639
int x;
@@ -107,7 +110,6 @@ void psxcontrollerInit() {
107110
gpio_config(&gpioconf[0]);
108111
gpio_config(&gpioconf[1]);
109112

110-
PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO27_U);
111113
//Send a few dummy bytes to clean the pipes.
112114
psxSendRecv(0);
113115
psxDone();
@@ -126,3 +128,16 @@ void psxcontrollerInit() {
126128
}
127129
}
128130

131+
132+
#else
133+
134+
int psxReadInput() {
135+
return 0xFFFF;
136+
}
137+
138+
139+
void psxcontrollerInit() {
140+
printf("PSX controller disabled in menuconfig; no input enabled.\n");
141+
}
142+
143+
#endif

0 commit comments

Comments
 (0)