diff --git a/right/build/kds/.cproject b/right/build/kds/.cproject
index cc9d4c8..921b8cd 100644
--- a/right/build/kds/.cproject
+++ b/right/build/kds/.cproject
@@ -43,98 +43,61 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -223,114 +182,74 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
+
+
-
+
-
-
-
-
-
+
+
-
-
-
-
+
+
+
+
@@ -372,15 +291,16 @@
-
-
-
-
+
+
+
+
+
diff --git a/right/build/kds/.project b/right/build/kds/.project
index 7e53a67..73c7ea0 100644
--- a/right/build/kds/.project
+++ b/right/build/kds/.project
@@ -35,6 +35,16 @@
2
virtual:/virtual
+
+ drivers
+ 2
+ virtual:/virtual
+
+
+ osa
+ 2
+ virtual:/virtual
+
sources
2
@@ -53,128 +63,283 @@
board/board.c
1
- KSDK_DIR/examples/frdmk22f/board.c
+ PARENT-2-PROJECT_LOC/include/board/board.c
board/board.h
1
- KSDK_DIR/examples/frdmk22f/board.h
+ PARENT-2-PROJECT_LOC/include/board/board.h
- board/gpio_pins.c
+ board/clock_config.c
1
- KSDK_DIR/examples/frdmk22f/gpio_pins.c
+ PARENT-2-PROJECT_LOC/include/board/clock_config.c
- board/gpio_pins.h
+ board/clock_config.h
1
- KSDK_DIR/examples/frdmk22f/gpio_pins.h
-
-
- board/hardware_init.c
- 1
- PARENT-2-PROJECT_LOC/hardware_init.c
+ PARENT-2-PROJECT_LOC/include/board/clock_config.h
board/pin_mux.c
1
- KSDK_DIR/examples/frdmk22f/pin_mux.c
+ PARENT-2-PROJECT_LOC/include/board/pin_mux.c
board/pin_mux.h
1
- KSDK_DIR/examples/frdmk22f/pin_mux.h
+ PARENT-2-PROJECT_LOC/include/board/pin_mux.h
- sources/composite_app.c
+ drivers/fsl_clock.c
1
- PARENT-2-PROJECT_LOC/composite_app.c
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_clock.c
- sources/composite_app.h
+ drivers/fsl_clock.h
1
- PARENT-2-PROJECT_LOC/composite_app.h
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_clock.h
- sources/keyboard.c
+ drivers/fsl_common.c
1
- PARENT-2-PROJECT_LOC/keyboard.c
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_common.c
- sources/keyboard.h
+ drivers/fsl_common.h
1
- PARENT-2-PROJECT_LOC/keyboard.h
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_common.h
- sources/mouse.c
+ drivers/fsl_gpio.c
1
- PARENT-2-PROJECT_LOC/mouse.c
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_gpio.c
- sources/mouse.h
+ drivers/fsl_gpio.h
1
- PARENT-2-PROJECT_LOC/mouse.h
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_gpio.h
- sources/usb_descriptor.c
+ drivers/fsl_lpuart.c
1
- PARENT-2-PROJECT_LOC/usb_descriptor.c
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_lpuart.c
- sources/usb_descriptor.h
+ drivers/fsl_lpuart.h
1
- PARENT-2-PROJECT_LOC/usb_descriptor.h
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_lpuart.h
- startup/startup.c
+ drivers/fsl_port.h
1
- KSDK_DIR/platform/devices/startup.c
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_port.h
- startup/startup.h
+ drivers/fsl_sim.c
1
- KSDK_DIR/platform/devices/startup.h
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_sim.c
+
+
+ drivers/fsl_smc.c
+ 1
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_smc.c
+
+
+ drivers/fsl_smc.h
+ 1
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_smc.h
+
+
+ drivers/fsl_uart.c
+ 1
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_uart.c
+
+
+ drivers/fsl_uart.h
+ 1
+ KSDK_DIR/devices/MK22F51212/drivers/fsl_uart.h
+
+
+ osa/usb_osa.h
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/osa/usb_osa.h
+
+
+ osa/usb_osa_bm.c
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/osa/usb_osa_bm.c
+
+
+ osa/usb_osa_bm.h
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/osa/usb_osa_bm.h
+
+
+ sources/composite.c
+ 1
+ PARENT-2-PROJECT_LOC/composite.c
+
+
+ sources/composite.h
+ 1
+ PARENT-2-PROJECT_LOC/composite.h
+
+
+ sources/hid_keyboard.c
+ 1
+ PARENT-2-PROJECT_LOC/hid_keyboard.c
+
+
+ sources/hid_keyboard.h
+ 1
+ PARENT-2-PROJECT_LOC/hid_keyboard.h
+
+
+ sources/hid_mouse.c
+ 1
+ PARENT-2-PROJECT_LOC/hid_mouse.c
+
+
+ sources/hid_mouse.h
+ 1
+ PARENT-2-PROJECT_LOC/hid_mouse.h
+
+
+ sources/usb_device_config.h
+ 1
+ PARENT-2-PROJECT_LOC/usb_device_config.h
+
+
+ sources/usb_device_descriptor.c
+ 1
+ PARENT-2-PROJECT_LOC/usb_device_descriptor.c
+
+
+ sources/usb_device_descriptor.h
+ 1
+ PARENT-2-PROJECT_LOC/usb_device_descriptor.h
startup/startup_MK22F51212.S
1
- KSDK_DIR/platform/devices/MK22F51212/startup/gcc/startup_MK22F51212.S
+ KSDK_DIR/devices/MK22F51212/gcc/startup_MK22F51212.S
startup/system_MK22F51212.c
1
- KSDK_DIR/platform/devices/MK22F51212/startup/system_MK22F51212.c
+ KSDK_DIR/devices/MK22F51212/system_MK22F51212.c
+
+
+ startup/system_MK22F51212.h
+ 1
+ KSDK_DIR/devices/MK22F51212/system_MK22F51212.h
+
+
+ usb/include
+ 2
+ virtual:/virtual
utilities/fsl_debug_console.c
1
- KSDK_DIR/platform/utilities/src/fsl_debug_console.c
+ KSDK_DIR/devices/MK22F51212/utilities/fsl_debug_console.c
utilities/fsl_debug_console.h
1
- KSDK_DIR/platform/utilities/inc/fsl_debug_console.h
+ KSDK_DIR/devices/MK22F51212/utilities/fsl_debug_console.h
- utilities/fsl_misc_utilities.c
- 1
- KSDK_DIR/platform/utilities/src/fsl_misc_utilities.c
+ usb/device/class
+ 2
+ virtual:/virtual
- utilities/print_scan.c
- 1
- KSDK_DIR/platform/utilities/src/print_scan.c
+ usb/device/include
+ 2
+ virtual:/virtual
- utilities/print_scan.h
+ usb/device/source
+ 2
+ virtual:/virtual
+
+
+ usb/include/usb.h
1
- KSDK_DIR/platform/utilities/src/print_scan.h
+ KSDK_DIR/middleware/usb_1.0.0/include/usb.h
+
+
+ usb/device/class/hid
+ 2
+ virtual:/virtual
+
+
+ usb/device/class/usb_device_class.c
+ 1
+ PARENT-2-PROJECT_LOC/include/usb/usb_device_class.c
+
+
+ usb/device/class/usb_device_class.h
+ 1
+ PARENT-2-PROJECT_LOC/include/usb/usb_device_class.h
+
+
+ usb/device/include/usb_device.h
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/device/usb_device.h
+
+
+ usb/device/source/khci
+ 2
+ virtual:/virtual
+
+
+ usb/device/source/usb_device_ch9.c
+ 1
+ PARENT-2-PROJECT_LOC/include/usb/usb_device_ch9.c
+
+
+ usb/device/source/usb_device_ch9.h
+ 1
+ PARENT-2-PROJECT_LOC/include/usb/usb_device_ch9.h
+
+
+ usb/device/source/usb_device_dci.c
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/device/usb_device_dci.c
+
+
+ usb/device/source/usb_device_dci.h
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/device/usb_device_dci.h
+
+
+ usb/device/class/hid/usb_device_hid.c
+ 1
+ PARENT-2-PROJECT_LOC/include/usb/usb_device_hid.c
+
+
+ usb/device/class/hid/usb_device_hid.h
+ 1
+ PARENT-2-PROJECT_LOC/include/usb/usb_device_hid.h
+
+
+ usb/device/source/khci/usb_device_khci.c
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/device/usb_device_khci.c
+
+
+ usb/device/source/khci/usb_device_khci.h
+ 1
+ KSDK_DIR/middleware/usb_1.0.0/device/usb_device_khci.h
KSDK_DIR
- file:/home/laci/projects/kds/KSDK_1.3.0
+ file:/home/laci/projects/kds/KSDK_2.0
diff --git a/right/build/kds/.settings/language.settings.xml b/right/build/kds/.settings/language.settings.xml
index 3115a4a..dbd3995 100644
--- a/right/build/kds/.settings/language.settings.xml
+++ b/right/build/kds/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -16,7 +16,7 @@
-
+
diff --git a/right/build/kds/MK22FN512xxx12_flash.ld b/right/build/kds/MK22FN512xxx12_flash.ld
new file mode 100644
index 0000000..f3f0711
--- /dev/null
+++ b/right/build/kds/MK22FN512xxx12_flash.ld
@@ -0,0 +1,262 @@
+/*
+** ###################################################################
+** Processors: MK22FN512CAP12
+** MK22FN512VDC12
+** MK22FN512VLH12
+** MK22FN512VLL12
+** MK22FN512VMP12
+**
+** Compiler: GNU C Compiler
+** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
+** Version: rev. 2.8, 2015-02-19
+** Build: b151217
+**
+** Abstract:
+** Linker file for the GNU C Compiler
+**
+** Copyright (c) 2015 Freescale Semiconductor, Inc.
+** All rights reserved.
+**
+** Redistribution and use in source and binary forms, with or without modification,
+** are permitted provided that the following conditions are met:
+**
+** o Redistributions of source code must retain the above copyright notice, this list
+** of conditions and the following disclaimer.
+**
+** o Redistributions in binary form must reproduce the above copyright notice, this
+** list of conditions and the following disclaimer in the documentation and/or
+** other materials provided with the distribution.
+**
+** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+** contributors may be used to endorse or promote products derived from this
+** software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+** http: www.freescale.com
+** mail: support@freescale.com
+**
+** ###################################################################
+*/
+
+/* Entry Point */
+ENTRY(Reset_Handler)
+
+HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x2000;
+STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
+M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0;
+
+/* Specify the memory areas */
+MEMORY
+{
+ m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
+ m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
+ m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x0007FBF0
+ m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
+ m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
+}
+
+/* Define output sections */
+SECTIONS
+{
+ /* The startup code goes first into internal flash */
+ .interrupts :
+ {
+ __VECTOR_TABLE = .;
+ . = ALIGN(4);
+ KEEP(*(.isr_vector)) /* Startup code */
+ . = ALIGN(4);
+ } > m_interrupts
+
+ .flash_config :
+ {
+ . = ALIGN(4);
+ KEEP(*(.FlashConfig)) /* Flash Configuration Field (FCF) */
+ . = ALIGN(4);
+ } > m_flash_config
+
+ /* The program code and other data goes into internal flash */
+ .text :
+ {
+ . = ALIGN(4);
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+ *(.glue_7) /* glue arm to thumb code */
+ *(.glue_7t) /* glue thumb to arm code */
+ *(.eh_frame)
+ KEEP (*(.init))
+ KEEP (*(.fini))
+ . = ALIGN(4);
+ } > m_text
+
+ .ARM.extab :
+ {
+ *(.ARM.extab* .gnu.linkonce.armextab.*)
+ } > m_text
+
+ .ARM :
+ {
+ __exidx_start = .;
+ *(.ARM.exidx*)
+ __exidx_end = .;
+ } > m_text
+
+ .ctors :
+ {
+ __CTOR_LIST__ = .;
+ /* gcc uses crtbegin.o to find the start of
+ the constructors, so we make sure it is
+ first. Because this is a wildcard, it
+ doesn't matter if the user does not
+ actually link against crtbegin.o; the
+ linker won't look for a file to match a
+ wildcard. The wildcard also means that it
+ doesn't matter which directory crtbegin.o
+ is in. */
+ KEEP (*crtbegin.o(.ctors))
+ KEEP (*crtbegin?.o(.ctors))
+ /* We don't want to include the .ctor section from
+ from the crtend.o file until after the sorted ctors.
+ The .ctor section from the crtend file contains the
+ end of ctors marker and it must be last */
+ KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ __CTOR_END__ = .;
+ } > m_text
+
+ .dtors :
+ {
+ __DTOR_LIST__ = .;
+ KEEP (*crtbegin.o(.dtors))
+ KEEP (*crtbegin?.o(.dtors))
+ KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ __DTOR_END__ = .;
+ } > m_text
+
+ .preinit_array :
+ {
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array*))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ } > m_text
+
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array*))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ } > m_text
+
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array*))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ } > m_text
+
+ __etext = .; /* define a global symbol at end of code */
+ __DATA_ROM = .; /* Symbol is used by startup for data initialization */
+
+ .interrupts_ram :
+ {
+ . = ALIGN(4);
+ __VECTOR_RAM__ = .;
+ __interrupts_ram_start__ = .; /* Create a global symbol at data start */
+ *(.m_interrupts_ram) /* This is a user defined section */
+ . += M_VECTOR_RAM_SIZE;
+ . = ALIGN(4);
+ __interrupts_ram_end__ = .; /* Define a global symbol at data end */
+ } > m_data
+
+ __VECTOR_RAM = DEFINED(__ram_vector_table__) ? __VECTOR_RAM__ : ORIGIN(m_interrupts);
+ __RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0;
+
+ .data : AT(__DATA_ROM)
+ {
+ . = ALIGN(4);
+ __DATA_RAM = .;
+ __data_start__ = .; /* create a global symbol at data start */
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+ KEEP(*(.jcr*))
+ . = ALIGN(4);
+ __data_end__ = .; /* define a global symbol at data end */
+ } > m_data
+
+ __DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
+ text_end = ORIGIN(m_text) + LENGTH(m_text);
+ ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")
+
+ USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800;
+ /* Uninitialized data section */
+ .bss :
+ {
+ /* This is used by the startup in order to initialize the .bss section */
+ . = ALIGN(4);
+ __START_BSS = .;
+ __bss_start__ = .;
+ *(.bss)
+ *(.bss*)
+ . = ALIGN(512);
+ USB_RAM_START = .;
+ . += USB_RAM_GAP;
+ *(COMMON)
+ . = ALIGN(4);
+ __bss_end__ = .;
+ __END_BSS = .;
+ } > m_data
+
+ .heap :
+ {
+ . = ALIGN(8);
+ __end__ = .;
+ PROVIDE(end = .);
+ __HeapBase = .;
+ . += HEAP_SIZE;
+ __HeapLimit = .;
+ __heap_limit = .; /* Add for _sbrk */
+ } > m_data_2
+
+ .stack :
+ {
+ . = ALIGN(8);
+ . += STACK_SIZE;
+ } > m_data_2
+
+ m_usb_bdt USB_RAM_START (NOLOAD) :
+ {
+ *(m_usb_bdt)
+ USB_RAM_BDT_END = .;
+ }
+
+ m_usb_global USB_RAM_BDT_END (NOLOAD) :
+ {
+ *(m_usb_global)
+ }
+
+ /* Initializes stack on the end of block */
+ __StackTop = ORIGIN(m_data_2) + LENGTH(m_data_2);
+ __StackLimit = __StackTop - STACK_SIZE;
+ PROVIDE(__stack = __StackTop);
+
+ .ARM.attributes 0 : { *(.ARM.attributes) }
+
+ ASSERT(__StackLimit >= __HeapLimit, "region m_data_2 overflowed with stack and heap")
+}
+
diff --git a/right/build/kds/uhk-right debug cmsisdap.launch b/right/build/kds/uhk-right debug cmsisdap.launch
index 53f3049..1cf2ac8 100644
--- a/right/build/kds/uhk-right debug cmsisdap.launch
+++ b/right/build/kds/uhk-right debug cmsisdap.launch
@@ -2,7 +2,6 @@
-
@@ -32,7 +31,7 @@
-
+
@@ -48,17 +47,16 @@
-
-
-
+
+
-
+
diff --git a/right/build/kds/uhk-right release cmsisdap.launch b/right/build/kds/uhk-right release cmsisdap.launch
index e9486f6..50c9efe 100644
--- a/right/build/kds/uhk-right release cmsisdap.launch
+++ b/right/build/kds/uhk-right release cmsisdap.launch
@@ -2,6 +2,7 @@
+
@@ -50,10 +51,10 @@
-
+
-
-
+
+
diff --git a/right/build/kds/uhk-right release jlink.launch b/right/build/kds/uhk-right release jlink.launch
index 34e2f1f..be9101d 100644
--- a/right/build/kds/uhk-right release jlink.launch
+++ b/right/build/kds/uhk-right release jlink.launch
@@ -2,7 +2,6 @@
-
@@ -17,7 +16,7 @@
-
+
@@ -69,10 +68,10 @@
-
+
-
-
+
+
diff --git a/right/composite.c b/right/composite.c
new file mode 100644
index 0000000..6f795e1
--- /dev/null
+++ b/right/composite.c
@@ -0,0 +1,190 @@
+#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 "include/usb/usb_device_ch9.h"
+#include "usb_device_descriptor.h"
+#include "composite.h"
+#include "hid_keyboard.h"
+#include "hid_mouse.h"
+#include "fsl_device_registers.h"
+#include "include/board/clock_config.h"
+#include "include/board/board.h"
+#include "fsl_debug_console.h"
+#include
+#include
+#include "fsl_common.h"
+#include "include/board/pin_mux.h"
+
+void BOARD_InitHardware(void);
+
+static usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param);
+static void USB_DeviceApplicationInit(void);
+
+extern usb_device_class_struct_t g_UsbDeviceHidMouseConfig;
+extern usb_device_class_struct_t g_UsbDeviceHidKeyboardConfig;
+
+static usb_device_composite_struct_t g_UsbDeviceComposite;
+
+usb_device_class_config_struct_t g_CompositeClassConfig[USB_COMPOSITE_INTERFACE_COUNT] = {
+ {
+ USB_DeviceHidKeyboardCallback,
+ (class_handle_t)NULL,
+ &g_UsbDeviceHidKeyboardConfig,
+ },
+ {
+ USB_DeviceHidMouseCallback,
+ (class_handle_t)NULL,
+ &g_UsbDeviceHidMouseConfig,
+ }
+};
+
+usb_device_class_config_list_struct_t g_UsbDeviceCompositeConfigList = {
+ g_CompositeClassConfig,
+ USB_DeviceCallback,
+ USB_COMPOSITE_INTERFACE_COUNT,
+};
+
+static usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)
+{
+ usb_status_t error = kStatus_USB_Error;
+ uint16_t *temp16 = (uint16_t *)param;
+ uint8_t *temp8 = (uint8_t *)param;
+
+ switch (event) {
+ case kUSB_DeviceEventBusReset:
+ g_UsbDeviceComposite.attach = 0U;
+ error = kStatus_USB_Success;
+ break;
+ case kUSB_DeviceEventSetConfiguration:
+ if (param) {
+ g_UsbDeviceComposite.attach = 1U;
+ g_UsbDeviceComposite.currentConfiguration = *temp8;
+ USB_DeviceHidMouseSetConfigure(g_UsbDeviceComposite.hidMouseHandle, *temp8);
+ USB_DeviceHidKeyboardSetConfigure(g_UsbDeviceComposite.hidKeyboardHandle, *temp8);
+ error = kStatus_USB_Success;
+ }
+ break;
+ case kUSB_DeviceEventSetInterface:
+ if (g_UsbDeviceComposite.attach) {
+ uint8_t interface = (uint8_t)((*temp16 & 0xFF00U) >> 0x08U);
+ uint8_t alternateSetting = (uint8_t)(*temp16 & 0x00FFU);
+ if (interface < USB_COMPOSITE_INTERFACE_COUNT) {
+ g_UsbDeviceComposite.currentInterfaceAlternateSetting[interface] = alternateSetting;
+ USB_DeviceHidMouseSetInterface(g_UsbDeviceComposite.hidMouseHandle, interface, alternateSetting);
+ USB_DeviceHidKeyboardSetInterface(g_UsbDeviceComposite.hidKeyboardHandle, interface,
+ alternateSetting);
+ error = kStatus_USB_Success;
+ }
+ }
+ break;
+ case kUSB_DeviceEventGetConfiguration:
+ if (param) {
+ *temp8 = g_UsbDeviceComposite.currentConfiguration;
+ error = kStatus_USB_Success;
+ }
+ break;
+ case kUSB_DeviceEventGetInterface:
+ if (param) {
+ uint8_t interface = (uint8_t)((*temp16 & 0xFF00U) >> 0x08U);
+ if (interface < USB_COMPOSITE_INTERFACE_COUNT) {
+ *temp16 = (*temp16 & 0xFF00U) | g_UsbDeviceComposite.currentInterfaceAlternateSetting[interface];
+ error = kStatus_USB_Success;
+ } else {
+ error = kStatus_USB_InvalidRequest;
+ }
+ }
+ break;
+ case kUSB_DeviceEventGetDeviceDescriptor:
+ if (param) {
+ error = USB_DeviceGetDeviceDescriptor(handle, (usb_device_get_device_descriptor_struct_t *)param);
+ }
+ break;
+ case kUSB_DeviceEventGetConfigurationDescriptor:
+ if (param) {
+ error = USB_DeviceGetConfigurationDescriptor(handle,
+ (usb_device_get_configuration_descriptor_struct_t *)param);
+ }
+ break;
+ case kUSB_DeviceEventGetStringDescriptor:
+ if (param) {
+ error = USB_DeviceGetStringDescriptor(handle, (usb_device_get_string_descriptor_struct_t *)param);
+ }
+ break;
+ case kUSB_DeviceEventGetHidDescriptor:
+ if (param) {
+ error = USB_DeviceGetHidDescriptor(handle, (usb_device_get_hid_descriptor_struct_t *)param);
+ }
+ break;
+ case kUSB_DeviceEventGetHidReportDescriptor:
+ if (param) {
+ error =
+ USB_DeviceGetHidReportDescriptor(handle, (usb_device_get_hid_report_descriptor_struct_t *)param);
+ }
+ break;
+ case kUSB_DeviceEventGetHidPhysicalDescriptor:
+ if (param) {
+ error = USB_DeviceGetHidPhysicalDescriptor(handle, (usb_device_get_hid_physical_descriptor_struct_t *)param);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return error;
+}
+
+void USB0_IRQHandler(void)
+{
+ USB_DeviceKhciIsrFunction(g_UsbDeviceComposite.deviceHandle);
+}
+
+static void USB_DeviceApplicationInit(void)
+{
+ uint8_t usbDeviceKhciIrq[] = USB_IRQS;
+ uint8_t irqNumber = usbDeviceKhciIrq[CONTROLLER_ID - kUSB_ControllerKhci0];
+
+ SystemCoreClockUpdate();
+
+ CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U);
+
+ // Set composite device to default state.
+ g_UsbDeviceComposite.speed = USB_SPEED_FULL;
+ g_UsbDeviceComposite.attach = 0U;
+ g_UsbDeviceComposite.hidMouseHandle = (class_handle_t)NULL;
+ g_UsbDeviceComposite.hidKeyboardHandle = (class_handle_t)NULL;
+ g_UsbDeviceComposite.deviceHandle = NULL;
+
+ usb_status_t deviceStatus = USB_DeviceClassInit(
+ CONTROLLER_ID, &g_UsbDeviceCompositeConfigList, &g_UsbDeviceComposite.deviceHandle);
+
+ if (kStatus_USB_Success != deviceStatus) {
+ usb_echo("USB device composite demo init failed\r\n");
+ return;
+ } else {
+ usb_echo("USB device composite demo\r\n");
+ g_UsbDeviceComposite.hidKeyboardHandle = g_UsbDeviceCompositeConfigList.config[0].classHandle;
+ g_UsbDeviceComposite.hidMouseHandle = g_UsbDeviceCompositeConfigList.config[1].classHandle;
+ USB_DeviceHidKeyboardInit(&g_UsbDeviceComposite);
+ USB_DeviceHidMouseInit(&g_UsbDeviceComposite);
+ }
+
+ // Install ISR, set priority, and enable IRQ.
+ NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
+ NVIC_EnableIRQ((IRQn_Type)irqNumber);
+
+ // Start the device function.
+ USB_DeviceRun(g_UsbDeviceComposite.deviceHandle);
+}
+
+void main(void)
+{
+ BOARD_InitPins();
+ BOARD_BootClockHSRUN();
+ BOARD_InitDebugConsole();
+ USB_DeviceApplicationInit();
+
+ while (1U) {
+ }
+}
diff --git a/right/composite.h b/right/composite.h
new file mode 100644
index 0000000..cb33b0f
--- /dev/null
+++ b/right/composite.h
@@ -0,0 +1,21 @@
+#ifndef __USB_DEVICE_COMPOSITE_H__
+#define __USB_DEVICE_COMPOSITE_H__
+
+/* Macros: */
+
+ #define CONTROLLER_ID kUSB_ControllerKhci0
+ #define USB_DEVICE_INTERRUPT_PRIORITY (3U)
+
+/* Type defines: */
+
+ typedef struct _usb_device_composite_struct {
+ usb_device_handle deviceHandle;
+ class_handle_t hidMouseHandle;
+ class_handle_t hidKeyboardHandle;
+ uint8_t speed;
+ uint8_t attach;
+ uint8_t currentConfiguration;
+ uint8_t currentInterfaceAlternateSetting[USB_COMPOSITE_INTERFACE_COUNT];
+ } usb_device_composite_struct_t;
+
+#endif
diff --git a/right/composite_app.c b/right/composite_app.c
deleted file mode 100644
index a48cc61..0000000
--- a/right/composite_app.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "usb_device_config.h"
-#include "usb.h"
-#include "usb_device_stack_interface.h"
-#include "mouse.h"
-#include "keyboard.h"
-#include "usb_class_composite.h"
-#include "composite_app.h"
-#include "fsl_device_registers.h"
-#include "fsl_clock_manager.h"
-#include "board.h"
-#include "fsl_debug_console.h"
-#include "fsl_port_hal.h"
-#include
-#include
-
-composite_device_struct_t g_composite_device;
-uint16_t g_composite_speed;
-extern usb_desc_request_notify_struct_t desc_callback;
-
-extern void USB_Keyboard_App_Device_Callback(uint8_t event_type, void* val, void* arg);
-extern void Hid_USB_Mouse_App_Device_Callback(uint8_t event_type, void* val, void* arg);
-extern uint8_t USB_Keyboard_App_Class_Callback(
- uint8_t request, uint16_t value, uint8_t ** data, uint32_t* size, void* arg);
-extern uint8_t Hid_USB_Mouse_App_Class_Callback(
- uint8_t request, uint16_t value, uint8_t ** data, uint32_t* size, void* arg);
-
-void APP_init(void) {
- USB_PRINTF("initializing...\n");
-
- class_config_struct_t* keyboard_config_callback_handle;
- keyboard_config_callback_handle = &g_composite_device.composite_device_config_list[HID_KEYBOARD_INTERFACE_INDEX];
- keyboard_config_callback_handle->composite_application_callback.callback = USB_Keyboard_App_Device_Callback;
- keyboard_config_callback_handle->composite_application_callback.arg = &g_composite_device.hid_keyboard;
- keyboard_config_callback_handle->class_specific_callback.callback = USB_Keyboard_App_Class_Callback;
- keyboard_config_callback_handle->class_specific_callback.arg = &g_composite_device.hid_keyboard;
- keyboard_config_callback_handle->board_init_callback.callback = usb_device_board_init;
- keyboard_config_callback_handle->board_init_callback.arg = CONTROLLER_ID;
- keyboard_config_callback_handle->desc_callback_ptr = &desc_callback;
- keyboard_config_callback_handle->type = USB_CLASS_HID;
- OS_Mem_zero(&g_composite_device.hid_keyboard, sizeof(keyboard_global_variable_struct_t));
-
- /* hid mouse device */
- class_config_struct_t* mouse_config_callback_handle;
- mouse_config_callback_handle = &g_composite_device.composite_device_config_list[HID_MOUSE_INTERFACE_INDEX];
- mouse_config_callback_handle->composite_application_callback.callback = Hid_USB_Mouse_App_Device_Callback;
- mouse_config_callback_handle->composite_application_callback.arg = &g_composite_device.hid_mouse;
- mouse_config_callback_handle->class_specific_callback.callback = Hid_USB_Mouse_App_Class_Callback;
- mouse_config_callback_handle->class_specific_callback.arg = &g_composite_device.hid_mouse;
- mouse_config_callback_handle->board_init_callback.callback = usb_device_board_init;
- mouse_config_callback_handle->board_init_callback.arg = CONTROLLER_ID;
- mouse_config_callback_handle->desc_callback_ptr = &desc_callback;
- mouse_config_callback_handle->type = USB_CLASS_HID;
- OS_Mem_zero(&g_composite_device.hid_mouse, sizeof(hid_mouse_struct_t));
-
- g_composite_device.composite_device_config_callback.count = 2;
- g_composite_device.composite_device_config_callback.class_app_callback = g_composite_device.composite_device_config_list;
-
- /* Initialize the USB interface */
- USB_Composite_Init(CONTROLLER_ID, &g_composite_device.composite_device_config_callback, &g_composite_device.composite_device);
-
- g_composite_device.hid_keyboard.app_handle = (hid_handle_t) g_composite_device.composite_device_config_list[HID_KEYBOARD_INTERFACE_INDEX].class_handle;
- g_composite_device.hid_mouse.app_handle = (hid_handle_t) g_composite_device.composite_device_config_list[HID_MOUSE_INTERFACE_INDEX].class_handle;
-
- hid_keyboard_init(&g_composite_device.hid_keyboard);
- hid_mouse_init(&g_composite_device.hid_mouse);
-}
-
-void main(void) {
- hardware_init();
- OSA_Init(); // No RTOS is used but the USB device doesn't enumerate without this call.
- dbg_uart_init();
- APP_init();
- OSA_Start(); // Shouldn't be needed but OSA_Init() is needed so let's leave it in.
-}
diff --git a/right/composite_app.h b/right/composite_app.h
deleted file mode 100644
index a7b4d1a..0000000
--- a/right/composite_app.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef _COMPOSITE_APP_H
-#define _COMPOSITE_APP_H
-
-#include "keyboard.h"
-
-/* Macros: */
-
- #define COMPOSITE_CFG_MAX 2
- #define HID_KEYBOARD_INTERFACE_INDEX 0
- #define HID_MOUSE_INTERFACE_INDEX 1
- #define CONTROLLER_ID USB_CONTROLLER_KHCI_0
-
-/* Type defines: */
-
- typedef struct composite_device_struct {
- composite_handle_t composite_device;
- keyboard_global_variable_struct_t hid_keyboard;
- hid_mouse_struct_t hid_mouse;
- composite_config_struct_t composite_device_config_callback;
- class_config_struct_t composite_device_config_list[COMPOSITE_CFG_MAX];
- } composite_device_struct_t;
-
-/* Function prototypes */
-
- extern composite_device_struct_t g_composite_device;
-
-#endif
diff --git a/right/hardware_init.c b/right/hardware_init.c
deleted file mode 100644
index 8d902e4..0000000
--- a/right/hardware_init.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "board.h"
-#include "pin_mux.h"
-#include "fsl_clock_manager.h"
-#include "fsl_debug_console.h"
-
-void hardware_init(void)
-{
-
- uint8_t i;
-
- /* enable clock for PORTs */
- for (i = 0; i < PORT_INSTANCE_COUNT; i++)
- {
- CLOCK_SYS_EnablePortClock(i);
- }
-
- /* Init board clock */
- BOARD_ClockInit();
- dbg_uart_init();
-}
-
-/*!
- ** @}
- */
-/*
- ** ###################################################################
- **
- ** This file was created by Processor Expert 10.4 [05.10]
- ** for the Freescale Kinetis series of microcontrollers.
- **
- ** ###################################################################
- */
diff --git a/right/hid_keyboard.c b/right/hid_keyboard.c
new file mode 100644
index 0000000..3468fb6
--- /dev/null
+++ b/right/hid_keyboard.c
@@ -0,0 +1,95 @@
+#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 "include/usb/usb_device_ch9.h"
+#include "usb_device_descriptor.h"
+#include "composite.h"
+#include "hid_keyboard.h"
+
+static usb_status_t USB_DeviceHidKeyboardAction(void);
+
+static usb_device_composite_struct_t *s_UsbDeviceComposite;
+static usb_device_hid_keyboard_struct_t s_UsbDeviceHidKeyboard;
+
+static usb_status_t USB_DeviceHidKeyboardAction(void)
+{
+ static int x = 0U;
+ enum {
+ DOWN,
+ UP
+ };
+ static uint8_t dir = DOWN;
+
+ s_UsbDeviceHidKeyboard.buffer[2] = 0x00U;
+ switch (dir) {
+ case DOWN:
+ x++;
+ if (x > 200U) {
+ dir++;
+ s_UsbDeviceHidKeyboard.buffer[2] = KEY_PAGEUP;
+ }
+ break;
+ case UP:
+ x--;
+ if (x < 1U) {
+ dir = DOWN;
+ s_UsbDeviceHidKeyboard.buffer[2] = KEY_PAGEDOWN;
+ }
+ break;
+ default:
+ break;
+ }
+ return USB_DeviceHidSend(s_UsbDeviceComposite->hidKeyboardHandle, USB_HID_KEYBOARD_ENDPOINT_IN,
+ s_UsbDeviceHidKeyboard.buffer, USB_HID_KEYBOARD_REPORT_LENGTH);
+}
+
+usb_status_t USB_DeviceHidKeyboardCallback(class_handle_t handle, uint32_t event, void *param)
+{
+ usb_status_t error = kStatus_USB_Error;
+
+ switch (event) {
+ case kUSB_DeviceHidEventSendResponse:
+ if (s_UsbDeviceComposite->attach) {
+ return USB_DeviceHidKeyboardAction();
+ }
+ 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 USB_DeviceHidKeyboardSetConfigure(class_handle_t handle, uint8_t configure)
+{
+ if (USB_COMPOSITE_CONFIGURE_INDEX == configure) {
+ return USB_DeviceHidKeyboardAction();
+ }
+ return kStatus_USB_Error;
+}
+
+usb_status_t USB_DeviceHidKeyboardSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
+{
+ if (USB_HID_KEYBOARD_INTERFACE_INDEX == interface) {
+ return USB_DeviceHidKeyboardAction();
+ }
+ return kStatus_USB_Error;
+}
+
+usb_status_t USB_DeviceHidKeyboardInit(usb_device_composite_struct_t *deviceComposite)
+{
+ s_UsbDeviceComposite = deviceComposite;
+ return kStatus_USB_Success;
+}
diff --git a/right/hid_keyboard.h b/right/hid_keyboard.h
new file mode 100644
index 0000000..c7797c4
--- /dev/null
+++ b/right/hid_keyboard.h
@@ -0,0 +1,248 @@
+#ifndef __USB_DEVICE_HID_KEYBOARD_H__
+#define __USB_DEVICE_HID_KEYBOARD_H__
+
+/* Macros: */
+
+ #define KEY_ERRORROLLOVER 0x01U
+ #define KEY_POSTFAIL 0x02U
+ #define KEY_ERRORUNDEFINED 0x03U
+ #define KEY_A 0x04U
+ #define KEY_B 0x05U
+ #define KEY_C 0x06U
+ #define KEY_D 0x07U
+ #define KEY_E 0x08U
+ #define KEY_F 0x09U
+ #define KEY_G 0x0AU
+ #define KEY_H 0x0BU
+ #define KEY_I 0x0CU
+ #define KEY_J 0x0DU
+ #define KEY_K 0x0EU
+ #define KEY_L 0x0FU
+ #define KEY_M 0x10U
+ #define KEY_N 0x11U
+ #define KEY_O 0x12U
+ #define KEY_P 0x13U
+ #define KEY_Q 0x14U
+ #define KEY_R 0x15U
+ #define KEY_S 0x16U
+ #define KEY_T 0x17U
+ #define KEY_U 0x18U
+ #define KEY_V 0x19U
+ #define KEY_W 0x1AU
+ #define KEY_X 0x1BU
+ #define KEY_Y 0x1CU
+ #define KEY_Z 0x1DU
+ #define KEY_1_EXCLAMATION_MARK 0x1EU
+ #define KEY_2_AT 0x1FU
+ #define KEY_3_NUMBER_SIGN 0x20U
+ #define KEY_4_DOLLAR 0x21U
+ #define KEY_5_PERCENT 0x22U
+ #define KEY_6_CARET 0x23U
+ #define KEY_7_AMPERSAND 0x24U
+ #define KEY_8_ASTERISK 0x25U
+ #define KEY_9_OPARENTHESIS 0x26U
+ #define KEY_0_CPARENTHESIS 0x27U
+ #define KEY_ENTER 0x28U
+ #define KEY_ESCAPE 0x29U
+ #define KEY_BACKSPACE 0x2AU
+ #define KEY_TAB 0x2BU
+ #define KEY_SPACEBAR 0x2CU
+ #define KEY_MINUS_UNDERSCORE 0x2DU
+ #define KEY_EQUAL_PLUS 0x2EU
+ #define KEY_OBRACKET_AND_OBRACE 0x2FU
+ #define KEY_CBRACKET_AND_CBRACE 0x30U
+ #define KEY_BACKSLASH_VERTICAL_BAR 0x31U
+ #define KEY_NONUS_NUMBER_SIGN_TILDE 0x32U
+ #define KEY_SEMICOLON_COLON 0x33U
+ #define KEY_SINGLE_AND_DOUBLE_QUOTE 0x34U
+ #define KEY_GRAVE_ACCENT_AND_TILDE 0x35U
+ #define KEY_COMMA_AND_LESS 0x36U
+ #define KEY_DOT_GREATER 0x37U
+ #define KEY_SLASH_QUESTION 0x38U
+ #define KEY_CAPS_LOCK 0x39U
+ #define KEY_F1 0x3AU
+ #define KEY_F2 0x3BU
+ #define KEY_F3 0x3CU
+ #define KEY_F4 0x3DU
+ #define KEY_F5 0x3EU
+ #define KEY_F6 0x3FU
+ #define KEY_F7 0x40U
+ #define KEY_F8 0x41U
+ #define KEY_F9 0x42U
+ #define KEY_F10 0x43U
+ #define KEY_F11 0x44U
+ #define KEY_F12 0x45U
+ #define KEY_PRINTSCREEN 0x46U
+ #define KEY_SCROLL_LOCK 0x47U
+ #define KEY_PAUSE 0x48U
+ #define KEY_INSERT 0x49U
+ #define KEY_HOME 0x4AU
+ #define KEY_PAGEUP 0x4BU
+ #define KEY_DELETE 0x4CU
+ #define KEY_END1 0x4DU
+ #define KEY_PAGEDOWN 0x4EU
+ #define KEY_RIGHTARROW 0x4FU
+ #define KEY_LEFTARROW 0x50U
+ #define KEY_DOWNARROW 0x51U
+ #define KEY_UPARROW 0x52U
+ #define KEY_KEYPAD_NUM_LOCK_AND_CLEAR 0x53U
+ #define KEY_KEYPAD_SLASH 0x54U
+ #define KEY_KEYPAD_ASTERIKS 0x55U
+ #define KEY_KEYPAD_MINUS 0x56U
+ #define KEY_KEYPAD_PLUS 0x57U
+ #define KEY_KEYPAD_ENTER 0x58U
+ #define KEY_KEYPAD_1_END 0x59U
+ #define KEY_KEYPAD_2_DOWN_ARROW 0x5AU
+ #define KEY_KEYPAD_3_PAGEDN 0x5BU
+ #define KEY_KEYPAD_4_LEFT_ARROW 0x5CU
+ #define KEY_KEYPAD_5 0x5DU
+ #define KEY_KEYPAD_6_RIGHT_ARROW 0x5EU
+ #define KEY_KEYPAD_7_HOME 0x5FU
+ #define KEY_KEYPAD_8_UP_ARROW 0x60U
+ #define KEY_KEYPAD_9_PAGEUP 0x61U
+ #define KEY_KEYPAD_0_INSERT 0x62U
+ #define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE 0x63U
+ #define KEY_NONUS_BACK_SLASH_VERTICAL_BAR 0x64U
+ #define KEY_APPLICATION 0x65U
+ #define KEY_POWER 0x66U
+ #define KEY_KEYPAD_EQUAL 0x67U
+ #define KEY_F13 0x68U
+ #define KEY_F14 0x69U
+ #define KEY_F15 0x6AU
+ #define KEY_F16 0x6BU
+ #define KEY_F17 0x6CU
+ #define KEY_F18 0x6DU
+ #define KEY_F19 0x6EU
+ #define KEY_F20 0x6FU
+ #define KEY_F21 0x70U
+ #define KEY_F22 0x71U
+ #define KEY_F23 0x72U
+ #define KEY_F24 0x73U
+ #define KEY_EXECUTE 0x74U
+ #define KEY_HELP 0x75U
+ #define KEY_MENU 0x76U
+ #define KEY_SELECT 0x77U
+ #define KEY_STOP 0x78U
+ #define KEY_AGAIN 0x79U
+ #define KEY_UNDO 0x7AU
+ #define KEY_CUT 0x7BU
+ #define KEY_COPY 0x7CU
+ #define KEY_PASTE 0x7DU
+ #define KEY_FIND 0x7EU
+ #define KEY_MUTE 0x7FU
+ #define KEY_VOLUME_UP 0x80U
+ #define KEY_VOLUME_DOWN 0x81U
+ #define KEY_LOCKING_CAPS_LOCK 0x82U
+ #define KEY_LOCKING_NUM_LOCK 0x83U
+ #define KEY_LOCKING_SCROLL_LOCK 0x84U
+ #define KEY_KEYPAD_COMMA 0x85U
+ #define KEY_KEYPAD_EQUAL_SIGN 0x86U
+ #define KEY_INTERNATIONAL1 0x87U
+ #define KEY_INTERNATIONAL2 0x88U
+ #define KEY_INTERNATIONAL3 0x89U
+ #define KEY_INTERNATIONAL4 0x8AU
+ #define KEY_INTERNATIONAL5 0x8BU
+ #define KEY_INTERNATIONAL6 0x8CU
+ #define KEY_INTERNATIONAL7 0x8DU
+ #define KEY_INTERNATIONAL8 0x8EU
+ #define KEY_INTERNATIONAL9 0x8FU
+ #define KEY_LANG1 0x90U
+ #define KEY_LANG2 0x91U
+ #define KEY_LANG3 0x92U
+ #define KEY_LANG4 0x93U
+ #define KEY_LANG5 0x94U
+ #define KEY_LANG6 0x95U
+ #define KEY_LANG7 0x96U
+ #define KEY_LANG8 0x97U
+ #define KEY_LANG9 0x98U
+ #define KEY_ALTERNATE_ERASE 0x99U
+ #define KEY_SYSREQ 0x9AU
+ #define KEY_CANCEL 0x9BU
+ #define KEY_CLEAR 0x9CU
+ #define KEY_PRIOR 0x9DU
+ #define KEY_RETURN 0x9EU
+ #define KEY_SEPARATOR 0x9FU
+ #define KEY_OUT 0xA0U
+ #define KEY_OPER 0xA1U
+ #define KEY_CLEAR_AGAIN 0xA2U
+ #define KEY_CRSEL 0xA3U
+ #define KEY_EXSEL 0xA4U
+ #define KEY_KEYPAD_00 0xB0U
+ #define KEY_KEYPAD_000 0xB1U
+ #define KEY_THOUSANDS_SEPARATOR 0xB2U
+ #define KEY_DECIMAL_SEPARATOR 0xB3U
+ #define KEY_CURRENCY_UNIT 0xB4U
+ #define KEY_CURRENCY_SUB_UNIT 0xB5U
+ #define KEY_KEYPAD_OPARENTHESIS 0xB6U
+ #define KEY_KEYPAD_CPARENTHESIS 0xB7U
+ #define KEY_KEYPAD_OBRACE 0xB8U
+ #define KEY_KEYPAD_CBRACE 0xB9U
+ #define KEY_KEYPAD_TAB 0xBAU
+ #define KEY_KEYPAD_BACKSPACE 0xBBU
+ #define KEY_KEYPAD_A 0xBCU
+ #define KEY_KEYPAD_B 0xBDU
+ #define KEY_KEYPAD_C 0xBEU
+ #define KEY_KEYPAD_D 0xBFU
+ #define KEY_KEYPAD_E 0xC0U
+ #define KEY_KEYPAD_F 0xC1U
+ #define KEY_KEYPAD_XOR 0xC2U
+ #define KEY_KEYPAD_CARET 0xC3U
+ #define KEY_KEYPAD_PERCENT 0xC4U
+ #define KEY_KEYPAD_LESS 0xC5U
+ #define KEY_KEYPAD_GREATER 0xC6U
+ #define KEY_KEYPAD_AMPERSAND 0xC7U
+ #define KEY_KEYPAD_LOGICAL_AND 0xC8U
+ #define KEY_KEYPAD_VERTICAL_BAR 0xC9U
+ #define KEY_KEYPAD_LOGIACL_OR 0xCAU
+ #define KEY_KEYPAD_COLON 0xCBU
+ #define KEY_KEYPAD_NUMBER_SIGN 0xCCU
+ #define KEY_KEYPAD_SPACE 0xCDU
+ #define KEY_KEYPAD_AT 0xCEU
+ #define KEY_KEYPAD_EXCLAMATION_MARK 0xCFU
+ #define KEY_KEYPAD_MEMORY_STORE 0xD0U
+ #define KEY_KEYPAD_MEMORY_RECALL 0xD1U
+ #define KEY_KEYPAD_MEMORY_CLEAR 0xD2U
+ #define KEY_KEYPAD_MEMORY_ADD 0xD3U
+ #define KEY_KEYPAD_MEMORY_SUBTRACT 0xD4U
+ #define KEY_KEYPAD_MEMORY_MULTIPLY 0xD5U
+ #define KEY_KEYPAD_MEMORY_DIVIDE 0xD6U
+ #define KEY_KEYPAD_PLUSMINUS 0xD7U
+ #define KEY_KEYPAD_CLEAR 0xD8U
+ #define KEY_KEYPAD_CLEAR_ENTRY 0xD9U
+ #define KEY_KEYPAD_BINARY 0xDAU
+ #define KEY_KEYPAD_OCTAL 0xDBU
+ #define KEY_KEYPAD_DECIMAL 0xDCU
+ #define KEY_KEYPAD_HEXADECIMAL 0xDDU
+ #define KEY_LEFTCONTROL 0xE0U
+ #define KEY_LEFTSHIFT 0xE1U
+ #define KEY_LEFTALT 0xE2U
+ #define KEY_LEFT_GUI 0xE3U
+ #define KEY_RIGHTCONTROL 0xE4U
+ #define KEY_RIGHTSHIFT 0xE5U
+ #define KEY_RIGHTALT 0xE6U
+ #define KEY_RIGHT_GUI 0xE7U
+
+ #define MODIFERKEYS_LEFT_CTRL 0x01U
+ #define MODIFERKEYS_LEFT_SHIFT 0x02U
+ #define MODIFERKEYS_LEFT_ALT 0x04U
+ #define MODIFERKEYS_LEFT_GUI 0x08U
+ #define MODIFERKEYS_RIGHT_CTRL 0x10U
+ #define MODIFERKEYS_RIGHT_SHIFT 0x20U
+ #define MODIFERKEYS_RIGHT_ALT 0x40U
+ #define MODIFERKEYS_RIGHT_GUI 0x80U
+
+/* Type defines: */
+
+ typedef struct _usb_device_hid_keyboard_struct {
+ uint8_t buffer[USB_HID_KEYBOARD_REPORT_LENGTH];
+ uint8_t idleRate;
+ } usb_device_hid_keyboard_struct_t;
+
+/* Function prototypes: */
+
+ extern usb_status_t USB_DeviceHidKeyboardInit(usb_device_composite_struct_t *deviceComposite);
+ extern usb_status_t USB_DeviceHidKeyboardCallback(class_handle_t handle, uint32_t event, void *param);
+ extern usb_status_t USB_DeviceHidKeyboardSetConfigure(class_handle_t handle, uint8_t configure);
+ extern usb_status_t USB_DeviceHidKeyboardSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
+
+#endif
diff --git a/right/hid_mouse.c b/right/hid_mouse.c
new file mode 100644
index 0000000..b6b1e43
--- /dev/null
+++ b/right/hid_mouse.c
@@ -0,0 +1,122 @@
+#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 "include/usb/usb_device_ch9.h"
+#include "usb_device_descriptor.h"
+#include "composite.h"
+#include "hid_mouse.h"
+
+static usb_status_t USB_DeviceHidMouseAction(void);
+
+static usb_device_composite_struct_t *s_UsbDeviceComposite;
+static usb_device_hid_mouse_struct_t s_UsbDeviceHidMouse;
+
+/* Update mouse pointer location: draw a rectangular rotation. */
+static usb_status_t USB_DeviceHidMouseAction(void)
+{
+ static int8_t x = 0U;
+ static int8_t y = 0U;
+ enum {
+ RIGHT,
+ DOWN,
+ LEFT,
+ UP
+ };
+ static uint8_t dir = RIGHT;
+
+ switch (dir) {
+ case RIGHT:
+ /* Move right. Increase X value. */
+ s_UsbDeviceHidMouse.buffer[1] = 1U;
+ s_UsbDeviceHidMouse.buffer[2] = 0U;
+ x++;
+ if (x > 99U) {
+ dir++;
+ }
+ break;
+ case DOWN:
+ /* Move down. Increase Y value. */
+ s_UsbDeviceHidMouse.buffer[1] = 0U;
+ s_UsbDeviceHidMouse.buffer[2] = 1U;
+ y++;
+ if (y > 99U) {
+ dir++;
+ }
+ break;
+ case LEFT:
+ /* Move left. Discrease X value. */
+ s_UsbDeviceHidMouse.buffer[1] = (uint8_t)(0xFFU);
+ s_UsbDeviceHidMouse.buffer[2] = 0U;
+ x--;
+ if (x < 1U) {
+ dir++;
+ }
+ break;
+ case UP:
+ /* Move up. Discrease Y value. */
+ s_UsbDeviceHidMouse.buffer[1] = 0U;
+ s_UsbDeviceHidMouse.buffer[2] = (uint8_t)(0xFFU);
+ y--;
+ if (y < 1U) {
+ dir = RIGHT;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return USB_DeviceHidSend(s_UsbDeviceComposite->hidMouseHandle, USB_HID_MOUSE_ENDPOINT_IN,
+ s_UsbDeviceHidMouse.buffer, USB_HID_MOUSE_REPORT_LENGTH);
+}
+
+usb_status_t USB_DeviceHidMouseCallback(class_handle_t handle, uint32_t event, void *param)
+{
+ usb_status_t error = kStatus_USB_Error;
+
+ switch (event)
+ {
+ case kUSB_DeviceHidEventSendResponse:
+ if (s_UsbDeviceComposite->attach) {
+ return USB_DeviceHidMouseAction();
+ }
+ 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 USB_DeviceHidMouseSetConfigure(class_handle_t handle, uint8_t configure)
+{
+ if (USB_COMPOSITE_CONFIGURE_INDEX == configure) {
+ return USB_DeviceHidMouseAction();
+ }
+ return kStatus_USB_Error;
+}
+
+usb_status_t USB_DeviceHidMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
+{
+ if (USB_HID_KEYBOARD_INTERFACE_INDEX == interface) {
+ return USB_DeviceHidMouseAction();
+ }
+ return kStatus_USB_Error;
+}
+
+usb_status_t USB_DeviceHidMouseInit(usb_device_composite_struct_t *deviceComposite)
+{
+ s_UsbDeviceComposite = deviceComposite;
+ return kStatus_USB_Success;
+}
diff --git a/right/hid_mouse.h b/right/hid_mouse.h
new file mode 100644
index 0000000..0bb77b8
--- /dev/null
+++ b/right/hid_mouse.h
@@ -0,0 +1,18 @@
+#ifndef __USB_DEVICE_HID_MOUSE_H__
+#define __USB_DEVICE_HID_MOUSE_H__
+
+/* Type defines: */
+
+ typedef struct usb_device_hid_mouse_struct {
+ uint8_t buffer[USB_HID_MOUSE_REPORT_LENGTH];
+ uint8_t idleRate;
+ } usb_device_hid_mouse_struct_t;
+
+/* Function prototypes: */
+
+ extern usb_status_t USB_DeviceHidMouseInit(usb_device_composite_struct_t *deviceComposite);
+ extern usb_status_t USB_DeviceHidMouseCallback(class_handle_t handle, uint32_t event, void *param);
+ extern usb_status_t USB_DeviceHidMouseSetConfigure(class_handle_t handle, uint8_t configure);
+ extern usb_status_t USB_DeviceHidMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
+
+#endif
diff --git a/right/include/board/board.c b/right/include/board/board.c
new file mode 100644
index 0000000..f7b78a9
--- /dev/null
+++ b/right/include/board/board.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "fsl_common.h"
+#include "fsl_debug_console.h"
+#include "board.h"
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+/* Initialize debug console. */
+void BOARD_InitDebugConsole(void)
+{
+ uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;
+
+ DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
+}
diff --git a/right/include/board/board.h b/right/include/board/board.h
new file mode 100644
index 0000000..69e32d1
--- /dev/null
+++ b/right/include/board/board.h
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _BOARD_H_
+#define _BOARD_H_
+
+#include "clock_config.h"
+#include "fsl_gpio.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief The board name */
+#define BOARD_NAME "FRDM-K22F"
+
+/*! @brief The UART to use for debug messages. */
+#define BOARD_USE_UART
+#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART
+#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART1
+#define BOARD_DEBUG_UART_CLKSRC SYS_CLK
+#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetCoreSysClkFreq()
+#define BOARD_UART_IRQ UART1_RX_TX_IRQn
+#define BOARD_UART_IRQ_HANDLER UART1_RX_TX_IRQHandler
+
+#ifndef BOARD_DEBUG_UART_BAUDRATE
+#define BOARD_DEBUG_UART_BAUDRATE 115200
+#endif /* BOARD_DEBUG_UART_BAUDRATE */
+
+/*! @brief The Flextimer instance/channel used for board */
+#define BOARD_FTM_BASEADDR FTM0
+#define BOARD_FTM_CHANNEL 5U
+#define BOARD_FTM_X_CHANNEL 0U
+#define BOARD_FTM_Y_CHANNEL 1U
+#define BOARD_FTM_PERIOD_HZ 100U
+#define BOARD_FTM_IRQ_HANDLER FTM0_IRQHandler
+#define BOARD_FTM_IRQ_VECTOR FTM0_IRQn
+
+/*! @brief The bubble level demo information */
+#define BOARD_FXOS8700_ADDR 0x1C
+#define BOARD_ACCEL_ADDR BOARD_FXOS8700_ADDR
+#define BOARD_ACCEL_BAUDRATE 100
+#define BOARD_ACCEL_I2C_BASEADDR I2C0
+
+/*! @brief The i2c instance used for i2c connection by default */
+#define BOARD_I2C_BASEADDR I2C0
+
+/*! @brief The CMP instance/channel used for board. */
+#define BOARD_CMP_BASEADDR CMP0
+#define BOARD_CMP_CHANNEL 0U
+
+/*! @brief The rtc instance used for board. */
+#define BOARD_RTC_FUNC_BASEADDR RTC
+
+/*! @brief Define the port interrupt number for the board switches */
+#define BOARD_SW3_GPIO GPIOB
+#define BOARD_SW3_PORT PORTB
+#define BOARD_SW3_GPIO_PIN 17
+#define BOARD_SW3_IRQ PORTB_IRQn
+#define BOARD_SW3_IRQ_HANDLER PORTB_IRQHandler
+#define BOARD_SW3_NAME "SW3"
+
+#define BOARD_SW2_GPIO GPIOC
+#define BOARD_SW2_PORT PORTC
+#define BOARD_SW2_GPIO_PIN 1
+#define BOARD_SW2_IRQ PORTC_IRQn
+#define BOARD_SW2_IRQ_HANDLER PORTC_IRQHandler
+#define BOARD_SW2_NAME "SW2"
+
+/* Board led color mapping */
+#define LOGIC_LED_ON 0U
+#define LOGIC_LED_OFF 1U
+#define BOARD_LED_RED_GPIO GPIOA
+#define BOARD_LED_RED_GPIO_PORT PORTA
+#define BOARD_LED_RED_GPIO_PIN 1U
+#define BOARD_LED_GREEN_GPIO GPIOA
+#define BOARD_LED_GREEN_GPIO_PORT PORTA
+#define BOARD_LED_GREEN_GPIO_PIN 2U
+#define BOARD_LED_BLUE_GPIO GPIOD
+#define BOARD_LED_BLUE_GPIO_PORT PORTD
+#define BOARD_LED_BLUE_GPIO_PIN 5U
+
+#define LED_RED_INIT(output) \
+ GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, \
+ &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_RED */
+#define LED_RED_ON() \
+ GPIO_ClearPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
+#define LED_RED_OFF() \
+ GPIO_SetPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */
+#define LED_RED_TOGGLE() \
+ GPIO_TogglePinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
+
+#define LED_GREEN_INIT(output) \
+ GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, \
+ &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_GREEN */
+#define LED_GREEN_ON() \
+ GPIO_ClearPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
+#define LED_GREEN_OFF() \
+ GPIO_SetPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
+#define LED_GREEN_TOGGLE() \
+ GPIO_TogglePinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
+
+#define LED_BLUE_INIT(output) \
+ GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, \
+ &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_BLUE */
+#define LED_BLUE_ON() \
+ GPIO_ClearPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
+#define LED_BLUE_OFF() \
+ GPIO_SetPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
+#define LED_BLUE_TOGGLE() \
+ GPIO_TogglePinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
+
+/* @brief FreeRTOS tickless timer configuration. */
+#define vPortLptmrIsr LPTMR0_IRQHandler /*!< Timer IRQ handler. */
+#define TICKLESS_LPTMR_BASE_PTR LPTMR0 /*!< Tickless timer base address. */
+#define TICKLESS_LPTMR_IRQn LPTMR0_IRQn /*!< Tickless timer IRQ number. */
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus */
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+void BOARD_InitDebugConsole(void);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus */
+
+#endif /* _BOARD_H_ */
diff --git a/right/include/board/clock_config.c b/right/include/board/clock_config.c
new file mode 100644
index 0000000..feda869
--- /dev/null
+++ b/right/include/board/clock_config.c
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "fsl_common.h"
+#include "fsl_smc.h"
+#include "clock_config.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief Clock configuration structure. */
+typedef struct _clock_config
+{
+ mcg_config_t mcgConfig; /*!< MCG configuration. */
+ sim_clock_config_t simConfig; /*!< SIM configuration. */
+ osc_config_t oscConfig; /*!< OSC configuration. */
+ uint32_t coreClock; /*!< core clock frequency. */
+} clock_config_t;
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+/* System clock frequency. */
+extern uint32_t SystemCoreClock;
+
+/* Configuration for enter VLPR mode. Core clock = 4MHz. */
+const clock_config_t g_defaultClockConfigVlpr = {
+ .mcgConfig =
+ {
+ .mcgMode = kMCG_ModeBLPI, /* Work in BLPI mode. */
+ .irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enable. */
+ .ircs = kMCG_IrcFast, /* Select IRC4M. */
+ .fcrdiv = 0U, /* FCRDIV is 0. */
+
+ .frdiv = 0U,
+ .drs = kMCG_DrsLow, /* Low frequency range. */
+ .dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25%. */
+ .oscsel = kMCG_OscselOsc, /* Select OSC. */
+
+ .pll0Config =
+ {
+ .enableMode = 0U, /* Don't eanble PLL. */
+ .prdiv = 0U,
+ .vdiv = 0U,
+ },
+ },
+ .simConfig =
+ {
+ .pllFllSel = 3U, /* PLLFLLSEL select IRC48MCLK. */
+ .er32kSrc = 2U, /* ERCLK32K selection, use RTC. */
+ .clkdiv1 = 0x00040000U, /* SIM_CLKDIV1. */
+ },
+ .oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
+ .capLoad = 0,
+ .workMode = kOSC_ModeOscLowPower,
+ .oscerConfig =
+ {
+ .enableMode = kOSC_ErClkEnable,
+#if (defined(FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER) && FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER)
+ .erclkDiv = 0U,
+#endif
+ }},
+ .coreClock = 4000000U, /* Core clock frequency */
+};
+
+/* Configuration for enter RUN mode. Core clock = 80MHz. */
+const clock_config_t g_defaultClockConfigRun = {
+ .mcgConfig =
+ {
+ .mcgMode = kMCG_ModePEE, /* Work in PEE mode. */
+ .irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enable. */
+ .ircs = kMCG_IrcSlow, /* Select IRC32k.*/
+ .fcrdiv = 0U, /* FCRDIV is 0. */
+
+ .frdiv = 3U,
+ .drs = kMCG_DrsLow, /* Low frequency range. */
+ .dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25%. */
+ .oscsel = kMCG_OscselOsc, /* Select OSC. */
+
+ .pll0Config =
+ {
+ .enableMode = 0U, .prdiv = 0x3U, .vdiv = 0x10U,
+ },
+ },
+ .simConfig =
+ {
+ .pllFllSel = 1U, /* PLLFLLSEL select PLL. */
+ .er32kSrc = 2U, /* ERCLK32K selection, use RTC. */
+ .clkdiv1 = 0x01230000U, /* SIM_CLKDIV1. */
+ },
+ .oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
+ .capLoad = 0,
+ .workMode = kOSC_ModeOscLowPower,
+ .oscerConfig =
+ {
+ .enableMode = kOSC_ErClkEnable,
+#if (defined(FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER) && FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER)
+ .erclkDiv = 0U,
+#endif
+ }},
+ .coreClock = 80000000U, /* Core clock frequency */
+};
+
+/* Configuration for HSRUN mode. Core clock = 120MHz. */
+const clock_config_t g_defaultClockConfigHsrun = {
+ .mcgConfig =
+ {
+ .mcgMode = kMCG_ModePEE, /* Work in PEE mode. */
+ .irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enable. */
+ .ircs = kMCG_IrcSlow, /* Select IRC32k. */
+ .fcrdiv = 0U, /* FCRDIV is 0. */
+
+ .frdiv = 3U,
+ .drs = kMCG_DrsLow, /* Low frequency range. */
+ .dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25%. */
+ .oscsel = kMCG_OscselOsc, /* Select OSC. */
+
+ .pll0Config =
+ {
+ .enableMode = 0U, .prdiv = 0x1U, .vdiv = 0x6U,
+ },
+ },
+ .simConfig =
+ {
+ .pllFllSel = 1U, /* PLLFLLSEL select PLL. */
+ .er32kSrc = 2U, /* ERCLK32K selection, use RTC. */
+ .clkdiv1 = 0x01340000U, /* SIM_CLKDIV1. */
+ },
+ .oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
+ .capLoad = 0,
+ .workMode = kOSC_ModeOscLowPower,
+ .oscerConfig =
+ {
+ .enableMode = kOSC_ErClkEnable,
+#if (defined(FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER) && FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER)
+ .erclkDiv = 0U,
+#endif
+ }},
+ .coreClock = 120000000U, /* Core clock frequency */
+};
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*
+ * How to setup clock using clock driver functions:
+ *
+ * 1. CLOCK_SetSimSafeDivs, to make sure core clock, bus clock, flexbus clock
+ * and flash clock are in allowed range during clock mode switch.
+ *
+ * 2. Call CLOCK_Osc0Init to setup OSC clock, if it is used in target mode.
+ *
+ * 3. Set MCG configuration, MCG includes three parts: FLL clock, PLL clock and
+ * internal reference clock(MCGIRCLK). Follow the steps to setup:
+ *
+ * 1). Call CLOCK_BootToXxxMode to set MCG to target mode.
+ *
+ * 2). If target mode is FBI/BLPI/PBI mode, the MCGIRCLK has been configured
+ * correctly. For other modes, need to call CLOCK_SetInternalRefClkConfig
+ * explicitly to setup MCGIRCLK.
+ *
+ * 3). Don't need to configure FLL explicitly, because if target mode is FLL
+ * mode, then FLL has been configured by the function CLOCK_BootToXxxMode,
+ * if the target mode is not FLL mode, the FLL is disabled.
+ *
+ * 4). If target mode is PEE/PBE/PEI/PBI mode, then the related PLL has been
+ * setup by CLOCK_BootToXxxMode. In FBE/FBI/FEE/FBE mode, the PLL could
+ * be enabled independently, call CLOCK_EnablePll0 explicitly in this case.
+ *
+ * 4. Call CLOCK_SetSimConfig to set the clock configuration in SIM.
+ */
+
+void BOARD_BootClockVLPR(void)
+{
+ CLOCK_SetSimSafeDivs();
+
+ CLOCK_BootToBlpiMode(g_defaultClockConfigVlpr.mcgConfig.fcrdiv, g_defaultClockConfigVlpr.mcgConfig.ircs,
+ g_defaultClockConfigVlpr.mcgConfig.irclkEnableMode);
+
+ CLOCK_SetSimConfig(&g_defaultClockConfigVlpr.simConfig);
+
+ SystemCoreClock = g_defaultClockConfigVlpr.coreClock;
+
+ SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
+ SMC_SetPowerModeVlpr(SMC);
+ while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateVlpr)
+ {
+ }
+}
+
+void BOARD_BootClockRUN(void)
+{
+ CLOCK_SetSimSafeDivs();
+
+ CLOCK_InitOsc0(&g_defaultClockConfigRun.oscConfig);
+ CLOCK_SetXtal0Freq(BOARD_XTAL0_CLK_HZ);
+
+ CLOCK_BootToPeeMode(g_defaultClockConfigRun.mcgConfig.oscsel, kMCG_PllClkSelPll0,
+ &g_defaultClockConfigRun.mcgConfig.pll0Config);
+
+ CLOCK_SetInternalRefClkConfig(g_defaultClockConfigRun.mcgConfig.irclkEnableMode,
+ g_defaultClockConfigRun.mcgConfig.ircs, g_defaultClockConfigRun.mcgConfig.fcrdiv);
+
+ CLOCK_SetSimConfig(&g_defaultClockConfigRun.simConfig);
+
+ SystemCoreClock = g_defaultClockConfigRun.coreClock;
+}
+
+void BOARD_BootClockHSRUN(void)
+{
+ SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
+ SMC_SetPowerModeHsrun(SMC);
+ while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateHsrun)
+ {
+ }
+
+ CLOCK_SetSimSafeDivs();
+
+ CLOCK_InitOsc0(&g_defaultClockConfigHsrun.oscConfig);
+ CLOCK_SetXtal0Freq(BOARD_XTAL0_CLK_HZ);
+
+ CLOCK_BootToPeeMode(g_defaultClockConfigHsrun.mcgConfig.oscsel, kMCG_PllClkSelPll0,
+ &g_defaultClockConfigHsrun.mcgConfig.pll0Config);
+
+ CLOCK_SetInternalRefClkConfig(g_defaultClockConfigHsrun.mcgConfig.irclkEnableMode,
+ g_defaultClockConfigHsrun.mcgConfig.ircs, g_defaultClockConfigHsrun.mcgConfig.fcrdiv);
+
+ CLOCK_SetSimConfig(&g_defaultClockConfigHsrun.simConfig);
+
+ SystemCoreClock = g_defaultClockConfigHsrun.coreClock;
+}
diff --git a/right/include/board/clock_config.h b/right/include/board/clock_config.h
new file mode 100644
index 0000000..7b1ca99
--- /dev/null
+++ b/right/include/board/clock_config.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _CLOCK_CONFIG_H_
+#define _CLOCK_CONFIG_H_
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define BOARD_XTAL0_CLK_HZ 8000000U
+#define BOARD_XTAL32K_CLK_HZ 32768U
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+void BOARD_BootClockVLPR(void);
+void BOARD_BootClockRUN(void);
+void BOARD_BootClockHSRUN(void);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+#endif /* _CLOCK_CONFIG_H_ */
diff --git a/right/include/board/pin_mux.c b/right/include/board/pin_mux.c
new file mode 100644
index 0000000..78c117f
--- /dev/null
+++ b/right/include/board/pin_mux.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "fsl_common.h"
+#include "fsl_port.h"
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/* Function Name : BOARD_InitPins */
+void BOARD_InitPins(void)
+{
+ /* Initialize UART1 pins below */
+ /* Ungate the port clock */
+ CLOCK_EnableClock(kCLOCK_PortE);
+
+ /* Affects PORTE_PCR0 register */
+ PORT_SetPinMux(PORTE, 0u, kPORT_MuxAlt3);
+ /* Affects PORTE_PCR1 register */
+ PORT_SetPinMux(PORTE, 1u, kPORT_MuxAlt3);
+}
diff --git a/right/include/board/pin_mux.h b/right/include/board/pin_mux.h
new file mode 100644
index 0000000..e685a6b
--- /dev/null
+++ b/right/include/board/pin_mux.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PIN_MUX_H_
+#define _PIN_MUX_H_
+
+#include "include/board/board.h"
+#include "fsl_common.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+ /*!
+ * @brief configure all pins for this demo/example
+ *
+ */
+void BOARD_InitPins(void);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+#endif /* _PIN_MUX_H_ */
diff --git a/right/include/usb/usb_device_ch9.c b/right/include/usb/usb_device_ch9.c
new file mode 100644
index 0000000..5414d5c
--- /dev/null
+++ b/right/include/usb/usb_device_ch9.c
@@ -0,0 +1,931 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "usb_device_config.h"
+#include "usb.h"
+
+#include "usb_device.h"
+#include "usb_device_dci.h"
+#include "usb_device_class.h"
+#include "usb_device_ch9.h"
+#if ((defined(USB_DEVICE_CONFIG_NUM)) && (USB_DEVICE_CONFIG_NUM > 0U))
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*!
+ * @brief Standard request callback function typedef.
+ *
+ * This function is used to handle the standard request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+typedef usb_status_t (*usb_standard_request_callback_t)(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+
+/*******************************************************************************
+ * Prototypes
+ ******************************************************************************/
+
+static usb_status_t USB_DeviceCh9GetStatus(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+static usb_status_t USB_DeviceCh9SetClearFeature(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+
+static usb_status_t USB_DeviceCh9SetAddress(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+static usb_status_t USB_DeviceCh9GetDescriptor(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+static usb_status_t USB_DeviceCh9GetConfiguration(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+static usb_status_t USB_DeviceCh9SetConfiguration(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+static usb_status_t USB_DeviceCh9GetInterface(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+static usb_status_t USB_DeviceCh9SetInterface(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+static usb_status_t USB_DeviceCh9SynchFrame(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length);
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+
+/* The function list to handle the standard request. */
+static const usb_standard_request_callback_t s_UsbDeviceStandardRequest[] = {
+ USB_DeviceCh9GetStatus,
+ USB_DeviceCh9SetClearFeature,
+ (usb_standard_request_callback_t)NULL,
+ USB_DeviceCh9SetClearFeature,
+ (usb_standard_request_callback_t)NULL,
+ USB_DeviceCh9SetAddress,
+ USB_DeviceCh9GetDescriptor,
+ (usb_standard_request_callback_t)NULL,
+ USB_DeviceCh9GetConfiguration,
+ USB_DeviceCh9SetConfiguration,
+ USB_DeviceCh9GetInterface,
+ USB_DeviceCh9SetInterface,
+ USB_DeviceCh9SynchFrame,
+};
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*!
+ * @brief Handle get status request.
+ *
+ * This function is used to handle get status request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9GetStatus(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ usb_status_t error = kStatus_USB_InvalidRequest;
+ uint8_t state;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if ((kUSB_DeviceStateAddress != state) && (kUSB_DeviceStateConfigured != state))
+ {
+ return error;
+ }
+
+ if ((setup->bmRequestType & USB_REQUEST_TYPE_RECIPIENT_MASK) == USB_REQUEST_TYPE_RECIPIENT_DEVICE)
+ {
+ /* Get the device status */
+ error =
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDevice, &classHandle->standardTranscationBuffer);
+ classHandle->standardTranscationBuffer = classHandle->standardTranscationBuffer & USB_GET_STATUS_DEVICE_MASK;
+ classHandle->standardTranscationBuffer = USB_SHORT_TO_LITTLE_ENDIAN(classHandle->standardTranscationBuffer);
+ /* The device status length must be USB_DEVICE_STATUS_SIZE. */
+ *length = USB_DEVICE_STATUS_SIZE;
+ }
+ else if ((setup->bmRequestType & USB_REQUEST_TYPE_RECIPIENT_MASK) == USB_REQUEST_TYPE_RECIPIENT_INTERFACE)
+ {
+ /* Get the interface status */
+ error = kStatus_USB_Success;
+ classHandle->standardTranscationBuffer = 0U;
+ /* The interface status length must be USB_INTERFACE_STATUS_SIZE. */
+ *length = USB_INTERFACE_STATUS_SIZE;
+ }
+ else if ((setup->bmRequestType & USB_REQUEST_TYPE_RECIPIENT_MASK) == USB_REQUEST_TYPE_RECIPIENT_ENDPOINT)
+ {
+ /* Get the endpoint status */
+ usb_device_endpoint_status_struct_t endpointStatus;
+ endpointStatus.endpointAddress = (uint8_t)setup->wIndex;
+ endpointStatus.endpointStatus = kUSB_DeviceEndpointStateIdle;
+ error = USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusEndpoint, &endpointStatus);
+ classHandle->standardTranscationBuffer = endpointStatus.endpointStatus & USB_GET_STATUS_ENDPOINT_MASK;
+ classHandle->standardTranscationBuffer = USB_SHORT_TO_LITTLE_ENDIAN(classHandle->standardTranscationBuffer);
+ /* The endpoint status length must be USB_INTERFACE_STATUS_SIZE. */
+ *length = USB_ENDPOINT_STATUS_SIZE;
+ }
+ else
+ {
+ }
+ *buffer = (uint8_t *)&classHandle->standardTranscationBuffer;
+
+ return error;
+}
+
+/*!
+ * @brief Handle set or clear device feature request.
+ *
+ * This function is used to handle set or clear device feature request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9SetClearFeature(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ usb_status_t error = kStatus_USB_InvalidRequest;
+ uint8_t state;
+ uint8_t isSet = 0U;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if ((kUSB_DeviceStateAddress != state) && (kUSB_DeviceStateConfigured != state))
+ {
+ return error;
+ }
+
+ /* Identify the request is set or clear the feature. */
+ if (USB_REQUSET_STANDARD_SET_FEATURE == setup->bRequest)
+ {
+ isSet = 1U;
+ }
+
+ if ((setup->bmRequestType & USB_REQUEST_TYPE_RECIPIENT_MASK) == USB_REQUEST_TYPE_RECIPIENT_DEVICE)
+ {
+ /* Set or Clear the device featrue. */
+ if (USB_REQUSET_STANDARD_FEATURE_SELECTOR_DEVICE_REMOTE_WAKEUP == setup->wValue)
+ {
+ /* Set or Clear the device remote wakeup featrue. */
+ error = USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventSetRemoteWakeup, &isSet);
+ }
+#if (defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)) && \
+ (defined(USB_DEVICE_CONFIG_EHCI_TEST_MODE) && (USB_DEVICE_CONFIG_EHCI_TEST_MODE > 0U))
+ else if (USB_REQUSET_STANDARD_FEATURE_SELECTOR_DEVICE_TEST_MODE == setup->wValue)
+ {
+ state = kUSB_DeviceStateTestMode;
+ error = USB_DeviceSetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+ }
+#endif
+ else
+ {
+ }
+ }
+ else if ((setup->bmRequestType & USB_REQUEST_TYPE_RECIPIENT_MASK) == USB_REQUEST_TYPE_RECIPIENT_ENDPOINT)
+ {
+ /* Set or Clear the endpoint featrue. */
+ if (USB_REQUSET_STANDARD_FEATURE_SELECTOR_ENDPOINT_HALT == setup->wValue)
+ {
+ if (USB_CONTROL_ENDPOINT == (setup->wIndex & USB_ENDPOINT_NUMBER_MASK))
+ {
+ /* Set or Clear the control endpoint status(halt or not). */
+ if (isSet)
+ {
+ USB_DeviceStallEndpoint(
+ classHandle->handle,
+ (setup->wIndex & USB_ENDPOINT_NUMBER_MASK) |
+ (uint8_t)(setup->wIndex >> USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT));
+ }
+ else
+ {
+ USB_DeviceUnstallEndpoint(
+ classHandle->handle,
+ (setup->wIndex & USB_ENDPOINT_NUMBER_MASK) |
+ (uint8_t)(setup->wIndex >> USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT));
+ }
+ }
+
+ /* Set or Clear the endpoint status featrue. */
+ if (isSet)
+ {
+ error = USB_DeviceClassEvent(classHandle->handle, kUSB_DeviceClassEventSetEndpointHalt, &setup->wIndex);
+ }
+ else
+ {
+ error =
+ USB_DeviceClassEvent(classHandle->handle, kUSB_DeviceClassEventClearEndpointHalt, &setup->wIndex);
+ }
+ }
+ else
+ {
+ }
+ }
+ else
+ {
+ }
+
+ return error;
+}
+
+/*!
+ * @brief Handle set address request.
+ *
+ * This function is used to handle set address request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state.
+ */
+static usb_status_t USB_DeviceCh9SetAddress(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ usb_status_t error = kStatus_USB_InvalidRequest;
+ uint8_t state;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if ((kUSB_DeviceStateAddressing != state) && (kUSB_DeviceStateAddress != state) &&
+ (kUSB_DeviceStateDefault != state))
+ {
+ return error;
+ }
+
+ if (kUSB_DeviceStateAddressing != state)
+ {
+ /* If the device address is not setting, pass the address and the device state will change to
+ * kUSB_DeviceStateAddressing internally. */
+ state = setup->wValue & 0xFFU;
+ error = USB_DeviceSetStatus(classHandle->handle, kUSB_DeviceStatusAddress, &state);
+ }
+ else
+ {
+ /* If the device address is setting, set device address and the address will be write into the controller
+ * internally. */
+ error = USB_DeviceSetStatus(classHandle->handle, kUSB_DeviceStatusAddress, NULL);
+ /* And then change the device state to kUSB_DeviceStateAddress. */
+ if (kStatus_USB_Success == error)
+ {
+ state = kUSB_DeviceStateAddress;
+ error = USB_DeviceSetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+ }
+ }
+
+ return error;
+}
+
+/*!
+ * @brief Handle get descriptor request.
+ *
+ * This function is used to handle get descriptor request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9GetDescriptor(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ usb_device_get_descriptor_common_union_t commonDescriptor;
+ usb_status_t error = kStatus_USB_InvalidRequest;
+ uint8_t state;
+ uint8_t descriptorType = (uint8_t)((setup->wValue & 0xFF00U) >> 8U);
+ uint8_t descriptorIndex = (uint8_t)((setup->wValue & 0x00FFU));
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if ((kUSB_DeviceStateAddress != state) && (kUSB_DeviceStateConfigured != state) &&
+ (kUSB_DeviceStateDefault != state))
+ {
+ return error;
+ }
+ commonDescriptor.commonDescriptor.length = setup->wLength;
+ if (USB_DESCRIPTOR_TYPE_DEVICE == descriptorType)
+ {
+ /* Get the device descriptor */
+ error = USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetDeviceDescriptor,
+ &commonDescriptor.deviceDescriptor);
+ }
+ else if (USB_DESCRIPTOR_TYPE_CONFIGURE == descriptorType)
+ {
+ /* Get the configuration descriptor */
+ commonDescriptor.configurationDescriptor.configuration = descriptorIndex;
+ error = USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetConfigurationDescriptor,
+ &commonDescriptor.configurationDescriptor);
+ }
+ else if (USB_DESCRIPTOR_TYPE_STRING == descriptorType)
+ {
+ /* Get the string descriptor */
+ commonDescriptor.stringDescriptor.stringIndex = descriptorIndex;
+ commonDescriptor.stringDescriptor.languageId = setup->wIndex;
+ error = USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetStringDescriptor,
+ &commonDescriptor.stringDescriptor);
+ }
+#if (defined(USB_DEVICE_CONFIG_HID) && (USB_DEVICE_CONFIG_HID > 0U))
+ else if (USB_DESCRIPTOR_TYPE_HID == descriptorType)
+ {
+ /* Get the hid descriptor */
+ commonDescriptor.hidDescriptor.interfaceNumber = setup->wIndex;
+ error = USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetHidDescriptor,
+ &commonDescriptor.hidDescriptor);
+ }
+ else if (USB_DESCRIPTOR_TYPE_HID_REPORT == descriptorType)
+ {
+ /* Get the hid report descriptor */
+ commonDescriptor.hidReportDescriptor.interfaceNumber = setup->wIndex;
+ error = USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetHidReportDescriptor,
+ &commonDescriptor.hidReportDescriptor);
+ }
+ else if (USB_DESCRIPTOR_TYPE_HID_PHYSICAL == descriptorType)
+ {
+ /* Get the hid physical descriptor */
+ commonDescriptor.hidPhysicalDescriptor.index = descriptorIndex;
+ commonDescriptor.hidPhysicalDescriptor.interfaceNumber = setup->wIndex;
+ error = USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetHidPhysicalDescriptor,
+ &commonDescriptor.hidPhysicalDescriptor);
+ }
+#endif
+ else
+ {
+ }
+ *buffer = commonDescriptor.commonDescriptor.buffer;
+ *length = commonDescriptor.commonDescriptor.length;
+ return error;
+}
+
+/*!
+ * @brief Handle get current configuration request.
+ *
+ * This function is used to handle get current configuration request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9GetConfiguration(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ uint8_t state;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if ((kUSB_DeviceStateAddress != state) && ((kUSB_DeviceStateConfigured != state)))
+ {
+ return kStatus_USB_InvalidRequest;
+ }
+
+ *length = USB_CONFIGURE_SIZE;
+ *buffer = (uint8_t *)&classHandle->standardTranscationBuffer;
+ return USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetConfiguration,
+ &classHandle->standardTranscationBuffer);
+}
+
+/*!
+ * @brief Handle set current configuration request.
+ *
+ * This function is used to handle set current configuration request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9SetConfiguration(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ uint8_t state;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if ((kUSB_DeviceStateAddress != state) && (kUSB_DeviceStateConfigured != state))
+ {
+ return kStatus_USB_InvalidRequest;
+ }
+
+ /* The device state is changed to kUSB_DeviceStateConfigured */
+ state = kUSB_DeviceStateConfigured;
+ USB_DeviceSetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+ if (!setup->wValue)
+ {
+ /* If the new configuration is zero, the device state is changed to kUSB_DeviceStateAddress */
+ state = kUSB_DeviceStateAddress;
+ USB_DeviceSetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+ }
+
+ /* Notify the class layer the configuration is changed */
+ USB_DeviceClassEvent(classHandle->handle, kUSB_DeviceClassEventSetConfiguration, &setup->wValue);
+ /* Notify the application the configuration is changed */
+ return USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventSetConfiguration, &setup->wValue);
+}
+
+/*!
+ * @brief Handle get the alternate setting of a interface request.
+ *
+ * This function is used to handle get the alternate setting of a interface request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9GetInterface(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ usb_status_t error = kStatus_USB_InvalidRequest;
+ uint8_t state;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if (state != kUSB_DeviceStateConfigured)
+ {
+ return error;
+ }
+ *length = USB_INTERFACE_SIZE;
+ *buffer = (uint8_t *)&classHandle->standardTranscationBuffer;
+ classHandle->standardTranscationBuffer = setup->wIndex & 0xFFU;
+ /* The Bit[15~8] is used to save the interface index, and the alternate setting will be saved in Bit[7~0] by
+ * application. */
+ return USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventGetInterface,
+ &classHandle->standardTranscationBuffer);
+}
+
+/*!
+ * @brief Handle set the alternate setting of a interface request.
+ *
+ * This function is used to handle set the alternate setting of a interface request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9SetInterface(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ uint8_t state;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if (state != kUSB_DeviceStateConfigured)
+ {
+ return kStatus_USB_InvalidRequest;
+ }
+ classHandle->standardTranscationBuffer = ((setup->wIndex & 0xFFU) << 8U) | (setup->wValue & 0xFFU);
+ /* Notify the class driver the alternate setting of the interface is changed. */
+ /* The Bit[15~8] is used to save the interface index, and the alternate setting is saved in Bit[7~0]. */
+ USB_DeviceClassEvent(classHandle->handle, kUSB_DeviceClassEventSetInterface,
+ &classHandle->standardTranscationBuffer);
+ /* Notify the application the alternate setting of the interface is changed. */
+ /* The Bit[15~8] is used to save the interface index, and the alternate setting will is saved in Bit[7~0]. */
+ return USB_DeviceClassCallback(classHandle->handle, kUSB_DeviceEventSetInterface,
+ &classHandle->standardTranscationBuffer);
+}
+
+/*!
+ * @brief Handle get sync frame request.
+ *
+ * This function is used to handle get sync frame request.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @retval kStatus_USB_Success The requst is handled successfully.
+ * @retval kStatus_USB_InvalidRequest The request can not be handle in current device state,
+ * or, the request is unsupported.
+ */
+static usb_status_t USB_DeviceCh9SynchFrame(usb_device_common_class_struct_t *classHandle,
+ usb_setup_struct_t *setup,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ usb_status_t error = kStatus_USB_InvalidRequest;
+ uint8_t state;
+
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if (state != kUSB_DeviceStateConfigured)
+ {
+ return error;
+ }
+
+ classHandle->standardTranscationBuffer = setup->wIndex;
+ /* Get the sync frame value */
+ error =
+ USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusSynchFrame, &classHandle->standardTranscationBuffer);
+ *buffer = (uint8_t *)&classHandle->standardTranscationBuffer;
+ *length = sizeof(classHandle->standardTranscationBuffer);
+
+ return error;
+}
+
+/*!
+ * @brief Send the reponse to the host.
+ *
+ * This function is used to send the reponse to the host.
+ *
+ * There are two cases this function will be called.
+ * Case one when a setup packet is received in control endpoint callback function:
+ * 1. If there is not data phase in the setup transfer, the function will prime an IN transfer with the data
+ * length is zero for status phase.
+ * 2. If there is an IN data phase, the function will prime an OUT transfer with the actual length to need to
+ * send for data phase. And then prime an IN transfer with the data length is zero for status phase.
+ * 3. If there is an OUT data phase, the function will prime an IN transfer with the actual length to want to
+ * receive for data phase.
+ *
+ * Case two when is not a setup packet received in control endpoint callback function:
+ * 1. The function will prime an IN transfer with data length is zero for status phase.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param setup The pointer of the setup packet.
+ * @param error The error code returned from the standard request fucntion.
+ * @param stage The stage of the control transfer.
+ * @param buffer It is an out parameter, is used to save the buffer address to response the host's request.
+ * @param length It is an out parameter, the data length.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+static usb_status_t USB_DeviceControlCallbackFeedback(usb_device_handle handle,
+ usb_setup_struct_t *setup,
+ usb_status_t error,
+ usb_device_control_read_write_sequence_t stage,
+ uint8_t **buffer,
+ uint32_t *length)
+{
+ usb_status_t errorCode = kStatus_USB_Error;
+ uint8_t direction = USB_IN;
+
+ if (kStatus_USB_InvalidRequest == error)
+ {
+ /* Stall the control pipe when the request is unsupported. */
+ if ((!((setup->bmRequestType & USB_REQUEST_TYPE_TYPE_MASK) == USB_REQUEST_TYPE_TYPE_STANDARD)) &&
+ ((setup->bmRequestType & USB_REQUSET_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_OUT) && (setup->wLength) &&
+ (kUSB_DeviceControlPipeSetupStage == stage))
+ {
+ direction = USB_OUT;
+ }
+ errorCode = USB_DeviceStallEndpoint(
+ handle,
+ (USB_CONTROL_ENDPOINT) | (uint8_t)((uint32_t)direction << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT));
+ }
+ else
+ {
+ if (*length > setup->wLength)
+ {
+ *length = setup->wLength;
+ }
+ errorCode = USB_DeviceSendRequest(handle, (USB_CONTROL_ENDPOINT), *buffer, *length);
+
+ if ((kStatus_USB_Success == errorCode) &&
+ (USB_REQUEST_TYPE_DIR_IN == (setup->bmRequestType & USB_REQUSET_TYPE_DIR_MASK)))
+ {
+ errorCode = USB_DeviceRecvRequest(handle, (USB_CONTROL_ENDPOINT), (uint8_t *)NULL, 0U);
+ }
+ }
+ return errorCode;
+}
+
+/*!
+ * @brief Control endpoint callback function.
+ *
+ * This callback function is used to notify uplayer the tranfser result of a transfer.
+ * This callback pointer is passed when a sepcified endpoint initialied by calling API USB_DeviceInitEndpoint.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param message The result of a transfer, includes transfer buffer, transfer length and whether is in setup
+ * phase for control pipe.
+ * @param callbackParam The paramter for this callback. It is same with
+ * usb_device_endpoint_callback_struct_t::callbackParam.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceControlCallback(usb_device_handle handle,
+ usb_device_endpoint_callback_message_struct_t *message,
+ void *callbackParam)
+{
+ usb_setup_struct_t *deviceSetup;
+ usb_device_common_class_struct_t *classHandle;
+ uint8_t *buffer = (uint8_t *)NULL;
+ uint32_t length = 0U;
+ usb_status_t error = kStatus_USB_InvalidRequest;
+ uint8_t state;
+
+ if ((0xFFFFFFFFU == message->length) || (NULL == callbackParam))
+ {
+ return error;
+ }
+
+ classHandle = (usb_device_common_class_struct_t *)callbackParam;
+ deviceSetup = (usb_setup_struct_t *)&classHandle->setupBuffer[0];
+ USB_DeviceGetStatus(handle, kUSB_DeviceStatusDeviceState, &state);
+
+ if (message->isSetup)
+ {
+ if ((USB_SETUP_PACKET_SIZE != message->length) || (NULL == message->buffer))
+ {
+ /* If a invalid setup is received, the control pipes should be de-init and init again.
+ * Due to the IP can not meet this require, it is revesed for feature.
+ */
+ /*
+ USB_DeviceDeinitEndpoint(handle,
+ USB_CONTROL_ENDPOINT | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT));
+ USB_DeviceDeinitEndpoint(handle,
+ USB_CONTROL_ENDPOINT | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT));
+ USB_DeviceControlPipeInit(handle, callbackParam);
+ */
+ return error;
+ }
+ /* Receive a setup request */
+ usb_setup_struct_t *setup = (usb_setup_struct_t *)(message->buffer);
+
+ /* Copy the setup packet to the application buffer */
+ deviceSetup->wValue = USB_SHORT_FROM_LITTLE_ENDIAN(setup->wValue);
+ deviceSetup->wIndex = USB_SHORT_FROM_LITTLE_ENDIAN(setup->wIndex);
+ deviceSetup->wLength = USB_SHORT_FROM_LITTLE_ENDIAN(setup->wLength);
+ deviceSetup->bRequest = setup->bRequest;
+ deviceSetup->bmRequestType = setup->bmRequestType;
+
+ if ((deviceSetup->bmRequestType & USB_REQUEST_TYPE_TYPE_MASK) == USB_REQUEST_TYPE_TYPE_STANDARD)
+ {
+ /* Handle the standard request */
+ if (s_UsbDeviceStandardRequest[deviceSetup->bRequest] != (usb_standard_request_callback_t)NULL)
+ {
+ error = s_UsbDeviceStandardRequest[deviceSetup->bRequest](classHandle, deviceSetup, &buffer, &length);
+ }
+ }
+ else
+ {
+ if ((deviceSetup->wLength) &&
+ ((deviceSetup->bmRequestType & USB_REQUSET_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_OUT))
+ {
+ /* Class or vendor request with the OUT data phase. */
+ if ((deviceSetup->wLength) &&
+ ((deviceSetup->bmRequestType & USB_REQUEST_TYPE_TYPE_CLASS) == USB_REQUEST_TYPE_TYPE_CLASS))
+ {
+ /* Get data buffer to receive the data from the host. */
+ usb_device_control_request_struct_t controlRequest;
+ controlRequest.buffer = (uint8_t *)NULL;
+ controlRequest.isSetup = 1U;
+ controlRequest.setup = deviceSetup;
+ controlRequest.length = deviceSetup->wLength;
+ error = USB_DeviceClassEvent(handle, kUSB_DeviceClassEventClassRequest, &controlRequest);
+ length = controlRequest.length;
+ buffer = controlRequest.buffer;
+ }
+ else if ((deviceSetup->wLength) &&
+ ((deviceSetup->bmRequestType & USB_REQUEST_TYPE_TYPE_VENDOR) == USB_REQUEST_TYPE_TYPE_VENDOR))
+ {
+ /* Get data buffer to receive the data from the host. */
+ usb_device_control_request_struct_t controlRequest;
+ controlRequest.buffer = (uint8_t *)NULL;
+ controlRequest.isSetup = 1U;
+ controlRequest.setup = deviceSetup;
+ controlRequest.length = deviceSetup->wLength;
+ error = USB_DeviceClassCallback(handle, kUSB_DeviceEventVendorRequest, &controlRequest);
+ length = controlRequest.length;
+ buffer = controlRequest.buffer;
+ }
+ else
+ {
+ }
+ if (kStatus_USB_Success == error)
+ {
+ /* Prime an OUT transfer */
+ error = USB_DeviceRecvRequest(handle, USB_CONTROL_ENDPOINT, buffer, deviceSetup->wLength);
+ return error;
+ }
+ }
+ else
+ {
+ /* Class or vendor request with the IN data phase. */
+ if (((deviceSetup->bmRequestType & USB_REQUEST_TYPE_TYPE_CLASS) == USB_REQUEST_TYPE_TYPE_CLASS))
+ {
+ /* Get data buffer to response the host. */
+ usb_device_control_request_struct_t controlRequest;
+ controlRequest.buffer = (uint8_t *)NULL;
+ controlRequest.isSetup = 1U;
+ controlRequest.setup = deviceSetup;
+ controlRequest.length = deviceSetup->wLength;
+ error = USB_DeviceClassEvent(handle, kUSB_DeviceClassEventClassRequest, &controlRequest);
+ length = controlRequest.length;
+ buffer = controlRequest.buffer;
+ }
+ else if (((deviceSetup->bmRequestType & USB_REQUEST_TYPE_TYPE_VENDOR) == USB_REQUEST_TYPE_TYPE_VENDOR))
+ {
+ /* Get data buffer to response the host. */
+ usb_device_control_request_struct_t controlRequest;
+ controlRequest.buffer = (uint8_t *)NULL;
+ controlRequest.isSetup = 1U;
+ controlRequest.setup = deviceSetup;
+ controlRequest.length = deviceSetup->wLength;
+ error = USB_DeviceClassCallback(handle, kUSB_DeviceEventVendorRequest, &controlRequest);
+ length = controlRequest.length;
+ buffer = controlRequest.buffer;
+ }
+ else
+ {
+ }
+ }
+ }
+ /* Send the reponse to the host. */
+ error = USB_DeviceControlCallbackFeedback(handle, deviceSetup, error, kUSB_DeviceControlPipeSetupStage, &buffer,
+ &length);
+ }
+ else if (kUSB_DeviceStateAddressing == state)
+ {
+ /* Set the device address to controller. */
+ error = s_UsbDeviceStandardRequest[deviceSetup->bRequest](classHandle, deviceSetup, &buffer, &length);
+ }
+#if (defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)) && \
+ (defined(USB_DEVICE_CONFIG_EHCI_TEST_MODE) && (USB_DEVICE_CONFIG_EHCI_TEST_MODE > 0U))
+ else if (kUSB_DeviceStateTestMode == state)
+ {
+ uint8_t portTestControl = (uint8_t)(deviceSetup->wIndex >> 8);
+ /* Set the controller.into test mode. */
+ error = USB_DeviceSetStatus(handle, kUSB_DeviceStatusTestMode, &portTestControl);
+ }
+#endif
+ else if ((message->length) && (deviceSetup->wLength) &&
+ ((deviceSetup->bmRequestType & USB_REQUSET_TYPE_DIR_MASK) == USB_REQUEST_TYPE_DIR_OUT))
+ {
+ if (((deviceSetup->bmRequestType & USB_REQUEST_TYPE_TYPE_CLASS) == USB_REQUEST_TYPE_TYPE_CLASS))
+ {
+ /* Data received in OUT phase, and notify the class driver. */
+ usb_device_control_request_struct_t controlRequest;
+ controlRequest.buffer = message->buffer;
+ controlRequest.isSetup = 0U;
+ controlRequest.setup = deviceSetup;
+ controlRequest.length = message->length;
+ error = USB_DeviceClassEvent(handle, kUSB_DeviceClassEventClassRequest, &controlRequest);
+ }
+ else if (((deviceSetup->bmRequestType & USB_REQUEST_TYPE_TYPE_VENDOR) == USB_REQUEST_TYPE_TYPE_VENDOR))
+ {
+ /* Data received in OUT phase, and notify the application. */
+ usb_device_control_request_struct_t controlRequest;
+ controlRequest.buffer = message->buffer;
+ controlRequest.isSetup = 0U;
+ controlRequest.setup = deviceSetup;
+ controlRequest.length = message->length;
+ error = USB_DeviceClassCallback(handle, kUSB_DeviceEventVendorRequest, &controlRequest);
+ }
+ else
+ {
+ }
+ /* Send the reponse to the host. */
+ error = USB_DeviceControlCallbackFeedback(handle, deviceSetup, error, kUSB_DeviceControlPipeDataStage, &buffer,
+ &length);
+ }
+ else
+ {
+ }
+ return error;
+}
+
+/*!
+ * @brief Control endpoint initialization function.
+ *
+ * This callback function is used to initialize the control pipes.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param param The up layer handle.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceControlPipeInit(usb_device_handle handle, void *param)
+{
+ usb_device_endpoint_init_struct_t epInitStruct;
+ usb_device_endpoint_callback_struct_t endpointCallback;
+ usb_status_t error;
+
+ endpointCallback.callbackFn = USB_DeviceControlCallback;
+ endpointCallback.callbackParam = param;
+
+ epInitStruct.zlt = 1U;
+ epInitStruct.transferType = USB_ENDPOINT_CONTROL;
+ epInitStruct.endpointAddress = USB_CONTROL_ENDPOINT | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
+ epInitStruct.maxPacketSize = USB_CONTROL_MAX_PACKET_SIZE;
+ /* Initialize the control IN pipe */
+ error = USB_DeviceInitEndpoint(handle, &epInitStruct, &endpointCallback);
+
+ if (kStatus_USB_Success != error)
+ {
+ return error;
+ }
+ epInitStruct.endpointAddress = USB_CONTROL_ENDPOINT | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
+ /* Initialize the control OUT pipe */
+ error = USB_DeviceInitEndpoint(handle, &epInitStruct, &endpointCallback);
+
+ if (kStatus_USB_Success != error)
+ {
+ USB_DeviceDeinitEndpoint(handle,
+ USB_CONTROL_ENDPOINT | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT));
+ return error;
+ }
+
+ return kStatus_USB_Success;
+}
+#endif /* USB_DEVICE_CONFIG_NUM */
diff --git a/right/include/usb/usb_device_ch9.h b/right/include/usb/usb_device_ch9.h
new file mode 100644
index 0000000..d73093e
--- /dev/null
+++ b/right/include/usb/usb_device_ch9.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __USB_DEVICE_CH9_H__
+#define __USB_DEVICE_CH9_H__
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*!
+ * @addtogroup usb_device_ch9
+ * @{
+ */
+/*! @brief Defines USB device status size when the host request to get device status */
+#define USB_DEVICE_STATUS_SIZE (0x02U)
+
+/*! @brief Defines USB device interface status size when the host request to get interface status */
+#define USB_INTERFACE_STATUS_SIZE (0x02U)
+
+/*! @brief Defines USB device endpoint status size when the host request to get endpoint status */
+#define USB_ENDPOINT_STATUS_SIZE (0x02U)
+
+/*! @brief Defines USB device configuration size when the host request to get current configuration */
+#define USB_CONFIGURE_SIZE (0X01U)
+
+/*! @brief Defines USB device interface alternate setting size when the host request to get interface alternate setting
+ */
+#define USB_INTERFACE_SIZE (0X01U)
+
+/*! @brief Defines USB device status mask */
+#define USB_GET_STATUS_DEVICE_MASK (0x03U)
+
+/*! @brief Defines USB device interface status mask */
+#define USB_GET_STATUS_INTERFACE_MASK (0x03U)
+
+/*! @brief Defines USB device endpoint status mask */
+#define USB_GET_STATUS_ENDPOINT_MASK (0x03U)
+
+/*! @brief Control read and write sequence */
+typedef enum _usb_device_control_read_write_sequence
+{
+ kUSB_DeviceControlPipeSetupStage = 0U, /*!< Setup stage */
+ kUSB_DeviceControlPipeDataStage, /*!< Data stage */
+ kUSB_DeviceControlPipeStatusStage, /*!< status stage */
+} usb_device_control_read_write_sequence_t;
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+/*!
+ * @brief Initializes the control pipes.
+ *
+ * The function is used to initialize the control pipes. This function should be called when event
+ * kUSB_DeviceEventBusReset is received.
+ *
+ * @param[in] handle The device handle.
+ * @param[in] param The event parameter.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+extern usb_status_t USB_DeviceControlPipeInit(usb_device_handle handle, void *param);
+
+#if defined(__cplusplus)
+}
+#endif
+
+/*! @}*/
+
+#endif /* __USB_DEVICE_CH9_H__ */
diff --git a/right/include/usb/usb_device_class.c b/right/include/usb/usb_device_class.c
new file mode 100644
index 0000000..b8032eb
--- /dev/null
+++ b/right/include/usb/usb_device_class.c
@@ -0,0 +1,571 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "usb_device_config.h"
+#include "usb.h"
+
+#include "usb_device.h"
+#include "usb_device_ch9.h"
+#include "usb_device_class.h"
+
+#if ((defined(USB_DEVICE_CONFIG_NUM)) && (USB_DEVICE_CONFIG_NUM > 0U))
+/* Include the class drivers according to the usb_device_config.h. */
+#if ((defined(USB_DEVICE_CONFIG_HID)) && (USB_DEVICE_CONFIG_HID > 0U))
+#include "usb_device_hid.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_CDC_ACM)) && (USB_DEVICE_CONFIG_CDC_ACM > 0U))
+#include "usb_device_cdc_acm.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_MSC)) && (USB_DEVICE_CONFIG_MSC > 0U))
+#include "usb_device_msc.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_AUDIO)) && (USB_DEVICE_CONFIG_AUDIO > 0U))
+#include "usb_device_audio.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_PHDC)) && (USB_DEVICE_CONFIG_PHDC > 0U))
+#include "usb_device_phdc.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_VIDEO)) && (USB_DEVICE_CONFIG_VIDEO > 0U))
+#include "usb_device_video.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_PRINTER)) && (USB_DEVICE_CONFIG_PRINTER > 0U))
+#include "usb_device_printer_config.h"
+#include "usb_device_printer.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_DFU)) && (USB_DEVICE_CONFIG_DFU > 0U))
+#include "usb_device_dfu_config.h"
+#include "usb_device_dfu.h"
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_CCID)) && (USB_DEVICE_CONFIG_CCID > 0U))
+#include "usb_device_ccid.h"
+#endif
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Prototypes
+ ******************************************************************************/
+static usb_status_t USB_DeviceClassAllocateHandle(uint8_t controllerId, usb_device_common_class_struct_t **handle);
+static usb_status_t USB_DeviceClassFreeHandle(uint8_t controllerId);
+static usb_status_t USB_DeviceClassGetHandleByControllerId(uint8_t controllerId,
+ usb_device_common_class_struct_t **handle);
+static usb_status_t USB_DeviceClassGetHandleByDeviceHandle(usb_device_handle deviceHandle,
+ usb_device_common_class_struct_t **handle);
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+
+/* The device class driver list. */
+static const usb_device_class_map_t s_UsbDeviceClassInterfaceMap[] = {
+#if ((defined(USB_DEVICE_CONFIG_HID)) && (USB_DEVICE_CONFIG_HID > 0U))
+ {USB_DeviceHidInit, USB_DeviceHidDeinit, USB_DeviceHidEvent, kUSB_DeviceClassTypeHid},
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_CDC_ACM)) && (USB_DEVICE_CONFIG_CDC_ACM > 0U))
+ {USB_DeviceCdcAcmInit, USB_DeviceCdcAcmDeinit, USB_DeviceCdcAcmEvent, kUSB_DeviceClassTypeCdc},
+#endif
+
+#if ((defined(USB_DEVICE_CONFIG_MSC)) && (USB_DEVICE_CONFIG_MSC > 0U))
+ {USB_DeviceMscInit, USB_DeviceMscDeinit, USB_DeviceMscEvent, kUSB_DeviceClassTypeMsc},
+#endif
+
+#if ((defined USB_DEVICE_CONFIG_AUDIO) && (USB_DEVICE_CONFIG_AUDIO > 0U))
+ {USB_DeviceAudioInit, USB_DeviceAudioDeinit, USB_DeviceAudioEvent, kUSB_DeviceClassTypeAudio},
+#endif
+
+#if ((defined USB_DEVICE_CONFIG_PHDC) && (USB_DEVICE_CONFIG_PHDC > 0U))
+ {USB_DevicePhdcInit, USB_DevicePhdcDeinit, USB_DevicePhdcEvent, kUSB_DeviceClassTypePhdc},
+#endif
+
+#if ((defined USB_DEVICE_CONFIG_VIDEO) && (USB_DEVICE_CONFIG_VIDEO > 0U))
+ {USB_DeviceVideoInit, USB_DeviceVideoDeinit, USB_DeviceVideoEvent, kUSB_DeviceClassTypeVideo},
+#endif
+
+#if ((defined USB_DEVICE_CONFIG_PRINTER) && (USB_DEVICE_CONFIG_PRINTER > 0U))
+ {usb_device_printer_init, usb_device_printer_deinit, usb_device_printer_event, kUSB_DeviceClassTypePrinter},
+#endif
+
+#if ((defined USB_DEVICE_CONFIG_DFU) && (USB_DEVICE_CONFIG_DFU > 0U))
+ {usb_device_dfu_init, usb_device_dfu_deinit, usb_device_dfu_event, kUSB_DeviceClassTypeDfu},
+#endif
+
+#if ((defined USB_DEVICE_CONFIG_CCID) && (USB_DEVICE_CONFIG_CCID > 0U))
+ {USB_DeviceCcidInit, USB_DeviceCcidDeinit, USB_DeviceCcidEvent, kUSB_DeviceClassTypeCcid},
+#endif
+
+ {(usb_device_class_init_call_t)NULL, (usb_device_class_deinit_call_t)NULL, (usb_device_class_event_callback_t)NULL,
+ (usb_device_class_type_t)0},
+};
+
+USB_GLOBAL static usb_device_common_class_struct_t s_UsbDeviceCommonClassStruct[USB_DEVICE_CONFIG_NUM];
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*!
+ * @brief Allocate a device common class handle.
+ *
+ * This function allocates a a device common class handle.
+ *
+ * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t.
+ * @param handle It is out parameter, is used to return pointer of the device common class handle to the
+ * caller.
+ *
+ * @retval kStatus_USB_Success Get a device handle successfully.
+ * @retval kStatus_USB_Busy Cannot allocate a common class handle.
+ * @retval kStatus_USB_Error The common class has been initialized.
+ */
+static usb_status_t USB_DeviceClassAllocateHandle(uint8_t controllerId, usb_device_common_class_struct_t **handle)
+{
+ int32_t count;
+ USB_OSA_SR_ALLOC();
+
+ USB_OSA_ENTER_CRITICAL();
+ /* Check the controller is initialized or not. */
+ for (count = 0U; count < USB_DEVICE_CONFIG_NUM; count++)
+ {
+ if ((NULL != s_UsbDeviceCommonClassStruct[count].handle) &&
+ (controllerId == s_UsbDeviceCommonClassStruct[count].controllerId))
+ {
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_Error;
+ }
+ }
+ /* Get a free common class handle. */
+ for (count = 0U; count < USB_DEVICE_CONFIG_NUM; count++)
+ {
+ if (NULL == s_UsbDeviceCommonClassStruct[count].handle)
+ {
+ s_UsbDeviceCommonClassStruct[count].controllerId = controllerId;
+ *handle = &s_UsbDeviceCommonClassStruct[count];
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_Success;
+ }
+ }
+
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_Busy;
+}
+
+/*!
+ * @brief Free a device common class handle.
+ *
+ * This function frees a device common class handle.
+ *
+ * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t.
+ *
+ * @retval kStatus_USB_Success Free device hanlde successfully.
+ * @retval kStatus_USB_InvalidParameter The common class can not be found.
+ */
+static usb_status_t USB_DeviceClassFreeHandle(uint8_t controllerId)
+{
+ int32_t count = 0U;
+ USB_OSA_SR_ALLOC();
+
+ USB_OSA_ENTER_CRITICAL();
+ for (; count < USB_DEVICE_CONFIG_NUM; count++)
+ {
+ if ((NULL != s_UsbDeviceCommonClassStruct[count].handle) &&
+ (controllerId == s_UsbDeviceCommonClassStruct[count].controllerId))
+ {
+ s_UsbDeviceCommonClassStruct[count].handle = NULL;
+ s_UsbDeviceCommonClassStruct[count].configList = (usb_device_class_config_list_struct_t *)NULL;
+ s_UsbDeviceCommonClassStruct[count].controllerId = 0U;
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_Success;
+ }
+ }
+ USB_OSA_EXIT_CRITICAL();
+
+ return kStatus_USB_InvalidParameter;
+}
+
+/*!
+ * @brief Get the device common class handle according to the controller id.
+ *
+ * This function gets the device common class handle according to the controller id.
+ *
+ * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t.
+ * @param handle It is out parameter, is used to return pointer of the device common class handle to the
+ * caller.
+ *
+ * @retval kStatus_USB_Success Free device hanlde successfully.
+ * @retval kStatus_USB_InvalidParameter The common class can not be found.
+ */
+static usb_status_t USB_DeviceClassGetHandleByControllerId(uint8_t controllerId,
+ usb_device_common_class_struct_t **handle)
+{
+ int32_t count = 0U;
+ USB_OSA_SR_ALLOC();
+
+ USB_OSA_ENTER_CRITICAL();
+ for (; count < USB_DEVICE_CONFIG_NUM; count++)
+ {
+ if ((NULL != s_UsbDeviceCommonClassStruct[count].handle) &&
+ (controllerId == s_UsbDeviceCommonClassStruct[count].controllerId))
+ {
+ *handle = &s_UsbDeviceCommonClassStruct[count];
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_Success;
+ }
+ }
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_InvalidParameter;
+}
+
+/*!
+ * @brief Get the device common class handle according to the device handle.
+ *
+ * This function gets the device common class handle according to the device handle.
+ *
+ * @param deviceHandle The device handle, got from the USB_DeviceInit.
+ * @param handle It is out parameter, is used to return pointer of the device common class handle to the
+ * caller.
+ *
+ * @retval kStatus_USB_Success Free device hanlde successfully.
+ * @retval kStatus_USB_InvalidParameter The common class can not be found.
+ */
+static usb_status_t USB_DeviceClassGetHandleByDeviceHandle(usb_device_handle deviceHandle,
+ usb_device_common_class_struct_t **handle)
+{
+ int32_t count = 0U;
+ USB_OSA_SR_ALLOC();
+
+ USB_OSA_ENTER_CRITICAL();
+ for (; count < USB_DEVICE_CONFIG_NUM; count++)
+ {
+ if (deviceHandle == s_UsbDeviceCommonClassStruct[count].handle)
+ {
+ *handle = &s_UsbDeviceCommonClassStruct[count];
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_Success;
+ }
+ }
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_InvalidParameter;
+}
+
+/*!
+ * @brief Get the device handle according to the controller id.
+ *
+ * This function gets the device handle according to the controller id.
+ *
+ * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t.
+ * @param handle It is out parameter, is used to return pointer of the device handle to the caller.
+ *
+ * @retval kStatus_USB_Success Free device hanlde successfully.
+ * @retval kStatus_USB_InvalidParameter The device handle not be found.
+ */
+usb_status_t USB_DeviceClassGetDeviceHandle(uint8_t controllerId, usb_device_handle *handle)
+{
+ int32_t count = 0U;
+ USB_OSA_SR_ALLOC();
+
+ USB_OSA_ENTER_CRITICAL();
+ for (; count < USB_DEVICE_CONFIG_NUM; count++)
+ {
+ if ((NULL != s_UsbDeviceCommonClassStruct[count].handle) &&
+ (controllerId == s_UsbDeviceCommonClassStruct[count].controllerId))
+ {
+ *handle = s_UsbDeviceCommonClassStruct[count].handle;
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_Success;
+ }
+ }
+ USB_OSA_EXIT_CRITICAL();
+ return kStatus_USB_InvalidParameter;
+}
+
+/*!
+ * @brief Handle the event passed to the class drivers.
+ *
+ * This function handles the event passed to the class drivers.
+ *
+ * @param handle The device handle, got from the USB_DeviceInit.
+ * @param event The event codes. Please refer to the enumeration usb_device_class_event_t.
+ * @param param The param type is determined by the event code.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ * @retval kStatus_USB_Success A valid request has been handled.
+ * @retval kStatus_USB_InvalidParameter The device handle not be found.
+ * @retval kStatus_USB_InvalidRequest The request is invalid, and the control pipe will be stalled by the caller.
+ */
+usb_status_t USB_DeviceClassEvent(usb_device_handle handle, usb_device_class_event_t event, void *param)
+{
+ usb_device_common_class_struct_t *classHandle;
+ uint8_t mapIndex;
+ uint8_t classIndex;
+ usb_status_t errorReturn = kStatus_USB_Error;
+ usb_status_t error = kStatus_USB_Error;
+
+ if (NULL == param)
+ {
+ return kStatus_USB_InvalidParameter;
+ }
+
+ /* Get the common class handle according to the device handle. */
+ errorReturn = USB_DeviceClassGetHandleByDeviceHandle(handle, &classHandle);
+ if (kStatus_USB_Success != errorReturn)
+ {
+ return kStatus_USB_InvalidParameter;
+ }
+
+ for (classIndex = 0U; classIndex < classHandle->configList->count; classIndex++)
+ {
+ for (mapIndex = 0U; mapIndex < (sizeof(s_UsbDeviceClassInterfaceMap) / sizeof(usb_device_class_map_t));
+ mapIndex++)
+ {
+ if (s_UsbDeviceClassInterfaceMap[mapIndex].type ==
+ classHandle->configList->config[classIndex].classInfomation->type)
+ {
+ /* Call class event callback of supported class */
+ errorReturn = s_UsbDeviceClassInterfaceMap[mapIndex].classEventCallback(
+ (void *)classHandle->configList->config[classIndex].classHandle, event, param);
+ /* Return the error code kStatus_USB_InvalidRequest immediately, when a class returns
+ * kStatus_USB_InvalidRequest. */
+ if (kStatus_USB_InvalidRequest == errorReturn)
+ {
+ return kStatus_USB_InvalidRequest;
+ }
+ /* For composite device, it should return kStatus_USB_Success once a valid request has been handled */
+ if (kStatus_USB_Success == errorReturn)
+ {
+ error = kStatus_USB_Success;
+ }
+ break;
+ }
+ }
+ }
+
+ return error;
+}
+
+/*!
+ * @brief Handle the common class callback.
+ *
+ * This function handles the common class callback.
+ *
+ * @param handle The device handle, got from the USB_DeviceInit.
+ * @param event The event codes. Please refer to the enumeration usb_device_event_t.
+ * @param param The param type is determined by the event code.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassCallback(usb_device_handle handle, uint32_t event, void *param)
+{
+ usb_device_common_class_struct_t *classHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ /* Get the common class handle according to the device handle. */
+ error = USB_DeviceClassGetHandleByDeviceHandle(handle, &classHandle);
+ if (kStatus_USB_Success != error)
+ {
+ return error;
+ }
+
+ if (kUSB_DeviceEventBusReset == event)
+ {
+ /* Initialize the control pipes */
+ USB_DeviceControlPipeInit(handle, classHandle);
+
+ /* Notify the classes the USB bus reset signal detected. */
+ USB_DeviceClassEvent(handle, kUSB_DeviceClassEventDeviceReset, classHandle);
+ }
+
+ /* Call the application device callback function. */
+ error = classHandle->configList->deviceCallback(handle, event, param);
+ return error;
+}
+
+/*!
+ * @brief Initialize the common class and the supported classes.
+ *
+ * This function is used to initialize the common class and the supported classes.
+ *
+ * @param[in] controllerId The controller id of the USB IP. Please refer to the enumeration #usb_controller_index_t.
+ * @param[in] configList The class configurations. The pointer must point to the goblal variable.
+ * Please refer to the structure #usb_device_class_config_list_struct_t.
+ * @param[out] handle It is out parameter, is used to return pointer of the device handle to the caller.
+ * The value of parameter is a pointer points the device handle, and this design is uesd to
+ * make simple device align with composite device. For composite device, there are many
+ * kinds of class handle, but there is only one device handle. So the handle points to
+ * a device instead of a class. And the class handle can be got from the
+ * #usb_device_class_config_struct_t::classHandle after the the function successfully.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassInit(
+ uint8_t controllerId, /*!< [IN] Controller ID */
+ usb_device_class_config_list_struct_t *configList, /*!< [IN] Pointer to class configuration list */
+ usb_device_handle *handle /*!< [OUT] Pointer to the device handle */
+ )
+{
+ usb_device_common_class_struct_t *classHandle;
+ usb_status_t error = kStatus_USB_Error;
+ uint8_t mapIndex;
+ uint8_t classIndex;
+
+ if ((NULL == handle) || (NULL == configList) || ((usb_device_callback_t)NULL == configList->deviceCallback))
+ {
+ return kStatus_USB_InvalidParameter;
+ }
+
+ /* Allocate a common class driver handle. */
+ error = USB_DeviceClassAllocateHandle(controllerId, &classHandle);
+ if (kStatus_USB_Success != error)
+ {
+ return error;
+ }
+ /* Save the configuration list */
+ classHandle->configList = configList;
+
+ /* Initialize the device stack. */
+ error = USB_DeviceInit(controllerId, USB_DeviceClassCallback, &classHandle->handle);
+
+ if (kStatus_USB_Success != error)
+ {
+ USB_DeviceDeinit(classHandle->handle);
+ USB_DeviceClassFreeHandle(controllerId);
+ return error;
+ }
+
+ /* Initialize the all supported classes according to the configuration list. */
+ for (classIndex = 0U; classIndex < classHandle->configList->count; classIndex++)
+ {
+ for (mapIndex = 0U; mapIndex < (sizeof(s_UsbDeviceClassInterfaceMap) / sizeof(usb_device_class_map_t));
+ mapIndex++)
+ {
+ if (classHandle->configList->config[classIndex].classInfomation->type ==
+ s_UsbDeviceClassInterfaceMap[mapIndex].type)
+ {
+ (void)s_UsbDeviceClassInterfaceMap[mapIndex].classInit(
+ controllerId, &classHandle->configList->config[classIndex],
+ &classHandle->configList->config[classIndex].classHandle);
+ }
+ }
+ }
+
+ *handle = classHandle->handle;
+ return error;
+}
+
+/*!
+ * @brief De-initialize the common class and the supported classes.
+ *
+ * This function is used to de-initialize the common class and the supported classes.
+ *
+ * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassDeinit(uint8_t controllerId /*!< [IN] Controller ID */
+ )
+{
+ usb_device_common_class_struct_t *classHandle;
+ usb_status_t error = kStatus_USB_Error;
+ uint8_t mapIndex;
+ uint8_t classIndex;
+
+ /* Get the common class handle according to the controller id. */
+ error = USB_DeviceClassGetHandleByControllerId(controllerId, &classHandle);
+
+ if (kStatus_USB_Success != error)
+ {
+ return error;
+ }
+
+ /* De-initialize the all supported classes according to the configuration list. */
+ for (classIndex = 0U; classIndex < classHandle->configList->count; classIndex++)
+ {
+ for (mapIndex = 0U; mapIndex < (sizeof(s_UsbDeviceClassInterfaceMap) / sizeof(usb_device_class_map_t));
+ mapIndex++)
+ {
+ if (classHandle->configList->config[classIndex].classInfomation->type ==
+ s_UsbDeviceClassInterfaceMap[mapIndex].type)
+ {
+ (void)s_UsbDeviceClassInterfaceMap[mapIndex].classDeinit(
+ classHandle->configList->config[classIndex].classHandle);
+ }
+ }
+ }
+
+ /* De-initialize the USB device stack. */
+ error = USB_DeviceDeinit(classHandle->handle);
+ if (kStatus_USB_Success == error)
+ {
+ /* Free the common class handle. */
+ (void)USB_DeviceClassFreeHandle(controllerId);
+ }
+ return error;
+}
+
+/*!
+ * @brief Get the USB bus speed.
+ *
+ * This function is used to get the USB bus speed.
+ *
+ * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t.
+ * @param speed It is an OUT parameter, return current speed of the controller.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassGetSpeed(uint8_t controllerId, /*!< [IN] Controller ID */
+ uint8_t *speed /*!< [OUT] Current speed */
+ )
+{
+ usb_device_common_class_struct_t *classHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ /* Get the common class handle according to the controller id. */
+ error = USB_DeviceClassGetHandleByControllerId(controllerId, &classHandle);
+
+ if (kStatus_USB_Success != error)
+ {
+ return error;
+ }
+
+ /* Get the current speed. */
+ error = USB_DeviceGetStatus(classHandle->handle, kUSB_DeviceStatusSpeed, speed);
+
+ return error;
+}
+#endif /* USB_DEVICE_CONFIG_NUM */
diff --git a/right/include/usb/usb_device_class.h b/right/include/usb/usb_device_class.h
new file mode 100644
index 0000000..fbc82b0
--- /dev/null
+++ b/right/include/usb/usb_device_class.h
@@ -0,0 +1,423 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __USB_DEVICE_CLASS_H__
+#define __USB_DEVICE_CLASS_H__
+
+/*!
+ * @addtogroup usb_device_class_driver
+ * @{
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief Macro to define class handle */
+#define class_handle_t uint32_t
+
+/*! @brief Available class types. */
+typedef enum _usb_usb_device_class_type
+{
+ kUSB_DeviceClassTypeHid = 1U,
+ kUSB_DeviceClassTypeCdc,
+ kUSB_DeviceClassTypeMsc,
+ kUSB_DeviceClassTypeAudio,
+ kUSB_DeviceClassTypePhdc,
+ kUSB_DeviceClassTypeVideo,
+ kUSB_DeviceClassTypePrinter,
+ kUSB_DeviceClassTypeDfu,
+ kUSB_DeviceClassTypeCcid,
+} usb_device_class_type_t;
+
+/*! @brief Available common class events. */
+typedef enum _usb_device_class_event
+{
+ kUSB_DeviceClassEventClassRequest = 1U,
+ kUSB_DeviceClassEventDeviceReset,
+ kUSB_DeviceClassEventSetConfiguration,
+ kUSB_DeviceClassEventSetInterface,
+ kUSB_DeviceClassEventSetEndpointHalt,
+ kUSB_DeviceClassEventClearEndpointHalt,
+} usb_device_class_event_t;
+
+/*!
+ * @brief Obtains the endpoint data structure.
+ *
+ * Define the endpoint data structure.
+ *
+ */
+typedef struct _usb_device_endpoint_struct
+{
+ uint8_t endpointAddress; /*!< Endpoint address*/
+ uint8_t transferType; /*!< Endpoint transfer type*/
+ uint16_t maxPacketSize; /*!< Endpoint maximum packet size */
+} usb_device_endpoint_struct_t;
+
+/*!
+* @brief Obtains the endpoint group.
+*
+* Structure representing endpoints and the number of endpoints that the user wants.
+*
+*/
+typedef struct _usb_device_endpoint_list
+{
+ uint8_t count; /*!< How many endpoints in current interface*/
+ usb_device_endpoint_struct_t *endpoint; /*!< Endpoint structure list*/
+} usb_device_endpoint_list_t;
+
+/*!
+ * @brief Obtains the interface list data structure.
+ *
+ * Structure representing an interface.
+ *
+ */
+typedef struct _usb_device_interface_struct
+{
+ uint8_t alternateSetting; /*!< Alternate setting number*/
+ usb_device_endpoint_list_t endpointList; /*!< Endpoints of the interface*/
+ void *classSpecific; /*!< Class specific structure handle*/
+} usb_device_interface_struct_t;
+
+/*!
+ * @brief Obtains the interface data structure.
+ *
+ * Structure representing interface.
+ *
+ */
+typedef struct _usb_device_interfaces_struct
+{
+ uint8_t classCode; /*!< Class code of the interface*/
+ uint8_t subclassCode; /*!< Subclass code of the interface*/
+ uint8_t protocolCode; /*!< Protocol code of the interface*/
+ uint8_t interfaceNumber; /*!< Interface number*/
+ usb_device_interface_struct_t *interface; /*!< Interface structure list*/
+ uint8_t count; /*!< Number of interfaces in the current interface*/
+} usb_device_interfaces_struct_t;
+
+/*!
+ * @brief Obtains the interface group.
+ *
+ * Structure representing how many interfaces in one class type.
+ *
+ */
+typedef struct _usb_device_interface_list
+{
+ uint8_t count; /*!< Number of interfaces of the class*/
+ usb_device_interfaces_struct_t *interfaces; /*!< All interfaces*/
+} usb_device_interface_list_t;
+
+/*!
+ * @brief Obtains the class data structure.
+ *
+ * Structure representing how many configurations in one class type.
+ *
+ */
+typedef struct _usb_device_class_struct
+{
+ usb_device_interface_list_t *interfaceList; /*!< Interfaces of the class*/
+ usb_device_class_type_t type; /*!< Class type*/
+ uint8_t configurations; /*!< Number of configurations of the class*/
+} usb_device_class_struct_t;
+
+/*callback function pointer structure for application to provide class parameters*/
+typedef usb_status_t (*usb_device_class_callback_t)(class_handle_t classHandle,
+ uint32_t callbackEvent,
+ void *eventParam);
+
+/*!
+ * @brief Obtains the device class information structure.
+ *
+ * Structure representing the device class information. This structure only can be stored in RAM space.
+ *
+ */
+typedef struct _usb_device_class_config_struct
+{
+ usb_device_class_callback_t classCallback; /*!< Class callback function to handle the device status-related event
+ for the specified type of class*/
+ class_handle_t classHandle; /*!< The class handle of the class, filled by the common driver.*/
+ usb_device_class_struct_t *classInfomation; /*!< Detailed information of the class*/
+} usb_device_class_config_struct_t;
+
+/*!
+ * @brief Obtains the device class configuration structure.
+ *
+ * Structure representing the device class configuration information.
+ *
+ */
+typedef struct _usb_device_class_config_list_struct
+{
+ usb_device_class_config_struct_t *config; /*!< Array of class configuration structures */
+ usb_device_callback_t deviceCallback; /*!< Device callback function */
+ uint8_t count; /*!< Number of class supported */
+} usb_device_class_config_list_struct_t;
+
+/*!
+ * @brief Obtains the control request structure.
+ *
+ * This structure is used to pass the control request information.
+ * The structure is used in following two cases.
+ * Case one, the host wants to send data to the device in the control data stage: @n
+ * 1. If a setup packet is received, the structure is used to pass the setup packet data and wants to get the
+ * buffer to receive data sent from the host.
+ * The field isSetup is 1.
+ * The length is the requested buffer length.
+ * The buffer is filled by the class or application by using the valid buffer address.
+ * The setup is the setup packet address.
+ * 2. If the data received is sent by the host, the structure is used to pass the data buffer address and the data
+ * length sent by the host.
+ * In this way, the field isSetup is 0.
+ * The buffer is the address of the data sent from the host.
+ * The length is the received data length.
+ * The setup is the setup packet address. @n
+ * Case two, the host wants to get data from the device in control data stage: @n
+ * 1. If the setup packet is received, the structure is used to pass the setup packet data and wants to get the
+ * data buffer address to send data to the host.
+ * The field isSetup is 1.
+ * The length is the requested data length.
+ * The buffer is filled by the class or application by using the valid buffer address.
+ * The setup is the setup packet address.
+ *
+ */
+typedef struct _usb_device_control_request_struct
+{
+ usb_setup_struct_t *setup; /*!< The pointer of the setup packet data. */
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length or requested length. */
+ uint8_t isSetup; /*!< Indicates whether a setup packet is received. */
+} usb_device_control_request_struct_t;
+
+/*! @brief Obtains the control get descriptor request common structure. */
+typedef struct _usb_device_get_descriptor_common_struct
+{
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length. */
+} usb_device_get_descriptor_common_struct_t;
+
+/*! @brief Obtains the control get device descriptor request structure. */
+typedef struct _usb_device_get_device_descriptor_struct
+{
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length. */
+} usb_device_get_device_descriptor_struct_t;
+
+/*! @brief Obtains the control get configuration descriptor request structure. */
+typedef struct _usb_device_get_configuration_descriptor_struct
+{
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length. */
+ uint8_t configuration; /*!< The configuration number. */
+} usb_device_get_configuration_descriptor_struct_t;
+
+/*! @brief Obtains the control get string descriptor request structure. */
+typedef struct _usb_device_get_string_descriptor_struct
+{
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length. */
+ uint16_t languageId; /*!< Language ID. */
+ uint8_t stringIndex; /*!< String index. */
+} usb_device_get_string_descriptor_struct_t;
+
+/*! @brief Obtains the control get hid descriptor request structure. */
+typedef struct _usb_device_get_hid_descriptor_struct
+{
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length. */
+ uint8_t interfaceNumber; /*!< The interface number. */
+} usb_device_get_hid_descriptor_struct_t;
+
+/*! @brief Obtains the control get hid report descriptor request structure. */
+typedef struct _usb_device_get_hid_report_descriptor_struct
+{
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length. */
+ uint8_t interfaceNumber; /*!< The interface number. */
+} usb_device_get_hid_report_descriptor_struct_t;
+
+/*! @brief Obtains the control get hid physical descriptor request structure. */
+typedef struct _usb_device_get_hid_physical_descriptor_struct
+{
+ uint8_t *buffer; /*!< Pass the buffer address. */
+ uint32_t length; /*!< Pass the buffer length. */
+ uint8_t index; /*!< Physical index */
+ uint8_t interfaceNumber; /*!< The interface number. */
+} usb_device_get_hid_physical_descriptor_struct_t;
+
+/*! @brief Obtains the control get descriptor request common union. */
+typedef union _usb_device_get_descriptor_common_union
+{
+ usb_device_get_descriptor_common_struct_t commonDescriptor; /*!< Common structure. */
+ usb_device_get_device_descriptor_struct_t deviceDescriptor; /*!< The structure to get device descriptor. */
+ usb_device_get_configuration_descriptor_struct_t
+ configurationDescriptor; /*!< The structure to get configuration descriptor. */
+ usb_device_get_string_descriptor_struct_t stringDescriptor; /*!< The structure to get string descriptor. */
+ usb_device_get_hid_descriptor_struct_t hidDescriptor; /*!< The structure to get hid descriptor. */
+ usb_device_get_hid_report_descriptor_struct_t
+ hidReportDescriptor; /*!< The structure to get hid report descriptor. */
+ usb_device_get_hid_physical_descriptor_struct_t
+ hidPhysicalDescriptor; /*!< The structure to get hid physical descriptor. */
+} usb_device_get_descriptor_common_union_t;
+
+/*! @brief Define function type for class device instance initialization */
+typedef usb_status_t (*usb_device_class_init_call_t)(uint8_t controllerId,
+ usb_device_class_config_struct_t *classConfig,
+ class_handle_t *classHandle);
+/*! @brief Define function type for class device instance deinitialization, internal */
+typedef usb_status_t (*usb_device_class_deinit_call_t)(class_handle_t handle);
+/*! @brief Define function type for class device instance Event change */
+typedef usb_status_t (*usb_device_class_event_callback_t)(void *classHandle, uint32_t event, void *param);
+
+/*! @brief Define class driver interface structure. */
+typedef struct _usb_device_class_map
+{
+ usb_device_class_init_call_t classInit; /*!< Class driver initialization- entry of the class driver */
+ usb_device_class_deinit_call_t classDeinit; /*!< Class driver de-initialization*/
+ usb_device_class_event_callback_t classEventCallback; /*!< Class driver event callback*/
+ usb_device_class_type_t type; /*!< Class type*/
+} usb_device_class_map_t;
+
+/*! @brief Structure holding common class state information */
+typedef struct _usb_device_common_class_struct
+{
+ usb_device_handle handle; /*!< USB device handle*/
+ usb_device_class_config_list_struct_t *configList; /*!< USB device configure list*/
+ uint8_t setupBuffer[USB_SETUP_PACKET_SIZE]; /*!< Setup packet data buffer*/
+ uint16_t standardTranscationBuffer; /*!<
+ * This variable is used in:
+ * get status request
+ * get configuration request
+ * get interface request
+ * set interface request
+ * get sync frame request
+ */
+ uint8_t controllerId; /*!< Controller ID*/
+} usb_device_common_class_struct_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*!
+ * @brief Initializes the common class and the supported classes.
+ *
+ * This function is used to initialize the common class and the supported classes.
+ *
+ * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
+ * @param[in] configList The class configurations. The pointer must point to the goblal variable.
+ * See the structure #usb_device_class_config_list_struct_t.
+ * @param[out] handle An parameter used to return pointer of the device handle to the caller.
+ * The value of the parameter is a pointer to the device handle. This design is used to
+ * make a simple device align with the composite device. For the composite device, there are many
+ * kinds of class handles. However, there is only one device handle. Therefore, the handle points to
+ * a device instead of a class. The class handle can be received from the
+ * #usb_device_class_config_struct_t::classHandle after the the function successfully.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassInit(uint8_t controllerId,
+ usb_device_class_config_list_struct_t *configList,
+ usb_device_handle *handle);
+
+/*!
+ * @brief Deinitializes the common class and the supported classes.
+ *
+ * This function is used to deinitialize the common class and the supported classes.
+ *
+ * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassDeinit(uint8_t controllerId);
+
+/*!
+ * @brief Gets the USB bus speed.
+ *
+ * This function is used to get the USB bus speed.
+ *
+ * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
+ * @param[out] speed It is an OUT parameter, which returns the current speed of the controller.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassGetSpeed(uint8_t controllerId, uint8_t *speed);
+
+/*!
+ * @brief Handles the event passed to the class drivers.
+ *
+ * A valid request has been handled.
+ *
+ * @param[in] handle The device handle received from the #USB_DeviceInit.
+ * @param[in] event The event codes. See the enumeration #usb_device_class_event_t.
+ * @param[in,out] param The parameter type is determined by the event code.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ * @retval kStatus_USB_Success A valid request has been handled.
+ * @retval kStatus_USB_InvalidParameter The device handle not be found.
+ * @retval kStatus_USB_InvalidRequest The request is invalid, and the control pipe is stalled by the caller.
+ */
+usb_status_t USB_DeviceClassEvent(usb_device_handle handle, usb_device_class_event_t event, void *param);
+
+/*!
+ * @brief Handles the common class callback.
+ *
+ * This function handles the common class callback.
+ *
+ * @param[in] handle The device handle received from the #USB_DeviceInit.
+ * @param[in] event The event codes. See the enumeration #usb_device_event_t.
+ * @param[in,out] param The parameter type is determined by the event code.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceClassCallback(usb_device_handle handle, uint32_t event, void *param);
+
+/*!
+ * @brief Gets the device handle according to the controller ID.
+ *
+ * This function gets the device handle according to the controller ID.
+ *
+ * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
+ * @param[out] handle An out parameter used to return the pointer of the device handle to the caller.
+ *
+ * @retval kStatus_USB_Success Get device handle successfully.
+ * @retval kStatus_USB_InvalidParameter The device handle can't be found.
+ */
+usb_status_t USB_DeviceClassGetDeviceHandle(uint8_t controllerId, usb_device_handle *handle);
+
+#if defined(__cplusplus)
+}
+#endif
+
+/*! @}*/
+
+#endif /* __USB_DEVICE_CLASS_H__ */
diff --git a/right/include/usb/usb_device_hid.c b/right/include/usb/usb_device_hid.c
new file mode 100644
index 0000000..c738354
--- /dev/null
+++ b/right/include/usb/usb_device_hid.c
@@ -0,0 +1,667 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "usb_device_config.h"
+#include "usb.h"
+#include "usb_device.h"
+
+#include "usb_device_class.h"
+
+#if ((defined(USB_DEVICE_CONFIG_HID)) && (USB_DEVICE_CONFIG_HID > 0U))
+#include "usb_device_hid.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Prototypes
+ ******************************************************************************/
+
+static usb_status_t USB_DeviceHidAllocateHandle(usb_device_hid_struct_t **handle);
+static usb_status_t USB_DeviceHidFreeHandle(usb_device_hid_struct_t *handle);
+static usb_status_t USB_DeviceHidInterruptIn(usb_device_handle handle,
+ usb_device_endpoint_callback_message_struct_t *message,
+ void *callbackParam);
+static usb_status_t USB_DeviceHidInterruptOut(usb_device_handle handle,
+ usb_device_endpoint_callback_message_struct_t *message,
+ void *callbackParam);
+static usb_status_t USB_DeviceHidEndpointsInit(usb_device_hid_struct_t *hidHandle);
+static usb_status_t USB_DeviceHidEndpointsDeinit(usb_device_hid_struct_t *hidHandle);
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+
+USB_GLOBAL static usb_device_hid_struct_t s_UsbDeviceHidHandle[USB_DEVICE_CONFIG_HID];
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*!
+ * @brief Allocate a device hid class handle.
+ *
+ * This function allocates a device hid class handle.
+ *
+ * @param handle It is out parameter, is used to return pointer of the device hid class handle to the caller.
+ *
+ * @retval kStatus_USB_Success Get a device hid class handle successfully.
+ * @retval kStatus_USB_Busy Cannot allocate a device hid class handle.
+ */
+static usb_status_t USB_DeviceHidAllocateHandle(usb_device_hid_struct_t **handle)
+{
+ int32_t count;
+ for (count = 0U; count < USB_DEVICE_CONFIG_HID; count++)
+ {
+ if (NULL == s_UsbDeviceHidHandle[count].handle)
+ {
+ *handle = &s_UsbDeviceHidHandle[count];
+ return kStatus_USB_Success;
+ }
+ }
+
+ return kStatus_USB_Busy;
+}
+
+/*!
+ * @brief Free a device hid class hanlde.
+ *
+ * This function frees a device hid class hanlde.
+ *
+ * @param handle The device hid class hanlde.
+ *
+ * @retval kStatus_USB_Success Free device hid class hanlde successfully.
+ */
+static usb_status_t USB_DeviceHidFreeHandle(usb_device_hid_struct_t *handle)
+{
+ handle->handle = NULL;
+ handle->configStruct = (usb_device_class_config_struct_t *)NULL;
+ handle->configuration = 0U;
+ handle->alternate = 0U;
+ return kStatus_USB_Success;
+}
+
+/*!
+ * @brief Interrupt IN endpoint callback function.
+ *
+ * This callback function is used to notify uplayer the tranfser result of a transfer.
+ * This callback pointer is passed when the interrupt IN pipe initialized.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param message The result of the interrupt IN pipe transfer.
+ * @param callbackParam The paramter for this callback. It is same with
+ * usb_device_endpoint_callback_struct_t::callbackParam. In the class, the value is the HID class handle.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+static usb_status_t USB_DeviceHidInterruptIn(usb_device_handle handle,
+ usb_device_endpoint_callback_message_struct_t *message,
+ void *callbackParam)
+{
+ usb_device_hid_struct_t *hidHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ /* Get the HID class handle */
+ hidHandle = (usb_device_hid_struct_t *)callbackParam;
+
+ if (!hidHandle)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+ hidHandle->interruptInPipeBusy = 0U;
+ if ((NULL != hidHandle->configStruct) && (hidHandle->configStruct->classCallback))
+ {
+ /* Notify the application data sent by calling the hid class callback. */
+ error =
+ hidHandle->configStruct->classCallback((class_handle_t)hidHandle, kUSB_DeviceHidEventSendResponse, message);
+ }
+
+ return error;
+}
+
+/*!
+ * @brief Interrupt OUT endpoint callback function.
+ *
+ * This callback function is used to notify uplayer the tranfser result of a transfer.
+ * This callback pointer is passed when the interrupt OUT pipe initialized.
+ *
+ * @param handle The device handle. It equals the value returned from USB_DeviceInit.
+ * @param message The result of the interrupt OUT pipe transfer.
+ * @param callbackParam The paramter for this callback. It is same with
+ * usb_device_endpoint_callback_struct_t::callbackParam. In the class, the value is the HID class handle.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+static usb_status_t USB_DeviceHidInterruptOut(usb_device_handle handle,
+ usb_device_endpoint_callback_message_struct_t *message,
+ void *callbackParam)
+{
+ usb_device_hid_struct_t *hidHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ /* Get the HID class handle */
+ hidHandle = (usb_device_hid_struct_t *)callbackParam;
+
+ if (!hidHandle)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+ hidHandle->interruptOutPipeBusy = 0U;
+ if ((NULL != hidHandle->configStruct) && (hidHandle->configStruct->classCallback))
+ {
+ /* Notify the application data received by calling the hid class callback. */
+ error =
+ hidHandle->configStruct->classCallback((class_handle_t)hidHandle, kUSB_DeviceHidEventRecvResponse, message);
+ }
+
+ return error;
+}
+
+/*!
+ * @brief Initialize the endpoints of the hid class.
+ *
+ * This callback function is used to initialize the endpoints of the hid class.
+ *
+ * @param hidHandle The device hid class handle. It equals the value returned from
+ * usb_device_class_config_struct_t::classHandle.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+static usb_status_t USB_DeviceHidEndpointsInit(usb_device_hid_struct_t *hidHandle)
+{
+ usb_device_interface_list_t *interfaceList;
+ usb_device_interface_struct_t *interface = (usb_device_interface_struct_t *)NULL;
+ usb_status_t error = kStatus_USB_Error;
+
+ /* Check the configuration is valid or not. */
+ if (hidHandle->configuration > hidHandle->configStruct->classInfomation->configurations)
+ {
+ return error;
+ }
+
+ /* Get the interface list of the new configuration. */
+ if (NULL == hidHandle->configStruct->classInfomation->interfaceList)
+ {
+ return error;
+ }
+ interfaceList = &hidHandle->configStruct->classInfomation->interfaceList[hidHandle->configuration - 1U];
+
+ /* Find interface by using the alternate setting of the interface. */
+ for (int count = 0U; count < interfaceList->count; count++)
+ {
+ if (USB_DEVICE_CONFIG_HID_CLASS_CODE == interfaceList->interfaces[count].classCode)
+ {
+ for (int index = 0U; index < interfaceList->interfaces[count].count; index++)
+ {
+ if (interfaceList->interfaces[count].interface[index].alternateSetting == hidHandle->alternate)
+ {
+ interface = &interfaceList->interfaces[count].interface[index];
+ break;
+ }
+ }
+ hidHandle->interfaceNumber = interfaceList->interfaces[count].interfaceNumber;
+ break;
+ }
+ }
+ if (!interface)
+ {
+ /* Return error if the interface is not found. */
+ return error;
+ }
+
+ /* Keep new interface handle. */
+ hidHandle->interfaceHandle = interface;
+
+ /* Initialize the endpoints of the new interface. */
+ for (int count = 0U; count < interface->endpointList.count; count++)
+ {
+ usb_device_endpoint_init_struct_t epInitStruct;
+ usb_device_endpoint_callback_struct_t ep_callback;
+ epInitStruct.zlt = 0U;
+ epInitStruct.endpointAddress = interface->endpointList.endpoint[count].endpointAddress;
+ epInitStruct.maxPacketSize = interface->endpointList.endpoint[count].maxPacketSize;
+ epInitStruct.transferType = interface->endpointList.endpoint[count].transferType;
+
+ if (USB_IN == ((epInitStruct.endpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) >>
+ USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT))
+ {
+ ep_callback.callbackFn = USB_DeviceHidInterruptIn;
+ }
+ else
+ {
+ ep_callback.callbackFn = USB_DeviceHidInterruptOut;
+ }
+ ep_callback.callbackParam = hidHandle;
+
+ error = USB_DeviceInitEndpoint(hidHandle->handle, &epInitStruct, &ep_callback);
+ }
+ return error;
+}
+
+/*!
+ * @brief De-initialize the endpoints of the hid class.
+ *
+ * This callback function is used to de-initialize the endpoints of the hid class.
+ *
+ * @param hidHandle The device hid class handle. It equals the value returned from
+ * usb_device_class_config_struct_t::classHandle.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+static usb_status_t USB_DeviceHidEndpointsDeinit(usb_device_hid_struct_t *hidHandle)
+{
+ usb_status_t error = kStatus_USB_Error;
+
+ if (!hidHandle->interfaceHandle)
+ {
+ return error;
+ }
+ /* De-initialize all endpoints of the interface */
+ for (int count = 0U; count < hidHandle->interfaceHandle->endpointList.count; count++)
+ {
+ error = USB_DeviceDeinitEndpoint(hidHandle->handle,
+ hidHandle->interfaceHandle->endpointList.endpoint[count].endpointAddress);
+ }
+ return error;
+}
+
+/*!
+ * @brief Handle the event passed to the hid class.
+ *
+ * This function handles the event passed to the hid class.
+ *
+ * @param handle The hid class handle, got from the usb_device_class_config_struct_t::classHandle.
+ * @param event The event codes. Please refer to the enumeration usb_device_class_event_t.
+ * @param param The param type is determined by the event code.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ * @retval kStatus_USB_Success Free device handle successfully.
+ * @retval kStatus_USB_InvalidParameter The device handle not be found.
+ * @retval kStatus_USB_InvalidRequest The request is invalid, and the control pipe will be stalled by the caller.
+ */
+usb_status_t USB_DeviceHidEvent(void *handle, uint32_t event, void *param)
+{
+ usb_device_hid_struct_t *hidHandle;
+ usb_device_hid_report_struct_t report;
+ usb_status_t error = kStatus_USB_Error;
+ uint16_t interfaceAlternate;
+ uint8_t *temp8;
+ uint8_t alternate;
+
+ if ((!param) || (!handle))
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+
+ /* Get the hid class handle. */
+ hidHandle = (usb_device_hid_struct_t *)handle;
+
+ switch (event)
+ {
+ case kUSB_DeviceClassEventDeviceReset:
+ /* Bus reset, clear the configuration. */
+ hidHandle->configuration = 0U;
+ hidHandle->interruptInPipeBusy = 0U;
+ hidHandle->interruptOutPipeBusy = 0U;
+ break;
+ case kUSB_DeviceClassEventSetConfiguration:
+ /* Get the new configuration. */
+ temp8 = ((uint8_t *)param);
+ if (!hidHandle->configStruct)
+ {
+ break;
+ }
+ if (*temp8 == hidHandle->configuration)
+ {
+ break;
+ }
+
+ /* De-initialize the endpoints when current configuration is none zero. */
+ if (hidHandle->configuration)
+ {
+ error = USB_DeviceHidEndpointsDeinit(hidHandle);
+ }
+ /* Save new configuration. */
+ hidHandle->configuration = *temp8;
+ /* Clear the alternate setting value. */
+ hidHandle->alternate = 0U;
+
+ /* Initialize the endpoints of the new current configuration by using the alternate setting 0. */
+ error = USB_DeviceHidEndpointsInit(hidHandle);
+ break;
+ case kUSB_DeviceClassEventSetInterface:
+ if (!hidHandle->configStruct)
+ {
+ break;
+ }
+ /* Get the new alternate setting of the interface */
+ interfaceAlternate = *((uint16_t *)param);
+ /* Get the alternate setting value */
+ alternate = (uint8_t)(interfaceAlternate & 0xFFU);
+
+ /* Whether the interface belongs to the class. */
+ if (hidHandle->interfaceNumber != ((uint8_t)(interfaceAlternate >> 8U)))
+ {
+ break;
+ }
+ /* Only handle new alternate setting. */
+ if (alternate == hidHandle->alternate)
+ {
+ break;
+ }
+ /* De-initialize old endpoints */
+ error = USB_DeviceHidEndpointsDeinit(hidHandle);
+ hidHandle->alternate = alternate;
+ /* Initialize new endpoints */
+ error = USB_DeviceHidEndpointsInit(hidHandle);
+ break;
+ case kUSB_DeviceClassEventSetEndpointHalt:
+ if ((!hidHandle->configStruct) || (!hidHandle->interfaceHandle))
+ {
+ break;
+ }
+ /* Get the endpoint address */
+ temp8 = ((uint8_t *)param);
+ for (int count = 0U; count < hidHandle->interfaceHandle->endpointList.count; count++)
+ {
+ if (*temp8 == hidHandle->interfaceHandle->endpointList.endpoint[count].endpointAddress)
+ {
+ /* Only stall the endpoint belongs to the class */
+ error = USB_DeviceStallEndpoint(hidHandle->handle, *temp8);
+ }
+ }
+ break;
+ case kUSB_DeviceClassEventClearEndpointHalt:
+ if ((!hidHandle->configStruct) || (!hidHandle->interfaceHandle))
+ {
+ break;
+ }
+ /* Get the endpoint address */
+ temp8 = ((uint8_t *)param);
+ for (int count = 0U; count < hidHandle->interfaceHandle->endpointList.count; count++)
+ {
+ if (*temp8 == hidHandle->interfaceHandle->endpointList.endpoint[count].endpointAddress)
+ {
+ /* Only un-stall the endpoint belongs to the class */
+ error = USB_DeviceUnstallEndpoint(hidHandle->handle, *temp8);
+ }
+ }
+ break;
+ case kUSB_DeviceClassEventClassRequest:
+ if (param)
+ {
+ /* Handle the hid class specific request. */
+ usb_device_control_request_struct_t *controlRequest = (usb_device_control_request_struct_t *)param;
+
+ if ((controlRequest->setup->bmRequestType & USB_REQUEST_TYPE_RECIPIENT_MASK) !=
+ USB_REQUEST_TYPE_RECIPIENT_INTERFACE)
+ {
+ break;
+ }
+
+ if ((controlRequest->setup->wIndex & 0xFFU) != hidHandle->interfaceNumber)
+ {
+ break;
+ }
+
+ switch (controlRequest->setup->bRequest)
+ {
+ case USB_DEVICE_HID_REQUEST_GET_REPORT:
+ /* Get report request */
+ report.reportType = (controlRequest->setup->wValue & 0xFF00U) >> 0x08U;
+ report.reportId = (controlRequest->setup->wValue & 0x00FFU);
+ error = hidHandle->configStruct->classCallback((class_handle_t)hidHandle,
+ kUSB_DeviceHidEventGetReport, &report);
+ controlRequest->buffer = report.reportBuffer;
+ controlRequest->length = report.reportLength;
+ break;
+ case USB_DEVICE_HID_REQUEST_GET_IDLE:
+ /* Get idle request */
+ error = hidHandle->configStruct->classCallback(
+ (class_handle_t)hidHandle, kUSB_DeviceHidEventGetIdle, &hidHandle->idleRate);
+ controlRequest->buffer = &hidHandle->idleRate;
+ break;
+ case USB_DEVICE_HID_REQUEST_GET_PROTOCOL:
+ /* Get protocol request */
+ error = hidHandle->configStruct->classCallback(
+ (class_handle_t)hidHandle, kUSB_DeviceHidEventGetIdle, &hidHandle->protocol);
+ controlRequest->buffer = &hidHandle->protocol;
+ break;
+ case USB_DEVICE_HID_REQUEST_SET_REPORT:
+ /* Set report request */
+ report.reportType = (controlRequest->setup->wValue & 0xFF00U) >> 0x08U;
+ report.reportId = (controlRequest->setup->wValue & 0x00FFU);
+ if (controlRequest->isSetup)
+ {
+ report.reportLength = controlRequest->length;
+ error = hidHandle->configStruct->classCallback(
+ (class_handle_t)hidHandle, kUSB_DeviceHidEventRequestReportBuffer, &report);
+ controlRequest->buffer = report.reportBuffer;
+ controlRequest->length = report.reportLength;
+ }
+ else
+ {
+ report.reportBuffer = controlRequest->buffer;
+ report.reportLength = controlRequest->length;
+ error = hidHandle->configStruct->classCallback((class_handle_t)hidHandle,
+ kUSB_DeviceHidEventSetReport, &report);
+ }
+ break;
+ case USB_DEVICE_HID_REQUEST_SET_IDLE:
+ /* Set idle request */
+ {
+ hidHandle->idleRate = (controlRequest->setup->wValue & 0xFF00U) >> 0x08U;
+ error = hidHandle->configStruct->classCallback(
+ (class_handle_t)hidHandle, kUSB_DeviceHidEventSetIdle, &controlRequest->setup->wValue);
+ }
+ break;
+ case USB_DEVICE_HID_REQUEST_SET_PROTOCOL:
+ /* Set protocol request */
+ {
+ hidHandle->protocol = (controlRequest->setup->wValue & 0x00FFU);
+ error = hidHandle->configStruct->classCallback(
+ (class_handle_t)hidHandle, kUSB_DeviceHidEventSetProtocol, &hidHandle->protocol);
+ }
+ break;
+ default:
+ error = kStatus_USB_InvalidRequest;
+ break;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return error;
+}
+
+/*!
+ * @brief Initialize the hid class.
+ *
+ * This function is used to initialize the hid class.
+ *
+ * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t.
+ * @param config The class configuration information.
+ * @param handle It is out parameter, is used to return pointer of the hid class handle to the caller.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceHidInit(uint8_t controllerId, usb_device_class_config_struct_t *config, class_handle_t *handle)
+{
+ usb_device_hid_struct_t *hidHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ /* Allocate a hid class handle. */
+ error = USB_DeviceHidAllocateHandle(&hidHandle);
+
+ if (kStatus_USB_Success != error)
+ {
+ return error;
+ }
+
+ /* Get the device handle according to the controller id. */
+ error = USB_DeviceClassGetDeviceHandle(controllerId, &hidHandle->handle);
+
+ if (kStatus_USB_Success != error)
+ {
+ return error;
+ }
+
+ if (!hidHandle->handle)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+ /* Save the configuration of the class. */
+ hidHandle->configStruct = config;
+ /* Clear the configuration value. */
+ hidHandle->configuration = 0U;
+ hidHandle->alternate = 0xffU;
+
+ *handle = (class_handle_t)hidHandle;
+ return error;
+}
+
+/*!
+ * @brief De-initialize the device hid class.
+ *
+ * The function de-initializes the device hid class.
+ *
+ * @param handle The hid class handle got from usb_device_class_config_struct_t::classHandle.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+usb_status_t USB_DeviceHidDeinit(class_handle_t handle)
+{
+ usb_device_hid_struct_t *hidHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ hidHandle = (usb_device_hid_struct_t *)handle;
+
+ if (!hidHandle)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+ /* De-initialzie the endpoints. */
+ error = USB_DeviceHidEndpointsDeinit(hidHandle);
+ /* Free the hid class handle. */
+ USB_DeviceHidFreeHandle(hidHandle);
+ return error;
+}
+
+/*!
+ * @brief Send data through a specified endpoint.
+ *
+ * The function is used to send data through a specified endpoint.
+ * The function calls USB_DeviceSendRequest internally.
+ *
+ * @param handle The hid class handle got from usb_device_class_config_struct_t::classHandle.
+ * @param ep Endpoint index.
+ * @param buffer The memory address to hold the data need to be sent.
+ * @param length The data length need to be sent.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ *
+ * @note The return value just means if the sending request is successful or not; the transfer done is notified by
+ * USB_DeviceHidInterruptIn.
+ * Currently, only one transfer request can be supported for one specific endpoint.
+ * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application
+ * should implement a queue in the application level.
+ * The subsequent transfer could begin only when the previous transfer is done (get notification through the endpoint
+ * callback).
+ */
+usb_status_t USB_DeviceHidSend(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length)
+{
+ usb_device_hid_struct_t *hidHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ if (!handle)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+ hidHandle = (usb_device_hid_struct_t *)handle;
+
+ if (hidHandle->interruptInPipeBusy)
+ {
+ return kStatus_USB_Busy;
+ }
+ error = USB_DeviceSendRequest(hidHandle->handle, ep, buffer, length);
+ if (kStatus_USB_Success == error)
+ {
+ hidHandle->interruptInPipeBusy = 1U;
+ }
+ return error;
+}
+
+/*!
+ * @brief Receive data through a specified endpoint.
+ *
+ * The function is used to receive data through a specified endpoint.
+ * The function calls USB_DeviceRecvRequest internally.
+ *
+ * @param handle The hid class handle got from usb_device_class_config_struct_t::classHandle.
+ * @param ep Endpoint index.
+ * @param buffer The memory address to save the received data.
+ * @param length The data length want to be received.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ *
+ * @note The return value just means if the receiving request is successful or not; the transfer done is notified by
+ * USB_DeviceHidInterruptOut.
+ * Currently, only one transfer request can be supported for one specific endpoint.
+ * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application
+ * should implement a queue in the application level.
+ * The subsequent transfer could begin only when the previous transfer is done (get notification through the endpoint
+ * callback).
+ */
+usb_status_t USB_DeviceHidRecv(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length)
+{
+ usb_device_hid_struct_t *hidHandle;
+ usb_status_t error = kStatus_USB_Error;
+
+ if (!handle)
+ {
+ return kStatus_USB_InvalidHandle;
+ }
+ hidHandle = (usb_device_hid_struct_t *)handle;
+
+ if (hidHandle->interruptOutPipeBusy)
+ {
+ return kStatus_USB_Busy;
+ }
+ error = USB_DeviceRecvRequest(hidHandle->handle, ep, buffer, length);
+ if (kStatus_USB_Success == error)
+ {
+ hidHandle->interruptOutPipeBusy = 1U;
+ }
+ return error;
+}
+
+#endif
diff --git a/right/include/usb/usb_device_hid.h b/right/include/usb/usb_device_hid.h
new file mode 100644
index 0000000..2f99eb9
--- /dev/null
+++ b/right/include/usb/usb_device_hid.h
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __USB_DEVICE_HID_H__
+#define __USB_DEVICE_HID_H__
+
+/*!
+ * @addtogroup usb_device_hid_drv
+ * @{
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief The class code of the HID class */
+#define USB_DEVICE_CONFIG_HID_CLASS_CODE (0x03U)
+
+/*! @brief Request code to get report of HID class. */
+#define USB_DEVICE_HID_REQUEST_GET_REPORT (0x01U)
+#define USB_DEVICE_HID_REQUEST_GET_REPORT_TYPE_INPUT (0x01U)
+#define USB_DEVICE_HID_REQUEST_GET_REPORT_TYPE_OUPUT (0x02U)
+#define USB_DEVICE_HID_REQUEST_GET_REPORT_TYPE_FEATURE (0x03U)
+/*! @brief Request code to get idle of HID class. */
+#define USB_DEVICE_HID_REQUEST_GET_IDLE (0x02U)
+/*! @brief Request code to get protocol of HID class. */
+#define USB_DEVICE_HID_REQUEST_GET_PROTOCOL (0x03U)
+/*! @brief Request code to set report of HID class. */
+#define USB_DEVICE_HID_REQUEST_SET_REPORT (0x09U)
+/*! @brief Request code to set idle of HID class. */
+#define USB_DEVICE_HID_REQUEST_SET_IDLE (0x0AU)
+/*! @brief Request code to set protocol of HID class. */
+#define USB_DEVICE_HID_REQUEST_SET_PROTOCOL (0x0BU)
+
+/*! @brief Available common EVENT types in HID class callback */
+typedef enum _usb_device_hid_event
+{
+ kUSB_DeviceHidEventSendResponse = 0x01U, /*!< Send data completed */
+ kUSB_DeviceHidEventRecvResponse, /*!< Data received */
+ kUSB_DeviceHidEventGetReport, /*!< Get report request */
+ kUSB_DeviceHidEventGetIdle, /*!< Get idle request */
+ kUSB_DeviceHidEventGetProtocol, /*!< Get protocol request */
+ kUSB_DeviceHidEventSetReport, /*!< Set report request */
+ kUSB_DeviceHidEventSetIdle, /*!< Set idle request */
+ kUSB_DeviceHidEventSetProtocol, /*!< Set protocol request */
+ kUSB_DeviceHidEventRequestReportBuffer, /*!< Get buffer to save the data of the set report request. */
+} usb_device_hid_event_t;
+
+/*!
+ * @brief The device HID GET/SET report structure.
+ *
+ * This structure is used to pass data when the event type is kUSB_DeviceHidEventGetReport,
+ * kUSB_DeviceHidEventSetReport, and kUSB_DeviceHidEventRequestReportBuffer.
+ * 1. kUSB_DeviceHidEventGetReport
+ * The structure is used to save the report buffer and report length got from the application.
+ * The reportBuffer is the report data buffer address filled by the application.
+ * The reportLength is the report length.
+ * The reportType is the requested report type.
+ * The reportId is the requested report ID.
+ *
+ * 2. kUSB_DeviceHidEventSetReport
+ * The structure is used to pass the report data received from the host to the application.
+ * The reportBuffer is buffer address of the report data received from the host.
+ * The reportLength is the report data length.
+ * The reportType is the requested report type.
+ * The reportId is the requested report ID.
+ *
+ * 3. kUSB_DeviceHidEventRequestReportBuffer
+ * The structure is used to get the buffer to save the report data sent by the host.
+ * The reportBuffer is buffer address to receive to report data. It is filled by the application.
+ * The reportLength is the requested report data buffer length.
+ * The reportType is the requested report type.
+ * The reportId is the requested report ID.
+ */
+typedef struct _usb_device_hid_report_struct
+{
+ uint8_t *reportBuffer; /*!< The report buffer address */
+ uint32_t reportLength; /*!< The report data length */
+ uint8_t reportType; /*!< The report type */
+ uint8_t reportId; /*!< The report ID */
+} usb_device_hid_report_struct_t;
+
+/*! @brief The HID device class status structure */
+typedef struct _usb_device_hid_struct
+{
+ usb_device_handle handle; /*!< The device handle */
+ usb_device_class_config_struct_t *configStruct; /*!< The configuration of the class. */
+ usb_device_interface_struct_t *interfaceHandle; /*!< Current interface handle */
+ uint8_t configuration; /*!< Current configuration */
+ uint8_t interfaceNumber; /*!< The interface number of the class */
+ uint8_t alternate; /*!< Current alternate setting of the interface */
+ uint8_t idleRate; /*!< The idle rate of the HID device */
+ uint8_t protocol; /*!< Current protocol */
+ uint8_t interruptInPipeBusy; /*!< Interrupt IN pipe busy flag */
+ uint8_t interruptOutPipeBusy; /*!< Interrupt OUT pipe busy flag */
+} usb_device_hid_struct_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*!
+ * @brief Initializes the HID class.
+ *
+ * This function is used to initialize the HID class. This function only can be called by #USB_DeviceClassInit.
+ *
+ * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
+ * @param[in] config The class configuration information.
+ * @param[out] handle An parameter used to return pointer of the HID class handle to the caller.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+extern usb_status_t USB_DeviceHidInit(uint8_t controllerId,
+ usb_device_class_config_struct_t *config,
+ class_handle_t *handle);
+
+/*!
+ * @brief Deinitializes the device HID class.
+ *
+ * The function deinitializes the device HID class. This function only can be called by #USB_DeviceClassDeinit.
+ *
+ * @param[in] handle The HID class handle got from usb_device_class_config_struct_t::classHandle.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ */
+extern usb_status_t USB_DeviceHidDeinit(class_handle_t handle);
+
+/*!
+ * @brief Handles the event passed to the HID class.
+ *
+ * This function handles the event passed to the HID class. This function only can be called by #USB_DeviceClassEvent.
+ *
+ * @param[in] handle The HID class handle received from the usb_device_class_config_struct_t::classHandle.
+ * @param[in] event The event codes. See the enumeration usb_device_class_event_t.
+ * @param[in,out] param The parameter type is determined by the event code.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ * @retval kStatus_USB_Success Free device handle successfully.
+ * @retval kStatus_USB_InvalidParameter The device handle not be found.
+ * @retval kStatus_USB_InvalidRequest The request is invalid, and the control pipe is stalled by the caller.
+ */
+extern usb_status_t USB_DeviceHidEvent(void *handle, uint32_t event, void *param);
+
+/*!
+ * @name USB device HID class APIs
+ * @{
+ */
+
+/*!
+ * @brief Sends data through a specified endpoint.
+ *
+ * The function is used to send data through a specified endpoint.
+ * The function calls #USB_DeviceSendRequest internally.
+ *
+ * @param[in] handle The HID class handle received from usb_device_class_config_struct_t::classHandle.
+ * @param[in] ep Endpoint index.
+ * @param[in] buffer The memory address to hold the data need to be sent.
+ * @param[in] length The data length to be sent.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ *
+ * @note The return value indicates whether the sending request is successful or not. The transfer done is notified by
+ * usb_device_hid_interrupt_in.
+ * Currently, only one transfer request can be supported for one specific endpoint.
+ * If there is a specific requirement to support multiple transfer requests for a specific endpoint, the application
+ * should implement a queue in the application level.
+ * The subsequent transfer can begin only when the previous transfer is done (a notification is received through the endpoint
+ * callback).
+ */
+extern usb_status_t USB_DeviceHidSend(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length);
+
+/*!
+ * @brief Receives data through a specified endpoint.
+ *
+ * The function is used to receive data through a specified endpoint.
+ * The function calls #USB_DeviceRecvRequest internally.
+ *
+ * @param[in] handle The HID class handle received from the usb_device_class_config_struct_t::classHandle.
+ * @param[in] ep Endpoint index.
+ * @param[in] buffer The memory address to save the received data.
+ * @param[in] length The data length to be received.
+ *
+ * @return A USB error code or kStatus_USB_Success.
+ *
+ * @note The return value indicates whether the receiving request is successful or not. The transfer done is notified by
+ * usb_device_hid_interrupt_out.
+ * Currently, only one transfer request can be supported for a specific endpoint.
+ * If there is a specific requirement to support multiple transfer requests for a specific endpoint, the application
+ * should implement a queue in the application level.
+ * The subsequent transfer can begin only when the previous transfer is done (a notification is received through the endpoint
+ * callback).
+ */
+extern usb_status_t USB_DeviceHidRecv(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length);
+
+/*! @}*/
+
+#if defined(__cplusplus)
+}
+#endif
+
+/*! @}*/
+
+#endif /* __USB_DEVICE_HID_H__ */
diff --git a/right/keyboard.c b/right/keyboard.c
deleted file mode 100644
index 71b26da..0000000
--- a/right/keyboard.c
+++ /dev/null
@@ -1,227 +0,0 @@
-#include "usb_device_config.h"
-#include "usb.h"
-#include "usb_device_stack_interface.h"
-#include "usb_class_hid.h"
-#include "keyboard.h"
-#include "usb_descriptor.h"
-#include "fsl_device_registers.h"
-#include "fsl_clock_manager.h"
-#include "board.h"
-#include "fsl_debug_console.h"
-#include "fsl_port_hal.h"
-#include
-#include
-
-extern void Main_Task(uint32_t param);
-#define MAIN_TASK 10
-
-keyboard_global_variable_struct_t* g_keyboard;
-uint32_t g_process_times = 1;
-uint8_t g_key_index = 2;
-uint8_t g_new_key_pressed = 0;
-
-void USB_Keyboard_App_Device_Callback(uint8_t event_type, void* val, void* arg);
-uint8_t USB_Keyboard_App_Class_Callback(uint8_t request, uint16_t value, uint8_t ** data,
- uint32_t* size, void* arg);
-
-/*****************************************************************************
- * Local Variables
- *****************************************************************************/
-
-/*****************************************************************************
- * Local Functions
- *****************************************************************************/
-/******************************************************************************
- * @name: KeyBoard_Events_Process
- *
- * @brief: This function gets the input from keyboard, the keyboard
- * does not include the code to filter the glitch on keys since
- * it is just for demo
- *
- * @param: None
- *
- * @return: None
- *
- *****************************************************************************
- * This function sends the keyboard data depending on which key is pressed on
- * the board
- *****************************************************************************/
-void KeyBoard_Events_Process(void)
-{
- static int32_t x = 0;
- static enum { UP, DOWN} dir = UP;
-
- switch(dir)
- {
- case UP:
- g_keyboard->rpt_buf[g_key_index] = KEY_PAGEUP;
- x++;
- if (x > 100)
- {
- dir = DOWN;
- }
- break;
- case DOWN:
- g_keyboard->rpt_buf[g_key_index] = KEY_PAGEDOWN;
- x--;
- if (x < 0)
- {
- dir = UP;
- }
- break;
- }
- (void) USB_Class_HID_Send_Data(g_keyboard->app_handle, HID_ENDPOINT, g_keyboard->rpt_buf, KEYBOARD_BUFF_SIZE);
-
- return;
-}
-
-/******************************************************************************
- *
- * @name USB_App_Device_Callback
- *
- * @brief This function handles the callback
- *
- * @param handle : handle to Identify the controller
- * @param event_type : value of the event
- * @param val : gives the configuration value
- *
- * @return None
- *
- *****************************************************************************/
-void USB_Keyboard_App_Device_Callback(uint8_t event_type, void* val, void* arg)
-{
- UNUSED_ARGUMENT (arg)
- UNUSED_ARGUMENT (val)
-
- switch(event_type)
- {
- case USB_DEV_EVENT_BUS_RESET:
- g_keyboard->keyboard_init = FALSE;
- if (USB_OK == USB_Class_HID_Get_Speed(g_keyboard->app_handle, &g_keyboard->app_speed)) {
- USB_Desc_Set_Speed(g_keyboard->app_handle, g_keyboard->app_speed);
- }
- break;
- case USB_DEV_EVENT_ENUM_COMPLETE:
- g_keyboard->keyboard_init = TRUE;
- g_process_times = 1;
- KeyBoard_Events_Process();/* run the cursor movement code */
- break;
- case USB_DEV_EVENT_ERROR:
- // user may add code here for error handling
- // NOTE : val has the value of error from h/w
- break;
- default:
- break;
- }
- return;
-}
-
-/******************************************************************************
- *
- * @name USB_App_Class_Callback
- *
- * @brief This function handles USB-HID Class callback
- *
- * @param request : request type
- * @param value : give report type and id
- * @param data : pointer to the data
- * @param size : size of the transfer
- *
- * @return status
- * USB_OK : if successful
- * else return error
- *
- *****************************************************************************
- * This function is called whenever a HID class request is received. This
- * function handles these class requests.
- *****************************************************************************/
-uint8_t USB_Keyboard_App_Class_Callback
-(
- uint8_t request,
- uint16_t value,
- uint8_t ** data,
- uint32_t* size,
- void* arg
- )
-{
- uint8_t error = USB_OK;
-
- uint8_t index = (uint8_t)((request - 2) & USB_HID_REQUEST_TYPE_MASK);
- if ((request == USB_DEV_EVENT_SEND_COMPLETE) && (value == USB_REQ_VAL_INVALID) && (*size != 0xFFFFFFFF)) {
- if ((g_keyboard->keyboard_init) && (arg != NULL)) {
-#if COMPLIANCE_TESTING
- uint32_t g_compliance_delay = 0x009FFFFF;
- while(g_compliance_delay--);
-#endif
-
- KeyBoard_Events_Process();/* run the cursor movement code */
- }
- return error;
- }
-
- /* index == 0 for get/set idle, index == 1 for get/set protocol */
- /* handle the class request */
- switch(request)
- {
- case USB_HID_GET_REPORT_REQUEST:
- *data = &g_keyboard->rpt_buf[0]; /* point to the report to send */
- *size = KEYBOARD_BUFF_SIZE; /* report size */
- break;
-
- case USB_HID_SET_REPORT_REQUEST:
- for (index = 0; index < (*size); index++)
- { /* copy the report sent by the host */
- //g_keyboard->rpt_buf[index] = *(*data + index);
- }
- *size = 0;
- break;
-
- case USB_HID_GET_IDLE_REQUEST:
- /* point to the current idle rate */
- *data = &g_keyboard->app_request_params[index];
- *size = REQ_DATA_SIZE;
- break;
-
- case USB_HID_SET_IDLE_REQUEST:
- /* set the idle rate sent by the host */
- g_keyboard->app_request_params[index] = (uint8_t)((value & MSB_MASK) >>
- HIGH_BYTE_SHIFT);
- *size = 0;
- break;
-
- case USB_HID_GET_PROTOCOL_REQUEST:
- /* point to the current protocol code
- 0 = Boot Protocol
- 1 = Report Protocol*/
- *data = &g_keyboard->app_request_params[index];
- *size = REQ_DATA_SIZE;
- break;
-
- case USB_HID_SET_PROTOCOL_REQUEST:
- /* set the protocol sent by the host
- 0 = Boot Protocol
- 1 = Report Protocol*/
- g_keyboard->app_request_params[index] = (uint8_t)(value);
- *size = 0;
- break;
- }
- return error;
-}
-
-/******************************************************************************
- *
- * @name APP_init
- *
- * @brief This function is the entry for Keyboard Application
- *
- * @param None
- *
- * @return None
- *
- *****************************************************************************
- * This function starts the keyboard application
- *****************************************************************************/
-
-void hid_keyboard_init(void* param) {
- g_keyboard = (keyboard_global_variable_struct_t*)param;
-}
diff --git a/right/keyboard.h b/right/keyboard.h
deleted file mode 100644
index cc7f8ed..0000000
--- a/right/keyboard.h
+++ /dev/null
@@ -1,265 +0,0 @@
-#ifndef _KEYBOARD_H
-#define _KEYBOARD_H
-
-// Macro definitions:
-
- #define CONTROLLER_ID USB_CONTROLLER_KHCI_0
-
- /* USB scancodes */
-
- #define WINDOWS_KEY 0x08
-
- #define KEY_NONE 0x00
- #define KEY_ERRORROLLOVER 0x01
- #define KEY_POSTFAIL 0x02
- #define KEY_ERRORUNDEFINED 0x03
- #define KEY_A 0x04
- #define KEY_B 0x05
- #define KEY_C 0x06
- #define KEY_D 0x07
- #define KEY_E 0x08
- #define KEY_F 0x09
- #define KEY_G 0x0A
- #define KEY_H 0x0B
- #define KEY_I 0x0C
- #define KEY_J 0x0D
- #define KEY_K 0x0E
- #define KEY_L 0x0F
- #define KEY_M 0x10
- #define KEY_N 0x11
- #define KEY_O 0x12
- #define KEY_P 0x13
- #define KEY_Q 0x14
- #define KEY_R 0x15
- #define KEY_S 0x16
- #define KEY_T 0x17
- #define KEY_U 0x18
- #define KEY_V 0x19
- #define KEY_W 0x1A
- #define KEY_X 0x1B
- #define KEY_Y 0x1C
- #define KEY_Z 0x1D
- #define KEY_1_EXCLAMATION_MARK 0x1E
- #define KEY_2_AT 0x1F
- #define KEY_3_NUMBER_SIGN 0x20
- #define KEY_4_DOLLAR 0x21
- #define KEY_5_PERCENT 0x22
- #define KEY_6_CARET 0x23
- #define KEY_7_AMPERSAND 0x24
- #define KEY_8_ASTERISK 0x25
- #define KEY_9_OPARENTHESIS 0x26
- #define KEY_0_CPARENTHESIS 0x27
- #define KEY_ENTER 0x28
- #define KEY_ESCAPE 0x29
- #define KEY_BACKSPACE 0x2A
- #define KEY_TAB 0x2B
- #define KEY_SPACEBAR 0x2C
- #define KEY_MINUS_UNDERSCORE 0x2D
- #define KEY_EQUAL_PLUS 0x2E
- #define KEY_OBRACKET_AND_OBRACE 0x2F
- #define KEY_CBRACKET_AND_CBRACE 0x30
- #define KEY_BACKSLASH_VERTICAL_BAR 0x31
- #define KEY_NONUS_NUMBER_SIGN_TILDE 0x32
- #define KEY_SEMICOLON_COLON 0x33
- #define KEY_SINGLE_AND_DOUBLE_QUOTE 0x34
- #define KEY_GRAVE_ACCENT_AND_TILDE 0x35
- #define KEY_COMMA_AND_LESS 0x36
- #define KEY_DOT_GREATER 0x37
- #define KEY_SLASH_QUESTION 0x38
- #define KEY_CAPS_LOCK 0x39
- #define KEY_F1 0x3A
- #define KEY_F2 0x3B
- #define KEY_F3 0x3C
- #define KEY_F4 0x3D
- #define KEY_F5 0x3E
- #define KEY_F6 0x3F
- #define KEY_F7 0x40
- #define KEY_F8 0x41
- #define KEY_F9 0x42
- #define KEY_F10 0x43
- #define KEY_F11 0x44
- #define KEY_F12 0x45
- #define KEY_PRINTSCREEN 0x46
- #define KEY_SCROLL_LOCK 0x47
- #define KEY_PAUSE 0x48
- #define KEY_INSERT 0x49
- #define KEY_HOME 0x4A
- #define KEY_PAGEUP 0x4B
- #define KEY_DELETE 0x4C
- #define KEY_END1 0x4D
- #define KEY_PAGEDOWN 0x4E
- #define KEY_RIGHTARROW 0x4F
- #define KEY_LEFTARROW 0x50
- #define KEY_DOWNARROW 0x51
- #define KEY_UPARROW 0x52
- #define KEY_KEYPAD_NUM_LOCK_AND_CLEAR 0x53
- #define KEY_KEYPAD_SLASH 0x54
- #define KEY_KEYPAD_ASTERIKS 0x55
- #define KEY_KEYPAD_MINUS 0x56
- #define KEY_KEYPAD_PLUS 0x57
- #define KEY_KEYPAD_ENTER 0x58
- #define KEY_KEYPAD_1_END 0x59
- #define KEY_KEYPAD_2_DOWN_ARROW 0x5A
- #define KEY_KEYPAD_3_PAGEDN 0x5B
- #define KEY_KEYPAD_4_LEFT_ARROW 0x5C
- #define KEY_KEYPAD_5 0x5D
- #define KEY_KEYPAD_6_RIGHT_ARROW 0x5E
- #define KEY_KEYPAD_7_HOME 0x5F
- #define KEY_KEYPAD_8_UP_ARROW 0x60
- #define KEY_KEYPAD_9_PAGEUP 0x61
- #define KEY_KEYPAD_0_INSERT 0x62
- #define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE 0x63
- #define KEY_NONUS_BACK_SLASH_VERTICAL_BAR 0x64
- #define KEY_APPLICATION 0x65
- #define KEY_POWER 0x66
- #define KEY_KEYPAD_EQUAL 0x67
- #define KEY_F13 0x68
- #define KEY_F14 0x69
- #define KEY_F15 0x6A
- #define KEY_F16 0x6B
- #define KEY_F17 0x6C
- #define KEY_F18 0x6D
- #define KEY_F19 0x6E
- #define KEY_F20 0x6F
- #define KEY_F21 0x70
- #define KEY_F22 0x71
- #define KEY_F23 0x72
- #define KEY_F24 0x73
- #define KEY_EXECUTE 0x74
- #define KEY_HELP 0x75
- #define KEY_MENU 0x76
- #define KEY_SELECT 0x77
- #define KEY_STOP 0x78
- #define KEY_AGAIN 0x79
- #define KEY_UNDO 0x7A
- #define KEY_CUT 0x7B
- #define KEY_COPY 0x7C
- #define KEY_PASTE 0x7D
- #define KEY_FIND 0x7E
- #define KEY_MUTE 0x7F
- #define KEY_VOLUME_UP 0x80
- #define KEY_VOLUME_DOWN 0x81
- #define KEY_LOCKING_CAPS_LOCK 0x82
- #define KEY_LOCKING_NUM_LOCK 0x83
- #define KEY_LOCKING_SCROLL_LOCK 0x84
- #define KEY_KEYPAD_COMMA 0x85
- #define KEY_KEYPAD_EQUAL_SIGN 0x86
- #define KEY_INTERNATIONAL1 0x87
- #define KEY_INTERNATIONAL2 0x88
- #define KEY_INTERNATIONAL3 0x89
- #define KEY_INTERNATIONAL4 0x8A
- #define KEY_INTERNATIONAL5 0x8B
- #define KEY_INTERNATIONAL6 0x8C
- #define KEY_INTERNATIONAL7 0x8D
- #define KEY_INTERNATIONAL8 0x8E
- #define KEY_INTERNATIONAL9 0x8F
- #define KEY_LANG1 0x90
- #define KEY_LANG2 0x91
- #define KEY_LANG3 0x92
- #define KEY_LANG4 0x93
- #define KEY_LANG5 0x94
- #define KEY_LANG6 0x95
- #define KEY_LANG7 0x96
- #define KEY_LANG8 0x97
- #define KEY_LANG9 0x98
- #define KEY_ALTERNATE_ERASE 0x99
- #define KEY_SYSREQ 0x9A
- #define KEY_CANCEL 0x9B
- #define KEY_CLEAR 0x9C
- #define KEY_PRIOR 0x9D
- #define KEY_RETURN 0x9E
- #define KEY_SEPARATOR 0x9F
- #define KEY_OUT 0xA0
- #define KEY_OPER 0xA1
- #define KEY_CLEAR_AGAIN 0xA2
- #define KEY_CRSEL 0xA3
- #define KEY_EXSEL 0xA4
- #define KEY_KEYPAD_00 0xB0
- #define KEY_KEYPAD_000 0xB1
- #define KEY_THOUSANDS_SEPARATOR 0xB2
- #define KEY_DECIMAL_SEPARATOR 0xB3
- #define KEY_CURRENCY_UNIT 0xB4
- #define KEY_CURRENCY_SUB_UNIT 0xB5
- #define KEY_KEYPAD_OPARENTHESIS 0xB6
- #define KEY_KEYPAD_CPARENTHESIS 0xB7
- #define KEY_KEYPAD_OBRACE 0xB8
- #define KEY_KEYPAD_CBRACE 0xB9
- #define KEY_KEYPAD_TAB 0xBA
- #define KEY_KEYPAD_BACKSPACE 0xBB
- #define KEY_KEYPAD_A 0xBC
- #define KEY_KEYPAD_B 0xBD
- #define KEY_KEYPAD_C 0xBE
- #define KEY_KEYPAD_D 0xBF
- #define KEY_KEYPAD_E 0xC0
- #define KEY_KEYPAD_F 0xC1
- #define KEY_KEYPAD_XOR 0xC2
- #define KEY_KEYPAD_CARET 0xC3
- #define KEY_KEYPAD_PERCENT 0xC4
- #define KEY_KEYPAD_LESS 0xC5
- #define KEY_KEYPAD_GREATER 0xC6
- #define KEY_KEYPAD_AMPERSAND 0xC7
- #define KEY_KEYPAD_LOGICAL_AND 0xC8
- #define KEY_KEYPAD_VERTICAL_BAR 0xC9
- #define KEY_KEYPAD_LOGIACL_OR 0xCA
- #define KEY_KEYPAD_COLON 0xCB
- #define KEY_KEYPAD_NUMBER_SIGN 0xCC
- #define KEY_KEYPAD_SPACE 0xCD
- #define KEY_KEYPAD_AT 0xCE
- #define KEY_KEYPAD_EXCLAMATION_MARK 0xCF
- #define KEY_KEYPAD_MEMORY_STORE 0xD0
- #define KEY_KEYPAD_MEMORY_RECALL 0xD1
- #define KEY_KEYPAD_MEMORY_CLEAR 0xD2
- #define KEY_KEYPAD_MEMORY_ADD 0xD3
- #define KEY_KEYPAD_MEMORY_SUBTRACT 0xD4
- #define KEY_KEYPAD_MEMORY_MULTIPLY 0xD5
- #define KEY_KEYPAD_MEMORY_DIVIDE 0xD6
- #define KEY_KEYPAD_PLUSMINUS 0xD7
- #define KEY_KEYPAD_CLEAR 0xD8
- #define KEY_KEYPAD_CLEAR_ENTRY 0xD9
- #define KEY_KEYPAD_BINARY 0xDA
- #define KEY_KEYPAD_OCTAL 0xDB
- #define KEY_KEYPAD_DECIMAL 0xDC
- #define KEY_KEYPAD_HEXADECIMAL 0xDD
- #define KEY_LEFTCONTROL 0xE0
- #define KEY_LEFTSHIFT 0xE1
- #define KEY_LEFTALT 0xE2
- #define KEY_LEFT_GUI 0xE3
- #define KEY_RIGHTCONTROL 0xE4
- #define KEY_RIGHTSHIFT 0xE5
- #define KEY_RIGHTALT 0xE6
- #define KEY_RIGHT_GUI 0xE7
-
- #define MODIFERKEYS_LEFT_CTRL 0x01
- #define MODIFERKEYS_LEFT_SHIFT 0x02
- #define MODIFERKEYS_LEFT_ALT 0x04
- #define MODIFERKEYS_LEFT_GUI 0x08
- #define MODIFERKEYS_RIGHT_CTRL 0x10
- #define MODIFERKEYS_RIGHT_SHIFT 0x20
- #define MODIFERKEYS_RIGHT_ALT 0x40
- #define MODIFERKEYS_RIGHT_GUI 0x80
-
- #define KEYBOARD_BUFF_SIZE (8) /* report buffer size */
- #define REQ_DATA_SIZE (1)
- #define KBI_STAT_MASK (0x0F)
- #define PAGEUP_PRESS (0x01) /* PAGE UP Key Press */
- #define PAGEDWON_PRESS (0x02) /* Page DOWN Key Press */
- #define SPACE_PRESS (0x04) /* Space Bar Press */
- #define PRTSCRN_PRESS (0x08) /* Print Screen Press */
-
-extern uint8_t kbi_stat; /* records the status of the buttons (PTG0-PTG3) used to emulate Keyboard */
-
-// Type definitions:
- typedef struct _keyboard_variable_struct {
- hid_handle_t app_handle;
- uint16_t app_speed;
- bool keyboard_init;/* flag to check lower layer status*/
- uint8_t rpt_buf[KEYBOARD_BUFF_SIZE];/*report/data buff for mouse application*/
- uint8_t app_request_params[2]; /* for get/set idle and protocol requests*/
- } keyboard_global_variable_struct_t;
-
-// Funciton prototypes:
- extern void TestApp_Init(void);
- extern void KeyBoard_Events_Process(void);
- void hid_keyboard_init(void* param);
-
-#endif
diff --git a/right/mouse.c b/right/mouse.c
deleted file mode 100644
index 83e90a5..0000000
--- a/right/mouse.c
+++ /dev/null
@@ -1,208 +0,0 @@
-#include "usb_device_config.h"
-#include "usb.h"
-#include "usb_device_stack_interface.h"
-#include "mouse.h"
-
-/* Add all the variables needed for mouse.c to this structure */
-hid_mouse_struct_t* g_hid_mouse_ptr;
-extern uint16_t g_composite_speed;
-
-void Hid_USB_Mouse_App_Device_Callback(uint8_t event_type, void* val, void* arg);
-uint8_t Hid_USB_Mouse_App_Class_Callback(
- uint8_t request, uint16_t value, uint8_t ** data, uint32_t* size, void* arg);
-
-/*****************************************************************************
- *
- * @name move_mouse
- *
- * @brief This function gets makes the cursor on screen move left,right
- * up and down
- *
- * @param None
- *
- * @return None
- *
- *
- ******************************************************************************/
-void move_mouse(void)
-{
- static int32_t x = 0, y = 0;
- enum { RIGHT, DOWN, LEFT, UP } ;
- static uint8_t dir = (uint8_t) RIGHT;
-
- switch(dir)
- {
- case RIGHT:
- g_hid_mouse_ptr->rpt_buf[1] = 2;
- g_hid_mouse_ptr->rpt_buf[2] = 0;
- x++;
- if (x > 1)
- {
- dir++;
- }
- break;
- case DOWN:
- g_hid_mouse_ptr->rpt_buf[1] = 0;
- g_hid_mouse_ptr->rpt_buf[2] = 2;
- y++;
- if (y > 1)
- {
- dir++;
- }
- break;
- case LEFT:
- g_hid_mouse_ptr->rpt_buf[1] = (uint8_t)(-2);
- g_hid_mouse_ptr->rpt_buf[2] = 0;
- x--;
- if (x < 0)
- {
- dir++;
- }
- break;
- case UP:
- g_hid_mouse_ptr->rpt_buf[1] = 0;
- g_hid_mouse_ptr->rpt_buf[2] = (uint8_t)(-2);
- y--;
- if (y < 0)
- {
- dir = RIGHT;
- }
- break;
- }
- (void) USB_Class_HID_Send_Data(g_hid_mouse_ptr->app_handle, HID_ENDPOINT,
- g_hid_mouse_ptr->rpt_buf, MOUSE_BUFF_SIZE);
-}
-
-/******************************************************************************
- *
- * @name Hid_USB_App_Device_Callback
- *
- * @brief This function handles the callback
- *
- * @param handle : handle to Identify the controller
- * @param event_type : value of the event
- * @param val : gives the configuration value
- *
- * @return None
- *
- *****************************************************************************/
-void Hid_USB_Mouse_App_Device_Callback(uint8_t event_type, void* val, void* arg)
-{
- UNUSED_ARGUMENT (arg)
- UNUSED_ARGUMENT (val)
-
- switch(event_type)
- {
- case USB_DEV_EVENT_BUS_RESET:
- g_hid_mouse_ptr->mouse_init = FALSE;
- if (USB_OK == USB_Class_HID_Get_Speed(g_hid_mouse_ptr->app_handle, &g_composite_speed))
- {
- USB_Desc_Set_Speed(g_hid_mouse_ptr->app_handle, g_composite_speed);
- }
- break;
- case USB_DEV_EVENT_ENUM_COMPLETE:
- g_hid_mouse_ptr->mouse_init = TRUE;
- move_mouse();/* run the cursor movement code */
- break;
- case USB_DEV_EVENT_ERROR:
- /* user may add code here for error handling
- NOTE : val has the value of error from h/w*/
- break;
- default:
- break;
- }
- return;
-}
-
-/******************************************************************************
- *
- * @name Hid_USB_App_Class_Callback
- *
- * @brief This function handles the callback for Get/Set report req
- *
- * @param request : request type
- * @param value : give report type and id
- * @param data : pointer to the data
- * @param size : size of the transfer
- *
- * @return status
- * USB_OK : if successful
- * else return error
- *
- *****************************************************************************/
-uint8_t Hid_USB_Mouse_App_Class_Callback
-(
- uint8_t request,
- uint16_t value,
- uint8_t ** data,
- uint32_t* size,
- void* arg
-)
-{
- uint8_t error = USB_OK;
- //uint8_t direction = (uint8_t)((request & USB_HID_REQUEST_DIR_MASK) >>3);
- uint8_t index = (uint8_t)((request - 2) & USB_HID_REQUEST_TYPE_MASK);
- if ((request == USB_DEV_EVENT_SEND_COMPLETE) && (value == USB_REQ_VAL_INVALID) && (*size != 0xFFFFFFFF))
- {
- if ((g_hid_mouse_ptr->mouse_init) && (arg != NULL))
- {
-#if COMPLIANCE_TESTING
- uint32_t g_compliance_delay = 0x009FFFFF;
- while(g_compliance_delay--);
-#endif
-
- move_mouse();/* run the cursor movement code */
- }
- return error;
- }
-
- /* index == 0 for get/set idle, index == 1 for get/set protocol */
- *size = 0;
- /* handle the class request */
- switch (request)
- {
- case USB_HID_GET_REPORT_REQUEST:
- *data = &g_hid_mouse_ptr->rpt_buf[0]; /* point to the report to send */
- *size = MOUSE_BUFF_SIZE; /* report size */
- break;
-
- case USB_HID_SET_REPORT_REQUEST:
- for (index = 0; index < MOUSE_BUFF_SIZE; index++)
- { /* copy the report sent by the host */
- g_hid_mouse_ptr->rpt_buf[index] = *(*data + index);
- }
- break;
-
- case USB_HID_GET_IDLE_REQUEST:
- /* point to the current idle rate */
- *data = &g_hid_mouse_ptr->app_request_params[index];
- *size = REQ_DATA_SIZE;
- break;
-
- case USB_HID_SET_IDLE_REQUEST:
- /* set the idle rate sent by the host */
- g_hid_mouse_ptr->app_request_params[index] = (uint8_t)((value & MSB_MASK) >>
- HIGH_BYTE_SHIFT);
- break;
-
- case USB_HID_GET_PROTOCOL_REQUEST:
- /* point to the current protocol code
- 0 = Boot Protocol
- 1 = Report Protocol*/
- *data = &g_hid_mouse_ptr->app_request_params[index];
- *size = REQ_DATA_SIZE;
- break;
-
- case USB_HID_SET_PROTOCOL_REQUEST:
- /* set the protocol sent by the host
- 0 = Boot Protocol
- 1 = Report Protocol*/
- g_hid_mouse_ptr->app_request_params[index] = (uint8_t)(value);
- break;
- }
- return error;
-}
-
-void hid_mouse_init(void* param) {
- g_hid_mouse_ptr = (hid_mouse_struct_t*) param;
-}
diff --git a/right/mouse.h b/right/mouse.h
deleted file mode 100644
index 25b0cdd..0000000
--- a/right/mouse.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _MOUSE_H
-#define _MOUSE_H
-
-#include "usb_descriptor.h"
-
-/* Macros: */
- #define MOUSE_BUFF_SIZE (4) /* report buffer size */
- #define REQ_DATA_SIZE (1)
- #define COMPLIANCE_TESTING (0) /* 1:TRUE, 0:FALSE */
-
-/* Type defines: */
- typedef struct hid_mouse_struct {
- hid_handle_t app_handle;
- bool mouse_init; /* flag to check lower layer status*/
- uint8_t rpt_buf[MOUSE_BUFF_SIZE]; /* report/data buff for mouse application */
- uint8_t app_request_params[2]; /* for get/set idle and protocol requests */
- } hid_mouse_struct_t;
-
-/* Function prototypes: */
- void hid_mouse_init(void* param);
-
-#endif
diff --git a/right/usb_descriptor.c b/right/usb_descriptor.c
deleted file mode 100644
index a0205ea..0000000
--- a/right/usb_descriptor.c
+++ /dev/null
@@ -1,733 +0,0 @@
-#include "usb_device_config.h"
-#include "usb.h"
-#include "usb_device_stack_interface.h"
-#include "usb_descriptor.h"
-#include "mouse.h"
-#include "composite_app.h"
-
-///////////////////////////////// Keyboard endpoint and interface /////////////////////////////////
-
-usb_ep_struct_t keyboard_endpoint[HID_DESC_ENDPOINT_COUNT] =
-{
- {
- HID_ENDPOINT,
- USB_INTERRUPT_PIPE,
- USB_SEND,
- FS_INTERRUPT_OUT_ENDP_PACKET_SIZE,
- }
-};
-
-usb_endpoints_t keyboard_endpoints =
-{
- HID_DESC_ENDPOINT_COUNT,
- keyboard_endpoint
-};
-
-static usb_if_struct_t keyboard_interface[1];
-
-/////////////////////////////////// Mouse endpoint and interface ///////////////////////////////////
-
-usb_ep_struct_t mouse_endpoint[HID_DESC_ENDPOINT_COUNT] =
-{
- {
- HID_ENDPOINT,
- USB_INTERRUPT_PIPE,
- USB_SEND,
- FS_INTERRUPT_OUT_ENDP_PACKET_SIZE,
- }
-};
-
-usb_endpoints_t mouse_endpoints =
-{
- HID_DESC_ENDPOINT_COUNT,
- mouse_endpoint
-};
-
-static usb_if_struct_t mouse_interface[1];
-
-////////////////////////////////////// USB class descriptors //////////////////////////////////////
-
-usb_class_struct_t usb_interfaces[2] =
-{
- {
- USB_CLASS_HID,
- {
- 1,
- keyboard_interface
- }
- },
- {
- USB_CLASS_HID,
- {
- 1,
- mouse_interface
- }
- },
-};
-
-static usb_composite_info_struct_t usb_composite_info =
-{
- 2,
- usb_interfaces
-};
-
-uint8_t g_device_descriptor[DEVICE_DESCRIPTOR_SIZE] =
-{
- DEVICE_DESCRIPTOR_SIZE, /* "Device Descriptor Size */
- USB_DEVICE_DESCRIPTOR, /* "Device" Type of descriptor */
- 0x00,0x02, /* BCD USB version */
- 0x00, /* Device Class is indicated in
- the interface descriptors */
- 0x00, /* Device Subclass is indicated
- in the interface descriptors */
- 0x00, /* Device Protocol */
- CONTROL_MAX_PACKET_SIZE, /* Max Packet size */
- 0xa2,0x15, /* Vendor ID */
- 0x00, 0x02, /* Product ID */
- 0x00, 0x02, /* BCD Device version */
- 0x01, /* Manufacturer string index */
- 0x02, /* Product string index */
- 0x00, /* Serial number string index */
- 0x01 /* Number of configurations */
-};
-
-uint8_t g_config_descriptor[CONFIG_DESC_SIZE] =
-{
- CONFIG_ONLY_DESC_SIZE, /* Configuration Descriptor Size - always 9 bytes*/
- USB_CONFIG_DESCRIPTOR, /* "Configuration" type of descriptor */
- CONFIG_DESC_SIZE, 0x00, /* Total length of the Configuration descriptor */
- 0x02, /* NumInterfaces */
- 0x01, /* Configuration Value */
- 0, /* Configuration Description String Index*/
- /* Attributes.support RemoteWakeup and self power */
- (USB_DESC_CFG_ATTRIBUTES_D7_POS) | (USBCFG_DEV_SELF_POWER << USB_DESC_CFG_ATTRIBUTES_SELF_POWERED_SHIFT) | (USBCFG_DEV_REMOTE_WAKEUP << USB_DESC_CFG_ATTRIBUTES_REMOTE_WAKEUP_SHIFT),
- /* S08/CFv1 are both self powered (its compulsory to set bus powered)*/
- /*Attributes.support RemoteWakeup and self power*/
- 0x32, /* Current draw from bus */
-
- /* Keyboard Interface Descriptor */
- IFACE_ONLY_DESC_SIZE,
- USB_IFACE_DESCRIPTOR,
- 0x00,
- 0x00,
- HID_DESC_ENDPOINT_COUNT,
- 0x03,
- 0x01,
- 0x01, /* 0x01 for keyboard */
- 0x00,
-
- /* Keyboard HID descriptor */
- HID_ONLY_DESC_SIZE,
- USB_HID_DESCRIPTOR,
- 0x00, 0x01,
- 0x00,
- 0x01,
- 0x22,
- 0x3F, 0x00,
-
- /* Keyboard Endpoint descriptor */
- ENDP_ONLY_DESC_SIZE,
- USB_ENDPOINT_DESCRIPTOR,
- HID_ENDPOINT |(USB_SEND << 7),
- USB_INTERRUPT_PIPE,
- FS_INTERRUPT_OUT_ENDP_PACKET_SIZE, 0x00,
- FS_INTERRUPT_OUT_ENDP_INTERVAL,
-
- /* Mouse Interface Descriptor */
- IFACE_ONLY_DESC_SIZE,
- USB_IFACE_DESCRIPTOR,
- 0x00,
- 0x00,
- HID_DESC_ENDPOINT_COUNT,
- 0x03,
- 0x01,
- 0x02,
- 0x00,
-
- /* Mouse HID descriptor */
- HID_ONLY_DESC_SIZE,
- USB_HID_DESCRIPTOR,
- 0x00,0x01,
- 0x00,
- 0x01,
- 0x22,
- 0x34,0x00,
-
- /* Mouse Endpoint descriptor */
- ENDP_ONLY_DESC_SIZE,
- USB_ENDPOINT_DESCRIPTOR,
- HID_ENDPOINT | (USB_SEND << 7),
- USB_INTERRUPT_PIPE,
- FS_INTERRUPT_OUT_ENDP_PACKET_SIZE, 0x00,
- FS_INTERRUPT_OUT_ENDP_INTERVAL
-};
-
-uint8_t USB_STR_0[USB_STR_0_SIZE+USB_STR_DESC_SIZE] =
-{
- sizeof(USB_STR_0),
- USB_STRING_DESCRIPTOR,
- 0x09,
- 0x04/*equivalent to 0x0409*/
-};
-
-uint8_t USB_STR_1[USB_STR_1_SIZE+USB_STR_DESC_SIZE] =
-{
- sizeof(USB_STR_1),
- USB_STRING_DESCRIPTOR,
- 'F',0,
- 'R',0,
- 'E',0,
- 'E',0,
- 'S',0,
- 'C',0,
- 'A',0,
- 'L',0,
- 'E',0,
- ' ',0,
- 'S',0,
- 'E',0,
- 'M',0,
- 'I',0,
- 'C',0,
- 'O',0,
- 'N',0,
- 'D',0,
- 'U',0,
- 'C',0,
- 'T',0,
- 'O',0,
- 'R',0,
- ' ',0,
- 'I',0,
- 'N',0,
- 'C',0,
- '.',0
-};
-
-uint8_t USB_STR_2[USB_STR_2_SIZE+USB_STR_DESC_SIZE] =
-{
- sizeof(USB_STR_2),
- USB_STRING_DESCRIPTOR,
- 'U',0,
- 'S',0,
- 'B',0,
- ' ',0,
- 'A',0,
- 'U',0,
- 'D',0,
- 'I',0,
- 'O',0,
- '+',0,
- 'H',0,
- 'I',0,
- 'D',0,
- ' ',0,
- 'D',0,
- 'E',0,
- 'M',0,
- 'O',0,
-};
-
-uint8_t USB_STR_n[USB_STR_n_SIZE+USB_STR_DESC_SIZE] =
-{
- sizeof(USB_STR_n),
- USB_STRING_DESCRIPTOR,
- 'B',0,
- 'A',0,
- 'D',0,
- ' ',0,
- 'S',0,
- 'T',0,
- 'R',0,
- 'I',0,
- 'N',0,
- 'G',0,
- ' ',0,
- 'I',0,
- 'N',0,
- 'D',0,
- 'E',0,
- 'X',0
-};
-
-uint8_t keyboard_hid_report_descriptor[KEYBOARD_REPORT_DESC_SIZE] =
-{
- 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
- 0x09, 0x06, /* USAGE (Keyboard) */
- 0xa1, 0x01, /* COLLECTION (Application) */
- 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
- 0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */
- 0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
- 0x75, 0x01, /* REPORT_SIZE (1) */
- 0x95, 0x08, /* REPORT_COUNT (8) */
- 0x81, 0x02, /* INPUT (Data,Var,Abs) modifier keys (CTRL, ALT, etc...*/
- 0x95, 0x01, /* REPORT_COUNT (1) */
- 0x75, 0x08, /* REPORT_SIZE (8) */
- 0x81, 0x01, /* INPUT (Cnst,Var,Abs) filupp to byte boundary */
- 0x95, 0x05, /* REPORT_COUNT (5) */
- 0x75, 0x01, /* REPORT_SIZE (1) */
- 0x05, 0x08, /* USAGE_PAGE (LEDs) */
- 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */
- 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */
- 0x91, 0x02, /* OUTPUT (Data,Var,Abs) pc->kbd */
- 0x95, 0x01, /* REPORT_COUNT (1) */
- 0x75, 0x03, /* REPORT_SIZE (3 */
- 0x91, 0x01, /* OUTPUT (Cnst,Var,Abs) filupp to byte boundary */
- 0x95, 0x06, /* REPORT_COUNT (6) */
- 0x75, 0x08, /* REPORT_SIZE (8) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */
- 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
- 0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */
- 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */
- 0x81, 0x00, /* INPUT (Data,Ary,Abs) array for pressed keys */
- 0xc0 /* END_COLLECTION */
-};
-
-uint8_t mouse_hid_report_descriptor[MOUSE_REPORT_DESC_SIZE] =
-{
- 0x05, 0x01, /* Usage Page (Generic Desktop)*/
- 0x09, 0x02, /* Usage (Mouse) */
- 0xA1, 0x01, /* Collection (Application) */
- 0x09, 0x01, /* Usage (Pointer) */
-
- 0xA1, 0x00, /* Collection (Physical) */
- 0x05, 0x09, /* Usage Page (Buttons) */
- 0x19, 0x01, /* Usage Minimum (01) */
- 0x29, 0x03, /* Usage Maximum (03) */
-
- 0x15, 0x00, /* logical Minimum (0) */
- 0x25, 0x01, /* logical Maximum (1) */
- 0x95, 0x03, /* Report Count (3) */
- 0x75, 0x01, /* Report Size (1) */
-
- 0x81, 0x02, /* Input(Data, Variable, Absolute) 3 button bits */
- 0x95, 0x01, /* Report count (1) */
- 0x75, 0x05, /* Report Size (5) */
- 0x81, 0x01, /* Input (Constant), 5 bit padding */
-
- 0x05, 0x01, /* Usage Page (Generic Desktop) */
- 0x09, 0x30, /* Usage (X) */
- 0x09, 0x31, /* Usage (Y) */
- 0x09, 0x38, /* Usage (Z) */
-
- 0x15, 0x81, /* Logical Minimum (-127) */
- 0x25, 0x7F, /* Logical Maximum (127) */
- 0x75, 0x08, /* Report Size (8) */
- 0x95, 0x03, /* Report Count (2) */
-
- 0x81, 0x06, /* Input(Data, Variable, Relative), 2 position bytes (X & Y)*/
- 0xC0, /* end collection */
- 0xC0 /* end collection */
-};
-
-uint32_t g_std_desc_size[USB_MAX_STD_DESCRIPTORS+1] =
-{
- 0,
- DEVICE_DESCRIPTOR_SIZE,
- CONFIG_DESC_SIZE,
- 0, /* String */
- 0, /* Interface */
- 0, /* Endpoint */
- 0, /* Device Qualifier */
- 0 /* other speed config */
-};
-
-uint8_t *g_std_descriptors[USB_MAX_STD_DESCRIPTORS+1] =
-{
- NULL,
- g_device_descriptor,
- g_config_descriptor,
- NULL, /* String */
- NULL, /* Interface */
- NULL, /* Endpoint */
- NULL, /* Device Qualifier */
- NULL /* Other speed config */
-};
-
-uint8_t g_string_desc_size[USB_MAX_STRING_DESCRIPTORS] =
-{
- sizeof(USB_STR_0),
- sizeof(USB_STR_1),
- sizeof(USB_STR_2),
- sizeof(USB_STR_n)
-};
-
-uint8_t *g_string_descriptors[USB_MAX_STRING_DESCRIPTORS+1] =
-{
- USB_STR_0,
- USB_STR_1,
- USB_STR_2,
- USB_STR_n
-};
-
-usb_language_t usb_lang[USB_MAX_SUPPORTED_LANGUAGES] =
-{
- {
- (uint16_t)0x0409,
- g_string_descriptors,
- g_string_desc_size
- }
-};
-
-usb_all_languages_t g_languages =
-{
- USB_STR_0, sizeof(USB_STR_0),
- USB_MAX_SUPPORTED_LANGUAGES,
- usb_lang
-};
-
-uint8_t g_valid_config_values[USB_MAX_CONFIG_SUPPORTED+1]={0,1};
-
-/****************************************************************************
- * Global Variables
- ****************************************************************************/
-static uint8_t g_alternate_interface[USB_MAX_SUPPORTED_INTERFACES];
-
-/**************************************************************************//*!
- *
- * @name USB_Desc_Get_Descriptor
- *
- * @brief The function returns the corresponding descriptor
- *
- * @param controller_ID : Controller ID
- * @param type : Type of descriptor requested
- * @param sub_type : String index for string descriptor
- * @param index : String descriptor language Id
- * @param descriptor : Output descriptor pointer
- * @param size : Size of descriptor returned
- *
- * @return USB_OK When Success
- * USBERR_INVALID_REQ_TYPE when Error
- *****************************************************************************
- * This function is used to pass the pointer of the requested descriptor
- *****************************************************************************/
-uint8_t USB_Desc_Get_Descriptor
-(
- uint32_t handle,
- uint8_t type,
- uint8_t str_num,
- uint16_t index,
- uint8_t** descriptor,
- uint32_t* size
-)
-{
- /* string descriptors are handled separately */
- if (type == USB_STRING_DESCRIPTOR) {
- if (index == 0) {
- /* return the string and size of all languages */
- *descriptor = (uint8_t *)g_languages.languages_supported_string;
- *size = g_languages.languages_supported_size;
- } else {
- uint8_t lang_id=0;
- uint8_t lang_index=USB_MAX_LANGUAGES_SUPPORTED;
-
- for (; lang_id< USB_MAX_LANGUAGES_SUPPORTED; lang_id++) {
- /* check whether we have a string for this language */
- if (index == g_languages.usb_language[lang_id].language_id) {
- /* check for max descriptors */
- if (str_num < USB_MAX_STRING_DESCRIPTORS) {
- /* setup index for the string to be returned */
- lang_index = str_num;
- }
- break;
- }
- }
- /* set return val for descriptor and size */
- *descriptor = (uint8_t *)g_languages.usb_language[lang_id].lang_desc[str_num];
- *size = g_languages.usb_language[lang_id].lang_desc_size[lang_index];
- }
- } else if (type < USB_MAX_STD_DESCRIPTORS+1) {
- /* set return val for descriptor and size*/
- *descriptor = (uint8_t *)g_std_descriptors[type];
-
- /* if there is no descriptor then return error */
- if (*descriptor == NULL) {
- return USBERR_INVALID_REQ_TYPE;
- }
- *size = g_std_desc_size[type];
- } else /* invalid descriptor */ {
- if (type == USB_REPORT_DESCRIPTOR) {
- type = USB_MAX_STD_DESCRIPTORS;
- *descriptor = (uint8_t *)g_std_descriptors[type];
- *size = g_std_desc_size[type];
- } else {
- return USBERR_INVALID_REQ_TYPE;
- }
- }
-
- return USB_OK;
-}
-
-/**************************************************************************//*!
- *
- * @name USB_Desc_Get_Interface
- *
- * @brief The function returns the alternate interface
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param alt_interface : Output alternate interface
- *
- * @return USB_OK When Success
- * USBERR_INVALID_REQ_TYPE when Error
- *****************************************************************************
- *This function is called by the framework module to get the current interface
- *****************************************************************************/
-uint8_t USB_Desc_Get_Interface(uint32_t handle, uint8_t interface, uint8_t *alt_interface) {
- if (interface < USB_MAX_SUPPORTED_INTERFACES) { /* if interface valid */
- /* get alternate interface */
- *alt_interface = g_alternate_interface[interface];
- return USB_OK;
- }
- return USBERR_INVALID_REQ_TYPE;
-}
-
-/**************************************************************************//*!
- *
- * @name USB_Desc_Set_Interface
- *
- * @brief The function sets the alternate interface
- *
- * @param handle : handle
- * @param interface : Interface number
- * @param alt_interface : Input alternate interface
- *
- * @return USB_OK When Success
- * USBERR_INVALID_REQ_TYPE when Error
- *****************************************************************************
- *This function is called by the framework module to set the interface
- *****************************************************************************/
-uint8_t USB_Desc_Set_Interface(uint32_t handle, uint8_t interface, uint8_t alt_interface) {
- if (interface < USB_MAX_SUPPORTED_INTERFACES) { /* if interface valid */
- /* set alternate interface*/
- g_alternate_interface[interface] = alt_interface;
- return USB_OK;
- }
- return USBERR_INVALID_REQ_TYPE;
-}
-
-/**************************************************************************//*!
- *
- * @name USB_Desc_Valid_Configation
- *
- * @brief The function checks whether the configuration parameter
- * input is valid or not
- *
- * @param handle : handle
- * @param config_val : Configuration value
- *
- * @return TRUE When Valid
- * FALSE When Error
- *****************************************************************************
- * This function checks whether the configuration is valid or not
- *****************************************************************************/
-bool USB_Desc_Valid_Configation
-(
- uint32_t handle,/*[IN] Controller ID */
- uint16_t config_val /*[IN] Configuration value */
-)
-{
- uint8_t loop_index=0;
-
- UNUSED_ARGUMENT(handle)
-
- /* check with only supported val right now */
- while(loop_index < (USB_MAX_CONFIG_SUPPORTED+1)) {
- if(config_val == g_valid_config_values[loop_index]) {
- return TRUE;
- }
- loop_index++;
- }
- return FALSE;
-}
-/**************************************************************************//*!
- *
- * @name USB_Desc_Valid_Interface
- *
- * @brief The function checks whether the interface parameter
- * input is valid or not
- *
- * @param handle : handle
- * @param interface : Target interface
- *
- * @return TRUE When Valid
- * FALSE When Error
- *****************************************************************************
- * This function checks whether the interface is valid or not
- *****************************************************************************/
-bool USB_Desc_Valid_Interface
-(
- uint32_t handle, /*[IN] Controller ID */
- uint8_t interface /*[IN] Target interface */
-)
-{
- uint8_t loop_index=0;
- UNUSED_ARGUMENT(handle)
- /* check with only supported val right now */
- while(loop_index < USB_MAX_SUPPORTED_INTERFACES) {
- if(interface == g_alternate_interface[loop_index]) {
- return TRUE;
- }
- loop_index++;
- }
- return FALSE;
-}
-/**************************************************************************//*!
- *
- * @name USB_Desc_Remote_Wakeup
- *
- * @brief The function checks whether the remote wakeup is supported or not
- *
- * @param handle : handle
- *
- * @return REMOTE_WAKEUP_SUPPORT (TRUE) - If remote wakeup supported
- *****************************************************************************
- * This function returns remote wakeup is supported or not
- *****************************************************************************/
-bool USB_Desc_Remote_Wakeup(uint32_t handle /* [IN] Controller ID */) {
- return USBCFG_DEV_REMOTE_WAKEUP;
-}
-
-/* ****************************************************************************
- * Local available
- * Stock Array value of Parameter controller
- ******************************************************************************/
-
-/**************************************************************************//*!
- *
- * @name USB_Set_Configuration
- *
- * @brief The function set the configuration value of device
- *
- *
- * @param handle handle
- * @param config_val configuration value
- *
- * @return TRUE When Valid
- * FALSE When Error
- *****************************************************************************/
-uint8_t USB_Set_Configuration(audio_handle_t handle, uint8_t config) {
- return USB_OK; /* It's that simple since the device only has one configuration. */
-}
-
-/**************************************************************************//*!
- *
- * @name USB_Desc_Get_Entity
- *
- * @brief The function retrieves the entity specified by type.
- *
- * @param handle handle
- *
- * @return USB_OK - if success
- *****************************************************************************/
-uint8_t USB_Desc_Get_Entity(audio_handle_t handle, entity_type type, uint32_t *object)
-{
- switch (type) {
- case USB_CLASS_INFO:
- break;
- case USB_CLASS_INTERFACE_INDEX_INFO:
- *object = 0xff;
- if (handle == (uint32_t)g_composite_device.hid_keyboard.app_handle) {
- *object = (uint32_t)HID_KEYBOARD_INTERFACE_INDEX;
- break;
- } else if (handle == (uint32_t)g_composite_device.hid_mouse.app_handle) {
- *object = (uint32_t)HID_MOUSE_INTERFACE_INDEX;
- break;
- }
- break;
- case USB_COMPOSITE_INFO:
- keyboard_interface[0].index = 0;
- keyboard_interface[0].endpoints = keyboard_endpoints;
- mouse_interface[0].index = 1;
- mouse_interface[0].endpoints = mouse_endpoints;
- *object = (unsigned long)&usb_composite_info;
- break;
- default:
- break;
- }
- return USB_OK;
-
-}
-
-/**************************************************************************//*!
- *
- * @name USB_Desc_Set_Speed
- *
- * @brief The function is used to set device speed
- *
- * @param handle: handle
- * @param speed: speed
- *
- * @return USB_OK When Success
- * USBERR_INVALID_REQ_TYPE when Error
- *****************************************************************************/
-uint8_t USB_Desc_Set_Speed(uint32_t handle, uint16_t speed) {
- descriptor_union_t ptr1, ptr2;
-
- ptr1.pntr = g_config_descriptor;
- ptr2.pntr = g_config_descriptor + sizeof(g_config_descriptor);
-
- if (handle == g_composite_device.hid_keyboard.app_handle) {
- while (ptr1.word < ptr2.word) {
- if (ptr1.common->bDescriptorType == USB_DESC_TYPE_EP) {
- if (USB_SPEED_HIGH == speed) {
- ptr1.ndpt->iInterval = HS_INTERRUPT_OUT_ENDP_INTERVAL;
- ptr1.ndpt->wMaxPacketSize[0] = USB_uint_16_low(HS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- ptr1.ndpt->wMaxPacketSize[1] = USB_uint_16_high(HS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- } else {
- ptr1.ndpt->iInterval = FS_INTERRUPT_OUT_ENDP_INTERVAL;
- ptr1.ndpt->wMaxPacketSize[0] = USB_uint_16_low(FS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- ptr1.ndpt->wMaxPacketSize[1] = USB_uint_16_high(FS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- }
- }
- ptr1.word += ptr1.common->bLength;
- }
-
- for (int i = 0; i < HID_DESC_ENDPOINT_COUNT; i++) {
- if (USB_SPEED_HIGH == speed) {
- keyboard_endpoint[i].size = HS_INTERRUPT_OUT_ENDP_PACKET_SIZE;
- } else {
- keyboard_endpoint[i].size = FS_INTERRUPT_OUT_ENDP_PACKET_SIZE;
- }
- }
- } else if (handle == g_composite_device.hid_mouse.app_handle) {
- while (ptr1.word < ptr2.word) {
- if (ptr1.common->bDescriptorType == USB_DESC_TYPE_EP) {
- if ((ptr1.ndpt->bmAttributes & 0x03) == USB_INTERRUPT_PIPE) {
- if (USB_SPEED_HIGH == speed) {
- ptr1.ndpt->iInterval = HS_INTERRUPT_OUT_ENDP_INTERVAL;
- ptr1.ndpt->wMaxPacketSize[0] = USB_uint_16_low(HS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- ptr1.ndpt->wMaxPacketSize[1] = USB_uint_16_high(HS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- } else {
- ptr1.ndpt->iInterval = FS_INTERRUPT_OUT_ENDP_INTERVAL;
- ptr1.ndpt->wMaxPacketSize[0] = USB_uint_16_low(FS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- ptr1.ndpt->wMaxPacketSize[1] = USB_uint_16_high(FS_INTERRUPT_OUT_ENDP_PACKET_SIZE);
- }
- }
- }
- ptr1.word += ptr1.common->bLength;
- }
-
- for (int i = 0; i < HID_DESC_ENDPOINT_COUNT; i++) {
- if (USB_SPEED_HIGH == speed) {
- mouse_endpoint[i].size = HS_INTERRUPT_OUT_ENDP_PACKET_SIZE;
- } else {
- mouse_endpoint[i].size = FS_INTERRUPT_OUT_ENDP_PACKET_SIZE;
- }
- }
- }
-
- return USB_OK;
-}
-
-usb_desc_request_notify_struct_t desc_callback =
-{
- USB_Desc_Get_Descriptor,
- USB_Desc_Get_Interface,
- USB_Desc_Set_Interface,
- USB_Set_Configuration,
- USB_Desc_Get_Entity
-};
diff --git a/right/usb_descriptor.h b/right/usb_descriptor.h
deleted file mode 100644
index 1fef9a8..0000000
--- a/right/usb_descriptor.h
+++ /dev/null
@@ -1,98 +0,0 @@
-#ifndef _USB_DESCRIPTOR_H
-#define _USB_DESCRIPTOR_H
-
-/* Includes: */
-
- #include "usb_class_audio.h"
- #include "usb_device_stack_interface.h"
- #include "usb_class_composite.h"
- #include "usb_class_hid.h"
-
-/* Macro definitions: */
-
- #define BCD_USB_VERSION (0x0200)
-
- /* descriptors codes */
- #define USB_DEVICE_DESCRIPTOR (1)
- #define USB_CONFIG_DESCRIPTOR (2)
- #define USB_STRING_DESCRIPTOR (3)
- #define USB_IFACE_DESCRIPTOR (4)
- #define USB_ENDPOINT_DESCRIPTOR (5)
-
- /* Various descriptor sizes */
- #define DEVICE_DESCRIPTOR_SIZE (18)
- #define CONFIG_DESC_SIZE (59)
- #define DEVICE_QUALIFIER_DESCRIPTOR_SIZE (10)
- #define KEYBOARD_REPORT_DESC_SIZE (63)
- #define MOUSE_REPORT_DESC_SIZE (52)
-
- #define CONFIG_ONLY_DESC_SIZE (9)
- #define IFACE_ONLY_DESC_SIZE (9)
- #define ENDP_ONLY_DESC_SIZE (7)
- #define HEADER_ONLY_DESC_SIZE (9)
- #define INPUT_TERMINAL_ONLY_DESC_SIZE (12)
- #define OUTPUT_TERMINAL_ONLY_DESC_SIZE (9)
- #define FEATURE_UNIT_ONLY_DESC_SIZE (9)
-
- /* Max descriptors provided by the Application */
- #define USB_MAX_STD_DESCRIPTORS (8)
- #define USB_MAX_CLASS_SPECIFIC_DESCRIPTORS (2)
- /* Max configuration supported by the Application */
- #define USB_MAX_CONFIG_SUPPORTED (1)
-
- /* Max string descriptors supported by the Application */
- #define USB_MAX_STRING_DESCRIPTORS (4)
-
- /* Max language codes supported by the USB */
- #define USB_MAX_LANGUAGES_SUPPORTED (1)
-
- #define HS_ISO_OUT_ENDP_PACKET_SIZE (8)
- #define FS_ISO_OUT_ENDP_PACKET_SIZE (8)
- #define HS_ISO_OUT_ENDP_INTERVAL (0x04)
- #define FS_ISO_OUT_ENDP_INTERVAL (0x01)
-
- /* string descriptors sizes */
- #define USB_STR_DESC_SIZE (2)
- #define USB_STR_0_SIZE (2)
- #define USB_STR_1_SIZE (56)
- #define USB_STR_2_SIZE (36)
- #define USB_STR_n_SIZE (32)
-
- /* descriptors codes */
- #define USB_DEVICE_DESCRIPTOR (1)
- #define USB_CONFIG_DESCRIPTOR (2)
- #define USB_STRING_DESCRIPTOR (3)
- #define USB_IFACE_DESCRIPTOR (4)
- #define USB_ENDPOINT_DESCRIPTOR (5)
- #define USB_DEVQUAL_DESCRIPTOR (6)
- #define USB_REPORT_DESCRIPTOR (0x22)
-
- #define USB_MAX_SUPPORTED_INTERFACES (1)
- #define USB_MAX_SUPPORTED_LANGUAGES (1)
- #define CONTROL_MAX_PACKET_SIZE (64)
-
- #define HID_DESC_ENDPOINT_COUNT (1)
- #define HID_ENDPOINT (2)
- #define HID_DESC_INTERFACE_COUNT (1)
- #define HID_ONLY_DESC_SIZE (9)
- #define USB_HID_DESCRIPTOR (0x21)
- #define USB_REPORT_DESCRIPTOR (0x22)
- #define HS_INTERRUPT_OUT_ENDP_PACKET_SIZE (8)
- #define FS_INTERRUPT_OUT_ENDP_PACKET_SIZE (8)
- #define HS_INTERRUPT_OUT_ENDP_INTERVAL (0x07) /* 2^(7-1) = 8ms */
- #define FS_INTERRUPT_OUT_ENDP_INTERVAL (0x08)
-
-/* Function prototypes: */
-
- uint8_t USB_Desc_Get_Descriptor(uint32_t handle, uint8_t type, uint8_t str_num, uint16_t index, uint8_t** descriptor, uint32_t *size);
- uint8_t USB_Desc_Get_Interface(uint32_t handle, uint8_t interface, uint8_t* alt_interface);
-
- uint8_t USB_Desc_Set_Interface(uint32_t handle, uint8_t interface, uint8_t alt_interface);
- bool USB_Desc_Valid_Configation(uint32_t handle, uint16_t config_val);
- bool USB_Desc_Valid_Interface(uint32_t handle, uint8_t interface);
- bool USB_Desc_Remote_Wakeup(uint32_t handle);
-
- usb_endpoints_t* USB_Desc_Get_Endpoints(uint32_t handle);
- uint8_t USB_Desc_Set_Speed(uint32_t handle, uint16_t speed);
-
-#endif
diff --git a/right/usb_device_config.h b/right/usb_device_config.h
new file mode 100644
index 0000000..2818a88
--- /dev/null
+++ b/right/usb_device_config.h
@@ -0,0 +1,43 @@
+#ifndef _USB_DEVICE_CONFIG_H_
+#define _USB_DEVICE_CONFIG_H_
+
+/*! @brief KHCI instance count */
+#define USB_DEVICE_CONFIG_KHCI (1U)
+
+/*! @brief Device instance count, the sum of KHCI and EHCI instance counts*/
+#define USB_DEVICE_CONFIG_NUM (1U)
+
+/*! @brief HID instance count */
+#define USB_DEVICE_CONFIG_HID (2U)
+
+/*! @brief Whether device is self power. 1U supported, 0U not supported */
+#define USB_DEVICE_CONFIG_SELF_POWER (1U)
+
+/*! @brief Whether device remote wakeup supported. 1U supported, 0U not supported */
+#define USB_DEVICE_CONFIG_REMOTE_WAKEUP (0U)
+
+/*! @brief How many endpoints are supported in the stack. */
+#define USB_DEVICE_CONFIG_ENDPOINTS (4U)
+
+/*! @brief How many the notification message are supported when the device task enabled. */
+#define USB_DEVICE_CONFIG_MAX_MESSAGES (8U)
+
+/*! @brief The MAX buffer length for the KHCI DMA workaround.*/
+#define USB_DEVICE_CONFIG_KHCI_DMA_ALIGN_BUFFER_LENGTH (64U)
+
+/*! @brief Whether handle the USB KHCI bus error. */
+#define USB_DEVICE_CONFIG_KHCI_ERROR_HANDLING (0U)
+
+/*! @brief Whether the keep alive feature enabled. */
+#define USB_DEVICE_CONFIG_KEEP_ALIVE_MODE (0U)
+
+/*! @brief Whether the transfer buffer is cache-enabled or not. */
+#define USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE (0U)
+
+/*! @brief Whether the low power mode is enabled or not. */
+#define USB_DEVICE_CONFIG_LOW_POWER_MODE (0U)
+
+/*! @brief Whether the device detached feature is enabled or not. */
+#define USB_DEVICE_CONFIG_DETACH_ENABLE (0U)
+
+#endif
diff --git a/right/usb_device_descriptor.c b/right/usb_device_descriptor.c
new file mode 100644
index 0000000..c7291ea
--- /dev/null
+++ b/right/usb_device_descriptor.c
@@ -0,0 +1,567 @@
+#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_device_descriptor.h"
+#include "composite.h"
+#include "hid_mouse.h"
+#include "hid_keyboard.h"
+
+// HID keyboard endpoint
+usb_device_endpoint_struct_t g_UsbDeviceHidKeyboardEndpoints[USB_HID_KEYBOARD_ENDPOINT_COUNT] = {
+ /* HID keyboard interrupt IN pipe */
+ {
+ USB_HID_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
+ USB_ENDPOINT_INTERRUPT, FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
+ },
+};
+
+// HID keyboard interface
+usb_device_interface_struct_t g_UsbDeviceHidKeyboardInterface[] = {
+ {
+ 0U, // The alternate setting of the interface
+ {
+ USB_HID_KEYBOARD_ENDPOINT_COUNT,
+ g_UsbDeviceHidKeyboardEndpoints,
+ },
+ NULL,
+ }
+};
+
+usb_device_interfaces_struct_t g_UsbDeviceHidKeyboardInterfaces[USB_HID_KEYBOARD_INTERFACE_COUNT] = {
+ {
+ USB_HID_KEYBOARD_CLASS,
+ USB_HID_KEYBOARD_SUBCLASS,
+ USB_HID_KEYBOARD_PROTOCOL,
+ USB_HID_KEYBOARD_INTERFACE_INDEX,
+ g_UsbDeviceHidKeyboardInterface,
+ sizeof(g_UsbDeviceHidKeyboardInterface) / sizeof(usb_device_interfaces_struct_t),
+ },
+};
+
+usb_device_interface_list_t g_UsbDeviceHidKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {
+ {
+ USB_HID_KEYBOARD_INTERFACE_COUNT,
+ g_UsbDeviceHidKeyboardInterfaces,
+ },
+};
+
+usb_device_class_struct_t g_UsbDeviceHidKeyboardConfig = {
+ g_UsbDeviceHidKeyboardInterfaceList,
+ kUSB_DeviceClassTypeHid,
+ USB_DEVICE_CONFIGURATION_COUNT,
+};
+
+// HID mouse endpoint
+usb_device_endpoint_struct_t g_UsbDeviceHidMouseEndpoints[USB_HID_MOUSE_ENDPOINT_COUNT] = {
+ // HID mouse interrupt IN pipe
+ {
+ USB_HID_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), USB_ENDPOINT_INTERRUPT,
+ FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE,
+ },
+};
+
+// HID mouse interface information
+usb_device_interface_struct_t g_UsbDeviceHidMouseInterface[] = {{
+ 0U, // The alternate setting of the interface
+ {
+ USB_HID_MOUSE_ENDPOINT_COUNT,
+ g_UsbDeviceHidMouseEndpoints,
+ },
+ NULL,
+}};
+
+usb_device_interfaces_struct_t g_UsbDeviceHidMouseInterfaces[USB_HID_MOUSE_INTERFACE_COUNT] = {
+ {
+ USB_HID_MOUSE_CLASS,
+ USB_HID_MOUSE_SUBCLASS,
+ USB_HID_MOUSE_PROTOCOL,
+ USB_HID_MOUSE_INTERFACE_INDEX,
+ g_UsbDeviceHidMouseInterface,
+ sizeof(g_UsbDeviceHidMouseInterface) / sizeof(usb_device_interfaces_struct_t),
+ },
+};
+
+usb_device_interface_list_t g_UsbDeviceHidMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {
+ {
+ USB_HID_MOUSE_INTERFACE_COUNT,
+ g_UsbDeviceHidMouseInterfaces,
+ },
+};
+
+usb_device_class_struct_t g_UsbDeviceHidMouseConfig = {
+ g_UsbDeviceHidMouseInterfaceList,
+ kUSB_DeviceClassTypeHid,
+ USB_DEVICE_CONFIGURATION_COUNT,
+};
+
+uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = {
+ USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */
+ USB_DESCRIPTOR_TYPE_DEVICE, /* DEVICE Descriptor Type */
+ USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION),
+ USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* USB Specification Release Number in
+ Binary-Coded Decimal (i.e., 2.10 is 210H). */
+ USB_DEVICE_CLASS, /* Class code (assigned by the USB-IF). */
+ USB_DEVICE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */
+ USB_DEVICE_PROTOCOL, /* Protocol code (assigned by the USB-IF). */
+ USB_CONTROL_MAX_PACKET_SIZE, /* Maximum packet size for endpoint zero
+ (only 8, 16, 32, or 64 are valid) */
+ 0xA2U, 0x15U, /* Vendor ID (assigned by the USB-IF) */
+ 0x7EU, 0x00U, /* Product ID (assigned by the manufacturer) */
+ USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION),
+ USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Device release number in binary-coded decimal */
+ 0x01U, /* Index of string descriptor describing manufacturer */
+ 0x02U, /* Index of string descriptor describing product */
+ 0x00U, /* Index of string descriptor describing the
+ device's serial number */
+ USB_DEVICE_CONFIGURATION_COUNT, /* Number of possible configurations */
+};
+
+uint8_t g_UsbDeviceConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = {
+ USB_DESCRIPTOR_LENGTH_CONFIGURE, /* Size of this descriptor in bytes */
+ USB_DESCRIPTOR_TYPE_CONFIGURE, /* CONFIGURATION Descriptor Type */
+ USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL),
+ USB_SHORT_GET_HIGH(
+ USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL), /* Total length of data returned for this configuration. */
+ USB_COMPOSITE_INTERFACE_COUNT, /* Number of interfaces supported by this configuration */
+ USB_COMPOSITE_CONFIGURE_INDEX, /* Value to use as an argument to the
+ SetConfiguration() request to select this configuration */
+ 0x00U, /* Index of string descriptor describing this configuration */
+ (USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) |
+ (USB_DEVICE_CONFIG_SELF_POWER << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT) |
+ (USB_DEVICE_CONFIG_REMOTE_WAKEUP << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT),
+ /* Configuration characteristics
+ D7: Reserved (set to one)
+ D6: Self-powered
+ D5: Remote Wakeup
+ D4...0: Reserved (reset to zero)
+ */
+ USB_DEVICE_MAX_POWER, /* Maximum power consumption of the USB
+ * device from the bus in this specific
+ * configuration when the device is fully
+ * operational. Expressed in 2 mA units
+ * (i.e., 50 = 100 mA).
+ */
+ USB_DESCRIPTOR_LENGTH_INTERFACE, /* Size of this descriptor in bytes */
+ USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */
+ USB_HID_MOUSE_INTERFACE_INDEX, /* Number of this interface. */
+ 0x00U, /* Value used to select this alternate setting
+ for the interface identified in the prior field */
+ USB_HID_MOUSE_ENDPOINT_COUNT, /* Number of endpoints used by this
+ interface (excluding endpoint zero). */
+ USB_HID_MOUSE_CLASS, /* Class code (assigned by the USB-IF). */
+ USB_HID_MOUSE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */
+ USB_HID_MOUSE_PROTOCOL, /* Protocol code (assigned by the USB). */
+ 0x03U, /* Index of string descriptor describing this interface */
+
+ USB_DESCRIPTOR_LENGTH_HID, /* Numeric expression that is the total size of the
+ HID descriptor. */
+ USB_DESCRIPTOR_TYPE_HID, /* Constant name specifying type of HID
+ descriptor. */
+ 0x00U, 0x01U, /* Numeric expression identifying the HID Class
+ Specification release. */
+ 0x00U, /* Numeric expression identifying country code of
+ the localized hardware */
+ 0x01U, /* Numeric expression specifying the number of
+ class descriptors(at least one report descriptor) */
+ USB_DESCRIPTOR_TYPE_HID_REPORT, /* Constant name identifying type of class descriptor. */
+ USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT),
+ USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT),
+ /* Numeric expression that is the total size of the
+ Report descriptor. */
+ USB_DESCRIPTOR_LENGTH_ENDPOINT, /* Size of this descriptor in bytes */
+ USB_DESCRIPTOR_TYPE_ENDPOINT, /* ENDPOINT Descriptor Type */
+ USB_HID_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
+ /* The address of the endpoint on the USB device
+ described by this descriptor. */
+ USB_ENDPOINT_INTERRUPT, /* This field describes the endpoint's attributes */
+ USB_SHORT_GET_LOW(FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE), USB_SHORT_GET_HIGH(FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE),
+ /* Maximum packet size this endpoint is capable of
+ sending or receiving when this configuration is
+ selected. */
+ FS_HID_MOUSE_INTERRUPT_IN_INTERVAL, /* Interval for polling endpoint for data transfers. */
+
+ USB_DESCRIPTOR_LENGTH_INTERFACE, /* Size of this descriptor in bytes */
+ USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */
+ USB_HID_KEYBOARD_INTERFACE_INDEX, /* Number of this interface. */
+ 0x00U, /* Value used to select this alternate setting
+ for the interface identified in the prior field */
+ USB_HID_KEYBOARD_ENDPOINT_COUNT, /* Number of endpoints used by this
+ interface (excluding endpoint zero). */
+ USB_HID_KEYBOARD_CLASS, /* Class code (assigned by the USB-IF). */
+ USB_HID_KEYBOARD_SUBCLASS, /* Subclass code (assigned by the USB-IF). */
+ USB_HID_KEYBOARD_PROTOCOL, /* Protocol code (assigned by the USB). */
+ 0x04U, /* Index of string descriptor describing this interface */
+
+ USB_DESCRIPTOR_LENGTH_HID, /* Numeric expression that is the total size of the
+ HID descriptor. */
+ USB_DESCRIPTOR_TYPE_HID, /* Constant name specifying type of HID
+ descriptor. */
+ 0x00U, 0x01U, /* Numeric expression identifying the HID Class
+ Specification release. */
+ 0x00U, /* Numeric expression identifying country code of
+ the localized hardware */
+ 0x01U, /* Numeric expression specifying the number of
+ class descriptors(at least one report descriptor) */
+ USB_DESCRIPTOR_TYPE_HID_REPORT, /* Constant name identifying type of class descriptor. */
+ USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT),
+ USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT),
+ /* Numeric expression that is the total size of the
+ Report descriptor. */
+ USB_DESCRIPTOR_LENGTH_ENDPOINT, /* Size of this descriptor in bytes */
+ USB_DESCRIPTOR_TYPE_ENDPOINT, /* ENDPOINT Descriptor Type */
+ USB_HID_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
+ /* The address of the endpoint on the USB device
+ described by this descriptor. */
+ USB_ENDPOINT_INTERRUPT, /* This field describes the endpoint's attributes */
+ USB_SHORT_GET_LOW(FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
+ USB_SHORT_GET_HIGH(FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
+ /* Maximum packet size this endpoint is capable of
+ sending or receiving when this configuration is
+ selected. */
+ FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL, /* Interval for polling endpoint for data transfers. */
+};
+
+uint8_t g_UsbDeviceHidMouseReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT] = {
+ 0x05U, 0x01U, /* Usage Page (Generic Desktop)*/
+ 0x09U, 0x02U, /* Usage (Mouse) */
+ 0xA1U, 0x01U, /* Collection (Application) */
+ 0x09U, 0x01U, /* Usage (Pointer) */
+
+ 0xA1U, 0x00U, /* Collection (Physical) */
+ 0x05U, 0x09U, /* Usage Page (Buttons) */
+ 0x19U, 0x01U, /* Usage Minimum (01U) */
+ 0x29U, 0x03U, /* Usage Maximum (03U) */
+
+ 0x15U, 0x00U, /* logical Minimum (0U) */
+ 0x25U, 0x01U, /* logical Maximum (1U) */
+ 0x95U, 0x03U, /* Report Count (3U) */
+ 0x75U, 0x01U, /* Report Size (1U) */
+
+ 0x81U, 0x02U, /* Input(Data, Variable, Absolute) 3U button bit fields */
+ 0x95U, 0x01U, /* Report count (1U) */
+ 0x75U, 0x05U, /* Report Size (5U) */
+ 0x81U, 0x01U, /* Input (Constant), 5U constant field */
+
+ 0x05U, 0x01U, /* Usage Page (Generic Desktop) */
+ 0x09U, 0x30U, /* Usage (X) */
+ 0x09U, 0x31U, /* Usage (Y) */
+ 0x09U, 0x38U, /* Usage (Z) */
+
+ 0x15U, 0x81U, /* Logical Minimum (-127) */
+ 0x25U, 0x7FU, /* Logical Maximum (127) */
+ 0x75U, 0x08U, /* Report Size (8U) */
+ 0x95U, 0x03U, /* Report Count (3U) */
+
+ 0x81U, 0x06U, /* Input(Data, Variable, Relative), three position bytes (X & Y & Z)*/
+ 0xC0U, /* end collection, Close Pointer collection*/
+ 0xC0U /* end collection, Close Mouse collection */
+};
+
+/* HID keyboard report descriptor */
+uint8_t g_UsbDeviceHidKeyboardReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT] = {
+ 0x05U, 0x01U, /* Usage Page (Generic Desktop)*/
+ 0x09U, 0x06U, /* Usage (Keyboard) */
+ 0xA1U, 0x01U, /* Collection (Application) */
+ 0x75U, 0x01U, /* Report Size (1U) */
+ 0x95U, 0x08U, /* Report Count (8U) */
+ 0x05U, 0x07U, /* Usage Page (Key Codes) */
+ 0x19U, 0xE0U, /* Usage Minimum (224U) */
+ 0x29U, 0xE7U, /* Usage Maximum (231U) */
+
+ 0x15U, 0x00U, /* Logical Minimum (0U) */
+ 0x25U, 0x01U, /* Logical Maximum (1U) */
+ 0x81U, 0x02U, /* Input(Data, Variable, Absolute) Modifier byte */
+
+ 0x95U, 0x01U, /* Report count (1U) */
+ 0x75U, 0x08U, /* Report Size (8U) */
+ 0x81U, 0x01U, /* Input (Constant), Reserved byte */
+ 0x95U, 0x05U, /* Report count (5U) */
+ 0x75U, 0x01U, /* Report Size (1U) */
+
+ 0x05U, 0x01U, /* Usage Page (Page# for LEDs) */
+ 0x19U, 0x01U, /* Usage Minimum (1U) */
+ 0x29U, 0x05U, /* Usage Maximum (5U) */
+ 0x91U, 0x02U, /* Output (Data, Variable, Absolute) LED report */
+ 0x95U, 0x01U, /* Report count (1U) */
+ 0x75U, 0x03U, /* Report Size (3U) */
+ 0x91U, 0x01U, /* Output (Constant), LED report padding */
+
+ 0x95U, 0x06U, /* Report count (6U) */
+ 0x75U, 0x08U, /* Report Size (8U) */
+ 0x15U, 0x00U, /* logical Minimum (0U) */
+ 0x25U, 0xFFU, /* logical Maximum (255U) */
+ 0x05U, 0x07U, /* Usage Page (Key Codes) */
+ 0x19U, 0x00U, /* Usage Minimum (0U) */
+ 0x29U, 0xFFU, /* Usage Maximum (255U) */
+
+ 0x81U, 0x00U, /* Input(Data, Array), Key arrays(6U bytes)*/
+ 0xC0U, /* end collection */
+};
+
+uint8_t g_UsbDeviceString0[USB_DESCRIPTOR_LENGTH_STRING0] = {
+ sizeof(g_UsbDeviceString0), USB_DESCRIPTOR_TYPE_STRING, 0x09U, 0x04U,
+};
+
+uint8_t g_UsbDeviceString1[USB_DESCRIPTOR_LENGTH_STRING1] = {
+ sizeof(g_UsbDeviceString1),
+ 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 g_UsbDeviceString2[USB_DESCRIPTOR_LENGTH_STRING2] = {
+ sizeof(g_UsbDeviceString2),
+ 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,
+};
+
+uint8_t g_UsbDeviceString3[USB_DESCRIPTOR_LENGTH_STRING3] = {
+ sizeof(g_UsbDeviceString3),
+ USB_DESCRIPTOR_TYPE_STRING,
+ 'H', 0x00U,
+ 'I', 0x00U,
+ 'D', 0x00U,
+ ' ', 0x00U,
+ 'M', 0x00U,
+ 'O', 0x00U,
+ 'U', 0x00U,
+ 'S', 0x00U,
+ 'E', 0x00U,
+ ' ', 0x00U,
+ 'D', 0x00U,
+ 'E', 0x00U,
+ 'V', 0x00U,
+ 'I', 0x00U,
+ 'C', 0x00U,
+ 'E', 0x00U,
+};
+
+uint8_t g_UsbDeviceString4[USB_DESCRIPTOR_LENGTH_STRING4] = {
+ sizeof(g_UsbDeviceString4),
+ USB_DESCRIPTOR_TYPE_STRING,
+ 'H', 0x00U,
+ 'I', 0x00U,
+ 'D', 0x00U,
+ ' ', 0x00U,
+ 'K', 0x00U,
+ 'E', 0x00U,
+ 'Y', 0x00U,
+ 'B', 0x00U,
+ 'O', 0x00U,
+ 'A', 0x00U,
+ 'R', 0x00U,
+ 'D', 0x00U,
+ ' ', 0x00U,
+ 'D', 0x00U,
+ 'E', 0x00U,
+ 'V', 0x00U,
+ 'I', 0x00U,
+ 'C', 0x00U,
+ 'E', 0x00U,
+};
+
+uint32_t g_UsbDeviceStringDescriptorLength[USB_DEVICE_STRING_COUNT] = {
+ sizeof(g_UsbDeviceString0), sizeof(g_UsbDeviceString1), sizeof(g_UsbDeviceString2),
+ sizeof(g_UsbDeviceString3), sizeof(g_UsbDeviceString4),
+};
+
+uint8_t *g_UsbDeviceStringDescriptorArray[USB_DEVICE_STRING_COUNT] = {
+ g_UsbDeviceString0, g_UsbDeviceString1, g_UsbDeviceString2, g_UsbDeviceString3, g_UsbDeviceString4,
+};
+
+usb_language_t g_UsbDeviceLanguage[USB_DEVICE_LANGUAGE_COUNT] = {{
+ g_UsbDeviceStringDescriptorArray, g_UsbDeviceStringDescriptorLength, (uint16_t)0x0409U,
+}};
+
+usb_language_list_t g_UsbDeviceLanguageList = {
+ g_UsbDeviceString0, sizeof(g_UsbDeviceString0), g_UsbDeviceLanguage, USB_DEVICE_LANGUAGE_COUNT,
+};
+
+usb_status_t USB_DeviceGetDeviceDescriptor(usb_device_handle handle,
+ usb_device_get_device_descriptor_struct_t *deviceDescriptor)
+{
+ deviceDescriptor->buffer = g_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)
+{
+ if (USB_COMPOSITE_CONFIGURE_INDEX > configurationDescriptor->configuration) {
+ configurationDescriptor->buffer = g_UsbDeviceConfigurationDescriptor;
+ configurationDescriptor->length = USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL;
+ return kStatus_USB_Success;
+ }
+ 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 = (uint8_t *)g_UsbDeviceLanguageList.languageString;
+ stringDescriptor->length = g_UsbDeviceLanguageList.stringLength;
+ } else {
+ uint8_t languageId = 0U;
+ uint8_t languageIndex = USB_DEVICE_STRING_COUNT;
+
+ for (; languageId < USB_DEVICE_STRING_COUNT; languageId++) {
+ if (stringDescriptor->languageId == g_UsbDeviceLanguageList.languageList[languageId].languageId) {
+ if (stringDescriptor->stringIndex < USB_DEVICE_STRING_COUNT) {
+ languageIndex = stringDescriptor->stringIndex;
+ }
+ break;
+ }
+ }
+
+ if (USB_DEVICE_STRING_COUNT == languageIndex) {
+ return kStatus_USB_InvalidRequest;
+ }
+ stringDescriptor->buffer = (uint8_t *)g_UsbDeviceLanguageList.languageList[languageId].string[languageIndex];
+ stringDescriptor->length = g_UsbDeviceLanguageList.languageList[languageId].length[languageIndex];
+ }
+ return kStatus_USB_Success;
+}
+
+usb_status_t USB_DeviceGetHidDescriptor(usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor)
+{
+ return kStatus_USB_InvalidRequest;
+}
+
+usb_status_t USB_DeviceGetHidReportDescriptor(usb_device_handle handle,
+ usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor)
+{
+ if (USB_HID_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
+ hidReportDescriptor->buffer = g_UsbDeviceHidMouseReportDescriptor;
+ hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT;
+ } else if (USB_HID_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
+ hidReportDescriptor->buffer = g_UsbDeviceHidKeyboardReportDescriptor;
+ hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT;
+ } else {
+ return kStatus_USB_InvalidRequest;
+ }
+ return kStatus_USB_Success;
+}
+
+usb_status_t USB_DeviceGetHidPhysicalDescriptor(usb_device_handle handle,
+ usb_device_get_hid_physical_descriptor_struct_t *hidPhysicalDescriptor)
+{
+ return kStatus_USB_InvalidRequest;
+}
+
+/* Due to the difference of HS and FS descriptors, the device descriptors and configurations need to be updated to match
+ * current speed.
+ * As the default, the device descriptors and configurations are configured by using FS parameters for both EHCI and
+ * KHCI.
+ * When the EHCI is enabled, the application needs to call this function to update device by using current speed.
+ * The updated information includes endpoint max packet size, endpoint interval, etc. */
+usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed)
+{
+ usb_descriptor_union_t *descriptorHead;
+ usb_descriptor_union_t *descriptorTail;
+
+ descriptorHead = (usb_descriptor_union_t *)&g_UsbDeviceConfigurationDescriptor[0];
+ descriptorTail =
+ (usb_descriptor_union_t *)(&g_UsbDeviceConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL - 1U]);
+
+ while (descriptorHead < descriptorTail) {
+ if (descriptorHead->common.bDescriptorType == USB_DESCRIPTOR_TYPE_ENDPOINT) {
+ if (USB_SPEED_HIGH == speed) {
+ if (((descriptorHead->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) ==
+ USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
+ (USB_HID_MOUSE_ENDPOINT_IN ==
+ (descriptorHead->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
+ {
+ descriptorHead->endpoint.bInterval = HS_HID_MOUSE_INTERRUPT_IN_INTERVAL;
+ USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(HS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE,
+ descriptorHead->endpoint.wMaxPacketSize);
+ } else if (((descriptorHead->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) ==
+ USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
+ (USB_HID_KEYBOARD_ENDPOINT_IN ==
+ (descriptorHead->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
+ {
+ descriptorHead->endpoint.bInterval = HS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL;
+ USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(HS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
+ descriptorHead->endpoint.wMaxPacketSize);
+ }
+ } else {
+ if (((descriptorHead->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) ==
+ USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
+ (USB_HID_MOUSE_ENDPOINT_IN ==
+ (descriptorHead->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
+ {
+ descriptorHead->endpoint.bInterval = FS_HID_MOUSE_INTERRUPT_IN_INTERVAL;
+ USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE,
+ descriptorHead->endpoint.wMaxPacketSize);
+ } else if (((descriptorHead->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) ==
+ USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
+ (USB_HID_KEYBOARD_ENDPOINT_IN ==
+ (descriptorHead->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
+ {
+ descriptorHead->endpoint.bInterval = FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL;
+ USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
+ descriptorHead->endpoint.wMaxPacketSize);
+ }
+ }
+ }
+ descriptorHead = (usb_descriptor_union_t *)((uint8_t *)descriptorHead + descriptorHead->common.bLength);
+ }
+
+ if (USB_SPEED_HIGH == speed) {
+ g_UsbDeviceHidMouseEndpoints[0].maxPacketSize = HS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE;
+ } else {
+ g_UsbDeviceHidMouseEndpoints[0].maxPacketSize = FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE;
+ }
+
+ if (USB_SPEED_HIGH == speed) {
+ g_UsbDeviceHidKeyboardEndpoints[0].maxPacketSize = HS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE;
+ } else {
+ g_UsbDeviceHidKeyboardEndpoints[0].maxPacketSize = FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE;
+ }
+
+ return kStatus_USB_Success;
+}
diff --git a/right/usb_device_descriptor.h b/right/usb_device_descriptor.h
new file mode 100644
index 0000000..451057b
--- /dev/null
+++ b/right/usb_device_descriptor.h
@@ -0,0 +1,89 @@
+#ifndef __USB_DEVICE_DESCRIPTOR_H__
+#define __USB_DEVICE_DESCRIPTOR_H__
+
+/* Macros: */
+
+ #define USB_DEVICE_SPECIFIC_BCD_VERSION (0x0200U)
+ #define USB_DEVICE_DEMO_BCD_VERSION (0x0101U)
+
+ #define USB_DEVICE_CLASS (0x00U)
+ #define USB_DEVICE_SUBCLASS (0x00U)
+ #define USB_DEVICE_PROTOCOL (0x00U)
+
+ #define USB_DEVICE_MAX_POWER (0x32U)
+
+ #define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL (59U)
+ #define USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT (52U)
+ #define USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT (63U)
+ #define USB_DESCRIPTOR_LENGTH_HID (9U)
+ #define USB_DESCRIPTOR_LENGTH_STRING0 (4U)
+ #define USB_DESCRIPTOR_LENGTH_STRING1 (58U)
+ #define USB_DESCRIPTOR_LENGTH_STRING2 (34U)
+ #define USB_DESCRIPTOR_LENGTH_STRING3 (34U)
+ #define USB_DESCRIPTOR_LENGTH_STRING4 (40U)
+
+ #define USB_DEVICE_CONFIGURATION_COUNT (1U)
+ #define USB_DEVICE_STRING_COUNT (5U)
+ #define USB_DEVICE_LANGUAGE_COUNT (1U)
+
+ #define USB_COMPOSITE_CONFIGURE_INDEX (1U)
+
+ #define USB_HID_MOUSE_INTERFACE_COUNT (1U)
+ #define USB_HID_MOUSE_INTERFACE_INDEX (0U)
+ #define USB_HID_MOUSE_IN_BUFFER_LENGTH (8U)
+ #define USB_HID_MOUSE_ENDPOINT_COUNT (1U)
+ #define USB_HID_MOUSE_ENDPOINT_IN (1U)
+
+ #define USB_HID_MOUSE_REPORT_LENGTH (0x04U)
+
+ #define USB_HID_MOUSE_CLASS (0x03U)
+ #define USB_HID_MOUSE_SUBCLASS (0x01U)
+ #define USB_HID_MOUSE_PROTOCOL (0x02U)
+
+ #define HS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U)
+ #define FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U)
+ #define HS_HID_MOUSE_INTERRUPT_IN_INTERVAL (0x06U) /* 2^(6-1) = 4ms */
+ #define FS_HID_MOUSE_INTERRUPT_IN_INTERVAL (0x04U)
+
+ #define USB_HID_KEYBOARD_CLASS (0x03U)
+ #define USB_HID_KEYBOARD_SUBCLASS (0x01U)
+ #define USB_HID_KEYBOARD_PROTOCOL (0x01U)
+
+ #define USB_HID_KEYBOARD_INTERFACE_COUNT (1U)
+ #define USB_HID_KEYBOARD_INTERFACE_INDEX (1U)
+ #define USB_HID_KEYBOARD_IN_BUFFER_LENGTH (8U)
+ #define USB_HID_KEYBOARD_ENDPOINT_COUNT (1U)
+ #define USB_HID_KEYBOARD_ENDPOINT_IN (2U)
+
+ #define HS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U)
+ #define FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U)
+ #define HS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL (0x06U) /* 2^(6-1) = 4ms */
+ #define FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL (0x04U)
+
+ #define USB_HID_KEYBOARD_REPORT_LENGTH (0x08U)
+
+ #define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_KEYBOARD_INTERFACE_COUNT + USB_HID_MOUSE_INTERFACE_COUNT)
+
+/* Function prototypes: */
+
+ extern usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed);
+
+ usb_status_t USB_DeviceGetDeviceDescriptor(
+ usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor);
+
+ usb_status_t USB_DeviceGetConfigurationDescriptor(
+ usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor);
+
+ usb_status_t USB_DeviceGetStringDescriptor(
+ usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor);
+
+ usb_status_t USB_DeviceGetHidDescriptor(
+ usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor);
+
+ usb_status_t USB_DeviceGetHidReportDescriptor(
+ usb_device_handle handle, usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor);
+
+ usb_status_t USB_DeviceGetHidPhysicalDescriptor(
+ usb_device_handle handle, usb_device_get_hid_physical_descriptor_struct_t *hidPhysicalDescriptor);
+
+#endif