Skip to content

Commit

Permalink
Add methods for the USB Start Of Frame interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrrees committed Jun 30, 2021
1 parent 8c40356 commit 415d026
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions hal/src/thumbv6m/usb/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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().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 +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() {
Expand Down Expand Up @@ -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())
Expand Down
34 changes: 34 additions & 0 deletions hal/src/thumbv7em/usb/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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().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 @@ -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() {
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 415d026

Please sign in to comment.