- some fixes
This commit is contained in:
		
							parent
							
								
									a977b32471
								
							
						
					
					
						commit
						7960b2957e
					
				
							
								
								
									
										35
									
								
								usb.c
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								usb.c
									
									
									
									
									
								
							@ -20,15 +20,15 @@
 | 
				
			|||||||
// ---------------
 | 
					// ---------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint8_t tx_assembly_buf[USB_RX_BUF_SIZE] DWORD_ALIGN; ///< Buffer for assembling packets
 | 
					static uint8_t tx_assembly_buf[USB_RX_BUF_SIZE] DWORD_ALIGN; ///< Buffer for assembling packets
 | 
				
			||||||
static Usb_SetupTransferState stups; ///< Setup transfer state.
 | 
					static Usb_SetupTransferState stups;                         ///< Setup transfer state.
 | 
				
			||||||
static UsbDrv_DrvIntf *drv; ///< Mutable pointer to the driver interface
 | 
					static UsbDrv_DrvIntf *drv;                                  ///< Mutable pointer to the driver interface
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ----------------
 | 
					// ----------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @fn void usb_event_callback(USB_CallbackEvent *cbevt)
 | 
					 * @fn void usb_event_callback(USB_CallbackEvent *cbevt)
 | 
				
			||||||
 * Prototype for the USB event callback.
 | 
					 * Prototype for the USB event callback.
 | 
				
			||||||
 * 
 | 
					 *
 | 
				
			||||||
 * @param cbevt pointer to the event data
 | 
					 * @param cbevt pointer to the event data
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
__attribute__((weak)) void usb_event_callback(Usb_CallbackEvent *cbevt) {
 | 
					__attribute__((weak)) void usb_event_callback(Usb_CallbackEvent *cbevt) {
 | 
				
			||||||
@ -64,9 +64,25 @@ 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.
 | 
				
			||||||
 * 
 | 
					 *
 | 
				
			||||||
 * @param data pointer to the SETUP packet
 | 
					 * @param data pointer to the SETUP packet
 | 
				
			||||||
 * @param size size of the packet
 | 
					 * @param size size of the packet
 | 
				
			||||||
 * @param stage stage of the SETUP transaction
 | 
					 * @param stage stage of the SETUP transaction
 | 
				
			||||||
@ -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;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -205,14 +226,14 @@ void usbcore_process_setup_pckt(const uint8_t *data, uint16_t size, uint8_t stag
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Process the non-SETUP packets.
 | 
					 * Process the non-SETUP packets.
 | 
				
			||||||
 * 
 | 
					 *
 | 
				
			||||||
 * @param cbcpd pointer to callback compound
 | 
					 * @param cbcpd pointer to callback compound
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void usbcore_process_nonsetup_event(UsbDrv_CallbackCompound *cbcpd) {
 | 
					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
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								usb.h
									
									
									
									
									
								
							@ -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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// --------------
 | 
					// --------------
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user