Skip to content

Commit

Permalink
Fix broken build
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpenlin committed Jan 7, 2025
1 parent a722f00 commit 6b55268
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 23 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.134"
time = { version = "0.3.37", features = ["std", "serde-human-readable"] }
rmp-serde = "1.3.0"
toml = "0.8.19"

[[package.metadata.esp-idf-sys.extra_components]]
remote_component = { name = "espressif/esp_tinyusb", version = "96cbb5b308f92d2493a0c714f097dcfc51add807", git = "https://github.com/LaunchPlatform/esp-usb.git", path = "device/esp_tinyusb" }
Expand Down
8 changes: 2 additions & 6 deletions src/api/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ use crate::api::processor::Response::{Error, FetchFileChunk, GetInfo, ListFiles,
use crate::api::websocket::{ConnectionState, SessionEvent, WebSocketSession};
use anyhow::anyhow;
use embedded_svc::ws::FrameType;
use esp_idf_svc::hal::gpio::Pull;
use esp_idf_svc::ping::Info;
use serde::{Deserialize, Serialize};
use std::fs::{read_dir, FileType};
use std::io::{Read, Seek};
use std::mem::MaybeUninit;
use std::fs::read_dir;
use std::io::Read;
use std::path::Path;
use std::time::SystemTime;
use time::serde::timestamp::milliseconds;
use time::OffsetDateTime;

Expand Down
18 changes: 14 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::Deserialize;
use std::fmt::{Debug, Formatter};
use std::fs::File;
use std::io::Read;

#[derive(Default, Debug, Deserialize)]
pub enum AuthMethod {
Expand All @@ -16,7 +18,7 @@ pub enum AuthMethod {
}

#[derive(Deserialize)]
struct Wifi {
pub struct Wifi {
ssid: String,
auth_method: AuthMethod,
password: Option<String>,
Expand All @@ -33,12 +35,12 @@ impl Debug for Wifi {
}

#[derive(Debug, Deserialize)]
struct Api {
pub struct Api {
endpoint: String,
}

#[derive(Debug, Deserialize)]
struct Usb {
pub struct Usb {
high_speed: bool,
}

Expand All @@ -49,8 +51,16 @@ impl Default for Usb {
}

#[derive(Debug, Deserialize)]
struct Config {
pub struct Config {
wifi: Wifi,
api: Api,
usb: Usb,
}

impl Config {
pub fn read(file_path: &str) -> anyhow<Self> {
let mut config_str = String::new();
File::open(file_path)?.read_to_string(&mut config_str)?;
toml::from_str(&*config_str)?
}
}
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use std::thread;
use std::time::Duration;
use time::OffsetDateTime;

const DEFAULT_PARTITION_LABEL: &str = "storage";
const DEFAULT_MOUNT_PATH: &str = "/disk";

const PKG_NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand All @@ -35,9 +38,9 @@ const MOUNT_PATH: Option<&str> = option_env!("MOUNT_PATH");
async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
log::info!("Start {} - {}", PKG_NAME, VERSION,);

let mount_path = MOUNT_PATH.unwrap_or("/disk").to_string();
let mount_path = MOUNT_PATH.unwrap_or(DEFAULT_MOUNT_PATH).to_string();
let mut storage = Box::new(SPIFlashStorage::new());
storage.initialize_partition(PARTITION_LABEL.unwrap_or("storage"))?;
storage.initialize_partition(PARTITION_LABEL.unwrap_or(DEFAULT_PARTITION_LABEL))?;
storage.mount(&mount_path, 5);

let peripherals = Peripherals::take()?;
Expand Down
20 changes: 9 additions & 11 deletions src/usb/msc_device.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
use crate::storage::spiflash::SPIFlashStorage;
use anyhow::{bail, Context};
use anyhow::Context;
use esp_idf_svc::handle::RawHandle;
use esp_idf_svc::partition::{EspPartition, EspWlPartition};
use esp_idf_svc::sys::{
esp, esp_vfs_fat_mount_config_t, tinyusb_config_t, tinyusb_driver_install, tinyusb_msc_event_t,
tinyusb_msc_event_type_t, tinyusb_msc_event_type_t_TINYUSB_MSC_EVENT_MOUNT_CHANGED,
esp, tinyusb_config_t, tinyusb_driver_install, tinyusb_msc_event_t, tinyusb_msc_event_type_t,
tinyusb_msc_event_type_t_TINYUSB_MSC_EVENT_MOUNT_CHANGED,
tinyusb_msc_event_type_t_TINYUSB_MSC_EVENT_PREMOUNT_CHANGED, tinyusb_msc_spiflash_config_t,
tinyusb_msc_storage_init_spiflash, tinyusb_msc_storage_mount,
tinyusb_msc_storage_init_spiflash,
};
use std::ffi::CString;
use std::fmt::Debug;

pub trait Storage {
fn config_usb(&self, config: &mut tinyusb_msc_spiflash_config_t);
fn config_usb(&self, config: &mut tinyusb_msc_spiflash_config_t) -> anyhow::Result<()>;
}

impl Storage for SPIFlashStorage {
fn config_usb(&self, config: &mut tinyusb_msc_spiflash_config_t) -> anyhow::Result<()> {
config.wl_handle = self.handle();
esp!(unsafe { tinyusb_msc_storage_init_spiflash(config) })
.with_context(|| "Failed to initialize spiflash")?;
.with_context(|| "Failed to initialize spiflash for msc storage")?;
Ok(())
}
}

#[derive(Default, Clone)]
#[derive(Debug, Default, Clone)]
pub struct MSCDeviceConfig {
pub high_speed: bool,
}

#[derive(Default)]
pub struct MSCDevice {
config: MSCDeviceConfig,
storage: dyn Storage,
storage: Box<dyn Storage>,
}

fn msc_event_type_to_str(event_type: tinyusb_msc_event_type_t) -> String {
Expand Down

0 comments on commit 6b55268

Please sign in to comment.