diff --git a/doc/help_mla_usb.jar b/doc/help_mla_usb.jar index 0d16d5a..9b814b5 100644 Binary files a/doc/help_mla_usb.jar and b/doc/help_mla_usb.jar differ diff --git a/doc/help_mla_usb.pdf b/doc/help_mla_usb.pdf index 833214e..f5ba529 100644 Binary files a/doc/help_mla_usb.pdf and b/doc/help_mla_usb.pdf differ diff --git a/inc/usb.h b/inc/usb.h index 03b5073..4363f5b 100644 --- a/inc/usb.h +++ b/inc/usb.h @@ -42,8 +42,7 @@ please contact mla_licensing@microchip.com #ifndef _USB_H_ #define _USB_H_ -#include "system.h" -#include "system_config.h" // Must be defined by the application +#include "usb_config.h" #include "usb_common.h" // Common USB library definitions #include "usb_ch9.h" // USB device framework definitions diff --git a/inc/usb_common.h b/inc/usb_common.h index 00efb86..bc38906 100644 --- a/inc/usb_common.h +++ b/inc/usb_common.h @@ -47,9 +47,6 @@ please contact mla_licensing@microchip.com #include #include -#include "system.h" -#include "system_config.h" - // ***************************************************************************** // ***************************************************************************** // Section: USB Constants @@ -465,108 +462,6 @@ stalled (ie. bit 0 = EP0, bit 1 = EP1, etc.) typedef bool (*USB_EVENT_HANDLER) ( USB_EVENT event, void *data, unsigned int size ); - -// ***************************************************************************** -// ***************************************************************************** -// Section: USB Application Program Interface (API) Routines -// ***************************************************************************** -// ***************************************************************************** - -/**************************************************************************** - Function: - bool USBInitialize ( unsigned long flags ) - - Summary: - This interface initializes the variables of the USB host stack. - - Description: - This interface initializes the USB stack. - - Precondition: - None - - Parameters: - flags - reserved - - Return Values: - true - Initialization successful - false - Initialization failure - - Remarks: - This interface is implemented as a macro that can be defined by the - application or by default is defined correctly for the stack mode. - - ***************************************************************************/ - -#ifndef USBInitialize - #if defined( USB_SUPPORT_DEVICE ) - #if defined( USB_SUPPORT_HOST ) - #if defined( USB_SUPPORT_OTG ) - #error "USB OTG is not yet supported." - #else - #define USBInitialize(f) \ - (USBDEVInitialize(f) && USBHostInit(f)) ? \ - true : false - #endif - #else - #define USBInitialize(f) USBDeviceInit() - #endif - #else - #if defined( USB_SUPPORT_HOST ) - #define USBInitialize(f) USBHostInit(f) - #else - #error "Application must define support mode in usb_config.h" - #endif - #endif -#endif - - -/**************************************************************************** - Function: - void USBTasks( void ) - - Summary: - This function executes the tasks for USB operation. - - Description: - This function executes the tasks for USB host operation. It must be - executed on a regular basis to keep everything functioning. - - Precondition: - USBInitialize() has been called. - - Parameters: - None - - Returns: - None - - Remarks: - This interface is implemented as a macro that can be defined by the - application or by default is defined correctly for the stack mode. - - ***************************************************************************/ - -#ifndef USBTasks // Implemented as a macro that can be overridden. - #if defined( USB_SUPPORT_DEVICE ) - #if defined( USB_SUPPORT_HOST ) - #if defined( USB_SUPPORT_OTG ) - #error "USB OTG is not yet supported." - #else - #define USBTasks() {USBHostTasks(); USBHALHandleBusEvent();} - #endif - #else - #define USBTasks() USBDeviceTasks() - #endif - #else - #if defined( USB_SUPPORT_HOST ) - #define USBTasks() USBHostTasks() - #else - #error "Application must define support mode in usb_config.h" - #endif - #endif -#endif - #define USB_PING_PONG__NO_PING_PONG 0x00 //0b00 #define USB_PING_PONG__EP0_OUT_ONLY 0x01 //0b01 #define USB_PING_PONG__FULL_PING_PONG 0x02 //0b10 diff --git a/inc/usb_device.h b/inc/usb_device.h index 77781f9..37593cd 100644 --- a/inc/usb_device.h +++ b/inc/usb_device.h @@ -38,9 +38,10 @@ please contact mla_licensing@microchip.com #ifndef _USB_DEVICE_H #define _USB_DEVICE_H -#include "usb_common.h" #include +#include "usb_common.h" +#include "usb_config.h" #if defined(__XC8) #define __attribute__(a) @@ -2040,14 +2041,6 @@ typedef struct __attribute__ ((packed)) CTRL_TRF_RETURN (*pFunc)(CTRL_TRF_PARAMS); }OUT_PIPE; -/************* DWF - SHOULD BE REIMPLEMENTED AS AN EVENT *******************/ -//#if defined(ENABLE_EP0_DATA_RECEIVED_CALLBACK) -// void USBCBEP0DataReceived(void); -// #define USBCB_EP0_DATA_RECEIVED() USBCBEP0DataReceived() -//#else -// #define USBCB_EP0_DATA_RECEIVED() -//#endif - extern USB_VOLATILE bool RemoteWakeup; extern USB_VOLATILE bool USBBusIsSuspended; extern USB_VOLATILE USB_DEVICE_STATE USBDeviceState; diff --git a/inc/usb_device_msd.h b/inc/usb_device_msd.h index f6a3b89..7970ebc 100644 --- a/inc/usb_device_msd.h +++ b/inc/usb_device_msd.h @@ -519,8 +519,6 @@ typedef struct } LUN_FUNCTIONS; /** Section: Externs *********************************************************/ -extern USB_HANDLE USBMSDOutHandle; -extern USB_HANDLE USBMSDInHandle; extern volatile USB_MSD_CBW msd_cbw; extern volatile USB_MSD_CSW msd_csw; extern volatile char msd_buffer[512]; @@ -618,7 +616,33 @@ void USBMSDInit(void); **************************************************************************/ #define LUNSoftAttach(LUN) SoftDetach[LUN]=false; - +/****************************************************************************** + Function: + void MSDTransferTerminated(USB_HANDLE handle) + + Description: + Check if the host recently did a clear endpoint halt on the MSD OUT endpoint. + In this case, we want to re-arm the MSD OUT endpoint, so we are prepared + to receive the next CBW that the host might want to send. + Note: If however the STALL was due to a CBW not valid condition, + then we are required to have a persistent STALL, where it cannot + be cleared (until MSD reset recovery takes place). See MSD BOT + specs v1.0, section 6.6.1. + PreCondition: + A transfer was terminated. This should be called from the transfer + terminated event handler. + + Parameters: + USB_HANDLE handle - the handle of the transfer that was terminated. + + Return Values: + None + + Remarks: + None + + *****************************************************************************/ +void MSDTransferTerminated(USB_HANDLE handle); #endif diff --git a/inc/usb_hal_dspic33e.h b/inc/usb_hal_dspic33e.h index 1b648ab..6b21867 100644 --- a/inc/usb_hal_dspic33e.h +++ b/inc/usb_hal_dspic33e.h @@ -28,7 +28,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ #include "system.h" -#include "system_config.h" +#include "usb_config.h" #include #include diff --git a/inc/usb_hal_pic16f1.h b/inc/usb_hal_pic16f1.h index 4ae3300..d683c8d 100644 --- a/inc/usb_hal_pic16f1.h +++ b/inc/usb_hal_pic16f1.h @@ -26,12 +26,13 @@ please contact mla_licensing@microchip.com /****** include files ********************************************************/ /*****************************************************************************/ +#include + #include #include #include -#include -#include "system_config.h" +#include "usb_config.h" #ifdef __cplusplus // Provide C++ Compatability extern "C" { diff --git a/inc/usb_hal_pic18.h b/inc/usb_hal_pic18.h index c1a95d2..3e81499 100644 --- a/inc/usb_hal_pic18.h +++ b/inc/usb_hal_pic18.h @@ -47,8 +47,7 @@ please contact mla_licensing@microchip.com #include -#include "system.h" -#include "system_config.h" +#include "usb_config.h" #ifdef __cplusplus // Provide C++ Compatability extern "C" { diff --git a/inc/usb_hal_pic24.h b/inc/usb_hal_pic24.h index fa690d0..054cb49 100644 --- a/inc/usb_hal_pic24.h +++ b/inc/usb_hal_pic24.h @@ -26,8 +26,8 @@ please contact mla_licensing@microchip.com /****** include files ********************************************************/ /*****************************************************************************/ -#include "system.h" -#include "system_config.h" +#include +#include "usb_config.h" #include #include diff --git a/inc/usb_hal_pic24e.h b/inc/usb_hal_pic24e.h index bb46d7c..da0bdb8 100644 --- a/inc/usb_hal_pic24e.h +++ b/inc/usb_hal_pic24e.h @@ -27,7 +27,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ #include "system.h" -#include "system_config.h" +#include "usb_config.h" #include #include diff --git a/inc/usb_hal_pic24f.h b/inc/usb_hal_pic24f.h index fa690d0..ea3a88c 100644 --- a/inc/usb_hal_pic24f.h +++ b/inc/usb_hal_pic24f.h @@ -26,11 +26,12 @@ please contact mla_licensing@microchip.com /****** include files ********************************************************/ /*****************************************************************************/ -#include "system.h" -#include "system_config.h" +#include #include #include + +#include "usb_config.h" #include "usb_common.h" /*****************************************************************************/ @@ -75,6 +76,9 @@ please contact mla_licensing@microchip.com || defined(__PIC24FJ64GB410__) || defined(__PIC24FJ64GB412__) || defined(__PIC24FJ64GB406__) #define DEVICE_SPECIFIC_IEC_REGISTER_COUNT 8 //Number of IECx registers implemented in the microcontroller (varies from device to device, make sure this is set correctly for the intended CPU) #define USB_HAL_VBUSTristate() {TRISFbits.TRISF7 = 1;} +#elif defined(__PIC24FJ1024GB610__) || defined(__PIC24FJ512GB610__) || defined(__PIC24FJ256GB610__) || defined(__PIC24FJ128GB610__) || defined(__PIC24FJ1024GB606__) || defined(__PIC24FJ512GB606__) || defined(__PIC24FJ256GB606__) || defined(__PIC24FJ128GB606__) + #define DEVICE_SPECIFIC_IEC_REGISTER_COUNT 8 //Number of IECx registers implemented in the microcontroller (varies from device to device, make sure this is set correctly for the intended CPU) + #define USB_HAL_VBUSTristate() {TRISFbits.TRISF7 = 1;} #else #error "Unknown processor type selected. Refer to device datasheet and update the definition for DEVICE_SPECIFIC_IEC_REGISTER_COUNT." //#define DEVICE_SPECIFIC_IEC_REGISTER_COUNT 8 // <--- Update this number with the real number for your device and uncomment (and delete the above #error). diff --git a/inc/usb_host_msd_scsi.h b/inc/usb_host_msd_scsi.h index 1aa56f7..d4c73e2 100644 --- a/inc/usb_host_msd_scsi.h +++ b/inc/usb_host_msd_scsi.h @@ -23,7 +23,7 @@ please contact mla_licensing@microchip.com #define __USBHOSTMSDSCSI_H__ #include "usb.h" -#include "system_config.h" +#include "usb_config.h" #include "fileio.h" // ***************************************************************************** diff --git a/src/usb_device.c b/src/usb_device.c index 7400d87..010b606 100644 --- a/src/usb_device.c +++ b/src/usb_device.c @@ -42,17 +42,27 @@ please contact mla_licensing@microchip.com // Section: Included Files // ***************************************************************************** // ***************************************************************************** +#include + #include #include +#include -#include "system.h" -#include "system_config.h" +#include "usb_config.h" #include "usb.h" #include "usb_ch9.h" #include "usb_device.h" #include "usb_device_local.h" +#ifndef uintptr_t + #if defined(__XC8__) || defined(__XC16__) + #define uintptr_t uint16_t + #elif defined (__XC32__) + #define uintptr_t uint32_t + #endif +#endif + #if defined(USB_USE_MSD) #include "usb_device_msd.h" #endif @@ -241,34 +251,6 @@ static void USBStallHandler(void); // ***************************************************************************** // ***************************************************************************** -/**************************************************************************** - Function: - void USBAdvancePingPongBuffer(BDT_ENTRY** buffer) - - Description: - This function will advance the passed pointer to the next buffer based on - the ping pong option setting. This function should be used for EP1-EP15 - only. This function is not valid for EP0. - - Precondition: - None - - Parameters: - BDT_ENTRY** - pointer to the BDT_ENTRY pointer that you want to be advanced - to the next buffer state - - Return Values: - None - - Remarks: - None - - ***************************************************************************/ -#define USBAdvancePingPongBuffer(buffer) {((uint8_t_VAL*)buffer)->Val ^= USB_NEXT_PING_PONG;} -#define USBHALPingPongSetToOdd(buffer) {((uint8_t_VAL*)buffer)->Val |= USB_NEXT_PING_PONG;} -#define USBHALPingPongSetToEven(buffer) {((uint8_t_VAL*)buffer)->Val &= ~USB_NEXT_PING_PONG;} - - /************************************************************************** Function: void USBDeviceInit(void) @@ -1054,12 +1036,12 @@ USB_HANDLE USBTransferOnePacket(uint8_t ep,uint8_t dir,uint8_t* data,uint8_t len if(dir != OUT_FROM_HOST) { //toggle over the to the next buffer for an IN endpoint - USBAdvancePingPongBuffer(&pBDTEntryIn[ep]); + pBDTEntryIn[ep] = (BDT_ENTRY*)(((uintptr_t)pBDTEntryIn[ep]) ^ USB_NEXT_PING_PONG); } else { //toggle over the to the next buffer for an OUT endpoint - USBAdvancePingPongBuffer(&pBDTEntryOut[ep]); + pBDTEntryOut[ep] = (BDT_ENTRY*)(((uintptr_t)pBDTEntryOut[ep]) ^ USB_NEXT_PING_PONG); } return (USB_HANDLE)handle; } @@ -1158,8 +1140,8 @@ void USBCancelIO(uint8_t endpoint) //Point to the next buffer for ping pong purposes. UOWN getting cleared //(either due to SIE clearing it after a transaction, or the firmware //clearing it) makes hardware ping pong pointer advance. - USBAdvancePingPongBuffer(&pBDTEntryIn[endpoint]); - + pBDTEntryIn[endpoint] = (BDT_ENTRY*)(((uintptr_t)pBDTEntryIn[endpoint]) ^ USB_NEXT_PING_PONG); + pBDTEntryIn[endpoint]->STAT.Val &= _DTSMASK; pBDTEntryIn[endpoint]->STAT.Val ^= _DTSMASK; #endif @@ -2411,7 +2393,7 @@ static void USBCtrlEPService(void) //Set the next out to the current out packet pBDTEntryEP0OutNext = pBDTEntryEP0OutCurrent; //Toggle it to the next ping pong buffer (if applicable) - ((uint8_t_VAL*)&pBDTEntryEP0OutNext)->Val ^= USB_NEXT_EP0_OUT_PING_PONG; + pBDTEntryEP0OutNext = (volatile BDT_ENTRY*)(((uintptr_t)pBDTEntryEP0OutNext) ^ USB_NEXT_EP0_OUT_PING_PONG); //If the current EP0 OUT buffer has a SETUP packet if(pBDTEntryEP0OutCurrent->STAT.PID == PID_SETUP) @@ -2499,10 +2481,11 @@ static void USBCtrlTrfSetupHandler(void) //one or more UOWN bits might still be set. If so, we should clear the UOWN bits, //so the EP0 IN/OUT endpoints are in a known inactive state, ready for re-arming //by the class request handler that will be called next. - pBDTEntryIn[0]->STAT.Val &= ~(_USIE); - ((uint8_t_VAL*)&pBDTEntryIn[0])->Val ^= USB_NEXT_EP0_IN_PING_PONG; + pBDTEntryIn[0]->STAT.Val &= ~(_USIE); + + pBDTEntryIn[0] = (volatile BDT_ENTRY*)(((uintptr_t)pBDTEntryIn[0]) ^ USB_NEXT_EP0_IN_PING_PONG); pBDTEntryIn[0]->STAT.Val &= ~(_USIE); - ((uint8_t_VAL*)&pBDTEntryIn[0])->Val ^= USB_NEXT_EP0_IN_PING_PONG; + pBDTEntryIn[0] = (volatile BDT_ENTRY*)(((uintptr_t)pBDTEntryIn[0]) ^ USB_NEXT_EP0_IN_PING_PONG); pBDTEntryEP0OutNext->STAT.Val &= ~(_USIE); inPipes[0].info.Val = 0; @@ -2613,7 +2596,7 @@ static void USBCtrlTrfInHandler(void) lastDTS = pBDTEntryIn[0]->STAT.DTS; //switch to the next ping pong buffer - ((uint8_t_VAL*)&pBDTEntryIn[0])->Val ^= USB_NEXT_EP0_IN_PING_PONG; + pBDTEntryIn[0] = (volatile BDT_ENTRY*)(((uintptr_t)pBDTEntryIn[0]) ^ USB_NEXT_EP0_IN_PING_PONG); //Must check if in ADR_PENDING_STATE. If so, we need to update the address //now, since the IN status stage of the (set address) control transfer has @@ -2851,11 +2834,11 @@ static void USBStdFeatureReqHandler(void) #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) if(current_ep_data.bits.ping_pong_state == 0) //Check if even { - USBHALPingPongSetToEven(&p); + p = (BDT_ENTRY*)(((uintptr_t)p) & (~USB_NEXT_PING_PONG)); } else //else must have been odd { - USBHALPingPongSetToOdd(&p); + p = (BDT_ENTRY*)(((uintptr_t)p) | USB_NEXT_PING_PONG); } #endif @@ -2896,7 +2879,7 @@ static void USBStdFeatureReqHandler(void) //Else the request must have been a CLEAR_FEATURE endpoint halt. #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) //toggle over the to the non-active BDT - USBAdvancePingPongBuffer(&p); + p = (BDT_ENTRY*)(((uintptr_t)p) ^ USB_NEXT_PING_PONG); if(p->STAT.UOWN == 1) { @@ -2914,7 +2897,7 @@ static void USBStdFeatureReqHandler(void) //toggle back to the active BDT (the one the SIE is currently looking at //and will use for the next successful transaction to take place on the EP - USBAdvancePingPongBuffer(&p); + p = (BDT_ENTRY*)(((uintptr_t)p) ^ USB_NEXT_PING_PONG); //Check if we are currently terminating, or have previously terminated //a transaction on the given endpoint. If so, need to clear UOWN, diff --git a/src/usb_device_audio.c b/src/usb_device_audio.c index 5034881..36fa02e 100644 --- a/src/usb_device_audio.c +++ b/src/usb_device_audio.c @@ -20,7 +20,7 @@ please contact mla_licensing@microchip.com //DOM-IGNORE-END /** I N C L U D E S *******************************************************/ -#include "system_config.h" +#include "usb_config.h" #include "usb.h" #include "usb_device_audio.h" diff --git a/src/usb_device_hid.c b/src/usb_device_hid.c index 42143f0..ef8888b 100644 --- a/src/usb_device_hid.c +++ b/src/usb_device_hid.c @@ -41,7 +41,7 @@ please contact mla_licensing@microchip.com // Section: Included Files // ***************************************************************************** // ***************************************************************************** -#include "system_config.h" +#include "usb_config.h" #include "usb.h" #include "usb_device_hid.h" @@ -223,8 +223,8 @@ void USBCheckHIDRequest(void) break; case SET_IDLE: USBEP0Transmit(USB_EP0_NO_DATA); - idle_rate = ((USB_SETUP_SET_IDLE_RATE*)&SetupPkt)->duration; - USB_DEVICE_HID_IDLE_RATE_CALLBACK(((USB_SETUP_SET_IDLE_RATE*)&SetupPkt)->reportId, idle_rate); + idle_rate = SetupPkt.W_Value.byte.HB; + USB_DEVICE_HID_IDLE_RATE_CALLBACK(SetupPkt.W_Value.byte.LB, idle_rate); break; case GET_PROTOCOL: USBEP0SendRAMPtr( @@ -234,7 +234,7 @@ void USBCheckHIDRequest(void) break; case SET_PROTOCOL: USBEP0Transmit(USB_EP0_NO_DATA); - active_protocol = ((USB_SETUP_SET_PROTOCOL*)&SetupPkt)->protocol; + active_protocol = SetupPkt.W_Value.byte.LB; break; }//end switch(SetupPkt.bRequest) diff --git a/src/usb_device_local.h b/src/usb_device_local.h index 934c5ba..c372837 100644 --- a/src/usb_device_local.h +++ b/src/usb_device_local.h @@ -19,7 +19,7 @@ please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END -#include "system_config.h" +#include "usb_config.h" /* Short Packet States - Used by Control Transfer Read - CTRL_TRF_TX */ #define SHORT_PKT_NOT_USED 0 diff --git a/src/usb_device_msd.c b/src/usb_device_msd.c index c5fb4b2..67ba52d 100644 --- a/src/usb_device_msd.c +++ b/src/usb_device_msd.c @@ -22,7 +22,7 @@ please contact mla_licensing@microchip.com /** I N C L U D E S **************************************************/ #include "usb.h" #include "system.h" -#include "system_config.h" +#include "usb_config.h" #include @@ -1645,6 +1645,50 @@ void MSDErrorHandler(uint8_t ErrorCase) } +/****************************************************************************** + Function: + void MSDTransferTerminated(USB_HANDLE handle) + + Description: + Check if the host recently did a clear endpoint halt on the MSD OUT endpoint. + In this case, we want to re-arm the MSD OUT endpoint, so we are prepared + to receive the next CBW that the host might want to send. + Note: If however the STALL was due to a CBW not valid condition, + then we are required to have a persistent STALL, where it cannot + be cleared (until MSD reset recovery takes place). See MSD BOT + specs v1.0, section 6.6.1. + PreCondition: + A transfer was terminated. This should be called from the transfer + terminated event handler. + + Parameters: + USB_HANDLE handle - the handle of the transfer that was terminated. + + Return Values: + None + + Remarks: + None + + *****************************************************************************/ +void MSDTransferTerminated(USB_HANDLE handle) +{ + if(MSDWasLastCBWValid() == false) + { + //Need to re-stall the endpoints, for persistent STALL behavior. + USBStallEndpoint(MSD_DATA_IN_EP, IN_TO_HOST); + USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); + } + else + { + //Check if the host cleared halt on the bulk out endpoint. In this + //case, we should re-arm the endpoint, so we can receive the next CBW. + if((USB_HANDLE)handle == USBGetNextHandle(MSD_DATA_OUT_EP, OUT_FROM_HOST)) + { + USBMSDOutHandle = USBRxOnePacket(MSD_DATA_OUT_EP, (uint8_t*)&msd_cbw, MSD_OUT_EP_SIZE); + } + } +} //----------------------------------------------------------------------------------------- #endif //end of #ifdef USB_USE_MSD diff --git a/src/usb_hal_pic24.c b/src/usb_hal_pic24.c index 4043fd2..169da6c 100644 --- a/src/usb_hal_pic24.c +++ b/src/usb_hal_pic24.c @@ -22,8 +22,6 @@ please contact mla_licensing@microchip.com #ifndef USB_HAL_PIC24F_C #define USB_HAL_PIC24F_C -#include "system.h" -#include "system_config.h" #include "usb.h" //Only include the source for this file if you are using C30. This code diff --git a/src/usb_host.c b/src/usb_host.c index 1eb2445..09ec8d9 100644 --- a/src/usb_host.c +++ b/src/usb_host.c @@ -19,8 +19,7 @@ please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END -#include -#include +#include #include #include #include @@ -308,7 +307,15 @@ uint8_t USBHostDeviceStatus( uint8_t deviceAddress ) return usbDeviceInfo.errorCode; } - return USB_DEVICE_ENUMERATING; + + if ((usbHostState > STATE_ATTACHED) && + (usbHostState < STATE_RUNNING) + ) + { + return USB_DEVICE_ENUMERATING; + } + + return USB_HOLDING_UNSUPPORTED_DEVICE; } /**************************************************************************** @@ -1104,6 +1111,7 @@ void USBHostShutdown( void ) USB_VBUS_POWER_EVENT_DATA powerRequest; powerRequest.port = 0; // Currently was have only one port. + powerRequest.current = usbDeviceInfo.currentConfigurationPower; USB_HOST_APP_EVENT_HANDLER( usbDeviceInfo.deviceAddress, EVENT_VBUS_RELEASE_POWER, @@ -3542,7 +3550,10 @@ void _USB_FindNextToken( void ) // If the user wants an event from the interrupt handler to handle the data as quickly as // possible, send up the event. Then mark the packet as used. #ifdef USB_HOST_APP_DATA_EVENT_HANDLER - usbClientDrvTable[pCurrentEndpoint->clientDriver].DataEventHandler( usbDeviceInfo.deviceAddress, EVENT_DATA_ISOC_READ, ((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].pBuffer, pCurrentEndpoint->dataCount ); + if(usbClientDrvTable[pCurrentEndpoint->clientDriver].DataEventHandler != NULL) + { + usbClientDrvTable[pCurrentEndpoint->clientDriver].DataEventHandler( usbDeviceInfo.deviceAddress, EVENT_DATA_ISOC_READ, ((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].pBuffer, pCurrentEndpoint->dataCount ); + } ((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].bfDataLengthValid = 0; #endif @@ -3637,7 +3648,10 @@ void _USB_FindNextToken( void ) // If the user wants an event from the interrupt handler to handle the data as quickly as // possible, send up the event. #ifdef USB_HOST_APP_DATA_EVENT_HANDLER + if(usbClientDrvTable[pCurrentEndpoint->clientDriver].DataEventHandler != NULL) + { usbClientDrvTable[pCurrentEndpoint->clientDriver].DataEventHandler( usbDeviceInfo.deviceAddress, EVENT_DATA_ISOC_WRITE, ((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].pBuffer, pCurrentEndpoint->dataCount ); + } #endif // Move to the next data buffer. @@ -4616,7 +4630,10 @@ void _USB_NotifyDataClients( uint8_t address, USB_EVENT event, void *data, unsig pInterface = usbDeviceInfo.pInterfaceList; while (pInterface != NULL) // Scan the interface list for all active drivers. { - usbClientDrvTable[pInterface->clientDriver].DataEventHandler(address, event, data, size); + if(usbClientDrvTable[pInterface->clientDriver].DataEventHandler != NULL) + { + usbClientDrvTable[pInterface->clientDriver].DataEventHandler(address, event, data, size); + } pInterface = pInterface->next; } break; diff --git a/src/usb_host_hid.c b/src/usb_host_hid.c index 8e255a1..70e3a1d 100644 --- a/src/usb_host_hid.c +++ b/src/usb_host_hid.c @@ -1051,8 +1051,14 @@ bool USBHostHID_ApiFindValue(uint16_t usagePage,uint16_t usage,HIDReportTypeEnum /******************************************************************************* Function: - bool USBHostHID_ApiImportData(uint8_t *report, uint16_t reportLength, - HID_USER_DATA_SIZE *buffer,HID_DATA_DETAILS *pDataDetails) + bool USBHostHID_ApiImportData + ( + uint8_t *report, + uint16_t reportLength, + HID_USER_DATA_SIZE *buffer, + HID_DATA_DETAILS *pDataDetails + ) + Description: This function can be used by application to extract data from the input reports. On receiving the input report from the device application can call @@ -1062,8 +1068,8 @@ bool USBHostHID_ApiFindValue(uint16_t usagePage,uint16_t usage,HIDReportTypeEnum None Parameters: - uint8_t *report - Input report received from device - uint16_t reportLength - Length of input report report + uint8_t *report - Input report received from device + uint16_t reportLength - Length of input report report HID_USER_DATA_SIZE *buffer - Buffer into which data needs to be populated HID_DATA_DETAILS *pDataDetails - data details extracted from report @@ -1075,7 +1081,13 @@ bool USBHostHID_ApiFindValue(uint16_t usagePage,uint16_t usage,HIDReportTypeEnum Remarks: None *******************************************************************************/ -bool USBHostHID_ApiImportData(uint8_t *report, uint16_t reportLength, HID_USER_DATA_SIZE *buffer, HID_DATA_DETAILS *pDataDetails) +bool USBHostHID_ApiImportData +( + uint8_t *report, + uint16_t reportLength, + HID_USER_DATA_SIZE *buffer, + HID_DATA_DETAILS *pDataDetails +) { uint16_t data; uint16_t signBit; @@ -1087,53 +1099,66 @@ bool USBHostHID_ApiImportData(uint8_t *report, uint16_t reportLength, HID_USER_D uint16_t lastByte; uint16_t i; -// Report must be ok - - if (report == NULL) return false; - -// Must be the right report - - if ((pDataDetails->reportID != 0) && (pDataDetails->reportID != report[0])) return false; + if (report == NULL) + { + return false; + } -// Length must be ok + /* Check the report ID. */ + if ( (pDataDetails->reportID != 0) && + (pDataDetails->reportID != report[0]) + ) + { + return false; + } + - if (pDataDetails->reportLength != reportLength) return false; + /* Check the report length. */ + if (pDataDetails->reportLength != reportLength) + { + return false; + } + lastByte = (pDataDetails->bitOffset + (pDataDetails->bitLength * pDataDetails->count) - 1)/8; - if (lastByte > reportLength) return false; - -// Extract data one count at a time - + + if (lastByte > reportLength) + { + return false; + } + + /* Extract data one count at a time */ start = pDataDetails->bitOffset; - for (i=0; icount; i++) { + + for (i=0; icount; i++) + { startByte = start/8; startBit = start&7; lastByte = (start + pDataDetails->bitLength - 1)/8; -// Pick up the data bytes backwards - + /* Pick up the data bytes backwards */ data = 0; - do { + do + { data <<= 8; data |= (int) report[lastByte]; } while (lastByte-- > startByte); -// Shift to the right to byte align the least significant bit - - if (startBit > 0) data >>= startBit; - -// Done if 16 bits long + /* Shift to the right to byte align the least significant bit */ + if (startBit > 0) + { + data >>= startBit; + } + /* Done if 16 bits long */ if (pDataDetails->bitLength < 16) { -// Mask off the other bits - + /* Mask off the other bits */ mask = 1 << pDataDetails->bitLength; mask--; data &= mask; -// Sign extend the report item - + /* Sign extend the report item */ if (pDataDetails->signExtend) { signBit = 1; if (pDataDetails->bitLength > 1) signBit <<= (pDataDetails->bitLength-1); @@ -1143,12 +1168,10 @@ bool USBHostHID_ApiImportData(uint8_t *report, uint16_t reportLength, HID_USER_D } } -// Save the value - + /* Save the value */ *buffer++ = data; -// Next one - + /* Next one */ start += pDataDetails->bitLength; } return true; diff --git a/src/usb_host_hid_parser.c b/src/usb_host_hid_parser.c index 836ccd0..07b3d49 100644 --- a/src/usb_host_hid_parser.c +++ b/src/usb_host_hid_parser.c @@ -513,7 +513,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u lusageItem->usageMinimum = item.Data.uItemData; } - if (lusageItem->usagePage != deviceRptInfo.rangeUsagePage); + if (lusageItem->usagePage != deviceRptInfo.rangeUsagePage) lhidError = HID_ERR_BadUsageRangePage; /* Error: BadUsageRangePage */ lusageItem->usageMaximum = deviceRptInfo.usageMaximum; diff --git a/src/usb_host_msd_scsi.c b/src/usb_host_msd_scsi.c index cde831e..b1960df 100644 --- a/src/usb_host_msd_scsi.c +++ b/src/usb_host_msd_scsi.c @@ -21,11 +21,11 @@ please contact mla_licensing@microchip.com #include #include -#include "system_config.h" -#include "fileio.h" -#include "usb.h" -#include "usb_host_msd.h" -#include "usb_host_msd_scsi.h" +#include +#include +#include +#include +#include //#define DEBUG_MODE #if defined(DEBUG_MODE)