Restructure the codebase across more files.

This commit is contained in:
László Monda
2016-02-29 20:44:53 +01:00
parent 3ddd75db3a
commit ba1aee598d
27 changed files with 494 additions and 328 deletions

View File

@@ -185,85 +185,135 @@
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/composite.h</locationURI>
</link>
<link>
<name>sources/hid_generic.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/hid_generic.c</locationURI>
</link>
<link>
<name>sources/hid_generic.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/hid_generic.h</locationURI>
</link>
<link>
<name>sources/hid_keyboard.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/hid_keyboard.c</locationURI>
</link>
<link>
<name>sources/hid_keyboard.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/hid_keyboard.h</locationURI>
</link>
<link>
<name>sources/hid_mouse.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/hid_mouse.c</locationURI>
</link>
<link>
<name>sources/hid_mouse.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/hid_mouse.h</locationURI>
</link>
<link>
<name>sources/scancodes.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/scancodes.h</locationURI>
</link>
<link>
<name>sources/usb_class_generic_hid.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_class_generic_hid.c</locationURI>
</link>
<link>
<name>sources/usb_class_generic_hid.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_class_generic_hid.h</locationURI>
</link>
<link>
<name>sources/usb_class_keyboard.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_class_keyboard.c</locationURI>
</link>
<link>
<name>sources/usb_class_keyboard.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_class_keyboard.h</locationURI>
</link>
<link>
<name>sources/usb_class_mouse.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_class_mouse.c</locationURI>
</link>
<link>
<name>sources/usb_class_mouse.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_class_mouse.h</locationURI>
</link>
<link>
<name>sources/usb_descriptor_configuration.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_configuration.c</locationURI>
</link>
<link>
<name>sources/usb_descriptor_configuration.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_configuration.h</locationURI>
</link>
<link>
<name>sources/usb_descriptor_device.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_device.c</locationURI>
</link>
<link>
<name>sources/usb_descriptor_device.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_device.h</locationURI>
</link>
<link>
<name>sources/usb_descriptor_generic_hid_report.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_generic_hid_report.c</locationURI>
</link>
<link>
<name>sources/usb_descriptor_generic_hid_report.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_generic_hid_report.h</locationURI>
</link>
<link>
<name>sources/usb_descriptor_keyboard_report.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_keyboard_report.c</locationURI>
</link>
<link>
<name>sources/usb_descriptor_keyboard_report.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_keyboard_report.h</locationURI>
</link>
<link>
<name>sources/usb_descriptor_mouse_report.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_mouse_report.c</locationURI>
</link>
<link>
<name>sources/usb_descriptor_mouse_report.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_mouse_report.h</locationURI>
</link>
<link>
<name>sources/usb_descriptor_strings.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_strings.c</locationURI>
</link>
<link>
<name>sources/usb_descriptor_strings.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_descriptor_strings.h</locationURI>
</link>
<link>
<name>sources/usb_device_config.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_device_config.h</locationURI>
</link>
<link>
<name>sources/usb_device_descriptor.c</name>
<name>sources/usb_interface_generic_hid.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_device_descriptor.c</locationURI>
<locationURI>PARENT-2-PROJECT_LOC/usb_interface_generic_hid.c</locationURI>
</link>
<link>
<name>sources/usb_device_descriptor.h</name>
<name>sources/usb_interface_generic_hid.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_device_descriptor.h</locationURI>
<locationURI>PARENT-2-PROJECT_LOC/usb_interface_generic_hid.h</locationURI>
</link>
<link>
<name>sources/usb_generic_hid_descriptors.c</name>
<name>sources/usb_interface_keyboard.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_generic_hid_descriptors.c</locationURI>
<locationURI>PARENT-2-PROJECT_LOC/usb_interface_keyboard.c</locationURI>
</link>
<link>
<name>sources/usb_generic_hid_descriptors.h</name>
<name>sources/usb_interface_keyboard.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_generic_hid_descriptors.h</locationURI>
<locationURI>PARENT-2-PROJECT_LOC/usb_interface_keyboard.h</locationURI>
</link>
<link>
<name>sources/usb_keyboard_descriptors.c</name>
<name>sources/usb_interface_mouse.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_keyboard_descriptors.c</locationURI>
<locationURI>PARENT-2-PROJECT_LOC/usb_interface_mouse.c</locationURI>
</link>
<link>
<name>sources/usb_keyboard_descriptors.h</name>
<name>sources/usb_interface_mouse.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_keyboard_descriptors.h</locationURI>
</link>
<link>
<name>sources/usb_mouse_descriptors.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_mouse_descriptors.c</locationURI>
</link>
<link>
<name>sources/usb_mouse_descriptors.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/usb_mouse_descriptors.h</locationURI>
<locationURI>PARENT-2-PROJECT_LOC/usb_interface_mouse.h</locationURI>
</link>
<link>
<name>startup/startup_MK22F51212.S</name>

View File

@@ -4,11 +4,11 @@
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "include/usb/usb_device_ch9.h"
#include "usb_device_descriptor.h"
#include "usb_descriptor_device.h"
#include "composite.h"
#include "hid_keyboard.h"
#include "hid_mouse.h"
#include "hid_generic.h"
#include "usb_interface_keyboard.h"
#include "usb_interface_mouse.h"
#include "usb_interface_generic_hid.h"
#include "fsl_device_registers.h"
#include "include/board/clock_config.h"
#include "include/board/board.h"
@@ -17,9 +17,10 @@
#include <stdlib.h>
#include "fsl_common.h"
#include "include/board/pin_mux.h"
#include "usb_keyboard_descriptors.h"
#include "usb_mouse_descriptors.h"
#include "usb_generic_hid_descriptors.h"
#include "usb_class_keyboard.h"
#include "usb_class_mouse.h"
#include "usb_class_generic_hid.h"
#include "usb_descriptor_strings.h"
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param);
usb_device_composite_struct_t UsbCompositeDevice;

View File

@@ -1,6 +1,10 @@
#ifndef __USB_DEVICE_COMPOSITE_H__
#define __USB_DEVICE_COMPOSITE_H__
// Includes:
#include "usb_descriptor_configuration.h"
// Macros:
#define CONTROLLER_ID kUSB_ControllerKhci0

View File

@@ -3,8 +3,8 @@
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_device_descriptor.h"
#include "usb_generic_hid_descriptors.h"
#include "usb_descriptor_device.h"
#include "usb_class_generic_hid.h"
static usb_device_endpoint_struct_t UsbGenericHidEndpoints[USB_GENERIC_HID_ENDPOINT_COUNT] =
{
@@ -21,7 +21,7 @@ static usb_device_endpoint_struct_t UsbGenericHidEndpoints[USB_GENERIC_HID_ENDPO
};
static usb_device_interface_struct_t UsbGenericHidInterface[] = {{
USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING,
USB_GENERIC_HID_INTERFACE_ALTERNATE_SETTING,
{USB_GENERIC_HID_ENDPOINT_COUNT, UsbGenericHidEndpoints},
NULL,
}};
@@ -45,25 +45,3 @@ usb_device_class_struct_t UsbGenericHidClass = {
kUSB_DeviceClassTypeHid,
USB_DEVICE_CONFIGURATION_COUNT,
};
uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH] = {
0x05U, 0x81U, /* Usage Page (Vendor defined)*/
0x09U, 0x82U, /* Usage (Vendor defined) */
0xA1U, 0x01U, /* Collection (Application) */
0x09U, 0x83U, /* Usage (Vendor defined) */
0x09U, 0x84U, /* Usage (Vendor defined) */
0x15U, 0x80U, /* Logical Minimum (-128) */
0x25U, 0x7FU, /* Logical Maximum (127) */
0x75U, 0x08U, /* Report Size (8U) */
0x95U, 0x08U, /* Report Count (8U) */
0x81U, 0x02U, /* Input(Data, Variable, Absolute) */
0x09U, 0x84U, /* Usage (Vendor defined) */
0x15U, 0x80U, /* logical Minimum (-128) */
0x25U, 0x7FU, /* logical Maximum (127) */
0x75U, 0x08U, /* Report Size (8U) */
0x95U, 0x08U, /* Report Count (8U) */
0x91U, 0x02U, /* Input (Data, Variable, Absolute) */
0xC0U, /* End collection */
};

View File

@@ -1,5 +1,5 @@
#ifndef __USB_GENERIC_HID_DESCRIPTORS_H__
#define __USB_GENERIC_HID_DESCRIPTORS_H__
#ifndef __USB_CLASS_GENERIC_HID_H__
#define __USB_CLASS_GENERIC_HID_H__
// Macros:
@@ -20,13 +20,8 @@
#define USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE (64U)
#define USB_GENERIC_HID_INTERRUPT_OUT_INTERVAL (0x04U)
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH (33U)
#define USB_GENERIC_HID_STRING_DESCRIPTOR_LENGTH (38U)
// Variables:
extern usb_device_class_struct_t UsbGenericHidClass;
extern uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH];
extern uint8_t UsbGenericHidString[USB_GENERIC_HID_STRING_DESCRIPTOR_LENGTH];
#endif

View File

@@ -0,0 +1,39 @@
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_descriptor_device.h"
#include "usb_class_keyboard.h"
static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{
USB_KEYBOARD_ENDPOINT_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
}};
static usb_device_interface_struct_t UsbKeyboardInterface[] = {{
USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING,
{USB_KEYBOARD_ENDPOINT_COUNT, UsbKeyboardEndpoints},
NULL,
}};
static usb_device_interfaces_struct_t UsbKeyboardInterfaces[USB_KEYBOARD_INTERFACE_COUNT] = {{
USB_KEYBOARD_CLASS,
USB_KEYBOARD_SUBCLASS,
USB_KEYBOARD_PROTOCOL,
USB_KEYBOARD_INTERFACE_INDEX,
UsbKeyboardInterface,
sizeof(UsbKeyboardInterface) / sizeof(usb_device_interfaces_struct_t),
}};
static usb_device_interface_list_t UsbKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
USB_KEYBOARD_INTERFACE_COUNT,
UsbKeyboardInterfaces,
}};
usb_device_class_struct_t UsbKeyboardClass = {
UsbKeyboardInterfaceList,
kUSB_DeviceClassTypeHid,
USB_DEVICE_CONFIGURATION_COUNT,
};

View File

@@ -1,5 +1,5 @@
#ifndef __USB_KEYBOARD_DESCRIPTORS_H__
#define __USB_KEYBOARD_DESCRIPTORS_H__
#ifndef __USB_CLASS_KEYBOARD_H__
#define __USB_CLASS_KEYBOARD_H__
// Macros:
@@ -17,13 +17,8 @@
#define USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U)
#define USB_KEYBOARD_INTERRUPT_IN_INTERVAL (0x04U)
#define USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH (63U)
#define USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH (40U)
// Variables:
extern usb_device_class_struct_t UsbKeyboardClass;
extern uint8_t UsbKeyboardReportDescriptor[USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH];
extern uint8_t UsbKeyboardString[USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH];
#endif

40
right/usb_class_mouse.c Normal file
View File

@@ -0,0 +1,40 @@
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_descriptor_device.h"
#include "composite.h"
#include "usb_class_mouse.h"
static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{
USB_MOUSE_ENDPOINT_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_MOUSE_INTERRUPT_IN_PACKET_SIZE,
}};
static usb_device_interface_struct_t UsbMouseInterface[] = {{
USB_MOUSE_INTERFACE_ALTERNATE_SETTING,
{USB_MOUSE_ENDPOINT_COUNT, UsbMouseEndpoints},
NULL,
}};
static usb_device_interfaces_struct_t UsbMouseInterfaces[USB_MOUSE_INTERFACE_COUNT] = {{
USB_MOUSE_CLASS,
USB_MOUSE_SUBCLASS,
USB_MOUSE_PROTOCOL,
USB_MOUSE_INTERFACE_INDEX,
UsbMouseInterface,
sizeof(UsbMouseInterface) / sizeof(usb_device_interfaces_struct_t),
}};
static usb_device_interface_list_t UsbMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
USB_MOUSE_INTERFACE_COUNT,
UsbMouseInterfaces,
}};
usb_device_class_struct_t UsbMouseClass = {
UsbMouseInterfaceList,
kUSB_DeviceClassTypeHid,
USB_DEVICE_CONFIGURATION_COUNT,
};

View File

@@ -1,5 +1,5 @@
#ifndef __USB_MOUSE_DESCRIPTORS_H__
#define __USB_MOUSE_DESCRIPTORS_H__
#ifndef __USB_CLASS_MOUSE_H__
#define __USB_CLASS_MOUSE_H__
// Macros:
@@ -17,13 +17,8 @@
#define USB_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U)
#define USB_MOUSE_INTERRUPT_IN_INTERVAL (0x04U)
#define USB_MOUSE_REPORT_DESCRIPTOR_LENGTH (52U)
#define USB_MOUSE_STRING_DESCRIPTOR_LENGTH (34U)
// Variables:
extern usb_device_class_struct_t UsbMouseClass;
extern uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH];
extern uint8_t UsbMouseString[USB_MOUSE_STRING_DESCRIPTOR_LENGTH];
#endif

View File

@@ -3,32 +3,15 @@
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_device_descriptor.h"
#include "usb_descriptor_device.h"
#include "composite.h"
#include "hid_keyboard.h"
#include "hid_mouse.h"
#include "hid_generic.h"
uint8_t UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = {
USB_DESCRIPTOR_LENGTH_DEVICE,
USB_DESCRIPTOR_TYPE_DEVICE,
USB_SHORT_GET_LOW(USB_DEVICE_SPECIFICATION_VERSION),
USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFICATION_VERSION),
USB_DEVICE_CLASS,
USB_DEVICE_SUBCLASS,
USB_DEVICE_PROTOCOL,
USB_CONTROL_MAX_PACKET_SIZE,
USB_SHORT_GET_LOW(USB_DEVICE_VENDOR_ID),
USB_SHORT_GET_HIGH(USB_DEVICE_VENDOR_ID),
USB_SHORT_GET_LOW(USB_DEVICE_PRODUCT_ID),
USB_SHORT_GET_HIGH(USB_DEVICE_PRODUCT_ID),
USB_SHORT_GET_LOW(USB_DEVICE_RELEASE_NUMBER),
USB_SHORT_GET_HIGH(USB_DEVICE_RELEASE_NUMBER),
USB_STRING_DESCRIPTOR_ID_MANUFACTURER,
USB_STRING_DESCRIPTOR_ID_PRODUCT,
USB_STRING_DESCRIPTOR_ID_SUPPORTED_LANGUAGES,
USB_DEVICE_CONFIGURATION_COUNT,
};
#include "usb_class_keyboard.h"
#include "usb_class_mouse.h"
#include "usb_class_generic_hid.h"
#include "usb_descriptor_keyboard_report.h"
#include "usb_descriptor_mouse_report.h"
#include "usb_descriptor_generic_hid_report.h"
#include "usb_descriptor_configuration.h"
uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] = {
@@ -159,87 +142,6 @@ uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] =
USB_GENERIC_HID_INTERRUPT_IN_INTERVAL,
};
uint8_t UsbLanguageListStringDescriptor[USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH] = {
sizeof(UsbLanguageListStringDescriptor),
USB_DESCRIPTOR_TYPE_STRING,
USB_SHORT_GET_LOW(USB_LANGUAGE_ID_UNITED_STATES),
USB_SHORT_GET_HIGH(USB_LANGUAGE_ID_UNITED_STATES)
};
uint8_t UsbManufacturerString[USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH] = {
sizeof(UsbManufacturerString),
USB_DESCRIPTOR_TYPE_STRING,
'F', 0x00U,
'R', 0x00U,
'E', 0x00U,
'E', 0x00U,
'S', 0x00U,
'C', 0x00U,
'A', 0x00U,
'L', 0x00U,
'E', 0x00U,
' ', 0x00U,
'S', 0x00U,
'E', 0x00U,
'M', 0x00U,
'I', 0x00U,
'C', 0x00U,
'O', 0x00U,
'N', 0x00U,
'D', 0x00U,
'U', 0x00U,
'C', 0x00U,
'T', 0x00U,
'O', 0x00U,
'R', 0x00U,
' ', 0x00U,
'I', 0x00U,
'N', 0x00U,
'C', 0x00U,
'.', 0x00U,
};
uint8_t UsbProductString[USB_PRODUCT_STRING_DESCRIPTOR_LENGTH] = {
sizeof(UsbProductString),
USB_DESCRIPTOR_TYPE_STRING,
'C', 0x00U,
'O', 0x00U,
'M', 0x00U,
'P', 0x00U,
'O', 0x00U,
'S', 0x00U,
'I', 0x00U,
'T', 0x00U,
'E', 0x00U,
' ', 0x00U,
'D', 0x00U,
'E', 0x00U,
'V', 0x00U,
'I', 0x00U,
'C', 0x00U,
'E', 0x00U,
};
uint32_t UsbStringDescriptorLengths[USB_STRING_DESCRIPTOR_COUNT] = {
sizeof(UsbLanguageListStringDescriptor),
sizeof(UsbManufacturerString),
sizeof(UsbProductString),
};
uint8_t *UsbStringDescriptors[USB_STRING_DESCRIPTOR_COUNT] = {
UsbLanguageListStringDescriptor,
UsbManufacturerString,
UsbProductString,
};
usb_status_t USB_DeviceGetDeviceDescriptor(
usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor)
{
deviceDescriptor->buffer = UsbDeviceDescriptor;
deviceDescriptor->length = USB_DESCRIPTOR_LENGTH_DEVICE;
return kStatus_USB_Success;
}
usb_status_t USB_DeviceGetConfigurationDescriptor(
usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor)
{
@@ -251,23 +153,6 @@ usb_status_t USB_DeviceGetConfigurationDescriptor(
return kStatus_USB_InvalidRequest;
}
usb_status_t USB_DeviceGetStringDescriptor(
usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor)
{
if (stringDescriptor->stringIndex == 0U) {
stringDescriptor->buffer = UsbLanguageListStringDescriptor;
stringDescriptor->length = sizeof(UsbLanguageListStringDescriptor);
} else if (stringDescriptor->languageId == USB_LANGUAGE_ID_UNITED_STATES &&
stringDescriptor->stringIndex < USB_STRING_DESCRIPTOR_COUNT)
{
stringDescriptor->buffer = UsbStringDescriptors[stringDescriptor->stringIndex];
stringDescriptor->length = UsbStringDescriptorLengths[stringDescriptor->stringIndex];
} else {
return kStatus_USB_InvalidRequest;
}
return kStatus_USB_Success;
}
usb_status_t USB_DeviceGetHidDescriptor(
usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor)
{

View File

@@ -1,11 +1,11 @@
#ifndef __USB_DEVICE_DESCRIPTOR_H__
#define __USB_DEVICE_DESCRIPTOR_H__
#ifndef __USB_DESCRIPTOR_CONFIGURATION_H__
#define __USB_DESCRIPTOR_CONFIGURATION_H__
// Includes:
#include "usb_keyboard_descriptors.h"
#include "usb_mouse_descriptors.h"
#include "usb_generic_hid_descriptors.h"
#include "usb_class_keyboard.h"
#include "usb_class_mouse.h"
#include "usb_class_generic_hid.h"
// Macros:
@@ -38,29 +38,11 @@
#define USB_HID_DESCRIPTOR_LENGTH (9U)
#define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH (91U)
// String descriptors
#define USB_STRING_DESCRIPTOR_COUNT (3U)
#define USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH (4U)
#define USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH (58U)
#define USB_PRODUCT_STRING_DESCRIPTOR_LENGTH (34U)
#define USB_STRING_DESCRIPTOR_ID_SUPPORTED_LANGUAGES 0U
#define USB_STRING_DESCRIPTOR_ID_MANUFACTURER 1U
#define USB_STRING_DESCRIPTOR_ID_PRODUCT 2U
// Functions:
extern usb_status_t USB_DeviceGetDeviceDescriptor(
usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor);
extern usb_status_t USB_DeviceGetConfigurationDescriptor(
usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor);
extern usb_status_t USB_DeviceGetStringDescriptor(
usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor);
extern usb_status_t USB_DeviceGetHidDescriptor(
usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor);

View File

@@ -0,0 +1,40 @@
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_descriptor_device.h"
#include "composite.h"
#include "usb_class_keyboard.h"
#include "usb_class_mouse.h"
#include "usb_class_generic_hid.h"
#include "usb_descriptor_strings.h"
uint8_t UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = {
USB_DESCRIPTOR_LENGTH_DEVICE,
USB_DESCRIPTOR_TYPE_DEVICE,
USB_SHORT_GET_LOW(USB_DEVICE_SPECIFICATION_VERSION),
USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFICATION_VERSION),
USB_DEVICE_CLASS,
USB_DEVICE_SUBCLASS,
USB_DEVICE_PROTOCOL,
USB_CONTROL_MAX_PACKET_SIZE,
USB_SHORT_GET_LOW(USB_DEVICE_VENDOR_ID),
USB_SHORT_GET_HIGH(USB_DEVICE_VENDOR_ID),
USB_SHORT_GET_LOW(USB_DEVICE_PRODUCT_ID),
USB_SHORT_GET_HIGH(USB_DEVICE_PRODUCT_ID),
USB_SHORT_GET_LOW(USB_DEVICE_RELEASE_NUMBER),
USB_SHORT_GET_HIGH(USB_DEVICE_RELEASE_NUMBER),
USB_STRING_DESCRIPTOR_ID_MANUFACTURER,
USB_STRING_DESCRIPTOR_ID_PRODUCT,
USB_STRING_DESCRIPTOR_ID_SUPPORTED_LANGUAGES,
USB_DEVICE_CONFIGURATION_COUNT,
};
usb_status_t USB_DeviceGetDeviceDescriptor(
usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor)
{
deviceDescriptor->buffer = UsbDeviceDescriptor;
deviceDescriptor->length = USB_DESCRIPTOR_LENGTH_DEVICE;
return kStatus_USB_Success;
}

View File

@@ -0,0 +1,44 @@
#ifndef __USB_DEVICE_DESCRIPTOR_H__
#define __USB_DEVICE_DESCRIPTOR_H__
// Includes:
#include "usb_class_keyboard.h"
#include "usb_class_mouse.h"
#include "usb_class_generic_hid.h"
// Macros:
#define USB_DEVICE_CLASS (0x00U)
#define USB_DEVICE_SUBCLASS (0x00U)
#define USB_DEVICE_PROTOCOL (0x00U)
#define USB_DEVICE_SPECIFICATION_VERSION (0x0200U)
#define USB_HID_VERSION (0x0100U)
#define USB_DEVICE_VENDOR_ID (0x15A2U)
#define USB_DEVICE_PRODUCT_ID (0x007EU)
#define USB_DEVICE_RELEASE_NUMBER (0x0101U)
#define USB_DEVICE_CONFIGURATION_COUNT (1U)
#define USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE (1U)
#define USB_DEVICE_MAX_POWER (50U) // Expressed in 2mA units
#define USB_COMPOSITE_INTERFACE_COUNT (USB_KEYBOARD_INTERFACE_COUNT + \
USB_MOUSE_INTERFACE_COUNT + \
USB_GENERIC_HID_INTERFACE_COUNT)
#define USB_HID_COUNTRY_CODE_NOT_SUPPORTED (0x00U)
#define USB_INTERFACE_ALTERNATE_SETTING_NONE (0x00U)
#define USB_STRING_DESCRIPTOR_NONE 0U
// Descriptor lengths
#define USB_HID_DESCRIPTOR_LENGTH (9U)
#define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH (91U)
// Functions:
extern usb_status_t USB_DeviceGetDeviceDescriptor(
usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor);
#endif

View File

@@ -0,0 +1,28 @@
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_descriptor_generic_hid_report.h"
uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH] = {
0x05U, 0x81U, /* Usage Page (Vendor defined)*/
0x09U, 0x82U, /* Usage (Vendor defined) */
0xA1U, 0x01U, /* Collection (Application) */
0x09U, 0x83U, /* Usage (Vendor defined) */
0x09U, 0x84U, /* Usage (Vendor defined) */
0x15U, 0x80U, /* Logical Minimum (-128) */
0x25U, 0x7FU, /* Logical Maximum (127) */
0x75U, 0x08U, /* Report Size (8U) */
0x95U, 0x08U, /* Report Count (8U) */
0x81U, 0x02U, /* Input(Data, Variable, Absolute) */
0x09U, 0x84U, /* Usage (Vendor defined) */
0x15U, 0x80U, /* logical Minimum (-128) */
0x25U, 0x7FU, /* logical Maximum (127) */
0x75U, 0x08U, /* Report Size (8U) */
0x95U, 0x08U, /* Report Count (8U) */
0x91U, 0x02U, /* Input (Data, Variable, Absolute) */
0xC0U, /* End collection */
};

View File

@@ -0,0 +1,12 @@
#ifndef __USB_DESCRIPTOR_GENERIC_HID_REPORT_H__
#define __USB_DESCRIPTOR_GENERIC_HID_REPORT_H__
// Macros:
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH (33U)
// Variables:
extern uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH];
#endif

View File

@@ -3,40 +3,7 @@
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_device_descriptor.h"
#include "usb_keyboard_descriptors.h"
static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{
USB_KEYBOARD_ENDPOINT_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
}};
static usb_device_interface_struct_t UsbKeyboardInterface[] = {{
USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING,
{USB_KEYBOARD_ENDPOINT_COUNT, UsbKeyboardEndpoints},
NULL,
}};
static usb_device_interfaces_struct_t UsbKeyboardInterfaces[USB_KEYBOARD_INTERFACE_COUNT] = {{
USB_KEYBOARD_CLASS,
USB_KEYBOARD_SUBCLASS,
USB_KEYBOARD_PROTOCOL,
USB_KEYBOARD_INTERFACE_INDEX,
UsbKeyboardInterface,
sizeof(UsbKeyboardInterface) / sizeof(usb_device_interfaces_struct_t),
}};
static usb_device_interface_list_t UsbKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
USB_KEYBOARD_INTERFACE_COUNT,
UsbKeyboardInterfaces,
}};
usb_device_class_struct_t UsbKeyboardClass = {
UsbKeyboardInterfaceList,
kUSB_DeviceClassTypeHid,
USB_DEVICE_CONFIGURATION_COUNT,
};
#include "usb_descriptor_keyboard_report.h"
uint8_t UsbKeyboardReportDescriptor[USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH] = {
0x05U, 0x01U, // Usage Page (Generic Desktop)

View File

@@ -0,0 +1,12 @@
#ifndef __USB_DESCRIPTOR_KEYBOARD_H__
#define __USB_DESCRIPTOR_KEYBOARD_H__
// Macros:
#define USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH (63U)
// Variables:
extern uint8_t UsbKeyboardReportDescriptor[USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH];
#endif

View File

@@ -3,42 +3,7 @@
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_device_descriptor.h"
#include "composite.h"
#include "hid_mouse.h"
#include "hid_keyboard.h"
static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{
USB_MOUSE_ENDPOINT_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_MOUSE_INTERRUPT_IN_PACKET_SIZE,
}};
static usb_device_interface_struct_t UsbMouseInterface[] = {{
USB_MOUSE_INTERFACE_ALTERNATE_SETTING,
{USB_MOUSE_ENDPOINT_COUNT, UsbMouseEndpoints},
NULL,
}};
static usb_device_interfaces_struct_t UsbMouseInterfaces[USB_MOUSE_INTERFACE_COUNT] = {{
USB_MOUSE_CLASS,
USB_MOUSE_SUBCLASS,
USB_MOUSE_PROTOCOL,
USB_MOUSE_INTERFACE_INDEX,
UsbMouseInterface,
sizeof(UsbMouseInterface) / sizeof(usb_device_interfaces_struct_t),
}};
static usb_device_interface_list_t UsbMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
USB_MOUSE_INTERFACE_COUNT,
UsbMouseInterfaces,
}};
usb_device_class_struct_t UsbMouseClass = {
UsbMouseInterfaceList,
kUSB_DeviceClassTypeHid,
USB_DEVICE_CONFIGURATION_COUNT,
};
#include "usb_descriptor_mouse_report.h"
uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH] = {
0x05U, 0x01U, // Usage Page (Generic Desktop)

View File

@@ -0,0 +1,12 @@
#ifndef __USB_DESCRIPTOR_MOUSE_REPORT_H__
#define __USB_DESCRIPTOR_MOUSE_REPORT_H__
// Macros:
#define USB_MOUSE_REPORT_DESCRIPTOR_LENGTH (52U)
// Variables:
extern uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH];
#endif

View File

@@ -0,0 +1,96 @@
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "usb_descriptor_strings.h"
uint8_t UsbLanguageListStringDescriptor[USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH] = {
sizeof(UsbLanguageListStringDescriptor),
USB_DESCRIPTOR_TYPE_STRING,
USB_SHORT_GET_LOW(USB_LANGUAGE_ID_UNITED_STATES),
USB_SHORT_GET_HIGH(USB_LANGUAGE_ID_UNITED_STATES)
};
uint8_t UsbManufacturerString[USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH] = {
sizeof(UsbManufacturerString),
USB_DESCRIPTOR_TYPE_STRING,
'F', 0x00U,
'R', 0x00U,
'E', 0x00U,
'E', 0x00U,
'S', 0x00U,
'C', 0x00U,
'A', 0x00U,
'L', 0x00U,
'E', 0x00U,
' ', 0x00U,
'S', 0x00U,
'E', 0x00U,
'M', 0x00U,
'I', 0x00U,
'C', 0x00U,
'O', 0x00U,
'N', 0x00U,
'D', 0x00U,
'U', 0x00U,
'C', 0x00U,
'T', 0x00U,
'O', 0x00U,
'R', 0x00U,
' ', 0x00U,
'I', 0x00U,
'N', 0x00U,
'C', 0x00U,
'.', 0x00U,
};
uint8_t UsbProductString[USB_PRODUCT_STRING_DESCRIPTOR_LENGTH] = {
sizeof(UsbProductString),
USB_DESCRIPTOR_TYPE_STRING,
'C', 0x00U,
'O', 0x00U,
'M', 0x00U,
'P', 0x00U,
'O', 0x00U,
'S', 0x00U,
'I', 0x00U,
'T', 0x00U,
'E', 0x00U,
' ', 0x00U,
'D', 0x00U,
'E', 0x00U,
'V', 0x00U,
'I', 0x00U,
'C', 0x00U,
'E', 0x00U,
};
uint32_t UsbStringDescriptorLengths[USB_STRING_DESCRIPTOR_COUNT] = {
sizeof(UsbLanguageListStringDescriptor),
sizeof(UsbManufacturerString),
sizeof(UsbProductString),
};
uint8_t *UsbStringDescriptors[USB_STRING_DESCRIPTOR_COUNT] = {
UsbLanguageListStringDescriptor,
UsbManufacturerString,
UsbProductString,
};
usb_status_t USB_DeviceGetStringDescriptor(
usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor)
{
if (stringDescriptor->stringIndex == 0U) {
stringDescriptor->buffer = UsbLanguageListStringDescriptor;
stringDescriptor->length = sizeof(UsbLanguageListStringDescriptor);
} else if (stringDescriptor->languageId == USB_LANGUAGE_ID_UNITED_STATES &&
stringDescriptor->stringIndex < USB_STRING_DESCRIPTOR_COUNT)
{
stringDescriptor->buffer = UsbStringDescriptors[stringDescriptor->stringIndex];
stringDescriptor->length = UsbStringDescriptorLengths[stringDescriptor->stringIndex];
} else {
return kStatus_USB_InvalidRequest;
}
return kStatus_USB_Success;
}

View File

@@ -0,0 +1,23 @@
#ifndef __USB_DESCRIPTOR_STRINGS_H__
#define __USB_DESCRIPTOR_STRINGS_H__
// Macros:
#define USB_LANGUAGE_ID_UNITED_STATES (0x0409U)
#define USB_STRING_DESCRIPTOR_COUNT (3U)
#define USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH (4U)
#define USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH (58U)
#define USB_PRODUCT_STRING_DESCRIPTOR_LENGTH (34U)
#define USB_STRING_DESCRIPTOR_ID_SUPPORTED_LANGUAGES 0U
#define USB_STRING_DESCRIPTOR_ID_MANUFACTURER 1U
#define USB_STRING_DESCRIPTOR_ID_PRODUCT 2U
// Functions:
extern usb_status_t USB_DeviceGetStringDescriptor(
usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor);
#endif

View File

@@ -6,10 +6,11 @@
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "include/usb/usb_device_ch9.h"
#include "usb_device_descriptor.h"
#include "usb_interface_generic_hid.h"
#include "usb_class_generic_hid.h"
#include "usb_descriptor_configuration.h"
#include "composite.h"
#include "scancodes.h"
#include "hid_generic.h"
static usb_device_generic_hid_struct_t UsbGenericHidDevice;

View File

@@ -6,10 +6,11 @@
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "include/usb/usb_device_ch9.h"
#include "usb_device_descriptor.h"
#include "composite.h"
#include "scancodes.h"
#include "hid_keyboard.h"
#include "usb_interface_keyboard.h"
#include "usb_class_keyboard.h"
#include "usb_descriptor_configuration.h"
static usb_device_hid_keyboard_struct_t UsbKeyboardDevice;

View File

@@ -6,9 +6,10 @@
#include "include/usb/usb_device_class.h"
#include "include/usb/usb_device_hid.h"
#include "include/usb/usb_device_ch9.h"
#include "usb_device_descriptor.h"
#include "composite.h"
#include "hid_mouse.h"
#include "usb_class_mouse.h"
#include "usb_interface_mouse.h"
#include "usb_descriptor_configuration.h"
static usb_device_hid_mouse_struct_t UsbMouseDevice;
@@ -60,7 +61,7 @@ usb_status_t UsbMouseSetConfiguration(class_handle_t handle, uint8_t configurati
usb_status_t UsbMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
{
if (USB_KEYBOARD_INTERFACE_INDEX == interface) {
if (USB_MOUSE_INTERFACE_INDEX == interface) {
return UsbMouseAction();
}
return kStatus_USB_Error;