Move usb_interface_*.[ch] files to the newly created usb_interfaces directory.

This commit is contained in:
László Monda
2017-02-26 02:45:43 +01:00
parent d12dc7d8a0
commit 6f6d116351
11 changed files with 9 additions and 9 deletions

View File

@@ -0,0 +1,102 @@
#include "usb_composite_device.h"
#include "usb_interface_generic_hid.h"
static usb_device_endpoint_struct_t UsbGenericHidEndpoints[USB_GENERIC_HID_ENDPOINT_COUNT] =
{
{
USB_GENERIC_HID_ENDPOINT_IN_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE,
},
{
USB_GENERIC_HID_ENDPOINT_OUT_INDEX | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
USB_ENDPOINT_INTERRUPT,
USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE,
}
};
static usb_device_interface_struct_t UsbGenericHidInterface[] = {{
USB_INTERFACE_ALTERNATE_SETTING_NONE,
{USB_GENERIC_HID_ENDPOINT_COUNT, UsbGenericHidEndpoints},
NULL,
}};
static usb_device_interfaces_struct_t UsbGenericHidInterfaces[USB_GENERIC_HID_INTERFACE_COUNT] = {{
USB_CLASS_HID,
USB_HID_SUBCLASS_NONE,
USB_HID_PROTOCOL_NONE,
USB_GENERIC_HID_INTERFACE_INDEX,
UsbGenericHidInterface,
sizeof(UsbGenericHidInterface) / sizeof(usb_device_interfaces_struct_t),
}};
static usb_device_interface_list_t UsbGenericHidInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
USB_GENERIC_HID_INTERFACE_COUNT,
UsbGenericHidInterfaces,
}};
usb_device_class_struct_t UsbGenericHidClass = {
UsbGenericHidInterfaceList,
kUSB_DeviceClassTypeHid,
USB_DEVICE_CONFIGURATION_COUNT,
};
uint8_t GenericHidInBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH];
uint8_t GenericHidOutBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
static usb_status_t UsbReceiveData()
{
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) {
case kUSB_DeviceHidEventSendResponse:
break;
case kUSB_DeviceHidEventRecvResponse:
usbProtocolHandler();
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle,
USB_GENERIC_HID_ENDPOINT_IN_INDEX,
GenericHidOutBuffer,
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
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;
}

View File

@@ -0,0 +1,39 @@
#ifndef __USB_INTERFACE_GENERIC_HID_H__
#define __USB_INTERFACE_GENERIC_HID_H__
// Includes:
#include "usb_api.h"
#include "usb_descriptor_device.h"
#include "usb_protocol_handler.h"
// Macros:
#define USB_GENERIC_HID_INTERFACE_INDEX 0
#define USB_GENERIC_HID_ENDPOINT_IN_INDEX 1
#define USB_GENERIC_HID_ENDPOINT_OUT_INDEX 2
#define USB_GENERIC_HID_ENDPOINT_COUNT 2
#define USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE 64
#define USB_GENERIC_HID_INTERRUPT_IN_INTERVAL 4
#define USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE 64
#define USB_GENERIC_HID_INTERRUPT_OUT_INTERVAL 4
#define USB_GENERIC_HID_IN_BUFFER_LENGTH 64
#define USB_GENERIC_HID_OUT_BUFFER_LENGTH 64
// Variables:
extern usb_device_class_struct_t UsbGenericHidClass;
extern uint8_t GenericHidInBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH];
extern uint8_t GenericHidOutBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
// Functions:
extern usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param);
extern usb_status_t UsbGenericHidSetConfiguration(class_handle_t handle, uint8_t configuration);
extern usb_status_t UsbGenericHidSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
#endif

View File

@@ -0,0 +1,109 @@
#include "main.h"
#include "action.h"
#include "fsl_port.h"
#include "usb_api.h"
#include "usb_composite_device.h"
#include "test_led.h"
#include "fsl_i2c.h"
#include "i2c.h"
#include "i2c_addresses.h"
static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{
USB_KEYBOARD_ENDPOINT_INDEX | (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_INTERFACE_ALTERNATE_SETTING_NONE,
{USB_KEYBOARD_ENDPOINT_COUNT, UsbKeyboardEndpoints},
NULL,
}};
static usb_device_interfaces_struct_t UsbKeyboardInterfaces[USB_KEYBOARD_INTERFACE_COUNT] = {{
USB_CLASS_HID,
USB_HID_SUBCLASS_BOOT,
USB_HID_PROTOCOL_KEYBOARD,
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,
};
static usb_keyboard_report_t usbKeyboardReports[2];
usb_keyboard_report_t* ActiveUsbKeyboardReport = usbKeyboardReports;
usb_keyboard_report_t* getInactiveUsbKeyboardReport()
{
return ActiveUsbKeyboardReport == usbKeyboardReports ? usbKeyboardReports+1 : usbKeyboardReports;
}
void SwitchActiveUsbKeyboardReport()
{
ActiveUsbKeyboardReport = getInactiveUsbKeyboardReport();
}
void ResetActiveUsbKeyboardReport()
{
bzero(ActiveUsbKeyboardReport, USB_KEYBOARD_REPORT_LENGTH);
}
static usb_status_t UsbKeyboardAction(void)
{
UpdateUsbReports();
return USB_DeviceHidSend(UsbCompositeDevice.keyboardHandle, USB_KEYBOARD_ENDPOINT_INDEX,
(uint8_t*)getInactiveUsbKeyboardReport(), USB_KEYBOARD_REPORT_LENGTH);
}
usb_status_t UsbKeyboardCallback(class_handle_t handle, uint32_t event, void *param)
{
usb_status_t error = kStatus_USB_Error;
switch (event) {
case kUSB_DeviceHidEventSendResponse:
if (UsbCompositeDevice.attach) {
return UsbKeyboardAction();
}
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 UsbKeyboardSetConfiguration(class_handle_t handle, uint8_t configuration)
{
if (USB_COMPOSITE_CONFIGURATION_INDEX == configuration) {
return UsbKeyboardAction();
}
return kStatus_USB_Error;
}
usb_status_t UsbKeyboardSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
{
if (USB_KEYBOARD_INTERFACE_INDEX == interface) {
return UsbKeyboardAction();
}
return kStatus_USB_Error;
}

View File

@@ -0,0 +1,43 @@
#ifndef __USB_INTERFACE_KEYBOARD_H__
#define __USB_INTERFACE_KEYBOARD_H__
// Includes:
#include "usb_api.h"
#include "usb_descriptor_keyboard_report.h"
// Macros:
#define USB_KEYBOARD_INTERFACE_INDEX 1
#define USB_KEYBOARD_ENDPOINT_INDEX 3
#define USB_KEYBOARD_ENDPOINT_COUNT 1
#define USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE 8
#define USB_KEYBOARD_INTERRUPT_IN_INTERVAL 4
#define USB_KEYBOARD_REPORT_LENGTH 8
// Typedefs:
typedef struct {
uint8_t modifiers;
uint8_t reserved; // Always must be 0
uint8_t scancodes[USB_KEYBOARD_MAX_KEYS];
} __attribute__ ((packed)) usb_keyboard_report_t;
// Variables:
extern usb_device_class_struct_t UsbKeyboardClass;
extern usb_keyboard_report_t* ActiveUsbKeyboardReport;
// Functions:
extern usb_status_t UsbKeyboardCallback(class_handle_t handle, uint32_t event, void *param);
extern usb_status_t UsbKeyboardSetConfiguration(class_handle_t handle, uint8_t configuration);
extern usb_status_t UsbKeyboardSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
extern void ResetActiveUsbKeyboardReport();
extern void SwitchActiveUsbKeyboardReport();
#endif

View File

@@ -0,0 +1,89 @@
#include "usb_composite_device.h"
#include "usb_interface_mouse.h"
#include "fsl_i2c.h"
#include "i2c.h"
#include "reset_button.h"
#include "action.h"
static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{
USB_MOUSE_ENDPOINT_INDEX | (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_INTERFACE_ALTERNATE_SETTING_NONE,
{USB_MOUSE_ENDPOINT_COUNT, UsbMouseEndpoints},
NULL,
}};
static usb_device_interfaces_struct_t UsbMouseInterfaces[USB_MOUSE_INTERFACE_COUNT] = {{
USB_CLASS_HID,
USB_HID_SUBCLASS_BOOT,
USB_HID_PROTOCOL_MOUSE,
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,
};
usb_mouse_report_t UsbMouseReport;
static volatile usb_status_t usbMouseAction()
{
return USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_INDEX,
(uint8_t*)&UsbMouseReport, USB_MOUSE_REPORT_LENGTH);
}
usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param)
{
usb_status_t error = kStatus_USB_Error;
switch (event) {
case kUSB_DeviceHidEventSendResponse:
if (UsbCompositeDevice.attach) {
return usbMouseAction();
}
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 UsbMouseSetConfiguration(class_handle_t handle, uint8_t configuration)
{
if (USB_COMPOSITE_CONFIGURATION_INDEX == configuration) {
return usbMouseAction();
}
return kStatus_USB_Error;
}
usb_status_t UsbMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
{
if (USB_MOUSE_INTERFACE_INDEX == interface) {
return usbMouseAction();
}
return kStatus_USB_Error;
}

View File

@@ -0,0 +1,43 @@
#ifndef __USB_INTERFACE_MOUSE_H__
#define __USB_INTERFACE_MOUSE_H__
// Includes:
#include "usb_api.h"
#include "usb_descriptor_device.h"
// Macros:
#define USB_MOUSE_INTERFACE_INDEX 2
#define USB_MOUSE_ENDPOINT_INDEX 4
#define USB_MOUSE_ENDPOINT_COUNT 1
#define USB_MOUSE_INTERRUPT_IN_PACKET_SIZE 8
#define USB_MOUSE_INTERRUPT_IN_INTERVAL 4
#define USB_MOUSE_REPORT_LENGTH 7
// Typedefs:
typedef struct {
uint8_t buttons;
int16_t x;
int16_t y;
int8_t wheelX;
int8_t wheelY;
} __attribute__ ((packed)) usb_mouse_report_t;
// Variables:
extern usb_device_class_struct_t UsbMouseClass;
// Functions:
extern usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param);
extern usb_status_t UsbMouseSetConfiguration(class_handle_t handle, uint8_t configuration);
extern usb_status_t UsbMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
extern usb_mouse_report_t UsbMouseReport;
#endif