Handle usb interrupt flags in driver (#106)

Set interrupt enable flags in USB driver. The flags were already being cleared in the USB driver.
Update USB examples to remove interrupt flag set/check as it is no longer necessary.
This commit is contained in:
9names 2021-09-17 09:40:10 +10:00 committed by GitHub
parent c509b9d22f
commit 98b8e3ae9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 60 deletions

View file

@ -84,20 +84,6 @@ fn main() -> ! {
USB_DEVICE = Some(usb_dev); USB_DEVICE = Some(usb_dev);
} }
// The USB driver doesn't enable key interrupts yet, so manually do that here
unsafe {
let p = pac::Peripherals::steal();
// Enable interrupts for when a buffer is done, when the bus is reset,
// and when a setup packet is received
p.USBCTRL_REGS.inte.modify(|_, w| {
w.buff_status()
.set_bit()
.bus_reset()
.set_bit()
.setup_req()
.set_bit()
});
}
// Enable the USB interrupt // Enable the USB interrupt
unsafe { unsafe {
pac::NVIC::unmask(hal::pac::Interrupt::USBCTRL_IRQ); pac::NVIC::unmask(hal::pac::Interrupt::USBCTRL_IRQ);
@ -158,21 +144,4 @@ unsafe fn USBCTRL_IRQ() {
} }
}); });
} }
// Clear pending interrupt flags here.
// We could also move some of our code into these states to handle events
let p = pac::Peripherals::steal();
let status = &p.USBCTRL_REGS.sie_status;
if status.read().ack_rec().bit_is_set() {
status.modify(|_r, w| w.ack_rec().set_bit());
}
if status.read().setup_rec().bit_is_set() {
status.modify(|_r, w| w.setup_rec().set_bit());
}
if status.read().trans_complete().bit_is_set() {
status.modify(|_r, w| w.trans_complete().set_bit());
}
if status.read().bus_reset().bit_is_set() {
status.modify(|_r, w| w.bus_reset().set_bit());
}
} }

View file

@ -77,19 +77,6 @@ fn main() -> ! {
USB_DEVICE = Some(usb_dev); USB_DEVICE = Some(usb_dev);
} }
unsafe {
let p = pac::Peripherals::steal();
// Enable interrupts for when a buffer is done, when the bus is reset,
// and when a setup packet is received
p.USBCTRL_REGS.inte.modify(|_, w| {
w.buff_status()
.set_bit()
.bus_reset()
.set_bit()
.setup_req()
.set_bit()
});
}
unsafe { unsafe {
pac::NVIC::unmask(hal::pac::Interrupt::USBCTRL_IRQ); pac::NVIC::unmask(hal::pac::Interrupt::USBCTRL_IRQ);
}; };
@ -133,20 +120,4 @@ unsafe fn USBCTRL_IRQ() {
let usb_dev = USB_DEVICE.as_mut().unwrap(); let usb_dev = USB_DEVICE.as_mut().unwrap();
let usb_hid = USB_HID.as_mut().unwrap(); let usb_hid = USB_HID.as_mut().unwrap();
usb_dev.poll(&mut [usb_hid]); usb_dev.poll(&mut [usb_hid]);
// Clear pending interrupt flags
let p = pac::Peripherals::steal();
let status = &p.USBCTRL_REGS.sie_status;
if status.read().ack_rec().bit_is_set() {
status.modify(|_r, w| w.ack_rec().set_bit());
}
if status.read().setup_rec().bit_is_set() {
status.modify(|_r, w| w.setup_rec().set_bit());
}
if status.read().trans_complete().bit_is_set() {
status.modify(|_r, w| w.trans_complete().set_bit());
}
if status.read().bus_reset().bit_is_set() {
status.modify(|_r, w| w.bus_reset().set_bit());
}
} }

View file

@ -407,6 +407,18 @@ impl UsbBusTrait for UsbBus {
// at this stage ep's are expected to be in their reset state // at this stage ep's are expected to be in their reset state
// TODO: is it worth having a debug_assert for that here? // TODO: is it worth having a debug_assert for that here?
// Enable interrupt generation when a buffer is done, when the bus is reset,
// and when a setup packet is received
// this should be sufficient for device mode, will need more for host.
inner.ctrl_reg.inte.modify(|_, w| {
w.buff_status()
.set_bit()
.bus_reset()
.set_bit()
.setup_req()
.set_bit()
});
// enable pull up to let the host know we exist. // enable pull up to let the host know we exist.
inner inner
.ctrl_reg .ctrl_reg