mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 14:25:11 +03:00
USB joystick support for 9xrpro (#5776)
* hid-mouse example added
* cmake script and sources fixed
* massstorage is turned off (it is still not used)
* first test (mouse instead of joystick)
* mouse renamed to joystick one more time
* it works
* refactoring
* useless files removed
* usbJoystickUpdate() moved to appropriate place
* masstorage removed for sky9x
* "keyboard" -> "joystick"
* productDescriptor changed to "SKY9X Joystick"
* attempt to fix travis
* joystick.cpp moved to FIRMWARE_TARGET_SRC
* meaningless if removed
* code style fixed for opentx/radio/src/targets/sky9x/joystick.cpp
* Revert "masstorage removed for sky9x"
This reverts commit 426726283f
.
* opentx/radio/src/targets/sky9x/usb_driver.cpp added
* useless include removed
This commit is contained in:
parent
fc34d0a995
commit
59d3f2d16f
24 changed files with 2172 additions and 11 deletions
|
@ -90,14 +90,20 @@ set(FIRMWARE_TARGET_SRC
|
|||
eeprom_driver.cpp
|
||||
lcd_driver.cpp
|
||||
pwr_driver.cpp
|
||||
joystick.cpp
|
||||
massstorage.cpp
|
||||
keys_driver.cpp
|
||||
usb/device/core/USBD_UDP.c
|
||||
usb/device/core/USBDDriver.c
|
||||
usb_driver.cpp
|
||||
usb/device/massstorage/MSDDriver.c
|
||||
usb/device/massstorage/MSDDStateMachine.c
|
||||
usb/device/massstorage/MSDLun.c
|
||||
usb/device/massstorage/MSDDriverDescriptors.c
|
||||
usb/device/massstorage/SBCMethods.c
|
||||
usb/device/hid-joystick/HIDDJoystickDriver.c
|
||||
usb/device/hid-joystick/HIDDJoystickDriverDescriptors.c
|
||||
usb/device/hid-joystick/HIDDJoystickInputReport.c
|
||||
usb/common/core/USBEndpointDescriptor.c
|
||||
usb/common/core/USBGenericRequest.c
|
||||
usb/common/core/USBFeatureRequest.c
|
||||
|
@ -107,6 +113,8 @@ set(FIRMWARE_TARGET_SRC
|
|||
usb/common/core/USBSetConfigurationRequest.c
|
||||
usb/common/core/USBConfigurationDescriptor.c
|
||||
usb/common/core/USBGenericDescriptor.c
|
||||
usb/common/hid/HIDIdleRequest.c
|
||||
usb/common/hid/HIDReportRequest.c
|
||||
MEDSdcard.c
|
||||
)
|
||||
|
||||
|
@ -119,7 +127,6 @@ set(TARGET_SRC
|
|||
buzzer_driver.cpp
|
||||
haptic_driver.cpp
|
||||
sdcard_driver.cpp
|
||||
massstorage.cpp
|
||||
aux_serial_driver.cpp
|
||||
audio_driver.cpp
|
||||
trainer_driver.cpp
|
||||
|
|
|
@ -170,6 +170,10 @@ void lcdSetContrast();
|
|||
// USB driver
|
||||
void usbMassStorage();
|
||||
|
||||
#if !defined(SIMU)
|
||||
void usbJoystickUpdate();
|
||||
#endif
|
||||
|
||||
#define PIN_ENABLE 0x001
|
||||
#define PIN_PERIPHERAL 0x000
|
||||
#define PIN_INPUT 0x002
|
||||
|
|
88
radio/src/targets/sky9x/joystick.cpp
Normal file
88
radio/src/targets/sky9x/joystick.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
extern "C" {
|
||||
#include "usb/device/hid-joystick/HIDDJoystickDriver.h"
|
||||
extern void HIDDJoystickDriver_Initialize();
|
||||
unsigned char HIDDJoystickDriver_ChangeJoystickState(const HIDDJoystickInputReport *report);
|
||||
extern void USBD_Connect(void);
|
||||
}
|
||||
|
||||
static void ConfigureUsbClock(void)
|
||||
{
|
||||
/* Enable PLLB for USB */
|
||||
PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(1)
|
||||
| CKGR_PLLBR_MULB(7)
|
||||
| CKGR_PLLBR_PLLBCOUNT_Msk;
|
||||
while((PMC->PMC_SR & PMC_SR_LOCKB) == 0); // TODO && (timeout++ < CLOCK_TIMEOUT));
|
||||
/* USB Clock uses PLLB */
|
||||
PMC->PMC_USB = PMC_USB_USBDIV(1) /* /2 */
|
||||
| PMC_USB_USBS; /* PLLB */
|
||||
}
|
||||
|
||||
void usbJoystickUpdate()
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
if (usbPlugged()) {
|
||||
TRACE_DEBUG("usbJoystick\n\r");
|
||||
|
||||
if (!initialized) {
|
||||
ConfigureUsbClock();
|
||||
|
||||
HIDDJoystickDriver_Initialize();
|
||||
|
||||
// VBus_Configure();
|
||||
USBD_Connect();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
static uint8_t HID_Buffer[11];
|
||||
|
||||
HID_Buffer[0] = 0;
|
||||
HID_Buffer[1] = 0;
|
||||
HID_Buffer[2] = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ( channelOutputs[i+8] > 0 ) {
|
||||
HID_Buffer[0] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+16] > 0 ) {
|
||||
HID_Buffer[1] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+24] > 0 ) {
|
||||
HID_Buffer[2] |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
//analog values
|
||||
//uint8_t * p = HID_Buffer + 1;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
int16_t value = channelOutputs[i] / 8;
|
||||
if ( value > 127 ) value = 127;
|
||||
else if ( value < -127 ) value = -127;
|
||||
HID_Buffer[i+3] = static_cast<int8_t>(value);
|
||||
}
|
||||
|
||||
HIDDJoystickDriver_ChangeJoystickState((HIDDJoystickInputReport*)&HID_Buffer);
|
||||
}
|
||||
}
|
55
radio/src/targets/sky9x/usb/common/hid/HIDButton.h
Normal file
55
radio/src/targets/sky9x/usb/common/hid/HIDButton.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: HIDButton
|
||||
|
||||
About: Purpose
|
||||
Definitions of constants and methods for the HID Button usage page.
|
||||
|
||||
About: Usage
|
||||
1 - Use the constants declared in this file when instanciating a
|
||||
Report descriptor instance.
|
||||
2 - When implementing the functionality of an HID Mouse, use the
|
||||
key codes defined here to indicate keys that are being pressed and
|
||||
released.
|
||||
*/
|
||||
|
||||
#ifndef _HIDBUTTON_H
|
||||
#define _HIDBUTTON_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Identifier for the HID button usage page
|
||||
#define HIDButton_PAGEID 0x09
|
||||
|
||||
|
||||
#endif
|
93
radio/src/targets/sky9x/usb/common/hid/HIDDescriptor.h
Normal file
93
radio/src/targets/sky9x/usb/common/hid/HIDDescriptor.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Methods and definitions for manipulating a HID descriptor.
|
||||
*/
|
||||
|
||||
#ifndef HIDDESCRIPTOR_H
|
||||
#define HIDDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Release Numbers"
|
||||
/// ...
|
||||
///
|
||||
/// !Numbers
|
||||
/// - HIDDescriptor_HID1_11
|
||||
|
||||
/// Identifies version 1.11 of the HID specification.
|
||||
#define HIDDescriptor_HID1_11 0x0111
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Identifies the length of type of subordinate descriptors of a HID
|
||||
/// device. This particular type only supports one subordinate descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (HIDGenericDescriptor_HID).
|
||||
unsigned char bDescriptorType;
|
||||
/// HID class specification release number in BCD format.
|
||||
unsigned short bcdHID;
|
||||
/// Country code of the device if it is localized.
|
||||
unsigned char bCountryCode;
|
||||
/// Number of subordinate descriptors.
|
||||
unsigned char bNumDescriptors;
|
||||
/// Type of the first subordinate descriptor.
|
||||
unsigned char bDescriptorType0;
|
||||
/// Size in bytes of the first subordinate descriptor.
|
||||
unsigned short wDescriptorLength0;
|
||||
|
||||
} __attribute__ ((packed)) HIDDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef HIDDESCRIPTOR_H
|
||||
|
68
radio/src/targets/sky9x/usb/common/hid/HIDDeviceDescriptor.h
Normal file
68
radio/src/targets/sky9x/usb/common/hid/HIDDeviceDescriptor.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions used for declaring the device descriptor of a HID device.
|
||||
|
||||
!!!Usage
|
||||
|
||||
Use this constants when defining an instance of USBDeviceDescriptor for
|
||||
an HID device.
|
||||
*/
|
||||
|
||||
#ifndef HIDDEVICEDESCRIPTOR_H
|
||||
#define HIDDEVICEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Device Descriptor Codes"
|
||||
/// This page lists HID device class, subclass and protocol codes.
|
||||
///
|
||||
/// !Codes
|
||||
/// - HIDDeviceDescriptor_CLASS
|
||||
/// - HIDDeviceDescriptor_SUBCLASS
|
||||
/// - HIDDeviceDescriptor_PROTOCOL
|
||||
|
||||
/// Class code for a HID device.
|
||||
#define HIDDeviceDescriptor_CLASS 0
|
||||
/// Subclass code for a HID device.
|
||||
#define HIDDeviceDescriptor_SUBCLASS 0
|
||||
/// Protocol code for a HID device.
|
||||
#define HIDDeviceDescriptor_PROTOCOL 0
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef HIDDEVICEDESCRIPTOR_H
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions for using HID-specific descriptors.
|
||||
*/
|
||||
|
||||
#ifndef HIDGENERICDESCRIPTOR_H
|
||||
#define HIDGENERICDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Descriptors Types"
|
||||
/// ...
|
||||
///
|
||||
/// !Types
|
||||
/// - HIDGenericDescriptor_HID
|
||||
/// - HIDGenericDescriptor_REPORT
|
||||
/// - HIDGenericDescriptor_PHYSICAL
|
||||
|
||||
/// HID descriptor type.
|
||||
#define HIDGenericDescriptor_HID 0x21
|
||||
/// Report descriptor type.
|
||||
#define HIDGenericDescriptor_REPORT 0x22
|
||||
/// Physical descriptor type.
|
||||
#define HIDGenericDescriptor_PHYSICAL 0x23
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef HIDGENERICDESCRIPTOR_H
|
||||
|
109
radio/src/targets/sky9x/usb/common/hid/HIDGenericDesktop.h
Normal file
109
radio/src/targets/sky9x/usb/common/hid/HIDGenericDesktop.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Constants for using the HID generic desktop usage page.
|
||||
|
||||
!!!Usage
|
||||
|
||||
Use these constants when declaring a Report descriptor which references
|
||||
the generic desktop page.
|
||||
*/
|
||||
|
||||
#ifndef HIDGENERICDESKTOP_H
|
||||
#define HIDGENERICDESKTOP_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID GenericDesktop Page ID"
|
||||
/// ...
|
||||
///
|
||||
/// !ID
|
||||
/// - HIDGenericDesktop_PAGEID
|
||||
|
||||
/// ID for the HID generic desktop usage page.
|
||||
#define HIDGenericDesktop_PAGEID 0x01
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID GenericDesktop Usages"
|
||||
/// ...
|
||||
///
|
||||
/// !Usages
|
||||
/// - HIDGenericDesktop_POINTER
|
||||
/// - HIDGenericDesktop_MOUSE
|
||||
/// - HIDGenericDesktop_JOYSTICK
|
||||
/// - HIDGenericDesktop_GAMEPAD
|
||||
/// - HIDGenericDesktop_KEYBOARD
|
||||
/// - HIDGenericDesktop_KEYPAD
|
||||
/// - HIDGenericDesktop_MULTIAXIS
|
||||
/// - HIDGenericDesktop_X
|
||||
/// - HIDGenericDesktop_Y
|
||||
/// - HIDGenericDesktop_Z
|
||||
|
||||
/// Pointer usage ID.
|
||||
#define HIDGenericDesktop_POINTER 0x01
|
||||
/// Mouse usage ID.
|
||||
#define HIDGenericDesktop_MOUSE 0x02
|
||||
/// Joystick usage ID.
|
||||
#define HIDGenericDesktop_JOYSTICK 0x04
|
||||
/// Gamepad usage ID.
|
||||
#define HIDGenericDesktop_GAMEPAD 0x05
|
||||
/// Keyboard usage ID.
|
||||
#define HIDGenericDesktop_KEYBOARD 0x06
|
||||
/// Keypad usage ID.
|
||||
#define HIDGenericDesktop_KEYPAD 0x07
|
||||
/// Multi-axis controller usage ID.
|
||||
#define HIDGenericDesktop_MULTIAXIS 0x08
|
||||
|
||||
/// Axis Usage X direction ID.
|
||||
#define HIDGenericDesktop_X_AXIS 0x30
|
||||
/// Axis Usage Y direction ID.
|
||||
#define HIDGenericDesktop_Y_AXIS 0x31
|
||||
/// Axis Usage Z direction ID.
|
||||
#define HIDGenericDesktop_Z_AXIS 0x32
|
||||
/// Rotation Usage X direction ID.
|
||||
#define HIDGenericDesktop_X_ROTATION 0x33
|
||||
/// Rotation Usage Y direction ID.
|
||||
#define HIDGenericDesktop_Y_ROTATION 0x34
|
||||
/// Rotation Usage Z direction ID.
|
||||
#define HIDGenericDesktop_Z_ROTATION 0x35
|
||||
/// Slider usage ID.
|
||||
#define HIDGenericDesktop_SLIDER 0x36
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef HIDGENERICDESKTOP_H
|
||||
|
75
radio/src/targets/sky9x/usb/common/hid/HIDGenericRequest.h
Normal file
75
radio/src/targets/sky9x/usb/common/hid/HIDGenericRequest.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: HIDGenericRequest
|
||||
|
||||
About: Purpose
|
||||
Definition of constants for using HID-specific requests.
|
||||
|
||||
About: Usage
|
||||
When constructing or receiving an HID SETUP request, use the request
|
||||
codes provided by this header file.
|
||||
*/
|
||||
|
||||
#ifndef HIDGENERICREQUEST_H
|
||||
#define HIDGENERICREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Request Codes"
|
||||
/// ...
|
||||
///
|
||||
/// !Codes
|
||||
/// - HIDGenericRequest_GETREPORT
|
||||
/// - HIDGenericRequest_GETIDLE
|
||||
/// - HIDGenericRequest_GETPROTOCOL
|
||||
/// - HIDGenericRequest_SETREPORT
|
||||
/// - HIDGenericRequest_SETIDLE
|
||||
/// - HIDGenericRequest_SETPROTOCOL
|
||||
|
||||
/// GetReport request code.
|
||||
#define HIDGenericRequest_GETREPORT 0x01
|
||||
/// GetIdle request code.
|
||||
#define HIDGenericRequest_GETIDLE 0x02
|
||||
/// GetProtocol request code.
|
||||
#define HIDGenericRequest_GETPROTOCOL 0x03
|
||||
/// SetReport request code.
|
||||
#define HIDGenericRequest_SETREPORT 0x09
|
||||
/// SetIdle request code.
|
||||
#define HIDGenericRequest_SETIDLE 0x0A
|
||||
/// SetProtocol request code.
|
||||
#define HIDGenericRequest_SETPROTOCOL 0x0B
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef HIDGENERICREQUEST_H
|
||||
|
56
radio/src/targets/sky9x/usb/common/hid/HIDIdleRequest.c
Normal file
56
radio/src/targets/sky9x/usb/common/hid/HIDIdleRequest.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: HIDIdleRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the HIDIdleRequest methods.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "HIDIdleRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Retrieves the Idle rate (in milliseconds) indicated by a SET_IDLE
|
||||
/// request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New idle rate for the report.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char HIDIdleRequest_GetIdleRate(const USBGenericRequest *request)
|
||||
{
|
||||
return ((USBGenericRequest_GetValue(request) >> 8) & 0xFF);
|
||||
}
|
68
radio/src/targets/sky9x/usb/common/hid/HIDIdleRequest.h
Normal file
68
radio/src/targets/sky9x/usb/common/hid/HIDIdleRequest.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Methods and constants for manipulating HID-specific GET_IDLE and SET_IDLE
|
||||
requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Retrieve the idle rate indicated by a GET_IDLE or SET_IDLE request
|
||||
with HIDIdleRequest_GetIdleRate.
|
||||
*/
|
||||
|
||||
#ifndef HIDIDLEREQUEST_H
|
||||
#define HIDIDLEREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <usb/common/core/USBGenericRequest.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Infinite idle rate.
|
||||
#define HIDIdleRequest_INFINITE 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char HIDIdleRequest_GetIdleRate(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef HIDIDLEREQUEST_H
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Constants used when declaring an HID interface.
|
||||
|
||||
!!!Usage
|
||||
|
||||
Use the constants defined here when declaring a USBInterfaceDescriptor
|
||||
instance for a HID interface.
|
||||
*/
|
||||
|
||||
#ifndef HIDINTERFACEDESCRIPTOR_H
|
||||
#define HIDINTERFACEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Interface Descriptor Codes"
|
||||
/// This page lists HID Interface class, subclass and protocol codes.
|
||||
///
|
||||
/// !Codes
|
||||
/// - HIDInterfaceDescriptor_CLASS
|
||||
/// - HIDInterfaceDescriptor_SUBCLASS_NONE
|
||||
/// - HIDInterfaceDescriptor_SUBCLASS_BOOT
|
||||
/// - HIDInterfaceDescriptor_PROTOCOL_NONE
|
||||
/// - HIDInterfaceDescriptor_PROTOCOL_KEYBOARD
|
||||
/// - HIDInterfaceDescriptor_PROTOCOL_MOUSE
|
||||
|
||||
/// HID interface class code.
|
||||
#define HIDInterfaceDescriptor_CLASS 0x03
|
||||
/// Indicates the interface does not implement a particular subclass.
|
||||
#define HIDInterfaceDescriptor_SUBCLASS_NONE 0x00
|
||||
/// Indicates the interface is compliant with the boot specification.
|
||||
#define HIDInterfaceDescriptor_SUBCLASS_BOOT 0x01
|
||||
/// Indicates the interface does not implement a particular protocol.
|
||||
#define HIDInterfaceDescriptor_PROTOCOL_NONE 0x00
|
||||
/// Indicates the interface supports the boot specification as a keyboard.
|
||||
#define HIDInterfaceDescriptor_PROTOCOL_KEYBOARD 0x01
|
||||
/// Indicates the interface supports the boot specification as a mouse.
|
||||
#define HIDInterfaceDescriptor_PROTOCOL_MOUSE 0x02
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef HIDINTERFACEDESCRIPTOR_H
|
||||
|
231
radio/src/targets/sky9x/usb/common/hid/HIDReport.h
Normal file
231
radio/src/targets/sky9x/usb/common/hid/HIDReport.h
Normal file
|
@ -0,0 +1,231 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions used when declaring an HID report descriptor.
|
||||
|
||||
!!!Usage
|
||||
|
||||
Use the definitions provided here when declaring a report descriptor,
|
||||
which shall be an unsigned char array.
|
||||
*/
|
||||
|
||||
#ifndef HIDREPORT_H
|
||||
#define HIDREPORT_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Main Item Tags"
|
||||
/// This page lists the Main Item Tags defined for HID %device.
|
||||
/// ( HID Spec. 6.2.2 )
|
||||
///
|
||||
/// !Tags
|
||||
/// - HIDReport_INPUT
|
||||
/// - HIDReport_OUPUT
|
||||
/// - HIDReport_FEATURE
|
||||
/// - HIDReport_COLLECTION
|
||||
/// - HIDReport_ENDCOLLECTION
|
||||
|
||||
/// Input item.
|
||||
#define HIDReport_INPUT 0x80
|
||||
/// Output item.
|
||||
#define HIDReport_OUTPUT 0x90
|
||||
/// Feature item.
|
||||
#define HIDReport_FEATURE 0xB0
|
||||
/// Collection item.
|
||||
#define HIDReport_COLLECTION 0xA0
|
||||
/// End of collection item.
|
||||
#define HIDReport_ENDCOLLECTION 0xC0
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Items for Data Fields"
|
||||
/// This page lists defintions for HID Input, Output and Feature items that
|
||||
/// are used to create the data fields within a report.
|
||||
/// ( HID Spec. 6.2.2.5 )
|
||||
///
|
||||
/// !Items
|
||||
/// - HIDReport_CONSTANT
|
||||
/// - HIDReport_VARIABLE
|
||||
/// - HIDReport_RELATIVE
|
||||
/// - HIDReport_WRAP
|
||||
/// - HIDReport_NONLINEAR
|
||||
/// - HIDReport_NOPREFERRED
|
||||
/// - HIDReport_NULLSTATE
|
||||
/// - HIDReport_VOLATILE
|
||||
/// - HIDReport_BUFFEREDBYTES
|
||||
|
||||
/// The report value is constant (vs. variable).
|
||||
#define HIDReport_CONSTANT (1 << 0)
|
||||
/// Data reported is a variable (vs. array).
|
||||
#define HIDReport_VARIABLE (1 << 1)
|
||||
/// Data is relative (vs. absolute).
|
||||
#define HIDReport_RELATIVE (1 << 2)
|
||||
/// Value rolls over when it reach a maximum/minimum.
|
||||
#define HIDReport_WRAP (1 << 3)
|
||||
/// Indicates that the data reported has been processed and is no longuer
|
||||
/// linear with the original measurements.
|
||||
#define HIDReport_NONLINEAR (1 << 4)
|
||||
/// Device has no preferred state to which it automatically returns.
|
||||
#define HIDReport_NOPREFERRED (1 << 5)
|
||||
/// Device has a null state, in which it does not report meaningful
|
||||
/// information.
|
||||
#define HIDReport_NULLSTATE (1 << 6)
|
||||
/// Indicates data can change without the host intervention.
|
||||
#define HIDReport_VOLATILE (1 << 7)
|
||||
/// Indicates the device produces a fixed-length stream of bytes.
|
||||
#define HIDReport_BUFFEREDBYTES (1 << 8)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Collection Items"
|
||||
/// This page lists definitions for HID Collection Items.
|
||||
/// ( HID Spec. 6.2.2.6 )
|
||||
///
|
||||
/// !Items
|
||||
/// - HIDReport_COLLECTION_PHYSICAL
|
||||
/// - HIDReport_COLLECTION_APPLICATION
|
||||
/// - HIDReport_COLLECTION_LOGICAL
|
||||
/// - HIDReport_COLLECTION_REPORT
|
||||
/// - HIDReport_COLLECTION_NAMEDARRAY
|
||||
/// - HIDReport_COLLECTION_USAGESWITCH
|
||||
/// - HIDReport_COLLECTION_USAGEMODIFIER
|
||||
|
||||
/// Physical collection.
|
||||
#define HIDReport_COLLECTION_PHYSICAL 0x00
|
||||
/// Application collection.
|
||||
#define HIDReport_COLLECTION_APPLICATION 0x01
|
||||
/// Logical collection.
|
||||
#define HIDReport_COLLECTION_LOGICAL 0x02
|
||||
/// Report collection.
|
||||
#define HIDReport_COLLECTION_REPORT 0x03
|
||||
/// Named array collection.
|
||||
#define HIDReport_COLLECTION_NAMEDARRAY 0x04
|
||||
/// Usage switch collection.
|
||||
#define HIDReport_COLLECTION_USAGESWITCH 0x05
|
||||
/// Usage modifier collection
|
||||
#define HIDReport_COLLECTION_USAGEMODIFIER 0x06
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Global Items"
|
||||
/// This page lists HID Global Items.
|
||||
/// ( HID Spec. 6.2.2.7 )
|
||||
///
|
||||
/// !Items
|
||||
/// - HIDReport_GLOBAL_USAGEPAGE
|
||||
/// - HIDReport_GLOBAL_LOGICALMINIMUM
|
||||
/// - HIDReport_GLOBAL_LOGICALMAXIMUM
|
||||
/// - HIDReport_GLOBAL_PHYSICALMINIMUM
|
||||
/// - HIDReport_GLOBAL_PHYSICALMAXIMUM
|
||||
/// - HIDReport_GLOBAL_UNITEXPONENT
|
||||
/// - HIDReport_GLOBAL_UNIT
|
||||
/// - HIDReport_GLOBAL_REPORTSIZE
|
||||
/// - HIDReport_GLOBAL_REPORTID
|
||||
/// - HIDReport_GLOBAL_REPORTCOUNT
|
||||
/// - HIDReport_GLOBAL_PUSH
|
||||
/// - HIDReport_GLOBAL_POP
|
||||
|
||||
/// Current usage page.
|
||||
#define HIDReport_GLOBAL_USAGEPAGE 0x04
|
||||
/// Minimum value that a variable or array item will report.
|
||||
#define HIDReport_GLOBAL_LOGICALMINIMUM 0x14
|
||||
/// Maximum value that a variable or array item will report.
|
||||
#define HIDReport_GLOBAL_LOGICALMAXIMUM 0x24
|
||||
/// Minimum value for the physical extent of a variable item.
|
||||
#define HIDReport_GLOBAL_PHYSICALMINIMUM 0x34
|
||||
/// Maximum value for the physical extent of a variable item.
|
||||
#define HIDReport_GLOBAL_PHYSICALMAXIMUM 0x44
|
||||
/// Value of the unit exponent in base 10.
|
||||
#define HIDReport_GLOBAL_UNITEXPONENT 0x54
|
||||
/// Unit values.
|
||||
#define HIDReport_GLOBAL_UNIT 0x64
|
||||
/// Size of the report fields in bits.
|
||||
#define HIDReport_GLOBAL_REPORTSIZE 0x74
|
||||
/// Specifies the report ID.
|
||||
#define HIDReport_GLOBAL_REPORTID 0x84
|
||||
/// Number of data fields for an item.
|
||||
#define HIDReport_GLOBAL_REPORTCOUNT 0x94
|
||||
/// Places a copy of the global item state table on the stack.
|
||||
#define HIDReport_GLOBAL_PUSH 0xA4
|
||||
/// Replaces the item state table with the top structure from the stack.
|
||||
#define HIDReport_GLOBAL_POP 0xB4
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Local Items"
|
||||
/// This page lists definitions for HID Local Items.
|
||||
///
|
||||
/// !Items
|
||||
/// - HIDReport_LOCAL_USAGE
|
||||
/// - HIDReport_LOCAL_USAGEMINIMUM
|
||||
/// - HIDReport_LOCAL_USAGEMAXIMUM
|
||||
/// - HIDReport_LOCAL_DESIGNATORINDEX
|
||||
/// - HIDReport_LOCAL_DESIGNATORMINIMUM
|
||||
/// - HIDReport_LOCAL_DESIGNATORMAXIMUM
|
||||
/// - HIDReport_LOCAL_STRINGINDEX
|
||||
/// - HIDReport_LOCAL_STRINGMINIMUM
|
||||
/// - HIDReport_LOCAL_STRINGMAXIMUM
|
||||
/// - HIDReport_LOCAL_DELIMITER
|
||||
|
||||
/// Suggested usage for an item or collection.
|
||||
#define HIDReport_LOCAL_USAGE 0x08
|
||||
/// Defines the starting usage associated with an array or bitmap.
|
||||
#define HIDReport_LOCAL_USAGEMINIMUM 0x18
|
||||
/// Defines the ending usage associated with an array or bitmap.
|
||||
#define HIDReport_LOCAL_USAGEMAXIMUM 0x28
|
||||
/// Determines the body part used for a control.
|
||||
#define HIDReport_LOCAL_DESIGNATORINDEX 0x38
|
||||
/// Defines the index of the starting designator associated with an array or
|
||||
/// bitmap.
|
||||
#define HIDReport_LOCAL_DESIGNATORMINIMUM 0x48
|
||||
/// Defines the index of the ending designator associated with an array or
|
||||
/// bitmap.
|
||||
#define HIDReport_LOCAL_DESIGNATORMAXIMUM 0x58
|
||||
/// String index for a string descriptor.
|
||||
#define HIDReport_LOCAL_STRINGINDEX 0x78
|
||||
/// Specifies the first string index when assigning a group of sequential
|
||||
/// strings to controls in an array or bitmap.
|
||||
#define HIDReport_LOCAL_STRINGMINIMUM 0x88
|
||||
/// Specifies the last string index when assigning a group of sequential
|
||||
/// strings to controls in an array or bitmap.
|
||||
#define HIDReport_LOCAL_STRINGMAXIMUM 0x98
|
||||
/// Defines the beginning or end of a set of local items.
|
||||
#define HIDReport_LOCAL_DELIMITER 0xA8
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif //#ifndef HIDREPORT_H
|
||||
|
68
radio/src/targets/sky9x/usb/common/hid/HIDReportRequest.c
Normal file
68
radio/src/targets/sky9x/usb/common/hid/HIDReportRequest.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: HIDReportRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the HIDReportRequest methods.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "HIDReportRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the type of report targetted by a SET_REPORT or GET_REPORT
|
||||
/// request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Requested report type (see "HID Report Types").
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char HIDReportRequest_GetReportType(const USBGenericRequest *request)
|
||||
{
|
||||
return ((USBGenericRequest_GetValue(request) >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the ID of the report targetted by a SET_REPORT or GET_REPORT
|
||||
/// request. This value should be 0 if report IDs are not used.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Requested report ID.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char HIDReportRequest_GetReportId(const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetValue(request) & 0xFF);
|
||||
}
|
||||
|
86
radio/src/targets/sky9x/usb/common/hid/HIDReportRequest.h
Normal file
86
radio/src/targets/sky9x/usb/common/hid/HIDReportRequest.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating HID-specific GET_REPORT and
|
||||
SET_REPORT requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Receive a GET_REPORT or SET_REPORT request from the host.
|
||||
-# Retrieve the report type using HIDReportRequest_GetReportType.
|
||||
-# Retrieve the report ID using HIDReportRequest_GetReportId.
|
||||
*/
|
||||
|
||||
#ifndef HIDREPORTREQUEST_H
|
||||
#define HIDREPORTREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <usb/common/core/USBGenericRequest.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Report Types"
|
||||
/// This page lists the types for USB HID Reports.
|
||||
///
|
||||
/// !Types
|
||||
/// - HIDReportRequest_INPUT
|
||||
/// - HIDReportRequest_OUTPUT
|
||||
/// - HIDReportRequest_FEATURE
|
||||
|
||||
/// Input report.
|
||||
#define HIDReportRequest_INPUT 1
|
||||
/// Output report.
|
||||
#define HIDReportRequest_OUTPUT 2
|
||||
/// Feature report.
|
||||
#define HIDReportRequest_FEATURE 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char HIDReportRequest_GetReportType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char HIDReportRequest_GetReportId(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef HIDREPORTREQUEST_H
|
||||
|
|
@ -0,0 +1,356 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "HIDDJoystickDriver.h"
|
||||
#include "HIDDJoystickDriverDescriptors.h"
|
||||
#include <usb/common/core/USBGetDescriptorRequest.h>
|
||||
#include <usb/common/hid/HIDGenericDescriptor.h>
|
||||
#include <usb/common/hid/HIDDescriptor.h>
|
||||
#include <usb/common/hid/HIDGenericRequest.h>
|
||||
#include <usb/common/hid/HIDReportRequest.h>
|
||||
#include <usb/common/hid/HIDIdleRequest.h>
|
||||
#include <usb/device/core/USBD.h>
|
||||
#include <usb/device/core/USBDDriver.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TRACE_INFO(...) { }
|
||||
#define TRACE_WARNING(...) { }
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Driver structure for an HID device implementing joystick functionalities.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Standard USB device driver instance.
|
||||
USBDDriver usbdDriver;
|
||||
/// Idle rate (in milliseconds) of the input report.
|
||||
unsigned char inputReportIdleRate;
|
||||
///
|
||||
unsigned char inputProtocol;
|
||||
/// Input report instance.
|
||||
HIDDJoystickInputReport inputReport;
|
||||
|
||||
} HIDDJoystickDriver;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Static instance of the HID joystick device driver.
|
||||
static HIDDJoystickDriver hiddJoystickDriver;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the descriptor requested by the host.
|
||||
/// \param type Descriptor type.
|
||||
/// \param length Maximum number of bytes to send.
|
||||
/// \return 1 if the request has been handled by this function, otherwise 0.
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char HIDDJoystickDriver_GetDescriptor(unsigned char type,
|
||||
unsigned char length)
|
||||
{
|
||||
extern int hiddReportDescriptorSize;
|
||||
|
||||
const USBConfigurationDescriptor *pConfiguration;
|
||||
HIDDescriptor *hidDescriptor;
|
||||
|
||||
switch (type) {
|
||||
|
||||
case HIDGenericDescriptor_REPORT:
|
||||
TRACE_INFO("Report ");
|
||||
|
||||
// Adjust length and send report descriptor
|
||||
if (length > hiddReportDescriptorSize) {
|
||||
|
||||
length = hiddReportDescriptorSize;
|
||||
}
|
||||
USBD_Write(0, &hiddReportDescriptor, length, 0, 0);
|
||||
break;
|
||||
|
||||
case HIDGenericDescriptor_HID:
|
||||
TRACE_INFO("HID ");
|
||||
|
||||
// Configuration descriptor is different depending on configuration
|
||||
if (USBD_IsHighSpeed()) {
|
||||
|
||||
pConfiguration =
|
||||
hiddJoystickDriver.usbdDriver.pDescriptors->pHsConfiguration;
|
||||
}
|
||||
else {
|
||||
|
||||
pConfiguration =
|
||||
hiddJoystickDriver.usbdDriver.pDescriptors->pFsConfiguration;
|
||||
}
|
||||
|
||||
// Parse the device configuration to get the HID descriptor
|
||||
USBConfigurationDescriptor_Parse(pConfiguration, 0, 0,
|
||||
(USBGenericDescriptor **) &hidDescriptor);
|
||||
|
||||
// Adjust length and send HID descriptor
|
||||
if (length > sizeof(HIDDescriptor)) {
|
||||
|
||||
length = sizeof(HIDDescriptor);
|
||||
}
|
||||
USBD_Write(0, hidDescriptor, length, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the current Idle rate of the input report to the host.
|
||||
//------------------------------------------------------------------------------
|
||||
static void HIDDJoystickDriver_GetIdle()
|
||||
{
|
||||
TRACE_INFO("gIdle ");
|
||||
|
||||
USBD_Write(0, &(hiddJoystickDriver.inputReportIdleRate), 1, 0, 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Retrieves the new idle rate of the input report from the USB host.
|
||||
/// \param idleRate New input report idle rate.
|
||||
//------------------------------------------------------------------------------
|
||||
static void HIDDJoystickDriver_SetIdle(unsigned char idleRate)
|
||||
{
|
||||
TRACE_INFO("sIdle(%d) ", idleRate);
|
||||
|
||||
hiddJoystickDriver.inputReportIdleRate = idleRate;
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Sends the requested report to the host.
|
||||
/// \param type Report type.
|
||||
/// \param length Maximum number of bytes to send.
|
||||
//------------------------------------------------------------------------------
|
||||
static void HIDDJoystickDriver_GetReport(unsigned char type,
|
||||
unsigned short length)
|
||||
{
|
||||
TRACE_INFO("gReport ");
|
||||
|
||||
// Check report type
|
||||
switch (type) {
|
||||
|
||||
case HIDReportRequest_INPUT:
|
||||
TRACE_INFO("In ");
|
||||
|
||||
// Adjust size and send report
|
||||
if (length > sizeof(HIDDJoystickInputReport)) {
|
||||
|
||||
length = sizeof(HIDDJoystickInputReport);
|
||||
}
|
||||
USBD_Write(0, // Endpoint #0
|
||||
&(hiddJoystickDriver.inputReport),
|
||||
length,
|
||||
0, // No callback
|
||||
0);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_Stall(0);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Retrieves the new value of a report from the host and saves it.
|
||||
/// \param type Report type.
|
||||
/// \param length Report length.
|
||||
//------------------------------------------------------------------------------
|
||||
static void HIDDJoystickDriver_SetReport(unsigned char type,
|
||||
unsigned short length)
|
||||
{
|
||||
TRACE_INFO("sReport ");
|
||||
|
||||
// Check report type
|
||||
switch (type) {
|
||||
|
||||
case HIDReportRequest_INPUT:
|
||||
// SET_REPORT requests on input reports are ignored
|
||||
USBD_Stall(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_Stall(0);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Optional RequestReceived() callback re-implementation
|
||||
//------------------------------------------------------------------------------
|
||||
#if !defined(NOAUTOCALLBACK)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Callback function when new request receivce from host
|
||||
/// \param request Pointer to the USBGenericRequest instance
|
||||
//------------------------------------------------------------------------------
|
||||
//void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
//{
|
||||
// HIDDJoystickDriver_RequestHandler(request);
|
||||
//}
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ConfigurationChanged() callback re-implementation
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Callback function when configureation changed
|
||||
/// \param cfgnum New configuration number
|
||||
//------------------------------------------------------------------------------
|
||||
//void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
//{
|
||||
// (void)cfgnum;
|
||||
//}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes the HID Joystick %device driver.
|
||||
//------------------------------------------------------------------------------
|
||||
void HIDDJoystickDriver_Initialize()
|
||||
{
|
||||
hiddJoystickDriver.inputReportIdleRate = 0;
|
||||
HIDDJoystickInputReport_Initialize(&(hiddJoystickDriver.inputReport));
|
||||
USBDDriver_Initialize(&(hiddJoystickDriver.usbdDriver),
|
||||
&hiddJoystickDriverDescriptors,
|
||||
0); // Multiple interface settings not supported
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Handles HID-specific SETUP request sent by the host.
|
||||
/// \param request Pointer to a USBGenericRequest instance
|
||||
//------------------------------------------------------------------------------
|
||||
void HIDDJoystickDriver_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
TRACE_INFO("NewReq ");
|
||||
|
||||
// Check if this is a standard request
|
||||
if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) {
|
||||
|
||||
// This is a standard request
|
||||
switch (USBGenericRequest_GetRequest(request)) {
|
||||
|
||||
case USBGenericRequest_GETDESCRIPTOR:
|
||||
// Check if this is a HID descriptor, otherwise forward it to
|
||||
// the standard driver
|
||||
if (!HIDDJoystickDriver_GetDescriptor(
|
||||
USBGetDescriptorRequest_GetDescriptorType(request),
|
||||
USBGenericRequest_GetLength(request))) {
|
||||
|
||||
USBDDriver_RequestHandler(&(hiddJoystickDriver.usbdDriver),
|
||||
request);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBDDriver_RequestHandler(&(hiddJoystickDriver.usbdDriver),
|
||||
request);
|
||||
}
|
||||
}
|
||||
// Check if this is a class request
|
||||
else if (USBGenericRequest_GetType(request) == USBGenericRequest_CLASS) {
|
||||
|
||||
// This is a class-specific request
|
||||
switch (USBGenericRequest_GetRequest(request)) {
|
||||
|
||||
case HIDGenericRequest_GETIDLE:
|
||||
HIDDJoystickDriver_GetIdle();
|
||||
break;
|
||||
|
||||
case HIDGenericRequest_SETIDLE:
|
||||
HIDDJoystickDriver_SetIdle(HIDIdleRequest_GetIdleRate(request));
|
||||
break;
|
||||
|
||||
case HIDGenericRequest_GETREPORT:
|
||||
HIDDJoystickDriver_GetReport(
|
||||
HIDReportRequest_GetReportType(request),
|
||||
USBGenericRequest_GetLength(request));
|
||||
break;
|
||||
|
||||
case HIDGenericRequest_SETREPORT:
|
||||
HIDDJoystickDriver_SetReport(
|
||||
HIDReportRequest_GetReportType(request),
|
||||
USBGenericRequest_GetLength(request));
|
||||
break;
|
||||
|
||||
case HIDGenericRequest_GETPROTOCOL:
|
||||
USBD_Write(0, &hiddJoystickDriver.inputProtocol, 1, 0, 0);
|
||||
break;
|
||||
|
||||
case HIDGenericRequest_SETPROTOCOL:
|
||||
hiddJoystickDriver.inputProtocol = request->wValue;
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
TRACE_WARNING(
|
||||
"HIDDJoystickDriver_RequestHandler: Unknown request 0x%02X\n\r",
|
||||
USBGenericRequest_GetRequest(request));
|
||||
USBD_Stall(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Vendor request ?
|
||||
USBD_Stall(0);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Update the Joystick state via input report
|
||||
/// to host
|
||||
/// \param report Pointer to a HIDDJoystickInputReport instance
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char HIDDJoystickDriver_ChangeJoystickState(const HIDDJoystickInputReport *report)
|
||||
{
|
||||
memcpy(&(hiddJoystickDriver.inputReport), report, sizeof(HIDDJoystickInputReport));
|
||||
|
||||
// Send input report through the interrupt IN endpoint
|
||||
return USBD_Write(HIDDJoystickDriverDescriptors_INTERRUPTIN,
|
||||
&(hiddJoystickDriver.inputReport),
|
||||
sizeof(HIDDJoystickInputReport),
|
||||
0,
|
||||
0);
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of methods for using a HID joystick device driver.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Re-implement the USBDCallbacks_RequestReceived callback to forward
|
||||
requests to HIDDJoystickDriver_RequestHandler. This is done
|
||||
automatically unless the NOAUTOCALLBACK symbol is defined during
|
||||
compilation.
|
||||
-# Initialize the driver using HIDDJoystickDriver_Initialize. The
|
||||
USB driver is automatically initialized by this method.
|
||||
-# Call the HIDDJoystickDriver_ChangePoints method when one or more
|
||||
keys are pressed/released.
|
||||
*/
|
||||
|
||||
#ifndef HIDDJOYSTICKDRIVER_H
|
||||
#define HIDDJOYSTICKDRIVER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <usb/common/core/USBGenericRequest.h>
|
||||
#include "HIDDJoystickInputReport.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: HIDDJoystickDriver_Initialize
|
||||
Initializes the HID joystick device driver.
|
||||
*/
|
||||
extern void HIDDJoystickDriver_Initialize();
|
||||
|
||||
/*
|
||||
Function: HIDDJoystickDriver_RequestHandler
|
||||
Handles HID-specific SETUP request sent by the host.
|
||||
|
||||
Parameters:
|
||||
request - Pointer to a USBGenericRequest instance.
|
||||
*/
|
||||
extern void HIDDJoystickDriver_RequestHandler(const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char HIDDJoystickDriver_ChangeJoystickState(const HIDDJoystickInputReport *report);
|
||||
|
||||
#endif //#ifndef HIDDJOYSTICKDRIVER_H
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: HIDDJoystickDriverDescriptors
|
||||
|
||||
About: Purpose
|
||||
Declaration of the descriptors used by the HID device joystick driver.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "HIDDJoystickDriverDescriptors.h"
|
||||
#include "HIDDJoystickInputReport.h"
|
||||
#include <usb/common/core/USBDeviceDescriptor.h>
|
||||
#include <usb/common/core/USBConfigurationDescriptor.h>
|
||||
#include <usb/common/core/USBInterfaceDescriptor.h>
|
||||
#include <usb/common/core/USBEndpointDescriptor.h>
|
||||
#include <usb/common/core/USBStringDescriptor.h>
|
||||
#include <usb/common/hid/HIDGenericDescriptor.h>
|
||||
#include <usb/common/hid/HIDDeviceDescriptor.h>
|
||||
#include <usb/common/hid/HIDInterfaceDescriptor.h>
|
||||
#include <usb/common/hid/HIDDescriptor.h>
|
||||
#include <usb/common/hid/HIDReport.h>
|
||||
#include <usb/common/hid/HIDGenericDesktop.h>
|
||||
#include <usb/common/hid/HIDButton.h>
|
||||
#include <usb/device/core/USBDDriverDescriptors.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "HID Joystick Device Descriptor IDs"
|
||||
/// ...
|
||||
///
|
||||
/// !IDs
|
||||
/// - HIDDJoystickDriverDescriptors_PRODUCTID
|
||||
/// - HIDDJoystickDriverDescriptors_VENDORID
|
||||
/// - HIDDJoystickDriverDescriptors_RELEASE
|
||||
|
||||
/// Device product ID.
|
||||
#define HIDDJoystickDriverDescriptors_PRODUCTID 0x6200
|
||||
/// Device vendor ID.
|
||||
#define HIDDJoystickDriverDescriptors_VENDORID 0x03EB
|
||||
/// Device release number.
|
||||
#define HIDDJoystickDriverDescriptors_RELEASE 0x0100
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// List of descriptors that make up the configuration descriptors of a
|
||||
/// %device using the HID Joystick driver.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Configuration descriptor.
|
||||
USBConfigurationDescriptor configuration;
|
||||
/// Interface descriptor.
|
||||
USBInterfaceDescriptor interface;
|
||||
/// HID descriptor.
|
||||
HIDDescriptor hid;
|
||||
/// Interrupt IN endpoint descriptor.
|
||||
USBEndpointDescriptor interruptIn;
|
||||
|
||||
} __attribute__ ((packed)) HIDDJoystickDriverConfigurationDescriptors;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) (((i == 0)||(i == 3)||(i == 4)) ? 64 :\
|
||||
(((i == 1) || (i == 2)) ? 512 : 1024))
|
||||
|
||||
/// Device descriptor.
|
||||
static const USBDeviceDescriptor deviceDescriptor = {
|
||||
|
||||
sizeof(USBDeviceDescriptor),
|
||||
USBGenericDescriptor_DEVICE,
|
||||
USBDeviceDescriptor_USB2_00,
|
||||
HIDDeviceDescriptor_CLASS,
|
||||
HIDDeviceDescriptor_SUBCLASS,
|
||||
HIDDeviceDescriptor_PROTOCOL,
|
||||
BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||
HIDDJoystickDriverDescriptors_VENDORID,
|
||||
HIDDJoystickDriverDescriptors_PRODUCTID,
|
||||
HIDDJoystickDriverDescriptors_RELEASE,
|
||||
1, // Index of manufacturer description
|
||||
2, // Index of product description
|
||||
3, // Index of serial number description
|
||||
1 // One possible configuration
|
||||
};
|
||||
|
||||
/// Report descriptor used by the driver.
|
||||
const unsigned char hiddReportDescriptor[] = {
|
||||
|
||||
HIDReport_GLOBAL_USAGEPAGE + 1, HIDGenericDesktop_PAGEID, // USAGE_PAGE (Generic Desktop)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_GAMEPAD, // USAGE (Game Pad)
|
||||
HIDReport_COLLECTION + 1, HIDReport_COLLECTION_APPLICATION, // COLLECTION (Application)
|
||||
HIDReport_COLLECTION + 1, HIDReport_COLLECTION_PHYSICAL, // COLLECTION (Physical)
|
||||
HIDReport_GLOBAL_USAGEPAGE + 1, HIDButton_PAGEID, // USAGE_PAGE (Button)
|
||||
HIDReport_LOCAL_USAGEMINIMUM + 1, 1, // USAGE_MINIMUM (Button 1)
|
||||
HIDReport_LOCAL_USAGEMAXIMUM + 1, 24, // USAGE_MAXIMUM (Button 24)
|
||||
HIDReport_GLOBAL_LOGICALMINIMUM + 1, 0, // LOGICAL_MINIMUM (0)
|
||||
HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 1, // LOGICAL_MAXIMUM (1)
|
||||
HIDReport_GLOBAL_REPORTCOUNT + 1, 24, // REPORT_COUNT (24)
|
||||
HIDReport_GLOBAL_REPORTSIZE + 1, 1, // REPORT_SIZE (1)
|
||||
HIDReport_INPUT + 1, HIDReport_VARIABLE, // INPUT (Data,Var,Abs)
|
||||
HIDReport_GLOBAL_USAGEPAGE + 1, HIDGenericDesktop_PAGEID, // USAGE_PAGE (Generic Desktop)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_X_AXIS, // USAGE (X)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_Y_AXIS, // USAGE (Y)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_Z_AXIS, // USAGE (Z)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_X_ROTATION, // USAGE (Rx)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_Y_ROTATION, // USAGE (Ry)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_Z_ROTATION, // USAGE (Rz)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_SLIDER, // USAGE (Slider)
|
||||
HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_SLIDER, // USAGE (Slider)
|
||||
HIDReport_GLOBAL_LOGICALMINIMUM + 1, (unsigned char) -127, // LOGICAL_MINIMUM (-127)
|
||||
HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 127, // LOGICAL_MAXIMUM (127)
|
||||
HIDReport_GLOBAL_REPORTSIZE + 1, 8, // REPORT_SIZE (8)
|
||||
HIDReport_GLOBAL_REPORTCOUNT + 1, 8, // REPORT_COUNT (8)
|
||||
HIDReport_INPUT + 1, HIDReport_VARIABLE, // INPUT (Data,Var,Abs)
|
||||
HIDReport_ENDCOLLECTION, // END_COLLECTION
|
||||
HIDReport_ENDCOLLECTION // END_COLLECTION
|
||||
};
|
||||
int hiddReportDescriptorSize = sizeof(hiddReportDescriptor);
|
||||
|
||||
/// Configuration descriptor.
|
||||
static const HIDDJoystickDriverConfigurationDescriptors configurationDescriptors = {
|
||||
|
||||
// Configuration descriptor
|
||||
{
|
||||
sizeof(USBConfigurationDescriptor),
|
||||
USBGenericDescriptor_CONFIGURATION,
|
||||
sizeof(HIDDJoystickDriverConfigurationDescriptors),
|
||||
1, // One interface in this configuration
|
||||
1, // This is configuration #1
|
||||
0, // No associated string descriptor
|
||||
BOARD_USB_BMATTRIBUTES,
|
||||
USBConfigurationDescriptor_POWER(100)
|
||||
},
|
||||
// Interface descriptor
|
||||
{
|
||||
sizeof(USBInterfaceDescriptor),
|
||||
USBGenericDescriptor_INTERFACE,
|
||||
0, // This is interface #0
|
||||
0, // This is alternate setting #0
|
||||
1, // One endpoints used
|
||||
HIDInterfaceDescriptor_CLASS,
|
||||
HIDInterfaceDescriptor_SUBCLASS_NONE,
|
||||
HIDInterfaceDescriptor_PROTOCOL_NONE,
|
||||
0 // No associated string descriptor
|
||||
},
|
||||
// HID descriptor
|
||||
{
|
||||
sizeof(HIDDescriptor),
|
||||
HIDGenericDescriptor_HID,
|
||||
HIDDescriptor_HID1_11,
|
||||
0, // Device is not localized, no country code
|
||||
1, // One HID-specific descriptor (apart from this one)
|
||||
HIDGenericDescriptor_REPORT,
|
||||
sizeof(hiddReportDescriptor),
|
||||
},
|
||||
// Interrupt IN endpoint descriptor
|
||||
{
|
||||
sizeof(USBEndpointDescriptor),
|
||||
USBGenericDescriptor_ENDPOINT, // 5
|
||||
USBEndpointDescriptor_ADDRESS(
|
||||
USBEndpointDescriptor_IN,
|
||||
HIDDJoystickDriverDescriptors_INTERRUPTIN),
|
||||
USBEndpointDescriptor_INTERRUPT,
|
||||
sizeof(HIDDJoystickInputReport),
|
||||
HIDDJoystickDriverDescriptors_INTERRUPTIN_POLLING
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Variables: String descriptors
|
||||
languageIdDescriptor - Language ID string descriptor.
|
||||
manufacturerDescriptor - Manufacturer name.
|
||||
productDescriptor - Product name.
|
||||
serialNumberDescriptor - Product serial number.
|
||||
stringDescriptors - Array of pointers to string descriptors.
|
||||
*/
|
||||
static const unsigned char languageIdDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(1),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_ENGLISH_US
|
||||
};
|
||||
|
||||
static const unsigned char manufacturerDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(5),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('T'),
|
||||
USBStringDescriptor_UNICODE('M'),
|
||||
USBStringDescriptor_UNICODE('E'),
|
||||
USBStringDescriptor_UNICODE('L')
|
||||
};
|
||||
|
||||
static const unsigned char productDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(14),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('S'),
|
||||
USBStringDescriptor_UNICODE('K'),
|
||||
USBStringDescriptor_UNICODE('Y'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('X'),
|
||||
USBStringDescriptor_UNICODE(' '),
|
||||
USBStringDescriptor_UNICODE('J'),
|
||||
USBStringDescriptor_UNICODE('o'),
|
||||
USBStringDescriptor_UNICODE('y'),
|
||||
USBStringDescriptor_UNICODE('s'),
|
||||
USBStringDescriptor_UNICODE('t'),
|
||||
USBStringDescriptor_UNICODE('i'),
|
||||
USBStringDescriptor_UNICODE('c'),
|
||||
USBStringDescriptor_UNICODE('k'),
|
||||
};
|
||||
|
||||
static const unsigned char serialNumberDescriptor[] = {
|
||||
|
||||
USBStringDescriptor_LENGTH(12),
|
||||
USBGenericDescriptor_STRING,
|
||||
USBStringDescriptor_UNICODE('0'),
|
||||
USBStringDescriptor_UNICODE('1'),
|
||||
USBStringDescriptor_UNICODE('2'),
|
||||
USBStringDescriptor_UNICODE('3'),
|
||||
USBStringDescriptor_UNICODE('4'),
|
||||
USBStringDescriptor_UNICODE('5'),
|
||||
USBStringDescriptor_UNICODE('6'),
|
||||
USBStringDescriptor_UNICODE('7'),
|
||||
USBStringDescriptor_UNICODE('8'),
|
||||
USBStringDescriptor_UNICODE('9'),
|
||||
USBStringDescriptor_UNICODE('A'),
|
||||
USBStringDescriptor_UNICODE('F')
|
||||
};
|
||||
|
||||
static const unsigned char *stringDescriptors[] = {
|
||||
|
||||
languageIdDescriptor,
|
||||
manufacturerDescriptor,
|
||||
productDescriptor,
|
||||
serialNumberDescriptor
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported variables
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// List of descriptors used by the HID joystick driver.
|
||||
USBDDriverDescriptors hiddJoystickDriverDescriptors = {
|
||||
|
||||
&deviceDescriptor,
|
||||
(USBConfigurationDescriptor *) &configurationDescriptors,
|
||||
0, // No full-speed device qualifier descriptor
|
||||
0, // No full-speed other speed configuration
|
||||
0, // No high-speed device descriptor
|
||||
0, // No high-speed configuration descriptor
|
||||
0, // No high-speed device qualifier descriptor
|
||||
0, // No high-speed other speed configuration descriptor
|
||||
stringDescriptors,
|
||||
4 // Four string descriptors in list
|
||||
};
|
|
@ -0,0 +1,79 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions of the descriptors required by the HID device joystick
|
||||
driver.
|
||||
|
||||
!!!Usage
|
||||
-# Use the hiddJoystickDriverDescriptors variable to initialize a
|
||||
USBDDriver instance.
|
||||
-# Send hiddReportDescriptor to the host when a GET_DESCRIPTOR request
|
||||
for the report descriptor is received.
|
||||
*/
|
||||
|
||||
#ifndef HIDDJOYSTICKDRIVERDESCRIPTORS_H
|
||||
#define HIDDJOYSTICKDRIVERDESCRIPTORS_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <usb/device/core/USBDDriverDescriptors.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Constants: Endpoints
|
||||
HIDDJoystickDriverDescriptors_INTERRUPTIN - Interrupt IN endpoint number.
|
||||
HIDDJoystickDriverDescriptors_INTERRUPTIN_POLLING - Interrupt IN endpoint
|
||||
polling rate (in milliseconds).
|
||||
*/
|
||||
#define HIDDJoystickDriverDescriptors_INTERRUPTIN 1
|
||||
#define HIDDJoystickDriverDescriptors_INTERRUPTIN_POLLING 10
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported variables
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Variables: HID joystick driver descriptors
|
||||
hiddJoystickDriverDescriptors - List of descriptors used by the HID
|
||||
joystick driver.
|
||||
hiddReportDescriptor - Report descriptor used by the driver.
|
||||
*/
|
||||
extern USBDDriverDescriptors hiddJoystickDriverDescriptors;
|
||||
extern const unsigned char hiddReportDescriptor[];
|
||||
|
||||
#endif //#ifndef HIDDJOYSTICKDRIVERDESCRIPTORS_H
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: HIDDJoystickInputReport implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the HIDDJoystickInputReport class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "HIDDJoystickInputReport.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes a joystick input report instance.
|
||||
/// \param report Pointer to a HIDDJoystickInputReport instance.
|
||||
//------------------------------------------------------------------------------
|
||||
void HIDDJoystickInputReport_Initialize(HIDDJoystickInputReport *report)
|
||||
{
|
||||
report->buttons1 = 0;
|
||||
report->buttons2 = 0;
|
||||
report->buttons3 = 0;
|
||||
report->X = 0;
|
||||
report->Y = 0;
|
||||
report->Z = 0;
|
||||
report->Rx = 0;
|
||||
report->Ry = 0;
|
||||
report->Rz = 0;
|
||||
report->S1 = 0;
|
||||
report->S2 = 0;
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating HID Joystick input reports.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Initialize a newly created input report with
|
||||
HIDDJoystickInputReport_Initialize
|
||||
*/
|
||||
|
||||
#ifndef HIDDJOYSTICKINPUTREPORT_H
|
||||
#define HIDDJOYSTICKINPUTREPORT_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// HID input report structure used by the Joystick driver to notify the
|
||||
/// host of pressed keys.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
unsigned char buttons1; // bit 0 - button 1, bit 1 - button 2, ..., mapped to channels 9-16, on if channel > 0
|
||||
unsigned char buttons2; // mapped to channels 17-24, on if channel > 0
|
||||
unsigned char buttons3; // mapped to channels 25-32, on if channel > 0
|
||||
unsigned char X; // analog value, mapped to channel 1
|
||||
unsigned char Y; // analog value, mapped to channel 2
|
||||
unsigned char Z; // analog value, mapped to channel 3
|
||||
unsigned char Rx; // analog value, mapped to channel 4
|
||||
unsigned char Ry; // analog value, mapped to channel 5
|
||||
unsigned char Rz; // analog value, mapped to channel 6
|
||||
unsigned char S1; // analog value, mapped to channel 7
|
||||
unsigned char S2; // analog value, mapped to channel 8
|
||||
|
||||
} __attribute__ ((packed)) HIDDJoystickInputReport; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void HIDDJoystickInputReport_Initialize(HIDDJoystickInputReport *report);
|
||||
|
||||
#endif //#ifndef HIDDJOYSTICKINPUTREPORT_H
|
||||
|
|
@ -76,23 +76,23 @@ static void MSDDriver_Reset(void)
|
|||
/// request to the Mass Storage device driver handler function.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
{
|
||||
MSDDriver_RequestHandler(request);
|
||||
}
|
||||
//void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
//{
|
||||
// MSDDriver_RequestHandler(request);
|
||||
//}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Invoked when the configuration of the device changes. Resets the mass
|
||||
/// storage driver.
|
||||
/// \param cfgnum New configuration number.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
{
|
||||
if (cfgnum > 0) {
|
||||
//void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
//{
|
||||
// if (cfgnum > 0) {
|
||||
|
||||
MSDDriver_Reset();
|
||||
}
|
||||
}
|
||||
// MSDDriver_Reset();
|
||||
// }
|
||||
//}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Driver functions
|
||||
|
|
44
radio/src/targets/sky9x/usb_driver.cpp
Normal file
44
radio/src/targets/sky9x/usb_driver.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
// TODO: enable masstorage & implement choice between masstorage and joystick
|
||||
|
||||
extern "C" {
|
||||
#include "usb/device/hid-joystick/HIDDJoystickDriver.h"
|
||||
#include "usb/device/massstorage/MSDDriver.h"
|
||||
}
|
||||
|
||||
extern "C" void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
|
||||
{
|
||||
// if (selectedUsbMode == USB_JOYSTICK_MODE) {
|
||||
(void)cfgnum;
|
||||
// } else if (selectedUsbMode == USB_MASS_STORAGE_MODE){
|
||||
// MSDDriver_Reset();
|
||||
// }
|
||||
}
|
||||
|
||||
extern "C" void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
|
||||
{
|
||||
// if (selectedUsbMode == USB_JOYSTICK_MODE) {
|
||||
HIDDJoystickDriver_RequestHandler(request);
|
||||
// } else if (selectedUsbMode == USB_MASS_STORAGE_MODE){
|
||||
// MSDDriver_RequestHandler(request);
|
||||
// }
|
||||
}
|
|
@ -180,6 +180,10 @@ TASK_FUNCTION(mixerTask)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X) && !defined(SIMU)
|
||||
usbJoystickUpdate();
|
||||
#endif
|
||||
|
||||
DEBUG_TIMER_START(debugTimerTelemetryWakeup);
|
||||
telemetryWakeup();
|
||||
DEBUG_TIMER_STOP(debugTimerTelemetryWakeup);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue