Skip to content

Commit 2e6c670

Browse files
committed
Mon 24 Feb 2020 20:46:58 EST - v.2.1-NES+LYNX featuring acceleration and scaling from @ducalex
1 parent 43bac23 commit 2e6c670

File tree

5 files changed

+196
-5
lines changed

5 files changed

+196
-5
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#include "odroid_system.h"
2+
#include "freertos/FreeRTOS.h"
3+
#include "esp_heap_caps.h"
4+
#include "esp_partition.h"
5+
#include "esp_ota_ops.h"
6+
#include "esp_system.h"
7+
#include "esp_event.h"
8+
#include "driver/rtc_io.h"
9+
#include "string.h"
10+
#include "stdio.h"
11+
12+
static bool system_initialized = false;
13+
14+
ODROID_START_ACTION startAction = 0;
15+
ODROID_SCALING scalingMode = ODROID_SCALING_FILL;
16+
int8_t speedupEnabled = 0;
17+
int8_t forceRedraw = 0;
18+
19+
void odroid_system_init(int app_id, int sampleRate, char **romPath)
20+
{
21+
if (system_initialized) abort();
22+
23+
printf("odroid_system_init: %d KB free\n", esp_get_free_heap_size() / 1024);
24+
25+
odroid_settings_init(app_id);
26+
odroid_overlay_init();
27+
odroid_system_gpio_init();
28+
odroid_input_gamepad_init();
29+
odroid_input_battery_level_init();
30+
31+
odroid_gamepad_state bootState = odroid_input_read_raw();
32+
if (bootState.values[ODROID_INPUT_MENU])
33+
{
34+
// Force return to menu to recover from ROM loading crashes
35+
odroid_system_application_set(0);
36+
esp_restart();
37+
}
38+
39+
startAction = odroid_settings_StartAction_get();
40+
if (startAction == ODROID_START_ACTION_RESTART)
41+
{
42+
odroid_settings_StartAction_set(ODROID_START_ACTION_RESUME);
43+
}
44+
45+
//sdcard init must be before LCD init
46+
esp_err_t sd_init = odroid_sdcard_open();
47+
48+
ili9341_init();
49+
50+
if (esp_reset_reason() == ESP_RST_PANIC)
51+
{
52+
odroid_overlay_alert("The emulator crashed");
53+
odroid_system_application_set(0);
54+
esp_restart();
55+
}
56+
57+
if (esp_reset_reason() != ESP_RST_SW)
58+
{
59+
ili9341_blank_screen();
60+
//odroid_display_show_hourglass();
61+
}
62+
63+
if (sd_init != ESP_OK)
64+
{
65+
odroid_display_show_error(ODROID_SD_ERR_NOCARD);
66+
odroid_system_halt();
67+
}
68+
69+
*romPath = odroid_settings_RomFilePath_get();
70+
if (!*romPath || strlen(*romPath) < 4)
71+
{
72+
odroid_overlay_alert("ROM File not found!");
73+
odroid_system_halt();
74+
}
75+
76+
odroid_audio_init(odroid_settings_AudioSink_get(), sampleRate);
77+
78+
scalingMode = odroid_settings_Scaling_get();
79+
80+
if (startAction == ODROID_START_ACTION_NETPLAY)
81+
{
82+
// odroid_netplay_init();
83+
}
84+
85+
system_initialized = true;
86+
87+
printf("odroid_system_init: System ready!\n");
88+
}
89+
90+
void odroid_system_gpio_init()
91+
{
92+
rtc_gpio_deinit(ODROID_GAMEPAD_IO_MENU);
93+
//rtc_gpio_deinit(GPIO_NUM_14);
94+
95+
// blue led
96+
gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
97+
gpio_set_level(GPIO_NUM_2, 0);
98+
99+
// Disable LCD CD to prevent garbage
100+
gpio_set_direction(GPIO_NUM_5, GPIO_MODE_OUTPUT);
101+
gpio_set_level(GPIO_NUM_5, 1);
102+
}
103+
104+
void odroid_system_application_set(int slot)
105+
{
106+
const esp_partition_t* partition = esp_partition_find_first(
107+
ESP_PARTITION_TYPE_APP,
108+
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + slot,
109+
NULL);
110+
if (partition != NULL)
111+
{
112+
esp_err_t err = esp_ota_set_boot_partition(partition);
113+
if (err != ESP_OK)
114+
{
115+
printf("odroid_system_application_set: esp_ota_set_boot_partition failed.\n");
116+
abort();
117+
}
118+
}
119+
}
120+
121+
void odroid_system_sleep()
122+
{
123+
printf("odroid_system_sleep: Entered.\n");
124+
125+
// Wait for button release
126+
odroid_gamepad_state joystick;
127+
odroid_input_gamepad_read(&joystick);
128+
129+
while (joystick.values[ODROID_INPUT_MENU])
130+
{
131+
vTaskDelay(1);
132+
odroid_input_gamepad_read(&joystick);
133+
}
134+
135+
vTaskDelay(100);
136+
esp_deep_sleep_start();
137+
}
138+
139+
void odroid_system_halt()
140+
{
141+
vTaskSuspendAll();
142+
while (1);
143+
}
144+
145+
void odroid_system_led_set(int value)
146+
{
147+
if (!system_initialized)
148+
{
149+
printf("odroid_system_init not called before use.\n");
150+
abort();
151+
}
152+
153+
gpio_set_level(GPIO_NUM_2, value);
154+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include "odroid_audio.h"
4+
#include "odroid_display.h"
5+
#include "odroid_input.h"
6+
#include "odroid_overlay.h"
7+
#include "odroid_netplay.h"
8+
#include "odroid_sdcard.h"
9+
#include "odroid_settings.h"
10+
#include "esp_system.h"
11+
#include "stdbool.h"
12+
13+
void odroid_system_init(int app_id, int sampleRate, char **romPath);
14+
void odroid_system_halt();
15+
void odroid_system_sleep();
16+
void odroid_system_application_set(int slot);
17+
void odroid_system_led_set(int value);
18+
void odroid_system_gpio_init();
19+
20+
extern ODROID_START_ACTION startAction;
21+
extern ODROID_SCALING scalingMode;
22+
extern int8_t forceRedraw;
23+
extern int8_t speedupEnabled;
24+
25+
inline uint get_elapsed_time_since(uint start)
26+
{
27+
uint now = xthal_get_ccount();
28+
return ((now > start) ? now - start : ((uint64_t)now + (uint64_t)0xffffffff) - start);
29+
}

Launchers/retro-esp32/sdkconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ CONFIG_MONITOR_BAUD=115200
8383
#
8484
# Retro ESP32 Configuration
8585
#
86-
CONFIG_LCD_DRIVER_CHIP_ODROID_GO=y
87-
CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32=
88-
CONFIG_DEFAULT_MENU_KEY=y
89-
CONFIG_COMBO_MENU_KEY=
86+
CONFIG_LCD_DRIVER_CHIP_ODROID_GO=
87+
CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32=y
88+
CONFIG_DEFAULT_MENU_KEY=
89+
CONFIG_COMBO_MENU_KEY=y
9090

9191
#
9292
# Partition Table

Launchers/retro-esp32/sdkconfig.old

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ CONFIG_MONITOR_BAUD_OTHER=
8080
CONFIG_MONITOR_BAUD_OTHER_VAL=115200
8181
CONFIG_MONITOR_BAUD=115200
8282

83+
#
84+
# Retro ESP32 Configuration
85+
#
86+
CONFIG_LCD_DRIVER_CHIP_ODROID_GO=y
87+
CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32=
88+
CONFIG_DEFAULT_MENU_KEY=y
89+
CONFIG_COMBO_MENU_KEY=
90+
8391
#
8492
# Partition Table
8593
#

Odroid/odroid-go-firmware

0 commit comments

Comments
 (0)