diff --git a/right/build/armgcc/CMakeLists.txt b/right/build/armgcc/CMakeLists.txt
new file mode 100644
index 0000000..a34a577
--- /dev/null
+++ b/right/build/armgcc/CMakeLists.txt
@@ -0,0 +1,221 @@
+INCLUDE(CMakeForceCompiler)
+
+# CROSS COMPILER SETTING
+SET(CMAKE_SYSTEM_NAME Generic)
+CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
+
+# THE VERSION NUMBER
+SET (Tutorial_VERSION_MAJOR 1)
+SET (Tutorial_VERSION_MINOR 0)
+
+# ENABLE ASM
+ENABLE_LANGUAGE(ASM)
+
+SET(CMAKE_STATIC_LIBRARY_PREFIX)
+SET(CMAKE_STATIC_LIBRARY_SUFFIX)
+
+SET(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
+SET(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)
+
+# KSDK DIRECTORY
+SET(KsdkDir $ENV{KSDK_DIR})
+
+# CURRENT DIRECTORY
+SET(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR})
+
+# DEBUG LINK FILE
+set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -T${KsdkDir}/platform/devices/MK22F51212/linker/gcc/MK22FN512xxx12_flash.ld -static")
+
+# RELEASE LINK FILE
+set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -T${KsdkDir}/platform/devices/MK22F51212/linker/gcc/MK22FN512xxx12_flash.ld -static")
+
+# DEBUG ASM FLAGS
+SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -g -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99")
+
+# DEBUG C FLAGS
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -Wno-format -fno-strict-aliasing -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -MMD -MP -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99")
+
+# DEBUG LD FLAGS
+SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -Xlinker --defsym=__ram_vector_table__=1 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -lm -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mthumb -mapcs -Xlinker --gc-sections -Xlinker -static -Xlinker -z -Xlinker muldefs -Xlinker --defsym=__stack_size__=0x1000 -Xlinker --defsym=__heap_size__=0x0400")
+
+# RELEASE ASM FLAGS
+SET(CMAKE_ASM_FLAGS_RELEASE "${CMAKE_ASM_FLAGS_RELEASE} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99")
+
+# RELEASE C FLAGS
+SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os -Wno-format -fno-strict-aliasing -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -MMD -MP -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99")
+
+# RELEASE LD FLAGS
+SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Xlinker --defsym=__ram_vector_table__=1 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -lm -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mthumb -mapcs -Xlinker --gc-sections -Xlinker -static -Xlinker -z -Xlinker muldefs -Xlinker --defsym=__stack_size__=0x1000 -Xlinker --defsym=__heap_size__=0x0400")
+
+# ASM MACRO
+SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -DDEBUG")
+
+# C MACRO
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG=1")
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCPU_MK22FN512VLH12")
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DFRDM_K22F")
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DFREEDOM")
+SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_DEBUG=0")
+SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DCPU_MK22FN512VLH12")
+SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DFRDM_K22F")
+SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DFREEDOM")
+
+# CXX MACRO
+
+# INCLUDE_DIRECTORIES
+IF(CMAKE_BUILD_TYPE MATCHES Debug)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/osa/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/rtos)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/utilities/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/CMSIS/Include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/devices)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/devices/MK22F51212/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/devices/MK22F51212/startup)
+ INCLUDE_DIRECTORIES(${KsdkDir}/examples/frdmk22f)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/adapter/sources)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/adapter/sources/sdk)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/include/MK22F51212)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/audio)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/cdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/common)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/composite)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/hid)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/include/config)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/msd)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/phdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/video)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/controller/khci)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/controller)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/hal)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/include/MK22F51212)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/audio)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/cdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/hid)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/hub)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/msd)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/phdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/printer)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/controller/khci)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/controller)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/sources/driver/khci)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/sources/driver/max3353/sdk)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/sources/otg)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/uart)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/gpio)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/pit)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/edma)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/hal/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/system/inc)
+ELSEIF(CMAKE_BUILD_TYPE MATCHES Release)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/osa/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/rtos)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/utilities/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/CMSIS/Include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/devices)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/devices/MK22F51212/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/devices/MK22F51212/startup)
+ INCLUDE_DIRECTORIES(${KsdkDir}/examples/frdmk22f)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/adapter/sources)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/adapter/sources/sdk)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/include/MK22F51212)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/audio)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/cdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/common)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/composite)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/hid)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/include/config)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/msd)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/phdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/classes/video)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/controller/khci)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/device/sources/controller)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/hal)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/include/MK22F51212)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/audio)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/cdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/hid)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/hub)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/msd)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/phdc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/classes/printer)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/controller/khci)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/host/sources/controller)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/sources/driver/khci)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/sources/driver/max3353/sdk)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/include)
+ INCLUDE_DIRECTORIES(${KsdkDir}/usb/usb_core/otg/sources/otg)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/uart)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/gpio)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/pit)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/drivers/src/edma)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/hal/inc)
+ INCLUDE_DIRECTORIES(${KsdkDir}/platform/system/inc)
+ENDIF()
+
+# ADD_EXECUTABLE
+ADD_EXECUTABLE(uhk-right
+ "${KsdkDir}/platform/utilities/src/fsl_misc_utilities.c"
+ "${KsdkDir}/platform/devices/MK22F51212/startup/gcc/startup_MK22F51212.S"
+ "${ProjDirPath}/../../audio_data.c"
+ "${ProjDirPath}/../../audio_generator.c"
+ "${ProjDirPath}/../../audio_generator.h"
+ "${ProjDirPath}/../../composite_app.c"
+ "${ProjDirPath}/../../composite_app.h"
+ "${ProjDirPath}/../../mouse.c"
+ "${ProjDirPath}/../../mouse.h"
+ "${ProjDirPath}/../../usb_descriptor.c"
+ "${ProjDirPath}/../../usb_descriptor.h"
+ "${ProjDirPath}/../../usb_request.c"
+ "${ProjDirPath}/../../usb_request.h"
+ "${ProjDirPath}/../../hardware_init.c"
+ "${KsdkDir}/examples/frdmk22f/gpio_pins.c"
+ "${KsdkDir}/examples/frdmk22f/gpio_pins.h"
+ "${KsdkDir}/examples/frdmk22f/pin_mux.c"
+ "${KsdkDir}/examples/frdmk22f/pin_mux.h"
+ "${KsdkDir}/examples/frdmk22f/board.h"
+ "${KsdkDir}/examples/frdmk22f/board.c"
+ "${KsdkDir}/platform/utilities/src/fsl_debug_console.c"
+ "${KsdkDir}/platform/utilities/inc/fsl_debug_console.h"
+ "${KsdkDir}/platform/utilities/src/print_scan.c"
+ "${KsdkDir}/platform/utilities/src/print_scan.h"
+ "${KsdkDir}/platform/devices/MK22F51212/startup/system_MK22F51212.c"
+ "${KsdkDir}/platform/devices/startup.c"
+ "${KsdkDir}/platform/devices/startup.h"
+)
+SET_TARGET_PROPERTIES(uhk-right PROPERTIES OUTPUT_NAME "uhk-right.elf")
+
+TARGET_LINK_LIBRARIES(uhk-right -Wl,--start-group)
+# LIBRARIES
+IF(CMAKE_BUILD_TYPE MATCHES Debug)
+ TARGET_LINK_LIBRARIES(uhk-right ${KsdkDir}/usb/usb_core/device/lib/bm/armgcc/MK22F51212/debug/libusbd_bm.a)
+ TARGET_LINK_LIBRARIES(uhk-right ${KsdkDir}/lib/ksdk_platform_lib/armgcc/K22F51212/debug/libksdk_platform.a)
+ELSEIF(CMAKE_BUILD_TYPE MATCHES Release)
+ TARGET_LINK_LIBRARIES(uhk-right ${KsdkDir}/usb/usb_core/device/lib/bm/armgcc/MK22F51212/release/libusbd_bm.a)
+ TARGET_LINK_LIBRARIES(uhk-right ${KsdkDir}/lib/ksdk_platform_lib/armgcc/K22F51212/release/libksdk_platform.a)
+ENDIF()
+
+# SYSTEM LIBRARIES
+TARGET_LINK_LIBRARIES(uhk-right m)
+TARGET_LINK_LIBRARIES(uhk-right c)
+TARGET_LINK_LIBRARIES(uhk-right gcc)
+TARGET_LINK_LIBRARIES(uhk-right nosys)
+TARGET_LINK_LIBRARIES(uhk-right -Wl,--end-group)
+
+# MAP FILE
+SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker -Map=debug/uhk-right.map")
+SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Xlinker -Map=release/uhk-right.map")
+
+# BIN AND HEX
+ADD_CUSTOM_COMMAND(TARGET uhk-right POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex ${EXECUTABLE_OUTPUT_PATH}/uhk-right.elf ${EXECUTABLE_OUTPUT_PATH}/uhk-right.hex)
+ADD_CUSTOM_COMMAND(TARGET uhk-right POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary ${EXECUTABLE_OUTPUT_PATH}/uhk-right.elf ${EXECUTABLE_OUTPUT_PATH}/uhk-right.bin)
diff --git a/right/build/armgcc/build_all.bat b/right/build/armgcc/build_all.bat
new file mode 100644
index 0000000..ee8198f
--- /dev/null
+++ b/right/build/armgcc/build_all.bat
@@ -0,0 +1,5 @@
+cmake -DCMAKE_TOOLCHAIN_FILE="%KSDK_DIR%/tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug .
+mingw32-make -j4
+cmake -DCMAKE_TOOLCHAIN_FILE="%KSDK_DIR%/tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release .
+mingw32-make -j4
+pause
diff --git a/right/build/armgcc/build_all.sh b/right/build/armgcc/build_all.sh
new file mode 100755
index 0000000..b3eea47
--- /dev/null
+++ b/right/build/armgcc/build_all.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+cmake -DCMAKE_TOOLCHAIN_FILE="$KSDK_DIR/tools/cmake_toolchain_files/armgcc.cmake" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug .
+make -j4
+cmake -DCMAKE_TOOLCHAIN_FILE="$KSDK_DIR/tools/cmake_toolchain_files/armgcc.cmake" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .
+make -j4
diff --git a/right/build/armgcc/build_debug.bat b/right/build/armgcc/build_debug.bat
new file mode 100644
index 0000000..ad00bdf
--- /dev/null
+++ b/right/build/armgcc/build_debug.bat
@@ -0,0 +1,3 @@
+cmake -DCMAKE_TOOLCHAIN_FILE="%KSDK_DIR%/tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug .
+mingw32-make -j4
+pause
diff --git a/right/build/armgcc/build_debug.sh b/right/build/armgcc/build_debug.sh
new file mode 100755
index 0000000..75372d5
--- /dev/null
+++ b/right/build/armgcc/build_debug.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+cmake -DCMAKE_TOOLCHAIN_FILE="$KSDK_DIR/tools/cmake_toolchain_files/armgcc.cmake" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug .
+make -j4
diff --git a/right/build/armgcc/build_release.bat b/right/build/armgcc/build_release.bat
new file mode 100644
index 0000000..344b963
--- /dev/null
+++ b/right/build/armgcc/build_release.bat
@@ -0,0 +1,3 @@
+cmake -DCMAKE_TOOLCHAIN_FILE="%KSDK_DIR%/tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release .
+mingw32-make -j4
+pause
diff --git a/right/build/armgcc/build_release.sh b/right/build/armgcc/build_release.sh
new file mode 100755
index 0000000..ffc490d
--- /dev/null
+++ b/right/build/armgcc/build_release.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+cmake -DCMAKE_TOOLCHAIN_FILE="$KSDK_DIR/tools/cmake_toolchain_files/armgcc.cmake" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .
+make -j4
diff --git a/right/build/armgcc/clean.bat b/right/build/armgcc/clean.bat
new file mode 100644
index 0000000..ffea088
--- /dev/null
+++ b/right/build/armgcc/clean.bat
@@ -0,0 +1,3 @@
+RD /s /Q Debug Release CMakeFiles
+DEL /s /Q /F Makefile cmake_install.cmake CMakeCache.txt
+pause
diff --git a/right/build/armgcc/clean.sh b/right/build/armgcc/clean.sh
new file mode 100755
index 0000000..795ad87
--- /dev/null
+++ b/right/build/armgcc/clean.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+rm -rf debug release CMakeFiles
+rm -rf Makefile cmake_install.cmake CMakeCache.txt
diff --git a/right/build/kds/.cproject b/right/build/kds/.cproject
new file mode 100644
index 0000000..cc9d4c8
--- /dev/null
+++ b/right/build/kds/.cproject
@@ -0,0 +1,386 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/build/kds/.project b/right/build/kds/.project
new file mode 100644
index 0000000..7e53a67
--- /dev/null
+++ b/right/build/kds/.project
@@ -0,0 +1,180 @@
+
+
+ uhk-right
+
+
+
+
+
+ com.freescale.processorexpert.core.expertprojectbuilder
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ com.freescale.processorexpert.core.expertprojectnature
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
+
+ board
+ 2
+ virtual:/virtual
+
+
+ sources
+ 2
+ virtual:/virtual
+
+
+ startup
+ 2
+ virtual:/virtual
+
+
+ utilities
+ 2
+ virtual:/virtual
+
+
+ board/board.c
+ 1
+ KSDK_DIR/examples/frdmk22f/board.c
+
+
+ board/board.h
+ 1
+ KSDK_DIR/examples/frdmk22f/board.h
+
+
+ board/gpio_pins.c
+ 1
+ KSDK_DIR/examples/frdmk22f/gpio_pins.c
+
+
+ board/gpio_pins.h
+ 1
+ KSDK_DIR/examples/frdmk22f/gpio_pins.h
+
+
+ board/hardware_init.c
+ 1
+ PARENT-2-PROJECT_LOC/hardware_init.c
+
+
+ board/pin_mux.c
+ 1
+ KSDK_DIR/examples/frdmk22f/pin_mux.c
+
+
+ board/pin_mux.h
+ 1
+ KSDK_DIR/examples/frdmk22f/pin_mux.h
+
+
+ sources/composite_app.c
+ 1
+ PARENT-2-PROJECT_LOC/composite_app.c
+
+
+ sources/composite_app.h
+ 1
+ PARENT-2-PROJECT_LOC/composite_app.h
+
+
+ sources/keyboard.c
+ 1
+ PARENT-2-PROJECT_LOC/keyboard.c
+
+
+ sources/keyboard.h
+ 1
+ PARENT-2-PROJECT_LOC/keyboard.h
+
+
+ sources/mouse.c
+ 1
+ PARENT-2-PROJECT_LOC/mouse.c
+
+
+ sources/mouse.h
+ 1
+ PARENT-2-PROJECT_LOC/mouse.h
+
+
+ sources/usb_descriptor.c
+ 1
+ PARENT-2-PROJECT_LOC/usb_descriptor.c
+
+
+ sources/usb_descriptor.h
+ 1
+ PARENT-2-PROJECT_LOC/usb_descriptor.h
+
+
+ startup/startup.c
+ 1
+ KSDK_DIR/platform/devices/startup.c
+
+
+ startup/startup.h
+ 1
+ KSDK_DIR/platform/devices/startup.h
+
+
+ startup/startup_MK22F51212.S
+ 1
+ KSDK_DIR/platform/devices/MK22F51212/startup/gcc/startup_MK22F51212.S
+
+
+ startup/system_MK22F51212.c
+ 1
+ KSDK_DIR/platform/devices/MK22F51212/startup/system_MK22F51212.c
+
+
+ utilities/fsl_debug_console.c
+ 1
+ KSDK_DIR/platform/utilities/src/fsl_debug_console.c
+
+
+ utilities/fsl_debug_console.h
+ 1
+ KSDK_DIR/platform/utilities/inc/fsl_debug_console.h
+
+
+ utilities/fsl_misc_utilities.c
+ 1
+ KSDK_DIR/platform/utilities/src/fsl_misc_utilities.c
+
+
+ utilities/print_scan.c
+ 1
+ KSDK_DIR/platform/utilities/src/print_scan.c
+
+
+ utilities/print_scan.h
+ 1
+ KSDK_DIR/platform/utilities/src/print_scan.h
+
+
+
+
+ KSDK_DIR
+ file:/home/laci/projects/kds/KSDK_1.3.0
+
+
+
diff --git a/right/build/kds/.settings/com.processorexpert.core.ide.newprojectwizard.prefs b/right/build/kds/.settings/com.processorexpert.core.ide.newprojectwizard.prefs
new file mode 100644
index 0000000..d6c0e7e
--- /dev/null
+++ b/right/build/kds/.settings/com.processorexpert.core.ide.newprojectwizard.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+versionGenerated/versionGenerated=1.8.4.RT7_b1550-0615
diff --git a/right/build/kds/.settings/language.settings.xml b/right/build/kds/.settings/language.settings.xml
new file mode 100644
index 0000000..3115a4a
--- /dev/null
+++ b/right/build/kds/.settings/language.settings.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/build/kds/uhk-right debug cmsisdap.launch b/right/build/kds/uhk-right debug cmsisdap.launch
new file mode 100644
index 0000000..53f3049
--- /dev/null
+++ b/right/build/kds/uhk-right debug cmsisdap.launch
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/build/kds/uhk-right debug jlink.launch b/right/build/kds/uhk-right debug jlink.launch
new file mode 100644
index 0000000..a7f08e9
--- /dev/null
+++ b/right/build/kds/uhk-right debug jlink.launch
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/build/kds/uhk-right debug pne.launch b/right/build/kds/uhk-right debug pne.launch
new file mode 100644
index 0000000..acea0c4
--- /dev/null
+++ b/right/build/kds/uhk-right debug pne.launch
@@ -0,0 +1,199 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/build/kds/uhk-right release cmsisdap.launch b/right/build/kds/uhk-right release cmsisdap.launch
new file mode 100644
index 0000000..e9486f6
--- /dev/null
+++ b/right/build/kds/uhk-right release cmsisdap.launch
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/build/kds/uhk-right release jlink.launch b/right/build/kds/uhk-right release jlink.launch
new file mode 100644
index 0000000..34e2f1f
--- /dev/null
+++ b/right/build/kds/uhk-right release jlink.launch
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/build/kds/uhk-right release pne.launch b/right/build/kds/uhk-right release pne.launch
new file mode 100644
index 0000000..1efc46a
--- /dev/null
+++ b/right/build/kds/uhk-right release pne.launch
@@ -0,0 +1,199 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/right/composite_app.c b/right/composite_app.c
new file mode 100644
index 0000000..a48cc61
--- /dev/null
+++ b/right/composite_app.c
@@ -0,0 +1,74 @@
+#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
new file mode 100644
index 0000000..a7b4d1a
--- /dev/null
+++ b/right/composite_app.h
@@ -0,0 +1,27 @@
+#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
new file mode 100644
index 0000000..8d902e4
--- /dev/null
+++ b/right/hardware_init.c
@@ -0,0 +1,32 @@
+#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/keyboard.c b/right/keyboard.c
new file mode 100644
index 0000000..71b26da
--- /dev/null
+++ b/right/keyboard.c
@@ -0,0 +1,227 @@
+#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
new file mode 100644
index 0000000..cc7f8ed
--- /dev/null
+++ b/right/keyboard.h
@@ -0,0 +1,265 @@
+#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
new file mode 100644
index 0000000..83e90a5
--- /dev/null
+++ b/right/mouse.c
@@ -0,0 +1,208 @@
+#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
new file mode 100644
index 0000000..25b0cdd
--- /dev/null
+++ b/right/mouse.h
@@ -0,0 +1,22 @@
+#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
new file mode 100644
index 0000000..a0205ea
--- /dev/null
+++ b/right/usb_descriptor.c
@@ -0,0 +1,733 @@
+#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
new file mode 100644
index 0000000..1fef9a8
--- /dev/null
+++ b/right/usb_descriptor.h
@@ -0,0 +1,98 @@
+#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