Move the USB protocol handler into its own file.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "include/board/board.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "usb_interface_generic_hid.h"
|
||||
#include "test_led.h"
|
||||
|
||||
static usb_device_endpoint_struct_t UsbGenericHidEndpoints[USB_GENERIC_HID_ENDPOINT_COUNT] =
|
||||
{
|
||||
@@ -43,8 +42,8 @@ usb_device_class_struct_t UsbGenericHidClass = {
|
||||
USB_DEVICE_CONFIGURATION_COUNT,
|
||||
};
|
||||
|
||||
static uint8_t GenericHidInBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH];
|
||||
static uint8_t GenericHidOutBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
||||
uint8_t GenericHidInBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH];
|
||||
uint8_t GenericHidOutBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
||||
|
||||
static usb_status_t UsbReceiveData()
|
||||
{
|
||||
@@ -54,40 +53,15 @@ static usb_status_t UsbReceiveData()
|
||||
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
}
|
||||
|
||||
uint8_t x=0;
|
||||
usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param)
|
||||
{
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
uint8_t command, arg;
|
||||
|
||||
switch (event) {
|
||||
case kUSB_DeviceHidEventSendResponse:
|
||||
break;
|
||||
case kUSB_DeviceHidEventRecvResponse:
|
||||
|
||||
command = GenericHidInBuffer[0];
|
||||
arg = GenericHidInBuffer[1];
|
||||
|
||||
switch (command) {
|
||||
case USB_COMMAND_JUMP_TO_BOOTLOADER:
|
||||
break;
|
||||
case USB_COMMAND_TEST_LED:
|
||||
switch (arg) {
|
||||
case 0:
|
||||
TEST_RED_ON();
|
||||
break;
|
||||
case 1:
|
||||
TEST_RED_OFF();
|
||||
break;
|
||||
}
|
||||
GenericHidOutBuffer[0]=arg;
|
||||
GenericHidOutBuffer[1]=arg;
|
||||
GenericHidOutBuffer[2]=0x66+x++;
|
||||
case USB_COMMAND_LED_DRIVER:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
UsbProtocolHandler();
|
||||
|
||||
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle,
|
||||
USB_GENERIC_HID_ENDPOINT_IN_INDEX,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_device.h"
|
||||
#include "usb_protocol_handler.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
@@ -22,13 +23,11 @@
|
||||
#define USB_GENERIC_HID_IN_BUFFER_LENGTH 64
|
||||
#define USB_GENERIC_HID_OUT_BUFFER_LENGTH 64
|
||||
|
||||
#define USB_COMMAND_JUMP_TO_BOOTLOADER 0
|
||||
#define USB_COMMAND_TEST_LED 1
|
||||
#define USB_COMMAND_LED_DRIVER 2
|
||||
|
||||
// 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:
|
||||
|
||||
@@ -36,4 +35,5 @@
|
||||
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
|
||||
|
||||
26
right/src/usb_protocol_handler.c
Normal file
26
right/src/usb_protocol_handler.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "usb_protocol_handler.h"
|
||||
#include "test_led.h"
|
||||
|
||||
void UsbProtocolHandler()
|
||||
{
|
||||
uint8_t command = GenericHidInBuffer[0];
|
||||
uint8_t arg = GenericHidInBuffer[1];
|
||||
|
||||
switch (command) {
|
||||
case USB_COMMAND_JUMP_TO_BOOTLOADER:
|
||||
break;
|
||||
case USB_COMMAND_TEST_LED:
|
||||
switch (arg) {
|
||||
case 0:
|
||||
TEST_RED_ON();
|
||||
break;
|
||||
case 1:
|
||||
TEST_RED_OFF();
|
||||
break;
|
||||
}
|
||||
case USB_COMMAND_LED_DRIVER:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
18
right/src/usb_protocol_handler.h
Normal file
18
right/src/usb_protocol_handler.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __USB_PROTOCOL_HANDLER_H__
|
||||
#define __USB_PROTOCOL_HANDLER_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_interface_generic_hid.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_COMMAND_JUMP_TO_BOOTLOADER 0
|
||||
#define USB_COMMAND_TEST_LED 1
|
||||
#define USB_COMMAND_LED_DRIVER 2
|
||||
|
||||
// Functions:
|
||||
|
||||
extern void UsbProtocolHandler();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user