Skip to content

Commit

Permalink
flesh out example and remove warnings; improve i/o on uSd card
Browse files Browse the repository at this point in the history
  • Loading branch information
finger563 committed Jul 3, 2024
1 parent c38ec61 commit aea8e11
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
12 changes: 6 additions & 6 deletions components/box-emu/example/main/box_emu_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extern "C" void app_main(void) {
}

if (!emu.initialize_sdcard()) {
logger.error("Failed to initialize SD card!");
return;
logger.warn("Failed to initialize SD card!");
logger.warn("This may happen if the SD card is not inserted.");
}

if (!emu.initialize_memory()) {
Expand All @@ -43,13 +43,13 @@ extern "C" void app_main(void) {
}

if (!emu.initialize_gamepad()) {
logger.error("Failed to initialize gamepad!");
return;
logger.warn("Failed to initialize gamepad!");
logger.warn("This may happen if the gamepad is not connected.");
}

if (!emu.initialize_battery()) {
logger.error("Failed to initialize battery!");
return;
logger.warn("Failed to initialize battery!");
logger.warn("This may happen if the battery is not connected.");
}

if (!emu.initialize_video()) {
Expand Down
37 changes: 22 additions & 15 deletions components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ std::shared_ptr<espp::KeypadInput> BoxEmu::keypad() const {
/////////////////////////////////////////////////////////////////////////////

bool BoxEmu::initialize_battery() {
if (version_ == BoxEmu::Version::V0) {
logger_.warn("Battery not supported on version 0");
return false;
}

if (battery_) {
logger_.error("Battery already initialized!");
return false;
Expand Down Expand Up @@ -544,25 +549,29 @@ bool BoxEmu::initialize_usb() {

fmt::print("USB MSC initialization\n");
// register the callback for the storage mount changed event.
const tinyusb_msc_sdmmc_config_t config_sdmmc = {
tinyusb_msc_sdmmc_config_t config_sdmmc = {
.card = card,
.callback_mount_changed = nullptr, // storage_mount_changed_cb,
.callback_mount_changed = nullptr,
.callback_premount_changed = nullptr,
.mount_config = {
.format_if_mount_failed = false,
.max_files = 5,
}
.allocation_unit_size = 16 * 1024, // sector size is 512 bytes, this should be between sector size and (128 * sector size). Larger means higher read/write performance and higher overhead for small files.
.disk_status_check_enable = false, // true if you see issues or are unmounted properly; slows down I/O
},
};
ESP_ERROR_CHECK(tinyusb_msc_storage_init_sdmmc(&config_sdmmc));
// ESP_ERROR_CHECK(tinyusb_msc_register_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED, storage_mount_changed_cb));

// initialize the tinyusb stack
fmt::print("USB MSC initialization\n");
const tinyusb_config_t tusb_cfg = {
.device_descriptor = &descriptor_config,
.string_descriptor = string_desc_arr,
.string_descriptor_count = sizeof(string_desc_arr) / sizeof(string_desc_arr[0]),
.external_phy = false,
.configuration_descriptor = desc_configuration,
};
tinyusb_config_t tusb_cfg;
memset(&tusb_cfg, 0, sizeof(tusb_cfg));
tusb_cfg.device_descriptor = &descriptor_config;
tusb_cfg.string_descriptor = string_desc_arr;
tusb_cfg.string_descriptor_count = sizeof(string_desc_arr) / sizeof(string_desc_arr[0]);
tusb_cfg.external_phy = false;
tusb_cfg.configuration_descriptor = desc_configuration;
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
fmt::print("USB MSC initialization DONE\n");
usb_enabled_ = true;
Expand All @@ -584,11 +593,9 @@ bool BoxEmu::deinitialize_usb() {
usb_enabled_ = false;
// and reconnect the CDC port, see:
// https://github.com/espressif/idf-extra-components/pull/229
usb_phy_config_t phy_conf = {
// NOTE: for some reason, USB_PHY_CTRL_SERIAL_JTAG is not defined in the SDK
// for the ESP32s3
.controller = USB_PHY_CTRL_SERIAL_JTAG, // (usb_phy_controller_t)1,
};
usb_phy_config_t phy_conf;
memset(&phy_conf, 0, sizeof(phy_conf));
phy_conf.controller = USB_PHY_CTRL_SERIAL_JTAG;
usb_new_phy(&phy_conf, &jtag_phy_);
return true;
}
Expand Down

0 comments on commit aea8e11

Please sign in to comment.