From 49456f49d0d18d023e5617dc87ff4a5192a1f497 Mon Sep 17 00:00:00 2001 From: David Madison Date: Thu, 21 Feb 2019 11:42:06 -0500 Subject: Add USB receive callback to USB ISR Using the OUT endpoint interrupt --- cores/arduino/USBCore.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 8794250..f2a2365 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -360,6 +360,9 @@ void InitEndpoints() UERST = 0x7E; // Reset endpoints UERST = 0; // End reset + + SetEP(XINPUT_RX_ENDPOINT); // Select XInput RX endpoint (OUT) + UEIENX |= (1 << RXOUTE); // Enable received "OUT" interrupt } static int _cmark; @@ -506,9 +509,17 @@ bool SendDescriptor(USBSetup& setup) return true; } -// Endpoint 0 interrupt +// Endpoint interrupt ISR(USB_COM_vect) { + SetEP(XINPUT_RX_ENDPOINT); // Select XInput RX endpoint (OUT) + if (UEINTX & (1 << RXOUTI)) { // If data received... + UEINTX &= ~(1 << RXOUTI); // Clear interrupt flag + if (XInputUSB::RecvCallback != nullptr) { + XInputUSB::RecvCallback(); // Call callback function if it exists + } + } + SetEP(0); if (!ReceivedSetupInt()) return; -- cgit v1.2.3-18-g5258