Files
firmware/right/src/usb_interfaces/usb_interface_generic_hid.c
Kristian Sloth Lauszus edf34de4b5 Fixed comment
2018-06-30 23:23:12 +02:00

73 lines
2.3 KiB
C

#include "usb_composite_device.h"
#include "usb_protocol_handler.h"
uint32_t UsbGenericHidActionCounter;
uint8_t GenericHidInBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH];
uint8_t GenericHidOutBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
static usb_status_t UsbReceiveData(void)
{
if (!UsbCompositeDevice.attach) {
return kStatus_USB_Error; // The device is not attached
}
return USB_DeviceHidRecv(UsbCompositeDevice.genericHidHandle,
USB_GENERIC_HID_ENDPOINT_OUT_INDEX,
GenericHidInBuffer,
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
}
usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param)
{
usb_status_t error = kStatus_USB_Error;
switch (event) {
// This event is received when the report has been sent
case kUSB_DeviceHidEventSendResponse:
if (UsbCompositeDevice.attach) {
error = kStatus_USB_Success;
}
break;
case kUSB_DeviceHidEventRecvResponse:
UsbProtocolHandler();
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle,
USB_GENERIC_HID_ENDPOINT_IN_INDEX,
GenericHidOutBuffer,
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
UsbGenericHidActionCounter++;
return UsbReceiveData();
break;
case kUSB_DeviceHidEventGetReport:
case kUSB_DeviceHidEventSetReport:
case kUSB_DeviceHidEventRequestReportBuffer:
error = kStatus_USB_InvalidRequest;
break;
case kUSB_DeviceHidEventGetIdle:
case kUSB_DeviceHidEventGetProtocol:
case kUSB_DeviceHidEventSetIdle:
case kUSB_DeviceHidEventSetProtocol:
break;
default:
break;
}
return error;
}
usb_status_t UsbGenericHidSetConfiguration(class_handle_t handle, uint8_t configuration)
{
if (USB_COMPOSITE_CONFIGURATION_INDEX == configuration) {
return UsbReceiveData();
}
return kStatus_USB_Error;
}
usb_status_t UsbGenericHidSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
{
if (USB_GENERIC_HID_INTERFACE_INDEX == interface) {
return UsbReceiveData();
}
return kStatus_USB_Error;
}