Build Your Own ESP32 Game Console and Controller – Open Source Project

Build Your Own ESP32 Game Console and Controller - Open Source Project

Project Name: 【Rachel】 Mini Game Console~

Project Author: Forairaaaaa

Introduction

This is a super easy to replicate game console!

Build Your Own ESP32 Game Console and Controller - Open Source Project

Because!

Not only are the circuit files and source code open source…

Software part explanation is extremely detailed!!

Build Your Own ESP32 Game Console and Controller - Open Source Project

Netizens have expressed—“Learning the source code makes programming much easier!”

Build Your Own ESP32 Game Console and Controller - Open Source Project

01
Open Source Project Description

This is an ESP32 mini game console, also a controller! Simple functionality, great feel!

Build Your Own ESP32 Game Console and Controller - Open Source Project
Build Your Own ESP32 Game Console and Controller - Open Source Project

Moreover,the components are all 0603, can be soldered with a hot plate!

Build Your Own ESP32 Game Console and Controller - Open Source Project

Next, let’s share itscircuit design and software compilation instructions!

PS: You can directly go to the end of the article to get the open-source materials for DIY one yourself~

02
Circuit Design Diagram

Build Your Own ESP32 Game Console and Controller - Open Source Project

Schematic

Build Your Own ESP32 Game Console and Controller - Open Source Project

PCB Diagram

Build Your Own ESP32 Game Console and Controller - Open Source Project

PCB Physical Diagram

03
Compilation

RachelSDK is PIO project, VS Code download PlatformIO plugin, open the folder with VS Code.

01
SDK Directory Tree
.
├── apps
│   ├── app_ble_gamepad               BLE Gamepad
│   ├── app_music                     Music Player
│   ├── app_nofrendo                  NES Emulator
│   ├── app_raylib_games              Raylib Games
│   ├── app_screencast                WiFi Screen Casting
│   ├── app_settings                  Settings
│   ├── app_genshin                   __,__!
│   ├── app_template                  App Template
│   ├── launcher                      Launcher
│   ├── utils                         Utility Component Library
│   ├── assets                        Public Resources
│   ├── tools                         App Related Tools (Scripts)
│   └── apps.h                        App Installation Callback
├── hal
│   ├── hal.cpp                       HAL Base Class
│   ├── hal.h                         HAL Base Class
│   ├── hal_rachel                    HAL Rachel Derived Class
│   ├── hal_simulator                 HAL PC Simulator Derived Class
│   └── lgfx_fx                       lgfx Derived Class (Extended Graphics API)
├── rachel.cpp
└── rachel.h                          RachelSDK Entry
02
SD Card Directory Tree

NES Emulator, Music Player, etc., will try to load resource files from specified directories on the SD card.

.
├── buzz_music                        Buzzer Music
│   ├── harrypotter.json
│   ├── nokia.json
│   ├── ...
├── fonts                             Fonts
│   └── font_text_24.vlw
└── nes_roms                          NES ROM Files
    ├── Kirby's Adventure (E).nes
    ├── Snow Bros (U).nes
    ├── ...

font_text_24.vlw This font I used is Zpix very cool and beautiful, can replace any font you like.

NES ROM Just drop it in, anything not too large should work.

03
Common App API

Some commonly used app APIs are provided here.

destroyApp()

Close the app, calling it will inform the framework that you are done, and the framework will destroy and release your app, so it is ineffective while being blocked in onRunning().

// Validvoid AppTemplate::onRunning()
{
destroyApp();
}// Invalidvoid AppTemplate::onRunning()
{
destroyApp();
HAL::Delay(66666666666);
}
getAppName()

Get the app name, it will return the name you set for the app.

// In your App header file:class AppHello_world_Packer : public APP_PACKER_BASE
{
    // Here modify your app name:
    std::string getAppName() override { return "Civilization Lecture Foreigner"; }
    ...
}

getAppIcon()

Get the app icon, the launcher will call it when rendering the screen.

// In your App header file:class AppHello_world_Packer : public APP_PACKER_BASE
{
    ...    // Here modify your app icon (there is a default icon)
    void* getAppIcon() override { return (void*)image_data_icon_app_default; }
    ...
}

mcAppGetDatabase()

Get the database instance, a simple RAM based KV database, can be used for App exit data saving, data sharing between multiple Apps (of course not during power off).

void AppTemplate::onResume()
{    // Check if this key exists in the database
    if (mcAppGetDatabase()->Exist("Opened?"))
    {        // Get it from the database, see how many times it was opened
        int how_many = mcAppGetDatabase()->Get("Opened?")->value();
        spdlog::info("Opened {} times", how_many);
        // Add this time, write it into the database
        how_many++;
        mcAppGetDatabase()->Put("Opened?", how_many);
    }    // If not, create one
    else
        mcAppGetDatabase()->Add("Opened?", 1);
}
mcAppGetFramework()

Get the Mooncake framework instance, generally used to write the launcher.

// Check how many apps are installedauto installed_app_num = mcAppGetFramework()->getAppRegister().getInstalledAppNum();
spdlog::info("Installed {} apps", installed_app_num);// Check what they are for (const auto& app_packer : mcAppGetFramework()->getAppRegister().getInstalledAppList())
{
    spdlog::info("{}", app_packer->getAppName());
}
06
HAL Hardware Abstraction Layer

Build Your Own ESP32 Game Console and Controller - Open Source Project

HAL is a singleton pattern, a HAL instance will be injected when the SDK initializes.

  • For HAL Rachel, hold down Button A to power on, it will pause at the initialization screen, allowing you to view detailed HAL initialization logs.

  • If there are different underlying hardware requirements, just derive a new HAL object, override the API methods and inject it during initialization.

Include

#include "{path to}/hal/hal.h"

Display API

The display driver uses LovyanGFX.

// Get the screen driver instanceHAL::GetDisplay();// Get full screen buffer instanceHAL::GetCanvas();// Push full screen buffer to the displayHAL::CanvasUpdate();// Render FPS panelHA::RenderFpsPanel();

System API

HAL Rachel will adjust the system time with RTC time during initialization, so time-related POSIX standard APIs can be used normally.

// Delay (milliseconds)HAL::Delay(unsigned long milliseconds);// Get system running millisecondsHAL::Millis();// Power offHAL::PowerOff();// RebootHAL::Reboot();// Set RTC timeHAL::SetSystemTime(tm dateTime);// Get current timeHAL::GetLocalTime();// Gracefully throw a blue screenHAL::PopFatalError(std::string msg);

Peripheral API

// Refresh IMU dataHAL::UpdateImuData();// Get IMU dataHAL::GetImuData();// Buzzer start beepingHAL::Beep(float frequency, uint32_t duration);// Stop buzzer beepingHAL::BeepStop();// Check if SD card is availableHAL::CheckSdCard();// Get button statusHAL::GetButton(GAMEPAD::GamePadButton_t button);// Get any button statusHAL::GetAnyButton();
System Configuration API
// Load system configuration from internal FSHAL::LoadSystemConfig();// Save system configuration to internal FSHAL::SaveSystemConfig();// Get system configurationHAL::GetSystemConfig();// Set system configurationHAL::SetSystemConfig(CONFIG::SystemConfig_t cfg);// Refresh device with system configurationHAL::UpdateSystemFromConfig();
07
Utility Component Library

Some useful general utility libraries are placed here rachel/apps/utils/system.

Select Menu
Create a selection menu.
Build Your Own ESP32 Game Console and Controller - Open Source Project
Include
#include "{path to}/utils/system/ui/ui.h"

Example

using namespace SYSTEM::UI;// Create select menuauto select_menu = SelectMenu();// Create options liststd::vector items = {    "[WHAT 7 TO PLAY]",    "Jenshin Import",    "Light Soul",    "Grand Cop Manual",    "Super Maliao",    "Quit"};// Wait for selectionauto selected_index = select_menu.waitResult(items);
spdlog::info("selected: {}", items[selected_index]);

Progress Bar Window

Create a window with a progress bar (u1s1, now should count as a page).

Build Your Own ESP32 Game Console and Controller - Open Source Project

Include

#include "{path to}/utils/system/ui/ui.h"

Example

using namespace SYSTEM::UI;for (int i = 0; i < 100; i++)
{
    ProgressWindow("Checking IQ..", i);
    HAL::CanvasUpdate();
    HAL::Delay(20);
}
Buzzer Music Player

Reference to the json format buzzer music player of arduino-songs.

Include

#include "{path to}/utils/system/audio/audio.h"

Example

using namespace SYSTEM::AUDIO;// Play json music file from SD pathBuzzMusicPlayer::playFromSdCard("/buzz_music/nokia.json");

Include

#include "{path to}/utils/system/inputs/inputs.h"
Example
using namespace SYSTEM::INPUTS;auto button_a = Button(GAMEPAD::BTN_A);while (1)
{    if (button_a.pressed())
        spdlog::info("button a was pressed");    if (button_a.released())
        spdlog::info("button a was released");    if (button_a.toggled())
        spdlog::info("button a was toggled");
    HAL::Delay(20);
}
08
In-Depth

For a more in-depth look at the specific framework and implementation, you can check the original project.

Build Your Own ESP32 Game Console and Controller - Open Source Project

Carefully crafted tutorials, you won’t worry about not learning real skills!

Open source website: https://oshwhub.com/eedadada/mason

Build Your Own ESP32 Game Console and Controller - Open Source Project

*This article is a reprint of user creation from the “Lichuang Open Source Hardware Platform”, if there is any infringement, please contact for deletion.

If you are watching, please give me a thumbs up!
Build Your Own ESP32 Game Console and Controller - Open Source Project
Click here to view the original project

Leave a Comment

Your email address will not be published. Required fields are marked *