Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/box-emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ idf_component_register(
"esp_lcd"
"esp_psram"
"hal"
"usb"
"esp_tinyusb"
"esp_hw_support"
"usb_device"
"sdcard"
"lvgl"
"codec"
"adc"
Expand Down
28 changes: 14 additions & 14 deletions components/box-emu/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
idf: '>=5.5'
espressif/esp_tinyusb: '>=2.0'
lvgl/lvgl: '>=9.2.2'
espp/adc: '>=1.0'
espp/aw9523: '>=1.0'
espp/button: '>=1.0'
espp/drv2605: '>=1.0'
espp/esp-box: '>=1.0'
espp/event_manager: '>=1.0'
espp/max1704x: '>=1.0'
espp/mcp23x17: '>=1.0'
espp/task: '>=1.0'
espp/timer: '>=1.0'
espp/serialization: '>=1.0'
espressif/usb: '>=1.4.1'
lvgl/lvgl: '>=9.6.0'
espp/adc: '>=1.3.4'
espp/aw9523: '>=1.3.4'
espp/button: '>=1.3.4'
espp/drv2605: '>=1.3.4'
espp/esp-box: '>=1.3.4'
espp/event_manager: '>=1.3.4'
espp/max1704x: '>=1.3.4'
espp/mcp23x17: '>=1.3.4'
espp/sdcard: '>=1.3.4'
espp/serialization: '>=1.3.4'
espp/task: '>=1.3.4'
espp/timer: '>=1.3.4'
espp/usb_device: '>=1.3.4'
33 changes: 22 additions & 11 deletions components/box-emu/include/box-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@

#include <esp_err.h>
#include <esp_partition.h>
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>

// #include <hal/usb_phy_types.h>
#include <esp_private/usb_phy.h>

#include <tinyusb.h>
#include <class/msc/msc.h>
#include <tinyusb_msc.h>

#include <tinyusb_default_config.h>

#include "esp-box.hpp"
#include "event_manager.hpp"

Expand All @@ -31,9 +23,11 @@
#include "max1704x.hpp"
#include "mcp23x17.hpp"
#include "oneshot_adc.hpp"
#include "sdcard.hpp"
#include "serialization.hpp"
#include "task.hpp"
#include "timer.hpp"
#include "usb_device.hpp"

#include "battery_info.hpp"
#include "gamepad_state.hpp"
Expand Down Expand Up @@ -130,8 +124,15 @@ class BoxEmu : public espp::BaseComponent {
// uSD Card
/////////////////////////////////////////////////////////////////////////////

/// Initialize the uSD card (SPI) and mount its FAT volume at mount_point.
/// \return True if the card was initialized and mounted.
bool initialize_sdcard();
/// The initialized card, or nullptr if there is none.
/// \note While USB mass storage is enabled the card belongs to the USB host
/// and its volume is not mounted for the application.
sdmmc_card_t *sdcard() const;
/// The SD card component (nullptr if the card was not initialized).
espp::SdCard *sdcard_component() const;

/////////////////////////////////////////////////////////////////////////////
// Memory
Expand Down Expand Up @@ -187,7 +188,14 @@ class BoxEmu : public espp::BaseComponent {
// USB
/////////////////////////////////////////////////////////////////////////////

/// Expose the uSD card to a USB host as a mass storage device.
/// \note The card's volume is unmounted from the application while USB is
/// enabled (the emulator cannot read roms until it is disabled again);
/// the USB-Serial-JTAG console is disconnected as well, since it shares
/// the USB port.
/// \return True if USB mass storage was started.
bool initialize_usb();
/// Stop USB mass storage, reconnect the console and mount the card again.
bool deinitialize_usb();
bool is_usb_enabled() const;

Expand Down Expand Up @@ -322,6 +330,7 @@ class BoxEmu : public espp::BaseComponent {
static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13;
static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12;
static constexpr auto sdcard_spi_num = SPI3_HOST;
static constexpr int sdcard_max_files = 16;

static constexpr int num_rows_in_framebuffer = 30;

Expand All @@ -334,7 +343,7 @@ class BoxEmu : public espp::BaseComponent {
.scl_pullup_en = GPIO_PULLUP_ENABLE}};

// sdcard
sdmmc_card_t *sdcard_{nullptr};
std::unique_ptr<espp::SdCard> sdcard_{nullptr};

// memory
uint8_t *romdata_{nullptr};
Expand Down Expand Up @@ -377,8 +386,10 @@ class BoxEmu : public espp::BaseComponent {

// usb
std::atomic<bool> usb_enabled_{false};
usb_phy_handle_t jtag_phy_;
tinyusb_msc_storage_handle_t msc_storage_handle_{nullptr};
std::unique_ptr<espp::UsbDevice> usb_device_{nullptr};
// The USB-Serial-JTAG console PHY, re-created after USB mass storage is stopped
// so the console comes back (the OTG stack owns the PHY while it runs).
usb_phy_handle_t jtag_phy_{nullptr};
};

// for libfmt printing of the BoxEmu::Version enum
Expand Down
Loading
Loading