diff --git a/usb.c b/usb.c index 8de7160..213016e 100644 --- a/usb.c +++ b/usb.c @@ -64,6 +64,22 @@ void usbcore_reset() { memset(&stups, 0, sizeof(Usb_SetupTransferState)); } +/** + * Response follow-up if the ful response could not fit in a single packet. + * + * @param ep endpoint number + */ +static void usbcore_response_follow_up(uint8_t ep) { + uint32_t armSize = drv->arm_IN(0, stups.fup_data, stups.fup_sz); + stups.fup_sz -= armSize; // calculate remaining follow-up size + stups.fup_data += armSize; // advance follow-up data pointer + + if (stups.fup_sz > 0) { // we need further follow-ups + } else { // transfer done, remove callback + drv->reg_IN_cb(0, NULL); // remove IN callback + } +} + /** * Process SETUP packets. * @@ -158,7 +174,12 @@ void usbcore_process_setup_pckt(const uint8_t *data, uint16_t size, uint8_t stag } // arm data transmission - drv->arm_IN(0, data, sz); + uint32_t armSize = drv->arm_IN(0, data, sz); + if (armSize < sz) { // if could not arm the full response at once, then hook up a callback + stups.fup_sz = sz - armSize; // follow-up size + stups.fup_data = data + armSize; // generate follow-up data pointer + drv->reg_IN_cb(0, usbcore_response_follow_up); // register follow-up callback + } break; } @@ -212,7 +233,7 @@ void usbcore_process_nonsetup_event(UsbDrv_CallbackCompound *cbcpd) { Usb_CallbackEvent cbevt = {0}; // allocate and clear structure... cbevt.ep = cbcpd->ep; // later only fill nonzero fields - bool discard_event = false; // only discard if event does not fit any category above + bool discard_event = false; // only discard if event does not fit any category below switch (cbcpd->code) { case USB_CBC_OUT: { cbevt.type = USB_CBEVT_OUT; diff --git a/usb.h b/usb.h index 29706dd..7a75229 100644 --- a/usb.h +++ b/usb.h @@ -15,6 +15,8 @@ typedef struct { USB_SetupRequest setup_req; ///< Setup request uint8_t next_stage; ///< Next expected stage bool out_complete; ///< Signals if transfer's OUT direction is complete, no later data reception is expected + uint16_t fup_sz; ///< Some SETUP response IN data follows + const uint8_t * fup_data; ///< Pointer on follow-up data } Usb_SetupTransferState; // --------------