From e9304c942b28b49d62af2c9844f01bb24a7b601c Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Thu, 16 Mar 2017 18:14:33 +1100 Subject: [PATCH] Strip all whitespace on line endings. --- inc/usb.h | 4 +- inc/usb_ch9.h | 6 +- inc/usb_common.h | 124 ++--- inc/usb_device.h | 766 +++++++++++++++--------------- inc/usb_device_audio.h | 22 +- inc/usb_device_ccid.h | 58 +-- inc/usb_device_cdc.h | 220 ++++----- inc/usb_device_generic.h | 44 +- inc/usb_device_hid.h | 82 ++-- inc/usb_device_midi.h | 4 +- inc/usb_device_msd.h | 80 ++-- inc/usb_device_phdc.h | 84 ++-- inc/usb_device_phdc_com_model.h | 2 +- inc/usb_hal.h | 136 +++--- inc/usb_hal_dspic33e.h | 98 ++-- inc/usb_hal_pic16f1.h | 76 +-- inc/usb_hal_pic18.h | 114 ++--- inc/usb_hal_pic24.h | 96 ++-- inc/usb_hal_pic24e.h | 98 ++-- inc/usb_hal_pic24f.h | 96 ++-- inc/usb_hal_pic32mm.h | 112 ++--- inc/usb_hid.h | 2 +- inc/usb_host.h | 42 +- inc/usb_host_android.h | 34 +- inc/usb_host_audio_v1.h | 70 +-- inc/usb_host_cdc.h | 6 +- inc/usb_host_cdc_interface.h | 2 +- inc/usb_host_hid.h | 152 +++--- inc/usb_host_hid_parser.h | 34 +- inc/usb_host_msd.h | 4 +- inc/usb_host_msd_scsi.h | 8 +- inc/usb_struct_queue.h | 42 +- src/usb_device.c | 708 +++++++++++++-------------- src/usb_device_audio.c | 6 +- src/usb_device_ccid.c | 88 ++-- src/usb_device_cdc.c | 186 ++++---- src/usb_device_generic.c | 78 +-- src/usb_device_hid.c | 44 +- src/usb_device_local.h | 38 +- src/usb_device_msd.c | 496 +++++++++---------- src/usb_device_msd_multi_sector.c | 570 +++++++++++----------- src/usb_device_phdc.c | 192 ++++---- src/usb_device_phdc_com_model.c | 4 +- src/usb_hal_16bit.c | 22 +- src/usb_hal_32bit.c | 46 +- src/usb_hal_dspic33e.c | 20 +- src/usb_hal_local.h | 4 +- src/usb_hal_pic24.c | 20 +- src/usb_hal_pic24e.c | 20 +- src/usb_hal_pic24f.c | 22 +- src/usb_host.c | 118 ++--- src/usb_host_android.c | 114 ++--- src/usb_host_android_local.h | 2 +- src/usb_host_audio_v1.c | 126 ++--- src/usb_host_cdc.c | 190 ++++---- src/usb_host_cdc_interface.c | 24 +- src/usb_host_generic.c | 6 +- src/usb_host_hid.c | 76 +-- src/usb_host_hid_parser.c | 80 ++-- src/usb_host_local.h | 2 +- src/usb_host_midi.c | 70 +-- src/usb_host_msd.c | 2 +- src/usb_host_msd_scsi.c | 4 +- src/usb_host_printer.c | 2 +- src/usb_host_printer_esc_pos.c | 26 +- src/usb_host_printer_pcl_5.c | 2 +- src/usb_host_printer_postscript.c | 2 +- src/usb_host_printer_primitives.c | 2 +- src/usb_pic18_local.h | 28 +- 69 files changed, 3079 insertions(+), 3079 deletions(-) diff --git a/inc/usb.h b/inc/usb.h index 4363f5b..3bbb105 100644 --- a/inc/usb.h +++ b/inc/usb.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -57,7 +57,7 @@ please contact mla_licensing@microchip.com #include "usb_hal.h" // Hardware Abstraction Layer interface -/* USB Library version number. This can be used to verify in an application +/* USB Library version number. This can be used to verify in an application specific version of the library is being used. */ #define USB_MAJOR_VER 2 // Firmware version, major release number. diff --git a/inc/usb_ch9.h b/inc/usb_ch9.h index 30cf63c..8992bd2 100644 --- a/inc/usb_ch9.h +++ b/inc/usb_ch9.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -179,7 +179,7 @@ typedef struct __attribute__ ((packed)) _USB_ENDPOINT_DESCRIPTOR #define EP_SM_PKT_BULK_FS 8 // Small full-speed bulk packet /* Descriptor IDs -The descriptor ID type defines the information required by the HOST during a +The descriptor ID type defines the information required by the HOST during a GET_DESCRIPTOR request */ typedef struct @@ -521,7 +521,7 @@ typedef union __attribute__ ((packed)) /******************************************************************** USB Endpoint Definitions USB Standard EP Address Format: DIR:X:X:X:EP3:EP2:EP1:EP0 -This is used in the descriptors. +This is used in the descriptors. ********************************************************************/ #define _EP_IN 0x80 #define _EP_OUT 0x00 diff --git a/inc/usb_common.h b/inc/usb_common.h index bc38906..6200173 100644 --- a/inc/usb_common.h +++ b/inc/usb_common.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -213,110 +213,110 @@ typedef enum EVENT_HOST_STACK_BASE = 100, // A USB hub has been attached. Hub support is not currently available. - EVENT_HUB_ATTACH, - + EVENT_HUB_ATTACH, + // A stall has occurred. This event is not used by the Host stack. - EVENT_STALL, - + EVENT_STALL, + // VBus SRP Pulse, (VBus > 2.0v), Data: uint8_t Port Number (For future support) - EVENT_VBUS_SES_REQUEST, - - // The voltage on Vbus has dropped below 4.4V/4.7V. The application is + EVENT_VBUS_SES_REQUEST, + + // The voltage on Vbus has dropped below 4.4V/4.7V. The application is // responsible for monitoring Vbus and calling USBHostVbusEvent() with this // event. This event is not generated by the stack. - EVENT_VBUS_OVERCURRENT, - + EVENT_VBUS_OVERCURRENT, + // An enumerating device is requesting power. The data associated with this - // event is of the data type USB_VBUS_POWER_EVENT_DATA. Note that + // event is of the data type USB_VBUS_POWER_EVENT_DATA. Note that // the requested current is specified in 2mA units, identical to the power // specification in a device's Configuration Descriptor. - EVENT_VBUS_REQUEST_POWER, - + EVENT_VBUS_REQUEST_POWER, + // Release power from a detaching device. The data associated with this // event is of the data type USB_VBUS_POWER_EVENT_DATA. The current value // specified in the data can be ignored. - EVENT_VBUS_RELEASE_POWER, - - // The voltage on Vbus is good, and the USB OTG module can be powered on. - // The application is responsible for monitoring Vbus and calling - // USBHostVbusEvent() with this event. This event is not generated by the + EVENT_VBUS_RELEASE_POWER, + + // The voltage on Vbus is good, and the USB OTG module can be powered on. + // The application is responsible for monitoring Vbus and calling + // USBHostVbusEvent() with this event. This event is not generated by the // stack. If the application issues an EVENT_VBUS_OVERCURRENT, then no // power will be applied to that port, and no device can attach to that // port, until the application issues the EVENT_VBUS_POWER_AVAILABLE for // the port. - EVENT_VBUS_POWER_AVAILABLE, - + EVENT_VBUS_POWER_AVAILABLE, + // The attached device is not supported by the application. The attached // device is not allowed to enumerate. - EVENT_UNSUPPORTED_DEVICE, - + EVENT_UNSUPPORTED_DEVICE, + // Cannot enumerate the attached device. This is generated if communication // errors prevent the device from enumerating. - EVENT_CANNOT_ENUMERATE, - - // The client driver cannot initialize the the attached device. The + EVENT_CANNOT_ENUMERATE, + + // The client driver cannot initialize the the attached device. The // attached is not allowed to enumerate. - EVENT_CLIENT_INIT_ERROR, - + EVENT_CLIENT_INIT_ERROR, + // The Host stack does not have enough heap space to enumerate the device. // Check the amount of heap space allocated to the application. In MPLAB, // select Project> Build Options...> Project. Select the appropriate // linker tab, and inspect the "Heap size" entry. - EVENT_OUT_OF_MEMORY, - + EVENT_OUT_OF_MEMORY, + // Unspecified host error. (This error should not occur). - EVENT_UNSPECIFIED_ERROR, - + EVENT_UNSPECIFIED_ERROR, + // USB cable has been detached. The data associated with this event is the // address of detached device, a single uint8_t. - EVENT_DETACH, - + EVENT_DETACH, + // A USB transfer has completed. The data associated with this event is of // the data type HOST_TRANSFER_DATA if the event is generated from the host // stack. EVENT_TRANSFER, - + // A USB Start of Frame token has been received. This event is not // used by the Host stack. - EVENT_SOF, - + EVENT_SOF, + // Device-mode resume received. This event is not used by the Host stack. EVENT_RESUME, - + // Device-mode suspend/idle event received. This event is not used by the // Host stack. EVENT_SUSPEND, - - // Device-mode bus reset received. This event is not used by the Host - // stack. - EVENT_RESET, - + + // Device-mode bus reset received. This event is not used by the Host + // stack. + EVENT_RESET, + // In Host mode, an isochronous data read has completed. This event will only // be passed to the DataEventHandler, which is only utilized if it is defined. - // Note that the DataEventHandler is called from within the USB interrupt, so + // Note that the DataEventHandler is called from within the USB interrupt, so // it is critical that it return in time for the next isochronous data packet. EVENT_DATA_ISOC_READ, - + // In Host mode, an isochronous data write has completed. This event will only - // be passed to the DataEventHandler, which is only utilized if it is defined. - // Note that the DataEventHandler is called from within the USB interrupt, so + // be passed to the DataEventHandler, which is only utilized if it is defined. + // Note that the DataEventHandler is called from within the USB interrupt, so // it is critical that it return in time for the next isochronous data packet. EVENT_DATA_ISOC_WRITE, - + // In Host mode, this event gives the application layer the option to reject // a client driver that was selected by the stack. This is needed when multiple - // devices are supported by class level support, but one configuration and client + // devices are supported by class level support, but one configuration and client // driver is preferred over another. Since configuration number is not guaranteed, - // the stack cannot do this automatically. This event is issued only when - // looking through configuration descriptors; the driver selected at the device - // level cannot be overridden, since there shouldn't be any other options to + // the stack cannot do this automatically. This event is issued only when + // looking through configuration descriptors; the driver selected at the device + // level cannot be overridden, since there shouldn't be any other options to // choose from. EVENT_OVERRIDE_CLIENT_DRIVER_SELECTION, // In host mode, this event is thrown for every millisecond that passes. Like all // events, this is thrown from the USBHostTasks() or USBTasks() routine so its // timeliness will be determined by the rate that these functions are called. If - // they are not called very often, then the 1ms events will build up and be + // they are not called very often, then the 1ms events will build up and be // dispatched as the USBTasks() or USBHostTasks() functions are called (one event // per call to these functions. EVENT_1MS, @@ -327,7 +327,7 @@ typedef enum // up/down audio hardware. EVENT_ALT_INTERFACE, - // If the application layer must do things to the device before the device is + // If the application layer must do things to the device before the device is // configured, they should be done at this point. The application layer should // return true to hold the USB state machine at this point, while any USB or other // processing continues. When the USB state machine can safely proceed, the application @@ -342,19 +342,19 @@ typedef enum EVENT_HID_BASE = 600, // Offset for Human Interface Device class events EVENT_PRINTER_BASE = 700, // Offset for Printer class events - + EVENT_CDC_BASE = 800, // Offset for CDC class events EVENT_CHARGER_BASE = 900, // Offset for Charger client driver events. EVENT_AUDIO_BASE = 1000, // Offset for Audio client driver events. - + EVENT_USER_BASE = 10000, // Add integral values to this event number // to create user-defined events. // There was a transfer error on the USB. The data associated with this // event is of data type HOST_TRANSFER_DATA. - EVENT_BUS_ERROR = INT_MAX + EVENT_BUS_ERROR = INT_MAX } USB_EVENT; @@ -399,7 +399,7 @@ This data structure is passed to the application layer when a client driver is select, in case multiple client drivers can support a particular device. */ typedef struct _override_client_driver_data -{ +{ uint16_t idVendor; uint16_t idProduct; uint8_t bDeviceClass; @@ -438,26 +438,26 @@ stalled (ie. bit 0 = EP0, bit 1 = EP1, etc.) identified by the "event" parameter and may have associated data. If the higher layer was able to handle the event, it should return true. If not, it should return false. - + Preconditions: USBInitialize must have been called to initialize the USB SW Stack. - + Parameters: USB_EVENT event - Identifies the bus event that occurred void *data - Pointer to event-specific data unsigned int size - Size of the event-specific data - + Return Values: None - + Remarks: The function is name is defined by the layer that implements it. A pointer to the function will be placed by into a table that the lower-layer will use to call it. This requires the function to use a specific call "signature" (return data type and values and data parameter types and values). - + *******************************************************************************/ typedef bool (*USB_EVENT_HANDLER) ( USB_EVENT event, void *data, unsigned int size ); diff --git a/inc/usb_device.h b/inc/usb_device.h index 37593cd..389e6e2 100644 --- a/inc/usb_device.h +++ b/inc/usb_device.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -75,13 +75,13 @@ typedef enum /* Detached is the state in which the device is not attached to the bus. When in the detached state a device should not have any pull-ups attached to either the D+ or D- line. */ - DETACHED_STATE + DETACHED_STATE /*DOM-IGNORE-BEGIN*/ = 0x00 /*DOM-IGNORE-END*/, /* Attached is the state in which the device is attached ot the bus but the hub/port that it is attached to is not yet configured. */ ATTACHED_STATE /*DOM-IGNORE-BEGIN*/ = 0x01 /*DOM-IGNORE-END*/, - /* Powered is the state in which the device is attached to the bus and the + /* Powered is the state in which the device is attached to the bus and the hub/port that it is attached to is configured. */ POWERED_STATE /*DOM-IGNORE-BEGIN*/ = 0x02 /*DOM-IGNORE-END*/, @@ -90,7 +90,7 @@ typedef enum DEFAULT_STATE /*DOM-IGNORE-BEGIN*/ = 0x04 /*DOM-IGNORE-END*/, /* Address pending state is not an official state of the USB defined states. - This state is internally used to indicate that the device has received a + This state is internally used to indicate that the device has received a SET_ADDRESS command but has not received the STATUS stage of the transfer yet. The device is should not switch addresses until after the STATUS stage is complete. */ @@ -121,7 +121,7 @@ typedef enum EVENT_SET_DESCRIPTOR, // An endpoint 0 request was received that the stack did not know how to - // handle. This is most often a request for one of the class drivers. + // handle. This is most often a request for one of the class drivers. // Please refer to the class driver documentation for information related // to what to do if this request is received. (device) EVENT_EP0_REQUEST, @@ -130,22 +130,22 @@ typedef enum // // the data type HOST_TRANSFER_DATA if the event is generated from the host // // stack. // EVENT_TRANSFER, -// +// // // A USB Start of Frame token has been received. This event is not // // used by the Host stack. -// EVENT_SOF, -// +// EVENT_SOF, +// // // Device-mode resume received. This event is not used by the Host stack. // EVENT_RESUME, -// +// // // Device-mode suspend/idle event received. This event is not used by the // // Host stack. // EVENT_SUSPEND, -// -// // Device-mode bus reset received. This event is not used by the Host -// // stack. -// EVENT_RESET, - +// +// // Device-mode bus reset received. This event is not used by the Host +// // stack. +// EVENT_RESET, + // // Device Mode: A setup packet received (data: SETUP_PKT). This event is // // not used by the Host stack. // EVENT_SETUP, @@ -172,78 +172,78 @@ typedef enum /************************************************************************** Function: void USBDeviceInit(void) - + Description: This function initializes the device stack it in the default state. The USB module will be completely reset including all of the internal variables, registers, and interrupt flags. - + Precondition: This function must be called before any of the other USB Device functions can be called, including USBDeviceTasks(). - + Parameters: None - + Return Values: None - + Remarks: None - + **************************************************************************/ void USBDeviceInit(void); /************************************************************************** Function: void USBDeviceTasks(void) - + Summary: - This function is the main state machine/transaction handler of the USB - device side stack. When the USB stack is operated in "USB_POLLING" mode - (usb_config.h user option) the USBDeviceTasks() function should be called - periodically to receive and transmit packets through the stack. This - function also takes care of control transfers associated with the USB - enumeration process, and detecting various USB events (such as suspend). - This function should be called at least once every 1.8ms during the USB - enumeration process. After the enumeration process is complete (which can - be determined when USBGetDeviceState() returns CONFIGURED_STATE), the - USBDeviceTasks() handler may be called the faster of: either once - every 9.8ms, or as often as needed to make sure that the hardware USTAT + This function is the main state machine/transaction handler of the USB + device side stack. When the USB stack is operated in "USB_POLLING" mode + (usb_config.h user option) the USBDeviceTasks() function should be called + periodically to receive and transmit packets through the stack. This + function also takes care of control transfers associated with the USB + enumeration process, and detecting various USB events (such as suspend). + This function should be called at least once every 1.8ms during the USB + enumeration process. After the enumeration process is complete (which can + be determined when USBGetDeviceState() returns CONFIGURED_STATE), the + USBDeviceTasks() handler may be called the faster of: either once + every 9.8ms, or as often as needed to make sure that the hardware USTAT FIFO never gets full. A good rule of thumb is to call USBDeviceTasks() at - a minimum rate of either the frequency that USBTransferOnePacket() gets - called, or, once/1.8ms, whichever is faster. See the inline code comments - near the top of usb_device.c for more details about minimum timing + a minimum rate of either the frequency that USBTransferOnePacket() gets + called, or, once/1.8ms, whichever is faster. See the inline code comments + near the top of usb_device.c for more details about minimum timing requirements when calling USBDeviceTasks(). - + When the USB stack is operated in "USB_INTERRUPT" mode, it is not necessary to call USBDeviceTasks() from the main loop context. In the USB_INTERRUPT - mode, the USBDeviceTasks() handler only needs to execute when a USB - interrupt occurs, and therefore only needs to be called from the interrupt + mode, the USBDeviceTasks() handler only needs to execute when a USB + interrupt occurs, and therefore only needs to be called from the interrupt context. Description: - This function is the main state machine/transaction handler of the USB - device side stack. When the USB stack is operated in "USB_POLLING" mode - (usb_config.h user option) the USBDeviceTasks() function should be called - periodically to receive and transmit packets through the stack. This - function also takes care of control transfers associated with the USB - enumeration process, and detecting various USB events (such as suspend). - This function should be called at least once every 1.8ms during the USB - enumeration process. After the enumeration process is complete (which can - be determined when USBGetDeviceState() returns CONFIGURED_STATE), the - USBDeviceTasks() handler may be called the faster of: either once - every 9.8ms, or as often as needed to make sure that the hardware USTAT + This function is the main state machine/transaction handler of the USB + device side stack. When the USB stack is operated in "USB_POLLING" mode + (usb_config.h user option) the USBDeviceTasks() function should be called + periodically to receive and transmit packets through the stack. This + function also takes care of control transfers associated with the USB + enumeration process, and detecting various USB events (such as suspend). + This function should be called at least once every 1.8ms during the USB + enumeration process. After the enumeration process is complete (which can + be determined when USBGetDeviceState() returns CONFIGURED_STATE), the + USBDeviceTasks() handler may be called the faster of: either once + every 9.8ms, or as often as needed to make sure that the hardware USTAT FIFO never gets full. A good rule of thumb is to call USBDeviceTasks() at - a minimum rate of either the frequency that USBTransferOnePacket() gets - called, or, once/1.8ms, whichever is faster. See the inline code comments - near the top of usb_device.c for more details about minimum timing + a minimum rate of either the frequency that USBTransferOnePacket() gets + called, or, once/1.8ms, whichever is faster. See the inline code comments + near the top of usb_device.c for more details about minimum timing requirements when calling USBDeviceTasks(). - + When the USB stack is operated in "USB_INTERRUPT" mode, it is not necessary to call USBDeviceTasks() from the main loop context. In the USB_INTERRUPT - mode, the USBDeviceTasks() handler only needs to execute when a USB - interrupt occurs, and therefore only needs to be called from the interrupt + mode, the USBDeviceTasks() handler only needs to execute when a USB + interrupt occurs, and therefore only needs to be called from the interrupt context. Typical usage: @@ -263,7 +263,7 @@ void USBDeviceInit(void); } else { - //Otherwise we are free to run USB and non-USB related user + //Otherwise we are free to run USB and non-USB related user //application code. UserApplication(); } @@ -275,25 +275,25 @@ void USBDeviceInit(void); Make sure the USBDeviceInit() function has been called prior to calling USBDeviceTasks() for the first time. Remarks: - USBDeviceTasks() does not need to be called while in the USB suspend mode, + USBDeviceTasks() does not need to be called while in the USB suspend mode, if the user application firmware in the USBCBSuspend() callback function - enables the ACTVIF USB interrupt source and put the microcontroller into - sleep mode. If the application firmware decides not to sleep the - microcontroller core during USB suspend (ex: continues running at full + enables the ACTVIF USB interrupt source and put the microcontroller into + sleep mode. If the application firmware decides not to sleep the + microcontroller core during USB suspend (ex: continues running at full frequency, or clock switches to a lower frequency), then the USBDeviceTasks() - function must still be called periodically, at a rate frequent enough to + function must still be called periodically, at a rate frequent enough to ensure the 10ms resume recovery interval USB specification is met. Assuming - a worst case primary oscillator and PLL start up time of <5ms, then + a worst case primary oscillator and PLL start up time of <5ms, then USBDeviceTasks() should be called once every 5ms in this scenario. - - When the USB cable is detached, or the USB host is not actively powering - the VBUS line to +5V nominal, the application firmware does not always have - to call USBDeviceTasks() frequently, as no USB activity will be taking - place. However, if USBDeviceTasks() is not called regularly, some - alternative means of promptly detecting when VBUS is powered (indicating + + When the USB cable is detached, or the USB host is not actively powering + the VBUS line to +5V nominal, the application firmware does not always have + to call USBDeviceTasks() frequently, as no USB activity will be taking + place. However, if USBDeviceTasks() is not called regularly, some + alternative means of promptly detecting when VBUS is powered (indicating host attachment), or not powered (host powered down or USB cable unplugged) - is still needed. For self or dual self/bus powered USB applications, see - the USBDeviceAttach() and USBDeviceDetach() API documentation for additional + is still needed. For self or dual self/bus powered USB applications, see + the USBDeviceAttach() and USBDeviceDetach() API documentation for additional considerations. */ void USBDeviceTasks(void); @@ -302,14 +302,14 @@ void USBDeviceTasks(void); /******************************************************************************* Function: void USBEnableEndpoint(uint8_t ep, uint8_t options) - + Summary: This function will enable the specified endpoint with the specified options Description: This function will enable the specified endpoint with the specified options. - + Typical Usage: void USBCBInitEP(void) @@ -318,7 +318,7 @@ void USBDeviceTasks(void); USBMSDInit(); } - + In the above example endpoint number MSD_DATA_IN_EP is being configured for both IN and OUT traffic with handshaking enabled. Also since MSD_DATA_IN_EP is not endpoint 0 (MSD does not allow this), then we can @@ -346,7 +346,7 @@ void USBDeviceTasks(void); Return: None Remarks: - None + None *****************************************************************************/ void USBEnableEndpoint(uint8_t ep, uint8_t options); @@ -354,30 +354,30 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options); /************************************************************************* Function: USB_HANDLE USBTransferOnePacket(uint8_t ep, uint8_t dir, uint8_t* data, uint8_t len) - + Summary: Transfers a single packet (one transaction) of data on the USB bus. Description: The USBTransferOnePacket() function prepares a USB endpoint - so that it may send data to the host (an IN transaction), or - receive data from the host (an OUT transaction). The - USBTransferOnePacket() function can be used both to receive and - send data to the host. This function is the primary API function - provided by the USB stack firmware for sending or receiving application - data over the USB port. - - The USBTransferOnePacket() is intended for use with all application - endpoints. It is not used for sending or receiving application data - through endpoint 0 by using control transfers. Separate API + so that it may send data to the host (an IN transaction), or + receive data from the host (an OUT transaction). The + USBTransferOnePacket() function can be used both to receive and + send data to the host. This function is the primary API function + provided by the USB stack firmware for sending or receiving application + data over the USB port. + + The USBTransferOnePacket() is intended for use with all application + endpoints. It is not used for sending or receiving application data + through endpoint 0 by using control transfers. Separate API functions, such as USBEP0Receive(), USBEP0SendRAMPtr(), and USBEP0SendROMPtr() are provided for this purpose. The USBTransferOnePacket() writes to the Buffer Descriptor Table (BDT) - entry associated with an endpoint buffer, and sets the UOWN bit, which - prepares the USB hardware to allow the transaction to complete. The - application firmware can use the USBHandleBusy() macro to check the - status of the transaction, to see if the data has been successfully + entry associated with an endpoint buffer, and sets the UOWN bit, which + prepares the USB hardware to allow the transaction to complete. The + application firmware can use the USBHandleBusy() macro to check the + status of the transaction, to see if the data has been successfully transmitted yet. @@ -393,7 +393,7 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options); INPacket[0] = USEFUL_APPLICATION_VALUE1; INPacket[1] = USEFUL_APPLICATION_VALUE2; //INPacket[2] = ... (fill in the rest of the packet data) - + //Send the data contained in the INPacket[] array through endpoint "EP_NUM" USBInHandle = USBTransferOnePacket(EP_NUM,IN_TO_HOST,(uint8_t*)&INPacket[0],sizeof(INPacket)); } @@ -404,14 +404,14 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options); Before calling USBTransferOnePacket(), the following should be true. 1. The USB stack has already been initialized (USBDeviceInit() was called). 2. A transaction is not already pending on the specified endpoint. This - is done by checking the previous request using the USBHandleBusy() + is done by checking the previous request using the USBHandleBusy() macro (see the typical usage example). - 3. The host has already sent a set configuration request and the + 3. The host has already sent a set configuration request and the enumeration process is complete. - This can be checked by verifying that the USBGetDeviceState() - macro returns "CONFIGURED_STATE", prior to calling + This can be checked by verifying that the USBGetDeviceState() + macro returns "CONFIGURED_STATE", prior to calling USBTransferOnePacket(). - + Input: uint8_t ep - The endpoint number that the data will be transmitted or received on @@ -422,10 +422,10 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options); to the RAM buffer that the received data should get written to. uint8_t len - Length of the data needing to be sent (for IN transactions). For OUT transactions, the len parameter should normally be set - to the endpoint size specified in the endpoint descriptor. + to the endpoint size specified in the endpoint descriptor. Return Values: - USB_HANDLE - handle to the transfer. The handle is a pointer to + USB_HANDLE - handle to the transfer. The handle is a pointer to the BDT entry associated with this transaction. The status of the transaction (ex: if it is complete or still pending) can be checked using the USBHandleBusy() macro @@ -435,33 +435,33 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options); Remarks: If calling the USBTransferOnePacket() function from within the USBCBInitEP() callback function, the set configuration is still being processed and the - USBDeviceState may not be == CONFIGURED_STATE yet. In this special case, - the USBTransferOnePacket() may still be called, but make sure that the - endpoint has been enabled and initialized by the USBEnableEndpoint() - function first. - + USBDeviceState may not be == CONFIGURED_STATE yet. In this special case, + the USBTransferOnePacket() may still be called, but make sure that the + endpoint has been enabled and initialized by the USBEnableEndpoint() + function first. + *************************************************************************/ USB_HANDLE USBTransferOnePacket(uint8_t ep,uint8_t dir,uint8_t* data,uint8_t len); /******************************************************************** Function: void USBStallEndpoint(uint8_t ep, uint8_t dir) - + Summary: Configures the specified endpoint to send STALL to the host, the next time the host tries to access the endpoint. - + PreCondition: None - + Parameters: uint8_t ep - The endpoint number that should be configured to send STALL. uint8_t dir - The direction of the endpoint to STALL, either IN_TO_HOST or OUT_FROM_HOST. - + Return Values: None - + Remarks: None @@ -470,36 +470,36 @@ void USBStallEndpoint(uint8_t ep, uint8_t dir); /************************************************************************** Function: void USBCancelIO(uint8_t endpoint) - + Description: This function cancels the transfers pending on the specified endpoint. - This function can only be used after a SETUP packet is received and + This function can only be used after a SETUP packet is received and before that setup packet is handled. This is the time period in which the EVENT_EP0_REQUEST is thrown, before the event handler function returns to the stack. Precondition: - + Parameters: uint8_t endpoint - the endpoint number you wish to cancel the transfers for - + Return Values: None - + Remarks: None - + **************************************************************************/ void USBCancelIO(uint8_t endpoint); /************************************************************************** Function: void USBDeviceDetach(void) - + Summary: This function configures the USB module to "soft detach" itself from the USB host. - + Description: This function configures the USB module to perform a "soft detach" operation, by disabling the D+ (or D-) ~1.5k pull up resistor, which @@ -508,21 +508,21 @@ void USBCancelIO(uint8_t endpoint); useful, as it allows the USB device to force the host to re-enumerate the device (on the firmware has re-enabled the USB module/pull up, by calling USBDeviceAttach(), to "soft re-attach" to the host). - + Precondition: Should only be called when USB_INTERRUPT is defined. See remarks section if USB_POLLING mode option is being used (usb_config.h option). - Additionally, this function should only be called from the main() loop - context. Do not call this function from within an interrupt handler, as + Additionally, this function should only be called from the main() loop + context. Do not call this function from within an interrupt handler, as this function may modify global interrupt enable bits and settings. - + Parameters: None - + Return Values: None - + Remarks: If the application firmware calls USBDeviceDetach(), it is strongly recommended that the firmware wait at least >= 80ms before calling @@ -530,137 +530,137 @@ void USBCancelIO(uint8_t endpoint); re-attaches too soon (ex: after a few micro seconds for instance), some hosts may interpret this as an unexpected "glitch" rather than as a physical removal/re-attachment of the USB device. In this case the host - may simply ignore the event without re-enumerating the device. To + may simply ignore the event without re-enumerating the device. To ensure that the host properly detects and processes the device soft - detach/re-attach, it is recommended to make sure the device remains - detached long enough to mimic a real human controlled USB + detach/re-attach, it is recommended to make sure the device remains + detached long enough to mimic a real human controlled USB unplug/re-attach event (ex: after calling USBDeviceDetach(), do not call USBDeviceAttach() for at least 80+ms, preferably longer. - + Neither the USBDeviceDetach() or USBDeviceAttach() functions are blocking - or take long to execute. It is the application firmwares - responsibility for adding the 80+ms delay, when using these API + or take long to execute. It is the application firmwares + responsibility for adding the 80+ms delay, when using these API functions. - - Note: The Windows plug and play event handler processing is fairly + + Note: The Windows plug and play event handler processing is fairly slow, especially in certain versions of Windows, and for certain USB device classes. It has been observed that some device classes need to - provide even more USB detach dwell interval (before calling + provide even more USB detach dwell interval (before calling USBDeviceAttach()), in order to work correctly after re-enumeration. If the USB device is a CDC class device, it is recommended to wait at least 1.5 seconds or longer, before soft re-attaching to the host, - to provide the plug and play event handler enough time to finish + to provide the plug and play event handler enough time to finish processing the removal event, before the re-attach occurs. - - If the application is using the USB_POLLING mode option, then the - USBDeviceDetach() and USBDeviceAttach() functions are not available. - In this mode, the USB stack relies on the "#define USE_USB_BUS_SENSE_IO" - and "#define USB_BUS_SENSE" options in the - HardwareProfile � [platform name].h file. - - When using the USB_POLLING mode option, and the - "#define USE_USB_BUS_SENSE_IO" definition has been commented out, then - the USB stack assumes that it should always enable the USB module at - pretty much all times. Basically, anytime the application firmware - calls USBDeviceTasks(), the firmware will automatically enable the USB - module. This mode would typically be selected if the application was - designed to be a purely bus powered device. In this case, the - application is powered from the +5V VBUS supply from the USB port, so - it is correct and sensible in this type of application to power up and - turn on the USB module, at anytime that the microcontroller is - powered (which implies the USB cable is attached and the host is also + + If the application is using the USB_POLLING mode option, then the + USBDeviceDetach() and USBDeviceAttach() functions are not available. + In this mode, the USB stack relies on the "#define USE_USB_BUS_SENSE_IO" + and "#define USB_BUS_SENSE" options in the + HardwareProfile � [platform name].h file. + + When using the USB_POLLING mode option, and the + "#define USE_USB_BUS_SENSE_IO" definition has been commented out, then + the USB stack assumes that it should always enable the USB module at + pretty much all times. Basically, anytime the application firmware + calls USBDeviceTasks(), the firmware will automatically enable the USB + module. This mode would typically be selected if the application was + designed to be a purely bus powered device. In this case, the + application is powered from the +5V VBUS supply from the USB port, so + it is correct and sensible in this type of application to power up and + turn on the USB module, at anytime that the microcontroller is + powered (which implies the USB cable is attached and the host is also powered). - In a self powered application, the USB stack is designed with the - intention that the user will enable the "#define USE_USB_BUS_SENSE_IO" - option in the HardwareProfile � [platform name].h file. When this - option is defined, then the USBDeviceTasks() function will automatically - check the I/O pin port value of the designated pin (based on the - #define USB_BUS_SENSE option in the HardwareProfile � [platform name].h - file), every time the application calls USBDeviceTasks(). If the - USBDeviceTasks() function is executed and finds that the pin defined by - the #define USB_BUS_SENSE is in a logic low state, then it will - automatically disable the USB module and tri-state the D+ and D- pins. - If however the USBDeviceTasks() function is executed and finds the pin - defined by the #define USB_BUS_SENSE is in a logic high state, then it - will automatically enable the USB module, if it has not already been - enabled. - + In a self powered application, the USB stack is designed with the + intention that the user will enable the "#define USE_USB_BUS_SENSE_IO" + option in the HardwareProfile � [platform name].h file. When this + option is defined, then the USBDeviceTasks() function will automatically + check the I/O pin port value of the designated pin (based on the + #define USB_BUS_SENSE option in the HardwareProfile � [platform name].h + file), every time the application calls USBDeviceTasks(). If the + USBDeviceTasks() function is executed and finds that the pin defined by + the #define USB_BUS_SENSE is in a logic low state, then it will + automatically disable the USB module and tri-state the D+ and D- pins. + If however the USBDeviceTasks() function is executed and finds the pin + defined by the #define USB_BUS_SENSE is in a logic high state, then it + will automatically enable the USB module, if it has not already been + enabled. + **************************************************************************/ void USBDeviceDetach(void); /*DOM-IGNORE-BEGIN*/ #if !defined(USB_INTERRUPT) - #define USBDeviceDetach() + #define USBDeviceDetach() #endif /*DOM-IGNORE-END*/ /************************************************************************** Function: void USBDeviceAttach(void) - + Summary: - Checks if VBUS is present, and that the USB module is not already - initalized, and if so, enables the USB module so as to signal device - attachment to the USB host. + Checks if VBUS is present, and that the USB module is not already + initalized, and if so, enables the USB module so as to signal device + attachment to the USB host. Description: This function indicates to the USB host that the USB device has been attached to the bus. This function needs to be called in order for the device to start to enumerate on the bus. - + Precondition: - Should only be called when USB_INTERRUPT is defined. Also, should only + Should only be called when USB_INTERRUPT is defined. Also, should only be called from the main() loop context. Do not call USBDeviceAttach() from within an interrupt handler, as the USBDeviceAttach() function may modify global interrupt enable bits and settings. For normal USB devices: - Make sure that if the module was previously on, that it has been turned off + Make sure that if the module was previously on, that it has been turned off for a long time (ex: 100ms+) before calling this function to re-enable the module. If the device turns off the D+ (for full speed) or D- (for low speed) ~1.5k ohm - pull up resistor, and then turns it back on very quickly, common hosts will sometimes - reject this event, since no human could ever unplug and re-attach a USB device in a - microseconds (or nanoseconds) timescale. The host could simply treat this as some kind - of glitch and ignore the event altogether. + pull up resistor, and then turns it back on very quickly, common hosts will sometimes + reject this event, since no human could ever unplug and re-attach a USB device in a + microseconds (or nanoseconds) timescale. The host could simply treat this as some kind + of glitch and ignore the event altogether. Parameters: None - + Return Values: - None - - Remarks: - See also the USBDeviceDetach() API function documentation. + None + + Remarks: + See also the USBDeviceDetach() API function documentation. ****************************************************************************/ void USBDeviceAttach(void); /*DOM-IGNORE-BEGIN*/ #if !defined(USB_INTERRUPT) - #define USBDeviceAttach() + #define USBDeviceAttach() #endif /*DOM-IGNORE-END*/ /******************************************************************************* Function: void USBCtrlEPAllowStatusStage(void); - - Summary: This function prepares the proper endpoint 0 IN or endpoint 0 OUT + + Summary: This function prepares the proper endpoint 0 IN or endpoint 0 OUT (based on the controlTransferState) to allow the status stage packet - of a control transfer to complete. This function gets used + of a control transfer to complete. This function gets used internally by the USB stack itself, but it may also be called from the application firmware, IF the application firmware called the USBDeferStatusStage() function during the initial processing of the control transfer request. In this case, the application must call the USBCtrlEPAllowStatusStage() once, after it has fully completed processing and handling the data stage portion of the - request. - - If the application firmware has no need for delaying control + request. + + If the application firmware has no need for delaying control transfers, and therefore never calls USBDeferStatusStage(), then the application firmware should not call USBCtrlEPAllowStatusStage(). - + Description: - + Conditions: None @@ -669,7 +669,7 @@ void USBDeviceAttach(void); Return: Remarks: - None + None *****************************************************************************/ void USBCtrlEPAllowStatusStage(void); @@ -677,21 +677,21 @@ void USBCtrlEPAllowStatusStage(void); /******************************************************************************* Function: void USBCtrlEPAllowDataStage(void); - + Summary: This function allows the data stage of either a host-to-device or device-to-host control transfer (with data stage) to complete. This function is meant to be used in conjunction with either the USBDeferOUTDataStage() or USBDeferINDataStage(). If the firmware does not call either USBDeferOUTDataStage() or USBDeferINDataStage(), - then the firmware does not need to manually call + then the firmware does not need to manually call USBCtrlEPAllowDataStage(), as the USB stack will call this function instead. - + Description: - - Conditions: A control transfer (with data stage) should already be pending, + + Conditions: A control transfer (with data stage) should already be pending, if the firmware calls this function. Additionally, the firmware - should have called either USBDeferOUTDataStage() or + should have called either USBDeferOUTDataStage() or USBDeferINDataStage() at the start of the control transfer, if the firmware will be calling this function manually. @@ -699,14 +699,14 @@ void USBCtrlEPAllowStatusStage(void); Return: - Remarks: + Remarks: *****************************************************************************/ void USBCtrlEPAllowDataStage(void); /******************************************************************************* Function: void USBDeferOUTDataStage(void); - + Summary: This function will cause the USB hardware to continuously NAK the OUT data packets sent from the host, during the data stage of a device to host control transfer. This allows the firmware more time @@ -714,45 +714,45 @@ void USBCtrlEPAllowDataStage(void); data from the host. This is also useful, if the firmware wishes to receive the OUT data in a different context than what the USBDeviceTasks() function executes at. - + Calling this function (macro) will assert ownership of the currently pending control transfer. Therefore, the USB stack will not STALL when it reaches the data stage of the control transfer, even if the - firmware has not (yet) called the USBEP0Receive() API function. - However, the application firmware must still (eventually, once it is + firmware has not (yet) called the USBEP0Receive() API function. + However, the application firmware must still (eventually, once it is ready) call one of the aforementioned API function. - + Example Usage: - - 1. Host sends a SETUP packet to the device, requesting a host to + + 1. Host sends a SETUP packet to the device, requesting a host to device control transfer, with data stage (OUT data packets). 2. USBDeviceTasks() executes, and then calls the USBCBCheckOtherReq() callback event handler. The USBCBCheckOtherReq() calls the application specific/device class specific handler that detects the type of control transfer. - 3. If the firmware needs more time before it wishes to receive the - first OUT data packet, or, if the firmware wishes to process the - command in a different context, then it may call - USBDeferOUTDataStage(), in the context of the + 3. If the firmware needs more time before it wishes to receive the + first OUT data packet, or, if the firmware wishes to process the + command in a different context, then it may call + USBDeferOUTDataStage(), in the context of the USBCBCheckOtherReq() handler function. 4. If the firmware called USBDeferOUTDataStage() in step #3 above, then the hardware will NAK the OUT data packets sent by the host, for the OUT data stage. - 5. Once the firmware is ready, it should then call USBEP0Receive(), + 5. Once the firmware is ready, it should then call USBEP0Receive(), to prepare the USB stack to receive the OUT data from the host, and to write it to the user specified buffer. 6. The firmware should now call USBCtrlEPAllowDataStage(). This will allow the data stage to complete. Once all OUT data has been received, the user callback function (provided by the function pointer provided when calling USBEP0Receive()) will - get called. - 7. Once all data has been received from the host, the status stage - (a 0-byte IN packet) will complete automatically (assuming the + get called. + 7. Once all data has been received from the host, the status stage + (a 0-byte IN packet) will complete automatically (assuming the firmware did not call USBDeferStatusStage() during step #3). - - + + Description: - + Conditions: Before calling USBDeferOUTDataStage(), the firmware should first verify that the control transfer has a data stage, and that it is of type host-to-device (OUT). @@ -764,16 +764,16 @@ void USBCtrlEPAllowDataStage(void); Remarks: Section 9.2.6 of the official USB 2.0 specifications indicates that the USB device must be able to receive all bytes and complete the control transfer within a maximum of 5 seconds. - + If the firmware calls USBDeferOUTDataStage(), it must eventually call - USBEP0Receive(), and then call USBCtrlEPAllowDataStage(). If it does + USBEP0Receive(), and then call USBCtrlEPAllowDataStage(). If it does not do this, the control transfer will never be able to complete. This will break the USB connection, as the host needs to be able to - communicate over EP0, in order to perform basic tasks including - enumeration. - - The firmware should never call both USBDeferINDataStage() and - USBDeferOUTDataStage() during the same control transfer. These + communicate over EP0, in order to perform basic tasks including + enumeration. + + The firmware should never call both USBDeferINDataStage() and + USBDeferOUTDataStage() during the same control transfer. These functions are mutually exclusive (a control transfer with data stage can never contain both IN and OUT data packets during the data stage). *****************************************************************************/ @@ -785,15 +785,15 @@ extern volatile bool USBDeferOUTDataStagePackets; /******************************************************************************* Function: void USBDeferStatusStage(void); - + Summary: Calling this function will prevent the USB stack from automatically enabling the status stage for the currently pending control transfer - from completing immediately after all data bytes have been sent or - received. This is useful if a class handler or USB application - firmware project uses control transfers for sending/receiving data - over EP0, but requires time in order to finish processing and/or to + from completing immediately after all data bytes have been sent or + received. This is useful if a class handler or USB application + firmware project uses control transfers for sending/receiving data + over EP0, but requires time in order to finish processing and/or to consume the data. - + For example: Consider an application which receives OUT data from the USB host, through EP0 using control transfers. Now assume that this application wishes to do something time consuming with this data (ex: @@ -801,36 +801,36 @@ extern volatile bool USBDeferOUTDataStagePackets; via SPI/I2C/etc.). In this case, it would typically be desirable to defer allowing the USB status stage of the control transfer to complete, until after the data has been fully sent to the EEPconst device and saved. - + If the USB class handler firmware that processes the control transfer SETUP packet determines that it will need extra time to complete the control transfer, it may optionally call USBDeferStatusStage(). If it does so, it is then the responsibility of the application firmware to eventually call USBCtrlEPAllowStatusStage(), once the firmware has finished processing the data associated with the control transfer. - - If the firmware call USBDeferStatusStage(), but never calls + + If the firmware call USBDeferStatusStage(), but never calls USBCtrlEPAllowStatusStage(), then one of two possibilities will occur. - + 1. If the "USB_ENABLE_STATUS_STAGE_TIMEOUTS" option is commented in usb_config.h, then the status stage of the control transfer will never be able to complete. This is an error case and should be avoided. - 2. If the "USB_ENABLE_STATUS_STAGE_TIMEOUTS" option is enabled in - usb_config.h, then the USBDeviceTasks() function will - automatically call USBCtrlEPAllowStatusStage(), after the + 2. If the "USB_ENABLE_STATUS_STAGE_TIMEOUTS" option is enabled in + usb_config.h, then the USBDeviceTasks() function will + automatically call USBCtrlEPAllowStatusStage(), after the "USB_STATUS_STAGE_TIMEOUT" has elapsed, since the last quanta of - "progress" has occurred in the control transfer. Progress is + "progress" has occurred in the control transfer. Progress is defined as the last successful transaction completing on EP0 IN or EP0 OUT. Although the timeouts feature allows the status stage to - [eventually] complete, it is still preferable to manually call + [eventually] complete, it is still preferable to manually call USBCtrlEPAllowStatusStage() after the application firmware has finished processing/consuming the control transfer data, as this will allow for much faster processing of control transfers, and therefore much higher data rates and better user responsiveness. Description: - + Conditions: None @@ -845,7 +845,7 @@ extern volatile bool USBDeferOUTDataStagePackets; would be from within the USBCBCheckOtherReq() handler context. For example, in a HID application using control transfers, the USBDeferStatusStage() function would be called from within the - USER_GET_REPORT_HANDLER or USER_SET_REPORT_HANDLER functions. + USER_GET_REPORT_HANDLER or USER_SET_REPORT_HANDLER functions. *****************************************************************************/ void USBDeferStatusStage(void); extern volatile bool USBDeferStatusStagePacket; @@ -856,20 +856,20 @@ extern volatile bool USBDeferStatusStagePacket; /******************************************************************************* Function: bool USBOUTDataStageDeferred(void); - + Summary: Returns true if a control transfer with OUT data stage is pending, and the firmware has called USBDeferOUTDataStage(), but has not yet called USBCtrlEPAllowDataStage(). Returns false if a control transfer with OUT data stage is either not pending, or the firmware did not call USBDeferOUTDataStage() at the start of the control transfer. - + This function (macro) would typically be used in the case where the USBDeviceTasks() function executes in the interrupt context (ex: USB_INTERRUPT option selected in usb_config.h), but the firmware wishes to take care of handling the data stage of the control transfer - in the main loop context. - + in the main loop context. + In this scenario, typical usage would be: 1. Host starts a control transfer with OUT data stage. 2. USBDeviceTasks() (in this scenario, interrupt context) executes. @@ -879,8 +879,8 @@ extern volatile bool USBDeferStatusStagePacket; 4. The user code in USBCBCheckOtherReq() (also in interrupt context, since it is called from USBDeviceTasks(), and therefore executes at the same priority/context) calls USBDeferOUTDataStage(). - - 5. Meanwhile, in the main loop context, a polling handler may be + + 5. Meanwhile, in the main loop context, a polling handler may be periodically checking if(USBOUTDataStageDeferred() == true). Ordinarily, it would evaluate false, but when a control transfer becomes pending, and after the USBDeferOUTDataStage() macro has @@ -888,16 +888,16 @@ extern volatile bool USBDeferStatusStagePacket; will evaluate true. In this case, the main loop context can then take care of receiving the data, by calling USBEP0Receive() and USBCtrlEPAllowDataStage(). - + Description: - - Conditions: + + Conditions: Input: Return: - Remarks: + Remarks: *****************************************************************************/ bool USBOUTDataStageDeferred(void); /*DOM-IGNORE-BEGIN*/ @@ -906,7 +906,7 @@ bool USBOUTDataStageDeferred(void); /******************************************************************************* Function: void USBDeferINDataStage(void); - + Summary: This function will cause the USB hardware to continuously NAK the IN token packets sent from the host, during the data stage of a device to host control transfer. This allows the firmware more time @@ -914,18 +914,18 @@ bool USBOUTDataStageDeferred(void); sent to the host. This is also useful, if the firmware needs to process/prepare the IN data in a different context than what the USBDeviceTasks() function executes at. - + Calling this function (macro) will assert ownership of the currently pending control transfer. Therefore, the USB stack will not STALL when it reaches the data stage of the control transfer, even if the - firmware has not (yet) called the USBEP0SendRAMPtr() or + firmware has not (yet) called the USBEP0SendRAMPtr() or USBEP0SendROMPtr() API function. However, the application firmware - must still (eventually, once it is ready) call one of the + must still (eventually, once it is ready) call one of the aforementioned API functions. - + Example Usage: - - 1. Host sends a SETUP packet to the device, requesting a device to + + 1. Host sends a SETUP packet to the device, requesting a device to host control transfer, with data stage. 2. USBDeviceTasks() executes, and then calls the USBCBCheckOtherReq() callback event handler. The USBCBCheckOtherReq() calls the @@ -947,16 +947,16 @@ bool USBOUTDataStageDeferred(void); bytes to send to the host, and from what source location. 6. The firmware should now call USBCtrlEPAllowDataStage(). This will allow the data stage to complete. The USB stack will send - the data buffer specified by the USBEP0SendRAMPtr() or + the data buffer specified by the USBEP0SendRAMPtr() or USBEP0SendROMPtr() function, when it was called. 7. Once all data has been sent to the host, or if the host performs early termination, the status stage (a 0-byte OUT packet) will complete automatically (assuming the firmware did not call USBDeferStatusStage() during step #3). - - + + Description: - + Conditions: Before calling USBDeferINDataStage(), the firmware should first verify that the control transfer has a data stage, and that it is of type device-to-host (IN). @@ -970,15 +970,15 @@ bool USBOUTDataStageDeferred(void); of the start of the control transfer. In order to meet this specification, the firmware must call USBEP0SendRAMPtr() or USBEP0SendROMPtr(), and then call USBCtrlEPAllowDataStage(), in - less than 500ms from the start of the control transfer. - + less than 500ms from the start of the control transfer. + If the firmware calls USBDeferINDataStage(), it must eventually call USBEP0SendRAMPtr() or USBEP0SendROMPtr(), and then call USBCtrlEPAllowDataStage(). If it does not do this, the control transfer will never be able to complete. - - The firmware should never call both USBDeferINDataStage() and - USBDeferOUTDataStage() during the same control transfer. These + + The firmware should never call both USBDeferINDataStage() and + USBDeferOUTDataStage() during the same control transfer. These functions are mutually exclusive (a control transfer with data stage can never contain both IN and OUT data packets during the data stage). *****************************************************************************/ @@ -992,20 +992,20 @@ extern volatile bool USBDeferINDataStagePackets; /******************************************************************************* Function: bool USBINDataStageDeferred(void); - + Summary: Returns true if a control transfer with IN data stage is pending, and the firmware has called USBDeferINDataStage(), but has not yet called USBCtrlEPAllowDataStage(). Returns false if a control transfer with IN data stage is either not pending, or the firmware did not call USBDeferINDataStage() at the start of the control transfer. - + This function (macro) would typically be used in the case where the USBDeviceTasks() function executes in the interrupt context (ex: USB_INTERRUPT option selected in usb_config.h), but the firmware wishes to take care of handling the data stage of the control transfer - in the main loop context. - + in the main loop context. + In this scenario, typical usage would be: 1. Host starts a control transfer with IN data stage. 2. USBDeviceTasks() (in this scenario, interrupt context) executes. @@ -1015,26 +1015,26 @@ extern volatile bool USBDeferINDataStagePackets; 4. The user code in USBCBCheckOtherReq() (also in interrupt context, since it is called from USBDeviceTasks(), and therefore executes at the same priority/context) calls USBDeferINDataStage(). - - 5. Meanwhile, in the main loop context, a polling handler may be + + 5. Meanwhile, in the main loop context, a polling handler may be periodically checking if(USBINDataStageDeferred() == true). Ordinarily, it would evaluate false, but when a control transfer becomes pending, and after the USBDeferINDataStage() macro has been called (ex: in the interrupt context), the if() statement will evaluate true. In this case, the main loop context can then - take care of sending the data (when ready), by calling + take care of sending the data (when ready), by calling USBEP0SendRAMPtr() or USBEP0SendROMPtr() and USBCtrlEPAllowDataStage(). - + Description: - - Conditions: + + Conditions: Input: Return: - Remarks: + Remarks: *****************************************************************************/ bool USBINDataStageDeferred(void); /*DOM-IGNORE-BEGIN*/ @@ -1046,7 +1046,7 @@ bool USBINDataStageDeferred(void); /******************************************************************** Function: bool USBGetRemoteWakeupStatus(void) - + Summary: This function indicates if remote wakeup has been enabled by the host. Devices that support remote wakeup should use this function to @@ -1056,19 +1056,19 @@ bool USBINDataStageDeferred(void); This function indicates if remote wakeup has been enabled by the host. Devices that support remote wakeup should use this function to determine if it should send a remote wakeup. - + If a device does not support remote wakeup (the Remote wakeup bit, bit 5, of the bmAttributes field of the Configuration descriptor is set to 1), then it should not send a remote wakeup command to the PC and this function is not of any use to the device. If a device does support remote wakeup then it should use this function as described below. - + If this function returns false and the device is suspended, it should not issue a remote wakeup (resume). - + If this function returns true and the device is suspended, it should issue a remote wakeup (resume). - + A device can add remote wakeup support by having the _RWU symbol added in the configuration descriptor (located in the usb_descriptors.c file in the project). This done in the 8th byte of the configuration @@ -1076,23 +1076,23 @@ bool USBINDataStageDeferred(void); const uint8_t configDescriptor1[]={ - 0x09, // Size - USB_DESCRIPTOR_CONFIGURATION, // descriptor type + 0x09, // Size + USB_DESCRIPTOR_CONFIGURATION, // descriptor type DESC_CONFIG_WORD(0x0022), // Total length - 1, // Number of interfaces - 1, // Index value of this cfg - 0, // Configuration string index - _DEFAULT | _SELF | _RWU, // Attributes, see usb_device.h + 1, // Number of interfaces + 1, // Index value of this cfg + 0, // Configuration string index + _DEFAULT | _SELF | _RWU, // Attributes, see usb_device.h 50, // Max power consumption in 2X mA(100mA) - + //The rest of the configuration descriptor should follow For more information about remote wakeup, see the following section of - the USB v2.0 specification available at www.usb.org: + the USB v2.0 specification available at www.usb.org: * Section 9.2.5.2 - * Table 9-10 - * Section 7.1.7.7 + * Table 9-10 + * Section 7.1.7.7 * Section 9.4.5 Conditions: @@ -1104,7 +1104,7 @@ bool USBINDataStageDeferred(void); Remarks: None - + *******************************************************************/ bool USBGetRemoteWakeupStatus(void); /*DOM-IGNORE-BEGIN*/ @@ -1114,7 +1114,7 @@ bool USBGetRemoteWakeupStatus(void); /*************************************************************************** Function: USB_DEVICE_STATE USBGetDeviceState(void) - + Summary: This function will return the current state of the device on the USB. This function should return CONFIGURED_STATE before an application @@ -1124,14 +1124,14 @@ bool USBGetRemoteWakeupStatus(void); \function is used to determine when the device is ready to communicate on the bus. Applications should not try to send or receive data until this function returns CONFIGURED_STATE. - + It is also important that applications yield as much time as possible to the USBDeviceTasks() function as possible while the this function \returns any value between ATTACHED_STATE through CONFIGURED_STATE. - + For more information about the various device states, please refer to the USB specification section 9.1 available from www.usb.org. - + Typical usage: void main(void) @@ -1161,7 +1161,7 @@ bool USBGetRemoteWakeupStatus(void); USB_DEVICE_STATE - the current state of the device on the bus Remarks: - None + None ***************************************************************************/ USB_DEVICE_STATE USBGetDeviceState(void); /*DOM-IGNORE-BEGIN*/ @@ -1173,21 +1173,21 @@ USB_DEVICE_STATE USBGetDeviceState(void); /*************************************************************************** Function: bool USBGetSuspendState(void) - + Summary: - This function indicates if the USB port that this device is attached to is - currently suspended. When suspended, it will not be able to transfer data + This function indicates if the USB port that this device is attached to is + currently suspended. When suspended, it will not be able to transfer data over the bus. Description: - This function indicates if the USB port that this device is attached to is - currently suspended. When suspended, it will not be able to transfer data + This function indicates if the USB port that this device is attached to is + currently suspended. When suspended, it will not be able to transfer data over the bus. This function can be used by the application to skip over section of code that do not need to execute if the device is unable to send data - over the bus. This function can also be used to help determine when it is + over the bus. This function can also be used to help determine when it is legal to perform USB remote wakeup signaling, for devices supporting this - feature. - + feature. + Typical usage: void main(void) @@ -1217,7 +1217,7 @@ USB_DEVICE_STATE USBGetDeviceState(void); true - the USB port this device is attached to is suspended. false - the USB port this device is attached to is not suspended. Remarks: - This function is the same as USBIsBusSuspended(). + This function is the same as USBIsBusSuspended(). ***************************************************************************/ bool USBGetSuspendState(void); /*DOM-IGNORE-BEGIN*/ @@ -1227,7 +1227,7 @@ bool USBGetSuspendState(void); /******************************************************************************* Function: bool USBIsDeviceSuspended(void) - + Summary: This function indicates if the USB module is in suspend mode. @@ -1235,7 +1235,7 @@ bool USBGetSuspendState(void); This function indicates if the USB module is in suspend mode. This function does NOT indicate that a suspend request has been received. It only reflects the state of the USB module. - + Typical Usage: if(USBIsDeviceSuspended() == true) @@ -1244,7 +1244,7 @@ bool USBGetSuspendState(void); } // otherwise do some application specific tasks - + Conditions: None Input: @@ -1252,18 +1252,18 @@ bool USBGetSuspendState(void); Return: None Remarks: - None + None *****************************************************************************/ bool USBIsDeviceSuspended(void); /*DOM-IGNORE-BEGIN*/ -#define USBIsDeviceSuspended() USBSuspendControl +#define USBIsDeviceSuspended() USBSuspendControl /*DOM-IGNORE-END*/ /******************************************************************************* Function: bool USBIsBusSuspended(void); - + Summary: This function indicates if the USB bus is in suspend mode. @@ -1271,7 +1271,7 @@ bool USBIsDeviceSuspended(void); This function indicates if the USB bus is in suspend mode. This function is typically used for checking if the conditions are consistent with performing a USB remote wakeup sequence. - + Typical Usage: if((USBIsBusSuspended() == true) && (USBGetRemoteWakeupStatus() == true)) @@ -1284,7 +1284,7 @@ bool USBIsDeviceSuspended(void); } // otherwise do some other application specific tasks - + Conditions: None Input: @@ -1292,7 +1292,7 @@ bool USBIsDeviceSuspended(void); Return: None Remarks: - The USBIsBusSuspended() function relies on the USBBusIsSuspended boolean + The USBIsBusSuspended() function relies on the USBBusIsSuspended boolean variable, which gets updated by the USBDeviceTasks() function. Therefore, in order to be sure the return value is not "stale", it is suggested to make sure USBDeviceTasks() has executed recently (if using USB polling mode). @@ -1305,13 +1305,13 @@ bool USBIsBusSuspended(void); /******************************************************************************* Function: void USBSoftDetach(void); - + Summary: This function performs a detach from the USB bus via software. Description: This function performs a detach from the USB bus via software. - + Conditions: None Input: @@ -1319,9 +1319,9 @@ bool USBIsBusSuspended(void); Return: None Remarks: - Caution should be used when detaching from the bus. Some PC drivers and - programs may require additional time after a detach before a device can be - reattached to the bus. + Caution should be used when detaching from the bus. Some PC drivers and + programs may require additional time after a detach before a device can be + reattached to the bus. *****************************************************************************/ void USBSoftDetach(void); /*DOM-IGNORE-BEGIN*/ @@ -1332,7 +1332,7 @@ void USBSoftDetach(void); /************************************************************************* Function: bool USBHandleBusy(USB_HANDLE handle) - + Summary: Checks to see if the input handle is busy @@ -1359,7 +1359,7 @@ void USBSoftDetach(void); true - The specified handle is busy false - The specified handle is free and available for a transfer Remarks: - None + None *************************************************************************/ bool USBHandleBusy(USB_HANDLE handle); /*DOM-IGNORE-BEGIN*/ @@ -1373,31 +1373,31 @@ bool USBHandleBusy(USB_HANDLE handle); /******************************************************************** Function: uint16_t USBHandleGetLength(USB_HANDLE handle) - + Summary: Retrieves the length of the destination buffer of the input handle - + Description: Retrieves the length of the destination buffer of the input handle PreCondition: None - + Parameters: USB_HANDLE handle - the handle to the transfer you want the address for. - + Return Values: uint16_t - length of the current buffer that the input handle - points to. If the transfer is complete then this is the + points to. If the transfer is complete then this is the length of the data transmitted or the length of data actually received. - + Remarks: None - + *******************************************************************/ uint16_t USBHandleGetLength(USB_HANDLE handle); /*DOM-IGNORE-BEGIN*/ @@ -1407,29 +1407,29 @@ uint16_t USBHandleGetLength(USB_HANDLE handle); /******************************************************************** Function: uint16_t USBHandleGetAddr(USB_HANDLE) - + Summary: Retrieves the address of the destination buffer of the input handle - + Description: Retrieves the address of the destination buffer of the input handle PreCondition: None - + Parameters: USB_HANDLE handle - the handle to the transfer you want the address for. - + Return Values: uint16_t - address of the current buffer that the input handle points to. - + Remarks: None - + *******************************************************************/ uint16_t USBHandleGetAddr(USB_HANDLE); /*DOM-IGNORE-BEGIN*/ @@ -1441,14 +1441,14 @@ uint16_t USBHandleGetAddr(USB_HANDLE); Function: USB_HANDLE USBGetNextHandle(uint8_t ep_num, uint8_t ep_dir) Summary: - Retrieves the handle to the next endpoint BDT entry that the + Retrieves the handle to the next endpoint BDT entry that the USBTransferOnePacket() will use. Description: - Retrieves the handle to the next endpoint BDT that the + Retrieves the handle to the next endpoint BDT that the USBTransferOnePacket() will use. Useful for initialization and when ping pong buffering will be used on application endpoints. PreCondition: - Will return NULL if the USB device has not yet been configured/the + Will return NULL if the USB device has not yet been configured/the endpoint specified has not yet been initialized by USBEnableEndpoint(). Parameters: uint8_t ep_num - The endpoint number to get the handle for (valid @@ -1463,10 +1463,10 @@ uint16_t USBHandleGetAddr(USB_HANDLE); This API is useful for initializing USB_HANDLEs during initialization of the application firmware. It is also useful when ping-pong buffering is enabled, and the application firmware wishes to arm both the even and odd - BDTs for an endpoint simultaneously. In this case, the application - firmware for sending data to the host would typically be something like + BDTs for an endpoint simultaneously. In this case, the application + firmware for sending data to the host would typically be something like follows: - + USB_HANDLE Handle1; USB_HANDLE Handle2; @@ -1474,15 +1474,15 @@ uint16_t USBHandleGetAddr(USB_HANDLE); uint8_t UserDataBuffer1[64]; uint8_t UserDataBuffer2[64]; uint8_t* pDataBuffer = &UserDataBuffer1[0]; - - //Add some code that loads UserDataBuffer1[] with useful data to send, + + //Add some code that loads UserDataBuffer1[] with useful data to send, //using the pDataBuffer pointer, for example: //for(i = 0; i < 64; i++) //{ // *pDataBuffer++ = [useful data value]; //} - - //Check if the next USB endpoint BDT is available + + //Check if the next USB endpoint BDT is available if(!USBHandleBusy(USBGetNextHandle(ep_num, IN_TO_HOST)) { //The endpoint is available. Send the data. @@ -1499,19 +1499,19 @@ uint16_t USBHandleGetAddr(USB_HANDLE); pDataBuffer = &UserDataBuffer1[0]; } } - - //The firmware can then load the next data buffer (in this case - //UserDataBuffer2)with useful data, and send it using the same + + //The firmware can then load the next data buffer (in this case + //UserDataBuffer2)with useful data, and send it using the same //process. For example: - //Add some code that loads UserDataBuffer2[] with useful data to send, + //Add some code that loads UserDataBuffer2[] with useful data to send, //using the pDataBuffer pointer, for example: //for(i = 0; i < 64; i++) //{ // *pDataBuffer++ = [useful data value]; //} - - //Check if the next USB endpoint BDT is available + + //Check if the next USB endpoint BDT is available if(!USBHandleBusy(USBGetNextHandle(ep_num, IN_TO_HOST)) { //The endpoint is available. Send the data. @@ -1529,7 +1529,7 @@ uint16_t USBHandleGetAddr(USB_HANDLE); } } - + *******************************************************************/ USB_HANDLE USBGetNextHandle(uint8_t ep_num, uint8_t ep_dir); /*DOM-IGNORE-BEGIN*/ @@ -1539,14 +1539,14 @@ USB_HANDLE USBGetNextHandle(uint8_t ep_num, uint8_t ep_dir); /******************************************************************** Function: void USBEP0Transmit(uint8_t options) - + Summary: Sets the address of the data to send over the control endpoint - + PreCondition: None - + Parameters: options - the various options that you want when sending the control data. Options are: @@ -1556,13 +1556,13 @@ USB_HANDLE USBGetNextHandle(uint8_t ep_num, uint8_t ep_dir); USB_EP0_INCLUDE_ZERO USB_EP0_NO_DATA USB_EP0_NO_OPTIONS - + Return Values: None - + Remarks: None - + *******************************************************************/ void USBEP0Transmit(uint8_t options); /*DOM-IGNORE-BEGIN*/ @@ -1572,7 +1572,7 @@ void USBEP0Transmit(uint8_t options); /************************************************************************* Function: void USBEP0SendRAMPtr(uint8_t* src, uint16_t size, uint8_t Options) - + Summary: Sets the source, size, and options of the data you wish to send from a RAM source @@ -1590,7 +1590,7 @@ void USBEP0Transmit(uint8_t options); * USB_EP0_NO_DATA * USB_EP0_NO_OPTIONS Remarks: - None + None *************************************************************************/ void USBEP0SendRAMPtr(uint8_t* src, uint16_t size, uint8_t Options); /*DOM-IGNORE-BEGIN*/ @@ -1604,7 +1604,7 @@ void USBEP0SendRAMPtr(uint8_t* src, uint16_t size, uint8_t Options); /************************************************************************** Function: void USBEP0SendROMPtr(uint8_t* src, uint16_t size, uint8_t Options) - + Summary: Sets the source, size, and options of the data you wish to send from a const source @@ -1622,7 +1622,7 @@ void USBEP0SendRAMPtr(uint8_t* src, uint16_t size, uint8_t Options); * USB_EP0_NO_DATA * USB_EP0_NO_OPTIONS Remarks: - None + None **************************************************************************/ void USBEP0SendROMPtr(uint8_t* src, uint16_t size, uint8_t Options); /*DOM-IGNORE-BEGIN*/ @@ -1650,7 +1650,7 @@ void USBEP0SendROMPtr(uint8_t* src, uint16_t size, uint8_t Options); (*function) - a function that you want called once the data is received. If this is specified as NULL then no function is called. Remarks: - None + None ***************************************************************************/ void USBEP0Receive(uint8_t* dest, uint16_t size, void (*function)); /*DOM-IGNORE-BEGIN*/ @@ -1660,32 +1660,32 @@ void USBEP0Receive(uint8_t* dest, uint16_t size, void (*function)); /******************************************************************** Function: USB_HANDLE USBTxOnePacket(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Sends the specified data out the specified endpoint - + PreCondition: None - + Parameters: ep - the endpoint number you want to send the data out of - data - pointer to a user buffer that contains the data that you wish to + data - pointer to a user buffer that contains the data that you wish to send to the host. Note: This RAM buffer must be accessible by the USB module. len - the number of bytes of data that you wish to send to the host, in the next transaction on this endpoint. Note: this value should always be less than or equal to the endpoint size, as specified in the USB endpoint descriptor. - + Return Values: USB_HANDLE - Returns a pointer to the BDT entry associated with the transaction. The firmware can check for completion of the transaction by using the USBHandleBusy() function, using the returned USB_HANDLE value. - + Remarks: None - + *******************************************************************/ USB_HANDLE USBTxOnePacket(uint8_t ep, uint8_t* data, uint16_t len); /*DOM-IGNORE-BEGIN*/ @@ -1695,34 +1695,34 @@ USB_HANDLE USBTxOnePacket(uint8_t ep, uint8_t* data, uint16_t len); /******************************************************************** Function: USB_HANDLE USBRxOnePacket(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Receives the specified data out the specified endpoint - + PreCondition: None - + Parameters: ep - The endpoint number you want to receive the data on. - data - Pointer to a user buffer where the data will go when + data - Pointer to a user buffer where the data will go when it arrives from the host. Note: This RAM must be USB module accessible. len - The len parameter should always be set to the maximum endpoint packet size, specified in the USB descriptor for this endpoint. The host may send <= the number of bytes as the endpoint size in the endpoint - descriptor. After the transaction is complete, the application + descriptor. After the transaction is complete, the application firmware can call USBHandleGetLength() to determine how many bytes the host actually sent in the last transaction on this endpoint. - + Return Values: USB_HANDLE - Returns a pointer to the BDT entry associated with the transaction. The firmware can check for completion of the transaction by using the USBHandleBusy() function, using the returned USB_HANDLE value. - + Remarks: None - + *******************************************************************/ USB_HANDLE USBRxOnePacket(uint8_t ep, uint8_t* data, uint16_t len); /*DOM-IGNORE-BEGIN*/ @@ -1732,7 +1732,7 @@ USB_HANDLE USBRxOnePacket(uint8_t ep, uint8_t* data, uint16_t len); /******************************************************************************* Function: bool USB_APPLICATION_EVENT_HANDLER(uint8_t address, USB_EVENT event, void *pdata, uint16_t size); - + Summary: This function is called whenever the USB stack wants to notify the user of an event. @@ -1740,7 +1740,7 @@ USB_HANDLE USBRxOnePacket(uint8_t ep, uint8_t* data, uint16_t len); Description: This function is called whenever the USB stack wants to notify the user of an event. This function should be implemented by the user. - + Example Usage: Conditions: None @@ -1754,7 +1754,7 @@ USB_HANDLE USBRxOnePacket(uint8_t ep, uint8_t* data, uint16_t len); Return: None Remarks: - None + None *****************************************************************************/ bool USB_APPLICATION_EVENT_HANDLER(uint8_t address, USB_EVENT event, void *pdata, uint16_t size); @@ -1933,7 +1933,7 @@ uint8_t USBGetTicksSinceSuspendEnd(void); /* The DESC_CONFIG_uint8_t() macro is implemented for convenience. The DESC_CONFIG_uint8_t() macro provides a consistent macro for use with a byte - when generating a configuration descriptor when using either the + when generating a configuration descriptor when using either the DESC_CONFIG_WORD() or DESC_CONFIG_uint32_t() macros. */ #define DESC_CONFIG_uint8_t(a) (a) diff --git a/inc/usb_device_audio.h b/inc/usb_device_audio.h index ac64a8b..a3fa800 100644 --- a/inc/usb_device_audio.h +++ b/inc/usb_device_audio.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -157,11 +157,11 @@ please contact mla_licensing@microchip.com #define SAMPLING_FREQ_CONTROL 0x01 #define PITCH_CONTROL 0x02 -/*********** Terminal Types***********************/ -/*A complete list of Terminal Type codes is provided in -the document USB Audio Terminal Types */ +/*********** Terminal Types***********************/ +/*A complete list of Terminal Type codes is provided in +the document USB Audio Terminal Types */ #define USB_STREAMING 0x01, 0x01 -#define MICROPHONE 0x01,0x02 +#define MICROPHONE 0x01,0x02 #define SPEAKER 0x01,0x03 #define HEADPHONES 0x02,0x03 @@ -177,27 +177,27 @@ extern volatile uint8_t CtrlTrfData[USB_EP0_BUFF_SIZE]; /******************************************************************** Function: void USBCheckAudioRequest(void) - + Summary: This routine checks the setup data packet to see if it knows how to handle it - + Description: This routine checks the setup data packet to see if it knows how to handle it PreCondition: None - + Parameters: None - + Return Values: None - + Remarks: None - + *******************************************************************/ void USBCheckAudioRequest(void); #endif //AUDIO_H diff --git a/inc/usb_device_ccid.h b/inc/usb_device_ccid.h index bbce81b..9bfd5da 100644 --- a/inc/usb_device_ccid.h +++ b/inc/usb_device_ccid.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -81,7 +81,7 @@ please contact mla_licensing@microchip.com #define USB_CCID_CMD_SLOT_BUSY 0xE0 #define USB_CCID_CMD_NOT_SUPPORTED 0x00 - + //protocols #define USB_CCID_T0_PROTOCOL 0 #define USB_CCID_T1_PROTOCOL 1 @@ -99,30 +99,30 @@ extern unsigned char usbCcidBulkInEndpoint[USB_EP_SIZE]; //User application buff /****************************************************************************** Function: void mUSBCCIDBulkInRam(BYTE *pData, BYTE len) - + Description: Use this macro to transfer data located in data memory. Use this macro when: 1. Data stream is not null-terminated 2. Transfer length is known Remember: usbCcidBulkInTrfState must == USB_CCID_BULK_IN_READY - Unexpected behavior will occur if this function is called when + Unexpected behavior will occur if this function is called when usbCcidBulkInTrfState != USB_CCID_BULK_IN_READY - + PreCondition: usbCcidBulkInTrfState must be in the USB_CCID_BULK_IN_READY state. - + Paramters: pDdata : Pointer to the starting location of data bytes len : Number of bytes to be transferred - + Return Values: None - + Remarks: This macro only handles the setup of the transfer. The actual transfer is handled by USBCCIDBulkInService(). - + *****************************************************************************/ #define mUSBCCIDBulkInRam(pData,len) \ { \ @@ -134,30 +134,30 @@ extern unsigned char usbCcidBulkInEndpoint[USB_EP_SIZE]; //User application buff /****************************************************************************** Function: void USBCheckCCIDRequest(void) - + Description: This routine checks the setup data packet to see if it knows how to handle it - + PreCondition: None Parameters: None - + Return Values: None - + Remarks: None - + *****************************************************************************/ void USBCheckCCIDRequest(void); /************************************************************************** Function: void USBCCIDInitEP(void) - + Summary: This function initializes the CCID function driver. This function should be called after the SET_CONFIGURATION command. @@ -166,11 +166,11 @@ void USBCheckCCIDRequest(void); the default line coding (baud rate, bit parity, number of data bits, and format). This function also enables the endpoints and prepares for the first transfer from the host. - + This function should be called after the SET_CONFIGURATION command. This is most simply done by calling this function from the USBCBInitEP() function. - + Typical Usage: void USBCBInitEP(void) @@ -181,14 +181,14 @@ void USBCheckCCIDRequest(void); Conditions: None Remarks: - None + None **************************************************************************/ void USBCCIDInitEP(void); /************************************************************************ Function: void USBCCIDBulkInService(void) - + Summary: USBCCIDBulkInService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches @@ -197,7 +197,7 @@ void USBCCIDInitEP(void); USBCCIDBulkInService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches the configured state. - + Typical Usage: void main(void) @@ -227,14 +227,14 @@ void USBCCIDInitEP(void); Conditions: None Remarks: - None + None ************************************************************************/ void USBCCIDBulkInService(void); /****************************************************************************** Function: void USBCCIDSendDataToHost(BYTE *data, WORD length) - + Summary: USBCCIDSendDataToHost writes an array of data to the USB. Use this version, is capable of transfering 0x00 (what is typically a NULL character in any of @@ -244,8 +244,8 @@ void USBCCIDBulkInService(void); USBCCIDSendDataToHost writes an array of data to the USB. Use this version, is capable of transfering 0x00 (what is typically a NULL character in any of the string transfer functions). - - + + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -253,19 +253,19 @@ void USBCCIDBulkInService(void); must be called periodically to keep sending blocks of data to the host. Conditions: - + Input: BYTE *data - pointer to a RAM array of data to be transfered to the host - WORD length - the number of bytes to be transfered - + WORD length - the number of bytes to be transfered + *****************************************************************************/ void USBCCIDSendDataToHost(BYTE *pData, WORD len); /** Section: STRUCTURES **********************************************/ typedef union { BYTE CCID_BulkOutBuffer[271]; - BYTE CCID_BulkInBuffer[267]; -} USB_CCID_BUFFER; + BYTE CCID_BulkInBuffer[267]; +} USB_CCID_BUFFER; #endif //CCID_H diff --git a/inc/usb_device_cdc.h b/inc/usb_device_cdc.h index 9d0472c..ff88aa9 100644 --- a/inc/usb_device_cdc.h +++ b/inc/usb_device_cdc.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -96,7 +96,7 @@ please contact mla_licensing@microchip.com #define CDC_TX_BUSY_ZLP 2 // ZLP: Zero Length Packet #define CDC_TX_COMPLETING 3 -#if defined(USB_CDC_SET_LINE_CODING_HANDLER) +#if defined(USB_CDC_SET_LINE_CODING_HANDLER) #define LINE_CODING_TARGET &cdc_notice.SetLineCoding._byte[0] #define LINE_CODING_PFUNC &USB_CDC_SET_LINE_CODING_HANDLER #else @@ -143,7 +143,7 @@ please contact mla_licensing@microchip.com /****************************************************************************** Function: void CDCSetBaudRate(uint32_t baudRate) - + Summary: This macro is used set the baud rate reported back to the host during a get line coding request. (optional) @@ -159,57 +159,57 @@ please contact mla_licensing@microchip.com This function is optional for CDC devices that do not actually convert the USB traffic to a hardware UART. - + PreCondition: None - + Parameters: uint32_t baudRate - The desired baud rate - + Return Values: None - + Remarks: None - + *****************************************************************************/ #define CDCSetBaudRate(baudRate) {line_coding.dwDTERate=baudRate;} /****************************************************************************** Function: void CDCSetCharacterFormat(uint8_t charFormat) - + Summary: - This macro is used manually set the character format reported back to + This macro is used manually set the character format reported back to the host during a get line coding request. (optional) Description: - This macro is used manually set the character format reported back to + This macro is used manually set the character format reported back to the host during a get line coding request. Typical Usage: CDCSetCharacterFormat(NUM_STOP_BITS_1); - + This function is optional for CDC devices that do not actually convert the USB traffic to a hardware UART. PreCondition: None - + Parameters: uint8_t charFormat - number of stop bits. Available options are: * NUM_STOP_BITS_1 - 1 Stop bit * NUM_STOP_BITS_1_5 - 1.5 Stop bits * NUM_STOP_BITS_2 - 2 Stop bits - + Return Values: None - + Remarks: None - + *****************************************************************************/ #define CDCSetCharacterFormat(charFormat) {line_coding.bCharFormat=charFormat;} #define NUM_STOP_BITS_1 0 //1 stop bit - used by CDCSetLineCoding() and CDCSetCharacterFormat() @@ -219,26 +219,26 @@ please contact mla_licensing@microchip.com /****************************************************************************** Function: void CDCSetParity(uint8_t parityType) - + Summary: - This function is used manually set the parity format reported back to + This function is used manually set the parity format reported back to the host during a get line coding request. (optional) Description: - This macro is used manually set the parity format reported back to + This macro is used manually set the parity format reported back to the host during a get line coding request. Typical Usage: CDCSetParity(PARITY_NONE); - + This function is optional for CDC devices that do not actually convert the USB traffic to a hardware UART. PreCondition: None - + Parameters: uint8_t parityType - Type of parity. The options are the following: * PARITY_NONE @@ -246,13 +246,13 @@ please contact mla_licensing@microchip.com * PARITY_EVEN * PARITY_MARK * PARITY_SPACE - + Return Values: None - + Remarks: None - + *****************************************************************************/ #define CDCSetParity(parityType) {line_coding.bParityType=parityType;} #define PARITY_NONE 0 //no parity - used by CDCSetLineCoding() and CDCSetParity() @@ -264,61 +264,61 @@ please contact mla_licensing@microchip.com /****************************************************************************** Function: void CDCSetDataSize(uint8_t dataBits) - + Summary: - This function is used manually set the number of data bits reported back + This function is used manually set the number of data bits reported back to the host during a get line coding request. (optional) Description: - This function is used manually set the number of data bits reported back + This function is used manually set the number of data bits reported back to the host during a get line coding request. Typical Usage: CDCSetDataSize(8); - + This function is optional for CDC devices that do not actually convert the USB traffic to a hardware UART. PreCondition: None - + Parameters: uint8_t dataBits - number of data bits. The options are 5, 6, 7, 8, or 16. - + Return Values: None - + Remarks: None - + *****************************************************************************/ #define CDCSetDataSize(dataBits) {line_coding.bDataBits=dataBits;} /****************************************************************************** Function: void CDCSetLineCoding(uint32_t baud, uint8_t format, uint8_t parity, uint8_t dataSize) - + Summary: - This function is used to manually set the data reported back + This function is used to manually set the data reported back to the host during a get line coding request. (optional) Description: - This function is used to manually set the data reported back + This function is used to manually set the data reported back to the host during a get line coding request. Typical Usage: CDCSetLineCoding(19200, NUM_STOP_BITS_1, PARITY_NONE, 8); - + This function is optional for CDC devices that do not actually convert the USB traffic to a hardware UART. PreCondition: None - + Parameters: uint32_t baud - The desired baud rate uint8_t format - number of stop bits. Available options are: @@ -332,13 +332,13 @@ please contact mla_licensing@microchip.com * PARITY_MARK * PARITY_SPACE uint8_t dataSize - number of data bits. The options are 5, 6, 7, 8, or 16. - + Return Values: None - + Remarks: None - + *****************************************************************************/ #define CDCSetLineCoding(baud,format,parity,dataSize) {\ CDCSetBaudRate(baud);\ @@ -350,13 +350,13 @@ please contact mla_licensing@microchip.com /****************************************************************************** Function: bool USBUSARTIsTxTrfReady(void) - + Summary: This macro is used to check if the CDC class is ready to send more data. Description: - This macro is used to check if the CDC class handler firmware is + This macro is used to check if the CDC class handler firmware is ready to send more data to the host over the CDC bulk IN endpoint. Typical Usage: @@ -366,38 +366,38 @@ please contact mla_licensing@microchip.com putrsUSBUSART("Hello World"); } - + PreCondition: The return value of this function is only valid if the device is in a configured state (i.e. - USBDeviceGetState() returns CONFIGURED_STATE) - + Parameters: None - + Return Values: Returns a boolean value indicating if the CDC class handler firmware is ready to receive new data to send to the host over the bulk data IN - endpoint. A return value of true indicates that the CDC handler + endpoint. A return value of true indicates that the CDC handler firmware is ready to receive new data, and it is therefore safe to call other APIs like putrsUSBUSART() and putsUSBUSART(). A return value of false implies that the firmware is still busy sending the last data, or is otherwise not ready to process any new data at this time. - + Remarks: Make sure the application periodically calls the CDCTxService() handler, or pending USB IN transfers will not be able to advance and complete. - + *****************************************************************************/ #define USBUSARTIsTxTrfReady() (cdc_trf_state == CDC_TX_READY) /****************************************************************************** Function: void mUSBUSARTTxRam(uint8_t *pData, uint8_t len) - + Description: - Deprecated in MCHPFSUSB v2.3. This macro has been replaced by + Deprecated in MCHPFSUSB v2.3. This macro has been replaced by USBUSARTIsTxTrfReady(). *****************************************************************************/ #define mUSBUSARTIsTxTrfReady() USBUSARTIsTxTrfReady() @@ -405,7 +405,7 @@ please contact mla_licensing@microchip.com /****************************************************************************** Function: void mUSBUSARTTxRam(uint8_t *pData, uint8_t len) - + Description: Use this macro to transfer data located in data memory. Use this macro when: @@ -415,7 +415,7 @@ please contact mla_licensing@microchip.com Unlike putsUSBUSART, there is not code double checking the transfer state. Unexpected behavior will occur if this function is called when cdc_trf_state != CDC_TX_READY - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -423,30 +423,30 @@ please contact mla_licensing@microchip.com mUSBUSARTTxRam(&UserDataBuffer[0], 200); } - + PreCondition: cdc_trf_state must be in the CDC_TX_READY state. Value of 'len' must be equal to or smaller than 255 bytes. The USB stack should have reached the CONFIGURED_STATE prior to calling this API function for the first time. - + Parameters: pDdata : Pointer to the starting location of data bytes len : Number of bytes to be transferred - + Return Values: None - + Remarks: This macro only handles the setup of the transfer. The actual transfer is handled by CDCTxService(). This macro does not "double buffer" the data. The application firmware should not modify the contents of the pData buffer until all - of the data has been sent, as indicated by the + of the data has been sent, as indicated by the USBUSARTIsTxTrfReady() function returning true, subsequent to calling mUSBUSARTTxRam(). - - + + *****************************************************************************/ #define mUSBUSARTTxRam(pData,len) \ { \ @@ -459,18 +459,18 @@ please contact mla_licensing@microchip.com /****************************************************************************** Function: void mUSBUSARTTxRom(rom uint8_t *pData, uint8_t len) - + Description: Use this macro to transfer data located in program memory. Use this macro when: 1. Data stream is not null-terminated 2. Transfer length is known - + Remember: cdc_trf_state must == CDC_TX_READY Unlike putrsUSBUSART, there is not code double checking the transfer state. Unexpected behavior will occur if this function is called when cdc_trf_state != CDC_TX_READY - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -478,22 +478,22 @@ please contact mla_licensing@microchip.com mUSBUSARTTxRom(&SomeRomString[0], 200); } - + PreCondition: cdc_trf_state must be in the CDC_TX_READY state. Value of 'len' must be equal to or smaller than 255 bytes. - + Parameters: pDdata : Pointer to the starting location of data bytes len : Number of bytes to be transferred - + Return Values: None - + Remarks: This macro only handles the setup of the transfer. The actual transfer is handled by CDCTxService(). - + *****************************************************************************/ #define mUSBUSARTTxRom(pData,len) \ { \ @@ -506,7 +506,7 @@ please contact mla_licensing@microchip.com /************************************************************************** Function: void CDCInitEP(void) - + Summary: This function initializes the CDC function driver. This function should be called after the SET_CONFIGURATION command (ex: within the context of @@ -516,11 +516,11 @@ please contact mla_licensing@microchip.com the default line coding (baud rate, bit parity, number of data bits, and format). This function also enables the endpoints and prepares for the first transfer from the host. - + This function should be called after the SET_CONFIGURATION command. This is most simply done by calling this function from the USBCBInitEP() function. - + Typical Usage: void USBCBInitEP(void) @@ -531,33 +531,33 @@ please contact mla_licensing@microchip.com Conditions: None Remarks: - None + None **************************************************************************/ void CDCInitEP(void); /****************************************************************************** Function: void USBCheckCDCRequest(void) - + Description: - This routine checks the most recently received SETUP data packet to + This routine checks the most recently received SETUP data packet to see if the request is specific to the CDC class. If the request was a CDC specific request, this function will take care of handling the request and responding appropriately. - + PreCondition: This function should only be called after a control transfer SETUP packet has arrived from the host. Parameters: None - + Return Values: None - + Remarks: This function does not change status or do anything if the SETUP packet - did not contain a CDC class specific request. + did not contain a CDC class specific request. *****************************************************************************/ void USBCheckCDCRequest(void); @@ -566,14 +566,14 @@ void USBCheckCDCRequest(void); Function: void CDCNotificationHandler(void) Summary: Checks for changes in DSR status and reports them to the USB host. Description: Checks for changes in DSR pin state and reports any changes - to the USB host. + to the USB host. Conditions: CDCInitEP() must have been called previously, prior to calling CDCNotificationHandler() for the first time. Remarks: - This function is only implemented and needed when the + This function is only implemented and needed when the USB_CDC_SUPPORT_DSR_REPORTING option has been enabled. If the function is enabled, it should be called periodically to sample the DSR pin and feed - the information to the USB host. This can be done by calling + the information to the USB host. This can be done by calling CDCNotificationHandler() by itself, or, by calling CDCTxService() which also calls CDCNotificationHandler() internally, when appropriate. **************************************************************************/ @@ -583,15 +583,15 @@ void CDCNotificationHandler(void); /********************************************************************************** Function: bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size) - + Summary: - Handles events from the USB stack, which may have an effect on the CDC + Handles events from the USB stack, which may have an effect on the CDC endpoint(s). Description: - Handles events from the USB stack. This function should be called when + Handles events from the USB stack. This function should be called when there is a USB event that needs to be processed by the CDC driver. - + Conditions: Value of input argument 'len' should be smaller than the maximum endpoint size responsible for receiving bulk data from USB host for CDC @@ -601,7 +601,7 @@ void CDCNotificationHandler(void); event - the type of event that occurred pdata - pointer to the data that caused the event size - the size of the data that is pointed to by pdata - + **********************************************************************************/ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size); @@ -609,7 +609,7 @@ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size); /********************************************************************************** Function: uint8_t getsUSBUSART(char *buffer, uint8_t len) - + Summary: getsUSBUSART copies a string of BYTEs received through USB CDC Bulk OUT endpoint to a user's specified location. It is a non-blocking function. @@ -621,12 +621,12 @@ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size); endpoint to a user's specified location. It is a non-blocking function. It does not wait for data if there is no data available. Instead it returns '0' to notify the caller that there is no data available. - + Typical Usage: uint8_t numBytes; uint8_t buffer[64] - + numBytes = getsUSBUSART(buffer,sizeof(buffer)); //until the buffer is free. if(numBytes \> 0) { @@ -648,14 +648,14 @@ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size); received and copied into the specified buffer. The returned value can be anything from 0 up to the len input value. A return value of 0 indicates that no new CDC bulk OUT endpoint data was available. - + **********************************************************************************/ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len); /****************************************************************************** Function: void putUSBUSART(char *data, uint8_t length) - + Summary: putUSBUSART writes an array of data to the USB. Use this version, is capable of transferring 0x00 (what is typically a NULL character in any of @@ -665,7 +665,7 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len); putUSBUSART writes an array of data to the USB. Use this version, is capable of transferring 0x00 (what is typically a NULL character in any of the string transfer functions). - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -674,7 +674,7 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len); putUSBUSART(data,5); } - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -690,14 +690,14 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len); Input: char *data - pointer to a RAM array of data to be transfered to the host uint8_t length - the number of bytes to be transfered (must be less than 255). - + *****************************************************************************/ void putUSBUSART(uint8_t *data, uint8_t Length); /****************************************************************************** Function: void putsUSBUSART(char *data) - + Summary: putsUSBUSART writes a string of data to the USB including the null character. Use this version, 'puts', to transfer data from a RAM buffer. @@ -705,7 +705,7 @@ void putUSBUSART(uint8_t *data, uint8_t Length); Description: putsUSBUSART writes a string of data to the USB including the null character. Use this version, 'puts', to transfer data from a RAM buffer. - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -714,7 +714,7 @@ void putUSBUSART(uint8_t *data, uint8_t Length); putsUSBUSART(data); } - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -731,7 +731,7 @@ void putUSBUSART(uint8_t *data, uint8_t Length); char *data - null\-terminated string of constant data. If a null character is not found, 255 BYTEs of data will be transferred to the host. - + *****************************************************************************/ void putsUSBUSART(char *data); @@ -739,7 +739,7 @@ void putsUSBUSART(char *data); /************************************************************************** Function: void putrsUSBUSART(const const char *data) - + Summary: putrsUSBUSART writes a string of data to the USB including the null character. Use this version, 'putrs', to transfer data literals and @@ -749,7 +749,7 @@ void putsUSBUSART(char *data); putrsUSBUSART writes a string of data to the USB including the null character. Use this version, 'putrs', to transfer data literals and data located in program memory. - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -757,7 +757,7 @@ void putsUSBUSART(char *data); putrsUSBUSART("Hello World"); } - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -774,14 +774,14 @@ void putsUSBUSART(char *data); const const char *data - null\-terminated string of constant data. If a null character is not found, 255 BYTEs of data will be transferred to the host. - + **************************************************************************/ void putrsUSBUSART(const const char *data); /************************************************************************ Function: void CDCTxService(void) - + Summary: CDCTxService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches @@ -790,12 +790,12 @@ void putrsUSBUSART(const const char *data); CDCTxService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches the configured state (after the CDCIniEP() function has already executed). - This function is needed, in order to advance the internal software state + This function is needed, in order to advance the internal software state machine that takes care of sending multiple transactions worth of IN USB - data to the host, associated with CDC serial data. Failure to call + data to the host, associated with CDC serial data. Failure to call CDCTxService() periodically will prevent data from being sent to the USB host, over the CDC serial data interface. - + Typical Usage: void main(void) @@ -815,7 +815,7 @@ void putrsUSBUSART(const const char *data); { //Keep trying to send data to the PC as required CDCTxService(); - + //Run application code. UserApplication(); } @@ -826,7 +826,7 @@ void putrsUSBUSART(const const char *data); CDCIniEP() function should have already exectuted/the device should be in the CONFIGURED_STATE. Remarks: - None + None ************************************************************************/ void CDCTxService(void); @@ -923,8 +923,8 @@ typedef union uint8_t ParityError :1; uint8_t Overrun :1; uint8_t Reserved :1; - }bits; -}BM_SERIAL_STATE; + }bits; +}BM_SERIAL_STATE; /* Serial State Notification Packet Structure */ typedef struct @@ -936,7 +936,7 @@ typedef struct uint16_t wLength; //Should always be 2 for serial state notification packets BM_SERIAL_STATE SerialState; uint8_t Reserved; -}SERIAL_STATE_NOTIFICATION; +}SERIAL_STATE_NOTIFICATION; //DOM-IGNORE-BEGIN /** E X T E R N S ************************************************************/ diff --git a/inc/usb_device_generic.h b/inc/usb_device_generic.h index efd8c13..af7a3f8 100644 --- a/inc/usb_device_generic.h +++ b/inc/usb_device_generic.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -38,12 +38,12 @@ please contact mla_licensing@microchip.com /******************************************************************** Function: USB_HANDLE USBGenWrite(BYTE ep, BYTE* data, WORD len) - + Summary: Sends the specified data out the specified endpoint Description: - This function sends the specified data out the specified + This function sends the specified data out the specified endpoint and returns a handle to the transfer information. Typical Usage: @@ -56,22 +56,22 @@ please contact mla_licensing@microchip.com USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket[0],sizeof(INPacket)); } - + PreCondition: None - + Parameters: BYTE ep - the endpoint you want to send the data out of BYTE* data - pointer to the data that you wish to send WORD len - the length of the data that you wish to send - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ #define USBGenWrite(ep,data,len) USBTxOnePacket(ep,data,len) @@ -79,10 +79,10 @@ please contact mla_licensing@microchip.com /******************************************************************** Function: USB_HANDLE USBGenRead(BYTE ep, BYTE* data, WORD len) - + Summary: Receives the specified data out the specified endpoint - + Description: Receives the specified data out the specified endpoint. @@ -99,19 +99,19 @@ please contact mla_licensing@microchip.com PreCondition: None - + Parameters: BYTE ep - the endpoint you want to receive the data into BYTE* data - pointer to where the data will go when it arrives WORD len - the length of the data that you wish to receive - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ #define USBGenRead(ep,data,len) USBRxOnePacket(ep,data,len) @@ -127,9 +127,9 @@ please contact mla_licensing@microchip.com Description: This routine handles vendor specific requests that may arrive on EP0 as - a control transfer. These can include, but are not necessarily - limited to, requests for Microsft specific OS feature descriptor(s). - This function should be called from the USBCBCheckOtherReq() call back + a control transfer. These can include, but are not necessarily + limited to, requests for Microsft specific OS feature descriptor(s). + This function should be called from the USBCBCheckOtherReq() call back function whenever using a vendor class device. Typical Usage: @@ -149,7 +149,7 @@ please contact mla_licensing@microchip.com Although this function has a void input, this handler function will typically need to look at the 8-byte SETUP packet contents that the host just sent, which may contain the vendor class specific request. - + Therefore, the statically allocated SetupPkt structure may be looked at while in the context of this function, and it will contain the most recently received 8-byte SETUP packet data. @@ -160,17 +160,17 @@ please contact mla_licensing@microchip.com Remarks: This function normally gets called within the same context as the USBDeviceTasks() function, just after a new control transfer request - from the host has arrived. If the USB stack is operated in + from the host has arrived. If the USB stack is operated in USB_INTERRUPT mode (a usb_config.h option), then this function will be executed in the interrupt context. If however the USB stack is operated in the USB_POLLING mode, then this function executes in the main loop context. - + In order to respond to class specific control transfer request(s) in this handler function, it is suggested to use one or more of the - USBEP0SendRAMPtr(), USBEP0SendROMPtr(), or USBEP0Receive() API + USBEP0SendRAMPtr(), USBEP0SendROMPtr(), or USBEP0Receive() API functions. - + *******************************************************************/ void USBCheckVendorRequest(void); diff --git a/inc/usb_device_hid.h b/inc/usb_device_hid.h index 781c8ee..53f84f7 100644 --- a/inc/usb_device_hid.h +++ b/inc/usb_device_hid.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -100,23 +100,23 @@ void USBCheckHIDRequest(void); /******************************************************************** Function: bool HIDTxHandleBusy(USB_HANDLE handle) - + Summary: Retrieves the status of the buffer ownership Description: Retrieves the status of the buffer ownership. This function will indicate if the previous transfer is complete or not. - - This function will take the input handle (pointer to a BDT entry) and - will check the UOWN bit. If the UOWN bit is set then that indicates + + This function will take the input handle (pointer to a BDT entry) and + will check the UOWN bit. If the UOWN bit is set then that indicates that the transfer is not complete and the USB module still owns the data - memory. If the UOWN bit is clear that means that the transfer is - complete and that the CPU now owns the data memory. + memory. If the UOWN bit is clear that means that the transfer is + complete and that the CPU now owns the data memory. - For more information about the BDT, please refer to the appropriate + For more information about the BDT, please refer to the appropriate datasheet for the device in use. - + Typical Usage: //make sure that the last transfer isn't busy by checking the handle @@ -130,42 +130,42 @@ void USBCheckHIDRequest(void); PreCondition: None. - + Parameters: USB_HANDLE handle - the handle for the transfer in question. The handle is returned by the HIDTxPacket() and HIDRxPacket() functions. Please insure that USB_HANDLE objects are initialized to NULL. - + Return Values: TRUE - the HID handle is still busy FALSE - the HID handle is not busy and is ready to send additional data. - + Remarks: None - + *******************************************************************/ #define HIDTxHandleBusy(handle) USBHandleBusy(handle) /******************************************************************** Function: bool HIDRxHandleBusy(USB_HANDLE handle) - + Summary: Retrieves the status of the buffer ownership - + Description: Retrieves the status of the buffer ownership. This function will indicate if the previous transfer is complete or not. - - This function will take the input handle (pointer to a BDT entry) and - will check the UOWN bit. If the UOWN bit is set then that indicates + + This function will take the input handle (pointer to a BDT entry) and + will check the UOWN bit. If the UOWN bit is set then that indicates that the transfer is not complete and the USB module still owns the data - memory. If the UOWN bit is clear that means that the transfer is - complete and that the CPU now owns the data memory. + memory. If the UOWN bit is clear that means that the transfer is + complete and that the CPU now owns the data memory. - For more information about the BDT, please refer to the appropriate + For more information about the BDT, please refer to the appropriate datasheet for the device in use. Typical Usage: @@ -179,33 +179,33 @@ void USBCheckHIDRequest(void); PreCondition: None - + Parameters: USB_HANDLE handle - the handle for the transfer in question. The handle is returned by the HIDTxPacket() and HIDRxPacket() functions. Please insure that USB_HANDLE objects are initialized to NULL. - + Return Values: TRUE - the HID handle is still busy FALSE - the HID handle is not busy and is ready to receive additional data. - + Remarks: None - + *******************************************************************/ #define HIDRxHandleBusy(handle) USBHandleBusy(handle) /******************************************************************** Function: USB_HANDLE HIDTxPacket(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Sends the specified data out the specified endpoint Description: - This function sends the specified data out the specified + This function sends the specified data out the specified endpoint and returns a handle to the transfer information. Typical Usage: @@ -218,32 +218,32 @@ void USBCheckHIDRequest(void); USBInHandle = HIDTxPacket(HID_EP,(uint8_t*)&ToSendDataBuffer[0],sizeof(ToSendDataBuffer)); } - + PreCondition: None - + Parameters: uint8_t ep - the endpoint you want to send the data out of uint8_t* data - pointer to the data that you wish to send uint16_t len - the length of the data that you wish to send - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ #define HIDTxPacket USBTxOnePacket /******************************************************************** Function: USB_HANDLE HIDRxPacket(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Receives the specified data out the specified endpoint - + Description: Receives the specified data out the specified endpoint. @@ -257,25 +257,25 @@ void USBCheckHIDRequest(void); PreCondition: None - + Parameters: uint8_t ep - the endpoint you want to receive the data into uint8_t* data - pointer to where the data will go when it arrives uint16_t len - the length of the data that you wish to receive - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ #define HIDRxPacket USBRxOnePacket // Section: STRUCTURES *********************************************/ -//USB HID Descriptor header as detailed in section +//USB HID Descriptor header as detailed in section //"6.2.1 HID Descriptor" of the HID class definition specification typedef struct _USB_HID_DSC_HEADER { @@ -283,7 +283,7 @@ typedef struct _USB_HID_DSC_HEADER uint16_t wDscLength; //offset 10 } USB_HID_DSC_HEADER; -//USB HID Descriptor header as detailed in section +//USB HID Descriptor header as detailed in section //"6.2.1 HID Descriptor" of the HID class definition specification typedef struct _USB_HID_DSC { @@ -296,7 +296,7 @@ typedef struct _USB_HID_DSC //USB_HID_DSC_HEADER hid_dsc_header[HID_NUM_OF_DSC]; /* HID_NUM_OF_DSC is defined in usbcfg.h */ - + } USB_HID_DSC; /** Section: EXTERNS ********************************************************/ diff --git a/inc/usb_device_midi.h b/inc/usb_device_midi.h index 1a8a465..62d0e56 100644 --- a/inc/usb_device_midi.h +++ b/inc/usb_device_midi.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -32,7 +32,7 @@ typedef union uint8_t MIDI_0; uint8_t MIDI_1; uint8_t MIDI_2; - }; + }; struct { uint8_t CodeIndexNumber :4; diff --git a/inc/usb_device_msd.h b/inc/usb_device_msd.h index 7970ebc..01d29f2 100644 --- a/inc/usb_device_msd.h +++ b/inc/usb_device_msd.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -73,14 +73,14 @@ please contact mla_licensing@microchip.com #define MSD_DATA_OUT 0x02 //MSD_SEND_CSW is when the device is waiting to send the CSW (returned by MSDTasks()) #define MSD_SEND_CSW 0x03 - + //States of the MSDProcessCommand state machine #define MSD_COMMAND_WAIT 0xFF #define MSD_COMMAND_ERROR 0xFE #define MSD_COMMAND_RESPONSE 0xFD #define MSD_COMMAND_RESPONSE_SEND 0xFC #define MSD_COMMAND_STALL 0xFB - + /* SCSI Transparent Command Set Sub-class code */ #define MSD_INQUIRY 0x12 #define MSD_READ_FORMAT_CAPACITY 0x23 @@ -93,7 +93,7 @@ please contact mla_licensing@microchip.com #define MSD_TEST_UNIT_READY 0x00 #define MSD_VERIFY 0x2f #define MSD_STOP_START 0x1b - + #define MSD_READ10_WAIT 0x00 #define MSD_READ10_BLOCK 0x01 #define MSD_READ10_SECTOR 0x02 @@ -103,14 +103,14 @@ please contact mla_licensing@microchip.com #define MSD_READ10_XMITING_DATA 0x06 #define MSD_READ10_AWAITING_COMPLETION 0x07 #define MSD_READ10_ERROR 0xFF - + #define MSD_WRITE10_WAIT 0x00 #define MSD_WRITE10_BLOCK 0x01 #define MSD_WRITE10_SECTOR 0x02 #define MSD_WRITE10_RX_SECTOR 0x03 #define MSD_WRITE10_RX_PACKET 0x04 -//Define MSD_USE_BLOCKING in order to block the code in an +//Define MSD_USE_BLOCKING in order to block the code in an //attempt to get better throughput. //#define MSD_USE_BLOCKING @@ -165,7 +165,7 @@ please contact mla_licensing@microchip.com //------------------------------------------------------------------------------ //ASC/ASCQ Codes for Sense Data (only those that we plan to use): -//The ASC/ASCQ code expand on the information provided in the sense key error +//The ASC/ASCQ code expand on the information provided in the sense key error //code, and provide the host with more details about the specific issue/status. //------------------------------------------------------------------------------ //For use with sense key Illegal request for a command not supported @@ -222,7 +222,7 @@ please contact mla_licensing@microchip.com /** S T R U C T U R E S ******************************************************/ /********************** ******************************************************/ - + typedef struct _USB_MSD_CBW //31 bytes total Command Block Wrapper { uint32_t dCBWSignature; // 55 53 42 43h @@ -297,7 +297,7 @@ typedef struct { // Read Capacity 10 uint32_t LBA; // Logical Block Address uint16_t Reserved2; uint8_t PMI; // Partial medium Indicator b0 only - uint8_t Control; + uint8_t Control; } ReadCapacityCB; typedef struct { // Request Sense 0x03 @@ -357,7 +357,7 @@ typedef struct _USB_MSD_CSW // Command Status Wrapper uint8_t bCSWStatus; // 00h Command Passed, 01h Command Failed, 02h Phase Error, rest obsolete/reserved } USB_MSD_CSW; -typedef struct +typedef struct { uint8_t Peripheral; // Peripheral_Qualifier:3; Peripheral_DevType:5; uint8_t Removble; // removable medium bit7 = 0 means non removable, rest reserved @@ -457,7 +457,7 @@ typedef union __attribute__((packed)){ LUN_FUNCTIONS is a structure of function pointers that tells the stack where to find each of the physical layer functions it is looking for. This structure needs to be defined for any project for PIC24F or PIC32. - + Typical Usage: LUN_FUNCTIONS LUN[MAX_LUN + 1] = @@ -473,7 +473,7 @@ typedef union __attribute__((packed)){ } }; - + In the above code we are passing the address of the SDSPI functions to the corresponding member of the LUN_FUNCTIONS structure. In the above case we have created an array of LUN_FUNCTIONS structures so that it is @@ -482,15 +482,15 @@ typedef union __attribute__((packed)){ Please take caution to insure that each function is in the the correct location in the structure. Incorrect alignment will cause the USB stack to call the incorrect function for a given command. - + See the MDD File System Library for additional information about the available physical media, their requirements, and how to use their - associated functions. + associated functions. **************************************************************************/ typedef struct { // Function pointer to the MediaInitialize() function of the physical media - // being used. + // being used. FILEIO_MEDIA_INFORMATION* (*MediaInitialize)(void * config); // Function pointer to the ReadCapacity() function of the physical media // being used. @@ -536,32 +536,32 @@ void USBMSDInit(void); /************************************************************************** Function: bool MSDWasLastCBWValid(void) - + Summary: - Returns the BOOLean status of the most recently received command block + Returns the BOOLean status of the most recently received command block wrapper (CBW). If the last CBW passed the MSD "is valid" tests, then this function will return true. If the last received CBW was not valid, then the return value will be false. - + Description: - Returns the BOOLean status of the most recently received command block + Returns the BOOLean status of the most recently received command block wrapper (CBW). If the last CBW passed the "is valid" tests, then this function will return true. If the last received CBW was not valid, then the return value will be false. This function would - typically be used following a host initiated clear endpoint halt + typically be used following a host initiated clear endpoint halt operation on an MSD bulk IN or OUT endpoint. In this case, the firmware needs to check if the last received CBW was valid, in order to know if the firmware should re-stall the endpoint following the clear halt. This is necessary to fully comply with the MSD BOT error case handling - related specifications, which dictate that the MSD device must + related specifications, which dictate that the MSD device must persistently STALL the bulk endpoints when a non-valid CBW is received. - The host must issue an MSD reset command over EP0, prior to clear - endpoint halt, in order to clear the stall condition in this special + The host must issue an MSD reset command over EP0, prior to clear + endpoint halt, in order to clear the stall condition in this special scenario. - + Parameters: None - + Return Values: bool: true - if last received CBW was valid false - if the last received CBW was not valid @@ -569,7 +569,7 @@ void USBMSDInit(void); Remarks: None - + **************************************************************************/ #define MSDWasLastCBWValid() (MSDCBWValid) @@ -577,49 +577,49 @@ void USBMSDInit(void); /************************************************************************** Function: void LUNSoftDetach(uint8_t LUN) - + Summary: - + Description: - + Parameters: LUN - logical unit number to detach - + Return Values: None Remarks: Once a soft detached is initiated a soft attached, LUNSoftAttach(), on the same LUN must be performed before the device will re-attach - + **************************************************************************/ #define LUNSoftDetach(LUN) SoftDetach[LUN]=true; /************************************************************************** Function: void LUNSoftAttach(uint8_t LUN) - + Summary: - + Description: - + Parameters: LUN - logical unit number to detach - + Return Values: None Remarks: Once a soft detached is initiated a soft attached, LUNSoftAttach(), on the same LUN must be performed before the device will re-attach - + **************************************************************************/ #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 @@ -631,16 +631,16 @@ void USBMSDInit(void); 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); diff --git a/inc/usb_device_phdc.h b/inc/usb_device_phdc.h index 5dcf492..1087318 100644 --- a/inc/usb_device_phdc.h +++ b/inc/usb_device_phdc.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -43,7 +43,7 @@ please contact mla_licensing@microchip.com // the Meta-Data Message Preamble feature #define CLEAR_FEATURE -//An application may choose to use the Get DataStatus request to determine which +//An application may choose to use the Get DataStatus request to determine which //endpoints on the device have data #define GET_DATA_STATUS 0x00 @@ -88,7 +88,7 @@ extern volatile FAR unsigned char phdc_data_tx[PHDC_DATA_IN_EP_SIZE]; /* callback function pointer structure for Application to handle events */ typedef void(* USB_PHDC_CB)(uint8_t, void *); -extern volatile uint8_t CtrlTrfData[USB_EP0_BUFF_SIZE]; +extern volatile uint8_t CtrlTrfData[USB_EP0_BUFF_SIZE]; /** E X T E R N S ************************************************************/ typedef struct PHDC_RX_ENDPOINT_STRUCT { @@ -97,7 +97,7 @@ typedef struct PHDC_RX_ENDPOINT_STRUCT uint8_t qos; uint16_t offset; uint8_t size; - uint8_t len; + uint8_t len; uint8_t *app_buff; USB_HANDLE PHDCDataOutHandle; }PHDC_RX_ENDPOINT,*PTR_PHDC_RX_ENDPOINT; @@ -108,10 +108,10 @@ typedef struct PHDC_TX_ENDPOINT_STRUCT uint16_t transfer_size; bool memtype; uint8_t qos; - uint16_t offset; - uint16_t bytes_to_send; + uint16_t offset; + uint16_t bytes_to_send; uint8_t size; - uint8_t len; + uint8_t len; uint8_t *app_buff; USB_HANDLE PHDCDataInHandle; }PHDC_TX_ENDPOINT,*PTR_PHDC_TX_ENDPOINT; @@ -122,31 +122,31 @@ extern const uint8_t configDescriptor1[]; /****************************************************************************** Function: void USBDevicePHDCCheckRequest(void) - + Description: This routine checks the setup data packet to see if it is class specific request or vendor specific request and handles it - + PreCondition: None Parameters: None - + Return Values: None - + Remarks: None - + *****************************************************************************/ void USBDevicePHDCCheckRequest(void); /************************************************************************** Function: void PHDCInitEP(void) - + Summary: This function initializes the PHDC function driver. This function should be called after the SET_CONFIGURATION command. @@ -155,11 +155,11 @@ void USBDevicePHDCCheckRequest(void); the default line coding (baud rate, bit parity, number of data bits, and format). This function also enables the endpoints and prepares for the first transfer from the host. - + This function should be called after the SET_CONFIGURATION command. This is most simply done by calling this function from the USBCBInitEP() function. - + Typical Usage: void USBCBInitEP(void) @@ -170,13 +170,13 @@ void USBDevicePHDCCheckRequest(void); Conditions: None Remarks: - None + None **************************************************************************/ extern void USBDevicePHDCInit(USB_PHDC_CB); /********************************************************************************** Function: uint8_t USBDevicePHDCReceiveData(uint8_t qos, uint8_t *buffer, uint16_t len) - + Summary: USBDevicePHDCReceiveData copies a string of BYTEs received through USB PHDC Bulk OUT endpoint to a user's specified location. It is a non-blocking function. @@ -188,12 +188,12 @@ extern void USBDevicePHDCInit(USB_PHDC_CB); endpoint to a user's specified location. It is a non-blocking function. It does not wait for data if there is no data available. Instead it returns '0' to notify the caller that there is no data available. - + Typical Usage: uint8_t numBytes; uint8_t buffer[64] - + numBytes = USBDevicePHDCReceiveData(buffer,sizeof(buffer)); //until the buffer is free. if(numBytes \> 0) { @@ -211,7 +211,7 @@ extern void USBDevicePHDCInit(USB_PHDC_CB); qos - quality of service buffer - Pointer to where received BYTEs are to be stored len - The number of BYTEs expected. - + **********************************************************************************/ uint8_t USBDevicePHDCReceiveData(uint8_t qos, uint8_t *buffer, uint16_t len); @@ -219,13 +219,13 @@ uint8_t USBDevicePHDCReceiveData(uint8_t qos, uint8_t *buffer, uint16_t len); /****************************************************************************** Function: void USBDevicePHDCSendData(uint8_t qos, uint8_t *data, uint8_t Length) - + Summary: - USBDevicePHDCSendData writes an array of data to the USB. + USBDevicePHDCSendData writes an array of data to the USB. Description: USBDevicePHDCSendData writes an array of data to the USB. - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -234,7 +234,7 @@ uint8_t USBDevicePHDCReceiveData(uint8_t qos, uint8_t *buffer, uint16_t len); USBDevicePHDCSendData(1,data,5); } - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -249,13 +249,13 @@ uint8_t USBDevicePHDCReceiveData(uint8_t qos, uint8_t *buffer, uint16_t len); qos - Quality of service information *data - pointer to a RAM array of data to be transfered to the host length - the number of bytes to be transfered. - + *****************************************************************************/ void USBDevicePHDCSendData(uint8_t qos, uint8_t *data, uint16_t length, bool memtype); /************************************************************************ Function: void USBDevicePHDCTxRXService(void) - + Summary: USBDevicePHDCTxRXService handles device-to-host transaction(s) and host-to-device transaction(s). This function should be called once per Main Program loop after the device reaches @@ -264,7 +264,7 @@ void USBDevicePHDCSendData(uint8_t qos, uint8_t *data, uint16_t length, bool mem USBDevicePHDCTxRXService handles device-to-host transaction(s) and host-to-device transaction(s). This function should be called once per Main Program loop after the device reaches the configured state. - + Typical Usage: void main(void) @@ -284,7 +284,7 @@ void USBDevicePHDCSendData(uint8_t qos, uint8_t *data, uint16_t length, bool mem { //Keep trying to send data to the PC as required USBDevicePHDCTxRXService(); - + //Run application code. UserApplication(); } @@ -294,7 +294,7 @@ void USBDevicePHDCSendData(uint8_t qos, uint8_t *data, uint16_t length, bool mem Conditions: None Remarks: - None + None ************************************************************************/ void USBDevicePHDCTxRXService(USTAT_FIELDS* event); @@ -302,25 +302,25 @@ void USBDevicePHDCTxRXService(USTAT_FIELDS* event); /************************************************************************ Function: void USBDevicePHDCUpdateStatus (uint16_t EndpointNo, bool Status) - + Summary: - USBDevicePHDCUpdateStatus Function Gets the current status of an Endpoint and holds the status in variable phdcEpDataBitmap. The Status is sent to the host upon the - "Get Data Status" request from the host. - + USBDevicePHDCUpdateStatus Function Gets the current status of an Endpoint and holds the status in variable phdcEpDataBitmap. The Status is sent to the host upon the + "Get Data Status" request from the host. + Description: - USBDevicePHDCUpdateStatus Function helps to handle the "Get Data Status" PHDC specfic request received from the Host as mentioned in the - section 7.1.2 of the Personal Healthcare Devices Specification. This function Gets the current status of an Endpoint and holds the status in - variable phdcEpDataBitmap. - + USBDevicePHDCUpdateStatus Function helps to handle the "Get Data Status" PHDC specfic request received from the Host as mentioned in the + section 7.1.2 of the Personal Healthcare Devices Specification. This function Gets the current status of an Endpoint and holds the status in + variable phdcEpDataBitmap. + Input: - uint16_t EndpointNo : The number of the endpoint, for which the status is requested. - - bool Status: Current status of the Endpoint. - + uint16_t EndpointNo : The number of the endpoint, for which the status is requested. + + bool Status: Current status of the Endpoint. + Conditions: None Remarks: - None + None ************************************************************************/ void USBDevicePHDCUpdateStatus (uint16_t EndpointNo, bool Status); #endif //PHDC_H diff --git a/inc/usb_device_phdc_com_model.h b/inc/usb_device_phdc_com_model.h index fb222e4..61d8122 100644 --- a/inc/usb_device_phdc_com_model.h +++ b/inc/usb_device_phdc_com_model.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END diff --git a/inc/usb_hal.h b/inc/usb_hal.h index 416e50c..0a3caf5 100644 --- a/inc/usb_hal.h +++ b/inc/usb_hal.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -36,7 +36,7 @@ please contact mla_licensing@microchip.com #include "usb_hal_pic18.h" #endif #elif defined(__C30__) || defined __XC16__ - #if defined(__dsPIC33E__) + #if defined(__dsPIC33E__) #include "usb_hal_dspic33e.h" #elif defined(__PIC24E__) #include "usb_hal_pic24e.h" @@ -52,7 +52,7 @@ please contact mla_licensing@microchip.com #else #error "Silicon Platform not defined" #endif - + #ifdef __cplusplus // Provide C++ Compatability extern "C" { #endif @@ -131,11 +131,11 @@ please contact mla_licensing@microchip.com /************************************************************************* Function: void USBHALSetBusAddress( uint8_t addr ) - + Description: This routine sets the address of the system on the USB when acting as a peripheral device. - + Preconditions: 1. USBHALInitialize must have been called to initialize the USB HAL. @@ -143,20 +143,20 @@ please contact mla_licensing@microchip.com by calls to USBHALSetEpConfiguration. 3. The system must have been enumerated on the USB (as a device). - + Parameters: addr Desired address of this device on the USB. - + Return Values: None - + Side Effect: The bus address has been set. - + Remarks: The address is assigned by the host and is received in a SET_ADDRESS setup request. - + *************************************************************************/ /* This routine is implemented as a macro to a lower-level level routine. @@ -170,30 +170,30 @@ void USBHALSetBusAddress( uint8_t addr ); /************************************************************************* Function: void USBHALControlUsbResistors( uint8_t flags ); - + Description: This routine enables or disables the USB pull-up or pull-down resistors as requested. - + Precondition: USBInitialize must have been called to initialize the USB SW stack. - + Parameters: flags - This is a bit-mapped flags value indicating which resistors to enable or disable (see below). Return Values: true if successful, false if not. - + Side Effects: The resistors are enabled as requested. - + Remarks: Used for USB peripheral control to connect to or disconnect from the bus. Otherwise, used for OTG SRP/HNP and host support. - + *************************************************************************/ /* @@ -214,21 +214,21 @@ void USBHALSetBusAddress( uint8_t addr ); /************************************************************************* Function: bool USBHALSessionIsValid( void ) - + Description: This routine determines if there is currently a valid USB session or not. - + Precondition: USBInitialize must have been called to initialize the USB SW stack. - + Parameters: None - + Return Values: true if the session is currently valid, false if not. - + Remarks: Only used for host and OTG support. @@ -240,24 +240,24 @@ bool USBHALSessionIsValid( void ); /************************************************************************* Function: USBHALControlBusPower - + Description: This routine provides a bitmap of the most recent error conditions to occur. - + Precondition: USBInitialize must have been called to initialize the USB SW stack. - + Parameters: cmd - Identifies desired command (see below). - + Return Values: true if successful, false if not. - + Remarks: Only used for host and OTG support. - + *************************************************************************/ bool USBHALControlBusPower( uint8_t cmd ); @@ -265,29 +265,29 @@ bool USBHALControlBusPower( uint8_t cmd ); /************************************************************************* Function: unsigned long USBHALGetLastError( void ) - + Description: This routine provides a bitmap of the most recent error conditions to occur. - + Precondition: USBInitialize must have been called to initialize the USB SW stack. - + Parameters: None - + Return Values: Bitmap indicating the most recent error condition(s). - + Side Effect: Error record is cleared. - + Remarks: Although record of the error state is cleared, nothing is done to fix the condition or recover from the error. The client must take appropriate steps. - + *************************************************************************/ unsigned long USBHALGetLastError( void ); @@ -298,7 +298,7 @@ unsigned long USBHALGetLastError( void ); /************************************************************************* Function: void USBHALHandleBusEvent ( void ) - + Description: This routine checks the USB for any events that may have occurred and handles them appropriately. It may @@ -311,16 +311,16 @@ unsigned long USBHALGetLastError( void ); Parameters: None - + Return Values: None - + Side Effects: Depend on the event that may have occurred. - + Remarks: None - + *************************************************************************/ void USBHALHandleBusEvent ( void ); @@ -329,33 +329,33 @@ void USBHALHandleBusEvent ( void ); /************************************************************************* Function: bool USBHALStallPipe( TRANSFER_FLAGS pipe ) - + Description: This routine stalls the given endpoint. Preconditions: USBHALInitialize must have been called to initialize the USB HAL. - + Parameters: pipe - Uses the TRANSFER_FLAGS (see USBCommon.h) format to identify the endpoint and direction making up the pipe to stall. Note: Only ep_num and direction fields are required. - + Return Values: true if able to stall endpoint, false if not. - + Side Effects: The endpoint will stall if additional data transfer is attempted. Given endpoint has been stalled. - + Remarks: Starting another data transfer automatically "un-stalls" the endpoint. - + *************************************************************************/ /* Note: This function is implemented as a macro, calling directly into @@ -370,22 +370,22 @@ bool USBHALStallPipe( TRANSFER_FLAGS pipe ); /****************************************************************************** Function: bool USBHALUnstallPipe( TRANSFER_FLAGS pipe ) - + Description: This routine clears the stall condition for the given pipe. - + PreCondition: Assumes OTGCORE_DeviceEnable has been called and OTGCORE_StallPipe has been called on the given pipe. - + Parameters: pipe - Uses the TRANSFER_FLAGS (see USBCommon.h) format to identify the endpoint and direction making up the pipe to un-stall. - + Return Values: true if able to stall the pipe, false if not. - + Side Effects: The BSTALL and UOWN bits (and all other control bits) in the BDT for the given pipe will be cleared. @@ -407,13 +407,13 @@ bool USBHALUnstallPipe( TRANSFER_FLAGS pipe ); /************************************************************************** Function: USBHALGetStalledEndpoints - + Description: This function returns a 16-bit bit-mapped value with a bit set in the position of any endpoint that is stalled (i.e. if endpoint 0 is stalled then bit 0 is set, if - endpoint 1 is stalled then bit 1 is set, etc.). - + endpoint 1 is stalled then bit 1 is set, etc.). + Preconditions: USBHALInitialize must have been called to initialize the USB HAL. @@ -441,11 +441,11 @@ uint16_t USBHALGetStalledEndpoints ( void ); /****************************************************************************** Function: bool USBHALFlushPipe( TRANSFER_FLAGS pipe ) - + Description: This routine clears any pending transfers on the given pipe. - + Preconditions: USBHALInitialize must have been called to initialize the USB HAL. @@ -478,7 +478,7 @@ bool USBHALFlushPipe( TRANSFER_FLAGS pipe ); /************************************************************************** Function: USBHALTransferData - + Description: This routine prepares to transfer data on the USB. If the system is in device mode, the actual transfer @@ -501,7 +501,7 @@ bool USBHALFlushPipe( TRANSFER_FLAGS pipe ); with one or more flags indicating transfer direction and such (see "Data Transfer Macros" in USBCommon.h): - + 7 6 5 4 3 2 1 0 - Description | | | | \_____/ | | | | +----- Endpoint Number @@ -517,7 +517,7 @@ bool USBHALFlushPipe( TRANSFER_FLAGS pipe ); Return Values: true if the HAL was able to successfully start the data transfer, false if not. - + Side Effects: The HAL has prepared to transfer the data on the USB. @@ -529,7 +529,7 @@ bool USBHALFlushPipe( TRANSFER_FLAGS pipe ); The caller will receive notification that the transfer has completed when the EVT_XFER event is passed into the USBHALBusEventCallout call-out function. - + *************************************************************************/ bool USBHALTransferData ( TRANSFER_FLAGS flags, @@ -540,15 +540,15 @@ bool USBHALTransferData ( TRANSFER_FLAGS flags, /************************************************************************* Function: USBHALSetEpConfiguration - + Description: This routine allows the caller to configure various options (see "Flags for USBHALSetEpConfiguration", below) and set the behavior for the given endpoint. - + Precondition: USBHALInitialize has been called. - + Parameters: ep_num - Number of endpoint to configure, Must be (ep_num >=0) && (ep_num <= USB_DEV_HIGHEST_EP_NUMBER) @@ -559,7 +559,7 @@ bool USBHALTransferData ( TRANSFER_FLAGS flags, Return Values: true if successful, false if not. - + Side Effects: The endpoint has been configured as desired. @@ -577,18 +577,18 @@ bool USBHALSetEpConfiguration ( uint8_t ep_num, uint16_t max_pkt_size, uint16_t /************************************************************************* Function: USBHALInitialize - + Description: This call performs the basic initialization of the USB HAL. This routine must be called before any of the other HAL interface routines are called. - + Precondition: The system has been initialized. - + Parameters: flags - Initialization flags - + Return Values: true if successful, false if not. @@ -597,7 +597,7 @@ bool USBHALSetEpConfiguration ( uint8_t ep_num, uint16_t max_pkt_size, uint16_t Remarks: This routine can be called to reset the controller. - + *************************************************************************/ bool USBHALInitialize ( unsigned long flags ); diff --git a/inc/usb_hal_dspic33e.h b/inc/usb_hal_dspic33e.h index 6b21867..d8f98ef 100644 --- a/inc/usb_hal_dspic33e.h +++ b/inc/usb_hal_dspic33e.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -178,7 +178,7 @@ please contact mla_licensing@microchip.com //----- U1EP bit definitions -------------------------------------------------- #define UEP_STALL 0x0002 // Cfg Control pipe for this ep -#define EP_CTRL 0x0C // Cfg Control pipe for this ep +#define EP_CTRL 0x0C // Cfg Control pipe for this ep #define EP_OUT 0x18 // Cfg OUT only pipe for this ep #define EP_IN 0x14 // Cfg IN only pipe for this ep #define EP_OUT_IN 0x1C // Cfg both OUT & IN pipes for this ep @@ -204,7 +204,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ // Buffer Descriptor Status Register layout. -typedef union __attribute__ ((packed)) _BD_STAT +typedef union __attribute__ ((packed)) _BD_STAT { struct __attribute__ ((packed)){ unsigned :2; //Byte count @@ -237,8 +237,8 @@ typedef union __attribute__ ((packed))__BDT { BD_STAT STAT; uint16_t CNT:10; - uint16_t ADR; - uint16_t ADRH; + uint16_t ADR; + uint16_t ADRH; }; struct __attribute__ ((packed)) { @@ -283,7 +283,7 @@ typedef union _POINTER //byte bUpper; }; uint16_t _word; // bLow & bHigh - + //pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &; uint8_t* bRam; // Ram byte pointer: 2 bytes pointer pointing @@ -310,8 +310,8 @@ typedef union _POINTER #define USBMaskInterrupts() {IEC5bits.USB1IE = 0;} #define USBUnmaskInterrupts() {IEC5bits.USB1IE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif //STALLIE, IDLEIE, TRNIE, and URSTIE are all enabled by default and are required @@ -339,7 +339,7 @@ typedef union _POINTER U1EIE = 0x9F;\ U1IE = 0x99 | USB_SOF_INTERRUPT | USB_ERROR_INTERRUPT;\ USBT1MSECIE = 1;\ - } + } /******************************************************************** @@ -350,11 +350,11 @@ typedef union _POINTER Places the core into sleep and sets up the USB module to wake up the device on USB activity (either USB host resume or USB VBUS going away, such as due to USB cable detach). - + PreCondition: The USBDeviceInit() function should have been called at least once and the USB host should have suspended the USB device. - + Parameters: None @@ -379,44 +379,44 @@ bool USBSleepOnSuspend(void); /**************************************************************** Function: void USBPowerModule(void) - + Description: This macro is used to power up the USB module if required
PIC18: defines as nothing
PIC24: defines as U1PWRCbits.USBPWR = 1;
- + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() U1PWRCbits.USBPWR = 1; /**************************************************************** Function: void USBModuleDisable(void) - + Description: This macro is used to disable the USB module. This will perform a USB soft detach operation from the host, if the device was already plugged into the host at the time of calling this function. All USB module features including the internal USB 1ms timer and the USB VBUS monitoring comparators will be disabled. - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBModuleDisable() {\ U1CON = 0;\ @@ -425,95 +425,95 @@ bool USBSleepOnSuspend(void); U1PWRCbits.USUSPND = 0;\ U1PWRCbits.USBPWR = 0;\ USBDeviceState = DETACHED_STATE;\ -} +} /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) U1BDTP1 = (((unsigned int)addr)/256); /**************************************************************** Function: void USBClearInterruptRegister(int register) - + Description: Clears all of the interrupts in the requested register - + Parameters: register - the regsister that needs to be cleared. - + Return Values: None - + Remarks: Note that on these devices to clear an interrupt you must write a '1' to the interrupt location. - + ****************************************************************/ #define USBClearInterruptRegister(reg) reg = 0xFFFF; /******************************************************************** Function: void USBClearInterruptFlag(register, uint8_t if_flag_offset) - + Summary: Clears the specified USB interrupt flag. - + PreCondition: None - + Parameters: - register - the register mnemonic for the register holding the interrupt + register - the register mnemonic for the register holding the interrupt flag to be cleared uint8_t if_flag_offset - the bit position offset (for the interrupt flag to clear) from the "right of the register" - + Return Values: None - + Remarks: - Individual USB interrupt flag bits are cleared by writing '1' to the + Individual USB interrupt flag bits are cleared by writing '1' to the bit, in a word write operation. - + *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) +#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) /******************************************************************** Function: void DisableNonZeroEndpoints(UINT8 last_ep_num) - + Summary: Clears the control registers for the specified non-zero endpoints - + PreCondition: None - + Parameters: UINT8 last_ep_num - the last endpoint number to clear. This number should include all endpoints used in any configuration. - + Return Values: None - + Remarks: None - + *******************************************************************/ -#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); +#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); /******************************************************************** @@ -706,7 +706,7 @@ void USBRestoreUSBInterrupts(void); extern USB_VOLATILE OUT_PIPE outPipes[1]; #endif extern volatile BDT_ENTRY* pBDTEntryOut[USB_MAX_EP_NUMBER+1]; - extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; + extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; #endif #endif //USB_HAL_DSPIC33E_H diff --git a/inc/usb_hal_pic16f1.h b/inc/usb_hal_pic16f1.h index d683c8d..f26406f 100644 --- a/inc/usb_hal_pic16f1.h +++ b/inc/usb_hal_pic16f1.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -45,7 +45,7 @@ please contact mla_licensing@microchip.com // ***************************************************************************** #define USB_HAL_VBUSTristate() //No dedicated VBUS pin on these devices. - + //----- USBEnableEndpoint() input definitions ---------------------------------- #define USB_HANDSHAKE_ENABLED 0x10 #define USB_HANDSHAKE_DISABLED 0x00 @@ -217,7 +217,7 @@ please contact mla_licensing@microchip.com // Section: Data Types // ***************************************************************************** // ***************************************************************************** - + // Buffer Descriptor Status Register layout. typedef union _BD_STAT { @@ -298,7 +298,7 @@ typedef union _POINTER //byte bUpper; }; uint16_t _word; // bLow & bHigh - + //pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &; uint8_t* bRam; // Ram byte pointer: 2 bytes pointer pointing @@ -325,8 +325,8 @@ typedef union _POINTER #define USBMaskInterrupts() {PIE2bits.USBIE = 0;} #define USBUnmaskInterrupts() {PIE2bits.USBIE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif #define USBInterruptFlag PIR2bits.USBIF @@ -344,68 +344,68 @@ typedef union _POINTER U1CNFG1 = USB_PULLUP_OPTION | USB_TRANSCEIVER_OPTION | USB_SPEED_OPTION | USB_PING_PONG_MODE;\ U1EIE = 0x9F;\ UIE = 0x39 | USB_SOF_INTERRUPT | USB_ERROR_INTERRUPT;\ - } + } /**************************************************************** Function: void USBPowerModule(void) - + Description: This macro is used to power up the USB module if required
PIC18: defines as nothing
PIC24: defines as U1PWRCbits.USBPWR = 1;
- + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() /**************************************************************** Function: void USBModuleDisable(void) - + Description: This macro is used to disable the USB module - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBModuleDisable() {\ UCON = 0;\ UIE = 0;\ USBDeviceState = DETACHED_STATE;\ -} +} /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) @@ -414,8 +414,8 @@ typedef union _POINTER * * PreCondition: None * - * Input: - * register - the register mnemonic for the register holding the interrupt + * Input: + * register - the register mnemonic for the register holding the interrupt flag to be cleared * uint8_t if_and_flag_mask - an AND mask for the interrupt flag that will be cleared @@ -426,49 +426,49 @@ typedef union _POINTER * * Overview: Clears the specified USB interrupt flag. * - * Note: + * Note: *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_and_flag_mask) (reg_name &= if_and_flag_mask) +#define USBClearInterruptFlag(reg_name, if_and_flag_mask) (reg_name &= if_and_flag_mask) /******************************************************************** Function: void USBClearInterruptRegister(uint16_t reg) - + Summary: Clears the specified interrupt register - + PreCondition: None - + Parameters: uint16_t reg - the register name that needs to be cleared - + Return Values: None - + Remarks: None - + *******************************************************************/ #define USBClearInterruptRegister(reg) {reg = 0;} /******************************************************************** Function: void DisableNonZeroEndpoints(UINT8 last_ep_num) - + Summary: Clears the control registers for the specified non-zero endpoints - + PreCondition: None - + Parameters: UINT8 last_ep_num - the last endpoint number to clear. This number should include all endpoints used in any configuration. - + Return Values: None - + Remarks: None *******************************************************************/ diff --git a/inc/usb_hal_pic18.h b/inc/usb_hal_pic18.h index 3e81499..3235e02 100644 --- a/inc/usb_hal_pic18.h +++ b/inc/usb_hal_pic18.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -58,8 +58,8 @@ please contact mla_licensing@microchip.com // Section: Constants // ***************************************************************************** // ***************************************************************************** -#define USB_HAL_VBUSTristate() //No dedicated VBUS pin on these devices. - +#define USB_HAL_VBUSTristate() //No dedicated VBUS pin on these devices. + //----- USBEnableEndpoint() input definitions ---------------------------------- #define USB_HANDSHAKE_ENABLED 0x10 #define USB_HANDSHAKE_DISABLED 0x00 @@ -252,7 +252,7 @@ please contact mla_licensing@microchip.com // Section: Data Types // ***************************************************************************** // ***************************************************************************** - + // Buffer Descriptor Status Register layout. typedef union _BD_STAT { @@ -333,7 +333,7 @@ typedef union _POINTER //byte bUpper; }; uint16_t _word; // bLow & bHigh - + //pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &; uint8_t* bRam; // Ram byte pointer: 2 bytes pointer pointing @@ -368,21 +368,21 @@ typedef union _POINTER #define USBMaskInterrupts() {PIE3bits.USBIE = 0;} #define USBUnmaskInterrupts() {PIE3bits.USBIE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif - + #define USBInterruptFlag PIR3bits.USBIF - + //STALLIE, IDLEIE, TRNIE, and URSTIE are all enabled by default and are required #if defined(USB_INTERRUPT) #define USBEnableInterrupts() {RCONbits.IPEN = 1;IPR3bits.USBIP = 1;PIE3bits.USBIE = 1;INTCONbits.GIEH = 1;} #else #define USBEnableInterrupts() #endif - + #define USBDisableInterrupts() {PIE3bits.USBIE = 0;} - + #define SetConfigurationOptions() {\ U1CNFG1 = USB_PULLUP_OPTION | USB_TRANSCEIVER_OPTION | USB_SPEED_OPTION | USB_PING_PONG_MODE;\ U1EIE = 0x9F;\ @@ -398,26 +398,26 @@ typedef union _POINTER #define USBMaskInterrupts() {PIE2bits.USBIE = 0;} #define USBUnmaskInterrupts() {PIE2bits.USBIE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif - + #define USBInterruptFlag PIR2bits.USBIF - + //STALLIE, IDLEIE, TRNIE, and URSTIE are all enabled by default and are required #if defined(USB_INTERRUPT) #define USBEnableInterrupts() {PIE2bits.USBIE = 1;INTCONbits.PEIE = 1;INTCONbits.GIE = 1;} #else #define USBEnableInterrupts() #endif - + #define USBDisableInterrupts() {PIE2bits.USBIE = 0;} - + #define SetConfigurationOptions() {\ U1CNFG1 = USB_PULLUP_OPTION | USB_TRANSCEIVER_OPTION | USB_SPEED_OPTION | USB_PING_PONG_MODE;\ U1EIE = 0x9F;\ UIE = 0x39 | USB_SOF_INTERRUPT | USB_ERROR_INTERRUPT;\ - } + } #else //------------------------------------------------------------------------------ //This section is for all other PIC18 USB microcontrollers @@ -427,26 +427,26 @@ typedef union _POINTER #define USBMaskInterrupts() {PIE2bits.USBIE = 0;} #define USBUnmaskInterrupts() {PIE2bits.USBIE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif - + #define USBInterruptFlag PIR2bits.USBIF - + //STALLIE, IDLEIE, TRNIE, and URSTIE are all enabled by default and are required #if defined(USB_INTERRUPT) #define USBEnableInterrupts() {RCONbits.IPEN = 1;IPR2bits.USBIP = 1;PIE2bits.USBIE = 1;INTCONbits.GIEH = 1;} #else #define USBEnableInterrupts() #endif - + #define USBDisableInterrupts() {PIE2bits.USBIE = 0;} - + #define SetConfigurationOptions() {\ U1CNFG1 = USB_PULLUP_OPTION | USB_TRANSCEIVER_OPTION | USB_SPEED_OPTION | USB_PING_PONG_MODE;\ U1EIE = 0x9F;\ UIE = 0x39 | USB_SOF_INTERRUPT | USB_ERROR_INTERRUPT;\ - } + } #endif //end of #if defined(__18F45K50) || defined(__18F25K50)... //------------------------------------------------------------------------------ @@ -454,63 +454,63 @@ typedef union _POINTER /**************************************************************** Function: void USBPowerModule(void) - + Description: This macro is used to power up the USB module if required
PIC18: defines as nothing
PIC24: defines as U1PWRCbits.USBPWR = 1;
- + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() /**************************************************************** Function: void USBModuleDisable(void) - + Description: This macro is used to disable the USB module - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBModuleDisable() {\ UCON = 0;\ UIE = 0;\ USBDeviceState = DETACHED_STATE;\ -} +} /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) @@ -519,8 +519,8 @@ typedef union _POINTER * * PreCondition: None * - * Input: - * register - the register mnemonic for the register holding the interrupt + * Input: + * register - the register mnemonic for the register holding the interrupt flag to be cleared * uint8_t if_and_flag_mask - an AND mask for the interrupt flag that will be cleared @@ -531,52 +531,52 @@ typedef union _POINTER * * Overview: Clears the specified USB interrupt flag. * - * Note: + * Note: *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_and_flag_mask) (reg_name &= if_and_flag_mask) +#define USBClearInterruptFlag(reg_name, if_and_flag_mask) (reg_name &= if_and_flag_mask) /******************************************************************** Function: void USBClearInterruptRegister(uint16_t reg) - + Summary: Clears the specified interrupt register - + PreCondition: None - + Parameters: uint16_t reg - the register name that needs to be cleared - + Return Values: None - + Remarks: None - + *******************************************************************/ #define USBClearInterruptRegister(reg) {reg = 0;} /******************************************************************** Function: void DisableNonZeroEndpoints(UINT8 last_ep_num) - + Summary: Clears the control registers for the specified non-zero endpoints - + PreCondition: None - + Parameters: UINT8 last_ep_num - the last endpoint number to clear. This number should include all endpoints used in any configuration. - + Return Values: None - + Remarks: None - + *******************************************************************/ #define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num)); diff --git a/inc/usb_hal_pic24.h b/inc/usb_hal_pic24.h index 054cb49..992df55 100644 --- a/inc/usb_hal_pic24.h +++ b/inc/usb_hal_pic24.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -38,7 +38,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ -//Device specific IECx register count. Useful during interrupt context save and +//Device specific IECx register count. Useful during interrupt context save and //restore operations (such as prior to and after entering sleep on suspend). //IEC0-IEC5 on PIC24FJ64GB004 Family devices //IEC0-IEC5 on PIC24FJ256GB110 Family devices @@ -48,7 +48,7 @@ please contact mla_licensing@microchip.com //IEC0-IEC7 on PIC24FJ128GB204 Family devices //IEC0-IEC7 on PIC24FJ256GB412 Family devices #if defined(__PIC24FJ64GB004__) || defined(__PIC24FJ32GB004__) || defined(__PIC24FJ32GB004__) || defined(__PIC24FJ32GB002__) \ - || defined(__PIC24FJ256GB110__) || defined(__PIC24FJ192GB110__) || defined(__PIC24FJ128GB110__) || defined(__PIC24FJ64GB110__) || defined(__PIC24FJ256GB108__) || defined(__PIC24FJ192GB108__) || defined(__PIC24FJ128GB108__) || defined(__PIC24FJ64GB108__) || defined(__PIC24FJ256GB106__) || defined(__PIC24FJ192GB106__) || defined(__PIC24FJ128GB106__) || defined(__PIC24FJ64GB106__) + || defined(__PIC24FJ256GB110__) || defined(__PIC24FJ192GB110__) || defined(__PIC24FJ128GB110__) || defined(__PIC24FJ64GB110__) || defined(__PIC24FJ256GB108__) || defined(__PIC24FJ192GB108__) || defined(__PIC24FJ128GB108__) || defined(__PIC24FJ64GB108__) || defined(__PIC24FJ256GB106__) || defined(__PIC24FJ192GB106__) || defined(__PIC24FJ128GB106__) || defined(__PIC24FJ64GB106__) #define DEVICE_SPECIFIC_IEC_REGISTER_COUNT 6 //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() //No GPIO driver on VBUS on these devices. @@ -227,7 +227,7 @@ please contact mla_licensing@microchip.com //----- U1EP bit definitions -------------------------------------------------- #define UEP_STALL 0x0002 // Cfg Control pipe for this ep -#define EP_CTRL 0x0C +#define EP_CTRL 0x0C #define BDT_BASE_ADDR_TAG __attribute__ ((aligned (512))) @@ -321,7 +321,7 @@ typedef union _POINTER //byte bUpper; }; uint16_t _word; // bLow & bHigh - + //pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &; uint8_t* bRam; // Ram byte pointer: 2 bytes pointer pointing @@ -348,8 +348,8 @@ typedef union _POINTER #define USBMaskInterrupts() {IEC5bits.USB1IE = 0;} #define USBUnmaskInterrupts() {IEC5bits.USB1IE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif //STALLIE, IDLEIE, TRNIE, and URSTIE are all enabled by default and are required @@ -377,7 +377,7 @@ typedef union _POINTER U1EIE = 0x9F;\ U1IE = 0x99 | USB_SOF_INTERRUPT | USB_ERROR_INTERRUPT;\ USBT1MSECIE = 1;\ - } + } /******************************************************************** @@ -388,11 +388,11 @@ typedef union _POINTER Places the core into sleep and sets up the USB module to wake up the device on USB activity (either USB host resume or USB VBUS going away, such as due to USB cable detach). - + PreCondition: The USBDeviceInit() function should have been called at least once and the USB host should have suspended the USB device. - + Parameters: None @@ -417,44 +417,44 @@ bool USBSleepOnSuspend(void); /**************************************************************** Function: void USBPowerModule(void) - + Description: This macro is used to power up the USB module if required
PIC18: defines as nothing
PIC24: defines as U1PWRCbits.USBPWR = 1;
- + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() U1PWRCbits.USBPWR = 1; /**************************************************************** Function: void USBModuleDisable(void) - + Description: This macro is used to disable the USB module. This will perform a USB soft detach operation from the host, if the device was already plugged into the host at the time of calling this function. All USB module features including the internal USB 1ms timer and the USB VBUS monitoring comparators will be disabled. - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBModuleDisable() {\ U1CON = 0;\ @@ -463,95 +463,95 @@ bool USBSleepOnSuspend(void); U1PWRCbits.USUSPND = 0;\ U1PWRCbits.USBPWR = 0;\ USBDeviceState = DETACHED_STATE;\ -} +} /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) U1BDTP1 = (((unsigned int)addr)/256); /**************************************************************** Function: void USBClearInterruptRegister(int register) - + Description: Clears all of the interrupts in the requested register - + Parameters: register - the register that needs to be cleared. - + Return Values: None - + Remarks: Note that on these devices to clear an interrupt you must write a '1' to the interrupt location. - + ****************************************************************/ #define USBClearInterruptRegister(reg) reg = 0xFFFF; /******************************************************************** Function: void USBClearInterruptFlag(register, uint8_t if_flag_offset) - + Summary: Clears the specified USB interrupt flag. - + PreCondition: None - + Parameters: - register - the register mnemonic for the register holding the interrupt + register - the register mnemonic for the register holding the interrupt flag to be cleared uint8_t if_flag_offset - the bit position offset (for the interrupt flag to clear) from the "right of the register" - + Return Values: None - + Remarks: - Individual USB interrupt flag bits are cleared by writing '1' to the + Individual USB interrupt flag bits are cleared by writing '1' to the bit, in a word write operation. - + *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) +#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) /******************************************************************** Function: void DisableNonZeroEndpoints(UINT8 last_ep_num) - + Summary: Clears the control registers for the specified non-zero endpoints - + PreCondition: None - + Parameters: UINT8 last_ep_num - the last endpoint number to clear. This number should include all endpoints used in any configuration. - + Return Values: None - + Remarks: None - + *******************************************************************/ -#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); +#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); /******************************************************************** @@ -744,7 +744,7 @@ void USBRestoreUSBInterrupts(void); extern USB_VOLATILE OUT_PIPE outPipes[1]; #endif extern volatile BDT_ENTRY* pBDTEntryOut[USB_MAX_EP_NUMBER+1]; - extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; + extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; #endif #endif //USB_HAL_PIC24F_H diff --git a/inc/usb_hal_pic24e.h b/inc/usb_hal_pic24e.h index da0bdb8..1d2f9dc 100644 --- a/inc/usb_hal_pic24e.h +++ b/inc/usb_hal_pic24e.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -177,7 +177,7 @@ please contact mla_licensing@microchip.com //----- U1EP bit definitions -------------------------------------------------- #define UEP_STALL 0x0002 // Cfg Control pipe for this ep -#define EP_CTRL 0x0C // Cfg Control pipe for this ep +#define EP_CTRL 0x0C // Cfg Control pipe for this ep #define EP_OUT 0x18 // Cfg OUT only pipe for this ep #define EP_IN 0x14 // Cfg IN only pipe for this ep #define EP_OUT_IN 0x1C // Cfg both OUT & IN pipes for this ep @@ -203,7 +203,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ // Buffer Descriptor Status Register layout. -typedef union __attribute__ ((packed)) _BD_STAT +typedef union __attribute__ ((packed)) _BD_STAT { struct __attribute__ ((packed)){ unsigned :2; //Byte count @@ -236,8 +236,8 @@ typedef union __attribute__ ((packed))__BDT { BD_STAT STAT; uint16_t CNT:10; - uint16_t ADR; - uint16_t ADRH; + uint16_t ADR; + uint16_t ADRH; }; struct __attribute__ ((packed)) { @@ -282,7 +282,7 @@ typedef union _POINTER //byte bUpper; }; uint16_t _word; // bLow & bHigh - + //pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &; uint8_t* bRam; // Ram byte pointer: 2 bytes pointer pointing @@ -309,8 +309,8 @@ typedef union _POINTER #define USBMaskInterrupts() {IEC5bits.USB1IE = 0;} #define USBUnmaskInterrupts() {IEC5bits.USB1IE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif //STALLIE, IDLEIE, TRNIE, and URSTIE are all enabled by default and are required @@ -338,7 +338,7 @@ typedef union _POINTER U1EIE = 0x9F;\ U1IE = 0x99 | USB_SOF_INTERRUPT | USB_ERROR_INTERRUPT;\ USBT1MSECIE = 1;\ - } + } /******************************************************************** @@ -349,11 +349,11 @@ typedef union _POINTER Places the core into sleep and sets up the USB module to wake up the device on USB activity (either USB host resume or USB VBUS going away, such as due to USB cable detach). - + PreCondition: The USBDeviceInit() function should have been called at least once and the USB host should have suspended the USB device. - + Parameters: None @@ -378,44 +378,44 @@ bool USBSleepOnSuspend(void); /**************************************************************** Function: void USBPowerModule(void) - + Description: This macro is used to power up the USB module if required
PIC18: defines as nothing
PIC24: defines as U1PWRCbits.USBPWR = 1;
- + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() U1PWRCbits.USBPWR = 1; /**************************************************************** Function: void USBModuleDisable(void) - + Description: This macro is used to disable the USB module. This will perform a USB soft detach operation from the host, if the device was already plugged into the host at the time of calling this function. All USB module features including the internal USB 1ms timer and the USB VBUS monitoring comparators will be disabled. - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBModuleDisable() {\ U1CON = 0;\ @@ -424,95 +424,95 @@ bool USBSleepOnSuspend(void); U1PWRCbits.USUSPND = 0;\ U1PWRCbits.USBPWR = 0;\ USBDeviceState = DETACHED_STATE;\ -} +} /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) U1BDTP1 = (((unsigned int)addr)/256); /**************************************************************** Function: void USBClearInterruptRegister(int register) - + Description: Clears all of the interrupts in the requested register - + Parameters: register - the register that needs to be cleared. - + Return Values: None - + Remarks: Note that on these devices to clear an interrupt you must write a '1' to the interrupt location. - + ****************************************************************/ #define USBClearInterruptRegister(reg) reg = 0xFFFF; /******************************************************************** Function: void USBClearInterruptFlag(register, uint8_t if_flag_offset) - + Summary: Clears the specified USB interrupt flag. - + PreCondition: None - + Parameters: - register - the register mnemonic for the register holding the interrupt + register - the register mnemonic for the register holding the interrupt flag to be cleared uint8_t if_flag_offset - the bit position offset (for the interrupt flag to clear) from the "right of the register" - + Return Values: None - + Remarks: - Individual USB interrupt flag bits are cleared by writing '1' to the + Individual USB interrupt flag bits are cleared by writing '1' to the bit, in a word write operation. - + *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) +#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) /******************************************************************** Function: void DisableNonZeroEndpoints(uint8_t last_ep_num) - + Summary: Clears the control registers for the specified non-zero endpoints - + PreCondition: None - + Parameters: uint8_t last_ep_num - the last endpoint number to clear. This number should include all endpoints used in any configuration. - + Return Values: None - + Remarks: None - + *******************************************************************/ -#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); +#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); /******************************************************************** @@ -705,7 +705,7 @@ void USBRestoreUSBInterrupts(void); extern USB_VOLATILE OUT_PIPE outPipes[1]; #endif extern volatile BDT_ENTRY* pBDTEntryOut[USB_MAX_EP_NUMBER+1]; - extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; + extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; #endif #endif //USB_HAL_PIC24E_H diff --git a/inc/usb_hal_pic24f.h b/inc/usb_hal_pic24f.h index 7d4e7bf..d1ddbfb 100644 --- a/inc/usb_hal_pic24f.h +++ b/inc/usb_hal_pic24f.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -39,7 +39,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ -//Device specific IECx register count. Useful during interrupt context save and +//Device specific IECx register count. Useful during interrupt context save and //restore operations (such as prior to and after entering sleep on suspend). //IEC0-IEC5 on PIC24FJ64GB004 Family devices //IEC0-IEC5 on PIC24FJ256GB110 Family devices @@ -49,7 +49,7 @@ please contact mla_licensing@microchip.com //IEC0-IEC7 on PIC24FJ128GB204 Family devices //IEC0-IEC7 on PIC24FJ256GB412 Family devices #if defined(__PIC24FJ64GB004__) || defined(__PIC24FJ64GB002__) || defined(__PIC24FJ32GB004__) || defined(__PIC24FJ32GB002__) \ - || defined(__PIC24FJ256GB110__) || defined(__PIC24FJ192GB110__) || defined(__PIC24FJ128GB110__) || defined(__PIC24FJ64GB110__) || defined(__PIC24FJ256GB108__) || defined(__PIC24FJ192GB108__) || defined(__PIC24FJ128GB108__) || defined(__PIC24FJ64GB108__) || defined(__PIC24FJ256GB106__) || defined(__PIC24FJ192GB106__) || defined(__PIC24FJ128GB106__) || defined(__PIC24FJ64GB106__) + || defined(__PIC24FJ256GB110__) || defined(__PIC24FJ192GB110__) || defined(__PIC24FJ128GB110__) || defined(__PIC24FJ64GB110__) || defined(__PIC24FJ256GB108__) || defined(__PIC24FJ192GB108__) || defined(__PIC24FJ128GB108__) || defined(__PIC24FJ64GB108__) || defined(__PIC24FJ256GB106__) || defined(__PIC24FJ192GB106__) || defined(__PIC24FJ128GB106__) || defined(__PIC24FJ64GB106__) #define DEVICE_SPECIFIC_IEC_REGISTER_COUNT 6 //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() //No GPIO driver on VBUS on these devices. @@ -231,7 +231,7 @@ please contact mla_licensing@microchip.com //----- U1EP bit definitions -------------------------------------------------- #define UEP_STALL 0x0002 // Cfg Control pipe for this ep -#define EP_CTRL 0x0C +#define EP_CTRL 0x0C #define BDT_BASE_ADDR_TAG __attribute__ ((aligned (512))) @@ -325,7 +325,7 @@ typedef union _POINTER //byte bUpper; }; uint16_t _word; // bLow & bHigh - + //pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &; uint8_t* bRam; // Ram byte pointer: 2 bytes pointer pointing @@ -352,8 +352,8 @@ typedef union _POINTER #define USBMaskInterrupts() {IEC5bits.USB1IE = 0;} #define USBUnmaskInterrupts() {IEC5bits.USB1IE = 1;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif //STALLIE, IDLEIE, TRNIE, and URSTIE are all enabled by default and are required @@ -381,7 +381,7 @@ typedef union _POINTER U1EIE = 0x9F;\ U1IE = 0x99 | USB_SOF_INTERRUPT | USB_ERROR_INTERRUPT;\ USBT1MSECIE = 1;\ - } + } /******************************************************************** @@ -392,11 +392,11 @@ typedef union _POINTER Places the core into sleep and sets up the USB module to wake up the device on USB activity (either USB host resume or USB VBUS going away, such as due to USB cable detach). - + PreCondition: The USBDeviceInit() function should have been called at least once and the USB host should have suspended the USB device. - + Parameters: None @@ -421,44 +421,44 @@ bool USBSleepOnSuspend(void); /**************************************************************** Function: void USBPowerModule(void) - + Description: This macro is used to power up the USB module if required
PIC18: defines as nothing
PIC24: defines as U1PWRCbits.USBPWR = 1;
- + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() U1PWRCbits.USBPWR = 1; /**************************************************************** Function: void USBModuleDisable(void) - + Description: This macro is used to disable the USB module. This will perform a USB soft detach operation from the host, if the device was already plugged into the host at the time of calling this function. All USB module features including the internal USB 1ms timer and the USB VBUS monitoring comparators will be disabled. - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBModuleDisable() {\ U1CON = 0;\ @@ -467,95 +467,95 @@ bool USBSleepOnSuspend(void); U1PWRCbits.USUSPND = 0;\ U1PWRCbits.USBPWR = 0;\ USBDeviceState = DETACHED_STATE;\ -} +} /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) U1BDTP1 = (((unsigned int)addr)/256); /**************************************************************** Function: void USBClearInterruptRegister(int register) - + Description: Clears all of the interrupts in the requested register - + Parameters: register - the register that needs to be cleared. - + Return Values: None - + Remarks: Note that on these devices to clear an interrupt you must write a '1' to the interrupt location. - + ****************************************************************/ #define USBClearInterruptRegister(reg) reg = 0xFFFF; /******************************************************************** Function: void USBClearInterruptFlag(register, uint8_t if_flag_offset) - + Summary: Clears the specified USB interrupt flag. - + PreCondition: None - + Parameters: - register - the register mnemonic for the register holding the interrupt + register - the register mnemonic for the register holding the interrupt flag to be cleared uint8_t if_flag_offset - the bit position offset (for the interrupt flag to clear) from the "right of the register" - + Return Values: None - + Remarks: - Individual USB interrupt flag bits are cleared by writing '1' to the + Individual USB interrupt flag bits are cleared by writing '1' to the bit, in a word write operation. - + *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) +#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) /******************************************************************** Function: void DisableNonZeroEndpoints(UINT8 last_ep_num) - + Summary: Clears the control registers for the specified non-zero endpoints - + PreCondition: None - + Parameters: UINT8 last_ep_num - the last endpoint number to clear. This number should include all endpoints used in any configuration. - + Return Values: None - + Remarks: None - + *******************************************************************/ -#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); +#define DisableNonZeroEndpoints(last_ep_num) memset((void*)&U1EP1,0x00,(last_ep_num * 2)); /******************************************************************** @@ -748,7 +748,7 @@ void USBRestoreUSBInterrupts(void); extern USB_VOLATILE OUT_PIPE outPipes[1]; #endif extern volatile BDT_ENTRY* pBDTEntryOut[USB_MAX_EP_NUMBER+1]; - extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; + extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; #endif #endif //USB_HAL_PIC24F_H diff --git a/inc/usb_hal_pic32mm.h b/inc/usb_hal_pic32mm.h index 415ca52..d97542f 100644 --- a/inc/usb_hal_pic32mm.h +++ b/inc/usb_hal_pic32mm.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -36,7 +36,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ -//Device specific IECx register count. Useful during interrupt context save and +//Device specific IECx register count. Useful during interrupt context save and //restore operations (such as prior to and after entering sleep on suspend). #if defined(__32MM0256GPM064__) || defined(__32MM0128GPM064__) || defined(__32MM0064GPM064__) || \ defined(__32MM0256GPM048__) || defined(__32MM0128GPM048__) || defined(__32MM0064GPM048__) || \ @@ -44,7 +44,7 @@ please contact mla_licensing@microchip.com defined(__32MM0256GPM028__) || defined(__32MM0128GPM028__) || defined(__32MM0064PM028__) #define DEVICE_SPECIFIC_IEC_REGISTER_COUNT 4 //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() {TRISBbits.TRISB6 = 1;} + #define USB_HAL_VBUSTristate() {TRISBbits.TRISB6 = 1;} #else #warning "Add processor specific definitions here." @@ -181,8 +181,8 @@ please contact mla_licensing@microchip.com #define USBMaskInterrupts() {IEC0CLR = _IEC0_USBIE_MASK;} #define USBUnmaskInterrupts() {IEC0SET = _IEC0_USBIE_MASK;} #else - #define USBMaskInterrupts() - #define USBUnmaskInterrupts() + #define USBMaskInterrupts() + #define USBUnmaskInterrupts() #endif @@ -211,7 +211,7 @@ please contact mla_licensing@microchip.com //----- U1EP bit definitions -------------------------------------------------- #define UEP_STALL 0x0002 // Cfg Control pipe for this ep -#define EP_CTRL 0x0C +#define EP_CTRL 0x0C #define EP_OUT 0x18 // Cfg OUT only pipe for this ep #define EP_IN 0x14 // Cfg IN only pipe for this ep #define EP_OUT_IN 0x1C // Cfg both OUT & IN pipes for this ep @@ -237,7 +237,7 @@ please contact mla_licensing@microchip.com /*****************************************************************************/ // Buffer Descriptor Status Register layout. -typedef union __attribute__ ((packed)) _BD_STAT +typedef union __attribute__ ((packed)) _BD_STAT { struct __attribute__ ((packed)){ unsigned :2; @@ -309,7 +309,7 @@ typedef union _POINTER //uint8_t bUpper; }; uint16_t _uint16_t; // bLow & bHigh - + //pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &; uint8_t* bRam; // Ram byte pointer: 2 bytes pointer pointing @@ -336,11 +336,11 @@ typedef union _POINTER #if defined(__PIC32__) #if defined(_IFS1_USBIF_MASK) #define _ClearUSBIF() {IFS1CLR = _ISF1_USBIF_MASK;} - #define _SetUSBIF() {IEC1SET = _IEC1_USBIE_MASK;} - #define USBClearUSBInterrupt() {IFS1CLR = _IFS1_USBIF_MASK;} + #define _SetUSBIF() {IEC1SET = _IEC1_USBIE_MASK;} + #define USBClearUSBInterrupt() {IFS1CLR = _IFS1_USBIF_MASK;} #elif defined(_IFS0_USBIF_MASK) #define _ClearUSBIF() {IFS0CLR = _IFS0_USBIF_MASK;} - #define _SetUSBIE() {IEC0SET = _IEC0_USBIE_MASK;} + #define _SetUSBIE() {IEC0SET = _IEC0_USBIE_MASK;} #define USBClearUSBInterrupt() {IFS0CLR = _IFS0_USBIF_MASK;} #else #error Cannot clear USB interrupt. @@ -366,10 +366,10 @@ typedef union _POINTER * * PreCondition: None * - * Input: - * register - the register mnemonic for the register holding the interrupt + * Input: + * register - the register mnemonic for the register holding the interrupt * flag to be "kleared" - * uint8_t if_flag_offset - the bit position offset (for the interrupt flag to + * uint8_t if_flag_offset - the bit position offset (for the interrupt flag to * "klear") fconst the "right of the register" * * Output: None @@ -381,11 +381,11 @@ typedef union _POINTER * Note: Individual USB interrupt flag bits are "Kleared" by writing * '1' to the bit *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) +#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) + + - - #if !defined(Sleep) #define REGISTER_UNLOCK_SEQUENCE() {SYSKEY = 0; SYSKEY = 0xAA996655; SYSKEY = 0x556699AA;} #define REGISTER_LOCK_SEQUENCE() {SYSKEY = 0;} @@ -405,11 +405,11 @@ typedef union _POINTER Places the core into sleep and sets up the USB module to wake up the device on USB activity (either USB host resume or USB VBUS going away, such as due to USB cable detach). - + PreCondition: The USBDeviceInit() function should have been called at least once and the USB host should have suspended the USB device. - + Parameters: None @@ -434,46 +434,46 @@ bool USBSleepOnSuspend(void); /**************************************************************** Function: void USBPowerModule(void) - + Description: This macro is used to power up the USB module if required: PIC16: defines as nothing PIC18: defines as nothing PIC24: defines as U1PWRCbits.USBPWR = 1; PIC32: defines as U1PWRCbits.USBPWR = 1; - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() U1PWRCbits.USBPWR = 1; /**************************************************************** Function: void USBModuleDisable(void) - + Description: This macro is used to disable the USB module. This will perform a USB soft detach operation from the host, if the device was already plugged into the host at the time of calling this function. All USB module features including the internal USB 1ms timer and the USB VBUS monitoring comparators will be disabled. - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBModuleDisable() {\ U1CON = 0;\ @@ -482,93 +482,93 @@ bool USBSleepOnSuspend(void); U1PWRCbits.USUSPND = 0;\ U1PWRCbits.USBPWR = 0;\ USBDeviceState = DETACHED_STATE;\ -} +} /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) {U1BDTP3 = (((uint32_t)KVA_TO_PA(addr)) >> 24); U1BDTP2 = (((uint32_t)KVA_TO_PA(addr)) >> 16); U1BDTP1 = (((uint32_t)KVA_TO_PA(addr)) >> 8);} /**************************************************************** Function: void USBClearInterruptRegister(int register) - + Description: Clears all of the interrupts in the requested register - + Parameters: register - the register that needs to be cleared. - + Return Values: None - + Remarks: Note that on these devices to clear an interrupt you must write a '1' to the interrupt location. - + ****************************************************************/ #define USBClearInterruptRegister(reg) {reg = 0xFFFFFFFF;} /******************************************************************** Function: void USBClearInterruptFlag(register, uint8_t if_flag_offset) - + Summary: Clears the specified USB interrupt flag. - + PreCondition: None - + Parameters: - register - the register mnemonic for the register holding the interrupt + register - the register mnemonic for the register holding the interrupt flag to be cleared uint8_t if_flag_offset - the bit position offset (for the interrupt flag to clear) from the "right of the register" - + Return Values: None - + Remarks: - Individual USB interrupt flag bits are cleared by writing '1' to the + Individual USB interrupt flag bits are cleared by writing '1' to the bit, in a word write operation. - + *******************************************************************/ -#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) +#define USBClearInterruptFlag(reg_name, if_flag_offset) (reg_name = (1 << if_flag_offset)) /******************************************************************** Function: void DisableNonZeroEndpoints(UINT8 last_ep_num) - + Summary: Clears the control registers for the specified non-zero endpoints - + PreCondition: None - + Parameters: UINT8 last_ep_num - the last endpoint number to clear. This number should include all endpoints used in any configuration. - + Return Values: None - + Remarks: None - + *******************************************************************/ #define DisableNonZeroEndpoints(last_ep_num) {\ uint8_t i;\ @@ -770,7 +770,7 @@ void USBRestoreUSBInterrupts(void); extern USB_VOLATILE OUT_PIPE outPipes[1]; #endif extern volatile BDT_ENTRY* pBDTEntryOut[USB_MAX_EP_NUMBER+1]; - extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; + extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1]; #endif #endif //USB_HAL_PIC32MM_H diff --git a/inc/usb_hid.h b/inc/usb_hid.h index 23a69e4..ad7a582 100644 --- a/inc/usb_hid.h +++ b/inc/usb_hid.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END diff --git a/inc/usb_host.h b/inc/usb_host.h index a936467..e083a05 100644 --- a/inc/usb_host.h +++ b/inc/usb_host.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -175,9 +175,9 @@ This requires a tighter integration between the host layer and the application layer to manage the streaming data. If an application uses isochronous transfers, it must allocate one variable -of type ISOCHRONOUS_DATA for each concurrent transfer. When the device +of type ISOCHRONOUS_DATA for each concurrent transfer. When the device attaches, the client driver must inform the application layer of the maximum -transfer size. At this point, the application must allocate space for the +transfer size. At this point, the application must allocate space for the data buffers, and set the data buffer points in this structure to point to them. */ @@ -194,10 +194,10 @@ typedef struct _ISOCHRONOUS_DATA uint8_t currentBufferUSB; // The current buffer the USB peripheral is accessing. uint8_t currentBufferUser; // The current buffer the user is reading/writing. uint8_t *pDataUser; // User pointer for accessing data. - + ISOCHRONOUS_DATA_BUFFER buffers[USB_MAX_ISOCHRONOUS_DATA_BUFFERS]; // Data buffer information. } ISOCHRONOUS_DATA; - + // ***************************************************************************** /* Targeted Peripheral List @@ -326,7 +326,7 @@ typedef bool (*USB_CLIENT_EVENT_HANDLER) ( uint8_t address, USB_EVENT event, voi uint32_t flags - Initialization flags uint8_t clientDriverID - ID to send when issuing a Device Request via USBHostIssueDeviceRequest() or USBHostSetDeviceConfiguration(). - + Return Values: true - Successful false - Not successful @@ -415,7 +415,7 @@ typedef bool (*USB_CLIENT_INIT) ( uint8_t address, uint32_t flags, uint8_t cli passed to this event handler. If the application can handle the event successfully, the function - should return true. + should return true. Precondition: None @@ -456,11 +456,11 @@ typedef struct _CLIENT_DRIVER_TABLE { USB_CLIENT_INIT Initialize; // Initialization routine USB_CLIENT_EVENT_HANDLER EventHandler; // Event routine - + #ifdef USB_HOST_APP_DATA_EVENT_HANDLER USB_CLIENT_EVENT_HANDLER DataEventHandler; // Data Event routine #endif - + uint32_t flags; // Initialization flags } CLIENT_DRIVER_TABLE; @@ -659,7 +659,7 @@ uint8_t USBHostDeviceStatus( uint8_t deviceAddress ); /**************************************************************************** Function: uint8_t USBHostGetStringDescriptor ( uint8_t deviceAddress, uint8_t stringNumber, - uint8_t LangID, uint8_t *stringDescriptor, uint8_t stringLength, + uint8_t LangID, uint8_t *stringDescriptor, uint8_t stringLength, uint8_t clientDriverID ) Summary: @@ -680,7 +680,7 @@ uint8_t USBHostDeviceStatus( uint8_t deviceAddress ); LangID, stringDescriptorBuffer, sizeof(stringDescriptorBuffer), - 0xFF + 0xFF ); while(1) @@ -715,7 +715,7 @@ uint8_t USBHostDeviceStatus( uint8_t deviceAddress ); *stringDescriptor - Pointer to where to store the string. stringLength - Maximum length of the returned string. clientDriverID - Client driver to return the completion event to. - + Return Values: USB_SUCCESS - The request was started successfully. USB_UNKNOWN_DEVICE - Device not found @@ -771,9 +771,9 @@ bool USBHostInit( unsigned long flags ); /**************************************************************************** Function: - bool USBHostIsochronousBuffersCreate( ISOCHRONOUS_DATA * isocData, + bool USBHostIsochronousBuffersCreate( ISOCHRONOUS_DATA * isocData, uint8_t numberOfBuffers, uint16_t bufferSize ) - + Description: This function initializes the isochronous data buffer information and allocates memory for each buffer. This function will not allocate memory @@ -787,7 +787,7 @@ bool USBHostInit( unsigned long flags ); Return Values: true - All buffers are allocated successfully. - false - Not enough heap space to allocate all buffers - adjust the + false - Not enough heap space to allocate all buffers - adjust the project to provide more heap space. Remarks: @@ -803,7 +803,7 @@ bool USBHostIsochronousBuffersCreate( ISOCHRONOUS_DATA * isocData, uint8_t numbe /**************************************************************************** Function: void USBHostIsochronousBuffersDestroy( ISOCHRONOUS_DATA * isocData, uint8_t numberOfBuffers ) - + Description: This function releases all of the memory allocated for the isochronous data buffers. It also resets all other information about the buffers. @@ -830,9 +830,9 @@ void USBHostIsochronousBuffersDestroy( ISOCHRONOUS_DATA * isocData, uint8_t numb /**************************************************************************** Function: void USBHostIsochronousBuffersReset( ISOCHRONOUS_DATA * isocData, uint8_t numberOfBuffers ) - + Description: - This function resets all the isochronous data buffers. It does not do + This function resets all the isochronous data buffers. It does not do anything with the space allocated for the buffers. Precondition: @@ -911,7 +911,7 @@ void USBHostIsochronousBuffersReset( ISOCHRONOUS_DATA * isocData, uint8_t number ***************************************************************************/ uint8_t USBHostIssueDeviceRequest( uint8_t deviceAddress, uint8_t bmRequestType, uint8_t bRequest, - uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t *data, uint8_t dataDirection, + uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t *data, uint8_t dataDirection, uint8_t clientDriverID ); @@ -984,7 +984,7 @@ uint8_t USBHostRead( uint8_t deviceAddress, uint8_t endpoint, uint8_t *data, attached device. If the endpoint is not isochronous, use USBHostRead(). Once started, an isochronous transfer will continue with no upper layer - intervention until USBHostTerminateTransfer() is called. + intervention until USBHostTerminateTransfer() is called. Precondition: None @@ -1103,7 +1103,7 @@ uint8_t USBHostResumeDevice( uint8_t deviceAddress ); Parameters: uint8_t deviceAddress - Device address uint8_t configuration - Index of the new configuration - + Return Values: USB_SUCCESS - Process of changing the configuration was started successfully. diff --git a/inc/usb_host_android.h b/inc/usb_host_android.h index 390c731..63af683 100644 --- a/inc/usb_host_android.h +++ b/inc/usb_host_android.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -22,10 +22,10 @@ please contact mla_licensing@microchip.com #include #include -/* Error code indicating that the buffer passed to the read function was too small. +/* Error code indicating that the buffer passed to the read function was too small. Since the USB host can't control how much data it will receive in a single packet, the user must provide a buffer that is at least the size of the endpoint of the - attached device. If a buffer is passed in that is too small, the read will not + attached device. If a buffer is passed in that is too small, the read will not start and this error is returned to the user. */ #define USB_ERROR_BUFFER_TOO_SMALL USB_ERROR_CLASS_DEFINED + 0 @@ -44,10 +44,10 @@ please contact mla_licensing@microchip.com #endif #ifndef NUM_ANDROID_DEVICES_SUPPORTED - /* Defines the number of concurrent Android devices this implementation is allowed to + /* Defines the number of concurrent Android devices this implementation is allowed to talk to. This definition is only used for implementations where the accessory is the host and the Android device is the slave. This is also most often defined to - be 1. If this is not defined by the user, a default of 1 is used. + be 1. If this is not defined by the user, a default of 1 is used. This option is only used when compiling the source version of the library. This value is set to 1 for pre-compiled versions of the library. */ @@ -59,7 +59,7 @@ please contact mla_licensing@microchip.com /* This event is thrown when an Android device is attached and successfully entered into - accessory mode already. The data portion of this event is the handle that is + accessory mode already. The data portion of this event is the handle that is required to communicate to the device and should be saved so that it can be passed to all of the transfer functions. Always use this definition in the code and never put a static value as the value of this event may change based on various build options. */ @@ -88,10 +88,10 @@ typedef enum ANDROID_AUDIO_MODE__44K_16B_PCM = 1 } ANDROID_AUDIO_MODE; -/* This structure contains the informatin that is required to successfully create a link - between the Android device and the accessory. This information must match the - information entered in the accessory filter in the Android application in order for - the Android application to access the device. An instance of this structure should be +/* This structure contains the informatin that is required to successfully create a link + between the Android device and the accessory. This information must match the + information entered in the accessory filter in the Android application in order for + the Android application to access the device. An instance of this structure should be passed into the AndroidAppStart() at initialization. */ typedef struct { @@ -129,7 +129,7 @@ typedef struct Description: Sets the accessory information and initializes the client driver information after the initial power cycles. Since this resets all device information - this function should be used only after a compete system reset. This should + this function should be used only after a compete system reset. This should not be called while the USB is active or while connected to a device. Precondition: @@ -218,8 +218,8 @@ uint8_t AndroidAppWrite(void* handle, uint8_t* data, uint32_t size); Check to see if the last write to the Android device was completed Description: - Check to see if the last write to the Android device was completed. If - complete, returns the amount of data that was sent and the corresponding + Check to see if the last write to the Android device was completed. If + complete, returns the amount of data that was sent and the corresponding error code for the transmission. Precondition: @@ -260,7 +260,7 @@ bool AndroidAppIsWriteComplete(void* handle, uint8_t* errorCode, uint32_t* size) Description: Attempts to read information from the specified Android device. This - function does not block. Data availability is checked via the + function does not block. Data availability is checked via the AndroidAppIsReadComplete() function. Precondition: @@ -287,7 +287,7 @@ bool AndroidAppIsWriteComplete(void* handle, uint8_t* errorCode, uint32_t* size) USB_ENDPOINT_NOT_FOUND - Invalid endpoint. USB_ERROR_BUFFER_TOO_SMALL - The buffer passed to the read function was smaller than the endpoint size being used - (buffer must be larger than or equal to + (buffer must be larger than or equal to the endpoint size). Remarks: @@ -303,8 +303,8 @@ uint8_t AndroidAppRead(void* handle, uint8_t* data, uint32_t size); Check to see if the last read to the Android device was completed Description: - Check to see if the last read to the Android device was completed. If - complete, returns the amount of data that was sent and the corresponding + Check to see if the last read to the Android device was completed. If + complete, returns the amount of data that was sent and the corresponding error code for the transmission. Precondition: diff --git a/inc/usb_host_audio_v1.h b/inc/usb_host_audio_v1.h index 208ceff..cf76b91 100644 --- a/inc/usb_host_audio_v1.h +++ b/inc/usb_host_audio_v1.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -85,14 +85,14 @@ please contact mla_licensing@microchip.com #endif // No event occured (NULL event). -#define EVENT_AUDIO_NONE EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 0 +#define EVENT_AUDIO_NONE EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 0 // An audio device has attached. The returned data pointer points to a // USB_AUDIO_V1_DEVICE_ID structure. -#define EVENT_AUDIO_ATTACH EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 1 +#define EVENT_AUDIO_ATTACH EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 1 // An audio device has detached. The returned data pointer points to a // uint8_t with the previous address of the detached device. -#define EVENT_AUDIO_DETACH EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 2 - // An audio stream data packet has been received. The returned data +#define EVENT_AUDIO_DETACH EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 2 + // An audio stream data packet has been received. The returned data // pointer points to a HOST_TRANSFER_DATA structure, with information about // the most recent transfer. One event will be returned for each transfer, // so the application will know how much data was actually received in @@ -102,11 +102,11 @@ please contact mla_licensing@microchip.com // This event is returned after the sampling frequency is set via // USBHostAudioV1SetSamplingFrequency(). The returned data pointer points // to a HOST_TRANSFER_DATA structure, with the error code for this request. -#define EVENT_AUDIO_FREQUENCY_SET EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 4 +#define EVENT_AUDIO_FREQUENCY_SET EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 4 // This event is returned after the full or zero bandwidth interface has // been set. The returned data pointer is NULL, but the size is the // error code from the transfer. -#define EVENT_AUDIO_INTERFACE_SET EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 5 +#define EVENT_AUDIO_INTERFACE_SET EVENT_AUDIO_BASE + EVENT_AUDIO_OFFSET + 5 // ***************************************************************************** // ***************************************************************************** @@ -148,7 +148,7 @@ typedef struct _USB_AUDIO_V1_DEVICE_ID This function starts the reception of streaming, isochronous audio data. Precondition: - USBHostAudioV1SetInterfaceFullBandwidth() must be called to set the + USBHostAudioV1SetInterfaceFullBandwidth() must be called to set the device to its full bandwidth interface. Parameters: @@ -167,7 +167,7 @@ typedef struct _USB_AUDIO_V1_DEVICE_ID Remarks: Some devices require other operations between setting the full bandwidth - interface and starting the streaming audio data. Therefore, these two + interface and starting the streaming audio data. Therefore, these two functions are broken out separately. ***************************************************************************/ @@ -213,7 +213,7 @@ uint8_t USBHostAudioV1SetInterfaceFullBandwidth( uint8_t deviceAddress ); uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) Summary: - This function sets the zero bandwidth interface. + This function sets the zero bandwidth interface. Description: This function sets the full bandwidth interface. This function can @@ -231,7 +231,7 @@ uint8_t USBHostAudioV1SetInterfaceFullBandwidth( uint8_t deviceAddress ); USB_SUCCESS - Request started successfully USB_AUDIO_DEVICE_NOT_FOUND - No device with the specified address. Others - See USBHostIssueDeviceRequest() - + Remarks: None ***************************************************************************/ @@ -247,28 +247,28 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ); This function sets the sampling frequency for the device. Description: - This function sets the sampling frequency for the device. If the exact + This function sets the sampling frequency for the device. If the exact frequency is not supported by the device, the device will round it to the closest supported value. - IMPORTANT: If the request is initiated successfully, the frequency value - must remain valid until the EVENT_AUDIO_FREQUENCY_SET event is received. + IMPORTANT: If the request is initiated successfully, the frequency value + must remain valid until the EVENT_AUDIO_FREQUENCY_SET event is received. Therefore, this value cannot be a local (stack) variable. The application - can either use a global variable for this value, or it can use the + can either use a global variable for this value, or it can use the function USBHostAudioV1SupportedFrequencies() to obtain a pointer to the number and list of supported frequencies, and pass a pointer to the desired frequency in this list. - + Precondition: None Parameters: uint8_t deviceAddress - Device address uint8_t *frequency - Pointer to three uint8_ts that specify the desired - sampling frequency. NOTE: If the request is - initiated successfully, this location must - remain valid until the EVENT_AUDIO_FREQUENCY_SET - event is received. + sampling frequency. NOTE: If the request is + initiated successfully, this location must + remain valid until the EVENT_AUDIO_FREQUENCY_SET + event is received. Return Values: USB_SUCCESS - Request started successfully @@ -289,7 +289,7 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ); // Continuous sampling, minimum and maximum are specified. uint32_t minFrequency; uint32_t maxFrequency; - + minFrequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); ptr += 3; maxFrequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); @@ -304,9 +304,9 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ); } else { - // Discrete sampling frequencies are specified. + // Discrete sampling frequencies are specified. uint32_t frequency; - + while (numFrequencies) { frequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); @@ -325,7 +325,7 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ); } }
- + Remarks: If a global variable is used to old the frequency, it can be declared as a uint32_t. Since PIC Microcontrollers are little endian machines, a @@ -335,7 +335,7 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ); rc = USBHostAudioV1SetSamplingFrequency( deviceAddress, (uint8_t *)(&desiredFrequency) );
- + ***************************************************************************/ uint8_t USBHostAudioV1SetSamplingFrequency( uint8_t deviceAddress, uint8_t *frequency ); @@ -344,7 +344,7 @@ uint8_t USBHostAudioV1SetSamplingFrequency( uint8_t deviceAddress, uint8_t *freq /**************************************************************************** Function: uint8_t * USBHostAudioV1SupportedFrequencies( uint8_t deviceAddress ) - + Summary: This function returns a pointer to the list of supported frequencies. @@ -379,7 +379,7 @@ uint8_t USBHostAudioV1SetSamplingFrequency( uint8_t deviceAddress, uint8_t *freq // Continuous sampling, minimum and maximum are specified. uint32_t minFrequency; uint32_t maxFrequency; - + minFrequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); ptr += 3; maxFrequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); @@ -394,9 +394,9 @@ uint8_t USBHostAudioV1SetSamplingFrequency( uint8_t deviceAddress, uint8_t *freq } else { - // Discrete sampling frequencies are specified. + // Discrete sampling frequencies are specified. uint32_t frequency; - + while (numFrequencies) { frequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); @@ -415,7 +415,7 @@ uint8_t USBHostAudioV1SetSamplingFrequency( uint8_t deviceAddress, uint8_t *freq } }
- + Remarks: None ***************************************************************************/ @@ -428,18 +428,18 @@ uint8_t * USBHostAudioV1SupportedFrequencies( uint8_t deviceAddress ); void USBHostAudioV1TerminateTransfer( uint8_t deviceAddress ) Summary: - This function terminates an audio stream. + This function terminates an audio stream. Description: This function terminates an audio stream. It does not change the device's - selected interface. The application may wish to call + selected interface. The application may wish to call USBHostAudioV1SetInterfaceZeroBandwidth() after this function to set the device to the zero bandwidth interface. Between terminating one audio stream and starting another, the application - should call USBHostIsochronousBuffersReset() to reset the data buffers. + should call USBHostIsochronousBuffersReset() to reset the data buffers. This is done from the application layer rather than from this function, so - the application can process all received audio data. + the application can process all received audio data. Precondition: None @@ -490,7 +490,7 @@ void USBHostAudioV1TerminateTransfer( uint8_t deviceAddress ); false - Event was not handled Remarks: - The client driver does not need to process the data. Just pass the event + The client driver does not need to process the data. Just pass the event up to the application layer. ***************************************************************************/ diff --git a/inc/usb_host_cdc.h b/inc/usb_host_cdc.h index 98f0b0e..e975908 100644 --- a/inc/usb_host_cdc.h +++ b/inc/usb_host_cdc.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -384,8 +384,8 @@ typedef struct _USB_CDC_DEVICE_INFO process of initializing USB_PROCESSING_REPORT_DESCRIPTOR - CDC device is detected and report descriptor is being parsed - USB_CDC_NORMAL_RUNNING - CDC Device is running normal, - ready to send and receive reports + USB_CDC_NORMAL_RUNNING - CDC Device is running normal, + ready to send and receive reports USB_CDC_DEVICE_HOLDING - Device is holding due to error USB_CDC_DEVICE_DETACHED - CDC detached. diff --git a/inc/usb_host_cdc_interface.h b/inc/usb_host_cdc_interface.h index ed731fc..8fff013 100644 --- a/inc/usb_host_cdc_interface.h +++ b/inc/usb_host_cdc_interface.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END diff --git a/inc/usb_host_hid.h b/inc/usb_host_hid.h index 9032137..c387ce4 100644 --- a/inc/usb_host_hid.h +++ b/inc/usb_host_hid.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -73,7 +73,7 @@ typedef enum USB_HID_NORMAL_RUNNING, USB_HID_DEVICE_HOLDING, USB_HID_RESETTING_DEVICE - + } USB_HOST_HID_RETURN_CODES; @@ -82,11 +82,11 @@ typedef enum // Section: Interface and Protocol Constants // ***************************************************************************** -#define DEVICE_CLASS_HID 0x03 // HID Interface Class Code +#define DEVICE_CLASS_HID 0x03 // HID Interface Class Code -#define DSC_HID 0x21 // HID Descriptor Code +#define DSC_HID 0x21 // HID Descriptor Code #define DSC_RPT_wValue 0x2200 // Report Descriptor Code, used for USBHostIssueDeviceRequest -#define DSC_PHY 0x23 // Physical Descriptor Code +#define DSC_PHY 0x23 // Physical Descriptor Code // ***************************************************************************** // Section: HID Event Definition @@ -98,33 +98,33 @@ typedef enum #endif // No event occured (NULL event) -#define EVENT_HID_NONE EVENT_HID_BASE + EVENT_HID_OFFSET + 0 +#define EVENT_HID_NONE EVENT_HID_BASE + EVENT_HID_OFFSET + 0 // A Report Descriptor has been parsed. The returned data pointer is NULL. - // The application must collect details, or simply return true if the + // The application must collect details, or simply return true if the // application is already aware of the data format. -#define EVENT_HID_RPT_DESC_PARSED EVENT_HID_BASE + EVENT_HID_OFFSET + 1 +#define EVENT_HID_RPT_DESC_PARSED EVENT_HID_BASE + EVENT_HID_OFFSET + 1 //#define EVENT_HID_TRANSFER EVENT_HID_BASE + EVENT_HID_OFFSET + 3 // Unused - value retained for legacy. - // A HID Read transfer has completed. The returned data pointer points to a - // HID_TRANSFER_DATA structure, with information about the transfer. -#define EVENT_HID_READ_DONE EVENT_HID_BASE + EVENT_HID_OFFSET + 4 - // A HID Write transfer has completed. The returned data pointer points to a - // HID_TRANSFER_DATA structure, with information about the transfer. -#define EVENT_HID_WRITE_DONE EVENT_HID_BASE + EVENT_HID_OFFSET + 5 + // A HID Read transfer has completed. The returned data pointer points to a + // HID_TRANSFER_DATA structure, with information about the transfer. +#define EVENT_HID_READ_DONE EVENT_HID_BASE + EVENT_HID_OFFSET + 4 + // A HID Write transfer has completed. The returned data pointer points to a + // HID_TRANSFER_DATA structure, with information about the transfer. +#define EVENT_HID_WRITE_DONE EVENT_HID_BASE + EVENT_HID_OFFSET + 5 // HID reset complete. The returned data pointer is NULL. -#define EVENT_HID_RESET EVENT_HID_BASE + EVENT_HID_OFFSET + 6 +#define EVENT_HID_RESET EVENT_HID_BASE + EVENT_HID_OFFSET + 6 // A HID device has attached. The returned data pointer points to a // USB_HID_DEVICE_ID structure. -#define EVENT_HID_ATTACH EVENT_HID_BASE + EVENT_HID_OFFSET + 7 +#define EVENT_HID_ATTACH EVENT_HID_BASE + EVENT_HID_OFFSET + 7 // A HID device has detached. The returned data pointer points to a // byte with the previous address of the detached device. -#define EVENT_HID_DETACH EVENT_HID_BASE + EVENT_HID_OFFSET + 8 +#define EVENT_HID_DETACH EVENT_HID_BASE + EVENT_HID_OFFSET + 8 // There was a problem parsing the report descriptor of the attached device. // Communication with the device is not allowed, and the device should be - // detached. -#define EVENT_HID_BAD_REPORT_DESCRIPTOR EVENT_HID_BASE + EVENT_HID_OFFSET + 9 - // An error occurred while trying to do a HID reset. The returned data pointer + // detached. +#define EVENT_HID_BAD_REPORT_DESCRIPTOR EVENT_HID_BASE + EVENT_HID_OFFSET + 9 + // An error occurred while trying to do a HID reset. The returned data pointer // is NULL. -#define EVENT_HID_RESET_ERROR EVENT_HID_BASE + EVENT_HID_OFFSET + 10 +#define EVENT_HID_RESET_ERROR EVENT_HID_BASE + EVENT_HID_OFFSET + 10 @@ -201,7 +201,7 @@ typedef struct _HID_TRANSFER_DATA // ***************************************************************************** // ***************************************************************************** -// Section: Function Prototypes +// Section: Function Prototypes // ***************************************************************************** // ***************************************************************************** @@ -227,7 +227,7 @@ typedef struct _HID_TRANSFER_DATA *******************************************************************************/ uint8_t USBHostHIDDeviceDetect ( - void + void ); @@ -250,10 +250,10 @@ uint8_t USBHostHIDDeviceDetect device is not an HID USB_HID_INITIALIZING - HID is attached and in the process of initializing - USB_PROCESSING_REPORT_DESCRIPTOR - HID device is detected and report + USB_PROCESSING_REPORT_DESCRIPTOR - HID device is detected and report descriptor is being parsed - USB_HID_NORMAL_RUNNING - HID Device is running normal, - ready to send and receive reports + USB_HID_NORMAL_RUNNING - HID Device is running normal, + ready to send and receive reports USB_HID_DEVICE_HOLDING - Driver has encountered error and could not recover USB_HID_DEVICE_DETACHED - HID detached. @@ -263,12 +263,12 @@ uint8_t USBHostHIDDeviceDetect *******************************************************************************/ uint8_t USBHostHIDDeviceStatus ( - uint8_t deviceAddress + uint8_t deviceAddress ); /******************************************************************************* Function: - uint8_t USBHostHIDRead( uint8_t deviceAddress,uint8_t reportid, uint8_t interface, + uint8_t USBHostHIDRead( uint8_t deviceAddress,uint8_t reportid, uint8_t interface, uint8_t size, uint8_t *data) Summary: @@ -296,12 +296,12 @@ uint8_t USBHostHIDDeviceStatus None *******************************************************************************/ uint8_t USBHostHIDRead -( - uint8_t deviceAddress, - uint8_t reportid, - uint8_t interface, - uint8_t size, - uint8_t *data +( + uint8_t deviceAddress, + uint8_t reportid, + uint8_t interface, + uint8_t size, + uint8_t *data ); /******************************************************************************* @@ -331,10 +331,10 @@ uint8_t USBHostHIDRead false - Transfer is not complete, errorCode is not valid *******************************************************************************/ bool USBHostHIDReadIsComplete -( - uint8_t deviceAddress, - uint8_t *errorCode, - uint8_t *byteCount +( + uint8_t deviceAddress, + uint8_t *errorCode, + uint8_t *byteCount ); /******************************************************************************* @@ -353,18 +353,18 @@ bool USBHostHIDReadIsComplete Parameters: uint8_t deviceAddress - Device address uint8_t interfaceNum - Interface number - + Return Values: USB_SUCCESS - read request terminated USB_HID_DEVICE_NOT_FOUND - No device with specified address - + Remarks: None *******************************************************************************/ uint8_t USBHostHIDReadTerminate -( - uint8_t deviceAddress, - uint8_t interfaceNum +( + uint8_t deviceAddress, + uint8_t interfaceNum ); /******************************************************************************* @@ -393,8 +393,8 @@ uint8_t USBHostHIDReadTerminate None *******************************************************************************/ uint8_t USBHostHIDResetDevice -( - uint8_t deviceAddress +( + uint8_t deviceAddress ); /******************************************************************************* @@ -451,17 +451,17 @@ void USBHostHIDTasks( void ); performing a transfer Others - Return values from USBHostIssueDeviceRequest(), and USBHostWrite() - + Remarks: None *******************************************************************************/ uint8_t USBHostHIDWrite -( - uint8_t deviceAddress, - uint8_t reportid, +( + uint8_t deviceAddress, + uint8_t reportid, uint8_t interface, - uint8_t size, - uint8_t *data + uint8_t size, + uint8_t *data ); @@ -492,10 +492,10 @@ uint8_t USBHostHIDWrite false - Transfer is not complete, errorCode is not valid *******************************************************************************/ bool USBHostHIDWriteIsComplete -( - uint8_t deviceAddress, - uint8_t *errorCode, - uint8_t *byteCount +( + uint8_t deviceAddress, + uint8_t *errorCode, + uint8_t *byteCount ); @@ -515,18 +515,18 @@ bool USBHostHIDWriteIsComplete Parameters: uint8_t deviceAddress - Device address uint8_t interfaceNum - Interface number - + Return Values: USB_SUCCESS - write request terminated USB_HID_DEVICE_NOT_FOUND - No device with specified address - + Remarks: None *******************************************************************************/ uint8_t USBHostHIDWriteTerminate -( - uint8_t deviceAddress, - uint8_t interfaceNum +( + uint8_t deviceAddress, + uint8_t interfaceNum ); // ***************************************************************************** @@ -562,7 +562,7 @@ uint8_t USBHostHIDWriteTerminate Return Values: true - If the required usage is located in the report descriptor - false - If the application required usage is not supported by the + false - If the application required usage is not supported by the device(i.e report descriptor). Remarks: @@ -576,7 +576,7 @@ bool USBHostHID_ApiFindBit uint16_t usage, HIDReportTypeEnum type, uint8_t* Report_ID, - uint8_t* Report_Length, + uint8_t* Report_Length, uint8_t* Start_Bit ); @@ -609,7 +609,7 @@ bool USBHostHID_ApiFindBit Return Values: true - If the required usage is located in the report descriptor - false - If the application required usage is not supported by the + false - If the application required usage is not supported by the device(i.e report descriptor). Remarks: @@ -624,7 +624,7 @@ bool USBHostHID_ApiFindValue HIDReportTypeEnum type, uint8_t* Report_ID, uint8_t* Report_Length, - uint8_t* Start_Bit, + uint8_t* Start_Bit, uint8_t* Bit_Length ); @@ -656,10 +656,10 @@ uint8_t USBHostHID_ApiGetCurrentInterfaceNum(void); /******************************************************************************* Function: - bool USBHostHID_ApiImportData(uint8_t *report, uint16_t reportLength, + 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 + 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 the function with required inputs 'HID_DATA_DETAILS'. @@ -684,7 +684,7 @@ bool USBHostHID_ApiImportData ( uint8_t *report, uint16_t reportLength, - HID_USER_DATA_SIZE *buffer, + HID_USER_DATA_SIZE *buffer, HID_DATA_DETAILS *pDataDetails ); @@ -750,8 +750,8 @@ bool USBHostHID_ApiImportData Description: This function is the initialization routine for this client driver. It - is called by the host layer when the USB device is being enumerated.For a - HID device we need to look into HID descriptor, interface descriptor and + is called by the host layer when the USB device is being enumerated.For a + HID device we need to look into HID descriptor, interface descriptor and endpoint descriptor. Precondition: @@ -771,8 +771,8 @@ bool USBHostHID_ApiImportData *******************************************************************************/ bool USBHostHIDInitialize ( - uint8_t address, - uint32_t flags, + uint8_t address, + uint32_t flags, uint8_t clientDriverID ); @@ -805,11 +805,11 @@ bool USBHostHIDInitialize None *******************************************************************************/ bool USBHostHIDEventHandler -( - uint8_t address, - USB_EVENT event, - void *data, - uint32_t size +( + uint8_t address, + USB_EVENT event, + void *data, + uint32_t size ); /******************************************************************************* diff --git a/inc/usb_host_hid_parser.h b/inc/usb_host_hid_parser.h index 5c85d17..b036881 100644 --- a/inc/usb_host_hid_parser.h +++ b/inc/usb_host_hid_parser.h @@ -14,13 +14,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END #ifndef _USB_HOST_HID_PARSER_H_ /* usb_host_hid_parser.h */ -#define _USB_HOST_HID_PARSER_H_ +#define _USB_HOST_HID_PARSER_H_ #define HIDItem_SizeMask 0x03 // Mask for Size bitfield in Item header @@ -58,26 +58,26 @@ please contact mla_licensing@microchip.com // //------------------------------------------------------------------------------ #define HIDTag_UsagePage 0x00 // UsagePage Tag value -#define HIDTag_LogicalMinimum 0x01 // Logical Minimum Tag value +#define HIDTag_LogicalMinimum 0x01 // Logical Minimum Tag value #define HIDTag_LogicalMaximum 0x02 // Logical Maximum Tag value #define HIDTag_PhysicalMinimum 0x03 // Physical Minimum Tag value #define HIDTag_PhysicalMaximum 0x04 // Physical Maximum Tag value #define HIDTag_UnitExponent 0x05 // Unit Exponent Tag value -#define HIDTag_Unit 0x06 // Unit Tag value -#define HIDTag_ReportSize 0x07 // Report Size Tag value -#define HIDTag_ReportID 0x08 // Report ID Tag value +#define HIDTag_Unit 0x06 // Unit Tag value +#define HIDTag_ReportSize 0x07 // Report Size Tag value +#define HIDTag_ReportID 0x08 // Report ID Tag value #define HIDTag_ReportCount 0x09 // ReportCount Tag value #define HIDTag_Push 0x0A // Push Tag value -#define HIDTag_Pop 0x0B // Pop Tag value +#define HIDTag_Pop 0x0B // Pop Tag value //------------------------------------------------------------------------------ -// +// // HID Item Tag Definitions - Locals // //------------------------------------------------------------------------------ -#define HIDTag_Usage 0x00 // Usage Tag value -#define HIDTag_UsageMinimum 0x01 // Usage Minimum Tag value +#define HIDTag_Usage 0x00 // Usage Tag value +#define HIDTag_UsageMinimum 0x01 // Usage Minimum Tag value #define HIDTag_UsageMaximum 0x02 // Usage Maximum Tag value #define HIDTag_DesignatorIndex 0x03 // Designator Index Tag value #define HIDTag_DesignatorMinimum 0x04 // Designator Minimum Tag value @@ -108,10 +108,10 @@ please contact mla_licensing@microchip.com #define HIDData_Relative 0x04 // HID data type relative #define HIDData_Absolute 0x00 // HID data type absolute #define HIDData_VariableBit 0x02 // Variable bit position -#define HIDData_Variable 0x02 // HID data type variable -#define HIDData_ArrayBit 0x02 // Array Bit position +#define HIDData_Variable 0x02 // HID data type variable +#define HIDData_ArrayBit 0x02 // Array Bit position #define HIDData_Array 0x00 // Array indentifier value -#define HIDData_ConstantBit 0x01 // Constant Bit position +#define HIDData_ConstantBit 0x01 // Constant Bit position #define HIDData_Constant 0x01 // Constant data type indentifier value //------------------------------------------------------------------------------ @@ -131,7 +131,7 @@ typedef enum { } HIDReportTypeEnum; - + // ***************************************************************************** /* HID Item Information @@ -141,14 +141,14 @@ typedef struct _HID_ITEM_INFO { union { - struct + struct { uint8_t ItemSize :2; // Numeric expression specifying size of data uint8_t ItemType :2; // This field identifies type of item(Main, Global or Local) uint8_t ItemTag :4; // This field specifies the function of the item }; uint8_t val; // to access the data in byte format - } ItemDetails; + } ItemDetails; union { @@ -156,7 +156,7 @@ typedef struct _HID_ITEM_INFO uint32_t uItemData; // Item Data is stored in unsigned format uint8_t bItemData[4]; } Data; -} HID_ITEM_INFO; +} HID_ITEM_INFO; // ***************************************************************************** diff --git a/inc/usb_host_msd.h b/inc/usb_host_msd.h index 7bd1134..c6e4e15 100644 --- a/inc/usb_host_msd.h +++ b/inc/usb_host_msd.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -388,7 +388,7 @@ bool USBHostMSDTransferIsComplete( uint8_t deviceAddress, uint8_t *errorCode, uint32_t flags - Initialization flags uint8_t clientDriverID - ID to send when issuing a Device Request via USBHostSendDeviceRequest(), USBHostSetDeviceConfiguration(), - or USBHostSetDeviceInterface(). + or USBHostSetDeviceInterface(). Return Values: true - We can support the device. diff --git a/inc/usb_host_msd_scsi.h b/inc/usb_host_msd_scsi.h index d4c73e2..ee35b85 100644 --- a/inc/usb_host_msd_scsi.h +++ b/inc/usb_host_msd_scsi.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -81,9 +81,9 @@ uint8_t USBHostMSDSCSIMediaDetect( uint8_t * address); Returns: The function returns a pointer to the MEDIA_INFORMATION structure. The errorCode member may contain the following values: - * MEDIA_NO_ERROR - The media initialized successfully, and the - sector size should be valid (confirm using the validityFlags - bit). + * MEDIA_NO_ERROR - The media initialized successfully, and the + sector size should be valid (confirm using the validityFlags + bit). * MEDIA_DEVICE_NOT_PRESENT - The requested device is not attached. * MEDIA_CANNOT_INITIALIZE - Cannot initialize the media. diff --git a/inc/usb_struct_queue.h b/inc/usb_struct_queue.h index cb1be66..d0d88fb 100644 --- a/inc/usb_struct_queue.h +++ b/inc/usb_struct_queue.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -35,15 +35,15 @@ please contact mla_licensing@microchip.com * * Returns: zero (0) * - * Side Effects: The queue structure has been initialized and is ready + * Side Effects: The queue structure has been initialized and is ready * to use. * * Overview: This operation initializes a queue and makes it empty. * - * Note: This operation is implemented with a macro that + * Note: This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ - + #define StructQueueInit(q,N) ( (q)->head = (N), \ (q)->tail = (N), \ (q)->count = 0 ) @@ -51,7 +51,7 @@ please contact mla_licensing@microchip.com /* StructQueueAdd ************************************************************************* - * Precondition: The queue must have been initialized and must not + * Precondition: The queue must have been initialized and must not * currently be full. * * Input: q Pointer to the queue data structure @@ -66,17 +66,17 @@ please contact mla_licensing@microchip.com * * IMPORTANT! No data has been copied to the item. * - * Overview: This operation adds (enqueues) a new item into the + * Overview: This operation adds (enqueues) a new item into the * queue data buffer and updates the head index, * handling buffer wrap correctly. * - * Notes: The caller must first ensure that the queue is not - * full by performing one of the other operations (such - * as "StructQueueIsNotFull") before performing this - * operation. Adding an item into a full queue will + * Notes: The caller must first ensure that the queue is not + * full by performing one of the other operations (such + * as "StructQueueIsNotFull") before performing this + * operation. Adding an item into a full queue will * cause an access violation. * - * This operation is implemented with a macro that + * This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -104,7 +104,7 @@ please contact mla_licensing@microchip.com * * IMPORTANT! No data has been copied from the item. * - * Overview: This routine removes (dequeues) an item from the + * Overview: This routine removes (dequeues) an item from the * queue data buffer and updates the tail index, * handling buffer wrap correctly. * @@ -114,7 +114,7 @@ please contact mla_licensing@microchip.com * operation. Dequeueing an item from an empty queue * will cause an access violation. * - * This operation is implemented with a macro that + * This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -142,7 +142,7 @@ please contact mla_licensing@microchip.com * * IMPORTANT! No data has been copied from the item. * - * Overview: This routine provides access to an item in the + * Overview: This routine provides access to an item in the * queue data buffer at the tail index position, * handling buffer wrap correctly. * @@ -151,7 +151,7 @@ please contact mla_licensing@microchip.com * (such as "StructQueueIsNotEmpty") before performing this * operation. * - * This operation is implemented with a macro that + * This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -176,7 +176,7 @@ please contact mla_licensing@microchip.com * * Overview: This routine checks to see if the queue is full. * - * Note: This operation is implemented with a macro that + * Note: This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -199,7 +199,7 @@ please contact mla_licensing@microchip.com * * Overview: This routine checks to see if the queue is full. * - * Note: This operation is implemented with a macro that + * Note: This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -222,7 +222,7 @@ please contact mla_licensing@microchip.com * * Overview: This routine checks to see if the queue is empty. * - * Note: This operation is implemented with a macro that + * Note: This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -245,7 +245,7 @@ please contact mla_licensing@microchip.com * * Overview: This routine checks to see if the queue is not empty. * - * Note: This operation is implemented with a macro that + * Note: This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -270,7 +270,7 @@ please contact mla_licensing@microchip.com * Overview: This routine checks to see if the queue has at least * the specified number of slots free. * - * Note: This operation is implemented with a macro that + * Note: This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ @@ -293,7 +293,7 @@ please contact mla_licensing@microchip.com * * Overview: This routine provides the number of items in the queue. * - * Note: This operation is implemented with a macro that + * Note: This operation is implemented with a macro that * supports queues of any type of data items. *************************************************************************/ diff --git a/src/usb_device.c b/src/usb_device.c index 9ba97c9..5805ecb 100644 --- a/src/usb_device.c +++ b/src/usb_device.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -183,7 +183,7 @@ volatile uint8_t CtrlTrfData[USB_EP0_BUFF_SIZE] CTRL_TRF_DATA_ADDR_TAG; * non-EP0 Buffer Space *******************************************************************/ #if defined(USB_USE_MSD) - //Check if the MSD application specific USB endpoint buffer placement address + //Check if the MSD application specific USB endpoint buffer placement address //macros have already been defined or not (ex: in a processor specific header) //The msd_cbw and msd_csw buffers must be USB module accessible (and therefore //must be at a certain address range on certain microcontrollers). @@ -254,25 +254,25 @@ static void USBStallHandler(void); /************************************************************************** Function: void USBDeviceInit(void) - + Description: This function initializes the device stack it in the default state. The USB module will be completely reset including all of the internal variables, registers, and interrupt flags. - + Precondition: This function must be called before any of the other USB Device functions can be called, including USBDeviceTasks(). - + Parameters: None - + Return Values: None - + Remarks: None - + ***************************************************************************/ void USBDeviceInit(void) { @@ -280,19 +280,19 @@ void USBDeviceInit(void) USBDisableInterrupts(); - //Make sure that if a GPIO output driver exists on VBUS, that it is + //Make sure that if a GPIO output driver exists on VBUS, that it is //tri-stated to avoid potential contention with the host USB_HAL_VBUSTristate(); - + // Clear all USB error flags - USBClearInterruptRegister(U1EIR); - - // Clears all USB interrupts - USBClearInterruptRegister(U1IR); + USBClearInterruptRegister(U1EIR); + + // Clears all USB interrupts + USBClearInterruptRegister(U1IR); //Clear all of the endpoint control registers U1EP0 = 0; - + DisableNonZeroEndpoints(USB_MAX_EP_NUMBER); SetConfigurationOptions(); @@ -310,13 +310,13 @@ void USBDeviceInit(void) } // Assert reset request to all of the Ping Pong buffer pointers - USBPingPongBufferReset = 1; + USBPingPongBufferReset = 1; // Reset to default address - U1ADDR = 0x00; + U1ADDR = 0x00; // Make sure packet processing is enabled - USBPacketDisable = 0; + USBPacketDisable = 0; //Stop trying to reset ping pong buffer pointers USBPingPongBufferReset = 0; @@ -353,7 +353,7 @@ void USBDeviceInit(void) //Get ready for the first packet pBDTEntryIn[0] = (volatile BDT_ENTRY*)&BDT[EP0_IN_EVEN]; // Initialize EP0 as a Ctrl EP - U1EP0 = EP_CTRL|USB_HANDSHAKE_ENABLED; + U1EP0 = EP_CTRL|USB_HANDSHAKE_ENABLED; //Prepare for the first SETUP on EP0 OUT BDT[EP0_OUT_EVEN].ADR = ConvertToPhysicalAddress(&SetupPkt); BDT[EP0_OUT_EVEN].CNT = USB_EP0_BUFF_SIZE; @@ -361,7 +361,7 @@ void USBDeviceInit(void) BDT[EP0_OUT_EVEN].STAT.Val |= _USIE; // Clear active configuration - USBActiveConfiguration = 0; + USBActiveConfiguration = 0; USB1msTickCount = 0; //Keeps track of total number of milliseconds since calling USBDeviceInit() when first initializing the USB module/stack code. USBTicksSinceSuspendEnd = 0; //Keeps track of the number of milliseconds since a suspend condition has ended. @@ -375,53 +375,53 @@ void USBDeviceInit(void) /************************************************************************** Function: void USBDeviceTasks(void) - + Summary: - This function is the main state machine/transaction handler of the USB - device side stack. When the USB stack is operated in "USB_POLLING" mode - (usb_config.h user option) the USBDeviceTasks() function should be called - periodically to receive and transmit packets through the stack. This - function also takes care of control transfers associated with the USB - enumeration process, and detecting various USB events (such as suspend). - This function should be called at least once every 1.8ms during the USB - enumeration process. After the enumeration process is complete (which can - be determined when USBGetDeviceState() returns CONFIGURED_STATE), the - USBDeviceTasks() handler may be called the faster of: either once - every 9.8ms, or as often as needed to make sure that the hardware USTAT + This function is the main state machine/transaction handler of the USB + device side stack. When the USB stack is operated in "USB_POLLING" mode + (usb_config.h user option) the USBDeviceTasks() function should be called + periodically to receive and transmit packets through the stack. This + function also takes care of control transfers associated with the USB + enumeration process, and detecting various USB events (such as suspend). + This function should be called at least once every 1.8ms during the USB + enumeration process. After the enumeration process is complete (which can + be determined when USBGetDeviceState() returns CONFIGURED_STATE), the + USBDeviceTasks() handler may be called the faster of: either once + every 9.8ms, or as often as needed to make sure that the hardware USTAT FIFO never gets full. A good rule of thumb is to call USBDeviceTasks() at - a minimum rate of either the frequency that USBTransferOnePacket() gets - called, or, once/1.8ms, whichever is faster. See the inline code comments - near the top of usb_device.c for more details about minimum timing + a minimum rate of either the frequency that USBTransferOnePacket() gets + called, or, once/1.8ms, whichever is faster. See the inline code comments + near the top of usb_device.c for more details about minimum timing requirements when calling USBDeviceTasks(). - + When the USB stack is operated in "USB_INTERRUPT" mode, it is not necessary to call USBDeviceTasks() from the main loop context. In the USB_INTERRUPT - mode, the USBDeviceTasks() handler only needs to execute when a USB - interrupt occurs, and therefore only needs to be called from the interrupt + mode, the USBDeviceTasks() handler only needs to execute when a USB + interrupt occurs, and therefore only needs to be called from the interrupt context. Description: - This function is the main state machine/transaction handler of the USB - device side stack. When the USB stack is operated in "USB_POLLING" mode - (usb_config.h user option) the USBDeviceTasks() function should be called - periodically to receive and transmit packets through the stack. This - function also takes care of control transfers associated with the USB - enumeration process, and detecting various USB events (such as suspend). - This function should be called at least once every 1.8ms during the USB - enumeration process. After the enumeration process is complete (which can - be determined when USBGetDeviceState() returns CONFIGURED_STATE), the - USBDeviceTasks() handler may be called the faster of: either once - every 9.8ms, or as often as needed to make sure that the hardware USTAT + This function is the main state machine/transaction handler of the USB + device side stack. When the USB stack is operated in "USB_POLLING" mode + (usb_config.h user option) the USBDeviceTasks() function should be called + periodically to receive and transmit packets through the stack. This + function also takes care of control transfers associated with the USB + enumeration process, and detecting various USB events (such as suspend). + This function should be called at least once every 1.8ms during the USB + enumeration process. After the enumeration process is complete (which can + be determined when USBGetDeviceState() returns CONFIGURED_STATE), the + USBDeviceTasks() handler may be called the faster of: either once + every 9.8ms, or as often as needed to make sure that the hardware USTAT FIFO never gets full. A good rule of thumb is to call USBDeviceTasks() at - a minimum rate of either the frequency that USBTransferOnePacket() gets - called, or, once/1.8ms, whichever is faster. See the inline code comments - near the top of usb_device.c for more details about minimum timing + a minimum rate of either the frequency that USBTransferOnePacket() gets + called, or, once/1.8ms, whichever is faster. See the inline code comments + near the top of usb_device.c for more details about minimum timing requirements when calling USBDeviceTasks(). - + When the USB stack is operated in "USB_INTERRUPT" mode, it is not necessary to call USBDeviceTasks() from the main loop context. In the USB_INTERRUPT - mode, the USBDeviceTasks() handler only needs to execute when a USB - interrupt occurs, and therefore only needs to be called from the interrupt + mode, the USBDeviceTasks() handler only needs to execute when a USB + interrupt occurs, and therefore only needs to be called from the interrupt context. Typical usage: @@ -441,7 +441,7 @@ void USBDeviceInit(void) } else { - //Otherwise we are free to run USB and non-USB related user + //Otherwise we are free to run USB and non-USB related user //application code. UserApplication(); } @@ -453,25 +453,25 @@ void USBDeviceInit(void) Make sure the USBDeviceInit() function has been called prior to calling USBDeviceTasks() for the first time. Remarks: - USBDeviceTasks() does not need to be called while in the USB suspend mode, + USBDeviceTasks() does not need to be called while in the USB suspend mode, if the user application firmware in the USBCBSuspend() callback function - enables the ACTVIF USB interrupt source and put the microcontroller into - sleep mode. If the application firmware decides not to sleep the - microcontroller core during USB suspend (ex: continues running at full + enables the ACTVIF USB interrupt source and put the microcontroller into + sleep mode. If the application firmware decides not to sleep the + microcontroller core during USB suspend (ex: continues running at full frequency, or clock switches to a lower frequency), then the USBDeviceTasks() - function must still be called periodically, at a rate frequent enough to + function must still be called periodically, at a rate frequent enough to ensure the 10ms resume recovery interval USB specification is met. Assuming a worst case primary oscillator and PLL start up time of less than 5ms, then USBDeviceTasks() should be called once every 5ms in this scenario. - - When the USB cable is detached, or the USB host is not actively powering - the VBUS line to +5V nominal, the application firmware does not always have - to call USBDeviceTasks() frequently, as no USB activity will be taking - place. However, if USBDeviceTasks() is not called regularly, some - alternative means of promptly detecting when VBUS is powered (indicating + + When the USB cable is detached, or the USB host is not actively powering + the VBUS line to +5V nominal, the application firmware does not always have + to call USBDeviceTasks() frequently, as no USB activity will be taking + place. However, if USBDeviceTasks() is not called regularly, some + alternative means of promptly detecting when VBUS is powered (indicating host attachment), or not powered (host powered down or USB cable unplugged) - is still needed. For self or dual self/bus powered USB applications, see - the USBDeviceAttach() and USBDeviceDetach() API documentation for additional + is still needed. For self or dual self/bus powered USB applications, see + the USBDeviceAttach() and USBDeviceDetach() API documentation for additional considerations. ***************************************************************************/ void USBDeviceTasks(void) @@ -505,15 +505,15 @@ void USBDeviceTasks(void) if (USB_BUS_SENSE != 1) { // Disable module & detach from bus - U1CON = 0; + U1CON = 0; - // Mask all USB interrupts - U1IE = 0; + // Mask all USB interrupts + U1IE = 0; - //Move to the detached state + //Move to the detached state USBDeviceState = DETACHED_STATE; - #ifdef USB_SUPPORT_OTG + #ifdef USB_SUPPORT_OTG //Disable D+ Pullup U1OTGCONbits.DPPULUP = 0; @@ -522,10 +522,10 @@ void USBDeviceTasks(void) //Deactivate HNP USBOTGDeactivateHnp(); - + //If ID Pin Changed State if (USBIDIF && USBIDIE) - { + { //Re-detect & Initialize USBOTGInitialize(); @@ -535,9 +535,9 @@ void USBDeviceTasks(void) #endif #if defined __C30__ || defined __XC16__ - //USBClearInterruptFlag(U1OTGIR, 3); + //USBClearInterruptFlag(U1OTGIR, 3); #endif - //return so that we don't go through the rest of + //return so that we don't go through the rest of //the state machine USBClearUSBInterrupt(); return; @@ -549,7 +549,7 @@ void USBDeviceTasks(void) { //If SRP Is Ready if (USBOTGSRPIsReady()) - { + { //Clear SRPReady USBOTGClearSRPReady(); @@ -566,12 +566,12 @@ void USBDeviceTasks(void) if(USBDeviceState == DETACHED_STATE) { //Initialize register to known value - U1CON = 0; + U1CON = 0; // Mask all USB interrupts - U1IE = 0; + U1IE = 0; - //Enable/set things like: pull ups, full/low-speed mode, + //Enable/set things like: pull ups, full/low-speed mode, //set the ping pong mode, and set internal transceiver SetConfigurationOptions(); @@ -582,7 +582,7 @@ void USBDeviceTasks(void) USBDeviceState = ATTACHED_STATE; #ifdef USB_SUPPORT_OTG - U1OTGCON |= USB_OTG_DPLUS_ENABLE | USB_OTG_ENABLE; + U1OTGCON |= USB_OTG_DPLUS_ENABLE | USB_OTG_ENABLE; #endif } #endif //#if defined(USB_POLLING) @@ -620,7 +620,7 @@ void USBDeviceTasks(void) #ifdef USB_SUPPORT_OTG //If ID Pin Changed State if (USBIDIF && USBIDIE) - { + { //Re-detect & Initialize USBOTGInitialize(); @@ -635,7 +635,7 @@ void USBDeviceTasks(void) { USBClearInterruptFlag(USBActivityIFReg,USBActivityIFBitNum); #if defined(USB_SUPPORT_OTG) - U1OTGIR = 0x10; + U1OTGIR = 0x10; #else USBWakeFromSuspend(); #endif @@ -685,8 +685,8 @@ void USBDeviceTasks(void) * Task C: Service other USB interrupts */ if(USBIdleIF && USBIdleIE) - { - #ifdef USB_SUPPORT_OTG + { + #ifdef USB_SUPPORT_OTG //If Suspended, Try to switch to Host USBOTGSelectRole(ROLE_HOST); USBClearInterruptFlag(USBIdleIFReg,USBIdleIFBitNum); @@ -696,7 +696,7 @@ void USBDeviceTasks(void) } #if defined(__XC16__) || defined(__C30__) || defined(__XC32__) - //Check if a 1ms interval has elapsed. + //Check if a 1ms interval has elapsed. if(USBT1MSECIF) { USBClearInterruptFlag(USBT1MSECIFReg, USBT1MSECIFBitNum); @@ -711,7 +711,7 @@ void USBDeviceTasks(void) if(USBSOFIE) { USB_SOF_HANDLER(EVENT_SOF,0,1); - } + } USBClearInterruptFlag(USBSOFIFReg,USBSOFIFBitNum); #if defined(__XC8__) || defined(__C18__) @@ -723,28 +723,28 @@ void USBDeviceTasks(void) #if(USB_SPEED_OPTION == USB_LOW_SPEED) #warning "Double click this message. See inline code comments." //The "USB_ENABLE_STATUS_STAGE_TIMEOUTS" feature is optional and is - //not strictly needed in all applications (ex: those that never call + //not strictly needed in all applications (ex: those that never call //USBDeferStatusStage() and don't use host to device (OUT) control - //transfers with data stage). + //transfers with data stage). //However, if this feature is enabled and used in a low speed application, //it is required for the application code to periodically call the //USBIncrement1msInternalTimers() function at a nominally 1ms rate. #endif - + //Decrement our status stage counter. if(USBStatusStageTimeoutCounter != 0u) { USBStatusStageTimeoutCounter--; } - //Check if too much time has elapsed since progress was made in - //processing the control transfer, without arming the status stage. - //If so, auto-arm the status stage to ensure that the control + //Check if too much time has elapsed since progress was made in + //processing the control transfer, without arming the status stage. + //If so, auto-arm the status stage to ensure that the control //transfer can [eventually] complete, within the timing limits //dictated by section 9.2.6 of the official USB 2.0 specifications. if(USBStatusStageTimeoutCounter == 0) { USBCtrlEPAllowStatusStage(); //Does nothing if the status stage was already armed. - } + } #endif } @@ -759,8 +759,8 @@ void USBDeviceTasks(void) USBClearInterruptRegister(U1EIR); // This clears UERRIF //On PIC18, clearing the source of the error will automatically clear - // the interrupt flag. On other devices the interrupt flag must be - // manually cleared. + // the interrupt flag. On other devices the interrupt flag must be + // manually cleared. #if defined(__C32__) || defined(__C30__) || defined __XC16__ USBClearInterruptFlag( USBErrorIFReg, USBErrorIFBitNum ); #endif @@ -775,7 +775,7 @@ void USBDeviceTasks(void) { USBClearUSBInterrupt(); return; - } + } /* * Task D: Servicing USB Transaction Complete Interrupt @@ -829,14 +829,14 @@ void USBDeviceTasks(void) /******************************************************************************* Function: void USBEnableEndpoint(uint8_t ep, uint8_t options) - + Summary: This function will enable the specified endpoint with the specified options Description: This function will enable the specified endpoint with the specified options. - + Typical Usage: void USBCBInitEP(void) @@ -845,7 +845,7 @@ void USBDeviceTasks(void) USBMSDInit(); } - + In the above example endpoint number MSD_DATA_IN_EP is being configured for both IN and OUT traffic with handshaking enabled. Also since MSD_DATA_IN_EP is not endpoint 0 (MSD does not allow this), then we can @@ -873,13 +873,13 @@ void USBDeviceTasks(void) Return: None Remarks: - None + None *****************************************************************************/ void USBEnableEndpoint(uint8_t ep, uint8_t options) { unsigned char* p; - - //Use USBConfigureEndpoint() to set up the pBDTEntryIn/Out[ep] pointer and + + //Use USBConfigureEndpoint() to set up the pBDTEntryIn/Out[ep] pointer and //starting DTS state in the BDT entry. if(options & USB_OUT_ENABLED) { @@ -905,30 +905,30 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options) /************************************************************************* Function: USB_HANDLE USBTransferOnePacket(uint8_t ep, uint8_t dir, uint8_t* data, uint8_t len) - + Summary: Transfers a single packet (one transaction) of data on the USB bus. Description: The USBTransferOnePacket() function prepares a USB endpoint - so that it may send data to the host (an IN transaction), or - receive data from the host (an OUT transaction). The - USBTransferOnePacket() function can be used both to receive and - send data to the host. This function is the primary API function - provided by the USB stack firmware for sending or receiving application - data over the USB port. - - The USBTransferOnePacket() is intended for use with all application - endpoints. It is not used for sending or receiving application data - through endpoint 0 by using control transfers. Separate API + so that it may send data to the host (an IN transaction), or + receive data from the host (an OUT transaction). The + USBTransferOnePacket() function can be used both to receive and + send data to the host. This function is the primary API function + provided by the USB stack firmware for sending or receiving application + data over the USB port. + + The USBTransferOnePacket() is intended for use with all application + endpoints. It is not used for sending or receiving application data + through endpoint 0 by using control transfers. Separate API functions, such as USBEP0Receive(), USBEP0SendRAMPtr(), and USBEP0SendROMPtr() are provided for this purpose. The USBTransferOnePacket() writes to the Buffer Descriptor Table (BDT) - entry associated with an endpoint buffer, and sets the UOWN bit, which - prepares the USB hardware to allow the transaction to complete. The - application firmware can use the USBHandleBusy() macro to check the - status of the transaction, to see if the data has been successfully + entry associated with an endpoint buffer, and sets the UOWN bit, which + prepares the USB hardware to allow the transaction to complete. The + application firmware can use the USBHandleBusy() macro to check the + status of the transaction, to see if the data has been successfully transmitted yet. @@ -944,7 +944,7 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options) INPacket[0] = USEFUL_APPLICATION_VALUE1; INPacket[1] = USEFUL_APPLICATION_VALUE2; //INPacket[2] = ... (fill in the rest of the packet data) - + //Send the data contained in the INPacket[] array through endpoint "EP_NUM" USBInHandle = USBTransferOnePacket(EP_NUM,IN_TO_HOST,(uint8_t*)&INPacket[0],sizeof(INPacket)); } @@ -955,14 +955,14 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options) Before calling USBTransferOnePacket(), the following should be true. 1. The USB stack has already been initialized (USBDeviceInit() was called). 2. A transaction is not already pending on the specified endpoint. This - is done by checking the previous request using the USBHandleBusy() + is done by checking the previous request using the USBHandleBusy() macro (see the typical usage example). - 3. The host has already sent a set configuration request and the + 3. The host has already sent a set configuration request and the enumeration process is complete. - This can be checked by verifying that the USBGetDeviceState() - macro returns "CONFIGURED_STATE", prior to calling + This can be checked by verifying that the USBGetDeviceState() + macro returns "CONFIGURED_STATE", prior to calling USBTransferOnePacket(). - + Input: uint8_t ep - The endpoint number that the data will be transmitted or received on @@ -973,10 +973,10 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options) to the RAM buffer that the received data should get written to. uint8_t len - Length of the data needing to be sent (for IN transactions). For OUT transactions, the len parameter should normally be set - to the endpoint size specified in the endpoint descriptor. + to the endpoint size specified in the endpoint descriptor. Return Values: - USB_HANDLE - handle to the transfer. The handle is a pointer to + USB_HANDLE - handle to the transfer. The handle is a pointer to the BDT entry associated with this transaction. The status of the transaction (ex: if it is complete or still pending) can be checked using the USBHandleBusy() macro @@ -986,11 +986,11 @@ void USBEnableEndpoint(uint8_t ep, uint8_t options) Remarks: If calling the USBTransferOnePacket() function from within the USBCBInitEP() callback function, the set configuration is still being processed and the - USBDeviceState may not be == CONFIGURED_STATE yet. In this special case, - the USBTransferOnePacket() may still be called, but make sure that the - endpoint has been enabled and initialized by the USBEnableEndpoint() - function first. - + USBDeviceState may not be == CONFIGURED_STATE yet. In this special case, + the USBTransferOnePacket() may still be called, but make sure that the + endpoint has been enabled and initialized by the USBEnableEndpoint() + function first. + *************************************************************************/ USB_HANDLE USBTransferOnePacket(uint8_t ep,uint8_t dir,uint8_t* data,uint8_t len) { @@ -1007,7 +1007,7 @@ USB_HANDLE USBTransferOnePacket(uint8_t ep,uint8_t dir,uint8_t* data,uint8_t len //else point to the OUT BDT of the specified endpoint handle = pBDTEntryOut[ep]; } - + //Error checking code. Make sure the handle (pBDTEntryIn[ep] or //pBDTEntryOut[ep]) is initialized before using it. if(handle == 0) @@ -1050,22 +1050,22 @@ USB_HANDLE USBTransferOnePacket(uint8_t ep,uint8_t dir,uint8_t* data,uint8_t len /******************************************************************** Function: void USBStallEndpoint(uint8_t ep, uint8_t dir) - + Summary: Configures the specified endpoint to send STALL to the host, the next time the host tries to access the endpoint. - + PreCondition: None - + Parameters: uint8_t ep - The endpoint number that should be configured to send STALL. uint8_t dir - The direction of the endpoint to STALL, either IN_TO_HOST or OUT_FROM_HOST. - + Return Values: None - + Remarks: None @@ -1077,22 +1077,22 @@ void USBStallEndpoint(uint8_t ep, uint8_t dir) if(ep == 0) { //For control endpoints (ex: EP0), we need to STALL both IN and OUT - //endpoints. EP0 OUT must also be prepared to receive the next SETUP + //endpoints. EP0 OUT must also be prepared to receive the next SETUP //packet that will arrive. pBDTEntryEP0OutNext->CNT = USB_EP0_BUFF_SIZE; pBDTEntryEP0OutNext->ADR = ConvertToPhysicalAddress(&SetupPkt); pBDTEntryEP0OutNext->STAT.Val = _DAT0|(_DTSEN & _DTS_CHECKING_ENABLED)|_BSTALL; pBDTEntryEP0OutNext->STAT.Val |= _USIE; - pBDTEntryIn[0]->STAT.Val = _BSTALL; + pBDTEntryIn[0]->STAT.Val = _BSTALL; pBDTEntryIn[0]->STAT.Val |= _USIE; - + } else { p = (BDT_ENTRY*)(&BDT[EP(ep,dir,0)]); p->STAT.Val |= _BSTALL; p->STAT.Val |= _USIE; - + //If the device is in FULL or ALL_BUT_EP0 ping pong modes //then stall that entry as well #if (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) || (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) @@ -1106,25 +1106,25 @@ void USBStallEndpoint(uint8_t ep, uint8_t dir) /************************************************************************** Function: void USBCancelIO(uint8_t endpoint) - + Description: This function cancels the transfers pending on the specified endpoint. - This function can only be used after a SETUP packet is received and + This function can only be used after a SETUP packet is received and before that setup packet is handled. This is the time period in which the EVENT_EP0_REQUEST is thrown, before the event handler function returns to the stack. Precondition: - + Parameters: uint8_t endpoint - the endpoint number you wish to cancel the transfers for - + Return Values: None - + Remarks: None - + **************************************************************************/ void USBCancelIO(uint8_t endpoint) { @@ -1134,14 +1134,14 @@ void USBCancelIO(uint8_t endpoint) //to mess with the BDT right now. pBDTEntryIn[endpoint]->Val &= _DTSMASK; //Makes UOWN = 0 (_UCPU mode). Deactivates endpoint. Only sends NAKs. pBDTEntryIn[endpoint]->Val ^= _DTSMASK; //Toggle the DTS bit. This packet didn't get sent yet, and the next call to USBTransferOnePacket() will re-toggle the DTS bit back to the original (correct) value. - + //Need to do additional handling if ping-pong buffering is being used #if ((USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) || (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0)) //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. pBDTEntryIn[endpoint] = (BDT_ENTRY*)(((uintptr_t)pBDTEntryIn[endpoint]) ^ USB_NEXT_PING_PONG); - + pBDTEntryIn[endpoint]->STAT.Val &= _DTSMASK; pBDTEntryIn[endpoint]->STAT.Val ^= _DTSMASK; #endif @@ -1151,11 +1151,11 @@ void USBCancelIO(uint8_t endpoint) /************************************************************************** Function: void USBDeviceDetach(void) - + Summary: This function configures the USB module to "soft detach" itself from the USB host. - + Description: This function configures the USB module to perform a "soft detach" operation, by disabling the D+ (or D-) ~1.5k pull up resistor, which @@ -1164,21 +1164,21 @@ void USBCancelIO(uint8_t endpoint) useful, as it allows the USB device to force the host to re-enumerate the device (on the firmware has re-enabled the USB module/pull up, by calling USBDeviceAttach(), to "soft re-attach" to the host). - + Precondition: Should only be called when USB_INTERRUPT is defined. See remarks section if USB_POLLING mode option is being used (usb_config.h option). - Additionally, this function should only be called from the main() loop - context. Do not call this function from within an interrupt handler, as + Additionally, this function should only be called from the main() loop + context. Do not call this function from within an interrupt handler, as this function may modify global interrupt enable bits and settings. - + Parameters: None - + Return Values: None - + Remarks: If the application firmware calls USBDeviceDetach(), it is strongly recommended that the firmware wait at least >= 80ms before calling @@ -1186,62 +1186,62 @@ void USBCancelIO(uint8_t endpoint) re-attaches too soon (ex: after a few micro seconds for instance), some hosts may interpret this as an unexpected "glitch" rather than as a physical removal/re-attachment of the USB device. In this case the host - may simply ignore the event without re-enumerating the device. To + may simply ignore the event without re-enumerating the device. To ensure that the host properly detects and processes the device soft - detach/re-attach, it is recommended to make sure the device remains - detached long enough to mimic a real human controlled USB + detach/re-attach, it is recommended to make sure the device remains + detached long enough to mimic a real human controlled USB unplug/re-attach event (ex: after calling USBDeviceDetach(), do not call USBDeviceAttach() for at least 80+ms, preferably longer. - + Neither the USBDeviceDetach() or USBDeviceAttach() functions are blocking - or take long to execute. It is the application firmwares - responsibility for adding the 80+ms delay, when using these API + or take long to execute. It is the application firmwares + responsibility for adding the 80+ms delay, when using these API functions. - - Note: The Windows plug and play event handler processing is fairly + + Note: The Windows plug and play event handler processing is fairly slow, especially in certain versions of Windows, and for certain USB device classes. It has been observed that some device classes need to - provide even more USB detach dwell interval (before calling + provide even more USB detach dwell interval (before calling USBDeviceAttach()), in order to work correctly after re-enumeration. If the USB device is a CDC class device, it is recommended to wait at least 1.5 seconds or longer, before soft re-attaching to the host, - to provide the plug and play event handler enough time to finish + to provide the plug and play event handler enough time to finish processing the removal event, before the re-attach occurs. - - If the application is using the USB_POLLING mode option, then the - USBDeviceDetach() and USBDeviceAttach() functions are not available. - In this mode, the USB stack relies on the "#define USE_USB_BUS_SENSE_IO" - and "#define USB_BUS_SENSE" options in the - HardwareProfile – [platform name].h file. - - When using the USB_POLLING mode option, and the - "#define USE_USB_BUS_SENSE_IO" definition has been commented out, then - the USB stack assumes that it should always enable the USB module at - pretty much all times. Basically, anytime the application firmware - calls USBDeviceTasks(), the firmware will automatically enable the USB - module. This mode would typically be selected if the application was - designed to be a purely bus powered device. In this case, the - application is powered from the +5V VBUS supply from the USB port, so - it is correct and sensible in this type of application to power up and - turn on the USB module, at anytime that the microcontroller is - powered (which implies the USB cable is attached and the host is also + + If the application is using the USB_POLLING mode option, then the + USBDeviceDetach() and USBDeviceAttach() functions are not available. + In this mode, the USB stack relies on the "#define USE_USB_BUS_SENSE_IO" + and "#define USB_BUS_SENSE" options in the + HardwareProfile – [platform name].h file. + + When using the USB_POLLING mode option, and the + "#define USE_USB_BUS_SENSE_IO" definition has been commented out, then + the USB stack assumes that it should always enable the USB module at + pretty much all times. Basically, anytime the application firmware + calls USBDeviceTasks(), the firmware will automatically enable the USB + module. This mode would typically be selected if the application was + designed to be a purely bus powered device. In this case, the + application is powered from the +5V VBUS supply from the USB port, so + it is correct and sensible in this type of application to power up and + turn on the USB module, at anytime that the microcontroller is + powered (which implies the USB cable is attached and the host is also powered). - In a self powered application, the USB stack is designed with the - intention that the user will enable the "#define USE_USB_BUS_SENSE_IO" - option in the HardwareProfile – [platform name].h file. When this - option is defined, then the USBDeviceTasks() function will automatically - check the I/O pin port value of the designated pin (based on the - #define USB_BUS_SENSE option in the HardwareProfile – [platform name].h - file), every time the application calls USBDeviceTasks(). If the - USBDeviceTasks() function is executed and finds that the pin defined by - the #define USB_BUS_SENSE is in a logic low state, then it will - automatically disable the USB module and tri-state the D+ and D- pins. - If however the USBDeviceTasks() function is executed and finds the pin - defined by the #define USB_BUS_SENSE is in a logic high state, then it - will automatically enable the USB module, if it has not already been - enabled. - + In a self powered application, the USB stack is designed with the + intention that the user will enable the "#define USE_USB_BUS_SENSE_IO" + option in the HardwareProfile – [platform name].h file. When this + option is defined, then the USBDeviceTasks() function will automatically + check the I/O pin port value of the designated pin (based on the + #define USB_BUS_SENSE option in the HardwareProfile – [platform name].h + file), every time the application calls USBDeviceTasks(). If the + USBDeviceTasks() function is executed and finds that the pin defined by + the #define USB_BUS_SENSE is in a logic low state, then it will + automatically disable the USB module and tri-state the D+ and D- pins. + If however the USBDeviceTasks() function is executed and finds the pin + defined by the #define USB_BUS_SENSE is in a logic high state, then it + will automatically enable the USB module, if it has not already been + enabled. + **************************************************************************/ #if defined(USB_INTERRUPT) void USBDeviceDetach(void) @@ -1254,15 +1254,15 @@ void USBDeviceDetach(void) #endif { // Disable module & detach from bus - U1CON = 0; + U1CON = 0; - // Mask all USB interrupts - U1IE = 0; + // Mask all USB interrupts + U1IE = 0; - //Move to the detached state + //Move to the detached state USBDeviceState = DETACHED_STATE; - #ifdef USB_SUPPORT_OTG + #ifdef USB_SUPPORT_OTG //Disable D+ Pull-up U1OTGCONbits.DPPULUP = 0; @@ -1271,10 +1271,10 @@ void USBDeviceDetach(void) //Deactivate HNP USBOTGDeactivateHnp(); - + //If ID Pin Changed State if (USBIDIF && USBIDIE) - { + { //Re-detect & Initialize USBOTGInitialize(); @@ -1284,9 +1284,9 @@ void USBDeviceDetach(void) #endif #if defined __C30__ || defined __XC16__ - //USBClearInterruptFlag(U1OTGIR, 3); + //USBClearInterruptFlag(U1OTGIR, 3); #endif - //return so that we don't go through the rest of + //return so that we don't go through the rest of //the state machine return; } @@ -1297,7 +1297,7 @@ void USBDeviceDetach(void) { //If SRP Is Ready if (USBOTGSRPIsReady()) - { + { //Clear SRPReady USBOTGClearSRPReady(); @@ -1314,39 +1314,39 @@ void USBDeviceDetach(void) /************************************************************************** Function: void USBDeviceAttach(void) - + Summary: - Checks if VBUS is present, and that the USB module is not already - initialized, and if so, enables the USB module so as to signal device - attachment to the USB host. + Checks if VBUS is present, and that the USB module is not already + initialized, and if so, enables the USB module so as to signal device + attachment to the USB host. Description: This function indicates to the USB host that the USB device has been attached to the bus. This function needs to be called in order for the device to start to enumerate on the bus. - + Precondition: - Should only be called when USB_INTERRUPT is defined. Also, should only + Should only be called when USB_INTERRUPT is defined. Also, should only be called from the main() loop context. Do not call USBDeviceAttach() from within an interrupt handler, as the USBDeviceAttach() function may modify global interrupt enable bits and settings. For normal USB devices: - Make sure that if the module was previously on, that it has been turned off + Make sure that if the module was previously on, that it has been turned off for a long time (ex: 100ms+) before calling this function to re-enable the module. If the device turns off the D+ (for full speed) or D- (for low speed) ~1.5k ohm - pull up resistor, and then turns it back on very quickly, common hosts will sometimes - reject this event, since no human could ever unplug and re-attach a USB device in a - microseconds (or nanoseconds) timescale. The host could simply treat this as some kind - of glitch and ignore the event altogether. + pull up resistor, and then turns it back on very quickly, common hosts will sometimes + reject this event, since no human could ever unplug and re-attach a USB device in a + microseconds (or nanoseconds) timescale. The host could simply treat this as some kind + of glitch and ignore the event altogether. Parameters: None - + Return Values: - None - - Remarks: - See also the USBDeviceDetach() API function documentation. + None + + Remarks: + See also the USBDeviceDetach() API function documentation. ****************************************************************************/ #if defined(USB_INTERRUPT) void USBDeviceAttach(void) @@ -1357,25 +1357,25 @@ void USBDeviceAttach(void) if(USB_BUS_SENSE == 1) { //Initialize registers to known states. - U1CON = 0; - + U1CON = 0; + // Mask all USB interrupts - U1IE = 0; - - //Configure things like: pull ups, full/low-speed mode, + U1IE = 0; + + //Configure things like: pull ups, full/low-speed mode, //set the ping pong mode, and set internal transceiver SetConfigurationOptions(); - + USBEnableInterrupts(); //Modifies global interrupt settings - + // Enable module & attach to bus while(!U1CONbits.USBEN){U1CONbits.USBEN = 1;} - + //moved to the attached state USBDeviceState = ATTACHED_STATE; - + #ifdef USB_SUPPORT_OTG - U1OTGCON = USB_OTG_DPLUS_ENABLE | USB_OTG_ENABLE; + U1OTGCON = USB_OTG_DPLUS_ENABLE | USB_OTG_ENABLE; #endif } } @@ -1416,9 +1416,9 @@ void USBDeviceAttach(void) void USBCtrlEPAllowStatusStage(void) { //Check and set two flags, prior to actually modifying any BDT entries. - //This double checking is necessary to make certain that - //USBCtrlEPAllowStatusStage() can be called twice simultaneously (ex: once - //in main loop context, while simultaneously getting an interrupt which + //This double checking is necessary to make certain that + //USBCtrlEPAllowStatusStage() can be called twice simultaneously (ex: once + //in main loop context, while simultaneously getting an interrupt which //tries to call USBCtrlEPAllowStatusStage() again, at the same time). if(USBStatusStageEnabledFlag1 == false) { @@ -1426,13 +1426,13 @@ void USBCtrlEPAllowStatusStage(void) if(USBStatusStageEnabledFlag2 == false) { USBStatusStageEnabledFlag2 = true; - + //Determine which endpoints (EP0 IN or OUT needs arming for the status //stage), based on the type of control transfer currently pending. if(controlTransferState == CTRL_TRF_RX) { pBDTEntryIn[0]->CNT = 0; - pBDTEntryIn[0]->STAT.Val = _DAT1|(_DTSEN & _DTS_CHECKING_ENABLED); + pBDTEntryIn[0]->STAT.Val = _DAT1|(_DTSEN & _DTS_CHECKING_ENABLED); pBDTEntryIn[0]->STAT.Val |= _USIE; } else if(controlTransferState == CTRL_TRF_TX) @@ -1454,28 +1454,28 @@ void USBCtrlEPAllowStatusStage(void) pBDTEntryEP0OutNext->ADR = ConvertToPhysicalAddress(&SetupPkt); pBDTEntryEP0OutNext->STAT.Val = _USIE; // Note: DTSEN is 0 } - } + } } -} +} /******************************************************************************* Function: void USBCtrlEPAllowDataStage(void); - + Summary: This function allows the data stage of either a host-to-device or device-to-host control transfer (with data stage) to complete. This function is meant to be used in conjunction with either the USBDeferOUTDataStage() or USBDeferINDataStage(). If the firmware does not call either USBDeferOUTDataStage() or USBDeferINDataStage(), - then the firmware does not need to manually call + then the firmware does not need to manually call USBCtrlEPAllowDataStage(), as the USB stack will call this function instead. - + Description: - - Conditions: A control transfer (with data stage) should already be pending, + + Conditions: A control transfer (with data stage) should already be pending, if the firmware calls this function. Additionally, the firmware - should have called either USBDeferOUTDataStage() or + should have called either USBDeferOUTDataStage() or USBDeferINDataStage() at the start of the control transfer, if the firmware will be calling this function manually. @@ -1483,7 +1483,7 @@ void USBCtrlEPAllowStatusStage(void) Return: - Remarks: + Remarks: *****************************************************************************/ void USBCtrlEPAllowDataStage(void) { @@ -1497,7 +1497,7 @@ void USBCtrlEPAllowDataStage(void) pBDTEntryEP0OutNext->ADR = ConvertToPhysicalAddress(&CtrlTrfData); pBDTEntryEP0OutNext->STAT.Val = _DAT1|(_DTSEN & _DTS_CHECKING_ENABLED); pBDTEntryEP0OutNext->STAT.Val |= _USIE; - } + } else //else must be controlTransferState == CTRL_TRF_TX (...) { //Error check the data stage byte count. Make sure the user specified @@ -1514,8 +1514,8 @@ void USBCtrlEPAllowDataStage(void) pBDTEntryIn[0]->ADR = ConvertToPhysicalAddress(&CtrlTrfData); pBDTEntryIn[0]->STAT.Val = _DAT1|(_DTSEN & _DTS_CHECKING_ENABLED); pBDTEntryIn[0]->STAT.Val |= _USIE; - } -} + } +} /******************************************************************************/ @@ -1535,7 +1535,7 @@ void USBCtrlEPAllowDataStage(void) * * Side Effects: None * - * Overview: This function will configure the specified + * Overview: This function will configure the specified * endpoint * * Note: None @@ -1548,8 +1548,8 @@ static void USBConfigureEndpoint(uint8_t EPNum, uint8_t direction) //EPNum and direction values passed to this function. handle = (volatile BDT_ENTRY*)&BDT[EP0_OUT_EVEN]; //Get address of start of BDT handle += EP(EPNum,direction,0u); //Add in offset to the BDT of interest - - handle->STAT.UOWN = 0; //mostly redundant, since USBStdSetCfgHandler() + + handle->STAT.UOWN = 0; //mostly redundant, since USBStdSetCfgHandler() //already cleared the entire BDT table //Make sure our pBDTEntryIn/Out[] pointer is initialized. Needed later @@ -1575,7 +1575,7 @@ static void USBConfigureEndpoint(uint8_t EPNum, uint8_t direction) { handle->STAT.DTS = 1; } - #elif (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) + #elif (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) if(EPNum != 0) { handle->STAT.DTS = 0; @@ -1623,7 +1623,7 @@ static void USBCtrlEPServiceComplete(void) //Check the busy bits and the SetupPtk.DataDir variables to determine what type of //control transfer is currently in progress. We need to know the type of control - //transfer that is currently pending, in order to know how to properly arm the + //transfer that is currently pending, in order to know how to properly arm the //EP0 IN and EP0 OUT endpoints. if(inPipes[0].info.bits.busy == 0) { @@ -1644,8 +1644,8 @@ static void USBCtrlEPServiceComplete(void) { USBCtrlEPAllowDataStage(); } - - //2. IN endpoint 0 status stage will be armed by USBCtrlEPAllowStatusStage() + + //2. IN endpoint 0 status stage will be armed by USBCtrlEPAllowStatusStage() //after all of the OUT data has been received and consumed, or if a timeout occurs. USBStatusStageEnabledFlag2 = false; USBStatusStageEnabledFlag1 = false; @@ -1679,7 +1679,7 @@ static void USBCtrlEPServiceComplete(void) * Then the class request handler responsible should call the USBDeferDataStage() * macro. In this case, the firmware may wait up to 500ms, before it is required * to transmit the first IN data packet. Once the data is ready, and the firmware - * is ready to begin sending the data, it should then call the + * is ready to begin sending the data, it should then call the * USBCtrlEPAllowDataStage() function to start the data stage. */ if(USBDeferINDataStagePackets == false) @@ -1694,9 +1694,9 @@ static void USBCtrlEPServiceComplete(void) // be written so that it can handle the early termination scenario. // Ex: It should call USBCtrlEPAllowStatusStage() when any of the following occurs: // 1. The desired total number of bytes were sent to the host. - // 2. The number of bytes that the host originally requested (in the SETUP packet that + // 2. The number of bytes that the host originally requested (in the SETUP packet that // started the control transfer) has been reached. - // 3. Or, if a timeout occurs (ex: <50ms since the last successful EP0 IN transaction), regardless + // 3. Or, if a timeout occurs (ex: <50ms since the last successful EP0 IN transaction), regardless // of how many bytes have actually been sent. This is necessary to prevent a deadlock situation // (where the control transfer can't complete, due to continuous NAK on status stage) if the // host performs early termination. If enabled, the USB_ENABLE_STATUS_STAGE_TIMEOUTS usb_config.h @@ -1704,7 +1704,7 @@ static void USBCtrlEPServiceComplete(void) // Note: For this type of control transfer, there is normally no harm in simply arming the // status stage packet right now, even if the IN data is not ready yet. This allows for // immediate early termination, without adding unnecessary delay. Therefore, it is generally not - // recommended for the USB class handler firmware to call USBDeferStatusStage(), for this + // recommended for the USB class handler firmware to call USBDeferStatusStage(), for this // type of control transfer. If the USB class handler firmware needs more time to fetch the IN // data that needs to be sent to the host, it should instead use the USBDeferDataStage() function. USBStatusStageEnabledFlag2 = false; @@ -1712,7 +1712,7 @@ static void USBCtrlEPServiceComplete(void) if(USBDeferStatusStagePacket == false) { USBCtrlEPAllowStatusStage(); - } + } } else // (SetupPkt.DataDir == USB_SETUP_DIRECTION_HOST_TO_DEVICE) { @@ -1721,26 +1721,26 @@ static void USBCtrlEPServiceComplete(void) //control transfer. Ex: // // | - + //Although the data direction is HOST_TO_DEVICE, there is no data stage //(hence: outPipes[0].info.bits.busy == 0). There is however still //an IN status stage. controlTransferState = CTRL_TRF_RX; //Since this is a HOST_TO_DEVICE control transfer - + //1. Prepare OUT EP to receive the next SETUP packet. pBDTEntryEP0OutNext->CNT = USB_EP0_BUFF_SIZE; pBDTEntryEP0OutNext->ADR = ConvertToPhysicalAddress(&SetupPkt); pBDTEntryEP0OutNext->STAT.Val = _BSTALL; pBDTEntryEP0OutNext->STAT.Val |= _USIE; - + //2. Prepare for IN status stage of the control transfer USBStatusStageEnabledFlag2 = false; USBStatusStageEnabledFlag1 = false; if(USBDeferStatusStagePacket == false) { USBCtrlEPAllowStatusStage(); - } + } } }//end if(ctrl_trf_session_owner == MUID_NULL) @@ -1759,14 +1759,14 @@ static void USBCtrlEPServiceComplete(void) * * Side Effects: None * - * Overview: This routine is used for device to host control transfers + * Overview: This routine is used for device to host control transfers * (IN transactions). This function takes care of managing a * transfer over multiple USB transactions. * This routine should be called from only two places. * One from USBCtrlEPServiceComplete() and one from * USBCtrlTrfInHandler(). * - * Note: + * Note: *****************************************************************************/ static void USBCtrlTrfTxService(void) { @@ -1774,7 +1774,7 @@ static void USBCtrlTrfTxService(void) //Figure out how many bytes of data to send in the next IN transaction. //Assume a full size packet, unless otherwise determined below. - byteToSend = USB_EP0_BUFF_SIZE; + byteToSend = USB_EP0_BUFF_SIZE; if(inPipes[0].wCount.Val < (uint8_t)USB_EP0_BUFF_SIZE) { byteToSend = inPipes[0].wCount.Val; @@ -1782,7 +1782,7 @@ static void USBCtrlTrfTxService(void) //Keep track of whether or not we have sent a "short packet" yet. //This is useful so that later on, we can configure EP0 IN to STALL, //after we have sent all of the intended data. This makes sure the - //hardware STALLs if the host erroneously tries to send more IN token + //hardware STALLs if the host erroneously tries to send more IN token //packets, requesting more data than intended in the control transfer. if(shortPacketStatus == SHORT_PKT_NOT_USED) { @@ -1797,7 +1797,7 @@ static void USBCtrlTrfTxService(void) //Keep track of how many bytes remain to be sent in the transfer, by //subtracting the number of bytes about to be sent from the total. inPipes[0].wCount.Val -= byteToSend; - + //Next, load the number of bytes to send to BC7..0 in buffer descriptor. //Note: Control endpoints may never have a max packet size of > 64 bytes. //Therefore, the BC8 and BC9 bits should always be maintained clear. @@ -1854,9 +1854,9 @@ static void USBCtrlTrfRxService(void) uint8_t byteToRead; uint8_t i; - //Load byteToRead with the number of bytes the host just sent us in the + //Load byteToRead with the number of bytes the host just sent us in the //last OUT transaction. - byteToRead = pBDTEntryEP0OutCurrent->CNT; + byteToRead = pBDTEntryEP0OutCurrent->CNT; //Update the "outPipes[0].wCount.Val", which keeps track of the total number //of remaining bytes expected to be received from the host, in the control @@ -1865,7 +1865,7 @@ static void USBCtrlTrfRxService(void) if(byteToRead > outPipes[0].wCount.Val) { byteToRead = outPipes[0].wCount.Val; - } + } //Reduce the number of remaining bytes by the number we just received. outPipes[0].wCount.Val -= byteToRead; @@ -1876,7 +1876,7 @@ static void USBCtrlTrfRxService(void) *outPipes[0].pDst.bRam++ = CtrlTrfData[i]; }//end while(byteToRead.Val) - //If there is more data to receive, prepare EP0 OUT so that it can receive + //If there is more data to receive, prepare EP0 OUT so that it can receive //the next packet in the sequence. if(outPipes[0].wCount.Val > 0) { @@ -1909,7 +1909,7 @@ static void USBCtrlTrfRxService(void) //All data bytes for the host to device control write (OUT) have now been //received successfully. //Go ahead and call the user specified callback function, to use/consume - //the control transfer data (ex: if the "void (*function)" parameter + //the control transfer data (ex: if the "void (*function)" parameter //was non-NULL when USBEP0Receive() was called). if(outPipes[0].pFunc != NULL) { @@ -1924,14 +1924,14 @@ static void USBCtrlTrfRxService(void) outPipes[0].pFunc(); //Call the user's callback function #endif } - outPipes[0].info.bits.busy = 0; + outPipes[0].info.bits.busy = 0; //Ready to arm status stage IN transaction now, if the application //firmware has completed processing the request. If it is still busy //and needs more time to finish handling the request, then the user //callback (the one called by the outPipes[0].pFunc();) should set the //USBDeferStatusStagePacket to true (by calling USBDeferStatusStage()). In - //this case, it is the application's firmware responsibility to call + //this case, it is the application's firmware responsibility to call //the USBCtrlEPAllowStatusStage() function, once it is fully done handling the request. //Note: The application firmware must process the request and call //USBCtrlEPAllowStatusStage() in a semi-timely fashion. "Semi-timely" @@ -1941,8 +1941,8 @@ static void USBCtrlTrfRxService(void) if(USBDeferStatusStagePacket == false) { USBCtrlEPAllowStatusStage(); - } - } + } + } }//end USBCtrlTrfRxService @@ -1970,7 +1970,7 @@ static void USBStdSetCfgHandler(void) uint8_t i; // This will generate a zero length packet - inPipes[0].info.bits.busy = 1; + inPipes[0].info.bits.busy = 1; //Clear all of the endpoint control registers DisableNonZeroEndpoints(USB_MAX_EP_NUMBER); @@ -1979,10 +1979,10 @@ static void USBStdSetCfgHandler(void) memset((void*)&BDT[0], 0x00, sizeof(BDT)); // Assert reset request to all of the Ping Pong buffer pointers - USBPingPongBufferReset = 1; + USBPingPongBufferReset = 1; //Re-Initialize all ping pong software state bits to 0 (which corresponds to - //the EVEN buffer being the next one that will be used), since we are also + //the EVEN buffer being the next one that will be used), since we are also //doing a hardware ping pong pointer reset above. for(i = 0; i < (uint8_t)(USB_MAX_EP_NUMBER+1u); i++) { @@ -2019,7 +2019,7 @@ static void USBStdSetCfgHandler(void) //Otherwise go to the configured state. Update the state variable last, //after performing all of the set configuration related initialization //tasks. - USBDeviceState = CONFIGURED_STATE; + USBDeviceState = CONFIGURED_STATE; }//end if(SetupPkt.bConfigurationValue == 0) }//end USBStdSetCfgHandler @@ -2057,8 +2057,8 @@ static void USBStdGetDscHandler(void) inPipes[0].wCount.Val = sizeof(device_dsc); break; case USB_DESCRIPTOR_CONFIGURATION: - //First perform error case check, to make sure the host is requesting a - //legal descriptor index. If the request index is illegal, don't do + //First perform error case check, to make sure the host is requesting a + //legal descriptor index. If the request index is illegal, don't do //anything (so that the default STALL response will be sent). if(SetupPkt.bDscIndex < USB_MAX_NUM_CONFIG_DSC) { @@ -2088,7 +2088,7 @@ static void USBStdGetDscHandler(void) //Get a pointer to the String descriptor requested inPipes[0].pSrc.bRom = *(USB_SD_Ptr+SetupPkt.bDscIndex); // Set data count - inPipes[0].wCount.Val = *inPipes[0].pSrc.bRom; + inPipes[0].wCount.Val = *inPipes[0].pSrc.bRom; } #if defined(IMPLEMENT_MICROSOFT_OS_DESCRIPTOR) else if(SetupPkt.bDscIndex == MICROSOFT_OS_DESCRIPTOR_INDEX) @@ -2096,8 +2096,8 @@ static void USBStdGetDscHandler(void) //Get a pointer to the special MS OS string descriptor requested inPipes[0].pSrc.bRom = (const uint8_t*)&MSOSDescriptor; // Set data count - inPipes[0].wCount.Val = *inPipes[0].pSrc.bRom; - } + inPipes[0].wCount.Val = *inPipes[0].pSrc.bRom; + } #endif else { @@ -2192,9 +2192,9 @@ static void USBStdGetStatusHandler(void) * * Output: None * - * Side Effects: + * Side Effects: * - * Overview: This function handles the event of a STALL + * Overview: This function handles the event of a STALL * occurring on the bus * * Note: None @@ -2235,9 +2235,9 @@ static void USBStallHandler(void) * * Output: None * - * Side Effects: + * Side Effects: * - * Overview: This function handles if the host tries to + * Overview: This function handles if the host tries to * suspend the device * * Note: None @@ -2276,7 +2276,7 @@ static void USBSuspend(void) #endif USBBusIsSuspended = true; USBTicksSinceSuspendEnd = 0; - + /* * At this point the PIC can go into sleep,idle, or * switch to a slower clock, etc. This should be done in the @@ -2313,7 +2313,7 @@ static void USBWakeFromSuspend(void) #if defined(__18CXX) || defined(_PIC14E) || defined(__XC8) //To avoid improperly clocking the USB module, make sure the oscillator //settings are consistent with USB operation before clearing the SUSPND bit. - //Make sure the correct oscillator settings are selected in the + //Make sure the correct oscillator settings are selected in the //"USB_WAKEUP_FROM_SUSPEND_HANDLER(EVENT_RESUME,0,0)" handler. U1CONbits.SUSPND = 0; // Bring USB module out of power conserve // mode. @@ -2371,13 +2371,13 @@ static void USBWakeFromSuspend(void) *******************************************************************/ static void USBCtrlEPService(void) { - //If we get to here, that means a successful transaction has just occurred - //on EP0. This means "progress" has occurred in the currently pending + //If we get to here, that means a successful transaction has just occurred + //on EP0. This means "progress" has occurred in the currently pending //control transfer, so we should re-initialize our timeout counter. #if defined(USB_ENABLE_STATUS_STAGE_TIMEOUTS) USBStatusStageTimeoutCounter = USB_STATUS_STAGE_TIMEOUT; #endif - + //Check if the last transaction was on EP0 OUT endpoint (of any kind, to either the even or odd buffer if ping pong buffers used) if((USTATcopy.Val & USTAT_EP0_PP_MASK) == USTAT_EP0_OUT_EVEN) { @@ -2398,10 +2398,10 @@ static void USBCtrlEPService(void) //If the current EP0 OUT buffer has a SETUP packet if(pBDTEntryEP0OutCurrent->STAT.PID == PID_SETUP) { - //The SETUP transaction data may have gone into the the CtrlTrfData + //The SETUP transaction data may have gone into the the CtrlTrfData //buffer, or elsewhere, depending upon how the BDT was prepared - //before the transaction. Therefore, we should copy the data to the - //SetupPkt buffer so it can be processed correctly by USBCtrlTrfSetupHandler(). + //before the transaction. Therefore, we should copy the data to the + //SetupPkt buffer so it can be processed correctly by USBCtrlTrfSetupHandler(). memcpy((uint8_t*)&SetupPkt, (uint8_t*)ConvertToVirtualAddress(pBDTEntryEP0OutCurrent->ADR), 8); //Handle the control transfer (parse the 8-byte SETUP command and figure out what to do) @@ -2467,7 +2467,7 @@ static void USBCtrlTrfSetupHandler(void) //-------------------------------------------------------------------------- //1. Re-initialize state tracking variables related to control transfers. //-------------------------------------------------------------------------- - shortPacketStatus = SHORT_PKT_NOT_USED; + shortPacketStatus = SHORT_PKT_NOT_USED; USBDeferStatusStagePacket = false; USBDeferINDataStagePackets = false; USBDeferOUTDataStagePackets = false; @@ -2481,18 +2481,18 @@ 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); - + 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); + pBDTEntryIn[0]->STAT.Val &= ~(_USIE); pBDTEntryIn[0] = (volatile BDT_ENTRY*)(((uintptr_t)pBDTEntryIn[0]) ^ USB_NEXT_EP0_IN_PING_PONG); - pBDTEntryEP0OutNext->STAT.Val &= ~(_USIE); + pBDTEntryEP0OutNext->STAT.Val &= ~(_USIE); inPipes[0].info.Val = 0; inPipes[0].wCount.Val = 0; outPipes[0].info.Val = 0; outPipes[0].wCount.Val = 0; - + //-------------------------------------------------------------------------- //2. Now find out what was in the SETUP packet, and begin handling the request. @@ -2502,15 +2502,15 @@ static void USBCtrlTrfSetupHandler(void) //-------------------------------------------------------------------------- - //3. Re-arm EP0 IN and EP0 OUT endpoints, based on the control transfer in + //3. Re-arm EP0 IN and EP0 OUT endpoints, based on the control transfer in // progress. If one of the above handlers (in step 2) knew how to process // the request, it will have set one of the inPipes[0].info.bits.busy or // outPipes[0].info.bits.busy flags = 1. This lets the - // USBCtrlEPServiceComplete() function know how and which endpoints to + // USBCtrlEPServiceComplete() function know how and which endpoints to // arm. If both info.bits.busy flags are = 0, then no one knew how to // process the request. In this case, the default behavior will be to // perform protocol STALL on EP0. - //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- USBCtrlEPServiceComplete(); }//end USBCtrlTrfSetupHandler @@ -2543,7 +2543,7 @@ static void USBCtrlTrfOutHandler(void) } else //In this case the last OUT transaction must have been a status stage of a CTRL_TRF_TX (... <-- this last OUT just occurred as the status stage) { - //If the status stage is complete, this means we are done with the + //If the status stage is complete, this means we are done with the //control transfer. Go back to the idle "WAIT_SETUP" state. controlTransferState = WAIT_SETUP; @@ -2599,7 +2599,7 @@ static void USBCtrlTrfInHandler(void) 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 + //now, since the IN status stage of the (set address) control transfer has //evidently completed successfully. if(USBDeviceState == ADR_PENDING_STATE) { @@ -2658,11 +2658,11 @@ static void USBCtrlTrfInHandler(void) } outPipes[0].info.bits.busy = 0; } - + controlTransferState = WAIT_SETUP; //Don't need to arm EP0 OUT here. It was already armed by the last that //got processed by the USBCtrlTrfRxService() handler. - } + } } @@ -2747,9 +2747,9 @@ static void USBCheckStdRequest(void) * Overview: This routine handles the standard SET & CLEAR * FEATURES requests * - * Note: This is a private function, intended for internal + * Note: This is a private function, intended for internal * use by the USB stack, when processing SET/CLEAR - * feature requests. + * feature requests. *******************************************************************/ static void USBStdFeatureReqHandler(void) { @@ -2758,15 +2758,15 @@ static void USBStdFeatureReqHandler(void) #if defined(__C32__) uint32_t* pUEP; #else - unsigned char* pUEP; + unsigned char* pUEP; #endif - + #ifdef USB_SUPPORT_OTG //Check for USB On-The-Go (OTG) specific requests if ((SetupPkt.bFeature == OTG_FEATURE_B_HNP_ENABLE)&& (SetupPkt.Recipient == USB_SETUP_RECIPIENT_DEVICE_BITFIELD)) - { + { inPipes[0].info.bits.busy = 1; if(SetupPkt.bRequest == USB_REQUEST_SET_FEATURE) USBOTGEnableHnp(); @@ -2793,7 +2793,7 @@ static void USBStdFeatureReqHandler(void) else USBOTGDisableAltHnp(); } - #endif //#ifdef USB_SUPPORT_OTG + #endif //#ifdef USB_SUPPORT_OTG //Check if the host sent a valid SET or CLEAR feature (remote wakeup) request. if((SetupPkt.bFeature == USB_FEATURE_DEVICE_REMOTE_WAKEUP)&& @@ -2828,10 +2828,10 @@ static void USBStdFeatureReqHandler(void) current_ep_data.Val = ep_data_in[SetupPkt.EPNum].Val; } - //If ping pong buffering is enabled on the requested endpoint, need - //to point to the one that is the active BDT entry which the SIE will + //If ping pong buffering is enabled on the requested endpoint, need + //to point to the one that is the active BDT entry which the SIE will //use for the next attempted transaction on that EP number. - #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) + #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 { p = (BDT_ENTRY*)(((uintptr_t)p) & (~USB_NEXT_PING_PONG)); @@ -2841,7 +2841,7 @@ static void USBStdFeatureReqHandler(void) p = (BDT_ENTRY*)(((uintptr_t)p) | USB_NEXT_PING_PONG); } #endif - + //Update the BDT pointers with the new, next entry based on the feature // request if(SetupPkt.EPDir == OUT_FROM_HOST) @@ -2877,9 +2877,9 @@ static void USBStdFeatureReqHandler(void) else { //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) + #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 - p = (BDT_ENTRY*)(((uintptr_t)p) ^ USB_NEXT_PING_PONG); + p = (BDT_ENTRY*)(((uintptr_t)p) ^ USB_NEXT_PING_PONG); if(p->STAT.UOWN == 1) { @@ -2891,14 +2891,14 @@ static void USBStdFeatureReqHandler(void) } else { - //UOWN already clear, but still need to set DTS to DATA1 + //UOWN already clear, but still need to set DTS to DATA1 p->STAT.Val |= _DAT1; } //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 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, //set DTS to the proper state, and call the application callback @@ -2913,17 +2913,17 @@ static void USBStdFeatureReqHandler(void) { ep_data_in[SetupPkt.EPNum].bits.transfer_terminated = 0; } - //clear UOWN, clear DTS to DATA0, and finally remove the STALL condition - p->STAT.Val &= ~(_USIE | _DAT1 | _BSTALL); - //Call the application event handler callback function, so it can + //clear UOWN, clear DTS to DATA0, and finally remove the STALL condition + p->STAT.Val &= ~(_USIE | _DAT1 | _BSTALL); + //Call the application event handler callback function, so it can //decide if the endpoint should get re-armed again or not. USB_TRANSFER_TERMINATED_HANDLER(EVENT_TRANSFER_TERMINATED,p,sizeof(p)); } else { - //clear UOWN, clear DTS to DATA0, and finally remove the STALL condition - p->STAT.Val &= ~(_USIE | _DAT1 | _BSTALL); - } + //clear UOWN, clear DTS to DATA0, and finally remove the STALL condition + p->STAT.Val &= ~(_USIE | _DAT1 | _BSTALL); + } #else //else we must not be using ping-pong buffering on the requested endpoint //Check if we need to call the user transfer terminated event callback function. //We should call the callback, if the endpoint was previously terminated, @@ -2942,29 +2942,29 @@ static void USBStdFeatureReqHandler(void) { ep_data_in[SetupPkt.EPNum].bits.transfer_terminated = 0; } - - //Clear UOWN and remove the STALL condition. + + //Clear UOWN and remove the STALL condition. // In this case we also need to set the DTS bit to 1 so that // it toggles to DATA0 the next time the application firmware - // calls USBTransferOnePacket() (or equivalent macro). - p->STAT.Val &= ~(_USIE | _BSTALL); + // calls USBTransferOnePacket() (or equivalent macro). + p->STAT.Val &= ~(_USIE | _BSTALL); p->STAT.Val |= _DAT1; //Let the application firmware know a transaction just //got terminated by the host, and that it is now free to - //re-arm the endpoint or do other tasks if desired. + //re-arm the endpoint or do other tasks if desired. USB_TRANSFER_TERMINATED_HANDLER(EVENT_TRANSFER_TERMINATED,p,sizeof(p)); } else { - //Clear UOWN and remove the STALL condition. + //Clear UOWN and remove the STALL condition. // In this case we also need to set the DTS bit to 1 so that // it toggles to DATA0 the next time the application firmware - // calls USBTransferOnePacket() (or equivalent macro). - p->STAT.Val &= ~(_USIE | _BSTALL); + // calls USBTransferOnePacket() (or equivalent macro). + p->STAT.Val &= ~(_USIE | _BSTALL); p->STAT.Val |= _DAT1; - } - #endif //end of #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) - + } + #endif //end of #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) + //Get a pointer to the appropriate UEPn register #if defined(__C32__) pUEP = (uint32_t*)(&U1EP0); @@ -2974,7 +2974,7 @@ static void USBStdFeatureReqHandler(void) #endif //Clear the STALL bit in the UEP register - *pUEP &= ~UEP_STALL; + *pUEP &= ~UEP_STALL; }//end if(SetupPkt.bRequest == USB_REQUEST_SET_FEATURE) }//end if (lots of checks for set/clear endpoint halt) }//end USBStdFeatureReqHandler @@ -3082,7 +3082,7 @@ void USBIncrement1msInternalTimers(void) USBIncrement1msInternalTimers() periodically (ex: from a general purpose timer interrupt handler), or else the returned value from this function will not increment. - + Prior to calling USBDeviceInit() for the first time the returned value will be unpredictable. @@ -3114,8 +3114,8 @@ uint32_t USBGet1msTickCount(void) localContextValue = USB1msTickCount; }while(localContextValue != USB1msTickCount); - return localContextValue; - + return localContextValue; + #else return USB1msTickCount; #endif diff --git a/src/usb_device_audio.c b/src/usb_device_audio.c index 36fa02e..240256b 100644 --- a/src/usb_device_audio.c +++ b/src/usb_device_audio.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -28,7 +28,7 @@ please contact mla_licensing@microchip.com #if defined USB_AUDIO_INPUT_TERMINAL_CONTROL_REQUESTS_HANDLER void USB_AUDIO_INPUT_TERMINAL_CONTROL_REQUESTS_HANDLER(void); -#endif +#endif #if defined USB_AUDIO_OUTPUT_TERMINAL_CONTROL_REQUESTS_HANDLER void USB_AUDIO_OUTPUT_TERMINAL_CONTROL_REQUESTS_HANDLER(void); @@ -113,7 +113,7 @@ void USBCheckAudioRequest(void) */ if((SetupPkt.bIntfID != AUDIO_CONTROL_INTERFACE_ID)&& (SetupPkt.bIntfID != AUDIO_STREAMING_INTERFACE_ID)) return; - + switch(SetupPkt.wIndex >> 8)// checking for the Entity ID (Entity ID are defined in the config.h file) { case ID_INPUT_TERMINAL: diff --git a/src/usb_device_ccid.c b/src/usb_device_ccid.c index 9341a7f..0045b8e 100644 --- a/src/usb_device_ccid.c +++ b/src/usb_device_ccid.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -35,15 +35,15 @@ POINTER pCCIDSrc; // Dedicated source pointer /** P R I V A T E P R O T O T Y P E S ***************************************/ #if defined USB_CCID_SUPPORT_ABORT_REQUEST void USB_CCID_ABORT_REQUEST_HANDLER(void); -#endif +#endif #if defined USB_CCID_SUPPORT_GET_CLOCK_FREQUENCIES_REQUEST void USB_CCID_GET_CLOCK_FREQUENCIES_REQUEST_HANDLER(void); -#endif +#endif #if defined USB_CCID_SUPPORT_GET_DATA_RATES_REQUEST void USB_CCID_GET_DATA_RATES_REQUEST_HANDLER(void); -#endif +#endif @@ -53,25 +53,25 @@ POINTER pCCIDSrc; // Dedicated source pointer /****************************************************************************** Function: void USBCheckCCIDRequest(void) - + Description: This routine checks the setup data packet to see if it knows how to handle it - + PreCondition: None Parameters: None - + Return Values: None - + Remarks: None - + *****************************************************************************/ - void USBCheckCCIDRequest(void) + void USBCheckCCIDRequest(void) { /* * If request recipient is not an interface then return @@ -93,19 +93,19 @@ POINTER pCCIDSrc; // Dedicated source pointer case USB_CCID_ABORT: USB_CCID_ABORT_REQUEST_HANDLER(); break; - #endif - + #endif + #if defined (USB_CCID_SUPPORT_GET_CLOCK_FREQUENCIES_REQUEST) case USB_CCID_GET_CLOCK_FREQUENCIES: USB_CCID_GET_CLOCK_FREQUENCIES_REQUEST_HANDLER(); break; - #endif - + #endif + #if defined (USB_CCID_SUPPORT_GET_DATA_RATES_REQUEST) case USB_CCID_GET_DATA_RATES: USB_CCID_GET_DATA_RATES_REQUEST_HANDLER(); break; - #endif + #endif default: break; }//end switch(SetupPkt.bRequest) @@ -115,7 +115,7 @@ POINTER pCCIDSrc; // Dedicated source pointer /************************************************************************** Function: void USBCCIDInitEP(void) - + Summary: This function initializes the CCID function driver. This function should be called after the SET_CONFIGURATION command. @@ -124,11 +124,11 @@ POINTER pCCIDSrc; // Dedicated source pointer the default line coding (baud rate, bit parity, number of data bits, and format). This function also enables the endpoints and prepares for the first transfer from the host. - + This function should be called after the SET_CONFIGURATION command. This is most simply done by calling this function from the USBCBInitEP() function. - + Typical Usage: void USBCBInitEP(void) @@ -139,14 +139,14 @@ POINTER pCCIDSrc; // Dedicated source pointer Conditions: None Remarks: - None + None **************************************************************************/ void USBCCIDInitEP(void) { - + usbCcidBulkInTrfState = USB_CCID_BULK_IN_READY; usbCcidBulkInLen =0; - + /* * Do not have to init Cnt of IN pipes here. * Reason: Number of BYTEs to send to the host @@ -158,21 +158,21 @@ POINTER pCCIDSrc; // Dedicated source pointer * be known right before the data is * sent. */ - + USBEnableEndpoint(USB_EP_INT_IN,USB_IN_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP); USBEnableEndpoint(USB_EP_BULK_IN,USB_IN_ENABLED|USB_OUT_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP); usbCcidBulkInHandle = 0; usbCcidInterruptInHandle = 0; usbCcidBulkOutHandle = USBRxOnePacket(USB_EP_BULK_OUT,(BYTE*)&usbCcidBulkOutEndpoint,USB_EP_SIZE); - + }//end CCIDInitEP /************************************************************************ Function: void USBCCIDBulkInService(void) - + Summary: USBCCIDBulkInService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches @@ -181,7 +181,7 @@ POINTER pCCIDSrc; // Dedicated source pointer USBCCIDBulkInService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches the configured state. - + Typical Usage: void main(void) @@ -211,16 +211,16 @@ POINTER pCCIDSrc; // Dedicated source pointer Conditions: None Remarks: - None + None ************************************************************************/ - + void USBCCIDBulkInService(void) { WORD byte_to_send; BYTE i; USBMaskInterrupts(); - if(USBHandleBusy(usbCcidBulkInHandle)) + if(USBHandleBusy(usbCcidBulkInHandle)) { USBUnmaskInterrupts(); return; @@ -229,7 +229,7 @@ void USBCCIDBulkInService(void) if(usbCcidBulkInTrfState == USB_CCID_BULK_IN_COMPLETING) usbCcidBulkInTrfState = USB_CCID_BULK_IN_READY; - + /* * If USB_CCID_BULK_IN_READY state, nothing to do, just return. */ @@ -238,7 +238,7 @@ void USBCCIDBulkInService(void) USBUnmaskInterrupts(); return; } - + /* * If USB_CCID_BULK_IN_BUSY_ZLP state, send zero length packet */ @@ -247,25 +247,25 @@ void USBCCIDBulkInService(void) usbCcidBulkInHandle = USBTxOnePacket(USB_EP_BULK_IN,NULL,0); usbCcidBulkInTrfState = USB_CCID_BULK_IN_COMPLETING; } - else if(usbCcidBulkInTrfState == USB_CCID_BULK_IN_BUSY) + else if(usbCcidBulkInTrfState == USB_CCID_BULK_IN_BUSY) { /* * First, have to figure out how many byte of data to send. */ - if(usbCcidBulkInLen > sizeof(usbCcidBulkInEndpoint)) + if(usbCcidBulkInLen > sizeof(usbCcidBulkInEndpoint)) byte_to_send = sizeof(usbCcidBulkInEndpoint); else byte_to_send = usbCcidBulkInLen; - + /* * Subtract the number of bytes just about to be sent from the total. */ usbCcidBulkInLen = usbCcidBulkInLen - byte_to_send; - + pCCIDDst.bRam = (BYTE*)usbCcidBulkInEndpoint; // Set destination pointer - + i = byte_to_send; - + while(i) { *pCCIDDst.bRam = *pCCIDSrc.bRam; @@ -273,8 +273,8 @@ void USBCCIDBulkInService(void) pCCIDSrc.bRam++; i--; }//end while(byte_to_send._word) - - + + /* * Lastly, determine if a zero length packet state is necessary. * See explanation in USB Specification 2.0: Section 5.8.3 @@ -296,7 +296,7 @@ void USBCCIDBulkInService(void) /****************************************************************************** Function: void USBCCIDSendDataToHost(BYTE *data, WORD length) - + Summary: USBCCIDSendDataToHost writes an array of data to the USB. Use this version, is capable of transfering 0x00 (what is typically a NULL character in any of @@ -306,8 +306,8 @@ void USBCCIDBulkInService(void) USBCCIDSendDataToHost writes an array of data to the USB. Use this version, is capable of transfering 0x00 (what is typically a NULL character in any of the string transfer functions). - - + + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -315,12 +315,12 @@ void USBCCIDBulkInService(void) must be called periodically to keep sending blocks of data to the host. Conditions: - + Input: BYTE *data - pointer to a RAM array of data to be transfered to the host - WORD length - the number of bytes to be transfered - + WORD length - the number of bytes to be transfered + *****************************************************************************/ void USBCCIDSendDataToHost(BYTE *pData, WORD len) { diff --git a/src/usb_device_cdc.c b/src/usb_device_cdc.c index e6949d9..45e3b09 100644 --- a/src/usb_device_cdc.c +++ b/src/usb_device_cdc.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -23,7 +23,7 @@ please contact mla_licensing@microchip.com Change History: Rev Description ---- ----------- - 2.3 Deprecated the mUSBUSARTIsTxTrfReady() macro. It is + 2.3 Deprecated the mUSBUSARTIsTxTrfReady() macro. It is replaced by the USBUSARTIsTxTrfReady() function. 2.6 Minor definition changes @@ -31,7 +31,7 @@ please contact mla_licensing@microchip.com 2.6a No Changes 2.7 Fixed error in the part support list of the variables section - where the address of the CDC variables are defined. The + where the address of the CDC variables are defined. The PIC18F2553 was incorrectly named PIC18F2453 and the PIC18F4558 was incorrectly named PIC18F4458. @@ -39,7 +39,7 @@ please contact mla_licensing@microchip.com 2.8 Minor change to CDCInitEP() to enhance ruggedness in multi0-threaded usage scenarios. - + 2.9b Updated to implement optional support for DTS reporting. ********************************************************************/ @@ -123,26 +123,26 @@ void USBCDCSetLineCoding(void); /****************************************************************************** Function: void USBCheckCDCRequest(void) - + Description: - This routine checks the most recently received SETUP data packet to + This routine checks the most recently received SETUP data packet to see if the request is specific to the CDC class. If the request was a CDC specific request, this function will take care of handling the request and responding appropriately. - + PreCondition: This function should only be called after a control transfer SETUP packet has arrived from the host. Parameters: None - + Return Values: None - + Remarks: This function does not change status or do anything if the SETUP packet - did not contain a CDC class specific request. + did not contain a CDC class specific request. *****************************************************************************/ void USBCheckCDCRequest(void) { @@ -162,7 +162,7 @@ void USBCheckCDCRequest(void) */ if((SetupPkt.bIntfID != CDC_COMM_INTF_ID)&& (SetupPkt.bIntfID != CDC_DATA_INTF_ID)) return; - + switch(SetupPkt.bRequest) { //****** These commands are required ******// @@ -187,7 +187,7 @@ void USBCheckCDCRequest(void) outPipes[0].pFunc = LINE_CODING_PFUNC; outPipes[0].info.bits.busy = 1; break; - + case GET_LINE_CODING: USBEP0SendRAMPtr( (uint8_t*)&line_coding, @@ -197,11 +197,11 @@ void USBCheckCDCRequest(void) case SET_CONTROL_LINE_STATE: control_signal_bitmap._byte = (uint8_t)SetupPkt.wValue; - //------------------------------------------------------------------ + //------------------------------------------------------------------ //One way to control the RTS pin is to allow the USB host to decide the value //that should be output on the RTS pin. Although RTS and CTS pin functions //are technically intended for UART hardware based flow control, some legacy - //UART devices use the RTS pin like a "general purpose" output pin + //UART devices use the RTS pin like a "general purpose" output pin //from the PC host. In this usage model, the RTS pin is not related //to flow control for RX/TX. //In this scenario, the USB host would want to be able to control the RTS @@ -209,15 +209,15 @@ void USBCheckCDCRequest(void) //However, if the intention is to implement true RTS/CTS flow control //for the RX/TX pair, then this application firmware should override //the USB host's setting for RTS, and instead generate a real RTS signal, - //based on the amount of remaining buffer space available for the - //actual hardware UART of this microcontroller. In this case, the - //below code should be left commented out, but instead RTS should be - //controlled in the application firmware responsible for operating the + //based on the amount of remaining buffer space available for the + //actual hardware UART of this microcontroller. In this case, the + //below code should be left commented out, but instead RTS should be + //controlled in the application firmware responsible for operating the //hardware UART of this microcontroller. - //--------- - //CONFIGURE_RTS(control_signal_bitmap.CARRIER_CONTROL); - //------------------------------------------------------------------ - + //--------- + //CONFIGURE_RTS(control_signal_bitmap.CARRIER_CONTROL); + //------------------------------------------------------------------ + #if defined(USB_CDC_SUPPORT_DTR_SIGNALING) if(control_signal_bitmap.DTE_PRESENT == 1) { @@ -226,7 +226,7 @@ void USBCheckCDCRequest(void) else { UART_DTR = (USB_CDC_DTR_ACTIVE_LEVEL ^ 1); - } + } #endif inPipes[0].info.bits.busy = 1; break; @@ -241,7 +241,7 @@ void USBCheckCDCRequest(void) UART_TRISTx = 0; // Make sure TX pin configured as an output UART_ENABLE = 0; // Turn off USART (to relinquish TX pin control) } - else if (SetupPkt.wValue == 0x0000) //0x0000 means stop sending indefinite break + else if (SetupPkt.wValue == 0x0000) //0x0000 means stop sending indefinite break { UART_ENABLE = 1; // turn on USART UART_TRISTx = 1; // Make TX pin an input @@ -264,7 +264,7 @@ void USBCheckCDCRequest(void) /************************************************************************** Function: void CDCInitEP(void) - + Summary: This function initializes the CDC function driver. This function should be called after the SET_CONFIGURATION command (ex: within the context of @@ -274,11 +274,11 @@ void USBCheckCDCRequest(void) the default line coding (baud rate, bit parity, number of data bits, and format). This function also enables the endpoints and prepares for the first transfer from the host. - + This function should be called after the SET_CONFIGURATION command. This is most simply done by calling this function from the USBCBInitEP() function. - + Typical Usage: void USBCBInitEP(void) @@ -289,7 +289,7 @@ void USBCheckCDCRequest(void) Conditions: None Remarks: - None + None **************************************************************************/ void CDCInitEP(void) { @@ -300,7 +300,7 @@ void CDCInitEP(void) line_coding.bDataBits = 0x08; // 5,6,7,8, or 16 cdc_rx_len = 0; - + /* * Do not have to init Cnt of IN pipes here. * Reason: Number of BYTEs to send to the host @@ -327,22 +327,22 @@ void CDCInitEP(void) SerialStatePacket.bmRequestType = 0xA1; //Always 0xA1 for this type of packet. SerialStatePacket.bNotification = SERIAL_STATE; SerialStatePacket.wValue = 0x0000; //Always 0x0000 for this type of packet - SerialStatePacket.wIndex = CDC_COMM_INTF_ID; //Interface number + SerialStatePacket.wIndex = CDC_COMM_INTF_ID; //Interface number SerialStatePacket.SerialState.byte = 0x00; SerialStatePacket.Reserved = 0x00; - SerialStatePacket.wLength = 0x02; //Always 2 bytes for this type of packet + SerialStatePacket.wLength = 0x02; //Always 2 bytes for this type of packet CDCNotificationHandler(); #endif - + #if defined(USB_CDC_SUPPORT_DTR_SIGNALING) mInitDTRPin(); #endif - + #if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL) mInitRTSPin(); mInitCTSPin(); #endif - + cdc_trf_state = CDC_TX_READY; }//end CDCInitEP @@ -351,31 +351,31 @@ void CDCInitEP(void) Function: void CDCNotificationHandler(void) Summary: Checks for changes in DSR status and reports them to the USB host. Description: Checks for changes in DSR pin state and reports any changes - to the USB host. + to the USB host. Conditions: CDCInitEP() must have been called previously, prior to calling CDCNotificationHandler() for the first time. Remarks: - This function is only implemented and needed when the + This function is only implemented and needed when the USB_CDC_SUPPORT_DSR_REPORTING option has been enabled. If the function is enabled, it should be called periodically to sample the DSR pin and feed - the information to the USB host. This can be done by calling + the information to the USB host. This can be done by calling CDCNotificationHandler() by itself, or, by calling CDCTxService() which also calls CDCNotificationHandler() internally, when appropriate. **************************************************************************/ #if defined(USB_CDC_SUPPORT_DSR_REPORTING) void CDCNotificationHandler(void) { - //Check the DTS I/O pin and if a state change is detected, notify the + //Check the DTS I/O pin and if a state change is detected, notify the //USB host by sending a serial state notification element packet. if(UART_DTS == USB_CDC_DSR_ACTIVE_LEVEL) //UART_DTS must be defined to be an I/O pin in the hardware profile to use the DTS feature (ex: "PORTXbits.RXY") { SerialStateBitmap.bits.DSR = 1; - } + } else { SerialStateBitmap.bits.DSR = 0; - } - + } + //If the state has changed, and the endpoint is available, send a packet to //notify the hUSB host of the change. if((SerialStateBitmap.byte != OldSerialStateBitmap.byte) && (!USBHandleBusy(CDCNotificationInHandle))) @@ -388,11 +388,11 @@ void CDCNotificationHandler(void) //Send the packet over USB to the host. CDCNotificationInHandle = USBTransferOnePacket(CDC_COMM_EP, IN_TO_HOST, (uint8_t*)&SerialStatePacket, sizeof(SERIAL_STATE_NOTIFICATION)); - + //Save the old value, so we can detect changes later. OldSerialStateBitmap.byte = SerialStateBitmap.byte; - } -}//void CDCNotificationHandler(void) + } +}//void CDCNotificationHandler(void) #else #define CDCNotificationHandler() {} #endif @@ -401,15 +401,15 @@ void CDCNotificationHandler(void) /********************************************************************************** Function: bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size) - + Summary: - Handles events from the USB stack, which may have an effect on the CDC + Handles events from the USB stack, which may have an effect on the CDC endpoint(s). Description: - Handles events from the USB stack. This function should be called when + Handles events from the USB stack. This function should be called when there is a USB event that needs to be processed by the CDC driver. - + Conditions: Value of input argument 'len' should be smaller than the maximum endpoint size responsible for receiving bulk data from USB host for CDC @@ -419,12 +419,12 @@ void CDCNotificationHandler(void) event - the type of event that occurred pdata - pointer to the data that caused the event size - the size of the data that is pointed to by pdata - + **********************************************************************************/ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size) { switch( (uint16_t)event ) - { + { case EVENT_TRANSFER_TERMINATED: if(pdata == CDCDataOutHandle) { @@ -439,14 +439,14 @@ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size) break; default: return false; - } + } return true; } /********************************************************************************** Function: uint8_t getsUSBUSART(char *buffer, uint8_t len) - + Summary: getsUSBUSART copies a string of BYTEs received through USB CDC Bulk OUT endpoint to a user's specified location. It is a non-blocking function. @@ -458,12 +458,12 @@ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size) endpoint to a user's specified location. It is a non-blocking function. It does not wait for data if there is no data available. Instead it returns '0' to notify the caller that there is no data available. - + Typical Usage: uint8_t numBytes; uint8_t buffer[64] - + numBytes = getsUSBUSART(buffer,sizeof(buffer)); //until the buffer is free. if(numBytes \> 0) { @@ -480,12 +480,12 @@ bool USBCDCEventHandler(USB_EVENT event, void *pdata, uint16_t size) Input: buffer - Pointer to where received BYTEs are to be stored len - The number of BYTEs expected. - + **********************************************************************************/ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len) { cdc_rx_len = 0; - + if(!USBHandleBusy(CDCDataOutHandle)) { /* @@ -494,7 +494,7 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len) */ if(len > USBHandleGetLength(CDCDataOutHandle)) len = USBHandleGetLength(CDCDataOutHandle); - + /* * Copy data from dual-ram buffer to user's buffer */ @@ -508,15 +508,15 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len) CDCDataOutHandle = USBRxOnePacket(CDC_DATA_EP,(uint8_t*)&cdc_data_rx,sizeof(cdc_data_rx)); }//end if - + return cdc_rx_len; - + }//end getsUSBUSART /****************************************************************************** Function: void putUSBUSART(char *data, uint8_t length) - + Summary: putUSBUSART writes an array of data to the USB. Use this version, is capable of transferring 0x00 (what is typically a NULL character in any of @@ -526,7 +526,7 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len) putUSBUSART writes an array of data to the USB. Use this version, is capable of transferring 0x00 (what is typically a NULL character in any of the string transfer functions). - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -535,7 +535,7 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len) putUSBUSART(data,5); } - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -551,7 +551,7 @@ uint8_t getsUSBUSART(uint8_t *buffer, uint8_t len) Input: char *data - pointer to a RAM array of data to be transfered to the host uint8_t length - the number of bytes to be transfered (must be less than 255). - + *****************************************************************************/ void putUSBUSART(uint8_t *data, uint8_t length) { @@ -589,7 +589,7 @@ void putUSBUSART(uint8_t *data, uint8_t length) /****************************************************************************** Function: void putsUSBUSART(char *data) - + Summary: putsUSBUSART writes a string of data to the USB including the null character. Use this version, 'puts', to transfer data from a RAM buffer. @@ -597,7 +597,7 @@ void putUSBUSART(uint8_t *data, uint8_t length) Description: putsUSBUSART writes a string of data to the USB including the null character. Use this version, 'puts', to transfer data from a RAM buffer. - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -606,7 +606,7 @@ void putUSBUSART(uint8_t *data, uint8_t length) putsUSBUSART(data); } - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -623,9 +623,9 @@ void putUSBUSART(uint8_t *data, uint8_t length) char *data - null\-terminated string of constant data. If a null character is not found, 255 BYTEs of data will be transferred to the host. - + *****************************************************************************/ - + void putsUSBUSART(char *data) { uint8_t len; @@ -660,7 +660,7 @@ void putsUSBUSART(char *data) USBUnmaskInterrupts(); return; } - + /* * While loop counts the number of BYTEs to send including the * null character. @@ -672,7 +672,7 @@ void putsUSBUSART(char *data) len++; if(len == 255) break; // Break loop once max len is reached. }while(*pData++); - + /* * Second piece of information (length of data to send) is ready. * Call mUSBUSARTTxRam to setup the transfer. @@ -686,7 +686,7 @@ void putsUSBUSART(char *data) /************************************************************************** Function: void putrsUSBUSART(const const char *data) - + Summary: putrsUSBUSART writes a string of data to the USB including the null character. Use this version, 'putrs', to transfer data literals and @@ -696,7 +696,7 @@ void putsUSBUSART(char *data) putrsUSBUSART writes a string of data to the USB including the null character. Use this version, 'putrs', to transfer data literals and data located in program memory. - + Typical Usage: if(USBUSARTIsTxTrfReady()) @@ -704,7 +704,7 @@ void putsUSBUSART(char *data) putrsUSBUSART("Hello World"); } - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -721,7 +721,7 @@ void putsUSBUSART(char *data) const const char *data - null\-terminated string of constant data. If a null character is not found, 255 uint8_ts of data will be transferred to the host. - + **************************************************************************/ void putrsUSBUSART(const const char *data) { @@ -757,7 +757,7 @@ void putrsUSBUSART(const const char *data) USBUnmaskInterrupts(); return; } - + /* * While loop counts the number of BYTEs to send including the * null character. @@ -769,7 +769,7 @@ void putrsUSBUSART(const const char *data) len++; if(len == 255) break; // Break loop once max len is reached. }while(*pData++); - + /* * Second piece of information (length of data to send) is ready. * Call mUSBUSARTTxRom to setup the transfer. @@ -785,7 +785,7 @@ void putrsUSBUSART(const const char *data) /************************************************************************ Function: void CDCTxService(void) - + Summary: CDCTxService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches @@ -794,12 +794,12 @@ void putrsUSBUSART(const const char *data) CDCTxService handles device-to-host transaction(s). This function should be called once per Main Program loop after the device reaches the configured state (after the CDCIniEP() function has already executed). - This function is needed, in order to advance the internal software state + This function is needed, in order to advance the internal software state machine that takes care of sending multiple transactions worth of IN USB - data to the host, associated with CDC serial data. Failure to call + data to the host, associated with CDC serial data. Failure to call CDCTxService() periodically will prevent data from being sent to the USB host, over the CDC serial data interface. - + Typical Usage: void main(void) @@ -819,7 +819,7 @@ void putrsUSBUSART(const const char *data) { //Keep trying to send data to the PC as required CDCTxService(); - + //Run application code. UserApplication(); } @@ -830,19 +830,19 @@ void putrsUSBUSART(const const char *data) CDCIniEP() function should have already executed/the device should be in the CONFIGURED_STATE. Remarks: - None + None ************************************************************************/ - + void CDCTxService(void) { uint8_t byte_to_send; uint8_t i; - + USBMaskInterrupts(); - + CDCNotificationHandler(); - - if(USBHandleBusy(CDCDataInHandle)) + + if(USBHandleBusy(CDCDataInHandle)) { USBUnmaskInterrupts(); return; @@ -855,7 +855,7 @@ void CDCTxService(void) */ if(cdc_trf_state == CDC_TX_COMPLETING) cdc_trf_state = CDC_TX_READY; - + /* * If CDC_TX_READY state, nothing to do, just return. */ @@ -864,7 +864,7 @@ void CDCTxService(void) USBUnmaskInterrupts(); return; } - + /* * If CDC_TX_BUSY_ZLP state, send zero length packet */ @@ -888,9 +888,9 @@ void CDCTxService(void) * Subtract the number of bytes just about to be sent from the total. */ cdc_tx_len = cdc_tx_len - byte_to_send; - + pCDCDst.bRam = (uint8_t*)&cdc_data_tx; // Set destination pointer - + i = byte_to_send; if(cdc_mem_type == USB_EP0_ROM) // Determine type of memory source { @@ -912,7 +912,7 @@ void CDCTxService(void) i--; } } - + /* * Lastly, determine if a zero length packet state is necessary. * See explanation in USB Specification 2.0: Section 5.8.3 @@ -927,7 +927,7 @@ void CDCTxService(void) CDCDataInHandle = USBTxOnePacket(CDC_DATA_EP,(uint8_t*)&cdc_data_tx,byte_to_send); }//end if(cdc_tx_sate == CDC_TX_BUSY) - + USBUnmaskInterrupts(); }//end CDCTxService diff --git a/src/usb_device_generic.c b/src/usb_device_generic.c index 14efdf2..6eaed00 100644 --- a/src/usb_device_generic.c +++ b/src/usb_device_generic.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -37,9 +37,9 @@ please contact mla_licensing@microchip.com #if defined(USB_USE_GEN) /** V A R I A B L E S ********************************************************/ -extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the - //8-byte SETUP packet data from the - //host during control transfer +extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the + //8-byte SETUP packet data from the + //host during control transfer //requests. /** P R I V A T E P R O T O T Y P E S ***************************************/ @@ -51,12 +51,12 @@ extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the /******************************************************************** Function: USB_HANDLE USBGenWrite(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Sends the specified data out the specified endpoint Description: - This function sends the specified data out the specified + This function sends the specified data out the specified endpoint and returns a handle to the transfer information. Typical Usage: @@ -69,32 +69,32 @@ extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM,(uint8_t*)&INPacket[0],sizeof(INPacket)); } - + PreCondition: None - + Parameters: uint8_t ep - the endpoint you want to send the data out of uint8_t* data - pointer to the data that you wish to send uint16_t len - the length of the data that you wish to send - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ // Implemented as a macro. See usb_function_generic.h /******************************************************************** Function: USB_HANDLE USBGenRead(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Receives the specified data out the specified endpoint - + Description: Receives the specified data out the specified endpoint. @@ -111,19 +111,19 @@ extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the PreCondition: None - + Parameters: uint8_t ep - the endpoint you want to receive the data into uint8_t* data - pointer to where the data will go when it arrives uint16_t len - the length of the data that you wish to receive - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ // Implemented as a macro. See usb_function_generic.h @@ -139,9 +139,9 @@ extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the Description: This routine handles vendor specific requests that may arrive on EP0 as - a control transfer. These can include, but are not necessarily - limited to, requests for Microsft specific OS feature descriptor(s). - This function should be called from the USBCBCheckOtherReq() call back + a control transfer. These can include, but are not necessarily + limited to, requests for Microsft specific OS feature descriptor(s). + This function should be called from the USBCBCheckOtherReq() call back function whenever using a vendor class device. Typical Usage: @@ -161,7 +161,7 @@ extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the Although this function has a void input, this handler function will typically need to look at the 8-byte SETUP packet contents that the host just sent, which may contain the vendor class specific request. - + Therefore, the statically allocated SetupPkt structure may be looked at while in the context of this function, and it will contain the most recently received 8-byte SETUP packet data. @@ -172,23 +172,23 @@ extern volatile CTRL_TRF_SETUP SetupPkt; //Common buffer that receives the Remarks: This function normally gets called within the same context as the USBDeviceTasks() function, just after a new control transfer request - from the host has arrived. If the USB stack is operated in + from the host has arrived. If the USB stack is operated in USB_INTERRUPT mode (a usb_config.h option), then this function will be executed in the interrupt context. If however the USB stack is operated in the USB_POLLING mode, then this function executes in the main loop context. - + In order to respond to class specific control transfer request(s) in this handler function, it is suggested to use one or more of the - USBEP0SendRAMPtr(), USBEP0SendROMPtr(), or USBEP0Receive() API + USBEP0SendRAMPtr(), USBEP0SendROMPtr(), or USBEP0Receive() API functions. - + *******************************************************************/ void USBCheckVendorRequest(void) { #if defined(IMPLEMENT_MICROSOFT_OS_DESCRIPTOR) uint16_t Length; - + //Check if the most recent SETUP request is class specific if(SetupPkt.bmRequestType == 0b11000000) //Class specific, device to host, device level target { @@ -198,41 +198,41 @@ void USBCheckVendorRequest(void) //Figure out which descriptor is being requested if(SetupPkt.wIndex == EXTENDED_COMPAT_ID) { - //Determine number of bytes to send to host + //Determine number of bytes to send to host //Lesser of: requested amount, or total size of the descriptor Length = CompatIDFeatureDescriptor.dwLength; if(SetupPkt.wLength < Length) { Length = SetupPkt.wLength; - } - + } + //Prepare to send the requested descriptor to the host USBEP0SendROMPtr((const uint8_t*)&CompatIDFeatureDescriptor, Length, USB_EP0_ROM | USB_EP0_INCLUDE_ZERO); } - } - }//if(SetupPkt.bmRequestType == 0b11000000) + } + }//if(SetupPkt.bmRequestType == 0b11000000) else if(SetupPkt.bmRequestType == 0b11000001) //Class specific, device to host, interface target { //Check if the host is requesting an MS feature descriptor if(SetupPkt.bRequest == GET_MS_DESCRIPTOR) { //Figure out which descriptor is being requested - if(SetupPkt.wIndex == EXTENDED_PROPERTIES) + if(SetupPkt.wIndex == EXTENDED_PROPERTIES) { - //Determine number of bytes to send to host + //Determine number of bytes to send to host //Lesser of: requested amount, or total size of the descriptor Length = ExtPropertyFeatureDescriptor.dwLength; if(SetupPkt.wLength < Length) { Length = SetupPkt.wLength; - } - + } + //Prepare to send the requested descriptor to the host USBEP0SendROMPtr((const uint8_t*)&ExtPropertyFeatureDescriptor, Length, USB_EP0_ROM | USB_EP0_INCLUDE_ZERO); - } - } - }//else if(SetupPkt.bmRequestType == 0b11000001) - #endif //#if defined(IMPLEMENT_MICROSOFT_OS_DESCRIPTOR) + } + } + }//else if(SetupPkt.bmRequestType == 0b11000001) + #endif //#if defined(IMPLEMENT_MICROSOFT_OS_DESCRIPTOR) }//void USBCheckVendorRequest(void) diff --git a/src/usb_device_hid.c b/src/usb_device_hid.c index ef8888b..7574599 100644 --- a/src/usb_device_hid.c +++ b/src/usb_device_hid.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -92,7 +92,7 @@ extern const struct{uint8_t report[HID_RPT01_SIZE];}hid_rpt01; #if defined USER_SET_REPORT_HANDLER extern void USER_SET_REPORT_HANDLER(void); -#endif +#endif // ***************************************************************************** // ***************************************************************************** @@ -148,13 +148,13 @@ extern const struct{uint8_t report[HID_RPT01_SIZE];}hid_rpt01; Remarks: None - + *******************************************************************/ void USBCheckHIDRequest(void) { if(SetupPkt.Recipient != USB_SETUP_RECIPIENT_INTERFACE_BITFIELD) return; if(SetupPkt.bIntfID != HID_INTF_ID) return; - + /* * There are two standard requests that hid.c may support. * 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY); @@ -164,7 +164,7 @@ void USBCheckHIDRequest(void) { switch(SetupPkt.bDescriptorType) { - case DSC_HID: //HID Descriptor + case DSC_HID: //HID Descriptor if(USBActiveConfiguration == 1) { USBEP0SendROMPtr( @@ -173,7 +173,7 @@ void USBCheckHIDRequest(void) USB_EP0_INCLUDE_ZERO); } break; - case DSC_RPT: //Report Descriptor + case DSC_RPT: //Report Descriptor //if(USBActiveConfiguration == 1) { USBEP0SendROMPtr( @@ -197,7 +197,7 @@ void USBCheckHIDRequest(void) break; }//end switch(SetupPkt.bDescriptorType) }//end if(SetupPkt.bRequest == GET_DSC) - + if(SetupPkt.RequestType != USB_SETUP_TYPE_CLASS_BITFIELD) { return; @@ -213,7 +213,7 @@ void USBCheckHIDRequest(void) case SET_REPORT: #if defined USER_SET_REPORT_HANDLER USER_SET_REPORT_HANDLER(); - #endif + #endif break; case GET_IDLE: USBEP0SendRAMPtr( @@ -243,12 +243,12 @@ void USBCheckHIDRequest(void) /******************************************************************** Function: USB_HANDLE HIDTxPacket(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Sends the specified data out the specified endpoint Description: - This function sends the specified data out the specified + This function sends the specified data out the specified endpoint and returns a handle to the transfer information. Typical Usage: @@ -261,32 +261,32 @@ void USBCheckHIDRequest(void) USBInHandle = HIDTxPacket(HID_EP,(uint8_t*)&ToSendDataBuffer[0],sizeof(ToSendDataBuffer)); } - + PreCondition: None - + Parameters: uint8_t ep - the endpoint you want to send the data out of uint8_t* data - pointer to the data that you wish to send uint16_t len - the length of the data that you wish to send - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ // Implemented as a macro. See usb_function_hid.h /******************************************************************** Function: USB_HANDLE HIDRxPacket(uint8_t ep, uint8_t* data, uint16_t len) - + Summary: Receives the specified data out the specified endpoint - + Description: Receives the specified data out the specified endpoint. @@ -300,22 +300,22 @@ void USBCheckHIDRequest(void) PreCondition: None - + Parameters: uint8_t ep - the endpoint you want to receive the data into uint8_t* data - pointer to where the data will go when it arrives uint16_t len - the length of the data that you wish to receive - + Return Values: USB_HANDLE - a handle for the transfer. This information should be kept to track the status of the transfer - + Remarks: None - + *******************************************************************/ // Implemented as a macro. See usb_function_hid.h - + /******************************************************************************* End of File */ diff --git a/src/usb_device_local.h b/src/usb_device_local.h index c372837..27fe522 100644 --- a/src/usb_device_local.h +++ b/src/usb_device_local.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -365,59 +365,59 @@ typedef union decrease CPU utiliazation. ********************************************************************/ #if defined USB_DISABLE_SUSPEND_HANDLER - #define USB_SUSPEND_HANDLER(event,pointer,size) - - #warning "Disabling the suspend handler is not recommended. Proper suspend handling is required to create a compliant USB device." + #define USB_SUSPEND_HANDLER(event,pointer,size) + + #warning "Disabling the suspend handler is not recommended. Proper suspend handling is required to create a compliant USB device." #else #define USB_SUSPEND_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif #if defined USB_DISABLE_WAKEUP_FROM_SUSPEND_HANDLER - #define USB_WAKEUP_FROM_SUSPEND_HANDLER(event,pointer,size) + #define USB_WAKEUP_FROM_SUSPEND_HANDLER(event,pointer,size) - #warning "Disabling the wake from suspend handler is not recommended. Proper suspend handling is required to create a compliant USB device." + #warning "Disabling the wake from suspend handler is not recommended. Proper suspend handling is required to create a compliant USB device." #else - #define USB_WAKEUP_FROM_SUSPEND_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) + #define USB_WAKEUP_FROM_SUSPEND_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif #if defined USB_DISABLE_SOF_HANDLER - #define USB_SOF_HANDLER(event,pointer,size) + #define USB_SOF_HANDLER(event,pointer,size) #else #define USB_SOF_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif #if defined USB_DISABLE_TRANSFER_TERMINATED_HANDLER - #define USB_TRANSFER_TERMINATED_HANDLER(event,pointer,size) + #define USB_TRANSFER_TERMINATED_HANDLER(event,pointer,size) #else #define USB_TRANSFER_TERMINATED_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif -#if defined USB_DISABLE_ERROR_HANDLER - #define USB_ERROR_HANDLER(event,pointer,size) +#if defined USB_DISABLE_ERROR_HANDLER + #define USB_ERROR_HANDLER(event,pointer,size) #else #define USB_ERROR_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif -#if defined USB_DISABLE_NONSTANDARD_EP0_REQUEST_HANDLER - #define USB_NONSTANDARD_EP0_REQUEST_HANDLER(event,pointer,size) +#if defined USB_DISABLE_NONSTANDARD_EP0_REQUEST_HANDLER + #define USB_NONSTANDARD_EP0_REQUEST_HANDLER(event,pointer,size) #else #define USB_NONSTANDARD_EP0_REQUEST_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif -#if defined USB_DISABLE_SET_DESCRIPTOR_HANDLER - #define USB_SET_DESCRIPTOR_HANDLER(event,pointer,size) +#if defined USB_DISABLE_SET_DESCRIPTOR_HANDLER + #define USB_SET_DESCRIPTOR_HANDLER(event,pointer,size) #else - #define USB_SET_DESCRIPTOR_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) + #define USB_SET_DESCRIPTOR_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif #if defined USB_DISABLE_SET_CONFIGURATION_HANDLER - #define USB_SET_CONFIGURATION_HANDLER(event,pointer,size) + #define USB_SET_CONFIGURATION_HANDLER(event,pointer,size) #else #define USB_SET_CONFIGURATION_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif -#if defined USB_DISABLE_TRANSFER_COMPLETE_HANDLER - #define USB_TRANSFER_COMPLETE_HANDLER(event,pointer,size) +#if defined USB_DISABLE_TRANSFER_COMPLETE_HANDLER + #define USB_TRANSFER_COMPLETE_HANDLER(event,pointer,size) #else #define USB_TRANSFER_COMPLETE_HANDLER(event,pointer,size) USER_USB_CALLBACK_EVENT_HANDLER(event,pointer,size) #endif diff --git a/src/usb_device_msd.c b/src/usb_device_msd.c index 67ba52d..1407e00 100644 --- a/src/usb_device_msd.c +++ b/src/usb_device_msd.c @@ -14,11 +14,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END - + /** I N C L U D E S **************************************************/ #include "usb.h" #include "system.h" @@ -67,14 +67,14 @@ uint8_t MSDReadState; uint8_t MSDWriteState; uint8_t MSDRetryAttempt; //Other variables -USB_MSD_CBW gblCBW; +USB_MSD_CBW gblCBW; uint8_t gblCBWLength; RequestSenseResponse gblSenseData[MAX_LUN + 1]; uint8_t *ptrNextData; USB_HANDLE USBMSDOutHandle; USB_HANDLE USBMSDInHandle; uint16_t MSBBufferIndex; -uint16_t gblMediaPresent; +uint16_t gblMediaPresent; bool SoftDetach[MAX_LUN + 1]; bool MSDHostNoData; bool MSDCBWValid; @@ -82,11 +82,11 @@ bool MSDCBWValid; static USB_MSD_TRANSFER_LENGTH TransferLength; static USB_MSD_LBA LBA; -/* - * Number of Blocks and Block Length are global because - * for every READ_10 and WRITE_10 command need to verify if the last LBA - * is less than gblNumBLKS - */ +/* + * Number of Blocks and Block Length are global because + * for every READ_10 and WRITE_10 command need to verify if the last LBA + * is less than gblNumBLKS + */ USB_MSD_BLK gblNumBLKS,gblBLKLen; extern const InquiryResponse inq_resp; @@ -111,7 +111,7 @@ static void MSDComputeDeviceInAndResidue(uint16_t); /****************************************************************************** Function: void USBMSDInit(void) - + Summary: This routine initializes the MSD class packet handles, prepares to receive a MSD packet, and initializes the MSD state machine. This @@ -121,7 +121,7 @@ static void MSDComputeDeviceInAndResidue(uint16_t); This routine initializes the MSD class packet handles, prepares to receive a MSD packet, and initializes the MSD state machine. This \function should be called once after the device is enumerated. - + Typical Usage: void USBCBInitEP(void) @@ -133,12 +133,12 @@ static void MSDComputeDeviceInAndResidue(uint16_t); Conditions: The device should already be enumerated with a configuration that supports MSD before calling this function. - + Parameters: None Remarks: - None - ****************************************************************************/ + None + ****************************************************************************/ void USBMSDInit(void) { //Prepare to receive the first CBW @@ -182,15 +182,15 @@ void USBMSDInit(void) void USBCheckMSDRequest(void) Summary: - This routine handles MSD specific request that happen on EP0. - This function should be called from the USBCBCheckOtherReq() call back + This routine handles MSD specific request that happen on EP0. + This function should be called from the USBCBCheckOtherReq() call back function whenever implementing an MSD device. Description: This routine handles MSD specific request that happen on EP0. These - include, but are not limited to, the standard RESET and GET_MAX_LUN - command requests. This function should be called from the - USBCBCheckOtherReq() call back function whenever using an MSD device. + include, but are not limited to, the standard RESET and GET_MAX_LUN + command requests. This function should be called from the + USBCBCheckOtherReq() call back function whenever using an MSD device. Typical Usage: @@ -204,25 +204,25 @@ void USBMSDInit(void) PreCondition: None - + Parameters: None - + Return Values: None - + Remarks: None - - *****************************************************************************/ + + *****************************************************************************/ void USBCheckMSDRequest(void) { if(SetupPkt.Recipient != USB_SETUP_RECIPIENT_INTERFACE_BITFIELD) { return; } - - if(SetupPkt.bIntfID != MSD_INTF_ID) + + if(SetupPkt.bIntfID != MSD_INTF_ID) { return; } @@ -261,7 +261,7 @@ void USBCheckMSDRequest(void) //Allow zero byte status stage to proceed normally now. USBEP0Transmit(USB_EP0_NO_DATA); break; - + case GET_MAX_LUN: //First make sure all request parameters are correct: //MSD BOT specs require wValue to be == 0x0000, and wLengh == 1 @@ -281,7 +281,7 @@ void USBCheckMSDRequest(void) /********************************************************************************* Function: uint8_t MSDTasks(void) - + Summary: This function runs the MSD class state machines and all of its sub-systems. This function should be called periodically once the @@ -292,7 +292,7 @@ void USBCheckMSDRequest(void) sub-systems. This function should be called periodically once the device is in the configured state in order to keep the MSD state machine going. - + Typical Usage: void main(void) @@ -312,7 +312,7 @@ void USBCheckMSDRequest(void) { //Keep the MSD state machine going MSDTasks(); - + //Run application code. UserApplication(); } @@ -330,12 +330,12 @@ void USBCheckMSDRequest(void) * MSD_DATA_OUT * MSD_SEND_CSW Remarks: - None - *********************************************************************************/ + None + *********************************************************************************/ uint8_t MSDTasks(void) { uint8_t i; - + //Error check to make sure we have are in the CONFIGURED_STATE, prior to //performing MSDTasks(). Some of the MSDTasks require that the device be //configured first. @@ -343,15 +343,15 @@ uint8_t MSDTasks(void) { return MSD_WAIT; } - - //Note: Both the USB stack code (usb_device.c) and this MSD handler code - //have the ability to modify the BDT values for the MSD bulk endpoints. If the + + //Note: Both the USB stack code (usb_device.c) and this MSD handler code + //have the ability to modify the BDT values for the MSD bulk endpoints. If the //USB stack operates in USB_INTERRUPT mode (user option in usb_config.h), we - //should temporarily disable USB interrupts, to avoid any possibility of both + //should temporarily disable USB interrupts, to avoid any possibility of both //the USB stack and this MSD handler from modifying the same BDT entry, or //MSD state machine variables (ex: in the case of MSD_RESET) at the same time. USBMaskInterrupts(); - + //Main MSD task dispatcher. Receives MSD Command Block Wrappers (CBW) and //dispatches appropriate lower level handlers to service the requests. switch(MSD_State) @@ -500,10 +500,10 @@ uint8_t MSDTasks(void) { break; //Not available yet. Just stay in this state and try again later. } - - //Send the Command Status Wrapper (CSW) packet + + //Send the Command Status Wrapper (CSW) packet USBMSDInHandle = USBTxOnePacket(MSD_DATA_IN_EP,(uint8_t*)&msd_csw,MSD_CSW_SIZE); - //If the bulk OUT endpoint isn't already armed, make sure to do so + //If the bulk OUT endpoint isn't already armed, make sure to do so //now so we can receive the next CBW packet from the host. if(!USBHandleBusy(USBMSDOutHandle)) { @@ -519,10 +519,10 @@ uint8_t MSDTasks(void) msd_csw.bCSWStatus = MSD_CSW_PHASE_ERROR; USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); }//switch(MSD_State) - + //Safe to re-enable USB interrupts now. USBUnmaskInterrupts(); - + return MSD_State; } @@ -530,33 +530,33 @@ uint8_t MSDTasks(void) /****************************************************************************** Function: uint8_t MSDProcessCommand(void) - + Description: This function processes a command received through the MSD class driver - + PreCondition: None - + Parameters: None - + Return Values: uint8_t - the current state of the MSDProcessCommand state machine. The valid values are defined in MSD.h under the MSDProcessCommand state machine declaration section - + Remarks: None - - *****************************************************************************/ + + *****************************************************************************/ uint8_t MSDProcessCommand(void) -{ +{ //Check if the media is either not present, or has been flagged by firmware //to pretend to be non-present (ex: SoftDetached). if((LUNMediaDetect() == false) || (SoftDetach[gblCBW.bCBWLUN] == true)) { - //Clear flag so we know the media need initialization, if it becomes + //Clear flag so we know the media need initialization, if it becomes //present in the future. gblMediaPresent &= ~((uint16_t)1<= MSD_IN_EP_SIZE) { NumBytesInPacket = MSD_IN_EP_SIZE; gblCBW.dCBWDataTransferLength -= MSD_IN_EP_SIZE; - } + } else { //This is a short packet and will be our last IN packet sent //in the transfer. NumBytesInPacket = gblCBW.dCBWDataTransferLength; gblCBW.dCBWDataTransferLength = 0; - } - + } + //We still have more bytes needing to be sent. Check if we have //already fulfilled the device input expected quantity of bytes. //If so, we need to keep sending IN packets, but pad the extra - //bytes with value = 0x00 (see error case 5 MSD device BOT v1.0 + //bytes with value = 0x00 (see error case 5 MSD device BOT v1.0 //spec handling). if(TransferLength.Val >= NumBytesInPacket) { //No problem, just send the requested data and keep track of remaining count. TransferLength.Val -= NumBytesInPacket; - } + } else { //The host is reading more bytes than the device has to send. //In this case, we still need to send the quantity of bytes requested, //but we have to fill the pad bytes with 0x00. The below for loop - //is execution speed inefficient, but performance isn't important - //since this code only executes in the case of a host error + //is execution speed inefficient, but performance isn't important + //since this code only executes in the case of a host error //anyway (Hi > Di). for(i = 0; i < NumBytesInPacket; i++) { if(TransferLength.Val != 0) { - TransferLength.Val--; - } + TransferLength.Val--; + } else { msd_buffer[i] = 0x00; - } - } - } - - //We are now ready to send the packet to the host. + } + } + } + + //We are now ready to send the packet to the host. USBMSDInHandle = USBTxOnePacket(MSD_DATA_IN_EP,(uint8_t*)&msd_buffer[0],NumBytesInPacket); - + //Check to see if we are done sending all requested bytes of data if(gblCBW.dCBWDataTransferLength == 0) { //We have sent all the requested bytes. Go ahead and //advance state so as to send the CSW. MSDCommandState = MSD_COMMAND_WAIT; - break; - } + break; + } } break; case MSD_COMMAND_ERROR: @@ -957,38 +957,38 @@ void MSDProcessCommandMediaPresent(void) //STALL, to force the host to perform error recovery. MSDErrorHandler(MSD_ERROR_UNSUPPORTED_COMMAND); break; - } // end switch + } // end switch }//void MSDProcessCommandMediaPresent(void) /****************************************************************************** Function: static void MSDComputeDeviceInAndResidue(uint16_t DiExpected) - + Description: This is a private function that performs Hi > Di data size checking and handling. This function also computes the proper CSW data residue and updates the global variable. - + PreCondition: - Should only be called in the context of the + Should only be called in the context of the MSDProcessCommandMediaPresent() handler function, after receiving a new command that needs processing. Before calling this function, make sure the gblCBW.dCBWDataTransferLength and TransferLength.Val variables have been pre-loaded with the expected host and device data size values. - + Parameters: - uint16_t DiExpected - Input: Firmware can specify an additional value that + uint16_t DiExpected - Input: Firmware can specify an additional value that might be smaller than the TransferLength.Val value. The function will update TransferLength.Val with the smaller of the original value, or DiExpected. - + Return Values: None - + Remarks: None - + *****************************************************************************/ static void MSDComputeDeviceInAndResidue(uint16_t DiExpected) { @@ -999,49 +999,49 @@ static void MSDComputeDeviceInAndResidue(uint16_t DiExpected) //send only the host requested quantity of bytes. msd_csw.dCSWDataResidue = 0; TransferLength.Val = gblCBW.dCBWDataTransferLength; - } + } else { //The host requested greater than or equal to the number of bytes expected. if(DiExpected < TransferLength.Val) { TransferLength.Val = DiExpected; - } + } msd_csw.dCSWDataResidue = gblCBW.dCBWDataTransferLength - TransferLength.Val; - } -} + } +} /****************************************************************************** Function: uint8_t MSDReadHandler(void) - + Description: - This function processes a read command received through + This function processes a read command received through the MSD class driver - + PreCondition: None - + Parameters: None - + Return Values: uint8_t - the current state of the MSDReadHandler state - machine. The valid values are defined in MSD.h under the + machine. The valid values are defined in MSD.h under the MSDReadHandler state machine declaration section - + Remarks: None - + *****************************************************************************/ uint8_t MSDReadHandler(void) { switch(MSDReadState) { case MSD_READ10_WAIT: - //Extract the LBA from the CBW. Note: Also need to perform endian - //swap, since the multi-byte CBW fields are stored big endian, but + //Extract the LBA from the CBW. Note: Also need to perform endian + //swap, since the multi-byte CBW fields are stored big endian, but //the Microchip C compilers are little endian. LBA.v[3]=gblCBW.CBWCB[2]; LBA.v[2]=gblCBW.CBWCB[3]; @@ -1055,29 +1055,29 @@ uint8_t MSDReadHandler(void) if(MSDCheckForErrorCases(TransferLength.Val * (uint32_t)FILEIO_CONFIG_MEDIA_SECTOR_SIZE) != MSD_ERROR_CASE_NO_ERROR) { break; - } + } MSDReadState = MSD_READ10_BLOCK; //Fall through to MSD_READ_BLOCK - + case MSD_READ10_BLOCK: if(TransferLength.Val == 0) { MSDReadState = MSD_READ10_WAIT; break; } - + TransferLength.Val--; // we have read 1 LBA MSDReadState = MSD_READ10_SECTOR; //Fall through to MSD_READ10_SECTOR - + case MSD_READ10_SECTOR: //if the old data isn't completely sent yet if(USBHandleBusy(USBMSDInHandle) != 0) { break; } - + //Try to read a sector worth of data from the media, but check for //possible errors. if(LUNSectorRead(LBA.Val, (uint8_t*)&msd_buffer[0]) != true) @@ -1115,39 +1115,39 @@ uint8_t MSDReadHandler(void) //512 bytes of data read ptrNextData=(uint8_t *)&msd_buffer[0]; - + MSDReadState = MSD_READ10_TX_SECTOR; //Fall through to MSD_READ10_TX_SECTOR - + case MSD_READ10_TX_SECTOR: if(msd_csw.dCSWDataResidue == 0) { MSDReadState = MSD_READ10_BLOCK; break; } - + MSDReadState = MSD_READ10_TX_PACKET; //Fall through to MSD_READ10_TX_PACKET - + case MSD_READ10_TX_PACKET: /* Write next chunk of data to EP Buffer and send */ - + //Make sure the endpoint is available before using it. if(USBHandleBusy(USBMSDInHandle)) { break; } - + //Prepare the USB module to send an IN transaction worth of data to the host. USBMSDInHandle = USBTxOnePacket(MSD_DATA_IN_EP,ptrNextData,MSD_IN_EP_SIZE); - + MSDReadState = MSD_READ10_TX_SECTOR; gblCBW.dCBWDataTransferLength-= MSD_IN_EP_SIZE; msd_csw.dCSWDataResidue-=MSD_IN_EP_SIZE; ptrNextData+=MSD_IN_EP_SIZE; break; - + default: //Illegal condition, should never occur. In the event that it ever //did occur anyway, try to notify the host of the error. @@ -1157,7 +1157,7 @@ uint8_t MSDReadHandler(void) MSDReadState = MSD_READ10_WAIT; break; }//switch(MSDReadState) - + return MSDReadState; } @@ -1165,25 +1165,25 @@ uint8_t MSDReadHandler(void) /****************************************************************************** Function: uint8_t MSDWriteHandler(void) - + Description: - This function processes a write command received through + This function processes a write command received through the MSD class driver - + PreCondition: None - + Parameters: None - + Return Values: uint8_t - the current state of the MSDWriteHandler state - machine. The valid values are defined in MSD.h under the + machine. The valid values are defined in MSD.h under the MSDWriteHandler state machine declaration section - + Remarks: None - + *****************************************************************************/ uint8_t MSDWriteHandler(void) { @@ -1206,7 +1206,7 @@ uint8_t MSDWriteHandler(void) //have taken care of setting the proper states to report the error to the host. break; } - + //Check if the media is write protected before deciding what //to do with the data. if(LUNWriteProtectState()) @@ -1227,22 +1227,22 @@ uint8_t MSDWriteHandler(void) MSDWriteState = MSD_WRITE10_WAIT; return MSDWriteState; } - + MSD_State = MSD_WRITE10_BLOCK; //Fall through to MSD_WRITE10_BLOCK - + case MSD_WRITE10_BLOCK: if(TransferLength.Val == 0) { MSDWriteState = MSD_WRITE10_WAIT; break; } - + MSDWriteState = MSD_WRITE10_RX_SECTOR; ptrNextData=(uint8_t *)&msd_buffer[0]; - + msd_csw.dCSWDataResidue=BLOCKLEN_512; - + //Fall through to MSD_WRITE10_RX_SECTOR case MSD_WRITE10_RX_SECTOR: { @@ -1286,14 +1286,14 @@ uint8_t MSDWriteHandler(void) { break; } - + gblCBW.dCBWDataTransferLength-=USBHandleGetLength(USBMSDOutHandle); // 64B read msd_csw.dCSWDataResidue-=USBHandleGetLength(USBMSDOutHandle); ptrNextData += MSD_OUT_EP_SIZE; - + MSDWriteState = MSD_WRITE10_RX_SECTOR; break; - + case MSD_WRITE10_SECTOR: { //Make sure that no error has been detected, before performing the write @@ -1333,8 +1333,8 @@ uint8_t MSDWriteHandler(void) TransferLength.Val--; MSDWriteState = MSD_WRITE10_BLOCK; break; - } - + } + default: //Illegal condition which should not occur. If for some reason it //does, try to let the host know know an error has occurred. @@ -1343,7 +1343,7 @@ uint8_t MSDWriteHandler(void) MSDWriteState = MSD_WRITE10_WAIT; break; } - + return MSDWriteState; } @@ -1352,25 +1352,25 @@ uint8_t MSDWriteHandler(void) /****************************************************************************** Function: void ResetSenseData(void) - + Description: This routine resets the Sense Data, initializing the structure RequestSenseResponse gblSenseData. - + PreCondition: - None - + None + Parameters: None - + Return Values: None - + Remarks: None - + *****************************************************************************/ -void ResetSenseData(void) +void ResetSenseData(void) { gblSenseData[LUN_INDEX].ResponseCode=S_CURRENT; gblSenseData[LUN_INDEX].VALID=0; // no data in the information field @@ -1399,61 +1399,61 @@ void ResetSenseData(void) /****************************************************************************** Function: uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) - + Description: - This function can be called to check for various error cases, primarily + This function can be called to check for various error cases, primarily the "Thirteen Cases" errors described in the MSD BOT v1.0 specs. If an error is detected, the function internally calls the MSDErrorHandler() - handler function, to take care of appropriately responding to the host, + handler function, to take care of appropriately responding to the host, based on the error condition. PreCondition: None - + Parameters: - uint32_t DeviceBytes - Input: This is the total number of bytes the MSD - device firmware is expecting in the MSD transfer. + uint32_t DeviceBytes - Input: This is the total number of bytes the MSD + device firmware is expecting in the MSD transfer. Return Values: uint8_t - Returns a byte containing the error code. The possible error cases that can be detected and reported are: MSD_ERROR_CASE_NO_ERROR - None of the "Thirteen cases" errors were detected - MSD_ERROR_CASE_2 - MSD_ERROR_CASE_3 - MSD_ERROR_CASE_4 - MSD_ERROR_CASE_5 - MSD_ERROR_CASE_7 - MSD_ERROR_CASE_8 - MSD_ERROR_CASE_9 - MSD_ERROR_CASE_11 - MSD_ERROR_CASE_10 - MSD_ERROR_CASE_13 - + MSD_ERROR_CASE_2 + MSD_ERROR_CASE_3 + MSD_ERROR_CASE_4 + MSD_ERROR_CASE_5 + MSD_ERROR_CASE_7 + MSD_ERROR_CASE_8 + MSD_ERROR_CASE_9 + MSD_ERROR_CASE_11 + MSD_ERROR_CASE_10 + MSD_ERROR_CASE_13 + Remarks: None - + *****************************************************************************/ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) { uint8_t MSDErrorCase; bool HostMoreDataThanDevice; bool DeviceNoData; - + //Check if device is expecting no data (Dn) if(DeviceBytes == 0) { DeviceNoData = true; - } + } else { DeviceNoData = false; - } - + } + //First check for the three good/non-error cases - + //Check for good case: Hn = Dn (Case 1) if((MSDHostNoData == true) && (DeviceNoData == true)) { return MSD_ERROR_CASE_NO_ERROR; - } + } //Check for good cases where the data sizes between host and device match if(gblCBW.dCBWDataTransferLength == DeviceBytes) @@ -1465,18 +1465,18 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) if(MSDCommandState != MSD_WRITE_10) { return MSD_ERROR_CASE_NO_ERROR; - } + } } - else //if(MSD_State == MSD_DATA_OUT) + else //if(MSD_State == MSD_DATA_OUT) { //Check for good case: Ho = Do (Case 12) //Make sure Ho = Do, instead of Ho = Di if(MSDCommandState == MSD_WRITE_10) { return MSD_ERROR_CASE_NO_ERROR; - } - } - } + } + } + } //If we get to here, this implies some kind of error is occurring. Do some //checks to find out which error occurred, so we know how to handle it. @@ -1485,12 +1485,12 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) if(gblCBW.dCBWDataTransferLength > DeviceBytes) { HostMoreDataThanDevice = true; - } + } else { HostMoreDataThanDevice = false; - } - + } + //Check host's expected data direction if(MSD_State == MSD_DATA_OUT) { @@ -1498,7 +1498,7 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) if((MSDCommandState != MSD_WRITE_10) && (DeviceNoData == false)) MSDErrorCase = MSD_ERROR_CASE_10; //Check for Hn < Do (Case 3) - else if(MSDHostNoData == true) + else if(MSDHostNoData == true) MSDErrorCase = MSD_ERROR_CASE_3; //Check for Ho > Dn (Case 9) else if(DeviceNoData == true) @@ -1509,14 +1509,14 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) //Check for Ho < Do (Case 13) else //if(gblCBW.dCBWDataTransferLength < DeviceBytes) MSDErrorCase = MSD_ERROR_CASE_13; - } + } else //else the MSD_State must be == MSD_DATA_IN { //First check for Hi <> Do (Case 8) if(MSDCommandState == MSD_WRITE_10) - MSDErrorCase = MSD_ERROR_CASE_8; + MSDErrorCase = MSD_ERROR_CASE_8; //Check for Hn < Di (Case 2) - else if(MSDHostNoData == true) + else if(MSDHostNoData == true) MSDErrorCase = MSD_ERROR_CASE_2; //Check for Hi > Dn (Case 4) else if(DeviceNoData == true) @@ -1527,17 +1527,17 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) //Check for Hi < Di (Case 7) else //if(gblCBW.dCBWDataTransferLength < DeviceBytes) MSDErrorCase = MSD_ERROR_CASE_7; - } + } //Now call the MSDErrorHandler(), based on the error that was detected. MSDErrorHandler(MSDErrorCase); return MSDErrorCase; -} +} /****************************************************************************** Function: void MSDErrorHandler(uint8_t ErrorCase) - + Description: Once an error condition has been detected, this function can be called to set the proper states and perform the proper tasks needed to let the @@ -1545,44 +1545,44 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) PreCondition: Firmware should have already determined an error occurred, and it should know what the error code was before calling this handler. - + Parameters: - uint8_t ErrorCase - Input: This is the error code that the firmware + uint8_t ErrorCase - Input: This is the error code that the firmware detected. This error code will determine how the handler will behave (ex: what status to send to host, what endpoint(s) should be stalled, etc.). The implemented error case possibilities are (suffix - numbers correspond to the "Thirteen cases" numbers + numbers correspond to the "Thirteen cases" numbers described in the MSD BOT specs v1.0): - - MSD_ERROR_CASE_2 - MSD_ERROR_CASE_3 - MSD_ERROR_CASE_4 - MSD_ERROR_CASE_5 - MSD_ERROR_CASE_7 - MSD_ERROR_CASE_8 - MSD_ERROR_CASE_9 - MSD_ERROR_CASE_11 - MSD_ERROR_CASE_10 - MSD_ERROR_CASE_13 - MSD_ERROR_UNSUPPORTED_COMMAND + + MSD_ERROR_CASE_2 + MSD_ERROR_CASE_3 + MSD_ERROR_CASE_4 + MSD_ERROR_CASE_5 + MSD_ERROR_CASE_7 + MSD_ERROR_CASE_8 + MSD_ERROR_CASE_9 + MSD_ERROR_CASE_11 + MSD_ERROR_CASE_10 + MSD_ERROR_CASE_13 + MSD_ERROR_UNSUPPORTED_COMMAND Return Values: None - + Remarks: None - + *****************************************************************************/ void MSDErrorHandler(uint8_t ErrorCase) { uint8_t OldMSD_State; - + //Both MSD bulk IN and OUT endpoints should not be busy when these error cases are detected //If for some reason this isn't true, then we should preserve the state machines states for now. if((USBHandleBusy(USBMSDInHandle)) || (USBHandleBusy(USBMSDOutHandle))) { - return; + return; } //Save the old state before we change it. The old state is needed to determine @@ -1598,7 +1598,7 @@ void MSDErrorHandler(uint8_t ErrorCase) msd_csw.bCSWStatus = MSD_CSW_COMMAND_FAILED; //Gets changed later to phase error for errors that user phase error MSD_State = MSD_SEND_CSW; - //Now do other error related handling tasks, which depend on the specific + //Now do other error related handling tasks, which depend on the specific //error type that was detected. switch(ErrorCase) { @@ -1629,7 +1629,7 @@ void MSDErrorHandler(uint8_t ErrorCase) gblSenseData[LUN_INDEX].SenseKey=S_ILLEGAL_REQUEST; gblSenseData[LUN_INDEX].ASC=ASC_INVALID_COMMAND_OPCODE; gblSenseData[LUN_INDEX].ASCQ=ASCQ_INVALID_COMMAND_OPCODE; - + if((OldMSD_State == MSD_DATA_OUT) && (gblCBW.dCBWDataTransferLength != 0)) { USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); @@ -1642,13 +1642,13 @@ void MSDErrorHandler(uint8_t ErrorCase) default: //Shouldn't get hit, don't call MSDErrorHandler() if there is no error break; }//switch(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 @@ -1660,16 +1660,16 @@ void MSDErrorHandler(uint8_t ErrorCase) 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) { diff --git a/src/usb_device_msd_multi_sector.c b/src/usb_device_msd_multi_sector.c index c2a04e7..75062be 100644 --- a/src/usb_device_msd_multi_sector.c +++ b/src/usb_device_msd_multi_sector.c @@ -14,11 +14,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END - + /** I N C L U D E S **************************************************/ #include #include "system.h" @@ -70,14 +70,14 @@ uint8_t MSDReadState; uint8_t MSDWriteState; uint8_t MSDRetryAttempt; //Other variables -USB_MSD_CBW gblCBW; +USB_MSD_CBW gblCBW; uint8_t gblCBWLength; RequestSenseResponse gblSenseData[MAX_LUN + 1]; uint8_t *ptrNextData; USB_HANDLE USBMSDOutHandle; USB_HANDLE USBMSDInHandle; uint16_t MSBBufferIndex; -uint16_t gblMediaPresent; +uint16_t gblMediaPresent; bool SoftDetach[MAX_LUN + 1]; bool MSDHostNoData; bool MSDCBWValid; @@ -87,11 +87,11 @@ static USB_MSD_LBA LBA; FILEIO_SD_ASYNC_IO AsyncReadWriteInfo; uint8_t fetchStatus; -/* - * Number of Blocks and Block Length are global because - * for every READ_10 and WRITE_10 command need to verify if the last LBA - * is less than gblNumBLKS - */ +/* + * Number of Blocks and Block Length are global because + * for every READ_10 and WRITE_10 command need to verify if the last LBA + * is less than gblNumBLKS + */ USB_MSD_BLK gblNumBLKS,gblBLKLen; extern const InquiryResponse inq_resp; @@ -116,7 +116,7 @@ static void MSDComputeDeviceInAndResidue(uint16_t); /****************************************************************************** Function: void USBMSDInit(void) - + Summary: This routine initializes the MSD class packet handles, prepares to receive a MSD packet, and initializes the MSD state machine. This @@ -126,7 +126,7 @@ static void MSDComputeDeviceInAndResidue(uint16_t); This routine initializes the MSD class packet handles, prepares to receive a MSD packet, and initializes the MSD state machine. This \function should be called once after the device is enumerated. - + Typical Usage: void USBCBInitEP(void) @@ -138,16 +138,16 @@ static void MSDComputeDeviceInAndResidue(uint16_t); Conditions: The device should already be enumerated with a configuration that supports MSD before calling this function. - + Paramters: None Remarks: - None - ****************************************************************************/ + None + ****************************************************************************/ void USBMSDInit(void) { //Prepare to receive the first CBW - USBMSDInHandle = 0; + USBMSDInHandle = 0; USBMSDOutHandle = USBRxOnePacket(MSD_DATA_OUT_EP,(uint8_t*)&msd_cbw,MSD_OUT_EP_SIZE); //Initialize IN handle to point to first available IN MSD bulk endpoint entry USBMSDInHandle = USBGetNextHandle(MSD_DATA_IN_EP, IN_TO_HOST); @@ -188,15 +188,15 @@ void USBMSDInit(void) void USBCheckMSDRequest(void) Summary: - This routine handles MSD specific request that happen on EP0. - This function should be called from the USBCBCheckOtherReq() call back + This routine handles MSD specific request that happen on EP0. + This function should be called from the USBCBCheckOtherReq() call back function whenever implementing an MSD device. Description: This routine handles MSD specific request that happen on EP0. These - include, but are not limited to, the standard RESET and GET_MAX_LUN - command requests. This function should be called from the - USBCBCheckOtherReq() call back function whenever using an MSD device. + include, but are not limited to, the standard RESET and GET_MAX_LUN + command requests. This function should be called from the + USBCBCheckOtherReq() call back function whenever using an MSD device. Typical Usage: @@ -210,25 +210,25 @@ void USBMSDInit(void) PreCondition: None - + Parameters: None - + Return Values: None - + Remarks: None - - *****************************************************************************/ + + *****************************************************************************/ void USBCheckMSDRequest(void) { if(SetupPkt.Recipient != USB_SETUP_RECIPIENT_INTERFACE_BITFIELD) { return; } - - if(SetupPkt.bIntfID != MSD_INTF_ID) + + if(SetupPkt.bIntfID != MSD_INTF_ID) { return; } @@ -267,7 +267,7 @@ void USBCheckMSDRequest(void) //Allow zero byte status stage to proceed normally now. USBEP0Transmit(USB_EP0_NO_DATA); break; - + case GET_MAX_LUN: //First make sure all request parameters are correct: //MSD BOT specs require wValue to be == 0x0000, and wLengh == 1 @@ -287,7 +287,7 @@ void USBCheckMSDRequest(void) /********************************************************************************* Function: uint8_t MSDTasks(void) - + Summary: This function runs the MSD class state machines and all of its sub-systems. This function should be called periodically once the @@ -298,7 +298,7 @@ void USBCheckMSDRequest(void) sub-systems. This function should be called periodically once the device is in the configured state in order to keep the MSD state machine going. - + Typical Usage: void main(void) @@ -318,7 +318,7 @@ void USBCheckMSDRequest(void) { //Keep the MSD state machine going MSDTasks(); - + //Run application code. UserApplication(); } @@ -336,12 +336,12 @@ void USBCheckMSDRequest(void) * MSD_DATA_OUT * MSD_SEND_CSW Remarks: - None - *********************************************************************************/ + None + *********************************************************************************/ uint8_t MSDTasks(void) { uint8_t i; - + //Error check to make sure we have are in the CONFIGURED_STATE, prior to //performing MSDTasks(). Some of the MSDTasks require that the device be //configured first. @@ -349,15 +349,15 @@ uint8_t MSDTasks(void) { return MSD_WAIT; } - - //Note: Both the USB stack code (usb_device.c) and this MSD handler code - //have the ability to modify the BDT values for the MSD bulk endpoints. If the + + //Note: Both the USB stack code (usb_device.c) and this MSD handler code + //have the ability to modify the BDT values for the MSD bulk endpoints. If the //USB stack operates in USB_INTERRUPT mode (user option in usb_config.h), we - //should temporily disable USB interrupts, to avoid any possibility of both + //should temporily disable USB interrupts, to avoid any possibility of both //the USB stack and this MSD handler from modifying the same BDT entry, or //MSD state machine variables (ex: in the case of MSD_RESET) at the same time. USBMaskInterrupts(); - + //Main MSD task dispatcher. Receives MSD Command Block Wrappers (CBW) and //dispatches appropriate lower level handlers to service the requests. switch(MSD_State) @@ -506,10 +506,10 @@ uint8_t MSDTasks(void) { break; //Not available yet. Just stay in this state and try again later. } - - //Send the Command Status Wrapper (CSW) packet + + //Send the Command Status Wrapper (CSW) packet USBMSDInHandle = USBTxOnePacket(MSD_DATA_IN_EP,(uint8_t*)&msd_csw,MSD_CSW_SIZE); - //If the bulk OUT endpoint isn't already armed, make sure to do so + //If the bulk OUT endpoint isn't already armed, make sure to do so //now so we can receive the next CBW packet from the host. if(!USBHandleBusy(USBMSDOutHandle)) { @@ -525,10 +525,10 @@ uint8_t MSDTasks(void) msd_csw.bCSWStatus = MSD_CSW_PHASE_ERROR; USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); }//switch(MSD_State) - + //Safe to re-enable USB interrupts now. USBUnmaskInterrupts(); - + return MSD_State; } @@ -536,33 +536,33 @@ uint8_t MSDTasks(void) /****************************************************************************** Function: uint8_t MSDProcessCommand(void) - + Description: This funtion processes a command received through the MSD class driver - + PreCondition: None - + Paramters: None - + Return Values: uint8_t - the current state of the MSDProcessCommand state machine. The valid values are defined in MSD.h under the MSDProcessCommand state machine declaration section - + Remarks: None - - *****************************************************************************/ + + *****************************************************************************/ uint8_t MSDProcessCommand(void) -{ +{ //Check if the media is either not present, or has been flagged by firmware //to pretend to be non-present (ex: SoftDetached). if((LUNMediaDetect() == false) || (SoftDetach[gblCBW.bCBWLUN] == true)) { - //Clear flag so we know the media need initialization, if it becomes + //Clear flag so we know the media need initialization, if it becomes //present in the future. gblMediaPresent &= ~((uint16_t)1<= MSD_IN_EP_SIZE) { NumBytesInPacket = MSD_IN_EP_SIZE; gblCBW.dCBWDataTransferLength -= MSD_IN_EP_SIZE; - } + } else { //This is a short packet and will be our last IN packet sent //in the transfer. NumBytesInPacket = gblCBW.dCBWDataTransferLength; gblCBW.dCBWDataTransferLength = 0; - } - + } + //We still have more bytes needing to be sent. Check if we have //already fulfilled the device input expected quantity of bytes. //If so, we need to keep sending IN packets, but pad the extra - //bytes with value = 0x00 (see error case 5 MSD device BOT v1.0 + //bytes with value = 0x00 (see error case 5 MSD device BOT v1.0 //spec handling). if(TransferLength.Val >= NumBytesInPacket) { //No problem, just send the requested data and keep track of remaining count. TransferLength.Val -= NumBytesInPacket; - } + } else { //The host is reading more bytes than the device has to send. //In this case, we still need to send the quantity of bytes requested, //but we have to fill the pad bytes with 0x00. The below for loop - //is execution speed inefficient, but performance isn't important - //since this code only executes in the case of a host error + //is execution speed inefficient, but performance isn't important + //since this code only executes in the case of a host error //anyway (Hi > Di). for(i = 0; i < NumBytesInPacket; i++) { if(TransferLength.Val != 0) { - TransferLength.Val--; - } + TransferLength.Val--; + } else { msd_buffer[i] = 0x00; - } - } - } - - //We are now ready to send the packet to the host. + } + } + } + + //We are now ready to send the packet to the host. USBMSDInHandle = USBTxOnePacket(MSD_DATA_IN_EP,(uint8_t*)&msd_buffer[0],NumBytesInPacket); - + //Check to see if we are done sending all requested bytes of data if(gblCBW.dCBWDataTransferLength == 0) { //We have sent all the requested bytes. Go ahead and //advance state so as to send the CSW. MSDCommandState = MSD_COMMAND_WAIT; - break; - } + break; + } } break; case MSD_COMMAND_ERROR: @@ -963,38 +963,38 @@ void MSDProcessCommandMediaPresent(void) //STALL, to force the host to perform error recovery. MSDErrorHandler(MSD_ERROR_UNSUPPORTED_COMMAND); break; - } // end switch + } // end switch }//void MSDProcessCommandMediaPresent(void) /****************************************************************************** Function: static void MSDComputeDeviceInAndResidue(uint16_t DiExpected) - + Description: This is a private function that performs Hi > Di data size checking and handling. This function also computes the proper CSW data residue and updates the global variable. - + PreCondition: - Should only be called in the context of the + Should only be called in the context of the MSDProcessCommandMediaPresent() handler function, after receiving a new command that needs processing. Before calling this function, make sure the gblCBW.dCBWDataTransferLength and TransferLength.Val variables have been pre-loaded with the expected host and device data size values. - + Parameters: - uint16_t DiExpected - Input: Firmware can specify an addional value that + uint16_t DiExpected - Input: Firmware can specify an addional value that might be smaller than the TransferLength.Val value. The function will update TransferLength.Val with the smaller of the original value, or DiExpected. - + Return Values: None - + Remarks: None - + *****************************************************************************/ static void MSDComputeDeviceInAndResidue(uint16_t DiExpected) { @@ -1005,41 +1005,41 @@ static void MSDComputeDeviceInAndResidue(uint16_t DiExpected) //send only the host requested quantity of bytes. msd_csw.dCSWDataResidue = 0; TransferLength.Val = gblCBW.dCBWDataTransferLength; - } + } else { //The host requested greater than or equal to the number of bytes expected. if(DiExpected < TransferLength.Val) { TransferLength.Val = DiExpected; - } + } msd_csw.dCSWDataResidue = gblCBW.dCBWDataTransferLength - TransferLength.Val; - } -} + } +} /****************************************************************************** Function: uint8_t MSDReadHandler(void) - + Description: - This funtion processes a read command received through + This funtion processes a read command received through the MSD class driver - + PreCondition: None - + Parameters: None - + Return Values: uint8_t - the current state of the MSDReadHandler state - machine. The valid values are defined in MSD.h under the + machine. The valid values are defined in MSD.h under the MSDReadHandler state machine declaration section - + Remarks: None - + *****************************************************************************/ uint8_t MSDReadHandler(void) { @@ -1048,27 +1048,27 @@ uint8_t MSDReadHandler(void) static uint8_t* ptrLastData = (uint8_t*)&msd_buffer[0]; static uint8_t* ptrNextData = (uint8_t*)&msd_buffer[MSD_IN_EP_SIZE]; static bool NewDataAlreadyAvailable; - + //Call our data fetching poller, unless we already have unprocessed data //ready for our retrieval. In this case, we need to stop calling our - //MDD_SDSPI_AsyncReadTasks(), until we are ready to consume the new buffer + //MDD_SDSPI_AsyncReadTasks(), until we are ready to consume the new buffer //worth of data and update the AsyncReadWriteInfo structure with a new pointer. if((fetchStatus != FILEIO_SD_ASYNC_READ_NEW_PACKET_READY) && (fetchStatus != FILEIO_SD_ASYNC_READ_COMPLETE)) { fetchStatus = LUNAsyncReadTasks(&AsyncReadWriteInfo); - } - + } + switch(MSDReadState) { case MSD_READ10_WAIT: - //Extract the LBA from the CBW. Note: Also need to perform endian + //Extract the LBA from the CBW. Note: Also need to perform endian //swap, since the multi-uint8_t CBW fields are stored big endian, but //the Microchip C compilers are little endian. LBA.v[3]=gblCBW.CBWCB[2]; LBA.v[2]=gblCBW.CBWCB[3]; LBA.v[1]=gblCBW.CBWCB[4]; LBA.v[0]=gblCBW.CBWCB[5]; - + TransferLength.byte.HB = gblCBW.CBWCB[7]; //MSB of Transfer Length (in number of blocks, not bytes) TransferLength.byte.LB = gblCBW.CBWCB[8]; //LSB of Transfer Length (in number of blocks, not bytes) @@ -1076,13 +1076,13 @@ uint8_t MSDReadHandler(void) if(MSDCheckForErrorCases(TransferLength.Val * (uint32_t)FILEIO_CONFIG_MEDIA_SECTOR_SIZE) != MSD_ERROR_CASE_NO_ERROR) { break; - } + } - //Assume success initially, msd_csw.bCSWStatus will get set to 0x01 - //or 0x02 later if an error is detected during the actual read sequence. + //Assume success initially, msd_csw.bCSWStatus will get set to 0x01 + //or 0x02 later if an error is detected during the actual read sequence. msd_csw.bCSWStatus=0x0; msd_csw.dCSWDataResidue=gblCBW.dCBWDataTransferLength; - + //Set up our fetch info data structure. AsyncReadWriteInfo.wNumBytes = MSD_IN_EP_SIZE; AsyncReadWriteInfo.pBuffer = (uint8_t*)ptrNextData; @@ -1108,20 +1108,20 @@ uint8_t MSDReadHandler(void) else { fetchStatus = LUNAsyncReadTasks(&AsyncReadWriteInfo); - } - } + } + } //Check if we are done handling the whole READ10 request. if((fetchStatus == FILEIO_SD_ASYNC_READ_COMPLETE) && (msd_csw.dCSWDataResidue == 0)) { MSDReadState = MSD_READ10_AWAITING_COMPLETION; break; - } + } else if(fetchStatus == FILEIO_SD_ASYNC_READ_ERROR) { MSDReadState = MSD_READ10_ERROR; - } - + } + //Check if we currently have any new data ready and we are ready to //send the data over USB to the host. if((!USBHandleBusy(USBMSDInHandle)) && (NewDataAlreadyAvailable == true)) @@ -1131,24 +1131,24 @@ uint8_t MSDReadHandler(void) ptrLastData = ptrNextData; ptrNextData = ptrSave; //Prepare the USB module to send an IN transaction worth of data to the host. - USBMSDInHandle = USBTxOnePacket(MSD_DATA_IN_EP,ptrLastData,MSD_IN_EP_SIZE); + USBMSDInHandle = USBTxOnePacket(MSD_DATA_IN_EP,ptrLastData,MSD_IN_EP_SIZE); //Advance state machine now that the fetch operation is returning data. AsyncReadWriteInfo.pBuffer = (uint8_t*)ptrNextData; //Swap pointer, so we use the other buffer (the one not currently in use by USB). //We are sending a USB packet worth of data. Decrement counter. - msd_csw.dCSWDataResidue-=MSD_IN_EP_SIZE; - //Get the next operation started, so it can occur concurrently + msd_csw.dCSWDataResidue-=MSD_IN_EP_SIZE; + //Get the next operation started, so it can occur concurrently //with the above USB transfer, for maximum transfer speeds. if(fetchStatus == FILEIO_SD_ASYNC_READ_NEW_PACKET_READY) { fetchStatus = LUNAsyncReadTasks(&AsyncReadWriteInfo); NewDataAlreadyAvailable = true; - } + } else - { + { fetchStatus = LUNAsyncReadTasks(&AsyncReadWriteInfo); NewDataAlreadyAvailable = false; - } - } + } + } break; case MSD_READ10_AWAITING_COMPLETION: //If the old data isn't completely sent over USB yet, need to stay @@ -1160,7 +1160,7 @@ uint8_t MSDReadHandler(void) else { MSDReadState = MSD_READ10_WAIT; - } + } break; case MSD_READ10_ERROR: default: @@ -1181,8 +1181,8 @@ uint8_t MSDReadHandler(void) USBStallEndpoint(MSD_DATA_IN_EP,1); //Will cause host to perform clear endpoint halt, then request CSW MSDReadState = MSD_READ10_WAIT; } - - + + return MSDReadState; } @@ -1190,25 +1190,25 @@ uint8_t MSDReadHandler(void) /****************************************************************************** Function: uint8_t MSDWriteHandler(void) - + Description: - This funtion processes a write command received through + This funtion processes a write command received through the MSD class driver - + PreCondition: None - + Parameters: None - + Return Values: uint8_t - the current state of the MSDWriteHandler state - machine. The valid values are defined in MSD.h under the + machine. The valid values are defined in MSD.h under the MSDWriteHandler state machine declaration section - + Remarks: None - + *****************************************************************************/ uint8_t MSDWriteHandler(void) { @@ -1242,16 +1242,16 @@ uint8_t MSDWriteHandler(void) //An error was detected. The MSDCheckForErrorCases() function will //have taken care of setting the proper states to report the error to the host. break; - } - + } + //Check if the media is write protected before deciding what //to do with the data. - if(LUNWriteProtectState()) + if(LUNWriteProtectState()) { //The media appears to be write protected. //Let host know error occurred. The bCSWStatus flag is also used by //the write handler, to know not to even attempt the write sequence. - msd_csw.bCSWStatus = MSD_CSW_COMMAND_FAILED; + msd_csw.bCSWStatus = MSD_CSW_COMMAND_FAILED; //Set sense keys so the host knows what caused the error. gblSenseData[LUN_INDEX].SenseKey=S_DATA_PROTECT; @@ -1264,7 +1264,7 @@ uint8_t MSDWriteHandler(void) MSDWriteState = MSD_WRITE10_WAIT; return MSDWriteState; } - + //Initialize our ASYNC_IO structure, so the MDD_SDSPI_AsyncWriteTasks() //API will know what to do. AsyncReadWriteInfo.bStateVariable = FILEIO_SD_ASYNC_WRITE_QUEUED; @@ -1273,15 +1273,15 @@ uint8_t MSDWriteHandler(void) AsyncReadWriteInfo.pBuffer = (uint8_t*)&msd_buffer[0]; AsyncReadWriteInfo.wNumBytes = MSD_OUT_EP_SIZE; LastWriteStatus = FILEIO_SD_ASYNC_WRITE_BUSY; - - + + //Initialize other parameters PacketRequestCounter = gblCBW.dCBWDataTransferLength / MSD_OUT_EP_SIZE; PacketsRemainingToBeReceived = PacketRequestCounter; BufferredBytes = 0; pNextData = (uint8_t*)&msd_buffer[0]; pUSBReceive = (uint8_t*)&msd_buffer[0]; - + //Arm both MSD bulk OUT endpoints (even and odd) to begin receiving //the data to write to the media, from the host. if((!USBHandleBusy(USBMSDOutHandle)) && (!USBHandleBusy(USBGetNextHandle(MSD_DATA_OUT_EP, OUT_FROM_HOST)))) @@ -1295,18 +1295,18 @@ uint8_t MSDWriteHandler(void) } else { - //Something is wrong. The endpoints should have been free at + //Something is wrong. The endpoints should have been free at //this point in the code. msd_csw.bCSWStatus = MSD_CSW_PHASE_ERROR; USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); MSDWriteState = MSD_WRITE10_WAIT; - break; - } + break; + } NextHandleToCheck = MSDOutHandle1; USBMSDOutHandle = NextHandleToCheck; - - + + MSDWriteState = MSD_WRITE10_RX_SECTOR; //Fall through to MSD_WRITE10_RX_SECTOR case MSD_WRITE10_RX_SECTOR: @@ -1322,30 +1322,30 @@ uint8_t MSDWriteHandler(void) if(USBHandleGetLength(NextHandleToCheck) != MSD_OUT_EP_SIZE) { //The host sent us an unexpected short packet. This is - //presumably an error, possibly a phase error (ex: host - //send a CBW, instead of a data packet), since bulk - //endpoint sizes are required to be a power of 2, which + //presumably an error, possibly a phase error (ex: host + //send a CBW, instead of a data packet), since bulk + //endpoint sizes are required to be a power of 2, which //happens to be exact integer divider of the write block //size (512). msd_csw.bCSWStatus = MSD_CSW_PHASE_ERROR; USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); MSDWriteState = MSD_WRITE10_WAIT; break; - } + } BufferredBytes += MSD_OUT_EP_SIZE; //Reduce number of future packets we expect to receive for this //Write10 request. - PacketsRemainingToBeReceived--; - + PacketsRemainingToBeReceived--; + if(NextHandleToCheck == MSDOutHandle1) { - NextHandleToCheck = MSDOutHandle2; + NextHandleToCheck = MSDOutHandle2; } else { - NextHandleToCheck = MSDOutHandle1; - } - + NextHandleToCheck = MSDOutHandle1; + } + //Re-arm the endpoint now, if we still need more data from the //host to finish the Write10 request. if(PacketRequestCounter != 0) @@ -1354,16 +1354,16 @@ uint8_t MSDWriteHandler(void) //Decrement remaining packets to be requested, so we know when //to stop requesting more data. PacketRequestCounter--; - + //Increment next receive location pointer, but check for wraparound pUSBReceive += MSD_OUT_EP_SIZE; if(pUSBReceive >= (uint8_t*)&msd_buffer[4u * (uint16_t)MSD_OUT_EP_SIZE]) { pUSBReceive = (uint8_t*)&msd_buffer[0]; - } - } - } - + } + } + } + if(LastWriteStatus == FILEIO_SD_ASYNC_WRITE_BUSY) { @@ -1372,9 +1372,9 @@ uint8_t MSDWriteHandler(void) if(msd_csw.bCSWStatus == 0x00) { LastWriteStatus = LUNAsyncWriteTasks(&AsyncReadWriteInfo); - } - } - + } + } + if(LastWriteStatus == FILEIO_SD_ASYNC_WRITE_ERROR) { //Some unexpected error occurred. Notify the host. @@ -1382,16 +1382,16 @@ uint8_t MSDWriteHandler(void) USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); MSDWriteState = MSD_WRITE10_WAIT; break; - } + } if(LastWriteStatus == FILEIO_SD_ASYNC_WRITE_COMPLETE) { //The media is now fully done with all packets of the write request. MSDWriteState = MSD_WRITE10_WAIT; USBMSDOutHandle = USBGetNextHandle(MSD_DATA_OUT_EP, OUT_FROM_HOST); break; - } - - //Check if the media write state machine wants data, and we have + } + + //Check if the media write state machine wants data, and we have //data ready to send it. if((LastWriteStatus == FILEIO_SD_ASYNC_WRITE_SEND_PACKET) && (BufferredBytes > 0)) { @@ -1401,7 +1401,7 @@ uint8_t MSDWriteHandler(void) { msd_csw.dCSWDataResidue -= MSD_OUT_EP_SIZE; LastWriteStatus = LUNAsyncWriteTasks(&AsyncReadWriteInfo); - } + } //Update pointer to point to the next data location, so we will //be ready for the next iteration of this code. Make sure @@ -1410,17 +1410,17 @@ uint8_t MSDWriteHandler(void) if(pNextData >= (uint8_t*)&msd_buffer[4u * (uint16_t)MSD_OUT_EP_SIZE]) { pNextData = (uint8_t*)&msd_buffer[0]; - } - - //We removed data from the buffer. + } + + //We removed data from the buffer. BufferredBytes -= MSD_OUT_EP_SIZE; //Check for underflow. This shouldn't happen, and would only //occur in some kind of error case. if((signed short int)BufferredBytes < 0) { BufferredBytes = 0; - } - } + } + } break; @@ -1430,9 +1430,9 @@ uint8_t MSDWriteHandler(void) //does, try to let the host know know an error has occurred. msd_csw.bCSWStatus = MSD_CSW_PHASE_ERROR; //Phase Error USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); - MSDWriteState = MSD_WRITE10_WAIT; + MSDWriteState = MSD_WRITE10_WAIT; } - + return MSDWriteState; } @@ -1440,25 +1440,25 @@ uint8_t MSDWriteHandler(void) /****************************************************************************** Function: void ResetSenseData(void) - + Description: This routine resets the Sense Data, initializing the structure RequestSenseResponse gblSenseData. - + PreCondition: - None - + None + Parameters: None - + Return Values: None - + Remarks: None - + *****************************************************************************/ -void ResetSenseData(void) +void ResetSenseData(void) { gblSenseData[LUN_INDEX].ResponseCode=S_CURRENT; gblSenseData[LUN_INDEX].VALID=0; // no data in the information field @@ -1487,61 +1487,61 @@ void ResetSenseData(void) /****************************************************************************** Function: uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) - + Description: - This function can be called to check for various error cases, primarily + This function can be called to check for various error cases, primarily the "Thirteen Cases" errors described in the MSD BOT v1.0 specs. If an error is detected, the function internally calls the MSDErrorHandler() - handler function, to take care of appropriately responding to the host, + handler function, to take care of appropriately responding to the host, based on the error condition. PreCondition: None - + Parameters: - uint32_t DeviceBytes - Input: This is the total number of bytes the MSD - device firmware is expecting in the MSD transfer. + uint32_t DeviceBytes - Input: This is the total number of bytes the MSD + device firmware is expecting in the MSD transfer. Return Values: uint8_t - Returns a byte containing the error code. The possible error cases that can be detected and reported are: MSD_ERROR_CASE_NO_ERROR - None of the "Thirteen cases" errors were detected - MSD_ERROR_CASE_2 - MSD_ERROR_CASE_3 - MSD_ERROR_CASE_4 - MSD_ERROR_CASE_5 - MSD_ERROR_CASE_7 - MSD_ERROR_CASE_8 - MSD_ERROR_CASE_9 - MSD_ERROR_CASE_11 - MSD_ERROR_CASE_10 - MSD_ERROR_CASE_13 - + MSD_ERROR_CASE_2 + MSD_ERROR_CASE_3 + MSD_ERROR_CASE_4 + MSD_ERROR_CASE_5 + MSD_ERROR_CASE_7 + MSD_ERROR_CASE_8 + MSD_ERROR_CASE_9 + MSD_ERROR_CASE_11 + MSD_ERROR_CASE_10 + MSD_ERROR_CASE_13 + Remarks: None - + *****************************************************************************/ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) { uint8_t MSDErrorCase; bool HostMoreDataThanDevice; bool DeviceNoData; - + //Check if device is expecting no data (Dn) if(DeviceBytes == 0) { DeviceNoData = true; - } + } else { DeviceNoData = false; - } - + } + //First check for the three good/non-error cases - + //Check for good case: Hn = Dn (Case 1) if((MSDHostNoData == true) && (DeviceNoData == true)) { return MSD_ERROR_CASE_NO_ERROR; - } + } //Check for good cases where the data sizes between host and device match if(gblCBW.dCBWDataTransferLength == DeviceBytes) @@ -1553,18 +1553,18 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) if(MSDCommandState != MSD_WRITE_10) { return MSD_ERROR_CASE_NO_ERROR; - } + } } - else //if(MSD_State == MSD_DATA_OUT) + else //if(MSD_State == MSD_DATA_OUT) { //Check for good case: Ho = Do (Case 12) //Make sure Ho = Do, instead of Ho = Di if(MSDCommandState == MSD_WRITE_10) { return MSD_ERROR_CASE_NO_ERROR; - } - } - } + } + } + } //If we get to here, this implies some kind of error is occuring. Do some //checks to find out which error occurred, so we know how to handle it. @@ -1573,12 +1573,12 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) if(gblCBW.dCBWDataTransferLength > DeviceBytes) { HostMoreDataThanDevice = true; - } + } else { HostMoreDataThanDevice = false; - } - + } + //Check host's expected data direction if(MSD_State == MSD_DATA_OUT) { @@ -1586,7 +1586,7 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) if((MSDCommandState != MSD_WRITE_10) && (DeviceNoData == false)) MSDErrorCase = MSD_ERROR_CASE_10; //Check for Hn < Do (Case 3) - else if(MSDHostNoData == true) + else if(MSDHostNoData == true) MSDErrorCase = MSD_ERROR_CASE_3; //Check for Ho > Dn (Case 9) else if(DeviceNoData == true) @@ -1597,14 +1597,14 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) //Check for Ho < Do (Case 13) else //if(gblCBW.dCBWDataTransferLength < DeviceBytes) MSDErrorCase = MSD_ERROR_CASE_13; - } + } else //else the MSD_State must be == MSD_DATA_IN { //First check for Hi <> Do (Case 8) if(MSDCommandState == MSD_WRITE_10) - MSDErrorCase = MSD_ERROR_CASE_8; + MSDErrorCase = MSD_ERROR_CASE_8; //Check for Hn < Di (Case 2) - else if(MSDHostNoData == true) + else if(MSDHostNoData == true) MSDErrorCase = MSD_ERROR_CASE_2; //Check for Hi > Dn (Case 4) else if(DeviceNoData == true) @@ -1615,17 +1615,17 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) //Check for Hi < Di (Case 7) else //if(gblCBW.dCBWDataTransferLength < DeviceBytes) MSDErrorCase = MSD_ERROR_CASE_7; - } + } //Now call the MSDErrorHandler(), based on the error that was detected. MSDErrorHandler(MSDErrorCase); return MSDErrorCase; -} +} /****************************************************************************** Function: void MSDErrorHandler(uint8_t ErrorCase) - + Description: Once an error condition has been detected, this function can be called to set the proper states and perform the proper tasks needed to let the @@ -1633,44 +1633,44 @@ uint8_t MSDCheckForErrorCases(uint32_t DeviceBytes) PreCondition: Firmware should have already determined an error occurred, and it should know what the error code was before calling this handler. - + Parameters: - uint8_t ErrorCase - Input: This is the error code that the firmware + uint8_t ErrorCase - Input: This is the error code that the firmware detected. This error code will determine how the handler will behave (ex: what status to send to host, what endpoint(s) should be stalled, etc.). The implemented error case possibilities are (suffix - numbers correspond to the "Thirteen cases" numbers + numbers correspond to the "Thirteen cases" numbers described in the MSD BOT specs v1.0): - - MSD_ERROR_CASE_2 - MSD_ERROR_CASE_3 - MSD_ERROR_CASE_4 - MSD_ERROR_CASE_5 - MSD_ERROR_CASE_7 - MSD_ERROR_CASE_8 - MSD_ERROR_CASE_9 - MSD_ERROR_CASE_11 - MSD_ERROR_CASE_10 - MSD_ERROR_CASE_13 - MSD_ERROR_UNSUPPORTED_COMMAND + + MSD_ERROR_CASE_2 + MSD_ERROR_CASE_3 + MSD_ERROR_CASE_4 + MSD_ERROR_CASE_5 + MSD_ERROR_CASE_7 + MSD_ERROR_CASE_8 + MSD_ERROR_CASE_9 + MSD_ERROR_CASE_11 + MSD_ERROR_CASE_10 + MSD_ERROR_CASE_13 + MSD_ERROR_UNSUPPORTED_COMMAND Return Values: None - + Remarks: None - + *****************************************************************************/ void MSDErrorHandler(uint8_t ErrorCase) { uint8_t OldMSD_State; - + //Both MSD bulk IN and OUT endpoints should not be busy when these error cases are detected //If for some reason this isn't true, then we should preserve the state machines states for now. if((USBHandleBusy(USBMSDInHandle)) || (USBHandleBusy(USBMSDOutHandle))) { - return; + return; } //Save the old state before we change it. The old state is needed to determine @@ -1686,7 +1686,7 @@ void MSDErrorHandler(uint8_t ErrorCase) msd_csw.bCSWStatus = MSD_CSW_COMMAND_FAILED; //Gets changed later to phase error for errors that user phase error MSD_State = MSD_SEND_CSW; - //Now do other error related handling tasks, which depend on the specific + //Now do other error related handling tasks, which depend on the specific //error type that was detected. switch(ErrorCase) { @@ -1717,7 +1717,7 @@ void MSDErrorHandler(uint8_t ErrorCase) gblSenseData[LUN_INDEX].SenseKey=S_ILLEGAL_REQUEST; gblSenseData[LUN_INDEX].ASC=ASC_INVALID_COMMAND_OPCODE; gblSenseData[LUN_INDEX].ASCQ=ASCQ_INVALID_COMMAND_OPCODE; - + if((OldMSD_State == MSD_DATA_OUT) && (gblCBW.dCBWDataTransferLength != 0)) { USBStallEndpoint(MSD_DATA_OUT_EP, OUT_FROM_HOST); @@ -1730,7 +1730,7 @@ void MSDErrorHandler(uint8_t ErrorCase) default: //Shouldn't get hit, don't call MSDErrorHandler() if there is no error break; }//switch(ErrorCase) -} +} diff --git a/src/usb_device_phdc.c b/src/usb_device_phdc.c index 1ace70a..540a3ee 100644 --- a/src/usb_device_phdc.c +++ b/src/usb_device_phdc.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -42,7 +42,7 @@ please contact mla_licensing@microchip.com //The phdc_data_rx[] and phdc_data_tx[] arrays are used as //USB packet buffers in this firmware. Therefore, they must be located in //a USB module accessible portion of microcontroller RAM. - #if defined(__18F14K50) || defined(__18F13K50) || defined(__18LF14K50) || defined(__18LF13K50) + #if defined(__18F14K50) || defined(__18F13K50) || defined(__18LF14K50) || defined(__18LF13K50) #pragma udata usbram2 #elif defined(__18F2455) || defined(__18F2550) || defined(__18F4455) || defined(__18F4550)\ || defined(__18F2458) || defined(__18F2553) || defined(__18F4458) || defined(__18F4553)\ @@ -61,7 +61,7 @@ volatile FAR unsigned char phdc_data_tx[PHDC_DATA_IN_EP_SIZE]; #if defined(__18CXX) #pragma udata -#endif +#endif POINTER pPHDCSrc; // Dedicated source pointer POINTER pPHDCDst; // Dedicated destination pointer @@ -88,23 +88,23 @@ extern BYTE_VAL *pDst; /****************************************************************************** Function: void USBDevicePHDCCheckRequest(void) - + Description: This routine checks the setup data packet to see if it knows how to handle it - + PreCondition: None Parameters: None - + Return Values: None - + Remarks: None - + *****************************************************************************/ void USBDevicePHDCCheckRequest(void) { @@ -123,19 +123,19 @@ void USBDevicePHDCCheckRequest(void) * PHDC class, else return */ if(SetupPkt.bIntfID != PHDC_INTF_ID)return; - + switch(SetupPkt.bRequest) { //****** These commands are required ******// case GET_DATA_STATUS : if(SetupPkt.wValue == 0) { - CtrlTrfData[0] = (UINT8 )phdcEpDataBitmap; + CtrlTrfData[0] = (UINT8 )phdcEpDataBitmap; CtrlTrfData[1] = (UINT8) phdcEpDataBitmap >> 8; USBEP0SendRAMPtr((BYTE*)CtrlTrfData, 2, USB_EP0_NO_OPTIONS); } - - break; + + break; default: break; }//end switch(SetupPkt.bRequest) @@ -147,7 +147,7 @@ void USBDevicePHDCCheckRequest(void) /************************************************************************** Function: void USBDevicePHDCInit(USB_PHDC_CB callback) - + Summary: This function initializes the PHDC function driver. This function should be called during the init process. @@ -155,8 +155,8 @@ void USBDevicePHDCCheckRequest(void) This function initializes the PHDC function driver. This function initializes the end point data structures. A call back function from the upper layer is also registered. - - + + Typical Usage: void PHDCAppInit(PHDC_APP_CB callback) @@ -168,42 +168,42 @@ void USBDevicePHDCCheckRequest(void) Conditions: None Remarks: - None + None **************************************************************************/ void USBDevicePHDCInit(USB_PHDC_CB callback) -{ +{ PhdcRXEP[0].ep_num=PHDC_DATA_EP; PhdcRXEP[0].offset =0; - PhdcRXEP[0].qos = PHDC_BULK_OUT_QOS; + PhdcRXEP[0].qos = PHDC_BULK_OUT_QOS; + PhdcRXEP[0].transfer_size =0; PhdcRXEP[0].transfer_size =0; - PhdcRXEP[0].transfer_size =0; PhdcRXEP[0].size = PHDC_DATA_OUT_EP_SIZE; - + PhdcTXEP[0].ep_num=PHDC_DATA_EP; PhdcTXEP[0].offset =0; - PhdcTXEP[0].qos = PHDC_BULK_IN_QOS; + PhdcTXEP[0].qos = PHDC_BULK_IN_QOS; PhdcTXEP[0].transfer_size =0; - PhdcTXEP[0].bytes_to_send = 0; + PhdcTXEP[0].bytes_to_send = 0; PhdcTXEP[0].size =PHDC_DATA_IN_EP_SIZE; #if defined USE_PHDC_INTERRUPT_ENDPOINT PhdcTXEP[1].ep_num=PHDC_INT_EP; PhdcTXEP[1].offset =0; - PhdcTXEP[1].qos = PHDC_INT_IN_QOS; + PhdcTXEP[1].qos = PHDC_INT_IN_QOS; PhdcTXEP[1].transfer_size =0; - PhdcTXEP[1].bytes_to_send = 0; + PhdcTXEP[1].bytes_to_send = 0; PhdcTXEP[1].size =PHDC_INT_IN_EP_SIZE; - #endif + #endif PhdAppCB = callback; phdcEpDataBitmap = 0; - + }//end PHDCInitEP /********************************************************************************** Function: UINT8 USBDevicePHDCReceiveData(UINT8 qos, UINT8 *buffer, UINT16 len) - + Summary: USBDevicePHDCReceiveData copies a string of BYTEs received through USB PHDC Bulk OUT endpoint to a user's specified location. It is a non-blocking function. @@ -215,10 +215,10 @@ void USBDevicePHDCInit(USB_PHDC_CB callback) endpoint to a user's specified location. It is a non-blocking function. It does not wait for data if there is no data available. Instead it returns '0' to notify the caller that there is no data available. - + Typical Usage: - + Conditions: Value of input argument 'len' should be smaller than the maximum @@ -229,14 +229,14 @@ void USBDevicePHDCInit(USB_PHDC_CB callback) qos - quality of service buffer - Pointer to where received BYTEs are to be stored len - The number of BYTEs expected. - + **********************************************************************************/ UINT8 USBDevicePHDCReceiveData(UINT8 qos, UINT8* buffer, UINT16 len) -{ +{ PTR_PHDC_RX_ENDPOINT recv_endpoint; UINT8 index; UINT8 phdc_rx_len = 0; - + for(index=0; index< PHDC_RX_ENDPOINTS;index++) { if((PhdcRXEP[index].qos & qos) != 0) @@ -247,7 +247,7 @@ UINT8 USBDevicePHDCReceiveData(UINT8 qos, UINT8* buffer, UINT16 len) { return 0; //no endpoint supports the qos } - + recv_endpoint = &PhdcRXEP[index]; recv_endpoint->app_buff = (UINT8*)buffer; @@ -257,26 +257,26 @@ UINT8 USBDevicePHDCReceiveData(UINT8 qos, UINT8* buffer, UINT16 len) recv_endpoint->PHDCDataOutHandle = USBRxOnePacket(recv_endpoint->ep_num, (UINT8*) phdc_data_rx, recv_endpoint->size); - + return phdc_rx_len; - + }//end getsUSBUSART /****************************************************************************** Function: void USBDevicePHDCSendData(UINT8 qos, UINT8 *data, UINT8 Length) - + Summary: - USBDevicePHDCSendData writes an array of data to the USB. + USBDevicePHDCSendData writes an array of data to the USB. Description: USBDevicePHDCSendData writes an array of data to the USB. - + Typical Usage: - + - + The transfer mechanism for device-to-host(put) is more flexible than host-to-device(get). It can handle a string of data larger than the maximum size of bulk IN endpoint. A state machine is used to transfer a @@ -291,7 +291,7 @@ UINT8 USBDevicePHDCReceiveData(UINT8 qos, UINT8* buffer, UINT16 len) *data - pointer to a RAM/ROM array of data to be transfered to the host length - the number of bytes to be transfered. memtype - Indicates whether the data array is in ROM or RAM - + *****************************************************************************/ void USBDevicePHDCSendData(UINT8 qos, UINT8 *data, UINT16 length,BOOL memtype) { @@ -309,25 +309,25 @@ void USBDevicePHDCSendData(UINT8 qos, UINT8 *data, UINT16 length,BOOL memtype) return; //no endpoint supports the qos } tx_endpoint = &PhdcTXEP[index]; - + if( (tx_endpoint->transfer_size ==0) && (tx_endpoint->offset ==0) ) //new packet { tx_endpoint->transfer_size = length; tx_endpoint->memtype= memtype; if(tx_endpoint->transfer_size > tx_endpoint->size) - { + { tx_endpoint->bytes_to_send = tx_endpoint->size; //multiple send } else { tx_endpoint->bytes_to_send = tx_endpoint->transfer_size; //only packet to send - } + } } else { return; //send in progress } - USBMaskInterrupts(); + USBMaskInterrupts(); tx_endpoint->app_buff = (UINT8*)data; i= tx_endpoint->bytes_to_send; pPHDCDst.bRam = (BYTE*)phdc_data_tx; // Set destination pointer @@ -340,7 +340,7 @@ void USBDevicePHDCSendData(UINT8 qos, UINT8 *data, UINT16 length,BOOL memtype) pPHDCDst.bRam++; pPHDCSrc.bRom++; i--; - }//end while(byte_to_send) + }//end while(byte_to_send) } else // _RAM { @@ -351,12 +351,12 @@ void USBDevicePHDCSendData(UINT8 qos, UINT8 *data, UINT16 length,BOOL memtype) pPHDCDst.bRam++; pPHDCSrc.bRam++; i--; - }//end while(byte_to_send._word) + }//end while(byte_to_send._word) }//end if(phdc_mem_type...) - + tx_endpoint->PHDCDataInHandle = USBTxOnePacket(tx_endpoint->ep_num, (BYTE*)phdc_data_tx,tx_endpoint->bytes_to_send); - USBDevicePHDCUpdateStatus(tx_endpoint->ep_num, 1); // update the endpoint status. '1' if endpoint has data. '0' otherwise. + USBDevicePHDCUpdateStatus(tx_endpoint->ep_num, 1); // update the endpoint status. '1' if endpoint has data. '0' otherwise. USBUnmaskInterrupts(); }//end USBDevicePHDCSendData @@ -364,22 +364,22 @@ void USBDevicePHDCSendData(UINT8 qos, UINT8 *data, UINT16 length,BOOL memtype) /************************************************************************ Function: void USBDevicePHDCTxRXService(PTR_USTAT_STRUCT val) - + Summary: USBDevicePHDCTxRXService handles device-to-host transaction(s) and host-to-device transaction(s). This function is automatically called when a transfer event occurs.Device should be in configured state. - + Description: USBDevicePHDCTxRXService handles device-to-host transaction(s) and host-to-device transaction(s). This function is automatically called when a transfer event occurs.Device should be in configured state. - + Typical Usage: BOOL USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, WORD size) { switch(event) { - case EVENT_CONFIGURED: + case EVENT_CONFIGURED: USBCBInitEP(); break; case EVENT_SET_DESCRIPTOR: @@ -406,18 +406,18 @@ void USBDevicePHDCSendData(UINT8 qos, UINT8 *data, UINT16 length,BOOL memtype) break; default: break; - } - return TRUE; + } + return TRUE; } Conditions: None Remarks: - None + None ************************************************************************/ void USBDevicePHDCTxRXService(USTAT_FIELDS* pdata) { - + UINT8 i; PTR_PHDC_TX_ENDPOINT tx_endpoint; PTR_PHDC_RX_ENDPOINT recv_endpoint; @@ -426,30 +426,30 @@ void USBDevicePHDCTxRXService(USTAT_FIELDS* pdata) val = *pdata; if(USBHALGetLastDirection(val) == DIR_IN) - { + { /* Find which Endpoint needs to send data based on the qos value */ for(index = 0; index < PHDC_TX_ENDPOINTS; index++) { if(PhdcTXEP[index].ep_num == USBHALGetLastEndpoint(val)) break; } - + tx_endpoint = &PhdcTXEP[index]; - + USBDevicePHDCUpdateStatus(tx_endpoint->ep_num, 0); - + tx_endpoint->offset += USBHandleGetLength(tx_endpoint->PHDCDataInHandle); - if((tx_endpoint->offset == tx_endpoint->transfer_size)&& + if((tx_endpoint->offset == tx_endpoint->transfer_size)&& (USBHandleGetLength(tx_endpoint->PHDCDataInHandle) !=0)) //send zero lenght packet { if(tx_endpoint->transfer_size % tx_endpoint->size == 0) { tx_endpoint->PHDCDataInHandle = USBTxOnePacket(tx_endpoint->ep_num,NULL,0); - USBDevicePHDCUpdateStatus(tx_endpoint->ep_num, 1); - return; + USBDevicePHDCUpdateStatus(tx_endpoint->ep_num, 1); + return; } } - + //data sent. Also ZLP if(tx_endpoint->offset >= tx_endpoint->transfer_size) { @@ -466,18 +466,18 @@ void USBDevicePHDCTxRXService(USTAT_FIELDS* pdata) { tx_endpoint->bytes_to_send = tx_endpoint->size; //multiple send } - + } USBMaskInterrupts(); - + i= tx_endpoint->bytes_to_send; - pPHDCDst.bRam = (BYTE*)phdc_data_tx; // Set destination pointer + pPHDCDst.bRam = (BYTE*)phdc_data_tx; // Set destination pointer if(tx_endpoint->memtype == MEM_ROM) // Determine type of memory source { pPHDCSrc.bRom = (ROM UINT8*)(tx_endpoint->app_buff + tx_endpoint->offset); - + while(i) { *pPHDCDst.bRam = *pPHDCSrc.bRom; @@ -485,7 +485,7 @@ void USBDevicePHDCTxRXService(USTAT_FIELDS* pdata) pPHDCSrc.bRom++; i--; }//end while(byte_to_send) - + } else // _RAM { @@ -497,19 +497,19 @@ void USBDevicePHDCTxRXService(USTAT_FIELDS* pdata) pPHDCSrc.bRam++; i--; }//end while(byte_to_send._word) - + }//end if(phdc_mem_type...) - + tx_endpoint->PHDCDataInHandle = USBTxOnePacket(tx_endpoint->ep_num, (UINT8*)phdc_data_tx, tx_endpoint->bytes_to_send); - USBDevicePHDCUpdateStatus(tx_endpoint->ep_num, 1); - USBUnmaskInterrupts(); + USBDevicePHDCUpdateStatus(tx_endpoint->ep_num, 1); + USBUnmaskInterrupts(); } - + else //DIR_OUT { - + for(index = 0; index < PHDC_RX_ENDPOINTS; index++) { if(PhdcRXEP[index].ep_num == USBHALGetLastEndpoint(val)) @@ -524,13 +524,13 @@ void USBDevicePHDCTxRXService(USTAT_FIELDS* pdata) recv_endpoint->offset =0; memcpy(recv_endpoint->app_buff,(void *)phdc_data_rx,recv_endpoint->len ); PhdAppCB(USB_APP_GET_TRANSFER_SIZE,&TransferSize); - recv_endpoint->transfer_size = TransferSize; + recv_endpoint->transfer_size = TransferSize; } else if(recv_endpoint->transfer_size > PHDC_MAX_APDU_SIZE) { - // do not copy the data to appbuffer if transfer size is more than maximum APDU size specified by the user. - recv_endpoint->offset = 0; - } + // do not copy the data to appbuffer if transfer size is more than maximum APDU size specified by the user. + recv_endpoint->offset = 0; + } else { /* copy the data starting from the previuos offset*/ @@ -543,56 +543,56 @@ void USBDevicePHDCTxRXService(USTAT_FIELDS* pdata) if((recv_endpoint->offset >= recv_endpoint->transfer_size) || ((recv_endpoint->len % recv_endpoint->size!=0))) { - if(((recv_endpoint->transfer_size % recv_endpoint->size)==0)&& + if(((recv_endpoint->transfer_size % recv_endpoint->size)==0)&& (recv_endpoint->len!=0)) { //zero length packet receive here USBRxOnePacket(recv_endpoint->ep_num,NULL,0); } - recv_endpoint->offset =0; + recv_endpoint->offset =0; recv_endpoint->transfer_size =0; PhdAppCB(USB_APP_DATA_RECEIVED,NULL);/*inform the application*/ USBUnmaskInterrupts(); return; } - - + + USBRxOnePacket(recv_endpoint->ep_num,(BYTE *)phdc_data_rx, (recv_endpoint->transfer_size-recv_endpoint->offset)); - - + + } USBUnmaskInterrupts(); } - + /****************************************************************************** Function: void USBDevicePHDCUpdateStatus (WORD EndpointNo, BIT Status) - + Description: - This routine handles the Get Data Status request received from the PHDC Host. - + This routine handles the Get Data Status request received from the PHDC Host. + PreCondition: None Parameters: None - + Return Values: None - + Remarks: None - + *****************************************************************************/ void USBDevicePHDCUpdateStatus (WORD EndpointNo, BIT Status) { if (Status == 1) phdcEpDataBitmap |= 1 << EndpointNo ; - else - phdcEpDataBitmap &= ~(1 << EndpointNo); -} + else + phdcEpDataBitmap &= ~(1 << EndpointNo); +} #endif //USB_USE_PHDC diff --git a/src/usb_device_phdc_com_model.c b/src/usb_device_phdc_com_model.c index f3e6369..a9c7062 100644 --- a/src/usb_device_phdc_com_model.c +++ b/src/usb_device_phdc_com_model.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -651,7 +651,7 @@ static void PHDPrstApduHandler(BYTE* apdu_val) { //We have received the response for the measurement that we sent. PhdConfirmTimeoutStatus = TIMEOUT_DISABLED; - AppCB(PHD_MEASUREMENT_SENT); + AppCB(PHD_MEASUREMENT_SENT); } } else if (data.Val == ROIV_CMIP_CONFIRMED_ACTION_CHOSEN) diff --git a/src/usb_hal_16bit.c b/src/usb_hal_16bit.c index fb8efc7..f3f7f90 100644 --- a/src/usb_hal_16bit.c +++ b/src/usb_hal_16bit.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -51,20 +51,20 @@ static unsigned char USBIESave; /******************************************************************** Function: bool USBSleepOnSuspend(void) - + Summary: Places the core into sleep and sets up the USB module to wake up the device on USB activity. - + PreCondition: - + Parameters: None - + Return Values: true - if entered sleep successfully false - if there was an error entering sleep - + Remarks: Please note that before calling this function that it is the responsibility of the application to place all of the other @@ -117,7 +117,7 @@ bool USBSleepOnSuspend(void) if(USBRESUMEIF == 0) { //We woke up by some means other than resume from the host. Figure out what that source was. - + //Check the VBUS level. If VBUS is no longer present, then a user detach event //must have occurred, or, the cable is still plugged in, but the host itself //powered down. @@ -138,7 +138,7 @@ bool USBSleepOnSuspend(void) //Try to wake up the host. USBRemoteWakeupAssertBlocking(); } - #endif + #endif } @@ -147,7 +147,7 @@ bool USBSleepOnSuspend(void) //to their exact same USB state/operating condition after the end of suspend, //as they were in prior to entering suspend. USBRestorePreviousInterruptSettings(); - + return true; } @@ -358,12 +358,12 @@ int8_t USBVBUSSessionValidStateGet(bool AllowInvasiveReads) //Restore normal USB interrupt settings. USBRestoreUSBInterrupts(); - + return retValue; } else { - //Couldn't read the value... Module is not in a state where the + //Couldn't read the value... Module is not in a state where the //value can be meaningful, and the caller didn't allow us to make //module setting changes. diff --git a/src/usb_hal_32bit.c b/src/usb_hal_32bit.c index eb37416..bd2279a 100644 --- a/src/usb_hal_32bit.c +++ b/src/usb_hal_32bit.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -52,20 +52,20 @@ static unsigned char USBIESave; /******************************************************************** Function: bool USBSleepOnSuspend(void) - + Summary: Places the core into sleep and sets up the USB module to wake up the device on USB activity. - + PreCondition: - + Parameters: None - + Return Values: true - if entered sleep successfully false - if there was an error entering sleep - + Remarks: Please note that before calling this function that it is the responsibility of the application to place all of the other @@ -124,7 +124,7 @@ bool USBSleepOnSuspend(void) //either due to the USB host sending resume signaling, or, it could be due //to VBUS falling below the SESSVD threshold, due to either a USB detach event, //or the host powering itself down fully (and thereby turning off the +5V VBUS supply). - + //Check the VBUS level. If VBUS is no longer present, then a user detach event //must have occurred, or, the cable is still plugged in, but the host itself //powered down. @@ -134,11 +134,11 @@ bool USBSleepOnSuspend(void) //continue executing code in this case, or, go back to sleep until //the next re-attachment event. - - //Uncomment below break statement, if you want to continue executing + + //Uncomment below break statement, if you want to continue executing //code during the detached interval. //break; - + //If the user left the above break statement commented, then //just clear the prior wake up event and go back to sleep. USBClearInterruptFlag(USBActivityIFReg, USBActivityIFBitNum); @@ -165,17 +165,17 @@ bool USBSleepOnSuspend(void) { //Clear the wakeup source interrupt status flag, since we are now consuming/processing it. YOUR_REMOTE_WAKEUP_TRIGGER_SOURCE_FLAG = 0; //Replace with real code (ex: IFS0CLR = _IFS0_CNAIF_MASK;, etc.) - + //Try to wake up the host. if(USBRemoteWakeupAssertBlocking() == true) { //It was legal to send remote wakeup signaling, and it was sent. //Exit the while(1) loop, so we stay out of sleep. - break; + break; } - + } - #endif + #endif } } @@ -185,7 +185,7 @@ bool USBSleepOnSuspend(void) //to their exact same USB state/operating condition after the end of suspend, //as they were in prior to entering suspend. USBRestorePreviousInterruptSettings(); - + return true; } @@ -396,12 +396,12 @@ int8_t USBVBUSSessionValidStateGet(bool AllowInvasiveReads) //Restore normal USB interrupt settings. USBRestoreUSBInterrupts(); - + return retValue; } else { - //Couldn't read the value... Module is not in a state where the + //Couldn't read the value... Module is not in a state where the //value can be meaningful, and the caller didn't allow us to make //module setting changes. @@ -457,7 +457,7 @@ Return Values: void USBMaskAllUSBInterrupts(void) { unsigned int tempInterruptStatus; - + //Save and clear the USBIE bit to prevent USB interrupt vectoring. tempInterruptStatus = __builtin_get_isr_state(); __builtin_disable_interrupts(); //Disable all interrupts to make sure the USB interrupt enable state doesn't change in an interrupt handler @@ -546,16 +546,16 @@ static void USBSaveAndPrepareInterruptsForSleep(void) unsigned int i; volatile unsigned int* pRegister; - - //Save status and then disable all (maskable) interrupts + + //Save status and then disable all (maskable) interrupts CPUIPLSave = __builtin_get_isr_state(); //Save the current interrupt enable and CPU IPL state info __builtin_disable_interrupts(); //Disable all maskable interrupts - - //Set CPU priority level to 0, so that it can be woken up by a new USB interrupt + + //Set CPU priority level to 0, so that it can be woken up by a new USB interrupt //(at IPL = 4, which is higher than the CPU priority) but without going to the interrupt vector location. //Note: If the USB stack is operated in USB_INTERRUPT mode, then the current //CPU IPL may currently be 4, since this code is already operating within the interrupt context - //of the USB interrupt (ex: IDLEIF asserted, causing the USB stack to call + //of the USB interrupt (ex: IDLEIF asserted, causing the USB stack to call //the user suspend handler, which then called the USBSleepOnSuspend() handler, //which then called this function). In this case, we need to lower the CPU priority //level to < USB IPL, so that the CPU can wake back up from sleep. diff --git a/src/usb_hal_dspic33e.c b/src/usb_hal_dspic33e.c index b8c1536..64adb96 100644 --- a/src/usb_hal_dspic33e.c +++ b/src/usb_hal_dspic33e.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -29,21 +29,21 @@ please contact mla_licensing@microchip.com /******************************************************************** Function: bool USBSleepOnSuspend(void) - + Summary: Places the core into sleep and sets up the USB module to wake up the device on USB activity. - + PreCondition: IPL (in the SR register) must be non-zero. - + Parameters: None - + Return Values: true - if entered sleep successfully false - if there was an error entering sleep - + Remarks: Please note that before calling this function that it is the responsibility of the application to place all of the other @@ -58,7 +58,7 @@ bool USBSleepOnSuspend(void) #if defined(USB_POLLING) //If IPL is equal to 0 then there is no way for the USB module to - // generate an interrupt to wake up the device. + // generate an interrupt to wake up the device. if(_IPL == 0) { return false; @@ -67,7 +67,7 @@ bool USBSleepOnSuspend(void) //Set the interrupt priority to a level that will wake up the part (>0) // but will not cause a interrupt vector jump (USB1IP<=IPL) _USB1IP = 1; - #endif + #endif //Save the old interrupt and CPU settings U1EIE_save = U1EIE; @@ -78,7 +78,7 @@ bool USBSleepOnSuspend(void) //Disable all USB interrupts U1EIE = 0; U1IE = 0; - U1OTGIE = 0; + U1OTGIE = 0; //Enable the interrupt IFS5bits.USB1IF = 0; @@ -91,7 +91,7 @@ bool USBSleepOnSuspend(void) #if defined(USB_POLLING) //Disable the interrupt _USB1IP = 0; - #endif + #endif //restore the previous interrupt settings IEC5bits.USB1IE = USB1IE_save; diff --git a/src/usb_hal_local.h b/src/usb_hal_local.h index 4c01b25..7d73164 100644 --- a/src/usb_hal_local.h +++ b/src/usb_hal_local.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -31,7 +31,7 @@ please contact mla_licensing@microchip.com #include #endif #elif defined (__PIC32MX__) || defined (__PIC32MM__) - #include + #include #else #error "Error! Unsupported processor" #endif diff --git a/src/usb_hal_pic24.c b/src/usb_hal_pic24.c index 169da6c..7a7f258 100644 --- a/src/usb_hal_pic24.c +++ b/src/usb_hal_pic24.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -31,21 +31,21 @@ please contact mla_licensing@microchip.com /******************************************************************** Function: bool USBSleepOnSuspend(void) - + Summary: Places the PIC24F core into sleep and sets up the USB module to wake up the device on USB activity. - + PreCondition: IPL (in the SR register) must be non-zero. - + Parameters: None - + Return Values: true - if entered sleep successfully false - if there was an error entering sleep - + Remarks: Please note that before calling this function that it is the responsibility of the application to place all of the other @@ -60,7 +60,7 @@ bool USBSleepOnSuspend(void) #if defined(USB_POLLING) //If IPL is equal to 0 then there is no way for the USB module to - // generate an interrupt to wake up the device. + // generate an interrupt to wake up the device. if(_IPL == 0) { return false; @@ -69,7 +69,7 @@ bool USBSleepOnSuspend(void) //Set the interrupt priority to a level that will wake up the part (>0) // but will not cause a interrupt vector jump (USB1IP<=IPL) _USB1IP = 1; - #endif + #endif //Save the old interrupt and CPU settings U1EIE_save = U1EIE; @@ -80,7 +80,7 @@ bool USBSleepOnSuspend(void) //Disable all USB interrupts U1EIE = 0; U1IE = 0; - U1OTGIE = 0; + U1OTGIE = 0; //Enable the interrupt IFS5bits.USB1IF = 0; @@ -93,7 +93,7 @@ bool USBSleepOnSuspend(void) #if defined(USB_POLLING) //Disable the interrupt _USB1IP = 0; - #endif + #endif //restore the previous interrupt settings IEC5bits.USB1IE = USB1IE_save; diff --git a/src/usb_hal_pic24e.c b/src/usb_hal_pic24e.c index 7ad4eb9..c393a87 100644 --- a/src/usb_hal_pic24e.c +++ b/src/usb_hal_pic24e.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -28,21 +28,21 @@ please contact mla_licensing@microchip.com /******************************************************************** Function: BOOL USBSleepOnSuspend(void) - + Summary: Places the PIC24F core into sleep and sets up the USB module to wake up the device on USB activity. - + PreCondition: IPL (in the SR register) must be non-zero. - + Parameters: None - + Return Values: TRUE - if entered sleep successfully FALSE - if there was an error entering sleep - + Remarks: Please note that before calling this function that it is the responsibility of the application to place all of the other @@ -57,7 +57,7 @@ BOOL USBSleepOnSuspend(void) #if defined(USB_POLLING) //If IPL is equal to 0 then there is no way for the USB module to - // generate an interrupt to wake up the device. + // generate an interrupt to wake up the device. if(_IPL == 0) { return FALSE; @@ -66,7 +66,7 @@ BOOL USBSleepOnSuspend(void) //Set the interrupt priority to a level that will wake up the part (>0) // but will not cause a interrupt vector jump (USB1IP<=IPL) _USB1IP = 1; - #endif + #endif //Save the old interrupt and CPU settings U1EIE_save = U1EIE; @@ -77,7 +77,7 @@ BOOL USBSleepOnSuspend(void) //Disable all USB interrupts U1EIE = 0; U1IE = 0; - U1OTGIE = 0; + U1OTGIE = 0; //Enable the interrupt IFS5bits.USB1IF = 0; @@ -90,7 +90,7 @@ BOOL USBSleepOnSuspend(void) #if defined(USB_POLLING) //Disable the interrupt _USB1IP = 0; - #endif + #endif //restore the previous interrupt settings IEC5bits.USB1IE = USB1IE_save; diff --git a/src/usb_hal_pic24f.c b/src/usb_hal_pic24f.c index 9c0df7d..dddf330 100644 --- a/src/usb_hal_pic24f.c +++ b/src/usb_hal_pic24f.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -27,7 +27,7 @@ please contact mla_licensing@microchip.com 2.7 Created USBSleepOnSuspend() function to simply process of putting the PIC24F device in the correct state before issuing the sleep instruction and returning the device to the correct state after - exiting sleep. + exiting sleep. ********************************************************************/ //DOM-IGNORE-END @@ -43,21 +43,21 @@ please contact mla_licensing@microchip.com /******************************************************************** Function: BOOL USBSleepOnSuspend(void) - + Summary: Places the PIC24F core into sleep and sets up the USB module to wake up the device on USB activity. - + PreCondition: IPL (in the SR register) must be non-zero. - + Parameters: None - + Return Values: TRUE - if entered sleep successfully FALSE - if there was an error entering sleep - + Remarks: Please note that before calling this function that it is the responsibility of the application to place all of the other @@ -72,7 +72,7 @@ BOOL USBSleepOnSuspend(void) #if defined(USB_POLLING) //If IPL is equal to 0 then there is no way for the USB module to - // generate an interrupt to wake up the device. + // generate an interrupt to wake up the device. if(_IPL == 0) { return FALSE; @@ -81,7 +81,7 @@ BOOL USBSleepOnSuspend(void) //Set the interrupt priority to a level that will wake up the part (>0) // but will not cause a interrupt vector jump (USB1IP<=IPL) _USB1IP = 1; - #endif + #endif //Save the old interrupt and CPU settings U1EIE_save = U1EIE; @@ -92,7 +92,7 @@ BOOL USBSleepOnSuspend(void) //Disable all USB interrupts U1EIE = 0; U1IE = 0; - U1OTGIE = 0; + U1OTGIE = 0; //Enable the interrupt IFS5bits.USB1IF = 0; @@ -105,7 +105,7 @@ BOOL USBSleepOnSuspend(void) #if defined(USB_POLLING) //Disable the interrupt _USB1IP = 0; - #endif + #endif //restore the previous interrupt settings IEC5bits.USB1IE = USB1IE_save; diff --git a/src/usb_host.c b/src/usb_host.c index 0833bc3..b4cb800 100644 --- a/src/usb_host.c +++ b/src/usb_host.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -307,14 +307,14 @@ uint8_t USBHostDeviceStatus( uint8_t deviceAddress ) return usbDeviceInfo.errorCode; } - - if ((usbHostState > STATE_ATTACHED) && + + if ((usbHostState > STATE_ATTACHED) && (usbHostState < STATE_RUNNING) ) { return USB_DEVICE_ENUMERATING; } - + return USB_HOLDING_UNSUPPORTED_DEVICE; } @@ -388,9 +388,9 @@ bool USBHostInit( unsigned long flags ) /**************************************************************************** Function: - bool USBHostIsochronousBuffersCreate( ISOCHRONOUS_DATA * isocData, + bool USBHostIsochronousBuffersCreate( ISOCHRONOUS_DATA * isocData, uint8_t numberOfBuffers, uint16_t bufferSize ) - + Description: This function initializes the isochronous data buffer information and allocates memory for each buffer. This function will not allocate memory @@ -404,7 +404,7 @@ bool USBHostInit( unsigned long flags ) Return Values: true - All buffers are allocated successfully. - false - Not enough heap space to allocate all buffers - adjust the + false - Not enough heap space to allocate all buffers - adjust the project to provide more heap space. Remarks: @@ -447,7 +447,7 @@ bool USBHostIsochronousBuffersCreate( ISOCHRONOUS_DATA * isocData, uint8_t numbe /**************************************************************************** Function: void USBHostIsochronousBuffersDestroy( ISOCHRONOUS_DATA * isocData, uint8_t numberOfBuffers ) - + Description: This function releases all of the memory allocated for the isochronous data buffers. It also resets all other information about the buffers. @@ -486,9 +486,9 @@ void USBHostIsochronousBuffersDestroy( ISOCHRONOUS_DATA * isocData, uint8_t numb /**************************************************************************** Function: void USBHostIsochronousBuffersReset( ISOCHRONOUS_DATA * isocData, uint8_t numberOfBuffers ) - + Description: - This function resets all the isochronous data buffers. It does not do + This function resets all the isochronous data buffers. It does not do anything with the space allocated for the buffers. Precondition: @@ -1118,7 +1118,7 @@ void USBHostShutdown( void ) &powerRequest, sizeof(USB_VBUS_POWER_EVENT_DATA) ); - + _USB_NotifyClients( usbDeviceInfo.deviceAddress, EVENT_DETACH, &usbDeviceInfo.deviceAddress, @@ -1333,7 +1333,7 @@ void USBHostTasks( void ) usbDeviceInfo.flags.val = 0; usbDeviceInfo.pInterfaceList = NULL; usbBusInfo.flags.val = 0; - + // Set up the hardware. U1IE = 0; // Clear and turn off interrupts. U1IR = 0xFF; @@ -1414,7 +1414,7 @@ void USBHostTasks( void ) #else #error "The selected PIC32 device is not currently supported by usb_host.c." #endif - _SetUSBIE(); + _SetUSBIE(); #else #error Cannot enable USB interrupt. #endif @@ -2890,11 +2890,11 @@ bool _USB_FindClassDriver( uint8_t bClass, uint8_t bSubClass, uint8_t bProtocol, // Make sure the application layer does not have a problem with the selection. // If the application layer returns false, which it should if the event is not // defined, then accept the selection. - eventData.idVendor = pDesc->idVendor; - eventData.idProduct = pDesc->idProduct; - eventData.bDeviceClass = bClass; - eventData.bDeviceSubClass = bSubClass; - eventData.bDeviceProtocol = bProtocol; + eventData.idVendor = pDesc->idVendor; + eventData.idProduct = pDesc->idProduct; + eventData.bDeviceClass = bClass; + eventData.bDeviceSubClass = bSubClass; + eventData.bDeviceProtocol = bProtocol; if (!USB_HOST_APP_EVENT_HANDLER( USB_ROOT_HUB, EVENT_OVERRIDE_CLIENT_DRIVER_SELECTION, &eventData, sizeof(USB_OVERRIDE_CLIENT_DRIVER_EVENT_DATA) )) @@ -2906,7 +2906,7 @@ bool _USB_FindClassDriver( uint8_t bClass, uint8_t bSubClass, uint8_t bProtocol, #endif return true; - } + } } i++; } @@ -3002,16 +3002,16 @@ bool _USB_FindDeviceLevelClientDriver( void ) (usbTPL[i].device.idProduct == 0xFFFF)) { USB_OVERRIDE_CLIENT_DRIVER_EVENT_DATA eventData; - + // Make sure the application layer does not have a problem with the selection. // If the application layer returns false, which it should if the event is not // defined, then accept the selection. - eventData.idVendor = pDesc->idVendor; - eventData.idProduct = pDesc->idProduct; - eventData.bDeviceClass = usbTPL[i].device.bClass; - eventData.bDeviceSubClass = usbTPL[i].device.bSubClass; - eventData.bDeviceProtocol = usbTPL[i].device.bProtocol; - + eventData.idVendor = pDesc->idVendor; + eventData.idProduct = pDesc->idProduct; + eventData.bDeviceClass = usbTPL[i].device.bClass; + eventData.bDeviceSubClass = usbTPL[i].device.bSubClass; + eventData.bDeviceProtocol = usbTPL[i].device.bProtocol; + if (!USB_HOST_APP_EVENT_HANDLER( USB_ROOT_HUB, EVENT_OVERRIDE_CLIENT_DRIVER_SELECTION, &eventData, sizeof(USB_OVERRIDE_CLIENT_DRIVER_EVENT_DATA) )) { @@ -3021,7 +3021,7 @@ bool _USB_FindDeviceLevelClientDriver( void ) usbDeviceInfo.flags.bfUseDeviceClientDriver = 1; } - } + } #endif } @@ -3098,7 +3098,7 @@ USB_ENDPOINT_INFO * _USB_FindEndpoint( uint8_t endpoint ) pEndpoint = pEndpoint->next; } } - + // Go to the next interface. pInterface = pInterface->next; } @@ -3498,7 +3498,7 @@ void _USB_FindNextToken( void ) switch (pCurrentEndpoint->transferState & TSUBSTATE_MASK) { case TSUBSTATE_ISOCHRONOUS_READ_DATA: - // Don't overwrite data the user has not yet processed. We will skip this interval. + // Don't overwrite data the user has not yet processed. We will skip this interval. if (((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].bfDataLengthValid) { // We have buffer overflow. @@ -3513,7 +3513,7 @@ void _USB_FindNextToken( void ) _USB_SetBDT( USB_TOKEN_IN ); _USB_SendToken( pCurrentEndpoint->bEndpointAddress, USB_TOKEN_IN ); return; - } + } break; case TSUBSTATE_ISOCHRONOUS_READ_COMPLETE: @@ -3545,7 +3545,7 @@ void _USB_FindNextToken( void ) pCurrentEndpoint->bmAttributes.val = USB_EVENT_QUEUE_FULL; } #endif - + // 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 @@ -3555,7 +3555,7 @@ void _USB_FindNextToken( void ) } ((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].bfDataLengthValid = 0; #endif - + // Move to the next data buffer. ((ISOCHRONOUS_DATA *)pCurrentEndpoint->pUserData)->currentBufferUSB++; if (((ISOCHRONOUS_DATA *)pCurrentEndpoint->pUserData)->currentBufferUSB >= ((ISOCHRONOUS_DATA *)pCurrentEndpoint->pUserData)->totalBuffers) @@ -3612,7 +3612,7 @@ void _USB_FindNextToken( void ) _USB_SetBDT( USB_TOKEN_OUT ); _USB_SendToken( pCurrentEndpoint->bEndpointAddress, USB_TOKEN_OUT ); return; - } + } break; case TSUBSTATE_ISOCHRONOUS_WRITE_COMPLETE: @@ -3652,14 +3652,14 @@ void _USB_FindNextToken( void ) 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. ((ISOCHRONOUS_DATA *)pCurrentEndpoint->pUserData)->currentBufferUSB++; if (((ISOCHRONOUS_DATA *)pCurrentEndpoint->pUserData)->currentBufferUSB >= ((ISOCHRONOUS_DATA *)pCurrentEndpoint->pUserData)->totalBuffers) { ((ISOCHRONOUS_DATA *)pCurrentEndpoint->pUserData)->currentBufferUSB = 0; } - ((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].bfDataLengthValid = 1; + ((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->buffers[((ISOCHRONOUS_DATA *)(pCurrentEndpoint->pUserData))->currentBufferUSB].bfDataLengthValid = 1; break; case TSUBSTATE_ERROR: @@ -4870,8 +4870,8 @@ bool _USB_ParseConfigurationDescriptor( void ) if ((newInterfaceInfo = (USB_INTERFACE_INFO *)USB_MALLOC( sizeof(USB_INTERFACE_INFO) )) == NULL) { // Out of memory - error = true; - + error = true; + } if(error == false) @@ -4881,7 +4881,7 @@ bool _USB_ParseConfigurationDescriptor( void ) newInterfaceInfo->clientDriver = ClientDriver; newInterfaceInfo->pInterfaceSettings = NULL; newInterfaceInfo->pCurrentSetting = NULL; - + // Insert it into the list. newInterfaceInfo->next = pTempInterfaceList; pTempInterfaceList = newInterfaceInfo; @@ -4894,11 +4894,11 @@ bool _USB_ParseConfigurationDescriptor( void ) if ((newSettingInfo = (USB_INTERFACE_SETTING_INFO *)USB_MALLOC( sizeof(USB_INTERFACE_SETTING_INFO) )) == NULL) { // Out of memory - error = true; + error = true; } - } - - if (!error) + } + + if (!error) { newSettingInfo->next = newInterfaceInfo->pInterfaceSettings; newSettingInfo->interfaceAltSetting = bAlternateSetting; @@ -4932,7 +4932,7 @@ bool _USB_ParseConfigurationDescriptor( void ) if ((newEndpointInfo = (USB_ENDPOINT_INFO *)USB_MALLOC( sizeof(USB_ENDPOINT_INFO) )) == NULL) { // Out of memory - error = true; + error = true; } newEndpointInfo->bEndpointAddress = *ptr++; newEndpointInfo->bmAttributes.val = *ptr++; @@ -4976,7 +4976,7 @@ bool _USB_ParseConfigurationDescriptor( void ) ptr = &pCurrentConfigurationDescriptor[index]; } } - } + } // Ensure that we found all the endpoints for this interface. if (currentEndpoint != bNumEndpoints) @@ -5012,33 +5012,33 @@ bool _USB_ParseConfigurationDescriptor( void ) { newInterfaceInfo = pTempInterfaceList; pTempInterfaceList = pTempInterfaceList->next; - + while (newInterfaceInfo->pInterfaceSettings != NULL) { newSettingInfo = newInterfaceInfo->pInterfaceSettings; newInterfaceInfo->pInterfaceSettings = newInterfaceInfo->pInterfaceSettings->next; - + while (newSettingInfo->pEndpointList != NULL) { newEndpointInfo = newSettingInfo->pEndpointList; newSettingInfo->pEndpointList = newSettingInfo->pEndpointList->next; - + USB_FREE_AND_CLEAR( newEndpointInfo ); - } - + } + USB_FREE_AND_CLEAR( newSettingInfo ); } - + USB_FREE_AND_CLEAR( newInterfaceInfo ); - } + } return false; } else - { + { // Set configuration. usbDeviceInfo.currentConfiguration = currentConfiguration; usbDeviceInfo.currentConfigurationPower = bMaxPower; - + // Success! #if defined (DEBUG_ENABLE) DEBUG_PutString( "HOST: Parse Descriptor success\r\n" ); @@ -5046,7 +5046,7 @@ bool _USB_ParseConfigurationDescriptor( void ) usbDeviceInfo.pInterfaceList = pTempInterfaceList; return true; - } + } } @@ -5483,7 +5483,7 @@ void USB_HostInterruptHandler(void) // Turn off the timer interrupt. U1OTGIEbits.T1MSECIE = 0; #endif - + if((usbHostState & STATE_MASK) != STATE_DETACHED) { // Advance to the next state. We can do this here, because the only time @@ -5756,7 +5756,7 @@ void USB_HostInterruptHandler(void) else if ((pBDT->STAT.PID == PID_DATA0) || (pBDT->STAT.PID == PID_DATA1)) { // We will only get these PID's from an IN packet. - + // Update the count of bytes tranferred. (If there was an error, this count will be 0.) // The Byte Count is NOT 0 if a NAK occurs. Therefore, we can only update the // count when an ACK, DATA0, or DATA1 is received. @@ -5940,15 +5940,15 @@ void USB_HostInterruptHandler(void) pEndpoint->wIntervalCount--; } } - + #ifndef ALLOW_MULTIPLE_NAKS_PER_FRAME pEndpoint->status.bfLastTransferNAKd = 0; #endif - + pEndpoint = pEndpoint->next; } } - + pInterface = pInterface->next; } diff --git a/src/usb_host_android.c b/src/usb_host_android.c index a7414f6..f2b4e41 100644 --- a/src/usb_host_android.c +++ b/src/usb_host_android.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -52,11 +52,11 @@ typedef enum _ANDROID_ACCESSORY_STRINGS #define USB_INTERFACE_DESC_BINTERFACEPROTOCOL_OFFSET 7 #define USB_CDC_DESC_BDESCRIPTORSUBTYPE_OFFSET 2 -#define USB_CDC_DESC_UNION_BMASTERINTERFACE_OFFSET 3 +#define USB_CDC_DESC_UNION_BMASTERINTERFACE_OFFSET 3 -#define USB_ENDPOINT_DESC_BENDPOINTADDRESS_OFFSET 2 -#define USB_ENDPOINT_DESC_BMATTRIBUTES_OFFSET 3 -#define USB_ENDPOINT_DESC_WMAXPACKETSIZE_OFFSET 4 +#define USB_ENDPOINT_DESC_BENDPOINTADDRESS_OFFSET 2 +#define USB_ENDPOINT_DESC_BMATTRIBUTES_OFFSET 3 +#define USB_ENDPOINT_DESC_WMAXPACKETSIZE_OFFSET 4 #define USB_ENDPOINT_DESC_BINTERVAL_OFFSET 5 #define ANDROID_ACCESSORY_GET_PROTOCOL 51 @@ -170,7 +170,7 @@ static uint8_t AndroidCommandGetProtocol(ANDROID_DEVICE_DATA* device, uint16_t * Initializes the Android protocol version 1 sub-driver Description: - Initializes the Android protocol version 1 sub-driver + Initializes the Android protocol version 1 sub-driver Precondition: None @@ -245,7 +245,7 @@ uint8_t AndroidAppWrite(void* handle, uint8_t* data, uint32_t size) if(device->state < READY) { return USB_INVALID_STATE; - } + } if(device->status.TXBusy == 1) { @@ -254,7 +254,7 @@ uint8_t AndroidAppWrite(void* handle, uint8_t* data, uint32_t size) errorCode = USBHostWrite( device->address, ANDROID_GetOUTEndpointNum(device), data, size ); - + switch(errorCode) { case USB_ENDPOINT_BUSY: @@ -277,8 +277,8 @@ uint8_t AndroidAppWrite(void* handle, uint8_t* data, uint32_t size) Check to see if the last write to the Android device was completed Description: - Check to see if the last write to the Android device was completed. If - complete, returns the amount of data that was sent and the corresponding + Check to see if the last write to the Android device was completed. If + complete, returns the amount of data that was sent and the corresponding error code for the transmission. Precondition: @@ -325,11 +325,11 @@ bool AndroidAppIsWriteComplete(void* handle, uint8_t* errorCode, uint32_t* size) if(device->state < READY) { return USB_INVALID_STATE; - } + } //If there was a transfer pending, then get the state of the transfer if(USBHostTransferIsComplete( - device->address, + device->address, ANDROID_GetOUTEndpointNum(device), errorCode, size @@ -352,7 +352,7 @@ bool AndroidAppIsWriteComplete(void* handle, uint8_t* errorCode, uint32_t* size) Description: Attempts to read information from the specified Android device. This - function does not block. Data availability is checked via the + function does not block. Data availability is checked via the AndroidAppIsReadComplete() function. Precondition: @@ -400,7 +400,7 @@ uint8_t AndroidAppRead(void* handle, uint8_t* data, uint32_t size) if(device->state < READY) { return USB_INVALID_STATE; - } + } if(device->status.RXBusy == 1) { @@ -414,7 +414,7 @@ uint8_t AndroidAppRead(void* handle, uint8_t* data, uint32_t size) errorCode = USBHostRead( device->address, ANDROID_GetINEndpointNum(device), data, ((size / device->INEndpointSize) * device->INEndpointSize) ); - + switch(errorCode) { case USB_SUCCESS: @@ -438,8 +438,8 @@ uint8_t AndroidAppRead(void* handle, uint8_t* data, uint32_t size) Check to see if the last read to the Android device was completed Description: - Check to see if the last read to the Android device was completed. If - complete, returns the amount of data that was sent and the corresponding + Check to see if the last read to the Android device was completed. If + complete, returns the amount of data that was sent and the corresponding error code for the transmission. Precondition: @@ -486,11 +486,11 @@ bool AndroidAppIsReadComplete(void* handle, uint8_t* errorCode, uint32_t* size) if(device->state < READY) { return USB_INVALID_STATE; - } + } //If there was a transfer pending, then get the state of the transfer if(USBHostTransferIsComplete( - device->address, + device->address, ANDROID_GetINEndpointNum(device), errorCode, size @@ -556,7 +556,7 @@ void AndroidTasks(void) { //If not, then let's send the manufacturer's string AndroidCommandGetProtocol(device, &device->protocol); - + device->status.EP0TransferPending = 1; device->state = WAIT_FOR_PROTOCOL; } @@ -567,7 +567,7 @@ void AndroidTasks(void) device->state = SEND_MANUFACTUER_STRING; } break; - + case SEND_MANUFACTUER_STRING: if(accessoryInfo->manufacturer == NULL) { @@ -593,7 +593,7 @@ void AndroidTasks(void) device->state = SEND_DESCRIPTION_STRING; break; } - + if(device->status.EP0TransferPending == 0) { //The manufacturing string is sent. Now try to send the model string @@ -602,7 +602,7 @@ void AndroidTasks(void) { //If not, then let's send the manufacturer's string AndroidCommandSendString(device, ANDROID_ACCESSORY_STRING_MODEL, accessoryInfo->model, accessoryInfo->model_size); - + device->status.EP0TransferPending = 1; device->state = SEND_DESCRIPTION_STRING; } @@ -624,7 +624,7 @@ void AndroidTasks(void) { //If not, then let's send the manufacturer's string AndroidCommandSendString(device, ANDROID_ACCESSORY_STRING_DESCRIPTION, accessoryInfo->description, accessoryInfo->description_size); - + device->status.EP0TransferPending = 1; device->state = SEND_VERSION_STRING; } @@ -646,7 +646,7 @@ void AndroidTasks(void) { //If not, then let's send the manufacturer's string AndroidCommandSendString(device, ANDROID_ACCESSORY_STRING_VERSION, accessoryInfo->version, accessoryInfo->version_size); - + device->status.EP0TransferPending = 1; device->state = SEND_URI_STRING; } @@ -668,7 +668,7 @@ void AndroidTasks(void) { //If not, then let's send the manufacturer's string AndroidCommandSendString(device, ANDROID_ACCESSORY_STRING_URI, accessoryInfo->URI, accessoryInfo->URI_size); - + device->status.EP0TransferPending = 1; device->state = SEND_SERIAL_STRING; } @@ -690,7 +690,7 @@ void AndroidTasks(void) { //If not, then let's send the manufacturer's string AndroidCommandSendString(device, ANDROID_ACCESSORY_STRING_SERIAL, accessoryInfo->serial, accessoryInfo->serial_size); - + device->status.EP0TransferPending = 1; device->state = SEND_AUDIO_MODE; } @@ -713,8 +713,8 @@ void AndroidTasks(void) //Set the audio mode USBHostIssueDeviceRequest( device->address, //uint8_t deviceAddress, USB_SETUP_HOST_TO_DEVICE //uint8_t bmRequestType, - | USB_SETUP_TYPE_VENDOR - | USB_SETUP_RECIPIENT_DEVICE, + | USB_SETUP_TYPE_VENDOR + | USB_SETUP_RECIPIENT_DEVICE, ANDROID_ACCESSORY_SET_AUDIO_MODE, //uint8_t bRequest, accessoryInfo->audio_mode, //uint16_t wValue, 0, //uint16_t wIndex, @@ -723,7 +723,7 @@ void AndroidTasks(void) USB_DEVICE_REQUEST_SET, //uint8_t dataDirection, device->clientDriverID //uint8_t clientDriverID ); - + device->status.EP0TransferPending = 1; device->state = START_ACCESSORY; } @@ -743,7 +743,7 @@ void AndroidTasks(void) //If not, then let's send the manufacturer's string AndroidCommandStart(device); - + device->status.EP0TransferPending = 1; device->state = ACCESSORY_STARTING; } @@ -758,7 +758,7 @@ void AndroidTasks(void) device->countDown = ANDROID_DEVICE_ATTACH_TIMEOUT; device->state = WAITING_FOR_ACCESSORY_RETURN; - } + } break; case WAITING_FOR_ACCESSORY_RETURN: @@ -768,8 +768,8 @@ void AndroidTasks(void) //The accessory has returned and has been initialialized. It is now ready to use. device->state = READY; USB_HOST_APP_EVENT_HANDLER(device->address,EVENT_ANDROID_ATTACH,device,sizeof(ANDROID_DEVICE_DATA*)); - break; - + break; + case READY: break; @@ -792,9 +792,9 @@ void AndroidTasks(void) USB_DEVICE_REQUEST_SET, //uint8_t dataDirection, device->clientDriverID //uint8_t clientDriverID ); - + device->status.EP0TransferPending = 1; - + device->state = SENDING_HID_REPORT_DESCRIPTOR; } } @@ -809,8 +809,8 @@ void AndroidTasks(void) //Set the audio mode USBHostIssueDeviceRequest( device->address, //uint8_t deviceAddress, USB_SETUP_HOST_TO_DEVICE //uint8_t bmRequestType, - | USB_SETUP_TYPE_VENDOR - | USB_SETUP_RECIPIENT_DEVICE, + | USB_SETUP_TYPE_VENDOR + | USB_SETUP_RECIPIENT_DEVICE, ANDROID_ACCESSORY_SET_HID_REPORT_DESC, //uint8_t bRequest, device->hid.id, //uint16_t wValue, device->hid.offset, //uint16_t wIndex, @@ -819,7 +819,7 @@ void AndroidTasks(void) USB_DEVICE_REQUEST_SET, //uint8_t dataDirection, device->clientDriverID //uint8_t clientDriverID ); - + device->status.EP0TransferPending = 1; //MCHP: should only make this move if we are completely done... @@ -933,7 +933,7 @@ bool AndroidAppInitialize ( uint8_t address, uint32_t flags, uint8_t clientDrive // the descriptor list config_desc_end = config_descriptor + tempWord; - //Skip past the configuration part of this descriptor to the next + //Skip past the configuration part of this descriptor to the next // descriptor in the configuration descriptor list. The size of the config // part of the descriptor is the first uint8_t of the list. config_descriptor += *config_descriptor; @@ -974,7 +974,7 @@ bool AndroidAppInitialize ( uint8_t address, uint32_t flags, uint8_t clientDrive if((config_descriptor[USB_ENDPOINT_DESC_BENDPOINTADDRESS_OFFSET] & 0x80) == 0x80) { //If this is an IN endpoint, record the endpoint number - device->INEndpointNum = config_descriptor[USB_ENDPOINT_DESC_BENDPOINTADDRESS_OFFSET]; + device->INEndpointNum = config_descriptor[USB_ENDPOINT_DESC_BENDPOINTADDRESS_OFFSET]; //record the endpoint size (2 uint8_ts) device->INEndpointSize = (config_descriptor[USB_ENDPOINT_DESC_WMAXPACKETSIZE_OFFSET]) + (config_descriptor[USB_ENDPOINT_DESC_WMAXPACKETSIZE_OFFSET+1] << 8); @@ -982,7 +982,7 @@ bool AndroidAppInitialize ( uint8_t address, uint32_t flags, uint8_t clientDrive else { //Otherwise this is an OUT endpoint, record the endpoint number - device->OUTEndpointNum = config_descriptor[USB_ENDPOINT_DESC_BENDPOINTADDRESS_OFFSET]; + device->OUTEndpointNum = config_descriptor[USB_ENDPOINT_DESC_BENDPOINTADDRESS_OFFSET]; //record the endpoint size (2 uint8_ts) device->OUTEndpointSize = (config_descriptor[USB_ENDPOINT_DESC_WMAXPACKETSIZE_OFFSET]) + (config_descriptor[USB_ENDPOINT_DESC_WMAXPACKETSIZE_OFFSET+1] << 8); @@ -1054,7 +1054,7 @@ bool AndroidAppDataEventHandler( uint8_t address, USB_EVENT event, void *data, u //Device has timed out. Destroy its info. memset(&devices[i],0x00,sizeof(ANDROID_DEVICE_DATA)); } - + devices[i].countDown--; break; default: @@ -1113,7 +1113,7 @@ bool AndroidAppEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 { if(devices[i].address == address) { - if(devices[i].state == ACCESSORY_STARTING) + if(devices[i].state == ACCESSORY_STARTING) { devices[i].state = WAITING_FOR_ACCESSORY_RETURN; } @@ -1125,7 +1125,7 @@ bool AndroidAppEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 USBHostTerminateTransfer( device->address, device->OUTEndpointNum ); USBHostTerminateTransfer( device->address, device->INEndpointNum ); USB_HOST_APP_EVENT_HANDLER(device->address,EVENT_ANDROID_DETACH,device,sizeof(ANDROID_DEVICE_DATA*)); - + //Device has timed out. Destroy its info. memset(&devices[i],0x00,sizeof(ANDROID_DEVICE_DATA)); } @@ -1156,7 +1156,7 @@ bool AndroidAppEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 //Otherwise, handle the data if(transfer_data->bEndpointAddress == 0x00) { - //If the transfer was EP0, just clear the pending bit and + //If the transfer was EP0, just clear the pending bit and // we will handle the rest in the tasks function so we don't // duplicate state machine changes both here and there device->status.EP0TransferPending = 0; @@ -1167,7 +1167,7 @@ bool AndroidAppEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 USB_HOST_APP_EVENT_HANDLER(device->address, EVENT_ANDROID_HID_SEND_EVENT_COMPLETE, device, sizeof(ANDROID_DEVICE_DATA*)); } } - + return true; case EVENT_RESUME: // Device-mode resume received return true; @@ -1210,7 +1210,7 @@ uint8_t AndroidAppHIDSendEvent(uint8_t address, uint8_t id, uint8_t* report, uin { return USB_UNKNOWN_DEVICE; } - + if(device->status.EP0TransferPending == 0) { //MCHP: should switch this to use the transfer events instead. It is safer. @@ -1242,7 +1242,7 @@ uint8_t AndroidAppHIDSendEvent(uint8_t address, uint8_t id, uint8_t* report, uin } } - return errorCode; + return errorCode; } bool AndroidAppHIDRegister(uint8_t address, uint8_t id, uint8_t* descriptor, uint8_t length) @@ -1264,7 +1264,7 @@ bool AndroidAppHIDRegister(uint8_t address, uint8_t id, uint8_t* descriptor, uin { return USB_UNKNOWN_DEVICE; } - + if(device->state != READY) { return false; @@ -1288,10 +1288,10 @@ bool AndroidAppHIDRegister(uint8_t address, uint8_t id, uint8_t* descriptor, uin static uint8_t AndroidCommandSendString(void *handle, ANDROID_ACCESSORY_STRINGS stringType, const char *string, uint16_t stringLength) Summary: - Sends a command String to the Android device using the EP0 command + Sends a command String to the Android device using the EP0 command Description: - Sends a command String to the Android device using the EP0 command + Sends a command String to the Android device using the EP0 command Precondition: None @@ -1320,8 +1320,8 @@ static uint8_t AndroidCommandSendString(void *handle, ANDROID_ACCESSORY_STRINGS return USBHostIssueDeviceRequest ( device->address, //uint8_t deviceAddress, USB_SETUP_HOST_TO_DEVICE //uint8_t bmRequestType, - | USB_SETUP_TYPE_VENDOR - | USB_SETUP_RECIPIENT_DEVICE, + | USB_SETUP_TYPE_VENDOR + | USB_SETUP_RECIPIENT_DEVICE, ANDROID_ACCESSORY_SEND_STRING, //uint8_t bRequest, 0, //uint16_t wValue, (uint16_t)stringType, //uint16_t wIndex, @@ -1337,7 +1337,7 @@ static uint8_t AndroidCommandSendString(void *handle, ANDROID_ACCESSORY_STRINGS static uint8_t AndroidCommandStart(void *handle) Summary: - Sends a the start command that makes the Android device go into accessory mode + Sends a the start command that makes the Android device go into accessory mode Description: Sends a the start command that makes the Android device go into accessory mode @@ -1366,8 +1366,8 @@ static uint8_t AndroidCommandStart(void *handle) return USBHostIssueDeviceRequest ( device->address, //uint8_t deviceAddress, USB_SETUP_HOST_TO_DEVICE //uint8_t bmRequestType, - | USB_SETUP_TYPE_VENDOR - | USB_SETUP_RECIPIENT_DEVICE, + | USB_SETUP_TYPE_VENDOR + | USB_SETUP_RECIPIENT_DEVICE, ANDROID_ACCESSORY_START, //uint8_t bRequest, 0, //uint16_t wValue, 0, //uint16_t wIndex, diff --git a/src/usb_host_android_local.h b/src/usb_host_android_local.h index aaf04be..0f9249a 100644 --- a/src/usb_host_android_local.h +++ b/src/usb_host_android_local.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END diff --git a/src/usb_host_audio_v1.c b/src/usb_host_audio_v1.c index 73c8fe7..7504e4c 100644 --- a/src/usb_host_audio_v1.c +++ b/src/usb_host_audio_v1.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -214,7 +214,7 @@ static USB_AUDIO_DEVICE_INFO deviceInfoAudioV1[USB_MAX_AUDIO_DEVICES] __ This function starts the reception of streaming, isochronous audio data. Precondition: - USBHostAudioV1SetInterfaceFullBandwidth() must be called to set the + USBHostAudioV1SetInterfaceFullBandwidth() must be called to set the device to its full bandwidth interface. Parameters: @@ -233,7 +233,7 @@ static USB_AUDIO_DEVICE_INFO deviceInfoAudioV1[USB_MAX_AUDIO_DEVICES] __ Remarks: Some devices require other operations between setting the full bandwidth - interface and starting the streaming audio data. Therefore, these two + interface and starting the streaming audio data. Therefore, these two functions are broken out separately. ***************************************************************************/ @@ -252,21 +252,21 @@ uint8_t USBHostAudioV1ReceiveAudioData( uint8_t deviceAddress, } // Make sure the device is not already receiving data or setting the interface. - if (!USBHostTransferIsComplete( deviceInfoAudioV1[i].ID.deviceAddress, - deviceInfoAudioV1[i].endpointAudioStream, &errorCode, &byteCount ) || + if (!USBHostTransferIsComplete( deviceInfoAudioV1[i].ID.deviceAddress, + deviceInfoAudioV1[i].endpointAudioStream, &errorCode, &byteCount ) || deviceInfoAudioV1[i].flags.bfSettingInterface) { return USB_AUDIO_DEVICE_BUSY; } // Start receiving data - errorCode = USBHostReadIsochronous( deviceInfoAudioV1[i].ID.deviceAddress, + errorCode = USBHostReadIsochronous( deviceInfoAudioV1[i].ID.deviceAddress, deviceInfoAudioV1[i].endpointAudioStream, pIsochronousData ); if (errorCode) { } - - return errorCode; + + return errorCode; } @@ -314,7 +314,7 @@ uint8_t USBHostAudioV1SetInterfaceFullBandwidth( uint8_t deviceAddress ) } // Make sure the device is not already receiving data. - if (!USBHostTransferIsComplete( deviceInfoAudioV1[i].ID.deviceAddress, + if (!USBHostTransferIsComplete( deviceInfoAudioV1[i].ID.deviceAddress, deviceInfoAudioV1[i].endpointAudioStream, &errorCode, &byteCount ) || deviceInfoAudioV1[i].flags.bfSettingInterface) { @@ -328,12 +328,12 @@ uint8_t USBHostAudioV1SetInterfaceFullBandwidth( uint8_t deviceAddress ) if (errorCode) { } - else + else { deviceInfoAudioV1[i].flags.bfSettingInterface = 1; } - - return errorCode; + + return errorCode; } @@ -342,7 +342,7 @@ uint8_t USBHostAudioV1SetInterfaceFullBandwidth( uint8_t deviceAddress ) uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) Summary: - This function sets the zero bandwidth interface. + This function sets the zero bandwidth interface. Description: This function sets the full bandwidth interface. This function can @@ -360,7 +360,7 @@ uint8_t USBHostAudioV1SetInterfaceFullBandwidth( uint8_t deviceAddress ) USB_SUCCESS - Request started successfully USB_AUDIO_DEVICE_NOT_FOUND - No device with the specified address. Others - See USBHostIssueDeviceRequest() - + Remarks: None ***************************************************************************/ @@ -379,7 +379,7 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) } // Make sure the device is not already receiving data. - if (!USBHostTransferIsComplete( deviceInfoAudioV1[i].ID.deviceAddress, + if (!USBHostTransferIsComplete( deviceInfoAudioV1[i].ID.deviceAddress, deviceInfoAudioV1[i].endpointAudioStream, &errorCode, &byteCount ) || deviceInfoAudioV1[i].flags.bfSettingInterface) { @@ -390,16 +390,16 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) errorCode = USBHostIssueDeviceRequest( deviceInfoAudioV1[i].ID.deviceAddress, 0x01, USB_REQUEST_SET_INTERFACE, deviceInfoAudioV1[i].settingZeroBandwidth, deviceInfoAudioV1[i].interface, 0, NULL, USB_DEVICE_REQUEST_SET, deviceInfoAudioV1[i].ID.clientDriverID ); - + if (errorCode) { } - else + else { deviceInfoAudioV1[i].flags.bfSettingInterface = 1; } - - return errorCode; + + return errorCode; } /**************************************************************************** @@ -410,28 +410,28 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) This function sets the sampling frequency for the device. Description: - This function sets the sampling frequency for the device. If the exact + This function sets the sampling frequency for the device. If the exact frequency is not supported by the device, the device will round it to the closest supported value. - IMPORTANT: If the request is initiated successfully, the frequency value - must remain valid until the EVENT_AUDIO_FREQUENCY_SET event is received. + IMPORTANT: If the request is initiated successfully, the frequency value + must remain valid until the EVENT_AUDIO_FREQUENCY_SET event is received. Therefore, this value cannot be a local (stack) variable. The application - can either use a global variable for this value, or it can use the + can either use a global variable for this value, or it can use the function USBHostAudioV1SupportedFrequencies() to obtain a pointer to the number and list of supported frequencies, and pass a pointer to the desired frequency in this list. - + Precondition: None Parameters: uint8_t deviceAddress - Device address uint8_t *frequency - Pointer to three bytes that specify the desired - sampling frequency. NOTE: If the request is - initiated successfully, this location must - remain valid until the EVENT_AUDIO_FREQUENCY_SET - event is received. + sampling frequency. NOTE: If the request is + initiated successfully, this location must + remain valid until the EVENT_AUDIO_FREQUENCY_SET + event is received. Return Values: USB_SUCCESS - Request started successfully @@ -452,7 +452,7 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) // Continuous sampling, minimum and maximum are specified. uint32_t minFrequency; uint32_t maxFrequency; - + minFrequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); ptr += 3; maxFrequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); @@ -467,9 +467,9 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) } else { - // Discrete sampling frequencies are specified. + // Discrete sampling frequencies are specified. uint32_t frequency; - + while (numFrequencies) { frequency = *ptr + (*(ptr+1) << 8) + (*(ptr+2) << 16); @@ -488,7 +488,7 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) } } - + Remarks: If a global variable is used to old the frequency, it can be declared as a uint32_t. Since PIC Microcontrollers are little endian machines, a @@ -498,14 +498,14 @@ uint8_t USBHostAudioV1SetInterfaceZeroBandwidth( uint8_t deviceAddress ) rc = USBHostAudioV1SetSamplingFrequency( deviceAddress, (uint8_t *)(&desiredFrequency) ); - + ***************************************************************************/ uint8_t USBHostAudioV1SetSamplingFrequency( uint8_t deviceAddress, uint8_t *frequency ) { uint8_t errorCode; uint8_t i; - + // Find the correct device. for (i=0; (i - + Remarks: None ***************************************************************************/ @@ -612,7 +612,7 @@ uint8_t USBHostAudioV1SetSamplingFrequency( uint8_t deviceAddress, uint8_t *freq uint8_t * USBHostAudioV1SupportedFrequencies( uint8_t deviceAddress ) { uint8_t i; - + // Find the correct device. for (i=0; (iidVendor; deviceInfoAudioV1[device].ID.pid = ((USB_DEVICE_DESCRIPTOR *)descriptor)->idProduct; - + // Get ready to parse the configuration descriptor. descriptor = USBHostGetCurrentConfigurationDescriptor( address ); @@ -948,7 +948,7 @@ bool USBHostAudioV1EventHandler( uint8_t address, USB_EVENT event, void *data, u } // The transfer event comes with data of the type HOST_TRANSFER_DATA. - + if (((HOST_TRANSFER_DATA *)data)->bEndpointAddress == 0) { if (deviceInfoAudioV1[i].flags.bfSettingInterface) @@ -956,13 +956,13 @@ bool USBHostAudioV1EventHandler( uint8_t address, USB_EVENT event, void *data, u // Either the full or the zero bandwidth interface has been set. deviceInfoAudioV1[i].flags.bfSettingInterface = 0; USB_HOST_APP_EVENT_HANDLER( i, EVENT_AUDIO_INTERFACE_SET, NULL, ((HOST_TRANSFER_DATA *)data)->bErrorCode ); - } + } if (deviceInfoAudioV1[i].flags.bfSettingFrequency) { // The sampling frequency has been set. deviceInfoAudioV1[i].flags.bfSettingFrequency = 0; USB_HOST_APP_EVENT_HANDLER( i, EVENT_AUDIO_FREQUENCY_SET, data, size ); - } + } } #ifdef USB_ENABLE_ISOC_TRANSFER_EVENT else if (((HOST_TRANSFER_DATA *)data)->bEndpointAddress == deviceInfoAudioV1[i].endpointAudioStream) @@ -970,7 +970,7 @@ bool USBHostAudioV1EventHandler( uint8_t address, USB_EVENT event, void *data, u // If we received streaming audio data, pass the event up to the application. // It's only one more byte of information more than they need (bmAttributes). USB_HOST_APP_EVENT_HANDLER( i, EVENT_AUDIO_RECEIVE_STREAM, data, size ); - } + } #endif break; @@ -982,7 +982,7 @@ bool USBHostAudioV1EventHandler( uint8_t address, USB_EVENT event, void *data, u } // The bus error event comes with data of the type HOST_TRANSFER_DATA. - + if (((HOST_TRANSFER_DATA *)data)->bEndpointAddress == 0) { ((HOST_TRANSFER_DATA *)data)->bErrorCode = USB_AUDIO_COMMAND_FAILED; @@ -991,21 +991,21 @@ bool USBHostAudioV1EventHandler( uint8_t address, USB_EVENT event, void *data, u // The interface could not be set. deviceInfoAudioV1[i].flags.bfSettingInterface = 0; USB_HOST_APP_EVENT_HANDLER( i, EVENT_AUDIO_INTERFACE_SET, NULL, ((HOST_TRANSFER_DATA *)data)->bErrorCode ); - } + } if (deviceInfoAudioV1[i].flags.bfSettingFrequency) { // The sampling frequency could not be set. deviceInfoAudioV1[i].flags.bfSettingFrequency = 0; USB_HOST_APP_EVENT_HANDLER( i, EVENT_AUDIO_FREQUENCY_SET, data, size ); - } + } } else if (((HOST_TRANSFER_DATA *)data)->bEndpointAddress == deviceInfoAudioV1[i].endpointAudioStream) { // Bus error on data stream. USB_HOST_APP_EVENT_HANDLER( i, EVENT_AUDIO_STREAM_RECEIVED, NULL, 0 ); - } + } break; - + case EVENT_SOF: // Start of frame - NOT NEEDED case EVENT_RESUME: // Device-mode resume received case EVENT_SUSPEND: // Device-mode suspend/idle event received diff --git a/src/usb_host_cdc.c b/src/usb_host_cdc.c index 554f21b..0d4cc36 100644 --- a/src/usb_host_cdc.c +++ b/src/usb_host_cdc.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -86,13 +86,13 @@ Currently this must be set to 1, due to limitations in the USB Host layer. #define STATE_MASK 0x00F0 // #define SUBSTATE_MASK 0x000F // - + #define NEXT_STATE 0x0010 // #define NEXT_SUBSTATE 0x0001 // #define STATE_DETACHED 0x0000 // - + #define STATE_INITIALIZE_DEVICE 0x0010 // #define SUBSTATE_WAIT_FOR_ENUMERATION 0x0000 // #define SUBSTATE_DEVICE_ENUMERATED 0x0001 // @@ -115,7 +115,7 @@ Currently this must be set to 1, due to limitations in the USB Host layer. #define SUBSTATE_SEND_RESET 0x0000 // #define SUBSTATE_WAIT_FOR_RESET 0x0001 // #define SUBSTATE_RESET_COMPLETE 0x0002 // - + #define STATE_HOLDING 0x0040 // @@ -145,23 +145,23 @@ Currently this must be set to 1, due to limitations in the USB Host layer. // ***************************************************************************** #define USB_CDC_RESET (0xFF) // Device Request code to reset the device. -#define MARK_RESET_RECOVERY (0x0E) // +#define MARK_RESET_RECOVERY (0x0E) // // Default values for RS232 configuration data -#ifndef USB_CDC_BAUDRATE_SUPPORTED +#ifndef USB_CDC_BAUDRATE_SUPPORTED #define USB_CDC_BAUDRATE_SUPPORTED 19200UL // default BAUDRATE for the device #endif -#ifndef USB_CDC_PARITY_TYPE +#ifndef USB_CDC_PARITY_TYPE #define USB_CDC_PARITY_TYPE 0 // default Parity type #endif -#ifndef USB_CDC_STOP_BITS +#ifndef USB_CDC_STOP_BITS #define USB_CDC_STOP_BITS 0 // default Stop bits #endif -#ifndef USB_CDC_NO_OF_DATA_BITS +#ifndef USB_CDC_NO_OF_DATA_BITS #define USB_CDC_NO_OF_DATA_BITS 8 // default value of data width #endif @@ -285,8 +285,8 @@ bool USBHostCDCInitAddress( uint8_t address, uint32_t flags, uint8_t clientDrive { // We can currently only handle one device. return false; - } -} + } +} // ***************************************************************************** @@ -314,10 +314,10 @@ bool USBHostCDCInitAddress( uint8_t address, uint32_t flags, uint8_t clientDrive device is not an CDC USB_CDC_INITIALIZING - CDC is attached and in the process of initializing - USB_PROCESSING_REPORT_DESCRIPTOR - CDC device is detected and report + USB_PROCESSING_REPORT_DESCRIPTOR - CDC device is detected and report descriptor is being parsed - USB_CDC_NORMAL_RUNNING - CDC Device is running normal, - ready to send and receive reports + USB_CDC_NORMAL_RUNNING - CDC Device is running normal, + ready to send and receive reports USB_CDC_DEVICE_HOLDING - CDC device could not recover from the error USB_CDC_DEVICE_DETACHED - CDC detached. @@ -335,7 +335,7 @@ uint8_t USBHostCDCDeviceStatus( uint8_t deviceAddress ) { return USB_CDC_DEVICE_NOT_FOUND; } - + status = USBHostDeviceStatus( deviceAddress ); if (status != USB_DEVICE_ATTACHED) { @@ -343,7 +343,7 @@ uint8_t USBHostCDCDeviceStatus( uint8_t deviceAddress ) } else { - // The device is attached and done enumerating. We can get more specific now. + // The device is attached and done enumerating. We can get more specific now. #ifndef USB_ENABLE_TRANSFER_EVENT switch (deviceInfoCDC[i].state & STATE_MASK) { @@ -361,9 +361,9 @@ uint8_t USBHostCDCDeviceStatus( uint8_t deviceAddress ) case STATE_CDC_RESET_RECOVERY: return USB_CDC_RESETTING_DEVICE; break; - - default: - return USB_CDC_DEVICE_DETACHED; + + default: + return USB_CDC_DEVICE_DETACHED; break; } #else @@ -382,20 +382,20 @@ uint8_t USBHostCDCDeviceStatus( uint8_t deviceAddress ) case STATE_HOLDING: return USB_CDC_DEVICE_HOLDING; break; - + case STATE_WAIT_FOR_RESET: case STATE_RESET_COMPLETE: return USB_CDC_RESETTING_DEVICE; break; - default: - return USB_CDC_DEVICE_DETACHED; + default: + return USB_CDC_DEVICE_DETACHED; break; } #endif - } + } } - + /******************************************************************************* Function: uint8_t USBHostCDCResetDevice( uint8_t deviceAddress ) @@ -453,7 +453,7 @@ uint8_t USBHostCDCResetDevice( uint8_t deviceAddress ) #else deviceInfoCDC[i].returnState = STATE_RUNNING; #endif - + _USBHostCDC_ResetStateJump( i ); return USB_SUCCESS; } @@ -520,22 +520,22 @@ void USBHostCDCTasks( void ) break; case SUBSTATE_DEVICE_ENUMERATED: - USBHostCDCInitAddress( deviceInfoCDC[i].deviceAddress,0, deviceInfoCDC[i].clientDriverID ); // Initialize device address for application use + USBHostCDCInitAddress( deviceInfoCDC[i].deviceAddress,0, deviceInfoCDC[i].clientDriverID ); // Initialize device address for application use _USBHostCDC_SetNextSubState(); /* need to add sub states to Set Config, Get LANGID & String Descriptors */ break; case SUBSTATE_GET_LINE_CODING: - - if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + + if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_CDC_GET_LINE_CODING, 0 , deviceInfoCDC[i].commInterface.interfaceNum , USB_CDC_LINE_CODING_LENGTH, (uint8_t*)&CDC_DEV_LINE_CODING_Buffer, USB_DEVICE_REQUEST_GET , deviceInfoCDC[i].clientDriverID )) - { + { _USBHostCDC_SetNextSubState(); } break; - case SUBSTATE_WAIT_FOR_GET_LINE_CODING: + case SUBSTATE_WAIT_FOR_GET_LINE_CODING: if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, 0, &errorCode, &byteCount )) { if (errorCode) @@ -564,16 +564,16 @@ void USBHostCDCTasks( void ) break; case SUBSTATE_SET_LINE_CODING: - - if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + + if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_CDC_SET_LINE_CODING, 1 , deviceInfoCDC[i].commInterface.interfaceNum , USB_CDC_LINE_CODING_LENGTH, (uint8_t*)PTR_HOST_LINE_CODING_BUFFER, USB_DEVICE_REQUEST_SET , deviceInfoCDC[i].clientDriverID )) - { + { _USBHostCDC_SetNextSubState(); } break; - case SUBSTATE_WAIT_FOR_SET_LINE_CODING: + case SUBSTATE_WAIT_FOR_SET_LINE_CODING: if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, 0, &errorCode, &byteCount )) { if (errorCode) @@ -589,16 +589,16 @@ void USBHostCDCTasks( void ) break; case SUBSTATE_SET_CONTROL_LINE_STATE: - - if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + + if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_CDC_SET_CONTROL_LINE_STATE , *(uint16_t*)PTR_HOST_CONTROL_LINE_BUFFER , deviceInfoCDC[i].commInterface.interfaceNum , USB_CDC_CONTROL_LINE_LENGTH, NULL, USB_DEVICE_REQUEST_SET , deviceInfoCDC[i].clientDriverID )) - { + { _USBHostCDC_SetNextSubState(); } break; - case SUBSTATE_WAIT_FOR_SET_CONTROL_LINE_STATE: + case SUBSTATE_WAIT_FOR_SET_CONTROL_LINE_STATE: if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, 0, &errorCode, &byteCount )) { if (errorCode) @@ -613,7 +613,7 @@ void USBHostCDCTasks( void ) } break; - default : + default : break; } break; @@ -621,18 +621,18 @@ void USBHostCDCTasks( void ) case STATE_RUNNING: switch (deviceInfoCDC[i].state & SUBSTATE_MASK) { - case SUBSTATE_WAITING_FOR_REQ: + case SUBSTATE_WAITING_FOR_REQ: /* waiting for request from application */ break; - case SUBSTATE_SEND_READ_REQ: + case SUBSTATE_SEND_READ_REQ: // if endpoint 0 then use control transfer - Communication interface request // otherwise request is for data interface transfer USBHostClearEndpointErrors( deviceInfoCDC[i].deviceAddress, deviceInfoCDC[i].endpointDATA ); if(deviceInfoCDC[i].endpointDATA == 0x00) { - errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, deviceInfoCDC[i].commRequest, 0, deviceInfoCDC[i].interface,deviceInfoCDC[i].reportSize, deviceInfoCDC[i].userData, USB_DEVICE_REQUEST_GET , deviceInfoCDC[i].clientDriverID ); } @@ -662,7 +662,7 @@ void USBHostCDCTasks( void ) } break; - case SUBSTATE_READ_REQ_WAIT: + case SUBSTATE_READ_REQ_WAIT: if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, deviceInfoCDC[i].endpointDATA, &errorCode, &byteCount )) { if (errorCode) @@ -694,16 +694,16 @@ void USBHostCDCTasks( void ) } #ifdef DEBUG_MODE UART2PrintString("|"); -#endif +#endif break; - case SUBSTATE_SEND_WRITE_REQ: + case SUBSTATE_SEND_WRITE_REQ: // if endpoint 0 then use control transfer - Communication interface request // otherwise request is for data interface transfer if(deviceInfoCDC[i].endpointDATA == 0x00) { - errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, deviceInfoCDC[i].commRequest, 0, deviceInfoCDC[i].interface,deviceInfoCDC[i].reportSize, deviceInfoCDC[i].userData, USB_DEVICE_REQUEST_SET , deviceInfoCDC[i].clientDriverID ); } @@ -747,7 +747,7 @@ void USBHostCDCTasks( void ) } break; - case SUBSTATE_WRITE_REQ_WAIT: + case SUBSTATE_WRITE_REQ_WAIT: if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, deviceInfoCDC[i].endpointDATA, &errorCode, &byteCount )) { if (errorCode) @@ -783,7 +783,7 @@ void USBHostCDCTasks( void ) break; - default : + default : break; } break; @@ -848,7 +848,7 @@ void USBHostCDCTasks( void ) case STATE_HOLDING: break; - default : + default : break; } @@ -913,7 +913,7 @@ uint8_t USBHostCDCTransfer( uint8_t deviceAddress,uint8_t request , uint8_t dire { return USB_CDC_DEVICE_BUSY; } - + // Initialize the transfer information. deviceInfoCDC[i].bytesTransferred = 0; deviceInfoCDC[i].errorCode = USB_SUCCESS; @@ -928,7 +928,7 @@ uint8_t USBHostCDCTransfer( uint8_t deviceAddress,uint8_t request , uint8_t dire UART2PutHex( deviceInfoCDC[i].endpointDATA ); UART2PrintString( "\r\n" ); #endif - + #ifndef USB_ENABLE_TRANSFER_EVENT // Jump to the transfer state. if(!direction) @@ -946,7 +946,7 @@ uint8_t USBHostCDCTransfer( uint8_t deviceAddress,uint8_t request , uint8_t dire { if(deviceInfoCDC[i].endpointDATA == 0x00)// if endpoint 0 then use control transfer for COMM interface request { - errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, request, 0, deviceInfoCDC[i].interface,deviceInfoCDC[i].reportSize, deviceInfoCDC[i].userData, USB_DEVICE_REQUEST_SET , deviceInfoCDC[i].clientDriverID ); deviceInfoCDC[i].state = STATE_WRITE_REQ_WAIT; @@ -962,14 +962,14 @@ uint8_t USBHostCDCTransfer( uint8_t deviceAddress,uint8_t request , uint8_t dire { if(deviceInfoCDC[i].endpointDATA == 0x00)// if endpoint 0 then use control transfer for COMM interface request { - errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + errorCode = USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, request, 0, deviceInfoCDC[i].interface,deviceInfoCDC[i].reportSize, deviceInfoCDC[i].userData, USB_DEVICE_REQUEST_GET , deviceInfoCDC[i].clientDriverID ); deviceInfoCDC[i].state = STATE_READ_REQ_WAIT; } else { - errorCode = USBHostRead( deviceInfoCDC[i].deviceAddress, deviceInfoCDC[i].endpointDATA, + errorCode = USBHostRead( deviceInfoCDC[i].deviceAddress, deviceInfoCDC[i].endpointDATA, deviceInfoCDC[i].userData, deviceInfoCDC[i].reportSize ); deviceInfoCDC[i].state = STATE_READ_REQ_WAIT; } @@ -1155,10 +1155,10 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 if(0 == memcmp(&CDC_DEV_LINE_CODING_Buffer, PTR_HOST_LINE_CODING_BUFFER, USB_CDC_LINE_CODING_LENGTH)) { // if fine goto set Control line state - if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_CDC_SET_CONTROL_LINE_STATE , *(uint16_t*)PTR_HOST_CONTROL_LINE_BUFFER , deviceInfoCDC[i].commInterface.interfaceNum , USB_CDC_CONTROL_LINE_LENGTH, NULL, - USB_DEVICE_REQUEST_SET , deviceInfoCDC[i].clientDriverID )) - { + USB_DEVICE_REQUEST_SET , deviceInfoCDC[i].clientDriverID )) + { deviceInfoCDC[i].state = STATE_WAIT_FOR_SET_CONTROL_LINE_STATE; } else @@ -1169,10 +1169,10 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 else { // if data not as expected goto Set Line coding - if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_CDC_SET_LINE_CODING, 1 , deviceInfoCDC[i].commInterface.interfaceNum , USB_CDC_LINE_CODING_LENGTH, (uint8_t*)PTR_HOST_LINE_CODING_BUFFER, USB_DEVICE_REQUEST_SET , deviceInfoCDC[i].clientDriverID )) - { + { deviceInfoCDC[i].state = STATE_WAIT_FOR_SET_LINE_CODING; } else @@ -1182,7 +1182,7 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 } } } - + break; case STATE_WAIT_FOR_SET_LINE_CODING : if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, 0, &errorCode, &byteCount )) @@ -1194,11 +1194,11 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 } else { // check again if line coding is correctly set - // Send GET Line Coding request to the device - if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + // Send GET Line Coding request to the device + if(!USBHostIssueDeviceRequest( deviceInfoCDC[i].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_CDC_GET_LINE_CODING, 0 , deviceInfoCDC[i].commInterface.interfaceNum , USB_CDC_LINE_CODING_LENGTH, (uint8_t*)&CDC_DEV_LINE_CODING_Buffer, USB_DEVICE_REQUEST_GET , deviceInfoCDC[i].clientDriverID )) - { + { // wait for transfer event for and then decide to alter the settings or not deviceInfoCDC[i].state = STATE_WAIT_FOR_GET_LINE_CODING; } @@ -1221,14 +1221,14 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 } else { - // device is ready to TX/RX data + // device is ready to TX/RX data USB_HOST_APP_EVENT_HANDLER(deviceInfoCDC[i].deviceAddress,EVENT_CDC_ATTACH,NULL, 0); deviceInfoCDC[i].state = STATE_RUNNING; } - } + } break; - + case STATE_READ_REQ_WAIT : if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, deviceInfoCDC[i].endpointDATA, &errorCode, &byteCount )) { @@ -1264,9 +1264,9 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 } #ifdef DEBUG_MODE UART2PrintString("|"); -#endif +#endif break; - + case STATE_WRITE_REQ_WAIT : if (USBHostTransferIsComplete( deviceInfoCDC[i].deviceAddress, deviceInfoCDC[i].endpointDATA, &errorCode, &byteCount )) { @@ -1302,7 +1302,7 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 } #ifdef DEBUG_MODE UART2PrintString("|"); -#endif +#endif break; default: @@ -1346,8 +1346,8 @@ bool USBHostCDCEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 Description: This function is the initialization routine for this client driver. It - is called by the host layer when the USB device is being enumerated.For a - CDC device we need to look into CDC descriptor, interface descriptor and + is called by the host layer when the USB device is being enumerated.For a + CDC device we need to look into CDC descriptor, interface descriptor and endpoint descriptor. This will decode information for Communication and Data interface. @@ -1416,7 +1416,7 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver // Total no of interfaces deviceInfoCDC[device].noOfInterfaces = descriptor[i+4] ; - + i += descriptor[i]; // skip configuration descriptor // Set current configuration to this configuration. We can change it later. @@ -1430,7 +1430,7 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver #endif // initialize device address deviceInfoCDC[device].deviceAddress = address; - + // See if we are pointing to an interface descriptor. if (descriptor[i+1] == USB_DESCRIPTOR_INTERFACE) { @@ -1441,39 +1441,39 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver deviceInfoCDC[device].commInterface.interfaceNum = descriptor[i+2]; deviceInfoCDC[device].commInterface.noOfEndpoints = descriptor[i+4]; // Since control has reached here , implies subclass & protocol is supported by the host - + // look for class specific functional descriptors i += descriptor[i]; // skip interface descriptor - + // parse all function descriptors while(USB_CDC_CS_INTERFACE == descriptor[i+1] ) { switch(descriptor[i+2]) { - case USB_CDC_DSC_FN_HEADER : - deviceInfoCDC[device].commInterface.Header_Fn_Dsc = + case USB_CDC_DSC_FN_HEADER : + deviceInfoCDC[device].commInterface.Header_Fn_Dsc = (*((USB_CDC_HEADER_FN_DSC*)&descriptor[i])); break; - case USB_CDC_DSC_FN_CALL_MGT : - deviceInfoCDC[device].commInterface.Call_Mgt_Fn_Desc = + case USB_CDC_DSC_FN_CALL_MGT : + deviceInfoCDC[device].commInterface.Call_Mgt_Fn_Desc = (*((USB_CDC_CALL_MGT_FN_DSC*)&descriptor[i])); break; case USB_CDC_DSC_FN_ACM : - deviceInfoCDC[device].commInterface.ACM_Fn_Desc = + deviceInfoCDC[device].commInterface.ACM_Fn_Desc = (*((USB_CDC_ACM_FN_DSC*)&descriptor[i])); break; case USB_CDC_DSC_FN_UNION : - deviceInfoCDC[device].commInterface.Union_Fn_Desc = + deviceInfoCDC[device].commInterface.Union_Fn_Desc = (*((USB_CDC_UNION_FN_DSC*)&descriptor[i])); break; default : // function not supported -- flag error/ return false break; } - + i += descriptor[i]; // goto next function descriptor } @@ -1493,7 +1493,7 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver } else { - // communication interface normaly has one endpoint. + // communication interface normaly has one endpoint. // Notification element is optional - currently not supported. } @@ -1506,7 +1506,7 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver validDataInterface = 1; deviceInfoCDC[device].dataInterface.interfaceNum = descriptor[i+2]; deviceInfoCDC[device].dataInterface.noOfEndpoints = descriptor[i+4]; - + i += descriptor[i]; // goto endpoint descriptors } else @@ -1520,7 +1520,7 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver // Look for bulk or isochronous , IN and OUT endpoints. endpointIN = 0; endpointOUT = 0; - + while(descriptor[i+1] == USB_DESCRIPTOR_ENDPOINT) { // Data Interface uses Bulk or Iscochronous endpoint deviceInfoCDC[device].dataInterface.endpointType = descriptor[i+3]; @@ -1536,19 +1536,19 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver endpointOUT = descriptor[i+2]; endpointOUTsize = ((descriptor[i+4])|(descriptor[i+5] << 8)); } - + } i += descriptor[i]; } - + if ((endpointIN != 0) || (endpointOUT != 0)) // normally endpoint should be in pair of same type { deviceInfoCDC[device].dataInterface.endpointIN = endpointIN; deviceInfoCDC[device].dataInterface.endpointInDataSize = endpointINsize; - + deviceInfoCDC[device].dataInterface.endpointOUT = endpointOUT; deviceInfoCDC[device].dataInterface.endpointOutDataSize = endpointOUTsize; - + USBHostSetNAKTimeout( address, endpointIN, USB_HOST_CDC_NAK_TIMEOUT, USB_NUM_BULK_NAKS ); USBHostSetNAKTimeout( address, endpointOUT, USB_HOST_CDC_NAK_TIMEOUT, USB_NUM_BULK_NAKS ); } @@ -1575,13 +1575,13 @@ bool USBHostCDCInitialize( uint8_t address, uint32_t flags, uint8_t clientDriver #ifndef USB_ENABLE_TRANSFER_EVENT deviceInfoCDC[device].state = STATE_INITIALIZE_DEVICE; #else - // Initialize device address for application use + // Initialize device address for application use USBHostCDCInitAddress( deviceInfoCDC[device].deviceAddress,0,deviceInfoCDC[device].clientDriverID ); - // Send GET Line Coding request to the device - if(USBHostIssueDeviceRequest( deviceInfoCDC[device].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, + // Send GET Line Coding request to the device + if(USBHostIssueDeviceRequest( deviceInfoCDC[device].deviceAddress, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_CDC_GET_LINE_CODING, 0 , deviceInfoCDC[device].commInterface.interfaceNum , USB_CDC_LINE_CODING_LENGTH, (uint8_t*)&CDC_DEV_LINE_CODING_Buffer, USB_DEVICE_REQUEST_GET , deviceInfoCDC[device].clientDriverID )) - { + { return false; } // wait for transfer event for and then decide to alter the settings or not @@ -1670,10 +1670,10 @@ void _USBHostCDC_ResetStateJump( uint8_t i ) Precondition: Configuration macros should be defined in file usb_config.h. USBConfig tool can be used to configure the CDC in ACM mode. - + Parameters: None - + Returns: None diff --git a/src/usb_host_cdc_interface.c b/src/usb_host_cdc_interface.c index 8acd7d5..8334069 100644 --- a/src/usb_host_cdc_interface.c +++ b/src/usb_host_cdc_interface.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -88,7 +88,7 @@ extern uint8_t CDCdeviceAddress ; bool USBHostCDC_Api_Get_IN_Data(uint8_t no_of_bytes, uint8_t* data) Description: - This function is called by application to receive Input data over DATA + This function is called by application to receive Input data over DATA interface. This function setsup the request to receive data from the device. Precondition: @@ -125,8 +125,8 @@ bool USBHostCDC_Api_Get_IN_Data(uint8_t no_of_bytes, uint8_t* data) bool USBHostCDC_Api_Send_OUT_Data(uint8_t no_of_bytes, uint8_t* data) Description: - This function is called by application to transmit out data over DATA - interface. This function setsup the request to transmit data to the + This function is called by application to transmit out data over DATA + interface. This function setsup the request to transmit data to the device. Precondition: @@ -164,9 +164,9 @@ bool USBHostCDC_Api_Send_OUT_Data(uint16_t no_of_bytes, uint8_t* data) bool USBHostCDC_ApiTransferIsComplete(uint8_t* errorCodeDriver,uint8_t* byteCount) Description: - This function is called by application to poll for transfer status. This + This function is called by application to poll for transfer status. This function returns true in the transfer is over. To check whether the transfer - was successfull or not , application must check the error code returned by + was successfull or not , application must check the error code returned by reference. Precondition: @@ -185,7 +185,7 @@ bool USBHostCDC_Api_Send_OUT_Data(uint16_t no_of_bytes, uint8_t* data) None ***************************************************************************/ bool USBHostCDC_ApiTransferIsComplete(uint8_t* errorCodeDriver, uint8_t* byteCount ) -{ +{ return(USBHostCDCTransferIsComplete(CDCdeviceAddress,errorCodeDriver,byteCount)); } @@ -232,7 +232,7 @@ bool USBHostCDC_ApiDeviceDetect( void ) Description: This function can be used by application code to dynamically access ACM specific - requests. This function should be used only if apllication intends to modify for + requests. This function should be used only if apllication intends to modify for example the Baudrate from previouly configured rate. Data transmitted/received to/from device is a array of bytes. Application must take extra care of understanding the data format before using this function. @@ -276,7 +276,7 @@ uint8_t USBHostCDC_Api_ACM_Request(uint8_t requestType, uint8_t size, uint8_t* d switch(requestType) { - case USB_CDC_SEND_ENCAPSULATED_COMMAND : + case USB_CDC_SEND_ENCAPSULATED_COMMAND : return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_SEND_ENCAPSULATED_COMMAND,0, deviceInfoCDC[i].commInterface.interfaceNum,size,data, 0); @@ -292,19 +292,19 @@ uint8_t USBHostCDC_Api_ACM_Request(uint8_t requestType, uint8_t size, uint8_t* d case USB_CDC_GET_COMM_FEATURE : break; - + case USB_CDC_SET_LINE_CODING : return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_SET_LINE_CODING,0, deviceInfoCDC[i].commInterface.interfaceNum,size,data, 0); break; - + case USB_CDC_GET_LINE_CODING : return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_GET_LINE_CODING,1, deviceInfoCDC[i].commInterface.interfaceNum,size,data, 0); break; - + case USB_CDC_SET_CONTROL_LINE_STATE : return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_SET_CONTROL_LINE_STATE,0, deviceInfoCDC[i].commInterface.interfaceNum,size,data, diff --git a/src/usb_host_generic.c b/src/usb_host_generic.c index 3cf469a..0965e37 100644 --- a/src/usb_host_generic.c +++ b/src/usb_host_generic.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -99,7 +99,7 @@ GENERIC_DEVICE gc_DevData; uint32_t flags - Initialization flags uint8_t clientDriverID - ID to send when issuing a Device Request via USBHostIssueDeviceRequest(), USBHostSetDeviceConfiguration(), - or USBHostSetDeviceInterface(). + or USBHostSetDeviceInterface(). Return Values: true - Initialization was successful @@ -130,7 +130,7 @@ bool USBHostGenericInit ( uint8_t address, uint32_t flags, uint8_t clientDriverI // Save the Client Driver ID gc_DevData.clientDriverID = clientDriverID; - + #ifdef DEBUG_MODE UART2PrintString( "GEN: USB Generic Client Initalized: flags=0x" ); UART2PutHex( flags ); diff --git a/src/usb_host_hid.c b/src/usb_host_hid.c index 70e3a1d..e84ee7e 100644 --- a/src/usb_host_hid.c +++ b/src/usb_host_hid.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -285,21 +285,21 @@ extern USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t*, uint16_t, uint1 uint8_t USBHostHIDDeviceDetect( void ) { uint8_t i; - + // Find the correct device. for (i=0; (ireportID != 0) && + if ( (pDataDetails->reportID != 0) && (pDataDetails->reportID != report[0]) - ) + ) { 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 */ start = pDataDetails->bitOffset; - - for (i=0; icount; i++) + + for (i=0; icount; i++) { startByte = start/8; startBit = start&7; @@ -1137,7 +1137,7 @@ bool USBHostHID_ApiImportData /* Pick up the data bytes backwards */ data = 0; - do + do { data <<= 8; data |= (int) report[lastByte]; @@ -1550,34 +1550,34 @@ bool USBHostHIDEventHandler( uint8_t address, USB_EVENT event, void *data, uint3 // This addition has not been fully tested yet. It may be included in the future. // case EVENT_BUS_ERROR: -// // We will get this error if we have a problem, like too many NAK's +// // We will get this error if we have a problem, like too many NAK's // // on a write, so we know the write failed. // switch (deviceInfoHID[i].state) // { // case STATE_READ_REQ_WAIT: // USBHostClearEndpointErrors( deviceInfoHID[i].ID.deviceAddress, deviceInfoHID[i].endpointDATA ); // deviceInfoHID[i].bytesTransferred = 0; -// #ifdef USB_HID_ENABLE_TRANSFER_EVENT +// #ifdef USB_HID_ENABLE_TRANSFER_EVENT // transferEventData.dataCount = 0; // transferEventData.bErrorCode = ((HOST_TRANSFER_DATA *)data)->bErrorCode; // #endif // _USBHostHID_TerminateReadTransfer( ((HOST_TRANSFER_DATA *)data)->bErrorCode ); // return true; // break; -// +// // case STATE_WRITE_REQ_WAIT: // USBHostClearEndpointErrors( deviceInfoHID[i].ID.deviceAddress, deviceInfoHID[i].endpointDATA ); // deviceInfoHID[i].bytesTransferred = 0; -// #ifdef USB_HID_ENABLE_TRANSFER_EVENT +// #ifdef USB_HID_ENABLE_TRANSFER_EVENT // transferEventData.dataCount = 0; // transferEventData.bErrorCode = ((HOST_TRANSFER_DATA *)data)->bErrorCode; // #endif // _USBHostHID_TerminateWriteTransfer( ((HOST_TRANSFER_DATA *)data)->bErrorCode ); // return true; // break; -// } +// } // break; - + case EVENT_SOF: // Start of frame - NOT NEEDED case EVENT_RESUME: // Device-mode resume received case EVENT_SUSPEND: // Device-mode suspend/idle event received @@ -1634,8 +1634,8 @@ bool USBHostHIDAppDataEventHandler( uint8_t address, USB_EVENT event, void *data Description: This function is the initialization routine for this client driver. It - is called by the host layer when the USB device is being enumerated.For a - HID device we need to look into HID descriptor, interface descriptor and + is called by the host layer when the USB device is being enumerated.For a + HID device we need to look into HID descriptor, interface descriptor and endpoint descriptor. Precondition: @@ -1941,7 +1941,7 @@ static void _USBHostHID_ResetStateJump( uint8_t i ) { deviceInfoHID[i].transferIN.state = STATE_TRANSFER_WAITING; deviceInfoHID[i].transferOUT.state = STATE_TRANSFER_WAITING; - + errorCode = USBHostIssueDeviceRequest( deviceInfoHID[i].ID.deviceAddress, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE, USB_HID_RESET, 0, deviceInfoHID[i].transferOUT.interface, 0, NULL, USB_DEVICE_REQUEST_SET, deviceInfoHID[i].ID.clientDriverID ); diff --git a/src/usb_host_hid_parser.c b/src/usb_host_hid_parser.c index 07b3d49..a37d3a9 100644 --- a/src/usb_host_hid_parser.c +++ b/src/usb_host_hid_parser.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -150,7 +150,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u memset( &deviceRptInfo, 0x00, sizeof( USB_HID_DEVICE_RPT_INFO ) ); _USBHostHID_InitDeviceRptInfo(); - + deviceRptInfo.interfaceNumber = interfaceNum; // update interface number for the report deviceRptInfo.reportPollingRate = pollRate; @@ -162,8 +162,8 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u item.ItemDetails.val = *currentRptDescPtr; /* Data need not be parsed at this point */ ldataSize = item.ItemDetails.ItemSize ; - if(item.ItemDetails.ItemSize == 3) - ldataSize = 4; + if(item.ItemDetails.ItemSize == 3) + ldataSize = 4; currentRptDescPtr += (ldataSize+1) ; /* point to next item i.e size of item data + 1(item detail) */ len_to_be_parsed -= (ldataSize+1); /* remaining bytes = current - (length of data + 1)*/ @@ -286,7 +286,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u } parsedDataMem = (uint8_t*) USB_MALLOC(sizeRequired); - + #ifdef DEBUG_MODE UART2PrintString( "HID: Memory for Report Descriptor: " ); UART2PutHex( sizeRequired ); @@ -294,8 +294,8 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u if (parsedDataMem == NULL) return(HID_ERR_NotEnoughMemory); /* Error: Not enough memory */ assignMem = (uint8_t*) parsedDataMem; - - /* Allocate Space */ + + /* Allocate Space */ itemListPtrs.collectionList = (HID_COLLECTION *) assignMem; assignMem += (sizeof(HID_COLLECTION) * deviceRptInfo.collections); itemListPtrs.reportItemList = (HID_REPORTITEM *) assignMem; @@ -350,8 +350,8 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u item.Data.uItemData = 0; ldataSize = item.ItemDetails.ItemSize ; - if(item.ItemDetails.ItemSize == 3) - ldataSize = 4; + if(item.ItemDetails.ItemSize == 3) + ldataSize = 4; currentRptDescPtr++; /* ptr points to data */ for (i = 0; i < ldataSize; i++) @@ -359,7 +359,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u dataByte = *currentRptDescPtr++; /* signed data will be taken care in ItemTag it is expected */ item.Data.uItemData |= ((uint32_t)dataByte << (i*8)); } - + len_to_be_parsed -= (ldataSize+1); /* remaining bytes = current - (length of current item + 1)*/ switch(item.ItemDetails.ItemType) @@ -382,7 +382,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u break; } break; - + case HIDType_Global: /* look for Global Items*/ switch(item.ItemDetails.ItemTag) { @@ -394,7 +394,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u // Sign extend one value _USBHostHID_ConvertDataToSigned(&item); deviceRptInfo.globals.logicalMinimum = item.Data.sItemData; - break; + break; case HIDTag_LogicalMaximum :/* convert to signed val */ // Sign extend one value @@ -428,15 +428,15 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u if (item.Data.uItemData) { // Look for the Report ID in the table - + lreportIndex = 0; while ((lreportIndex < deviceRptInfo.reports) && (itemListPtrs.reportList[lreportIndex].reportID != item.Data.uItemData)) lreportIndex++; - + // initialize the entry if it's new and there's room for it // Start with 8 bits for the Report ID - + if (lreportIndex == deviceRptInfo.reports) { lreport = &itemListPtrs.reportList[deviceRptInfo.reports++]; @@ -445,9 +445,9 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u lreport->outputBits = 8; lreport->featureBits = 8; } - + // remember which report is being processed - + deviceRptInfo.globals.reportID = item.Data.uItemData; deviceRptInfo.globals.reportIndex = lreportIndex; } @@ -475,7 +475,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u case HIDTag_Pop : deviceRptInfo.globals = itemListPtrs.globalsStack[--deviceRptInfo.globalsNesting] ; break; - + } break; @@ -515,16 +515,16 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u if (lusageItem->usagePage != deviceRptInfo.rangeUsagePage) lhidError = HID_ERR_BadUsageRangePage; /* Error: BadUsageRangePage */ - + lusageItem->usageMaximum = deviceRptInfo.usageMaximum; - + if (lusageItem->usageMaximum < lusageItem->usageMinimum) lhidError = HID_ERR_BadUsageRange; /* Error: BadUsageRange */ - + deviceRptInfo.haveUsageMax = false; deviceRptInfo.haveUsageMin = false; } - else + else { if(item.ItemDetails.ItemSize == 3) { @@ -536,7 +536,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u deviceRptInfo.rangeUsagePage = deviceRptInfo.globals.usagePage; deviceRptInfo.usageMinimum = item.Data.uItemData; } - + deviceRptInfo.haveUsageMin = true; } break; @@ -559,16 +559,16 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u if (lusageItem->usagePage != deviceRptInfo.rangeUsagePage) lhidError = HID_ERR_BadUsageRangePage; /* Error: BadUsageRangePage */ - + lusageItem->usageMinimum = deviceRptInfo.usageMinimum; - + if (lusageItem->usageMaximum < lusageItem->usageMinimum) lhidError = HID_ERR_BadUsageRange; /* Error: BadUsageRange */ - + deviceRptInfo.haveUsageMax = false; deviceRptInfo.haveUsageMin = false; } - else + else { if(item.ItemDetails.ItemSize == 3) { @@ -580,7 +580,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u deviceRptInfo.rangeUsagePage = deviceRptInfo.globals.usagePage; deviceRptInfo.usageMaximum = item.Data.uItemData; } - + deviceRptInfo.haveUsageMax = true; } break; @@ -667,7 +667,7 @@ USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_Report(uint8_t* hidReportDescriptor , u break; } - + break; default: @@ -732,7 +732,7 @@ static void _USBHostHID_InitDeviceRptInfo(void) deviceRptInfo.usages = 0; deviceRptInfo.usageRanges = 0; deviceRptInfo.usageItems = 0; - + deviceRptInfo.haveDesignatorMax = false; deviceRptInfo.haveDesignatorMin = false; deviceRptInfo.haveStringMax = false; @@ -759,7 +759,7 @@ static void _USBHostHID_InitDeviceRptInfo(void) static void _USBHostHID_Parse_Collection(HID_ITEM_INFO* ptrItem) Description: - This function is called by _USBHostHID_Parse_Report() to parse + This function is called by _USBHostHID_Parse_Report() to parse collection item. Precondition: @@ -870,13 +870,13 @@ static USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_ReportType(HID_ITEM_INFO* item) if(item == NULL) return(HID_ERR_NullPointer); - + // Reality Check on the Report Main Item if (deviceRptInfo.globals.logicalMinimum >= ((int32_t)1<= ((int32_t)1< deviceRptInfo.globals.logicalMaximum)return(HID_ERR_BadLogical); + // if (deviceRptInfo.globals.logicalMinimum > deviceRptInfo.globals.logicalMaximum)return(HID_ERR_BadLogical); if (deviceRptInfo.haveUsageMin || deviceRptInfo.haveUsageMax)return(HID_ERR_UnmatchedUsageRange); if (deviceRptInfo.haveStringMin || deviceRptInfo.haveStringMax)return(HID_ERR_UnmatchedStringRange); if (deviceRptInfo.haveDesignatorMin || deviceRptInfo.haveDesignatorMax)return(HID_ERR_UnmatchedDesignatorRange); @@ -901,7 +901,7 @@ static USB_HID_RPT_DESC_ERROR _USBHostHID_Parse_ReportType(HID_ITEM_INFO* item) lreport = &itemListPtrs.reportList[deviceRptInfo.globals.reportIndex]; bits = deviceRptInfo.globals.reportsize * deviceRptInfo.globals.reportCount; - switch (item->ItemDetails.ItemTag) + switch (item->ItemDetails.ItemTag) { case HIDTag_Feature: lreportItem->reportType = hidReportFeature; @@ -951,12 +951,12 @@ static void _USBHostHID_ConvertDataToSigned(HID_ITEM_INFO* item) { uint8_t dataByte=0; uint8_t index; - + index = item->ItemDetails.ItemSize; if(index) { - if(item->ItemDetails.ItemSize == 3) + if(item->ItemDetails.ItemSize == 3) index = 4; dataByte = item->Data.bItemData[index-1]; @@ -1021,7 +1021,7 @@ bool USBHostHID_HasUsage(HID_REPORTITEM *reportItem,uint16_t usagePage, uint16_t hidUsageItem = &itemListPtrs.usageItemList[usageItem++]; onPage = ((usagePage == 0) || (usagePage == hidUsageItem->usagePage)); - if (hidUsageItem->isRange) + if (hidUsageItem->isRange) { // For Usage Ranges // If the index is in the range @@ -1056,7 +1056,7 @@ bool USBHostHID_HasUsage(HID_REPORTITEM *reportItem,uint16_t usagePage, uint16_t if (usages < 0) usages = -usages; usageIndex += usages; } - else + else { // For Usages // If the index is zero @@ -1174,7 +1174,7 @@ void USBHID_ReportDecriptor_Dump(void) UART2PrintString("\r\nreportsize : ");UART2PutHex(lreportItem->globals.reportsize); UART2PrintString("\r\nreportID : ");UART2PutHex(lreportItem->globals.reportID); UART2PrintString("\r\nreportCount : ");UART2PutHex(lreportItem->globals.reportCount); - + } UART2PrintString("\n------------------------\n"); @@ -1187,7 +1187,7 @@ void USBHID_ReportDecriptor_Dump(void) UART2PrintString("\r\nUsages Minimum Maximum \n\r"); UART2PrintString("\t\t"); j = itemListPtrs.usageItemList[i].usageMaximum; - UART2PutHex(j); + UART2PutHex(j); UART2PrintString("\t"); j = itemListPtrs.usageItemList[i].usageMinimum; UART2PutHex(j); diff --git a/src/usb_host_local.h b/src/usb_host_local.h index 6e47a79..3c21b8b 100644 --- a/src/usb_host_local.h +++ b/src/usb_host_local.h @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END diff --git a/src/usb_host_midi.c b/src/usb_host_midi.c index 2bf7415..ad254ed 100644 --- a/src/usb_host_midi.c +++ b/src/usb_host_midi.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -59,7 +59,7 @@ Currently this must be set to 1, due to limitations in the USB Host layer. // Section: Global Variables // ***************************************************************************** // ***************************************************************************** - + static MIDI_DEVICE devices[USB_MAX_MIDI_DEVICES]; // ***************************************************************************** @@ -90,7 +90,7 @@ static MIDI_DEVICE devices[USB_MAX_MIDI_DEVICES]; uint32_t flags - Initialization flags uint8_t clientDriverID - ID to send when issuing a Device Request via USBHostIssueDeviceRequest(), USBHostSetDeviceConfiguration(), - or USBHostSetDeviceInterface(). + or USBHostSetDeviceInterface(). Return Values: true - Initialization was successful @@ -117,22 +117,22 @@ bool USBHostMIDIInit ( uint8_t address, uint32_t flags, uint8_t clientDriverID ) uint8_t Protocol; uint8_t currentEndpoint; uint16_t wTotalLength; - + uint8_t index = 0; bool error = false; - + MIDI_DEVICE *device = &devices[0]; - + config_descriptor = USBHostGetCurrentConfigurationDescriptor(address); ptr = config_descriptor; - + // Load up the values from the Configuration Descriptor bLength = *ptr++; bDescriptorType = *ptr++; wTotalLength = *ptr++; // In case these are not word aligned wTotalLength += (*ptr++) << 8; bNumInterfaces = *ptr++; - + // Skip over the rest of the Configuration Descriptor index += bLength; ptr = &config_descriptor[index]; @@ -173,16 +173,16 @@ bool USBHostMIDIInit ( uint8_t address, uint32_t flags, uint8_t clientDriverID ) device->deviceAddress = address; device->clientDriverID = clientDriverID; device->numEndpoints = bNumEndpoints; - - + + // Allocate enough memory for each endpoint if ((device->endpoints = (MIDI_ENDPOINT_DATA*)malloc( sizeof(MIDI_ENDPOINT_DATA) * bNumEndpoints)) == NULL) { // Out of memory - error = true; + error = true; } - - if (!error) + + if (!error) { // Skip over the rest of the Interface Descriptor index += bLength; @@ -208,21 +208,21 @@ bool USBHostMIDIInit ( uint8_t address, uint32_t flags, uint8_t clientDriverID ) device->endpoints[currentEndpoint].endpointSize = *ptr++; device->endpoints[currentEndpoint].endpointSize += (*ptr++) << 8; device->endpoints[currentEndpoint].busy = false; - + if(device->endpoints[currentEndpoint].endpointSize > 64) { // For full speed bulk endpoints, only 8, 16, 32, and 64 byte packets are supported // But we will accept anything less than or equal to 64. error = true; } - + // Get ready for the next endpoint. currentEndpoint++; index += bLength; ptr = &config_descriptor[index]; } } - } + } // Ensure that we found all the endpoints for this interface. if (currentEndpoint != bNumEndpoints) @@ -237,13 +237,13 @@ bool USBHostMIDIInit ( uint8_t address, uint32_t flags, uint8_t clientDriverID ) // Destroy whatever list of interfaces, settings, and endpoints we created. // The "new" variables point to the current node we are trying to remove. if (device->endpoints != NULL) - { + { free( device->endpoints ); device->endpoints = NULL; - } + } return false; } - + #ifdef DEBUG_MODE UART2PrintString( "USB MIDI Client Initalized: " ); UART2PrintString( " address=" ); @@ -296,7 +296,7 @@ bool USBHostMIDIInit ( uint8_t address, uint32_t flags, uint8_t clientDriverID ) bool USBHostMIDIEventHandler ( uint8_t address, USB_EVENT event, void *data, uint32_t size ) { unsigned char i; - + // Make sure it was for one of our devices for( i = 0; i < USB_MAX_MIDI_DEVICES; i++) { @@ -304,13 +304,13 @@ bool USBHostMIDIEventHandler ( uint8_t address, USB_EVENT event, void *data, uin { break; } - + } if(i == USB_MAX_MIDI_DEVICES) { return false; - } - + } + // Handle specific events switch (event) { @@ -326,14 +326,14 @@ bool USBHostMIDIEventHandler ( uint8_t address, USB_EVENT event, void *data, uin UART2PrintString( "\r\n" ); #endif return true; - + #ifdef USB_ENABLE_TRANSFER_EVENT case EVENT_TRANSFER: if ( (data != NULL) && (size == sizeof(HOST_TRANSFER_DATA)) ) { unsigned char currentEndpoint; //uint32_t dataCount = ((HOST_TRANSFER_DATA *)data)->dataCount; - + for(currentEndpoint = 0; currentEndpoint < devices[i].numEndpoints; currentEndpoint++) { if ( ((HOST_TRANSFER_DATA *)data)->bEndpointAddress == devices[i].endpoints[currentEndpoint].endpointAddress ) @@ -342,11 +342,11 @@ bool USBHostMIDIEventHandler ( uint8_t address, USB_EVENT event, void *data, uin USB_HOST_APP_EVENT_HANDLER(devices[i].deviceAddress, EVENT_MIDI_TRANSFER_DONE, &devices[i].endpoints[currentEndpoint], sizeof(MIDI_ENDPOINT_DATA)); return true; } - } + } } return false; #endif - + case EVENT_SUSPEND: case EVENT_RESUME: case EVENT_BUS_ERROR: @@ -427,7 +427,7 @@ bool USBHostMIDIEventHandler ( uint8_t address, USB_EVENT event, void *data, uin uint32_t USBHostMIDISizeOfEndpoint( void* handle, uint8_t endpointIndex ) Description: - This function retrieves the endpoint size of the endpoint at + This function retrieves the endpoint size of the endpoint at endpointIndex for device that's located at handle. Preconditions: @@ -467,7 +467,7 @@ bool USBHostMIDIEventHandler ( uint8_t address, USB_EVENT event, void *data, uin Remarks: None ***************************************************************************/ - + // Implemented as a macro. See usb_host_midi.h @@ -510,9 +510,9 @@ uint8_t USBHostMIDIRead( void* handle, uint8_t endpointIndex, void *buffer, uint { MIDI_DEVICE *device = (MIDI_DEVICE*)handle; uint8_t RetVal; - + RetVal = USBHostRead( device->deviceAddress, device->endpoints[endpointIndex].endpointAddress, (uint8_t *)buffer, length ); - + if (RetVal == USB_SUCCESS) { // Set the busy flag @@ -605,15 +605,15 @@ uint8_t USBHostMIDIRead( void* handle, uint8_t endpointIndex, void *buffer, uint bool USBHostMIDITransferIsComplete(void* handle, uint8_t endpointIndex, uint8_t* errorCode, uint32_t *byteCount ) { MIDI_DEVICE* device = (MIDI_DEVICE*)handle; - + if (USBHostTransferIsComplete(device->deviceAddress, endpointIndex, errorCode, byteCount) == true) { device->endpoints[endpointIndex].busy = 0; return true; } - + // Then this transfer is not complete - return false; + return false; } #endif @@ -657,7 +657,7 @@ uint8_t USBHostMIDIWrite(void* handle, uint8_t endpointIndex, void *buffer, uint { MIDI_DEVICE *device = (MIDI_DEVICE*)handle; uint8_t RetVal; - + RetVal = USBHostWrite( device->deviceAddress, device->endpoints[endpointIndex].endpointAddress, (uint8_t *)buffer, length ); if (RetVal == USB_SUCCESS) { diff --git a/src/usb_host_msd.c b/src/usb_host_msd.c index 0809662..ca7a1bc 100644 --- a/src/usb_host_msd.c +++ b/src/usb_host_msd.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END diff --git a/src/usb_host_msd_scsi.c b/src/usb_host_msd_scsi.c index b1960df..e76eb28 100644 --- a/src/usb_host_msd_scsi.c +++ b/src/usb_host_msd_scsi.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -738,7 +738,7 @@ static bool USBHostMSDSCSIRequestSense(uint8_t * address) // Fill in the command block with the READ10 parameters. commandBlock[0] = 0x03; // Request Sense commandBlock[1] = RDPROTECT_NORMAL | FUA_ALLOW_CACHE; - commandBlock[2] = 0; + commandBlock[2] = 0; commandBlock[3] = 0; commandBlock[4] = 0x12; commandBlock[5] = 0; diff --git a/src/usb_host_printer.c b/src/usb_host_printer.c index 9a9aee9..7544f55 100644 --- a/src/usb_host_printer.c +++ b/src/usb_host_printer.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END diff --git a/src/usb_host_printer_esc_pos.c b/src/usb_host_printer_esc_pos.c index 131e80d..7a2fbc4 100644 --- a/src/usb_host_printer_esc_pos.c +++ b/src/usb_host_printer_esc_pos.c @@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -To request to license the code under the MLA license (www.microchip.com/mla_license), +To request to license the code under the MLA license (www.microchip.com/mla_license), please contact mla_licensing@microchip.com *******************************************************************************/ //DOM-IGNORE-END @@ -884,7 +884,7 @@ uint8_t USBHostPrinterLanguageESCPOS( uint8_t address, { // Add one for the check digit that we will add. dataLength ++; - } + } break; case USB_PRINTER_POS_BARCODE_ITF: @@ -982,17 +982,17 @@ uint8_t USBHostPrinterLanguageESCPOS( uint8_t address, // calculate and print the checkdigit for this format. { uint16_t sum = 0; - + for (j=0; j PIC18: defines as nothing
PIC24: defines as U1PWRCbits.USBPWR = 1;
- + Precondition: None - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBPowerModule() /**************************************************************** Function: USBSetBDTAddress(addr) - + Description: This macro is used to power up the USB module if required - + Precondition: None - + Parameters: None - + Return Values: None - + Remarks: None - + ****************************************************************/ #define USBSetBDTAddress(addr) #define USBPingPongBufferReset UCONbits.PPBRST