Skip to content

Commit

Permalink
Implement force_reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mattico committed May 11, 2021
1 parent ae65590 commit baac8a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ keywords = ["no-std", "embedded", "usb"]
[dependencies]
riscv = { version = "0.5.4", optional = true }
cortex-m = { version = "0.6.0", optional = true }
embedded-hal = "0.2"
vcell = "0.1.0"
usb-device = "0.2.2"

Expand Down
12 changes: 12 additions & 0 deletions src/bus.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::marker::PhantomData;
use embedded_hal::blocking::delay::DelayMs;
use usb_device::{Result, UsbDirection, UsbError};
use usb_device::bus::{UsbBusAllocator, PollResult};
use usb_device::endpoint::{EndpointType, EndpointAddress};
Expand Down Expand Up @@ -126,6 +127,17 @@ impl<USB: UsbPeripheral> UsbBus<USB> {
}
}

pub fn force_reset(&self, delay: &mut impl DelayMs<u32>) -> Result<()> {
interrupt::free(|cs| {
let regs = self.regs.borrow(cs);
write_reg!(otg_device, regs.device(), DCTL, SDIS: 1); // Soft disconnect
delay.delay_ms(3);
write_reg!(otg_device, regs.device(), DCTL, SDIS: 0); // Soft connect
delay.delay_ms(3);
});
Ok(())
}

#[cfg(feature = "hs")]
/// Reads from a ULPI register in an external ULPI PHY.
///
Expand Down

0 comments on commit baac8a1

Please sign in to comment.