remove TUSB prefix for class enum definitions

add most of HID USAGE TABLE and definitions etc ...
This commit is contained in:
hathach 2013-02-05 13:57:06 +07:00
parent aa040c4c98
commit aeccdfde3f
11 changed files with 624 additions and 112 deletions

View File

@ -157,24 +157,24 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
{
.Config =
{
.bLength = sizeof(USB_CONFIGURATION_DESCRIPTOR),
.bDescriptorType = USB_CONFIGURATION_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_configuration_t),
.bDescriptorType = TUSB_DESC_CONFIGURATION,
.wTotalLength = sizeof(USB_FS_CONFIGURATION_DESCRIPTOR) - 1, // exclude termination
.bNumInterfaces = TOTAL_INTEFACES,
.bConfigurationValue = 1,
.iConfiguration = 0x00,
.bmAttributes = USB_CONFIG_BUS_POWERED,
.bMaxPower = USB_CONFIG_POWER_MA(100)
.bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER,
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
},
#if IAD_DESC_REQUIRED
// IAD points to CDC Interfaces
.CDC_IAD =
{
.bLength = sizeof(USB_Descriptor_InterfaceAssociation_t),
.bDescriptorType = USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_interface_association_t),
.bDescriptorType = TUSB_DESC_INTERFACE_ASSOCIATION,
.bFirstInterface = 0,
.bInterfaceCount = 2,
@ -192,8 +192,8 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
// CDC Control Interface
.CDC_CCI_Interface =
{
.bLength = sizeof(USB_INTERFACE_DESCRIPTOR),
.bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_INTERFACE,
.bInterfaceNumber = INTERFACE_INDEX_CDC,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
@ -233,8 +233,8 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
.CDC_NotificationEndpoint =
{
.bLength = sizeof(USB_ENDPOINT_DESCRIPTOR),
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_ENDPOINT,
.bEndpointAddress = CDC_NOTIFICATION_EP,
.bmAttributes = USB_ENDPOINT_TYPE_INTERRUPT,
.wMaxPacketSize = CDC_NOTIFICATION_EP_MAXPACKETSIZE,
@ -244,8 +244,8 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
// CDC Data Interface
.CDC_DCI_Interface =
{
.bLength = sizeof(USB_INTERFACE_DESCRIPTOR),
.bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_INTERFACE,
.bInterfaceNumber = INTERFACE_INDEX_CDC+1,
.bAlternateSetting = 0x00,
.bNumEndpoints = 2,
@ -257,8 +257,8 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
.CDC_DataOutEndpoint =
{
.bLength = sizeof(USB_ENDPOINT_DESCRIPTOR),
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_ENDPOINT,
.bEndpointAddress = CDC_DATA_EP_OUT,
.bmAttributes = USB_ENDPOINT_TYPE_BULK,
.wMaxPacketSize = CDC_DATA_EP_MAXPACKET_SIZE,
@ -267,8 +267,8 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
.CDC_DataInEndpoint =
{
.bLength = sizeof(USB_ENDPOINT_DESCRIPTOR),
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_ENDPOINT,
.bEndpointAddress = CDC_DATA_EP_IN,
.bmAttributes = USB_ENDPOINT_TYPE_BULK,
.wMaxPacketSize = CDC_DATA_EP_MAXPACKET_SIZE,
@ -280,14 +280,14 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
///// USB HID Keyboard interface
.HID_KeyboardInterface =
{
.bLength = sizeof(USB_INTERFACE_DESCRIPTOR),
.bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_INTERFACE,
.bInterfaceNumber = INTERFACE_INDEX_HID_KEYBOARD,
.bAlternateSetting = 0x00,
.bNumEndpoints = 1,
.bInterfaceClass = USB_DEVICE_CLASS_HUMAN_INTERFACE,
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
.bInterfaceClass = TUSB_CLASS_HID,
.bInterfaceSubClass = TUSB_HID_SUBCLASS_BOOT,
.bInterfaceProtocol = TUSB_HID_PROTOCOL_KEYBOARD,
.iInterface = 0x00
},
@ -307,8 +307,8 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
.HID_KeyboardEndpoint =
{
.bLength = sizeof(USB_ENDPOINT_DESCRIPTOR),
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_ENDPOINT,
.bEndpointAddress = HID_KEYBOARD_EP_IN,
.bmAttributes = USB_ENDPOINT_TYPE_INTERRUPT,
.wMaxPacketSize = 0x08,
@ -319,13 +319,13 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
.HID_MouseInterface =
{
.bLength = sizeof(USB_INTERFACE_DESCRIPTOR),
.bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_INTERFACE,
.bInterfaceNumber = INTERFACE_INDEX_HID_MOUSE,
.bAlternateSetting = 0x00,
.bNumEndpoints = 1,
.bInterfaceClass = USB_DEVICE_CLASS_HUMAN_INTERFACE,
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
.bInterfaceClass = TUSB_CLASS_HID,
.bInterfaceSubClass = TUSB_HID_SUBCLASS_BOOT,
.bInterfaceProtocol = HID_PROTOCOL_MOUSE,
.iInterface = 0x00
},
@ -346,8 +346,8 @@ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_F
.HID_MouseEndpoint =
{
.bLength = sizeof(USB_ENDPOINT_DESCRIPTOR),
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR_TYPE,
.bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_ENDPOINT,
.bEndpointAddress = HID_MOUSE_EP_IN,
.bmAttributes = USB_ENDPOINT_TYPE_INTERRUPT,
.wMaxPacketSize = 0x08,

View File

@ -115,39 +115,39 @@ typedef ATTR_PREPACKED struct ATTR_PACKED _USB_STR_DESCRIPTOR
///////////////////////////////////////////////////////////////////////
typedef struct
{
USB_CONFIGURATION_DESCRIPTOR Config;
tusb_descriptor_configuration_t Config;
#if IAD_DESC_REQUIRED
USB_Descriptor_InterfaceAssociation_t CDC_IAD;
tusb_descriptor_interface_association_t CDC_IAD;
#endif
#ifdef TUSB_CFG_DEVICE_CDC
//CDC - Serial
//CDC Control Interface
USB_INTERFACE_DESCRIPTOR CDC_CCI_Interface;
tusb_descriptor_interface_t CDC_CCI_Interface;
CDC_HEADER_DESCRIPTOR CDC_Header;
CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR CDC_ACM;
CDC_UNION_1SLAVE_DESCRIPTOR CDC_Union;
USB_ENDPOINT_DESCRIPTOR CDC_NotificationEndpoint;
tusb_descriptor_endpoint_t CDC_NotificationEndpoint;
//CDC Data Interface
USB_INTERFACE_DESCRIPTOR CDC_DCI_Interface;
USB_ENDPOINT_DESCRIPTOR CDC_DataOutEndpoint;
USB_ENDPOINT_DESCRIPTOR CDC_DataInEndpoint;
tusb_descriptor_interface_t CDC_DCI_Interface;
tusb_descriptor_endpoint_t CDC_DataOutEndpoint;
tusb_descriptor_endpoint_t CDC_DataInEndpoint;
#endif
#ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
//Keyboard HID Interface
USB_INTERFACE_DESCRIPTOR HID_KeyboardInterface;
tusb_descriptor_interface_t HID_KeyboardInterface;
HID_DESCRIPTOR HID_KeyboardHID;
USB_ENDPOINT_DESCRIPTOR HID_KeyboardEndpoint;
tusb_descriptor_endpoint_t HID_KeyboardEndpoint;
#endif
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
//Mouse HID Interface
USB_INTERFACE_DESCRIPTOR HID_MouseInterface;
tusb_descriptor_interface_t HID_MouseInterface;
HID_DESCRIPTOR HID_MouseHID;
USB_ENDPOINT_DESCRIPTOR HID_MouseEndpoint;
tusb_descriptor_endpoint_t HID_MouseEndpoint;
#endif
unsigned char ConfigDescTermination;

View File

@ -46,12 +46,12 @@ extern class_hid_keyboard_info_t keyboard_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
tusb_keyboard_report_t sample_key[2] =
{
{
.modifier = TUSB_KEYBOARD_MODIFIER_LEFTCTRL,
.keycode = {TUSB_KEYBOARD_KEYCODE_a}
.modifier = KEYBOARD_MODIFIER_LEFTCTRL,
.keycode = {KEYBOARD_KEYCODE_a}
},
{
.modifier = TUSB_KEYBOARD_MODIFIER_RIGHTALT,
.keycode = {TUSB_KEYBOARD_KEYCODE_z}
.modifier = KEYBOARD_MODIFIER_RIGHTALT,
.keycode = {KEYBOARD_KEYCODE_z}
}
};
@ -78,8 +78,8 @@ void setUp(void)
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = TUSB_CLASS_HID,
.bInterfaceSubClass = TUSB_HID_SUBCLASS_BOOT,
.bInterfaceProtocol = TUSB_HID_PROTOCOL_KEYBOARD,
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
.iInterface = 0
});

View File

@ -38,6 +38,7 @@
#include "unity.h"
#include "errors.h"
#include "usbh.h"
#include "descriptor_test.h"
#include "mock_osal.h"
#include "mock_hcd.h"
#include "mock_usbh_hcd.h"
@ -128,6 +129,7 @@ usbh_enumerate_t enum_connect =
};
extern usbh_device_addr0_t device_addr0;
void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call)
{
TEST_ASSERT_EQUAL_PTR(enum_queue_hdl, queue_hdl);
@ -140,49 +142,32 @@ void semaphore_wait_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, t
(*p_error) = TUSB_ERROR_NONE;
}
tusb_error_t pipe_control_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call)
tusb_error_t get_device_desc_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call)
{
tusb_descriptor_device_t dev_desc =
{
.bLength = sizeof(tusb_descriptor_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
TEST_ASSERT(num_call < 2);
TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest);
TEST_ASSERT_EQUAL(TUSB_DESC_DEVICE, p_request->wValue >> 8);
.bMaxPacketSize0 = 64,
memcpy(data, &desc_device, p_request->wLength);
.idVendor = 0x1FC9,
.idProduct = 0x4000,
.bcdDevice = 0x0100,
return TUSB_ERROR_NONE;
}
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x03,
tusb_error_t set_device_addr_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call)
{
TEST_ASSERT_EQUAL(TUSB_REQUEST_SET_ADDRESS, p_request->bRequest);
TEST_ASSERT_EQUAL(p_request->wValue, 1);
return TUSB_ERROR_NONE;
}
.bNumConfigurations = 0x02
};
tusb_error_t get_configuration_desc_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call)
{
TEST_ASSERT(num_call < 2);
switch (p_request->bRequest)
{
case TUSB_REQUEST_GET_DESCRIPTOR:
switch (p_request->wValue >> 8)
{
case TUSB_DESC_DEVICE:
memcpy(data, &dev_desc, p_request->wLength);
break;
TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest);
TEST_ASSERT_EQUAL(TUSB_DESC_CONFIGURATION, p_request->wValue >> 8);
default:
TEST_FAIL();
break;
}
break;
case TUSB_REQUEST_SET_ADDRESS:
TEST_ASSERT_EQUAL(p_request->wValue, 1);
break;
}
memcpy(data, &desc_device, p_request->wLength);
return TUSB_ERROR_NONE;
}
@ -199,16 +184,15 @@ void test_enum_task_connect(void)
hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE);
// get 8-byte of device descriptor
hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
hcd_pipe_control_xfer_StubWithCallback(get_device_desc_stub);
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
// set device address
hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
hcd_pipe_control_xfer_StubWithCallback(set_device_addr_stub);
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
hcd_addr0_close_IgnoreAndReturn(TUSB_ERROR_NONE);
}
usbh_enumeration_task();
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[0].status);
@ -217,6 +201,16 @@ void test_enum_task_connect(void)
TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[0].hub_addr);
TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[0].hub_port);
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
hcd_pipe_control_xfer_StubWithCallback(get_device_desc_stub); // get full device descriptor
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
hcd_pipe_control_xfer_StubWithCallback(get_configuration_desc_stub); // get 9 bytes of configuration descriptor
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
hcd_pipe_control_xfer_StubWithCallback(get_configuration_desc_stub); // get full-length configuration descriptor
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
}
void test_enum_task_disconnect(void)

View File

@ -0,0 +1,159 @@
/*
* descriptor_test.c
*
* Created on: Feb 5, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR 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.
*
* This file is part of the tiny usb stack.
*/
#include "tusb_option.h"
#include "descriptor_test.h"
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
tusb_descriptor_device_t desc_device =
{
.bLength = sizeof(tusb_descriptor_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = 64,
.idVendor = 0x1FC9,
.idProduct = 0x4000,
.bcdDevice = 0x0100,
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x03,
.bNumConfigurations = 0x02
} ;
//
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
const uint8_t keyboard_report_descriptor[] = {
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ),
HID_USAGE_MIN ( 224 ),
HID_USAGE_MAX ( 231 ),
HID_LOGICAL_MIN ( 0 ),
HID_LOGICAL_MAX ( 1 ),
HID_REPORT_COUNT ( 8 ), /* 8 bits */
HID_REPORT_SIZE ( 1 ),
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* maskable modifier key */
HID_REPORT_COUNT ( 1 ),
HID_REPORT_SIZE ( 8 ),
HID_INPUT ( HID_CONSTANT ), /* reserved */
HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
HID_USAGE_MIN ( 1 ),
HID_USAGE_MAX ( 5 ),
HID_REPORT_COUNT ( 5 ),
HID_REPORT_SIZE ( 1 ),
HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* 5-bit Led report */
HID_REPORT_COUNT ( 1 ),
HID_REPORT_SIZE ( 3 ), /* led padding */
HID_OUTPUT ( HID_CONSTANT ),
HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
HID_USAGE_MIN ( 0 ),
HID_USAGE_MAX ( 101 ),
HID_LOGICAL_MIN ( 0 ),
HID_LOGICAL_MAX ( 101 ),
HID_REPORT_COUNT ( 6 ),
HID_REPORT_SIZE ( 8 ),
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ), /* keycodes array 6 items */
HID_COLLECTION_END
};
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
const app_configuration_desc_t desc_configuration =
{
.configuration =
{
.bLength = sizeof(tusb_descriptor_configuration_t),
.bDescriptorType = TUSB_DESC_CONFIGURATION,
.wTotalLength = sizeof(app_configuration_desc_t) - 1, // exclude termination
.bNumInterfaces = 1,
.bConfigurationValue = 1,
.iConfiguration = 0x00,
.bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER,
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
},
///// USB HID Keyboard interface
.keyboard_interface =
{
.bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0x00,
.bNumEndpoints = 1,
.bInterfaceClass = TUSB_CLASS_HID,
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
.iInterface = 0x00
},
.keyboard_hid =
{
.bLength = sizeof(tusb_hid_descriptor_hid_t),
.bDescriptorType = HID_DESC_HID,
.bcdHID = 0x0111,
.bCountryCode = HID_Local_NotSupported,
.bNumDescriptors = 1,
.bReportType = HID_DESC_REPORT,
.wReportLength = sizeof(keyboard_report_descriptor)
},
.keyboard_endpoint =
{
.bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_ENDPOINT,
.bEndpointAddress = 0x81,
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
.wMaxPacketSize = 0x08,
.bInterval = 0x0A
},
.ConfigDescTermination = 0,
};

View File

@ -0,0 +1,109 @@
/*
* descriptor_test.h
*
* Created on: Feb 5, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR 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.
*
* This file is part of the tiny usb stack.
*/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_TEST_DESCRIPTOR_H_
#define _TUSB_TEST_DESCRIPTOR_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "common/common.h"
#include "class/hid.h"
typedef struct
{
tusb_descriptor_configuration_t configuration;
#if 0 //&& IAD_DESC_REQUIRED
tusb_descriptor_interface_association_t CDC_IAD;
#endif
#if 0 //&& TUSB_CFG_DEVICE_CDC
//CDC - Serial
//CDC Control Interface
tusb_descriptor_interface_t CDC_CCI_Interface;
CDC_HEADER_DESCRIPTOR CDC_Header;
CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR CDC_ACM;
CDC_UNION_1SLAVE_DESCRIPTOR CDC_Union;
tusb_descriptor_endpoint_t CDC_NotificationEndpoint;
//CDC Data Interface
tusb_descriptor_interface_t CDC_DCI_Interface;
tusb_descriptor_endpoint_t CDC_DataOutEndpoint;
tusb_descriptor_endpoint_t CDC_DataInEndpoint;
#endif
#if 1 // || TUSB_CFG_DEVICE_HID_KEYBOARD
//Keyboard HID Interface
tusb_descriptor_interface_t keyboard_interface;
tusb_hid_descriptor_hid_t keyboard_hid;
tusb_descriptor_endpoint_t keyboard_endpoint;
#endif
#if 0 // && TUSB_CFG_DEVICE_HID_MOUSE
//Mouse HID Interface
tusb_descriptor_interface_t HID_MouseInterface;
HID_DESCRIPTOR HID_MouseHID;
tusb_descriptor_endpoint_t HID_MouseEndpoint;
#endif
unsigned char ConfigDescTermination;
} app_configuration_desc_t;
extern tusb_descriptor_device_t desc_device;
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_TEST_DESCRIPTOR_H_ */
/** @} */

View File

@ -58,16 +58,34 @@
#include "common/common.h"
enum {
TUSB_HID_SUBCLASS_NONE = 0,
TUSB_HID_SUBCLASS_BOOT = 1
HID_SUBCLASS_NONE = 0,
HID_SUBCLASS_BOOT = 1
};
enum {
TUSB_HID_PROTOCOL_NONE = 0,
TUSB_HID_PROTOCOL_KEYBOARD = 1,
TUSB_HID_PROTOCOL_MOUSE = 2
HID_PROTOCOL_NONE = 0,
HID_PROTOCOL_KEYBOARD = 1,
HID_PROTOCOL_MOUSE = 2
};
/** \struct tusb_mouse_report_t
enum {
HID_DESC_HID = 0x21,
HID_DESC_REPORT = 0x22,
HID_DESC_PHYSICAL = 0x23
};
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
uint8_t bReportType; /**< Type of HID class report. */
uint16_t wReportLength; /**< the total size of the Report descriptor. */
} tusb_hid_descriptor_hid_t;
/**
* \brief Standard HID Boot Protocol Mouse Report.
*
* Type define for a standard Boot Protocol Mouse report
@ -79,7 +97,7 @@ typedef ATTR_PREPACKED struct
int8_t y; /**< Current delta y movement on the mouse. */
} ATTR_PACKED tusb_mouse_report_t;
/** \struct tusb_keyboard_report_t
/**
* \brief Standard HID Boot Protocol Keyboard Report.
*
* Type define for a standard Boot Protocol Keyboard report
@ -91,42 +109,42 @@ typedef ATTR_PREPACKED struct
uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
} ATTR_PACKED tusb_keyboard_report_t;
/** \enum USB_HID_MOUSE_BUTTON_CODE
/**
* \brief buttons codes for HID mouse
*/
enum USB_HID_MOUSE_BUTTON_CODE
enum
{
HID_MOUSEBUTTON_RIGHT = 0,
HID_MOUSEBUTTON_LEFT = 1,
HID_MOUSEBUTTON_MIDDLE = 2
};
/** \enum USB_HID_KB_KEYMODIFIER_CODE
/**
* \brief KB modifier codes for HID KB
*/
enum TUSB_KEYBOARD_MODIFIER_CODE
enum
{
TUSB_KEYBOARD_MODIFIER_LEFTCTRL = BIN8(00000001),
TUSB_KEYBOARD_MODIFIER_LEFTSHIFT = BIN8(00000010),
TUSB_KEYBOARD_MODIFIER_LEFTALT = BIN8(00000100),
TUSB_KEYBOARD_MODIFIER_LEFTGUI = BIN8(00001000),
TUSB_KEYBOARD_MODIFIER_RIGHTCTRL = BIN8(00010000),
TUSB_KEYBOARD_MODIFIER_RIGHTSHIFT = BIN8(00100000),
TUSB_KEYBOARD_MODIFIER_RIGHTALT = BIN8(01000000),
TUSB_KEYBOARD_MODIFIER_RIGHTGUI = BIN8(10000000)
KEYBOARD_MODIFIER_LEFTCTRL = BIN8(00000001),
KEYBOARD_MODIFIER_LEFTSHIFT = BIN8(00000010),
KEYBOARD_MODIFIER_LEFTALT = BIN8(00000100),
KEYBOARD_MODIFIER_LEFTGUI = BIN8(00001000),
KEYBOARD_MODIFIER_RIGHTCTRL = BIN8(00010000),
KEYBOARD_MODIFIER_RIGHTSHIFT = BIN8(00100000),
KEYBOARD_MODIFIER_RIGHTALT = BIN8(01000000),
KEYBOARD_MODIFIER_RIGHTGUI = BIN8(10000000)
};
enum TUSB_KEYBOARD_KEYCODE
enum
{
TUSB_KEYBOARD_KEYCODE_a = 0x04,
TUSB_KEYBOARD_KEYCODE_z = 0x1d,
KEYBOARD_KEYCODE_a = 0x04,
KEYBOARD_KEYCODE_z = 0x1d,
TUSB_KEYBOARD_KEYCODE_1 = 0x1e,
TUSB_KEYBOARD_KEYCODE_0 = 0x27
KEYBOARD_KEYCODE_1 = 0x1e,
KEYBOARD_KEYCODE_0 = 0x27
// TODO complete keycode table
};
/** \enum USB_HID_LOCAL_CODE
/**
* \brief Local Country code for HID
*/
enum USB_HID_LOCAL_CODE
@ -169,6 +187,218 @@ enum USB_HID_LOCAL_CODE
HID_Local_Turkish_F
};
//--------------------------------------------------------------------+
// REPORT DESCRIPTOR
//--------------------------------------------------------------------+
//------------- ITEM & TAG -------------//
#define HID_REPORT_DATA_0(data)
#define HID_REPORT_DATA_1(data) data
#define HID_REPORT_DATA_2(data) U16_TO_U8S_LE(data)
#define HID_REPORT_DATA_3(data) U32_TO_U8S_LE(data)
#define HID_REPORT_ITEM(data, tag, type, size) \
( (tag << 4) | (type << 2) | size), HID_REPORT_DATA_##size(data)
#define RI_TYPE_MAIN 0
#define RI_TYPE_GLOBAL 1
#define RI_TYPE_LOCAL 2
//------------- MAIN ITEMS 6.2.2.4 -------------//
#define HID_INPUT(x) HID_REPORT_ITEM(x, 8, RI_TYPE_MAIN, 1)
#define HID_OUTPUT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_MAIN, 1)
#define HID_COLLECTION(x) HID_REPORT_ITEM(x, 10, RI_TYPE_MAIN, 1)
#define HID_FEATURE(x) HID_REPORT_ITEM(x, 11, RI_TYPE_MAIN, 1)
#define HID_COLLECTION_END HID_REPORT_ITEM(x, 12, RI_TYPE_MAIN, 0)
//------------- INPUT, OUTPUT, FEATURE 6.2.2.5 -------------//
#define HID_DATA (0<<0)
#define HID_CONSTANT (1<<0)
#define HID_ARRAY (0<<1)
#define HID_VARIABLE (1<<1)
#define HID_ABSOLUTE (0<<2)
#define HID_RELATIVE (1<<2)
#define HID_WRAP_NO (0<<3)
#define HID_WRAP (1<<3)
#define HID_LINEAR (0<<4)
#define HID_NONLINEAR (1<<4)
#define HID_PREFERRED_STATE (0<<5)
#define HID_PREFERRED_NO (1<<5)
#define HID_NO_NULL_POSITION (0<<6)
#define HID_NULL_STATE (1<<6)
#define HID_NON_VOLATILE (0<<7)
#define HID_VOLATILE (1<<7)
#define HID_BITFIELD (0<<8)
#define HID_BUFFERED_BYTES (1<<8)
//------------- COLLECTION ITEM 6.2.2.6 -------------//
enum {
HID_COLLECTION_PHYSICAL = 0,
HID_COLLECTION_APPLICATION,
HID_COLLECTION_LOGICAL,
HID_COLLECTION_REPORT,
HID_COLLECTION_NAMED_ARRAY,
HID_COLLECTION_USAGE_SWITCH,
HID_COLLECTION_USAGE_MODIFIER
};
//------------- GLOBAL ITEMS 6.2.2.7 -------------//
#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, 1)
#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, n)
#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, 1)
#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, n)
#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, 1)
#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, n)
#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, 1)
#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, n)
#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, 1)
#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, n)
#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, 1)
#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, n)
#define HID_UNIT(x) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, 1)
#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, n)
#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, 1)
#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, n)
#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, 1)
#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, n)
#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, 1)
#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, n)
#define HID_PUSH HID_REPORT_ITEM(x, 10, RI_TYPE_GLOBAL, 0)
#define HID_POP HID_REPORT_ITEM(x, 11, RI_TYPE_GLOBAL, 0)
//------------- LOCAL ITEMS 6.2.2.8 -------------//
#define HID_USAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, 1)
#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, n)
#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, 1)
#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, n)
#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, 1)
#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, n)
//--------------------------------------------------------------------+
// Usage Table
//--------------------------------------------------------------------+
/// HID Usage Table - Table 1: Usage Page Summary
enum {
HID_USAGE_PAGE_DESKTOP = 0x01,
HID_USAGE_PAGE_SIMULATE = 0x02,
HID_USAGE_PAGE_VIRTUAL_REALITY = 0x03,
HID_USAGE_PAGE_SPORT = 0x04,
HID_USAGE_PAGE_GAME = 0x05,
HID_USAGE_PAGE_GENERIC_DEVICE = 0x06,
HID_USAGE_PAGE_KEYBOARD = 0x07,
HID_USAGE_PAGE_LED = 0x08,
HID_USAGE_PAGE_BUTTON = 0x09,
HID_USAGE_PAGE_ORDINAL = 0x0a,
HID_USAGE_PAGE_TELEPHONY = 0x0b,
HID_USAGE_PAGE_CONSUMER = 0x0c,
HID_USAGE_PAGE_DIGITIZER = 0x0d,
HID_USAGE_PAGE_PID = 0x0f,
HID_USAGE_PAGE_UNICODE = 0x10,
HID_USAGE_PAGE_ALPHA_DISPLAY = 0x14,
HID_USAGE_PAGE_MEDICAL = 0x40,
HID_USAGE_PAGE_MONITOR = 0x80, //0x80 - 0x83
HID_USAGE_PAGE_POWER = 0x84, // 0x084 - 0x87
HID_USAGE_PAGE_BARCODE_SCANNER = 0x8c,
HID_USAGE_PAGE_SCALE = 0x8d,
HID_USAGE_PAGE_MSR = 0x8e,
HID_USAGE_PAGE_CAMERA = 0x90,
HID_USAGE_PAGE_ARCADE = 0x91,
HID_USAGE_PAGE_VENDOR = 0xFFFF // 0xFF00 - 0xFFFF
};
/// HID Usage Table - Table 6: Generic Desktop Page
enum {
HID_USAGE_DESKTOP_POINTER = 0x01,
HID_USAGE_DESKTOP_MOUSE = 0x02,
HID_USAGE_DESKTOP_JOYSTICK = 0x04,
HID_USAGE_DESKTOP_GAMEPAD = 0x05,
HID_USAGE_DESKTOP_KEYBOARD = 0x06,
HID_USAGE_DESKTOP_KEYPAD = 0x07,
HID_USAGE_DESKTOP_MULTI_AXIS_CONTROLLER = 0x08,
HID_USAGE_DESKTOP_TABLET_PC_SYSTEM = 0x09,
HID_USAGE_DESKTOP_X = 0x30,
HID_USAGE_DESKTOP_Y = 0x31,
HID_USAGE_DESKTOP_Z = 0x32,
HID_USAGE_DESKTOP_RX = 0x33,
HID_USAGE_DESKTOP_RY = 0x34,
HID_USAGE_DESKTOP_RZ = 0x35,
HID_USAGE_DESKTOP_SLIDER = 0x36,
HID_USAGE_DESKTOP_DIAL = 0x37,
HID_USAGE_DESKTOP_WHEEL = 0x38,
HID_USAGE_DESKTOP_HAT_SWITCH = 0x39,
HID_USAGE_DESKTOP_COUNTED_BUFFER = 0x3a,
HID_USAGE_DESKTOP_BYTE_COUNT = 0x3b,
HID_USAGE_DESKTOP_MOTION_WAKEUP = 0x3c,
HID_USAGE_DESKTOP_START = 0x3d,
HID_USAGE_DESKTOP_SELECT = 0x3e,
HID_USAGE_DESKTOP_VX = 0x40,
HID_USAGE_DESKTOP_VY = 0x41,
HID_USAGE_DESKTOP_VZ = 0x42,
HID_USAGE_DESKTOP_VBRX = 0x43,
HID_USAGE_DESKTOP_VBRY = 0x44,
HID_USAGE_DESKTOP_VBRZ = 0x45,
HID_USAGE_DESKTOP_VNO = 0x46,
HID_USAGE_DESKTOP_FEATURE_NOTIFICATION = 0x47,
HID_USAGE_DESKTOP_RESOLUTION_MULTIPLIER = 0x48,
HID_USAGE_DESKTOP_SYSTEM_CONTROL = 0x80,
HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN = 0x81,
HID_USAGE_DESKTOP_SYSTEM_SLEEP = 0x82,
HID_USAGE_DESKTOP_SYSTEM_WAKE_UP = 0x83,
HID_USAGE_DESKTOP_SYSTEM_CONTEXT_MENU = 0x84,
HID_USAGE_DESKTOP_SYSTEM_MAIN_MENU = 0x85,
HID_USAGE_DESKTOP_SYSTEM_APP_MENU = 0x86,
HID_USAGE_DESKTOP_SYSTEM_MENU_HELP = 0x87,
HID_USAGE_DESKTOP_SYSTEM_MENU_EXIT = 0x88,
HID_USAGE_DESKTOP_SYSTEM_MENU_SELECT = 0x89,
HID_USAGE_DESKTOP_SYSTEM_MENU_RIGHT = 0x8A,
HID_USAGE_DESKTOP_SYSTEM_MENU_LEFT = 0x8B,
HID_USAGE_DESKTOP_SYSTEM_MENU_UP = 0x8C,
HID_USAGE_DESKTOP_SYSTEM_MENU_DOWN = 0x8D,
HID_USAGE_DESKTOP_SYSTEM_COLD_RESTART = 0x8E,
HID_USAGE_DESKTOP_SYSTEM_WARM_RESTART = 0x8F,
HID_USAGE_DESKTOP_DPAD_UP = 0x90,
HID_USAGE_DESKTOP_DPAD_DOWN = 0x91,
HID_USAGE_DESKTOP_DPAD_RIGHT = 0x92,
HID_USAGE_DESKTOP_DPAD_LEFT = 0x93,
HID_USAGE_DESKTOP_SYSTEM_DOCK = 0xA0,
HID_USAGE_DESKTOP_SYSTEM_UNDOCK = 0xA1,
HID_USAGE_DESKTOP_SYSTEM_SETUP = 0xA2,
HID_USAGE_DESKTOP_SYSTEM_BREAK = 0xA3,
HID_USAGE_DESKTOP_SYSTEM_DEBUGGER_BREAK = 0xA4,
HID_USAGE_DESKTOP_APPLICATION_BREAK = 0xA5,
HID_USAGE_DESKTOP_APPLICATION_DEBUGGER_BREAK = 0xA6,
HID_USAGE_DESKTOP_SYSTEM_SPEAKER_MUTE = 0xA7,
HID_USAGE_DESKTOP_SYSTEM_HIBERNATE = 0xA8,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INVERT = 0xB0,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INTERNAL = 0xB1,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_EXTERNAL = 0xB2,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_BOTH = 0xB3,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_DUAL = 0xB4,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_TOGGLE_INT_EXT = 0xB5,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_SWAP_PRIMARY_SECONDARY = 0xB6,
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_LCD_AUTOSCALE = 0xB7
};
#ifdef __cplusplus
}
#endif

View File

@ -86,6 +86,18 @@
#define STRING_(x) #x // stringify without expand
#define XSTRING_(x) STRING_(x) // expand then stringify
#define U16_HIGH_U8(u16) ((uint8_t) (((u16) > 8) & 0x00ff))
#define U16_LOW_U8(u16) ((uint8_t) ((u16) & 0x00ff))
#define U16_TO_U8S_BE(u16) U16_HIGH_U8(u16), U16_LOW_U8(u16)
#define U16_TO_U8S_LE(u16) U16_LOW_U8(u16), U16_HIGH_U8(u16)
#define U32_B1_U8(u32) ((uint8_t) (((u32) > 24) & 0x000000ff)) // MSB
#define U32_B2_U8(u32) ((uint8_t) (((u32) > 16) & 0x000000ff))
#define U32_B3_U8(u32) ((uint8_t) (((u32) > 8) & 0x000000ff))
#define U32_B4_U8(u32) ((uint8_t) ((u32) & 0x000000ff)) // LSB
#define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32)
#define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32)
/// form an uint32_t from 4 x uint8_t
static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) ATTR_ALWAYS_INLINE ATTR_CONST;
static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)

View File

@ -114,7 +114,14 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
uint8_t bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
ATTR_PREPACKED struct ATTR_PACKED {
uint8_t xfer : 2;
uint8_t sync : 2;
uint8_t usage : 2;
uint8_t : 2;
} bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
uint16_t wMaxPacketSize ; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
} tusb_descriptor_endpoint_t;

View File

@ -61,7 +61,7 @@
#include "common/binary.h"
typedef ATTR_PREPACKED struct ATTR_PACKED {
struct {
ATTR_PREPACKED struct ATTR_PACKED {
uint8_t recipient : 5; /**< Recipient type. */
uint8_t type : 2; /**< Request type. */
uint8_t direction : 1; /**< Direction type. */

View File

@ -161,6 +161,7 @@ enum {
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5)
};
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
#ifdef __cplusplus
}
#endif