Use USB_DEVICE_CONFIG_HID as a single source of truth and replace USB_COMPOSITE_INTERFACE_COUNT with it.

This commit is contained in:
László Monda
2016-03-03 23:55:58 +01:00
parent 22e36dc030
commit a988afe1ea
8 changed files with 11 additions and 13 deletions

View File

@@ -7,7 +7,7 @@
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param);
usb_composite_device_t UsbCompositeDevice;
usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_COMPOSITE_INTERFACE_COUNT] = {
usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_DEVICE_CONFIG_HID] = {
{UsbGenericHidCallback, (class_handle_t)NULL, &UsbGenericHidClass},
{UsbKeyboardCallback, (class_handle_t)NULL, &UsbKeyboardClass},
{UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass},
@@ -16,7 +16,7 @@ usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_COMPOSITE_INT
usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = {
UsbDeviceCompositeClassConfig,
UsbDeviceCallback,
USB_COMPOSITE_INTERFACE_COUNT
USB_DEVICE_CONFIG_HID
};
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param)
@@ -50,7 +50,7 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event,
if (UsbCompositeDevice.attach) {
uint8_t interface = (uint8_t)((*temp16 & 0xFF00U) >> 8);
uint8_t alternateSetting = (uint8_t)(*temp16 & 0x00FF);
if (interface < USB_COMPOSITE_INTERFACE_COUNT) {
if (interface < USB_DEVICE_CONFIG_HID) {
UsbCompositeDevice.currentInterfaceAlternateSetting[interface] = alternateSetting;
UsbGenericHidSetInterface(UsbCompositeDevice.genericHidHandle, interface, alternateSetting);
UsbKeyboardSetInterface(UsbCompositeDevice.keyboardHandle, interface, alternateSetting);
@@ -61,7 +61,7 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event,
break;
case kUSB_DeviceEventGetInterface: ;
uint8_t interface = (uint8_t)((*temp16 & 0xFF00) >> 8);
if (interface < USB_COMPOSITE_INTERFACE_COUNT) {
if (interface < USB_DEVICE_CONFIG_HID) {
*temp16 = (*temp16 & 0xFF00) | UsbCompositeDevice.currentInterfaceAlternateSetting[interface];
error = kStatus_USB_Success;
} else {

View File

@@ -19,7 +19,7 @@
class_handle_t genericHidHandle;
uint8_t attach;
uint8_t currentConfiguration;
uint8_t currentInterfaceAlternateSetting[USB_COMPOSITE_INTERFACE_COUNT];
uint8_t currentInterfaceAlternateSetting[USB_DEVICE_CONFIG_HID];
} usb_composite_device_t;
// Variables:

View File

@@ -11,7 +11,7 @@ uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] =
USB_DESCRIPTOR_TYPE_CONFIGURE,
USB_SHORT_GET_LOW(USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH),
USB_SHORT_GET_HIGH(USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH),
USB_COMPOSITE_INTERFACE_COUNT,
USB_DEVICE_CONFIG_HID,
USB_COMPOSITE_CONFIGURATION_INDEX,
USB_STRING_DESCRIPTOR_NONE,
(USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) |

View File

@@ -17,9 +17,6 @@
#define USB_DEVICE_CONFIGURATION_COUNT 1
#define USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE 1
#define USB_DEVICE_MAX_POWER 50 // Expressed in 2mA units
#define USB_COMPOSITE_INTERFACE_COUNT (USB_KEYBOARD_INTERFACE_COUNT + \
USB_MOUSE_INTERFACE_COUNT + \
USB_GENERIC_HID_INTERFACE_COUNT)
#define USB_CLASS_HID 0x03
#define USB_HID_COUNTRY_CODE_NOT_SUPPORTED 0x00

View File

@@ -8,7 +8,11 @@
#define USB_DEVICE_CONFIG_NUM 1
// HID instance count
#define USB_DEVICE_CONFIG_HID 3
#define USB_KEYBOARD_INTERFACE_COUNT 1
#define USB_MOUSE_INTERFACE_COUNT 1
#define USB_GENERIC_HID_INTERFACE_COUNT 1
#define USB_DEVICE_CONFIG_HID \
(USB_KEYBOARD_INTERFACE_COUNT + USB_MOUSE_INTERFACE_COUNT + USB_GENERIC_HID_INTERFACE_COUNT)
// Whether the device is self-powered: 1 supported, 0 not supported
#define USB_DEVICE_CONFIG_SELF_POWER 1

View File

@@ -9,7 +9,6 @@
// Macros:
#define USB_GENERIC_HID_INTERFACE_INDEX 0
#define USB_GENERIC_HID_INTERFACE_COUNT 1
#define USB_GENERIC_HID_ENDPOINT_IN_INDEX 3
#define USB_GENERIC_HID_ENDPOINT_OUT_INDEX 4

View File

@@ -9,7 +9,6 @@
// Macros:
#define USB_KEYBOARD_INTERFACE_INDEX 1
#define USB_KEYBOARD_INTERFACE_COUNT 1
#define USB_KEYBOARD_ENDPOINT_INDEX 2
#define USB_KEYBOARD_ENDPOINT_COUNT 1

View File

@@ -4,7 +4,6 @@
// Macros:
#define USB_MOUSE_INTERFACE_INDEX 2
#define USB_MOUSE_INTERFACE_COUNT 1
#define USB_MOUSE_ENDPOINT_INDEX 1
#define USB_MOUSE_ENDPOINT_COUNT 1