summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-06-03 14:31:17 +0700
committerhathach <[email protected]>2013-06-03 14:31:17 +0700
commitb527e6ec4a9d0b6ecad5a6ce74b27458d1cd24be (patch)
tree2d7c009e15d1fd73d9df62217c9e4a748ebe026f /tinyusb
parent7d78fc1baf24c537ea7386f698e1e20ed80f16ba (diff)
refractor tusb_descriptors
usbd device_class_driver added & tested HID mouse for device (work together with hid keyboard) rename DEVICE_ROM_REG_BASE, DEVICE_ROM_DRIVER_ADDR
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/hid_device.c37
-rw-r--r--tinyusb/class/hid_device.h2
-rw-r--r--tinyusb/class/hid_host.c2
-rw-r--r--tinyusb/core/std_descriptors.h8
-rw-r--r--tinyusb/device/dcd.c2
-rw-r--r--tinyusb/device/dcd_lpc11uxx_lpc13xx.h4
-rw-r--r--tinyusb/device/dcd_lpc18xx_lpc43xx.h4
-rw-r--r--tinyusb/device/dcd_nxp_romdriver.c16
-rw-r--r--tinyusb/device/dcd_nxp_romdriver.h4
-rw-r--r--tinyusb/device/usbd.c24
-rw-r--r--tinyusb/device/usbd.h5
11 files changed, 76 insertions, 32 deletions
diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c
index 97e81627d..6d4d46fc9 100644
--- a/tinyusb/class/hid_device.c
+++ b/tinyusb/class/hid_device.c
@@ -58,6 +58,7 @@ static volatile bool bKeyChanged = false;
#endif
#if TUSB_CFG_DEVICE_HID_MOUSE
+TUSB_CFG_ATTR_USBRAM uint8_t hidd_mouse_buffer[1024]; // TODO memory reduce
TUSB_CFG_ATTR_USBRAM tusb_mouse_report_t hid_mouse_report;
static volatile bool bMouseChanged = false;
#endif
@@ -81,7 +82,7 @@ ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event);
//--------------------------------------------------------------------+
// CLASS-USBH API (don't require to verify parameters)
//--------------------------------------------------------------------+
-tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc)
+tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
{
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
@@ -90,9 +91,37 @@ tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc)
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
ASSERT_INT(HID_DESC_TYPE_HID, p_desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
- ASSERT_STATUS( hidd_interface_init(p_interface_desc,
- app_tusb_keyboard_desc_report, p_desc_hid->wReportLength,
- hidd_keyboard_buffer , sizeof(hidd_keyboard_buffer)) );
+ if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
+ {
+ switch(p_interface_desc->bInterfaceProtocol)
+ {
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ case HID_PROTOCOL_KEYBOARD:
+ ASSERT_STATUS( hidd_interface_init(p_interface_desc,
+ app_tusb_keyboard_desc_report, p_desc_hid->wReportLength,
+ hidd_keyboard_buffer , sizeof(hidd_keyboard_buffer)) );
+ break;
+ #endif
+
+ #if TUSB_CFG_DEVICE_HID_MOUSE
+ case HID_PROTOCOL_MOUSE:
+ ASSERT_STATUS( hidd_interface_init(p_interface_desc,
+ app_tusb_mouse_desc_report, p_desc_hid->wReportLength,
+ hidd_mouse_buffer , sizeof(hidd_mouse_buffer)) );
+ break;
+ #endif
+
+ default: // TODO unknown, unsupported protocol --> skip this interface
+ return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
+ }
+ *p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
+ }else
+ {
+ // open generic
+ *p_length = 0;
+ return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
+ }
+
return TUSB_ERROR_NONE;
}
diff --git a/tinyusb/class/hid_device.h b/tinyusb/class/hid_device.h
index 4dde81ab0..d3a87fb84 100644
--- a/tinyusb/class/hid_device.h
+++ b/tinyusb/class/hid_device.h
@@ -66,7 +66,7 @@ tusb_error_t tusbd_hid_mouse_send_report(uint8_t buttons, int8_t x, int8_t y);
#ifdef _TINY_USB_SOURCE_FILE_
#include "device/romdriver/mw_usbd_rom_api.h" // TODO remove rom driver dependency
-tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc);
+tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
tusb_error_t hidd_configured(USBD_HANDLE_T hUsb);
#endif
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index 4ba1556dd..b109430af 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -238,7 +238,7 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
break;
#endif
- default: // unknown protocol --> skip this interface
+ default: // TODO unknown, unsupported protocol --> skip this interface
return TUSB_ERROR_NONE;
}
*p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
diff --git a/tinyusb/core/std_descriptors.h b/tinyusb/core/std_descriptors.h
index 4cef29746..854bbe06f 100644
--- a/tinyusb/core/std_descriptors.h
+++ b/tinyusb/core/std_descriptors.h
@@ -53,6 +53,8 @@
extern "C" {
#endif
+#define STRING_LEN_BYTE2UNICODE(n) (2 + ((n)<<1))
+
//--------------------------------------------------------------------+
// STANDARD DESCRIPTORS
//--------------------------------------------------------------------+
@@ -177,6 +179,12 @@ typedef ATTR_PREPACKED struct ATTR_PACKED
uint8_t bDescriptorType ; ///< Descriptor Type
} tusb_descriptor_header_t;
+//typedef ATTR_PACKED_STRUCT(struct)
+//{
+// uint8_t bLength ; ///< Size of this descriptor in bytes
+// uint8_t bDescriptorType ; ///< Descriptor Type
+// uint16_t unicode_string[];
+//} tusb_descriptor_string_t;
#ifdef __cplusplus
}
diff --git a/tinyusb/device/dcd.c b/tinyusb/device/dcd.c
index 4406b911c..3b36b649f 100644
--- a/tinyusb/device/dcd.c
+++ b/tinyusb/device/dcd.c
@@ -90,7 +90,7 @@ tusb_error_t dcd_init(uint8_t coreid)
USBD_API_INIT_PARAM_T usb_param =
{
- .usb_reg_base = DEVICE_ROM_REG_BASE,
+ .usb_reg_base = NXP_ROMDRIVER_REG_BASE,
.max_num_ep = USB_MAX_EP_NUM,
.mem_base = membase,
.mem_size = memsize,
diff --git a/tinyusb/device/dcd_lpc11uxx_lpc13xx.h b/tinyusb/device/dcd_lpc11uxx_lpc13xx.h
index ce7fc90ea..aac9cf58f 100644
--- a/tinyusb/device/dcd_lpc11uxx_lpc13xx.h
+++ b/tinyusb/device/dcd_lpc11uxx_lpc13xx.h
@@ -46,8 +46,8 @@
#ifndef _TUSB_DCD_LPC11UXX_LPC13XX_H_
#define _TUSB_DCD_LPC11UXX_LPC13XX_H_
-#define DEVICE_ROM_REG_BASE LPC_USB_BASE
-#define DEVICE_ROM_DRIVER_ADDR 0x1FFF1FF8
+#define NXP_ROMDRIVER_REG_BASE LPC_USB_BASE
+#define NXP_ROMDRIVER_FUNCTION_ADDR 0x1FFF1FF8
#ifdef __cplusplus
extern "C" {
diff --git a/tinyusb/device/dcd_lpc18xx_lpc43xx.h b/tinyusb/device/dcd_lpc18xx_lpc43xx.h
index a98196f6a..e7bdfad7c 100644
--- a/tinyusb/device/dcd_lpc18xx_lpc43xx.h
+++ b/tinyusb/device/dcd_lpc18xx_lpc43xx.h
@@ -50,8 +50,8 @@
extern "C" {
#endif
-#define DEVICE_ROM_REG_BASE LPC_USB0_BASE // TODO USB1
-#define DEVICE_ROM_DRIVER_ADDR 0x1040011C
+#define NXP_ROMDRIVER_REG_BASE LPC_USB0_BASE // TODO USB1
+#define NXP_ROMDRIVER_FUNCTION_ADDR 0x1040011C
#ifdef __cplusplus
}
diff --git a/tinyusb/device/dcd_nxp_romdriver.c b/tinyusb/device/dcd_nxp_romdriver.c
index 5c0e4d847..fb3084953 100644
--- a/tinyusb/device/dcd_nxp_romdriver.c
+++ b/tinyusb/device/dcd_nxp_romdriver.c
@@ -60,12 +60,6 @@ typedef struct {
usbd_info_t usbd_info; // TODO rename
-typedef struct {
- void (* const init) (void);
- void (* const configured) (void);
- void (* const unmounted) (void);
-}device_class_driver_t;
-
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
@@ -91,7 +85,7 @@ ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb)
ASSERT( TUSB_ERROR_NONE == hidd_configured(hUsb), ERR_FAILED );
#endif
- #ifdef TUSB_CFG_DEVICE_CDC
+ #if TUSB_CFG_DEVICE_CDC
ASSERT( TUSB_ERROR_NONE == tusb_cdc_configured(hUsb), ERR_FAILED );
#endif
}
@@ -123,7 +117,7 @@ tusb_error_t dcd_init(void)
USBD_API_INIT_PARAM_T usb_param =
{
- .usb_reg_base = DEVICE_ROM_REG_BASE,
+ .usb_reg_base = NXP_ROMDRIVER_REG_BASE,
.max_num_ep = USB_MAX_EP_NUM,
.mem_base = membase,
.mem_size = memsize,
@@ -150,12 +144,6 @@ tusb_error_t dcd_init(void)
membase += (memsize - usb_param.mem_size);
memsize = usb_param.mem_size;
- #if TUSB_CFG_DEVICE_HID_MOUSE
- ASSERT_STATUS( tusb_hid_init(romdriver_hdl , &USB_FsConfigDescriptor.HID_MouseInterface ,
- HID_MouseReportDescriptor, USB_FsConfigDescriptor.HID_MouseHID.DescriptorList[0].wDescriptorLength,
- &membase , &memsize) );
- #endif
-
return TUSB_ERROR_NONE;
}
diff --git a/tinyusb/device/dcd_nxp_romdriver.h b/tinyusb/device/dcd_nxp_romdriver.h
index fb3540d49..4143805e7 100644
--- a/tinyusb/device/dcd_nxp_romdriver.h
+++ b/tinyusb/device/dcd_nxp_romdriver.h
@@ -55,10 +55,10 @@
#if (MCU == MCU_LPC18XX) || (MCU == MCU_LPC43XX)
#include "dcd_lpc18xx_lpc43xx.h"
- #define ROM_API ( * ((USBD_API_T**) DEVICE_ROM_DRIVER_ADDR) )
+ #define ROM_API ( * ((USBD_API_T**) NXP_ROMDRIVER_FUNCTION_ADDR) )
#elif (MCU == MCU_LPC13UXX) || (MCU == MCU_LPC11UXX)
#include "dcd_lpc11uxx_lpc13xx.h"
- #define ROM_API ( * (*((USBD_API_T***) DEVICE_ROM_DRIVER_ADDR)) )
+ #define ROM_API ( * (*((USBD_API_T***) NXP_ROMDRIVER_FUNCTION_ADDR)) )
#else
#error forgot something, thach ?
#endif
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index 594112c88..160302d99 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -56,7 +56,15 @@
//
//};
-
+// TODO fix/compress number of class driver
+static device_class_driver_t const usbh_class_drivers[TUSB_CLASS_MAX_CONSEC_NUMBER] =
+{
+#if DEVICE_CLASS_HID
+ [TUSB_CLASS_HID] = {
+ .init = hidd_init,
+ },
+#endif
+};
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
@@ -80,8 +88,14 @@ tusb_error_t usbd_init (void)
ASSERT_STATUS ( dcd_init() );
+ uint16_t length = 0;
+
#if TUSB_CFG_DEVICE_HID_KEYBOARD
- ASSERT_STATUS( hidd_init(&app_tusb_desc_configuration.keyboard_interface) );
+ ASSERT_STATUS( hidd_init(&app_tusb_desc_configuration.keyboard_interface, &length) );
+ #endif
+
+ #if TUSB_CFG_DEVICE_HID_MOUSE
+ ASSERT_STATUS( hidd_init(&app_tusb_desc_configuration.mouse_interface, &length) );
#endif
#ifndef _TEST_
@@ -100,13 +114,13 @@ tusb_error_t usbd_init (void)
//--------------------------------------------------------------------+
static tusb_error_t usbd_string_descriptor_init(void)
{
- ASSERT_INT( USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1),
+ ASSERT_INT( STRING_LEN_BYTE2UNICODE(sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1),
app_tusb_desc_strings.manufacturer.bLength, TUSB_ERROR_USBD_DESCRIPTOR_STRING);
- ASSERT_INT( USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT)-1) ,
+ ASSERT_INT( STRING_LEN_BYTE2UNICODE(sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT)-1) ,
app_tusb_desc_strings.product.bLength , TUSB_ERROR_USBD_DESCRIPTOR_STRING);
- ASSERT_INT( USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1) ,
+ ASSERT_INT( STRING_LEN_BYTE2UNICODE(sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1) ,
app_tusb_desc_strings.serial.bLength , TUSB_ERROR_USBD_DESCRIPTOR_STRING);
for(uint32_t i=0; i < sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1; i++)
diff --git a/tinyusb/device/usbd.h b/tinyusb/device/usbd.h
index 364dba8af..8da6da229 100644
--- a/tinyusb/device/usbd.h
+++ b/tinyusb/device/usbd.h
@@ -61,6 +61,11 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
+typedef struct {
+ tusb_error_t (* const init)(tusb_descriptor_interface_t const *, uint16_t*);
+// void (* const isr) (pipe_handle_t, tusb_event_t);
+// void (* const close) (uint8_t);
+} device_class_driver_t;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION