Skip to content

Commit

Permalink
riot-rs-embassy: allow overriding USB Config
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Dec 21, 2023
1 parent b3bab4f commit 19cb0c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ net = [ "dep:embassy-net" ]
usb_ethernet = [ "usb", "net" ]

override_network_config = []
override_usb_config = []
42 changes: 26 additions & 16 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,31 @@ async fn net_task(stack: &'static Stack<Device<'static, ETHERNET_MTU>>) -> ! {
//

#[cfg(feature = "usb")]
const fn usb_default_config() -> embassy_usb::Config<'static> {
// Create embassy-usb Config
let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
config.manufacturer = Some("Embassy");
config.product = Some("USB-Ethernet example");
config.serial_number = Some("12345678");
config.max_power = 100;
config.max_packet_size_0 = 64;

// Required for Windows support.
config.composite_with_iads = true;
config.device_class = 0xEF;
config.device_sub_class = 0x02;
config.device_protocol = 0x01;
config
fn usb_config() -> embassy_usb::Config<'static> {
#[cfg(not(feature = "override_usb_config"))]
{
// Create embassy-usb Config
let mut config = embassy_usb::Config::new(0xc0de, 0xcafe);
config.manufacturer = Some("Embassy");
config.product = Some("USB-Ethernet example");
config.serial_number = Some("12345678");
config.max_power = 100;
config.max_packet_size_0 = 64;

// Required for Windows support.
config.composite_with_iads = true;
config.device_class = 0xEF;
config.device_sub_class = 0x02;
config.device_protocol = 0x01;
config
}
#[cfg(feature = "override_usb_config")]
{
extern "Rust" {
fn riot_rs_usb_config() -> embassy_usb::Config<'static>;
}
unsafe { riot_rs_usb_config() }
}
}

#[cfg(feature = "net")]
Expand Down Expand Up @@ -203,7 +213,7 @@ async fn init_task(peripherals: arch::Peripherals) {

#[cfg(feature = "usb")]
let mut usb_builder = {
let usb_config = usb_default_config();
let usb_config = usb_config();

#[cfg(context = "nrf52")]
let usb_driver = nrf52::usb::driver(peripherals.USBD);
Expand Down

0 comments on commit 19cb0c3

Please sign in to comment.