Skip to content

Commit 6b55268

Browse files
committed
Fix broken build
1 parent a722f00 commit 6b55268

File tree

6 files changed

+58
-23
lines changed

6 files changed

+58
-23
lines changed

Diff for: Cargo.lock

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ serde = { version = "1.0.217", features = ["derive"] }
3333
serde_json = "1.0.134"
3434
time = { version = "0.3.37", features = ["std", "serde-human-readable"] }
3535
rmp-serde = "1.3.0"
36+
toml = "0.8.19"
3637

3738
[[package.metadata.esp-idf-sys.extra_components]]
3839
remote_component = { name = "espressif/esp_tinyusb", version = "96cbb5b308f92d2493a0c714f097dcfc51add807", git = "https://github.com/LaunchPlatform/esp-usb.git", path = "device/esp_tinyusb" }

Diff for: src/api/processor.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ use crate::api::processor::Response::{Error, FetchFileChunk, GetInfo, ListFiles,
22
use crate::api::websocket::{ConnectionState, SessionEvent, WebSocketSession};
33
use anyhow::anyhow;
44
use embedded_svc::ws::FrameType;
5-
use esp_idf_svc::hal::gpio::Pull;
6-
use esp_idf_svc::ping::Info;
75
use serde::{Deserialize, Serialize};
8-
use std::fs::{read_dir, FileType};
9-
use std::io::{Read, Seek};
10-
use std::mem::MaybeUninit;
6+
use std::fs::read_dir;
7+
use std::io::Read;
118
use std::path::Path;
12-
use std::time::SystemTime;
139
use time::serde::timestamp::milliseconds;
1410
use time::OffsetDateTime;
1511

Diff for: src/config.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use serde::Deserialize;
22
use std::fmt::{Debug, Formatter};
3+
use std::fs::File;
4+
use std::io::Read;
35

46
#[derive(Default, Debug, Deserialize)]
57
pub enum AuthMethod {
@@ -16,7 +18,7 @@ pub enum AuthMethod {
1618
}
1719

1820
#[derive(Deserialize)]
19-
struct Wifi {
21+
pub struct Wifi {
2022
ssid: String,
2123
auth_method: AuthMethod,
2224
password: Option<String>,
@@ -33,12 +35,12 @@ impl Debug for Wifi {
3335
}
3436

3537
#[derive(Debug, Deserialize)]
36-
struct Api {
38+
pub struct Api {
3739
endpoint: String,
3840
}
3941

4042
#[derive(Debug, Deserialize)]
41-
struct Usb {
43+
pub struct Usb {
4244
high_speed: bool,
4345
}
4446

@@ -49,8 +51,16 @@ impl Default for Usb {
4951
}
5052

5153
#[derive(Debug, Deserialize)]
52-
struct Config {
54+
pub struct Config {
5355
wifi: Wifi,
5456
api: Api,
5557
usb: Usb,
5658
}
59+
60+
impl Config {
61+
pub fn read(file_path: &str) -> anyhow<Self> {
62+
let mut config_str = String::new();
63+
File::open(file_path)?.read_to_string(&mut config_str)?;
64+
toml::from_str(&*config_str)?
65+
}
66+
}

Diff for: src/main.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ use std::thread;
2323
use std::time::Duration;
2424
use time::OffsetDateTime;
2525

26+
const DEFAULT_PARTITION_LABEL: &str = "storage";
27+
const DEFAULT_MOUNT_PATH: &str = "/disk";
28+
2629
const PKG_NAME: &str = env!("CARGO_PKG_NAME");
2730
const VERSION: &str = env!("CARGO_PKG_VERSION");
2831

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

38-
let mount_path = MOUNT_PATH.unwrap_or("/disk").to_string();
41+
let mount_path = MOUNT_PATH.unwrap_or(DEFAULT_MOUNT_PATH).to_string();
3942
let mut storage = Box::new(SPIFlashStorage::new());
40-
storage.initialize_partition(PARTITION_LABEL.unwrap_or("storage"))?;
43+
storage.initialize_partition(PARTITION_LABEL.unwrap_or(DEFAULT_PARTITION_LABEL))?;
4144
storage.mount(&mount_path, 5);
4245

4346
let peripherals = Peripherals::take()?;

Diff for: src/usb/msc_device.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
use crate::storage::spiflash::SPIFlashStorage;
2-
use anyhow::{bail, Context};
2+
use anyhow::Context;
33
use esp_idf_svc::handle::RawHandle;
4-
use esp_idf_svc::partition::{EspPartition, EspWlPartition};
54
use esp_idf_svc::sys::{
6-
esp, esp_vfs_fat_mount_config_t, tinyusb_config_t, tinyusb_driver_install, tinyusb_msc_event_t,
7-
tinyusb_msc_event_type_t, tinyusb_msc_event_type_t_TINYUSB_MSC_EVENT_MOUNT_CHANGED,
5+
esp, tinyusb_config_t, tinyusb_driver_install, tinyusb_msc_event_t, tinyusb_msc_event_type_t,
6+
tinyusb_msc_event_type_t_TINYUSB_MSC_EVENT_MOUNT_CHANGED,
87
tinyusb_msc_event_type_t_TINYUSB_MSC_EVENT_PREMOUNT_CHANGED, tinyusb_msc_spiflash_config_t,
9-
tinyusb_msc_storage_init_spiflash, tinyusb_msc_storage_mount,
8+
tinyusb_msc_storage_init_spiflash,
109
};
11-
use std::ffi::CString;
10+
use std::fmt::Debug;
1211

1312
pub trait Storage {
14-
fn config_usb(&self, config: &mut tinyusb_msc_spiflash_config_t);
13+
fn config_usb(&self, config: &mut tinyusb_msc_spiflash_config_t) -> anyhow::Result<()>;
1514
}
1615

1716
impl Storage for SPIFlashStorage {
1817
fn config_usb(&self, config: &mut tinyusb_msc_spiflash_config_t) -> anyhow::Result<()> {
1918
config.wl_handle = self.handle();
2019
esp!(unsafe { tinyusb_msc_storage_init_spiflash(config) })
21-
.with_context(|| "Failed to initialize spiflash")?;
20+
.with_context(|| "Failed to initialize spiflash for msc storage")?;
2221
Ok(())
2322
}
2423
}
2524

26-
#[derive(Default, Clone)]
25+
#[derive(Debug, Default, Clone)]
2726
pub struct MSCDeviceConfig {
2827
pub high_speed: bool,
2928
}
3029

31-
#[derive(Default)]
3230
pub struct MSCDevice {
3331
config: MSCDeviceConfig,
34-
storage: dyn Storage,
32+
storage: Box<dyn Storage>,
3533
}
3634

3735
fn msc_event_type_to_str(event_type: tinyusb_msc_event_type_t) -> String {

0 commit comments

Comments
 (0)