add more test code for keyboard hid application API
refractor, restructure, rename several thing regarding host, keyboard etc ...
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
pipe_handle_t pipe_in;
|
||||
osal_queue_id_t qid;
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
class_hid_keyboard_info_t keyboard_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// 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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)\
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user