186 lines
5.5 KiB
C
186 lines
5.5 KiB
C
/**
|
|
* @file main.c
|
|
* @brief ESP32-S3 GNUBoy Emulator - Main Entry Point
|
|
*
|
|
* LEGO GameBoy Emulator Project
|
|
* Hardware: Waveshare ESP32-S3-Touch-LCD-2
|
|
*
|
|
* Features:
|
|
* - GameBoy/GameBoy Color emulation
|
|
* - NFC ROM selection
|
|
* - Potentiometer volume/brightness control
|
|
* - Link Cable 2-player support
|
|
* - SD Card ROM loading
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_system.h"
|
|
#include "esp_log.h"
|
|
#include "esp_err.h"
|
|
#include "nvs_flash.h"
|
|
#include "esp_psram.h"
|
|
|
|
#include "hardware_config.h"
|
|
|
|
// Component includes (will be created)
|
|
// #include "st7789.h"
|
|
// #include "nfc_manager.h"
|
|
// #include "link_cable.h"
|
|
// #include "potentiometer_manager.h"
|
|
// #include "gnuboy.h"
|
|
|
|
static const char *TAG = "MAIN";
|
|
|
|
/**
|
|
* @brief Callback for potentiometer changes
|
|
*/
|
|
static void poti_change_handler(uint8_t volume, uint8_t brightness)
|
|
{
|
|
ESP_LOGI(TAG, "Potentiometer changed: Volume=%d%%, Brightness=%d%%",
|
|
volume, brightness);
|
|
|
|
// TODO: Set audio volume when audio is implemented
|
|
// audio_set_volume(volume);
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize NVS (Non-Volatile Storage)
|
|
*/
|
|
static void init_nvs(void)
|
|
{
|
|
ESP_LOGI(TAG, "Initializing NVS...");
|
|
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
ESP_LOGW(TAG, "NVS partition was truncated, erasing...");
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK(ret);
|
|
|
|
ESP_LOGI(TAG, "✓ NVS initialized");
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize PSRAM
|
|
*/
|
|
static void init_psram(void)
|
|
{
|
|
ESP_LOGI(TAG, "Checking PSRAM...");
|
|
|
|
if (esp_psram_is_initialized()) {
|
|
size_t psram_size = esp_psram_get_size();
|
|
ESP_LOGI(TAG, "✓ PSRAM initialized: %d MB", psram_size / (1024 * 1024));
|
|
} else {
|
|
ESP_LOGE(TAG, "✗ PSRAM not available!");
|
|
ESP_LOGE(TAG, " Make sure PSRAM is enabled in sdkconfig!");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Print system information
|
|
*/
|
|
static void print_system_info(void)
|
|
{
|
|
ESP_LOGI(TAG, "");
|
|
ESP_LOGI(TAG, "╔════════════════════════════════════════════════════════╗");
|
|
ESP_LOGI(TAG, "║ ║");
|
|
ESP_LOGI(TAG, "║ ESP32-S3 GNUBoy LEGO GameBoy Emulator ║");
|
|
ESP_LOGI(TAG, "║ ║");
|
|
ESP_LOGI(TAG, "╚════════════════════════════════════════════════════════╝");
|
|
ESP_LOGI(TAG, "");
|
|
ESP_LOGI(TAG, "Hardware: Waveshare ESP32-S3-Touch-LCD-2");
|
|
ESP_LOGI(TAG, "Display: ST7789 2.0\" 240x320");
|
|
ESP_LOGI(TAG, "Flash: %d MB", spi_flash_get_chip_size() / (1024 * 1024));
|
|
|
|
if (esp_psram_is_initialized()) {
|
|
ESP_LOGI(TAG, "PSRAM: %d MB", esp_psram_get_size() / (1024 * 1024));
|
|
}
|
|
|
|
ESP_LOGI(TAG, "");
|
|
ESP_LOGI(TAG, "Features:");
|
|
ESP_LOGI(TAG, " ✓ GameBoy / GameBoy Color emulation");
|
|
ESP_LOGI(TAG, " ✓ NFC ROM selection");
|
|
ESP_LOGI(TAG, " ✓ Potentiometer controls");
|
|
ESP_LOGI(TAG, " ✓ Link Cable 2-player");
|
|
ESP_LOGI(TAG, " ✓ SD Card ROM loading");
|
|
ESP_LOGI(TAG, "");
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize hardware components
|
|
*/
|
|
static void init_hardware(void)
|
|
{
|
|
ESP_LOGI(TAG, "Initializing hardware components...");
|
|
|
|
// TODO: Initialize display (ST7789)
|
|
// st7789_init();
|
|
ESP_LOGI(TAG, " [ ] Display (ST7789) - TODO");
|
|
|
|
// TODO: Initialize buttons
|
|
// buttons_init();
|
|
ESP_LOGI(TAG, " [ ] Buttons - TODO");
|
|
|
|
// TODO: Initialize audio (I2S)
|
|
// audio_init();
|
|
ESP_LOGI(TAG, " [ ] Audio (I2S) - TODO");
|
|
|
|
// TODO: Initialize SD Card
|
|
// sd_card_init();
|
|
ESP_LOGI(TAG, " [ ] SD Card - TODO");
|
|
|
|
// TODO: Initialize NFC
|
|
// nfc_manager_init();
|
|
ESP_LOGI(TAG, " [ ] NFC Reader - TODO");
|
|
|
|
// TODO: Initialize Link Cable
|
|
// link_cable_init();
|
|
ESP_LOGI(TAG, " [ ] Link Cable - TODO");
|
|
|
|
// TODO: Initialize Potentiometers
|
|
// poti_manager_init();
|
|
// poti_manager_start(poti_change_handler);
|
|
ESP_LOGI(TAG, " [ ] Potentiometers - TODO");
|
|
|
|
ESP_LOGI(TAG, "✓ Hardware initialization complete");
|
|
}
|
|
|
|
/**
|
|
* @brief Main application entry point
|
|
*/
|
|
void app_main(void)
|
|
{
|
|
// Print welcome banner
|
|
print_system_info();
|
|
|
|
// Initialize core systems
|
|
init_nvs();
|
|
init_psram();
|
|
|
|
// Initialize hardware peripherals
|
|
init_hardware();
|
|
|
|
ESP_LOGI(TAG, "");
|
|
ESP_LOGI(TAG, "════════════════════════════════════════════════════════");
|
|
ESP_LOGI(TAG, "System initialization complete!");
|
|
ESP_LOGI(TAG, "════════════════════════════════════════════════════════");
|
|
ESP_LOGI(TAG, "");
|
|
|
|
// TODO: Start emulator
|
|
ESP_LOGI(TAG, "Starting GNUBoy emulator...");
|
|
ESP_LOGI(TAG, " (GNUBoy core not yet integrated)");
|
|
|
|
// Main loop
|
|
ESP_LOGI(TAG, "Entering main loop...");
|
|
while (1) {
|
|
// TODO: Run emulator main loop
|
|
// gnuboy_run_frame();
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
}
|
|
}
|