Skip to content

Commit 0c1fcd5

Browse files
authored
Added ESP32-P4 generic target file for developpement purpose (#212)
Adds a ESP32-P4 generic target file for development that can be replicated on a breadboard.
1 parent 58a6e55 commit 0c1fcd5

File tree

13 files changed

+2432
-2
lines changed

13 files changed

+2432
-2
lines changed

components/retro-go/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "targets/vmu/config.h"
2727
#elif defined(RG_TARGET_CROKPOCKET)
2828
#include "targets/crokpocket/config.h"
29+
#elif defined(RG_TARGET_ESP32_P4)
30+
#include "targets/esp32-p4/config.h"
2931
#else
3032
#warning "No target defined. Defaulting to ODROID-GO."
3133
#include "targets/odroid-go/config.h"

components/retro-go/drivers/display/ili9341.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ static void spi_init(void)
117117
.queue_size = SPI_TRANSACTION_COUNT, // We want to be able to queue 5 transactions at a time
118118
.pre_cb = &spi_pre_transfer_cb, // Specify pre-transfer callback to handle D/C line and SPI lock
119119
.flags = SPI_DEVICE_NO_DUMMY, // SPI_DEVICE_HALFDUPLEX;
120+
#ifdef RG_TARGET_ESP32_P4
121+
.clock_source = SPI_CLK_SRC_SPLL,
122+
#endif
120123
};
121124

122125
esp_err_t ret;

components/retro-go/rg_storage.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#define SDCARD_DO_TRANSACTION sdspi_host_do_transaction
1313
#elif defined(RG_STORAGE_SDMMC_HOST)
1414
#include <driver/sdmmc_host.h>
15+
#ifdef CONFIG_IDF_TARGET_ESP32P4
16+
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
17+
#endif
1518
#define SDCARD_DO_TRANSACTION sdmmc_host_do_transaction
1619
#endif
1720

@@ -121,18 +124,32 @@ void rg_storage_init(void)
121124
RG_LOGI("Looking for SD Card using SDMMC...");
122125

123126
sdmmc_host_t host_config = SDMMC_HOST_DEFAULT();
124-
host_config.flags = SDMMC_HOST_FLAG_1BIT;
125127
host_config.slot = RG_STORAGE_SDMMC_HOST;
126128
host_config.max_freq_khz = RG_STORAGE_SDMMC_SPEED;
127129
host_config.do_transaction = &sdcard_do_transaction;
128130

131+
#ifdef CONFIG_IDF_TARGET_ESP32P4
132+
sd_pwr_ctrl_ldo_config_t ldo_config = {
133+
.ldo_chan_id = 4,
134+
};
135+
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
136+
137+
esp_err_t ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
138+
if (ret != ESP_OK) {
139+
RG_LOGE("Failed to create a new on-chip LDO power control driver");
140+
return;
141+
}
142+
host_config.pwr_ctrl_handle = pwr_ctrl_handle;
143+
#endif
144+
129145
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
130146
slot_config.width = 1;
131147
#if SOC_SDMMC_USE_GPIO_MATRIX /* Only the esp32-s3 routes SDMMC through the GPIO matrix */
132148
slot_config.clk = RG_GPIO_SDMMC_CLK;
133149
slot_config.cmd = RG_GPIO_SDMMC_CMD;
134150
slot_config.d0 = RG_GPIO_SDMMC_D0;
135151
#if defined(RG_GPIO_SDMMC_D1) && defined(RG_GPIO_SDMMC_D2) && defined(RG_GPIO_SDMMC_D3)
152+
slot_config.width = 4;
136153
slot_config.d1 = RG_GPIO_SDMMC_D1;
137154
slot_config.d2 = RG_GPIO_SDMMC_D2;
138155
slot_config.d3 = RG_GPIO_SDMMC_D3;
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/* Configuration for the ESP32-P4 dev board
2+
* The GPIOs were chosen arbitrarily, but you can choose whatever you want thanks to the I/O MUX
3+
* command to build: python rg_tool.py --target esp32-p4 build-img --no-networking
4+
*/
5+
6+
/****************************************************************************
7+
* Target definition for ESP32-P4 Dev-Board *
8+
****************************************************************************/
9+
#define RG_TARGET_NAME "ESP32-P4"
10+
11+
12+
/****************************************************************************
13+
* Status LED *
14+
****************************************************************************/
15+
// #define RG_LED_DRIVER 1 // 1 = GPIO
16+
// #define RG_GPIO_LED GPIO_NUM_NC
17+
// #define RG_GPIO_LED_INVERT // Uncomment if the LED is active LOW
18+
19+
20+
/****************************************************************************
21+
* I2C / GPIO Extender *
22+
****************************************************************************/
23+
// #define RG_I2C_GPIO_DRIVER 0 // 1 = AW9523, 2 = PCF9539, 3 = MCP23017, 4 = PCF8575
24+
// #define RG_I2C_GPIO_ADDR 0x00
25+
// #define RG_GPIO_I2C_SDA GPIO_NUM_15
26+
// #define RG_GPIO_I2C_SCL GPIO_NUM_4
27+
28+
29+
/****************************************************************************
30+
* Storage *
31+
****************************************************************************/
32+
#define RG_STORAGE_ROOT "/sd"
33+
// #define RG_STORAGE_SDSPI_HOST SPI2_HOST
34+
// #define RG_STORAGE_SDSPI_SPEED SDMMC_FREQ_DEFAULT
35+
// #define RG_GPIO_SDSPI_MISO GPIO_NUM_19
36+
// #define RG_GPIO_SDSPI_MOSI GPIO_NUM_23
37+
// #define RG_GPIO_SDSPI_CLK GPIO_NUM_18
38+
// #define RG_GPIO_SDSPI_CS GPIO_NUM_22
39+
#define RG_STORAGE_SDMMC_HOST SDMMC_HOST_SLOT_1
40+
#define RG_STORAGE_SDMMC_SPEED SDMMC_FREQ_HIGHSPEED
41+
#define RG_GPIO_SDMMC_CLK GPIO_NUM_43
42+
#define RG_GPIO_SDMMC_CMD GPIO_NUM_44
43+
#define RG_GPIO_SDMMC_D0 GPIO_NUM_39
44+
#define RG_GPIO_SDMMC_D1 GPIO_NUM_40
45+
#define RG_GPIO_SDMMC_D2 GPIO_NUM_41
46+
#define RG_GPIO_SDMMC_D3 GPIO_NUM_42
47+
// #define RG_STORAGE_FLASH_PARTITION "vfs"
48+
49+
50+
/****************************************************************************
51+
* Audio *
52+
****************************************************************************/
53+
#define RG_AUDIO_USE_INT_DAC 0 // 0 = Disable, 1 = GPIO25, 2 = GPIO26, 3 = Both
54+
#define RG_AUDIO_USE_EXT_DAC 1 // 0 = Disable, 1 = Enable
55+
#define RG_GPIO_SND_I2S_BCK GPIO_NUM_48
56+
#define RG_GPIO_SND_I2S_WS GPIO_NUM_49
57+
#define RG_GPIO_SND_I2S_DATA GPIO_NUM_46
58+
#define RG_GPIO_SND_AMP_ENABLE GPIO_NUM_47
59+
// #define RG_GPIO_SND_AMP_ENABLE_INVERT // Uncomment if the mute = HIGH
60+
61+
62+
/****************************************************************************
63+
* Video *
64+
****************************************************************************/
65+
#define RG_SCREEN_DRIVER 0 // 0 = ILI9341/ST7789
66+
#define RG_SCREEN_HOST SPI3_HOST
67+
#define RG_SCREEN_SPEED SPI_MASTER_FREQ_80M // SPI_MASTER_FREQ_40M
68+
#define RG_SCREEN_BACKLIGHT 0
69+
#define RG_SCREEN_WIDTH 320
70+
#define RG_SCREEN_HEIGHT 240
71+
#define RG_SCREEN_ROTATE 0
72+
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
73+
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
74+
#define RG_SCREEN_PARTIAL_UPDATES 1
75+
#define RG_SCREEN_INIT() \
76+
ILI9341_CMD(0xCF, 0x00, 0xc3, 0x30); \
77+
ILI9341_CMD(0xED, 0x64, 0x03, 0x12, 0x81); \
78+
ILI9341_CMD(0xE8, 0x85, 0x00, 0x78); \
79+
ILI9341_CMD(0xCB, 0x39, 0x2c, 0x00, 0x34, 0x02); \
80+
ILI9341_CMD(0xF7, 0x20); \
81+
ILI9341_CMD(0xEA, 0x00, 0x00); \
82+
ILI9341_CMD(0xC0, 0x1B); /* Power control //VRH[5:0] */ \
83+
ILI9341_CMD(0xC1, 0x12); /* Power control //SAP[2:0];BT[3:0] */ \
84+
ILI9341_CMD(0xC5, 0x32, 0x3C); /* VCM control */ \
85+
ILI9341_CMD(0xC7, 0x91); /* VCM control2 */ \
86+
ILI9341_CMD(0x36, 0x08); /* Memory Access Control */ \
87+
ILI9341_CMD(0xB1, 0x00, 0x10); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
88+
ILI9341_CMD(0xB6, 0x0A, 0xA2); /* Display Function Control */ \
89+
ILI9341_CMD(0xF6, 0x01, 0x30); \
90+
ILI9341_CMD(0xF2, 0x00); /* 3Gamma Function Disable */ \
91+
ILI9341_CMD(0x26, 0x01); /* Gamma curve selected */ \
92+
ILI9341_CMD(0xE0, 0xD0, 0x00, 0x02, 0x07, 0x0a, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0e, 0x12, 0x14, 0x17); \
93+
ILI9341_CMD(0xE1, 0xD0, 0x00, 0x02, 0x07, 0x0a, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1b, 0x1e);
94+
95+
//#define RG_GPIO_LCD_MISO GPIO_NUM_NC
96+
#define RG_GPIO_LCD_MOSI GPIO_NUM_22
97+
#define RG_GPIO_LCD_CLK GPIO_NUM_23
98+
#define RG_GPIO_LCD_CS GPIO_NUM_24
99+
#define RG_GPIO_LCD_DC GPIO_NUM_25
100+
#define RG_GPIO_LCD_RST GPIO_NUM_26
101+
// #define RG_GPIO_LCD_BCKL GPIO_NUM_NC
102+
// #define RG_GPIO_LCD_BCKL_INVERT // Uncomment if the LED is active LOW
103+
104+
105+
/****************************************************************************
106+
* Input *
107+
****************************************************************************/
108+
// Refer to rg_input.h to see all available RG_KEY_* and RG_GAMEPAD_*_MAP types
109+
#define RG_GAMEPAD_GPIO_MAP {\
110+
{RG_KEY_LEFT, .num = GPIO_NUM_13, .pullup = 1, .level = 0},\
111+
{RG_KEY_RIGHT, .num = GPIO_NUM_14, .pullup = 1, .level = 0},\
112+
{RG_KEY_UP, .num = GPIO_NUM_15, .pullup = 1, .level = 0},\
113+
{RG_KEY_DOWN, .num = GPIO_NUM_16, .pullup = 1, .level = 0},\
114+
{RG_KEY_SELECT, .num = GPIO_NUM_17, .pullup = 1, .level = 0},\
115+
{RG_KEY_START, .num = GPIO_NUM_18, .pullup = 1, .level = 0},\
116+
{RG_KEY_MENU, .num = GPIO_NUM_19, .pullup = 1, .level = 0},\
117+
{RG_KEY_A, .num = GPIO_NUM_20, .pullup = 1, .level = 0},\
118+
{RG_KEY_B, .num = GPIO_NUM_21, .pullup = 1, .level = 0},\
119+
{RG_KEY_X, .num = GPIO_NUM_12, .pullup = 1, .level = 0},\
120+
{RG_KEY_Y, .num = GPIO_NUM_11, .pullup = 1, .level = 0},\
121+
{RG_KEY_L, .num = GPIO_NUM_10, .pullup = 1, .level = 0},\
122+
{RG_KEY_R, .num = GPIO_NUM_9, .pullup = 1, .level = 0},\
123+
}
124+
125+
126+
/****************************************************************************
127+
* Battery *
128+
****************************************************************************/
129+
// #define RG_BATTERY_DRIVER 1 // 1 = ADC, 2 = MRGC
130+
// #define RG_BATTERY_ADC_UNIT ADC_UNIT_1
131+
// #define RG_BATTERY_ADC_CHANNEL ADC_CHANNEL_0
132+
// #define RG_BATTERY_CALC_PERCENT(raw) (((raw) * 2.f - 3500.f) / (4200.f - 3500.f) * 100.f)
133+
// #define RG_BATTERY_CALC_VOLTAGE(raw) ((raw) * 2.f * 0.001f)
134+
135+
136+
/****************************************************************************
137+
* Updater *
138+
****************************************************************************/
139+
// #define RG_UPDATER_ENABLE 1
140+
// #define RG_UPDATER_APPLICATION RG_APP_FACTORY
141+
// #define RG_UPDATER_DOWNLOAD_LOCATION RG_STORAGE_ROOT "/odroid/firmware"
142+
143+
144+
145+
/****************************************************************************
146+
* Miscellaneous *
147+
****************************************************************************/
148+
#define RG_RECOVERY_BTN RG_KEY_MENU // Keep this button pressed to open the recovery menu
149+
150+
#define RG_CUSTOM_PLATFORM_INIT() \
151+
/* Arbitrary code executed very early during retro-go init */
152+
153+
// See components/retro-go/config.h for more things you can define here!
3.91 MB
Loading
236 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This is a very early "port" whose performance could be improved by adapting retro-go even further for the P4.
2+
3+
Networking has not been tested yet, so build the image without it:
4+
5+
command to build: `python rg_tool.py --target esp32-p4 build-img --no-networking`
6+
7+
ESP-IDF v5.5 is recommended.
8+
9+
## ESP32-P4
10+
- Status: development target
11+
12+
## Hardware
13+
- Module: ESP32-P4-MINI Development Board ref: https://www.cnx-software.com/2025/06/05/esp32-p4-mini-development-board-offers-two-34-pin-gpio-headers-esp32-c6-wireless-module
14+
- ST7789V 320*240 2 inches SPI Display ref: LCD TFT 2.0 inches, IC ST7789V 240RGBx320, SPI
15+
- SD card over SDMMC (4 bits)
16+
- NS4168 Dac (but any I2S DAC should work)
17+
- Built on breadboard
18+
19+
## Images
20+
![ESP32-P4_breadboard_setup.jpg](ESP32-P4_breadboard_setup.jpg)
21+
![SPI_ST7789V_2_inches.png](SPI_ST7789V_2_inches.png)
22+
![ESP32-P4_devboard.png](ESP32-P4_devboard.png)
144 KB
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file is injected late into rg_tool.py, you can run arbitrary python code here
2+
# For example override python variables or set environment variables with os.putenv
3+
4+
# Espressif chip in the device
5+
IDF_TARGET = "esp32p4"
6+
# .fw file format, if supported by the device
7+
# FW_FORMAT = "odroid"
8+
# Default apps to build when none is specified (comment to build all)
9+
DEFAULT_APPS = "launcher retro-core gwenesis fmsx prboom-go gbsp"

0 commit comments

Comments
 (0)