diff --git a/hal/src/thumbv6m/usb/bus.rs b/hal/src/thumbv6m/usb/bus.rs index 3f2b2f95b2a6..2c0d509656fd 100644 --- a/hal/src/thumbv6m/usb/bus.rs +++ b/hal/src/thumbv6m/usb/bus.rs @@ -717,6 +717,15 @@ impl Inner { usb.ctrlb.modify(|_, w| w.detach().clear_bit()); } + /// Enables/disables the Start Of Frame (SOF) interrupt + fn sof_interrupt(&self, enable: bool) { + if enable { + self.usb().intenset.write(|w| w.sof().set_bit()); + } else { + self.usb().intenclr.write(|w| w.sof().set_bit()); + } + } + /// Configures all endpoints based on prior calls to alloc_ep(). fn flush_eps(&self, mode: FlushConfigMode) { for idx in 0..8 { @@ -860,6 +869,14 @@ impl Inner { .write(|w| unsafe { w.dadd().bits(addr).adden().set_bit() }); } + fn check_sof_interrupt(&self) -> bool { + if self.usb().intflag.read().sof().bit() { + self.usb().intflag.write(|w| w.sof().set_bit()); + return true; + } + false + } + fn poll(&self) -> PollResult { let intflags = self.usb().intflag.read(); if intflags.eorst().bit() { @@ -1017,6 +1034,23 @@ impl Inner { } } +impl UsbBus { + /// Enables the Start Of Frame (SOF) interrupt + pub fn enable_sof_interrupt(&self) { + disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().sof_interrupt(true)) + } + + /// Disables the Start Of Frame (SOF) interrupt + pub fn disable_sof_interrupt(&self) { + disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().sof_interrupt(false)) + } + + /// Checks, and clears if set, the Start Of Frame (SOF) interrupt flag + pub fn check_sof_interrupt(&self) -> bool { + disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().check_sof_interrupt()) + } +} + impl usb_device::bus::UsbBus for UsbBus { fn enable(&mut self) { disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().enable()) diff --git a/hal/src/thumbv7em/usb/bus.rs b/hal/src/thumbv7em/usb/bus.rs index b9087e4fa1aa..4778dfd2f929 100644 --- a/hal/src/thumbv7em/usb/bus.rs +++ b/hal/src/thumbv7em/usb/bus.rs @@ -663,6 +663,15 @@ impl Inner { usb.ctrlb.modify(|_, w| w.detach().clear_bit()); } + /// Enables/disables the Start Of Frame (SOF) interrupt + fn sof_interrupt(&self, enable: bool) { + if enable { + self.usb().intenset.write(|w| w.sof().set_bit()); + } else { + self.usb().intenclr.write(|w| w.sof().set_bit()); + } + } + /// Configures all endpoints based on prior calls to alloc_ep(). fn flush_eps(&self, mode: FlushConfigMode) { for idx in 0..8 { @@ -806,6 +815,14 @@ impl Inner { .write(|w| unsafe { w.dadd().bits(addr).adden().set_bit() }); } + fn check_sof_interrupt(&self) -> bool { + if self.usb().intflag.read().sof().bit() { + self.usb().intflag.write(|w| w.sof().set_bit()); + return true; + } + false + } + fn poll(&self) -> PollResult { let intflags = self.usb().intflag.read(); if intflags.eorst().bit() { @@ -963,6 +980,23 @@ impl Inner { } } +impl UsbBus { + /// Enables the Start Of Frame (SOF) interrupt + pub fn enable_sof_interrupt(&self) { + disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().sof_interrupt(true)) + } + + /// Disables the Start Of Frame (SOF) interrupt + pub fn disable_sof_interrupt(&self) { + disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().sof_interrupt(false)) + } + + /// Checks, and clears if set, the Start Of Frame (SOF) interrupt flag + pub fn check_sof_interrupt(&self) -> bool { + disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().check_sof_interrupt()) + } +} + impl usb_device::bus::UsbBus for UsbBus { fn enable(&mut self) { disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().enable())