Added multiple Report ID support to the HID class driver. Removed OUT endpoint support from HID driver (all OUT reports are now processed through control requests) as a seperate endpoint had issues with determining the exact output report length.

This commit is contained in:
Dean Camera 2009-06-05 02:23:31 +00:00
parent 7665bf323e
commit 3d1baa6f95
23 changed files with 96 additions and 128 deletions

View file

@ -169,7 +169,7 @@ uint8_t USB_CDC_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
return DataByte;
}
void USB_CDC_SendSerialLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask)
void USB_CDC_SendSerialLineStateChange(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask)
{
Endpoint_SelectEndpoint(CDCInterfaceInfo->NotificationEndpointNumber);

View file

@ -167,7 +167,7 @@
uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
uint8_t ControlLineState; /**< Current control line state, as set by the host */
uint8_t ControlLineState; /**< Current control line states, as set by the host */
struct
{
@ -195,7 +195,7 @@
* \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration containing the
* given CDC interface is selected.
*
* \param CDCInterfaceInfo Pointer to a structure containing an CDC Class configuration and state.
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*
* \return Boolean true if the endpoints were sucessfully configured, false otherwise
*/
@ -204,25 +204,41 @@
/** Processes incomming control requests from the host, that are directed to the given CDC class interface. This should be
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
*
* \param CDCInterfaceInfo Pointer to a structure containing an CDC Class configuration and state.
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
/** General management task for a given CDC class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param CDCInterfaceInfo Pointer to a structure containing an CDC Class configuration and state.
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void USB_CDC_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
void EVENT_USB_CDC_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
void EVENT_USB_CDC_ControLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
/** CDC class driver event for a line encoding change on a CDC interface. This event fires each time the host requests a
* line encoding change (containing the serial parity, baud and other configuration information) and may be hooked in the
* user program by declaring a handler function with the same name and parameters listed here. The new line encoding
* settings are available in the LineEncoding structure inside the CDC interface structure passed as a parameter.
*
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void EVENT_USB_CDC_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
/** CDC class driver event for a control line state change on a CDC interface. This event fires each time the host requests a
* control line state change (containing the virtual serial control line states, such as DTR) and may be hooked in the
* user program by declaring a handler function with the same name and parameters listed here. The new control line states
* are available in the ControlLineState value inside the CDC interface structure passed as a parameter, set as a mask of
* CDC_CONTROL_LINE_OUT_* masks.
*
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void EVENT_USB_CDC_ControLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
void USB_CDC_SendString(USB_ClassInfo_CDC_t* CDCInterfaceInfo, char* Data, uint16_t Length);
void USB_CDC_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data);
uint16_t USB_CDC_BytesReceived(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
uint8_t USB_CDC_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
void USB_CDC_SendSerialLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask);
void USB_CDC_SendSerialLineStateChange(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask);
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)

View file

@ -47,10 +47,11 @@ void USB_HID_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
uint8_t ReportINData[HIDInterfaceInfo->ReportINBufferSize];
uint16_t ReportINSize;
uint8_t ReportID = (USB_ControlRequest.wValue & 0xFF);
memset(ReportINData, 0, sizeof(ReportINData));
ReportINSize = CALLBACK_USB_HID_CreateNextHIDReport(HIDInterfaceInfo, ReportINData);
ReportINSize = CALLBACK_USB_HID_CreateNextHIDReport(HIDInterfaceInfo, &ReportID, ReportINData);
Endpoint_Write_Control_Stream_LE(ReportINData, ReportINSize);
Endpoint_ClearOUT();
@ -64,11 +65,12 @@ void USB_HID_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
uint16_t ReportOUTSize = USB_ControlRequest.wLength;
uint8_t ReportOUTData[ReportOUTSize];
uint8_t ReportID = (USB_ControlRequest.wValue & 0xFF);
Endpoint_Read_Control_Stream_LE(ReportOUTData, ReportOUTSize);
Endpoint_ClearIN();
CALLBACK_USB_HID_ProcessReceivedHIDReport(HIDInterfaceInfo, ReportOUTData, ReportOUTSize);
CALLBACK_USB_HID_ProcessReceivedHIDReport(HIDInterfaceInfo, ReportID, ReportOUTData, ReportOUTSize);
}
break;
@ -135,15 +137,6 @@ bool USB_HID_ConfigureEndpoints(USB_ClassInfo_HID_t* HIDInterfaceInfo)
return false;
}
if (HIDInterfaceInfo->ReportOUTEndpointNumber)
{
if (!(Endpoint_ConfigureEndpoint(HIDInterfaceInfo->ReportOUTEndpointNumber, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_OUT, HIDInterfaceInfo->ReportOUTEndpointSize, ENDPOINT_BANK_SINGLE)))
{
return false;
}
}
return true;
}
@ -162,32 +155,20 @@ void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo)
uint8_t ReportINData[HIDInterfaceInfo->ReportINBufferSize];
uint16_t ReportINSize;
uint8_t ReportID = 0;
memset(ReportINData, 0, sizeof(ReportINData));
ReportINSize = CALLBACK_USB_HID_CreateNextHIDReport(HIDInterfaceInfo, ReportINData);
ReportINSize = CALLBACK_USB_HID_CreateNextHIDReport(HIDInterfaceInfo, &ReportID, ReportINData);
if (ReportINSize)
Endpoint_Write_Stream_LE(ReportINData, ReportINSize, NO_STREAM_CALLBACK);
{
if (ReportID)
Endpoint_Write_Stream_LE(&ReportID, sizeof(ReportID), NO_STREAM_CALLBACK);
Endpoint_Write_Stream_LE(ReportINData, ReportINSize, NO_STREAM_CALLBACK);
}
Endpoint_ClearIN();
}
if (HIDInterfaceInfo->ReportOUTEndpointNumber)
{
Endpoint_SelectEndpoint(HIDInterfaceInfo->ReportOUTEndpointNumber);
if (Endpoint_IsOUTReceived())
{
uint16_t ReportOUTSize = Endpoint_BytesInEndpoint();
uint8_t ReportOUTData[ReportOUTSize];
if (ReportOUTSize)
Endpoint_Read_Stream_LE(ReportOUTData, ReportOUTSize, NO_STREAM_CALLBACK);
CALLBACK_USB_HID_ProcessReceivedHIDReport(HIDInterfaceInfo, ReportOUTData, ReportOUTSize);
Endpoint_ClearOUT();
}
}
}

View file

@ -111,9 +111,6 @@
uint8_t ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */
uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */
uint8_t ReportOUTEndpointNumber; /**< Endpoint number of the HID interface's OUT report endpoint, if used */
uint16_t ReportOUTEndpointSize; /**< Size in bytes of the HID interface's OUT report endpoint, if used */
uint8_t ReportINBufferSize;
@ -127,8 +124,30 @@
void USB_HID_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo);
void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo);
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData, uint16_t ReportSize);
/** HID class driver callback for the user creation of a HID input report. This callback may fire in response to either
* HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback the
* user is responsible for the creation of the next HID input report to be sent to the host.
*
* \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
* \param ReportID If preset to a non-zero value, this is the report ID being requested by the host. If zero, this should
* be set to the report ID of the generated HID input report. If multiple reports are not sent via the
* given HID interface, this parameter should be ignored.
* \param ReportData Pointer to a buffer where the generated HID report should be stored.
*
* \return Number of bytes in the generated input report, or zero if no report is to be sent
*/
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
/** HID class driver callback for the user processing of a received HID input report. This callback may fire in response to
* either HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback
* the user is responsible for the processing of the received HID output report from the host.
*
* \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
* \param ReportID Report ID of the received output report. If multiple reports are not received via the given HID
* interface, this parameter should be ignored.
* \param ReportData Pointer to a buffer where the received HID report is stored.
*/
void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID, void* ReportData, uint16_t ReportSize);
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)

View file

@ -76,7 +76,7 @@
/** MIDI command for a note off (deactivation) event */
#define MIDI_COMMAND_NOTE_OFF 0x08
/** Standard key press velocity value used for all note events, as no pressure sensor is mounted */
/** Standard key press velocity value used for all note events */
#define MIDI_STANDARD_VELOCITY 64
/** Convenience macro. MIDI channels are numbered from 1-10 (natural numbers) however the logical channel