Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpenlin committed Jan 4, 2025
1 parent b053b27 commit 8f830f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ async fn run_async() -> Result<(), anyhow::Error> {
wifi.wifi().sta_netif().get_ip_info()?
);

let mut msc_device = MSCDevice {
base_path: String::from("/disk"),
partition_label: String::from("/storage"),
..MSCDevice::default()
};
let mut msc_device = MSCDevice::new("storage", "/disk");
msc_device.install()?;

let mut button = PinDriver::input(peripherals.pins.gpio14)?;
Expand Down
17 changes: 12 additions & 5 deletions src/usb/msc_device.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, bail, Context};
use anyhow::{bail, Context};
use esp_idf_svc::sys::{
esp, esp_partition_find_first, esp_partition_subtype_t_ESP_PARTITION_SUBTYPE_DATA_FAT,
esp_partition_type_t_ESP_PARTITION_TYPE_DATA, esp_vfs_fat_mount_config_t, tinyusb_config_t,
Expand All @@ -8,12 +8,11 @@ use esp_idf_svc::sys::{
tinyusb_msc_storage_init_spiflash, tinyusb_msc_storage_mount, wl_handle_t, wl_mount,
};
use std::ffi::CString;
use std::fmt::{Display, Formatter};

#[derive(Debug, Default)]
pub struct MSCDevice {
pub base_path: String,
pub partition_label: String,
pub base_path: String,
wl_handle: wl_handle_t,
base_path_c_str: CString,
partition_label_c_str: CString,
Expand All @@ -36,9 +35,17 @@ unsafe extern "C" fn storage_mount_changed_cb(event: *mut tinyusb_msc_event_t) {
}

impl MSCDevice {
pub fn new(partition_label: &str, base_path: &str) -> Self {
Self {
base_path: base_path.to_string(),
partition_label: partition_label.to_string(),
..Default::default()
}
}

pub fn install(&mut self) -> anyhow::Result<()> {
self.partition_label_c_str = CString::new(&self.partition_label).unwrap();
self.base_path_c_str = CString::new(&self.base_path).unwrap();
self.partition_label_c_str = CString::new(self.partition_label.as_bytes()).unwrap();
self.base_path_c_str = CString::new(self.base_path.as_bytes()).unwrap();

let data_partition = unsafe {
esp_partition_find_first(
Expand Down

0 comments on commit 8f830f8

Please sign in to comment.