-
Notifications
You must be signed in to change notification settings - Fork 2
/
nesemu.ino
139 lines (121 loc) · 3.55 KB
/
nesemu.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* Corn 2020
**
** Permission to use, copy, modify, and/or distribute this software for
** any purpose with or without fee is hereby granted, provided that the
** above copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
#include "freertos/FreeRTOS.h"
//#include <WiFi.h>
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "esp_partition.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_vfs_fat.h"
#include "esp_spiffs.h"
//#include "esp_int_wdt.h"
//#include "esp_task_wdt.h"
//#include "esp_bt.h"
#include "soc/rtc.h"
//#include "driver/spi_master.h"
//#include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h"
#include "driver/gpio.h"
#include "sdmmc_cmd.h"
#include "nvs_flash.h"
#include "config.h"
#include "src/Controller.h"
#include "src/nofrendo.h"
#include "src/menu.h"
#ifdef SKIP_MENU
extern char *selectedRomFilename = "/spiffs/unknown.nes";
#else
extern char *selectedRomFilename;
#endif
esp_err_t event_handler(void *ctx, system_event_t *event)
{
return ESP_OK;
}
#ifdef CONFIG_SD_CARD
esp_err_t registerSdCard()
{
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
// host.command_timeout_ms=200;
// host.max_freq_khz = SDMMC_FREQ_PROBING;
sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
slot_config.gpio_miso = (gpio_num_t)CONFIG_SD_MISO;
slot_config.gpio_mosi = (gpio_num_t)CONFIG_SD_MOSI;
slot_config.gpio_sck = (gpio_num_t)CONFIG_SD_SCK;
slot_config.gpio_cs = (gpio_num_t)CONFIG_SD_CS;
slot_config.dma_channel = 2; //2
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = false,
.max_files = 2
};
sdmmc_card_t *card;
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/spiffs", &host, &slot_config, &mount_config, &card);
// Card has been initialized, print its properties
if (!ret) sdmmc_card_print_info(stdout, card);
return ret;
}
#else
esp_err_t registerSpiffs()
{
esp_vfs_spiffs_conf_t conf = {
.base_path = "/spiffs",
.partition_label = NULL,
.max_files = 5,
.format_if_mount_failed = false
};
esp_err_t ret = esp_vfs_spiffs_register(&conf);
struct stat st;
if (stat(ROM_LIST, &st) != 0)
{
printf("Cannot locate rom list in %s", ROM_LIST);
}
return ret;
}
#endif
void setup()
{
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_240M); //make sure we run at full tilt ;)
//WiFi.mode( WIFI_OFF );
//btStop();
//esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); //Drop Bluetooth and get some memory back
#ifdef CONFIG_SD_CARD
vTaskDelay(300 / portTICK_RATE_MS); //a small delay to let SD card power up
if (registerSdCard()) {
printf("Failed to mount SD card\n");
while(1) vTaskDelay(1); //stop
}
#else
if (registerSpiffs()) {
printf("Failed to mount SPIFFS partition\n");
while(1) vTaskDelay(1); //stop
}
#endif
ControllerInit();
}
void esp_wake_deep_sleep()
{
esp_restart();
}
void loop() {
#ifndef SKIP_MENU
selectedRomFilename = runMenu();
#endif
printf("NoFrendo start!\n");
nofrendo_main(0, NULL);
printf("Ops...NoFrendo died?!\n");
while(1) vTaskDelay(1); //stop
}