Skip to content

Commit c4578e5

Browse files
committed
Fixed compilation for other esp32 chips
1 parent b3a1065 commit c4578e5

File tree

9 files changed

+48
-44
lines changed

9 files changed

+48
-44
lines changed

components/retro-go/rg_audio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void rg_audio_init(int sampleRate)
5656
.bits_per_sample = 16,
5757
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
5858
.communication_format = I2S_COMM_FORMAT_STAND_MSB,
59-
.dma_buf_count = 5, // Goal is to have ~800 samples over 2-8 buffers (optimize for 533 usage)
60-
.dma_buf_len = 180, // The unit is stereo samples (4 bytes)
59+
.dma_buf_count = 3, // Goal is to have ~800 samples over 2-8 buffers (3x270 or 5x180 are pretty good)
60+
.dma_buf_len = 270, // The unit is stereo samples (4 bytes) (optimize for 533 usage)
6161
.intr_alloc_flags = 0, // ESP_INTR_FLAG_LEVEL1
6262
.use_apll = 0
6363
};

components/retro-go/rg_display.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static void spi_init()
164164
gpio_set_level(RG_GPIO_LCD_DC, 1);
165165

166166
//Initialize the SPI bus
167-
spi_bus_initialize(HSPI_HOST, &buscfg, 1);
168-
spi_bus_add_device(HSPI_HOST, &devcfg, &spi_dev);
167+
spi_bus_initialize(SPI2_HOST, &buscfg, 1);
168+
spi_bus_add_device(SPI2_HOST, &devcfg, &spi_dev);
169169
//assert(ret==ESP_OK);
170170

171171
xTaskCreatePinnedToCore(&spi_task, "spi_task", 1024, NULL, 5, NULL, 1);
@@ -175,7 +175,7 @@ static void spi_deinit(void)
175175
{
176176
// To do: Stop SPI task...
177177
spi_bus_remove_device(spi_dev);
178-
spi_bus_free(HSPI_HOST);
178+
spi_bus_free(SPI2_HOST);
179179
}
180180

181181
static void ili9341_cmd(uint8_t cmd, const void *data, size_t data_len)
@@ -219,7 +219,7 @@ static void ili9341_init()
219219
spi_init();
220220

221221
#define ILI9341_CMD(cmd, data...) {const uint8_t x[] = data; ili9341_cmd(cmd, x, sizeof(x));}
222-
#if defined(RG_TARGET_ODROID_GO)
222+
#if RG_SCREEN_TYPE == 0 // LCD Model (ODROID-GO)
223223
ILI9341_CMD(0x01, {}); // Reset
224224
ILI9341_CMD(0x3A, {0x55}); // Pixel Format Set RGB565
225225
ILI9341_CMD(0xCF, {0x00, 0xc3, 0x30});
@@ -242,7 +242,7 @@ static void ili9341_init()
242242
ILI9341_CMD(0xE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}); // Set Gamma
243243
ILI9341_CMD(0x11, {}); // Exit Sleep
244244
ILI9341_CMD(0x29, {}); // Display on
245-
#elif defined(RG_TARGET_MRGC_G32)
245+
#elif RG_SCREEN_TYPE == 1 // LCD Model (MRGC-G32)
246246
ILI9341_CMD(0x01, {}); // Reset
247247
ILI9341_CMD(0x3A, {0x55}); // Pixel Format Set RGB565
248248
ILI9341_CMD(0x36, {(0x00|0x00|0x00)});
@@ -260,7 +260,7 @@ static void ili9341_init()
260260
ILI9341_CMD(0xE1, {0xD0, 0x00, 0x03, 0x09, 0x05, 0x25, 0x3A, 0x55, 0x50, 0x3D, 0x1C, 0x1D, 0x1D, 0x1E});
261261
ILI9341_CMD(0x11, {}); // Exit Sleep
262262
ILI9341_CMD(0x29, {}); // Display on
263-
#elif defined(RG_TARGET_QTPY_GAMER)
263+
#elif RG_SCREEN_TYPE == 2 // LCD Model (QT-PY Gamer)
264264
ILI9341_CMD(0x01, {}); // Reset
265265
ILI9341_CMD(0x11, {}); // Exit Sleep
266266
ILI9341_CMD(0x3A, {0x55}); // Pixel Format Set RGB565

components/retro-go/rg_input.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void rg_input_init(void)
168168

169169
const char *driver = "GPIO";
170170

171-
adc1_config_width(ADC_WIDTH_12Bit);
171+
adc1_config_width(ADC_WIDTH_MAX - 1);
172172
adc1_config_channel_atten(RG_GPIO_GAMEPAD_X, ADC_ATTEN_11db);
173173
adc1_config_channel_atten(RG_GPIO_GAMEPAD_Y, ADC_ATTEN_11db);
174174

@@ -303,9 +303,9 @@ bool rg_input_read_battery(float *percent, float *volts)
303303
// ADC not initialized
304304
if (adc_chars.vref == 0)
305305
{
306-
adc1_config_width(ADC_WIDTH_12Bit);
306+
adc1_config_width(ADC_WIDTH_MAX - 1);
307307
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_11db);
308-
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_11db, ADC_WIDTH_BIT_12, 1100, &adc_chars);
308+
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_11db, ADC_WIDTH_MAX - 1, 1100, &adc_chars);
309309
}
310310

311311
for (int i = 0; i < 4; ++i)

components/retro-go/rg_storage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void rg_storage_init(void)
6565
#if RG_STORAGE_DRIVER == 1
6666

6767
sdmmc_host_t host_config = SDSPI_HOST_DEFAULT();
68-
host_config.slot = HSPI_HOST;
68+
host_config.slot = SPI2_HOST;
6969
host_config.max_freq_khz = SDMMC_FREQ_DEFAULT; // SDMMC_FREQ_26M;
7070
host_config.do_transaction = &sdcard_do_transaction;
7171

components/retro-go/targets/esplay-micro.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

components/retro-go/targets/mrgc-g32.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
#define RG_AUDIO_USE_EXT_DAC 1
4242

4343
// Video
44-
#define RG_SCREEN_TYPE 0
44+
#define RG_SCREEN_DRIVER 0 // 0 = ILI9341
45+
#define RG_SCREEN_TYPE 1
4546
#define RG_SCREEN_WIDTH 240
4647
#define RG_SCREEN_HEIGHT 320
4748
#define RG_SCREEN_ROTATE 0

components/retro-go/targets/odroid-go.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define RG_AUDIO_USE_EXT_DAC 1
1313

1414
// Video
15+
#define RG_SCREEN_DRIVER 0 // 0 = ILI9341
1516
#define RG_SCREEN_TYPE 0
1617
#define RG_SCREEN_WIDTH 320
1718
#define RG_SCREEN_HEIGHT 240

components/retro-go/targets/qtpy-gamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#define RG_AUDIO_USE_SPEAKER 1
1212

1313
// Video
14-
#define RG_SCREEN_TYPE 0
14+
#define RG_SCREEN_DRIVER 0 // 0 = ILI9341
15+
#define RG_SCREEN_TYPE 2
1516
#define RG_SCREEN_WIDTH 240
1617
#define RG_SCREEN_HEIGHT 240
1718
#define RG_SCREEN_ROTATE 0

rg_tool.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import shutil
66
import shlex
7+
import glob
78
import time
89
import math
910
import sys
@@ -16,7 +17,11 @@
1617
except:
1718
pass
1819

19-
DEFAULT_TARGET = os.getenv("RG_TOOL_TARGET", "odroid-go")
20+
TARGETS = ["odroid-go", "mrgc-g32", "qtpy-gamer"]
21+
for t in glob.glob("components/retro-go/targets/*.h"):
22+
TARGETS.append(os.path.basename(t)[0:-2])
23+
24+
DEFAULT_TARGET = os.getenv("RG_TOOL_TARGET", TARGETS[0])
2025
DEFAULT_BAUD = os.getenv("RG_TOOL_BAUD", "1152000")
2126
DEFAULT_PORT = os.getenv("RG_TOOL_PORT", "COM3")
2227
PROJECT_NAME = os.getenv("PROJECT_NAME", "Retro-Go") # os.path.basename(os.getcwd()).title()
@@ -120,8 +125,8 @@ def analyze_profile(frames):
120125
debug_print("")
121126

122127

123-
def build_firmware(targets, device_type):
124-
print("Building firmware with: %s\n" % " ".join(targets))
128+
def build_firmware(apps, device_type):
129+
print("Building firmware with: %s\n" % " ".join(apps))
125130
args = [
126131
sys.executable,
127132
"tools/mkfw.py",
@@ -133,16 +138,16 @@ def build_firmware(targets, device_type):
133138
if device_type in ["mrgc-g32", "esplay"]:
134139
args.append("--esplay")
135140

136-
for target in targets:
137-
part = PROJECT_APPS[target]
138-
args += [str(part[0]), str(part[1]), str(part[2]), target, os.path.join(target, "build", target + ".bin")]
141+
for app in apps:
142+
part = PROJECT_APPS[app]
143+
args += [str(part[0]), str(part[1]), str(part[2]), app, os.path.join(app, "build", app + ".bin")]
139144

140145
print("Running: %s" % ' '.join(shlex.quote(arg) for arg in args[1:]))
141146
subprocess.run(args, check=True)
142147

143148

144-
def build_image(targets, device_type):
145-
print("Building image with: %s\n" % " ".join(targets))
149+
def build_image(apps, device_type):
150+
print("Building image with: %s\n" % " ".join(apps))
146151
image_file = ("%s_%s_%s.img" % (PROJECT_NAME, PROJECT_VER, device_type)).lower()
147152
image_data = bytearray(b"\xFF" * 0x10000)
148153
table_ota = 0
@@ -152,17 +157,17 @@ def build_image(targets, device_type):
152157
"phy_init, data, phy, 61440, 4096",
153158
]
154159

155-
for target in targets:
156-
part = PROJECT_APPS[target]
157-
with open(os.path.join(target, "build", target + ".bin"), "rb") as f:
160+
for app in apps:
161+
part = PROJECT_APPS[app]
162+
with open(os.path.join(app, "build", app + ".bin"), "rb") as f:
158163
data = f.read()
159164
part_size = max(part[2], math.ceil(len(data) / 0x10000) * 0x10000)
160-
table_csv.append("%s, app, ota_%d, %d, %d" % (target, table_ota, len(image_data), part_size))
165+
table_csv.append("%s, app, ota_%d, %d, %d" % (app, table_ota, len(image_data), part_size))
161166
table_ota += 1
162167
image_data += data + b"\xFF" * (part_size - len(data))
163168

164169
try:
165-
cwd = os.path.join(os.getcwd(), list(targets)[0])
170+
cwd = os.path.join(os.getcwd(), list(apps)[0])
166171
subprocess.run("idf.py bootloader", stdout=subprocess.DEVNULL, shell=True, check=True, cwd=cwd)
167172
with open(os.path.join(cwd, "build", "bootloader", "bootloader.bin"), "rb") as f:
168173
bootloader_bin = f.read()
@@ -182,32 +187,32 @@ def build_image(targets, device_type):
182187
print("Saved image '%s' (%d bytes)\n" % (image_file, len(image_data)))
183188

184189

185-
def clean_app(target):
186-
print("Cleaning up app '%s'..." % target)
190+
def clean_app(app):
191+
print("Cleaning up app '%s'..." % app)
187192
try:
188-
os.unlink(os.path.join(target, "sdkconfig"))
189-
os.unlink(os.path.join(target, "sdkconfig.old"))
193+
os.unlink(os.path.join(app, "sdkconfig"))
194+
os.unlink(os.path.join(app, "sdkconfig.old"))
190195
except:
191196
pass
192197
try:
193-
shutil.rmtree(os.path.join(target, "build"))
198+
shutil.rmtree(os.path.join(app, "build"))
194199
except:
195200
pass
196201
print("Done.\n")
197202

198203

199-
def build_app(target, device_type, with_profiling=False, with_netplay=False):
204+
def build_app(app, device_type, with_profiling=False, with_netplay=False):
200205
# To do: clean up if any of the flags changed since last build
201-
print("Building app '%s'" % target)
206+
print("Building app '%s'" % app)
202207
os.putenv("ENABLE_PROFILING", "1" if with_profiling else "0")
203208
os.putenv("ENABLE_NETPLAY", "1" if with_netplay else "0")
204209
os.putenv("PROJECT_VER", PROJECT_VER)
205210
os.putenv("RG_TARGET", re.sub(r'[^A-Z0-9]', '_', device_type.upper()))
206-
subprocess.run("idf.py app", shell=True, check=True, cwd=os.path.join(os.getcwd(), target))
211+
subprocess.run("idf.py app", shell=True, check=True, cwd=os.path.join(os.getcwd(), app))
207212

208213
try:
209214
print("\nPatching esp_image_header_t to skip sha256 on boot... ", end="")
210-
with open(os.path.join(target, "build", target + ".bin"), "r+b") as fp:
215+
with open(os.path.join(app, "build", app + ".bin"), "r+b") as fp:
211216
fp.seek(23)
212217
fp.write(b"\0")
213218
print("done!\n")
@@ -216,10 +221,10 @@ def build_app(target, device_type, with_profiling=False, with_netplay=False):
216221
pass
217222

218223

219-
def monitor_app(target, port, baudrate=115200):
220-
print("Starting monitor for app '%s'" % target)
224+
def monitor_app(app, port, baudrate=115200):
225+
print("Starting monitor for app '%s'" % app)
221226
mon = serial.Serial(port, baudrate=baudrate, timeout=0)
222-
elf = os.path.join(target, "build", target + ".elf")
227+
elf = os.path.join(app, "build", app + ".elf")
223228

224229
mon.setDTR(False)
225230
mon.setRTS(False)
@@ -287,7 +292,7 @@ def monitor_app(target, port, baudrate=115200):
287292
"apps", nargs="*", default="all", choices=["all"] + list(PROJECT_APPS.keys())
288293
)
289294
parser.add_argument(
290-
"--target", default=DEFAULT_TARGET, choices=["odroid-go", "esp32s2", "mrgc-g32", "qtpy-gamer"], help="Device to target"
295+
"--target", default=DEFAULT_TARGET, choices=set(TARGETS), help="Device to target"
291296
)
292297
parser.add_argument(
293298
"--with-netplay", action="store_const", const=True, help="Build with netplay enabled"

0 commit comments

Comments
 (0)