Facedancer uses a polling approach to service events from the board. You must implement the service_irqs() method, which acts as the core execution loop.
While service_irqs() is scheduled automatically by Facedancer, you are responsible for dispatching events generated by your board to the corresponding methods of the USBDevice object (which is obtained during the FacedancerBackend.connect() callback).
Common events to handle include:
USB_RECEIVE_SETUP: Receiving a setup packet.USB_RECEIVE_PACKET: Receiving data on an endpoint.USB_EP_IN_NAK: Receiving NAK events (e.g., host requested data from an IN endpoint).
Use the self.usb_device object to process these events.
class MydancerBackend(FacedancerApp, FacedancerBackend):
...
def service_irqs(self):
"""
Core routine of the Facedancer execution/event loop. Continuously monitors the
Moondancer's execution status, and reacts as events occur.
"""
# obtain latest events and handle them
for event in self.mydancer.get_events():
match event:
case USB_RECEIVE_SETUP:
self.usb_device.create_request(event.data)
case USB_RECEIVE_PACKET:
self.usb_device.handle_data_available(event.endpoint_number, event.data)
case USB_EP_IN_NAK:
self.usb_device.handle_nak(event.endpoint_number)