diff options
| author | hathach <[email protected]> | 2013-01-26 01:37:15 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-01-26 01:37:15 +0700 |
| commit | 7edda37518f0b193009c832b4092c357d0d01e96 (patch) | |
| tree | c6952e1f97b6c89e37968364c5c0a2a88958b3bf /tinyusb | |
| parent | fdc9a82e8c3dcce08613f0c0e1a773f0c39381e0 (diff) | |
add more test code for keyboard hid application API
refractor, restructure, rename several thing regarding host, keyboard etc ...
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/hid.h | 19 | ||||
| -rw-r--r-- | tinyusb/class/hid_host.c | 52 | ||||
| -rw-r--r-- | tinyusb/class/hid_host.h | 23 | ||||
| -rw-r--r-- | tinyusb/common/errors.h | 1 | ||||
| -rw-r--r-- | tinyusb/device/dcd.c | 2 | ||||
| -rw-r--r-- | tinyusb/host/usbd_host.c | 3 | ||||
| -rw-r--r-- | tinyusb/host/usbd_host.h | 62 | ||||
| -rw-r--r-- | tinyusb/osal/osal.h | 1 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 11 | ||||
| -rw-r--r-- | tinyusb/tusb.h | 21 | ||||
| -rw-r--r-- | tinyusb/tusb_option.h | 23 |
11 files changed, 167 insertions, 51 deletions
diff --git a/tinyusb/class/hid.h b/tinyusb/class/hid.h index 8b3696114..cf9a47278 100644 --- a/tinyusb/class/hid.h +++ b/tinyusb/class/hid.h @@ -55,19 +55,18 @@ extern "C" { #endif - // TODO refractor #include "common/common.h" -#ifdef TUSB_CFG_DEVICE - #include "device/dcd.h" - #include "hid_device.h" -#endif - -#ifdef TUSB_CFG_HOST - #include "host/usbd_host.h" - #include "hid_host.h" -#endif +enum { + TUSB_HID_SUBCLASS_NONE = 0, + TUSB_HID_SUBCLASS_BOOT = 1 +}; +enum { + TUSB_HID_PROTOCOL_NONE = 0, + TUSB_HID_PROTOCOL_KEYBOARD = 1, + TUSB_HID_PROTOCOL_MOUSE = 2 +}; /** \struct tusb_mouse_report_t * \brief Standard HID Boot Protocol Mouse Report. * diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c index 21bc1a93b..2d146a29a 100644 --- a/tinyusb/class/hid_host.c +++ b/tinyusb/class/hid_host.c @@ -39,28 +39,56 @@ #if defined TUSB_CFG_HOST && defined DEVICE_CLASS_HID +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ #include "hid_host.h" -tusb_error_t tusbh_keyboard_get(tusb_handle_device_t const device_hdl, tusb_keyboard_report_t * const report) -{ - usbh_device_info_t *p_device_info; +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +class_hid_keyboard_info_t keyboard_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; - pipe_handle_t pipe_in; - osal_queue_id_t qid; + +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ +tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8_t instance_num, tusb_keyboard_report_t * const report) +{ + keyboard_interface_t *p_kbd; ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA); - p_device_info = usbh_device_info_get(device_hdl); - ASSERT_PTR(p_device_info, TUSB_ERROR_INVALID_PARA); + ASSERT(device_hdl < TUSB_CFG_HOST_DEVICE_MAX, TUSB_ERROR_INVALID_PARA); + ASSERT(instance_num < TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, TUSB_ERROR_INVALID_PARA); - pipe_in = p_device_info->configuration.classes.hid_keyboard.pipe_in; - qid = p_device_info->configuration.classes.hid_keyboard.qid; + p_kbd = &keyboard_info_pool[device_hdl].instance[instance_num]; - ASSERT(0 != pipe_in, TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT); - ASSERT_STATUS( osal_queue_get(qid, (uint32_t*)report, OSAL_TIMEOUT_WAIT_FOREVER) ); - ASSERT_STATUS( osal_queue_get(qid, ((uint32_t*)report)+1, OSAL_TIMEOUT_WAIT_FOREVER) ); + ASSERT(0 != p_kbd->pipe_in, TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT); + + ASSERT_INT(PIPE_STATUS_COMPLETE, usbh_pipe_status_get(p_kbd->pipe_in), TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE); + + memcpy(report, p_kbd->buffer, p_kbd->report_size); return TUSB_ERROR_NONE; } +uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl) +{ + return 0; +} + +tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor) +{ + ASSERT(dev_addr < TUSB_CFG_HOST_DEVICE_MAX, TUSB_ERROR_INVALID_PARA); + ASSERT_PTR(descriptor, TUSB_ERROR_INVALID_PARA); + + return TUSB_ERROR_NONE; +} + + #endif diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h index 7a8c9887e..0dab9f08b 100644 --- a/tinyusb/class/hid_host.h +++ b/tinyusb/class/hid_host.h @@ -55,9 +55,30 @@ extern "C" { #endif +#include "host/usbd_host.h" #include "hid.h" -tusb_error_t tusbh_keyboard_get(tusb_handle_device_t const handle, tusb_keyboard_report_t * const report); +//--------------------------------------------------------------------+ +// APPLICATION API +//--------------------------------------------------------------------+ +uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl); +tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const handle, uint8_t instance_num, tusb_keyboard_report_t * const report); + +//--------------------------------------------------------------------+ +// INTERNAL API +//--------------------------------------------------------------------+ +typedef struct { + pipe_handle_t pipe_in; + uint8_t report_size; + uint8_t buffer[TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE]; +}keyboard_interface_t; + +typedef struct { // TODO internal structure + uint8_t instance_count; + keyboard_interface_t instance[TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE]; +} class_hid_keyboard_info_t; + +tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor); #ifdef __cplusplus } diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index bf1998365..3b37154d3 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -62,6 +62,7 @@ ENTRY(TUSB_ERROR_NONE)\ ENTRY(TUSB_ERROR_INVALID_PARA)\ ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\ + ENTRY(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE)\ ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\ ENTRY(TUSB_ERROR_FAILED)\ diff --git a/tinyusb/device/dcd.c b/tinyusb/device/dcd.c index 3ddcea147..3ec2b951c 100644 --- a/tinyusb/device/dcd.c +++ b/tinyusb/device/dcd.c @@ -42,7 +42,7 @@ #include "descriptors.h" // TODO refractor later #define USB_ROM_SIZE (1024*2) // TODO dcd abstract later -uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) TUSB_ATTR_RAM_SECTION; +uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) TUSB_CFG_ATTR_USBRAM; USBD_HANDLE_T g_hUsb; static volatile bool isConfigured = false; diff --git a/tinyusb/host/usbd_host.c b/tinyusb/host/usbd_host.c index f39ecf799..772503d28 100644 --- a/tinyusb/host/usbd_host.c +++ b/tinyusb/host/usbd_host.c @@ -39,6 +39,8 @@ #ifdef TUSB_CFG_HOST +usbh_device_info_t usbh_device_pool[TUSB_CFG_HOST_DEVICE_MAX]; + #if 0 tusb_error_t tusbh_keyboard_open(tusb_handle_device_t device_hdl, uint8_t configure_num, tusb_handle_keyboard_t *keyboard_hdl) { @@ -50,6 +52,5 @@ tusb_error_t tusbh_keyboard_open(tusb_handle_device_t device_hdl, uint8_t config } #endif -usbh_device_info_t usbh_device_pool[TUSB_CFG_HOST_DEVICE_MAX]; #endif diff --git a/tinyusb/host/usbd_host.h b/tinyusb/host/usbd_host.h index 926d586b0..828e81890 100644 --- a/tinyusb/host/usbd_host.h +++ b/tinyusb/host/usbd_host.h @@ -57,24 +57,53 @@ #include "hcd.h" -typedef struct { - pipe_handle_t pipe_in; - osal_queue_id_t qid; -}hid_info_t; +enum { + TUSB_FLAGS_CLASS_UNSPECIFIED = BIT_(0) , ///< 0 + TUSB_FLAGS_CLASS_AUDIO = BIT_(1) , ///< 1 + TUSB_FLAGS_CLASS_CDC = BIT_(2) , ///< 2 + TUSB_FLAGS_CLASS_HID_GENERIC = BIT_(3) , ///< 3 + TUSB_FLAGS_CLASS_RESERVED_4 = BIT_(4) , ///< 4 + TUSB_FLAGS_CLASS_PHYSICAL = BIT_(5) , ///< 5 + TUSB_FLAGS_CLASS_IMAGE = BIT_(6) , ///< 6 + TUSB_FLAGS_CLASS_PRINTER = BIT_(7) , ///< 7 + TUSB_FLAGS_CLASS_MSC = BIT_(8) , ///< 8 + TUSB_FLAGS_CLASS_HUB = BIT_(9) , ///< 9 + TUSB_FLAGS_CLASS_CDC_DATA = BIT_(10) , ///< 10 + TUSB_FLAGS_CLASS_SMART_CARD = BIT_(11) , ///< 11 + TUSB_FLAGS_CLASS_RESERVED_12 = BIT_(12) , ///< 12 + TUSB_FLAGS_CLASS_CONTENT_SECURITY = BIT_(13) , ///< 13 + TUSB_FLAGS_CLASS_VIDEO = BIT_(14) , ///< 14 + TUSB_FLAGS_CLASS_PERSONAL_HEALTHCARE = BIT_(15) , ///< 15 + TUSB_FLAGS_CLASS_AUDIO_VIDEO = BIT_(16) , ///< 16 + // reserved from 17 to 20 + TUSB_FLAGS_CLASS_RESERVED_20 = BIT_(20) , ///< 3 + + TUSB_FLAGS_CLASS_HID_KEYBOARD = BIT_(21) , ///< 3 + TUSB_FLAGS_CLASS_HID_MOUSE = BIT_(22) , ///< 3 + + // reserved from 25 to 26 + TUSB_FLAGS_CLASS_RESERVED_25 = BIT_(25) , ///< 3 + TUSB_FLAGS_CLASS_RESERVED_26 = BIT_(26) , ///< 3 + + TUSB_FLAGS_CLASS_DIAGNOSTIC = BIT_(27), + TUSB_FLAGS_CLASS_WIRELESS_CONTROLLER = BIT_(28), + TUSB_FLAGS_CLASS_MISC = BIT_(29), + TUSB_FLAGS_CLASS_APPLICATION_SPECIFIC = BIT_(30), + TUSB_FLAGS_CLASS_VENDOR_SPECIFIC = BIT_(31) +}; + +typedef uint32_t tusbh_flag_class_t; typedef struct { - uint8_t interface_num; + uint8_t interface_count; uint8_t attributes; - - struct { - hid_info_t hid_keyboard; - // hid_info_t hid_mouse; - // hid_info_t hid_generic; - } classes; } usbh_configure_info_t; typedef struct { uint8_t core_id; + pipe_handle_t pipe_control; + uint8_t configure_count; + #if 0 // TODO allow configure for vendor/product uint16_t vendor_id; uint16_t product_id; @@ -83,8 +112,11 @@ typedef struct { usbh_configure_info_t configuration; } usbh_device_info_t; - - +typedef enum { + PIPE_STATUS_AVAILABLE = 0, + PIPE_STATUS_BUSY, + PIPE_STATUS_COMPLETE +} pipe_status_t; //--------------------------------------------------------------------+ // Structures & Types //--------------------------------------------------------------------+ @@ -93,6 +125,7 @@ typedef uint32_t tusb_handle_device_t; //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ +void tusbh_device_mounting_cb (tusb_error_t error, tusb_handle_device_t device_hdl, uint32_t *configure_flags, uint8_t number_of_configure); void tusbh_device_mounted_cb (tusb_error_t error, tusb_handle_device_t device_hdl, uint32_t *configure_flags, uint8_t number_of_configure); tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, uint8_t const configure_number); @@ -101,7 +134,8 @@ tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, //--------------------------------------------------------------------+ // CLASS API //--------------------------------------------------------------------+ -usbh_device_info_t* usbh_device_info_get (tusb_handle_device_t device_hdl); +usbh_device_info_t* usbh_device_info_get(tusb_handle_device_t device_hdl); +pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl); #ifdef __cplusplus } diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index 07a65f5b2..2e3c2a2cf 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -81,6 +81,7 @@ enum //--------------------------------------------------------------------+ typedef uint32_t osal_queue_id_t; +tusb_error_t osal_queue_create(osal_queue_id_t qid, uint8_t *buffer); tusb_error_t osal_queue_put(osal_queue_id_t qid, uint32_t data, osal_timeout_t msec); tusb_error_t osal_queue_get(osal_queue_id_t qid, uint32_t *data, osal_timeout_t msec); diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index d14277f39..198e5dc2c 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -60,6 +60,17 @@ //--------------------------------------------------------------------+ // QUEUE API //--------------------------------------------------------------------+ +typedef struct{ + uint8_t *buf ; ///< buffer pointer + uint16_t size ; ///< buffer size + volatile uint16_t len ; ///< bytes in fifo + volatile uint16_t wr_ptr ; ///< write pointer + volatile uint16_t rd_ptr ; ///< read pointer +} osal_queue_t; + +#define OSAL_DEF_QUEUE(name, size)\ + osal_queue_t name;\ + uint8_t buffer_##name[size] #ifdef __cplusplus } diff --git a/tinyusb/tusb.h b/tinyusb/tusb.h index 91f8261c2..02a00d48d 100644 --- a/tinyusb/tusb.h +++ b/tinyusb/tusb.h @@ -51,24 +51,29 @@ #include "common/common.h" #ifdef TUSB_CFG_HOST - #include "host/hcd.h" + #include "host/usbd_host.h" + + #ifdef HOST_CLASS_HID + #include "class/hid_host.h" + #endif #endif #ifdef TUSB_CFG_DEVICE #include "device/dcd.h" + + #if DEVICE_CLASS_HID + #include "class/hid_device.h" + #endif + + #ifdef TUSB_CFG_DEVICE_CDC + #include "class/cdc.h" + #endif #endif #if !(defined TUSB_CFG_HOST) && !(defined TUSB_CFG_DEVICE) #error please enable either TUSB_CFG_HOST or TUSB_CFG_DEVICE #endif -#if DEVICE_CLASS_HID - #include "class/hid.h" -#endif - -#ifdef TUSB_CFG_DEVICE_CDC - #include "class/cdc.h" -#endif tusb_error_t tusb_init(void); diff --git a/tinyusb/tusb_option.h b/tinyusb/tusb_option.h index 95ef840b6..f84836428 100644 --- a/tinyusb/tusb_option.h +++ b/tinyusb/tusb_option.h @@ -75,6 +75,19 @@ #warning TUSB_CFG_HOST_DEVICE_MAX is not defined, default value is 1 #endif +#if TUSB_CFG_HOST_HID_KEYBOARD + #if !defined(TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE) + #define TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE 64 + #warning TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE is not defined, default value is 64 + #elif TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE < 8 + #error no endpoint size is allowed to be less than 8 + #endif + + #if !defined(TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE) + #define TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE 1 + #endif +#endif + #endif #ifndef TUSB_CFG_CONFIGURATION_MAX @@ -86,13 +99,15 @@ //#define TUSB_CFG_DEVICE /// USB RAM Section Placement, MCU's usb controller often has limited access to specific RAM region. This will be used to declare internal variables as follow: -/// uint8_t tinyusb_data[10] TUSB_ATTR_RAM_SECTION; -/// if your mcu's usb controller has no such limit, define TUSB_ATTR_RAM_SECTION as empty macro. -#ifndef TUSB_ATTR_RAM_SECTION - #error TUSB_ATTR_RAM_SECTION is not defined, needed to place data in accessible RAM for usb controller +/// uint8_t tinyusb_data[10] TUSB_CFG_ATTR_USBRAM; +/// if your mcu's usb controller has no such limit, define TUSB_CFG_ATTR_USBRAM as empty macro. +#ifndef TUSB_CFG_ATTR_USBRAM + #error TUSB_CFG_ATTR_USBRAM is not defined, please help me know how to place data in accessible RAM for usb controller #endif #define DEVICE_CLASS_HID ( (defined TUSB_CFG_DEVICE_HID_KEYBOARD) || (defined TUSB_CFG_DEVICE_HID_MOUSE) ) +#define HOST_CLASS_HID ( (defined TUSB_CFG_HOST_HID_KEYBOARD) ) + #define HOST_EHCI // TODO APP |
