- some fixes

This commit is contained in:
Wiesner András 2025-02-25 11:05:41 +01:00
parent a977b32471
commit 7960b2957e
2 changed files with 30 additions and 7 deletions

25
usb.c
View File

@ -64,6 +64,22 @@ void usbcore_reset() {
memset(&stups, 0, sizeof(Usb_SetupTransferState)); 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. * 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 // 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; break;
} }
@ -212,7 +233,7 @@ void usbcore_process_nonsetup_event(UsbDrv_CallbackCompound *cbcpd) {
Usb_CallbackEvent cbevt = {0}; // allocate and clear structure... Usb_CallbackEvent cbevt = {0}; // allocate and clear structure...
cbevt.ep = cbcpd->ep; // later only fill nonzero fields 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) { switch (cbcpd->code) {
case USB_CBC_OUT: { case USB_CBC_OUT: {
cbevt.type = USB_CBEVT_OUT; cbevt.type = USB_CBEVT_OUT;

2
usb.h
View File

@ -15,6 +15,8 @@ typedef struct {
USB_SetupRequest setup_req; ///< Setup request USB_SetupRequest setup_req; ///< Setup request
uint8_t next_stage; ///< Next expected stage uint8_t next_stage; ///< Next expected stage
bool out_complete; ///< Signals if transfer's OUT direction is complete, no later data reception is expected 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; } Usb_SetupTransferState;
// -------------- // --------------