From 5fe0ad185b111371d09d87052cdd40b86fb43ad1 Mon Sep 17 00:00:00 2001 From: Erik Henriksson Date: Tue, 2 Feb 2021 23:20:03 +0100 Subject: [PATCH] Support enabling SOF interrupt in USB peripheral --- hal/src/samd21/usb/bus.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hal/src/samd21/usb/bus.rs b/hal/src/samd21/usb/bus.rs index b2640ed3b59..8944e5069c1 100644 --- a/hal/src/samd21/usb/bus.rs +++ b/hal/src/samd21/usb/bus.rs @@ -716,6 +716,14 @@ impl Inner { usb.ctrlb.modify(|_, w| w.detach().clear_bit()); } + fn sof_interrupt(&self, enable: bool) { + if enable { + self.usb().intenset.write(|w| w.sof().set_bit()); + } else { + self.usb().intenset.write(|w| w.sof().clear_bit()); + } + } + /// Configures all endpoints based on prior calls to alloc_ep(). fn flush_eps(&self, mode: FlushConfigMode) { for idx in 0..8 { @@ -860,6 +868,10 @@ impl Inner { let intbits = self.usb().epintsmry.read().bits(); if intbits == 0 { + if intflags.sof().bit() { + // clear start of frame interrupt + self.usb().intflag.write(|w| w.sof().set_bit()); + } return PollResult::None; } @@ -1003,6 +1015,16 @@ impl Inner { } } +impl UsbBus { + fn enable_sof_interrupt(&self) { + disable_interrupts(|cs| self.inner.borrow(cs).borrow().sof_interrupt(true)) + } + + fn disable_sof_interrupt(&self) { + disable_interrupts(|cs| self.inner.borrow(cs).borrow().sof_interrupt(false)) + } +} + impl usb_device::bus::UsbBus for UsbBus { fn enable(&mut self) { disable_interrupts(|cs| self.inner.borrow(cs).borrow_mut().enable())