Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support enable/disable SOF interrupt in USB peripheral #398

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions hal/src/samd21/usb/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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())
Expand Down