From 64424febc6e48d926ee1c12394cdc600e9b0de29 Mon Sep 17 00:00:00 2001 From: doryan Date: Sat, 9 Nov 2024 16:47:05 +0400 Subject: [PATCH] feat(UsbBus): implement resume and set_device_address methods --- src/types/usb_device.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/types/usb_device.rs b/src/types/usb_device.rs index cf69629..e80a7c4 100644 --- a/src/types/usb_device.rs +++ b/src/types/usb_device.rs @@ -275,11 +275,45 @@ impl UsbBus for UsbDevice { } fn resume(&self) { - todo!(); + free(|cs| { + let usb = self.usb.borrow(cs); + let pll = self.pll.borrow(cs); + + // Enable PLL and wait PLL lock. // + + pll.pllcsr.modify(|_, w| w.plle().set_bit()); + + while pll.pllcsr.read().plock().bit_is_clear() {} + + // Unfreeze USB clock. // + + usb.usbcon.modify(|_, w| w.frzclk().clear_bit()); + + // Clear resume informations. // + + usb.udint + .modify(|_, w| w.wakeupi().clear_bit().suspi().clear_bit()); + + usb.udien + .modify(|_, w| w.wakeupe().clear_bit().suspe().set_bit()); + }) } fn set_device_address(&self, addr: u8) { - todo!(); + free(|cs| { + let usb = self.usb.borrow(cs); + + // Set address. // + + usb.udaddr.modify(|_, w| w.uadd().bits(addr)); + + // Note: ADDEN and UADD shall not be written at the same time. + // (written in atmega32u4/16u4 docs) + + // Enable. // + + usb.udaddr.modify(|_, w| w.adden().set_bit()); + }); } fn set_stalled(&self, ep_addr: usb_device::endpoint::EndpointAddress, stalled: bool) {