Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire up ESP32-Sx USB support #487

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 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 laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ modules:
- name: hw/usb-device-port
help: provided if a device has a USB device port wired up
context:
- espressif-esp32-s3-wroom-1
- nrf5340dk
- nrf52840dk
- rpi-pico
Expand Down
1 change: 1 addition & 0 deletions src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ spi = [
]
usb = [
"dep:embassy-usb",
"riot-rs-esp/usb",
"riot-rs-nrf/usb",
"riot-rs-rp/usb",
"riot-rs-stm32/usb",
Expand Down
4 changes: 4 additions & 0 deletions src/riot-rs-esp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ paste = { workspace = true }
riot-rs-debug = { workspace = true }
riot-rs-embassy-common = { workspace = true }
riot-rs-utils = { workspace = true }
static_cell = { workspace = true }

[target.'cfg(context = "cortex-m")'.dependencies]
embassy-executor = { workspace = true, default-features = false, features = [
Expand Down Expand Up @@ -81,6 +82,9 @@ spi = ["dep:fugit", "riot-rs-embassy-common/spi"]
## Enables defmt support.
defmt = ["dep:defmt", "esp-wifi?/defmt", "fugit?/defmt"]

# Enables USB support.
usb = []

## Enables Wi-Fi support.
wifi = []

Expand Down
3 changes: 3 additions & 0 deletions src/riot-rs-esp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub mod i2c;
#[cfg(feature = "spi")]
pub mod spi;

#[cfg(feature = "usb")]
pub mod usb;

#[cfg(feature = "wifi")]
pub mod wifi;

Expand Down
22 changes: 22 additions & 0 deletions src/riot-rs-esp/src/usb/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use esp_hal::otg_fs::asynch::Driver;
use static_cell::ConstStaticCell;

pub type UsbDriver = Driver<'static>;

pub fn driver(peripherals: &mut crate::OptionalPeripherals) -> UsbDriver {
use esp_hal::otg_fs::{asynch::Config, Usb};

let usb = Usb::new(
peripherals.USB0.take().unwrap(),
peripherals.GPIO_20.take().unwrap(),
peripherals.GPIO_19.take().unwrap(),
);

// Buffer size copied from upstream. There's no hint about sizing.
static EP_OUT_BUFFER: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0u8; 1024]);
let ep_out_buffer = EP_OUT_BUFFER.take();

let config = Config::default();

Driver::new(usb, ep_out_buffer, config)
}
Loading