add more test code for keyboard hid application API
refractor, restructure, rename several thing regarding host, keyboard etc ...
This commit is contained in:
parent
fdc9a82e8c
commit
7edda37518
|
@ -38,7 +38,7 @@
|
|||
#include "descriptors.h"
|
||||
|
||||
#ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const uint8_t HID_KeyboardReportDescriptor[] = {
|
||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const uint8_t HID_KeyboardReportDescriptor[] = {
|
||||
HID_UsagePage ( HID_USAGE_PAGE_GENERIC ),
|
||||
HID_Usage ( HID_USAGE_GENERIC_KEYBOARD ),
|
||||
HID_Collection ( HID_Application ),
|
||||
|
@ -81,7 +81,7 @@ TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const uint8_t HID_KeyboardReportDescriptor
|
|||
#endif
|
||||
|
||||
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
|
||||
TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const uint8_t HID_MouseReportDescriptor[] = {
|
||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const uint8_t HID_MouseReportDescriptor[] = {
|
||||
HID_UsagePage ( HID_USAGE_PAGE_GENERIC ),
|
||||
HID_Usage ( HID_USAGE_GENERIC_MOUSE ),
|
||||
HID_Collection ( HID_Application ),
|
||||
|
@ -119,7 +119,7 @@ TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const uint8_t HID_MouseReportDescriptor[]
|
|||
#endif
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const USB_DEVICE_DESCRIPTOR USB_DeviceDescriptor =
|
||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_DEVICE_DESCRIPTOR USB_DeviceDescriptor =
|
||||
{
|
||||
.bLength = sizeof(USB_DEVICE_DESCRIPTOR),
|
||||
.bDescriptorType = USB_DEVICE_DESCRIPTOR_TYPE,
|
||||
|
@ -153,7 +153,7 @@ TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const USB_DEVICE_DESCRIPTOR USB_DeviceDesc
|
|||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_FsConfigDescriptor =
|
||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_FsConfigDescriptor =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
|
@ -358,7 +358,7 @@ TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const USB_FS_CONFIGURATION_DESCRIPTOR USB_
|
|||
.ConfigDescTermination = 0,
|
||||
};
|
||||
|
||||
TUSB_ATTR_RAM_SECTION ATTR_ALIGNED(4) const USB_STR_DESCRIPTOR USB_StringDescriptor =
|
||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) const USB_STR_DESCRIPTOR USB_StringDescriptor =
|
||||
{
|
||||
.LangID = { .bLength = 0x04, .bDescriptorType = USB_STRING_DESCRIPTOR_TYPE },
|
||||
.strLangID= {0x0409}, // US English
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
#define TUSB_RAM_SECTION ".data.$RAM3"
|
||||
#endif
|
||||
|
||||
#define TUSB_ATTR_RAM_SECTION __attribute__ ((section(TUSB_RAM_SECTION)))
|
||||
#define TUSB_CFG_ATTR_USBRAM __attribute__ ((section(TUSB_RAM_SECTION)))
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -57,6 +57,12 @@
|
|||
|
||||
#define TUSB_CFG_HOST
|
||||
|
||||
#define TUSB_CFG_HOST_CONTROLLER_NUM 1
|
||||
#define TUSB_CFG_HOST_DEVICE_MAX 1
|
||||
#define TUSB_CFG_CONFIGURATION_MAX 1
|
||||
|
||||
#define TUSB_CFG_HOST_HID_KEYBOARD
|
||||
|
||||
/// Enable Device Support
|
||||
//#define TUSB_CFG_DEVICE
|
||||
|
||||
|
@ -80,7 +86,7 @@
|
|||
#define TUSB_RAM_SECTION ".data.$RAM3"
|
||||
#endif
|
||||
|
||||
#define TUSB_ATTR_RAM_SECTION __attribute__ ((section(TUSB_RAM_SECTION)))
|
||||
#define TUSB_CFG_ATTR_USBRAM __attribute__ ((section(TUSB_RAM_SECTION)))
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "mock_osal.h"
|
||||
#include "mock_usbd_host.h"
|
||||
|
||||
usbh_device_info_t usbh_device_pool [2];
|
||||
extern class_hid_keyboard_info_t keyboard_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
|
||||
tusb_keyboard_report_t sample_key[2] =
|
||||
{
|
||||
|
@ -56,72 +56,122 @@ tusb_keyboard_report_t sample_key[2] =
|
|||
};
|
||||
|
||||
tusb_handle_device_t device_hdl;
|
||||
tusb_descriptor_interface_t kbd_descriptor;
|
||||
tusb_keyboard_report_t report;
|
||||
uint8_t instance_num;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
device_hdl = 0; // deviceID = 0 ; Configure = 1
|
||||
instance_num = 0;
|
||||
memset(&report, 0, sizeof(tusb_keyboard_report_t));
|
||||
|
||||
usbh_device_pool[0].configuration.classes.hid_keyboard.pipe_in = 1;
|
||||
usbh_device_pool[0].configuration.classes.hid_keyboard.qid = 1;
|
||||
keyboard_info_pool[0].instance[0].pipe_in = 1;
|
||||
keyboard_info_pool[0].instance[0].report_size = sizeof(tusb_keyboard_report_t);
|
||||
|
||||
kbd_descriptor = ((tusb_descriptor_interface_t)
|
||||
{
|
||||
.bLength = sizeof(tusb_descriptor_interface_t),
|
||||
.bDescriptorType = TUSB_DESC_INTERFACE,
|
||||
.bInterfaceNumber = 1,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 1,
|
||||
.bInterfaceClass = TUSB_CLASS_HID,
|
||||
.bInterfaceSubClass = TUSB_HID_SUBCLASS_BOOT,
|
||||
.bInterfaceProtocol = TUSB_HID_PROTOCOL_KEYBOARD,
|
||||
.iInterface = 0
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
tusb_error_t queue_get_stub(osal_queue_id_t qid, uint32_t *data, osal_timeout_t msec, int num_call)
|
||||
//--------------------------------------------------------------------+
|
||||
// keyboard_install, keyboard_no_instances
|
||||
//--------------------------------------------------------------------+
|
||||
void test_keyboard_install_invalid_para(void)
|
||||
{
|
||||
memcpy(data, (uint32_t*)(&sample_key[num_call/2]) + (num_call%2), 4);
|
||||
return TUSB_ERROR_NONE;
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, class_hid_keyboard_install(TUSB_CFG_HOST_DEVICE_MAX, (uint8_t*) &kbd_descriptor));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, class_hid_keyboard_install(device_hdl, NULL));
|
||||
}
|
||||
|
||||
usbh_device_info_t* get_device_class_not_support_stub(tusb_handle_device_t device_hdl, int num_call)
|
||||
void test_keyboard_no_instances_invalid_para(void)
|
||||
{
|
||||
usbh_device_pool[0].configuration.classes.hid_keyboard.pipe_in = 0;
|
||||
usbh_device_pool[0].configuration.classes.hid_keyboard.qid = 0;
|
||||
|
||||
return &(usbh_device_pool[0]);
|
||||
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(TUSB_CFG_HOST_DEVICE_MAX));
|
||||
}
|
||||
|
||||
usbh_device_info_t* get_device_stub(tusb_handle_device_t device_hdl, int num_call)
|
||||
void test_keyboard_install_ok(void)
|
||||
{
|
||||
return &(usbh_device_pool[0]);
|
||||
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, class_hid_keyboard_install(device_hdl, (uint8_t*) &kbd_descriptor));
|
||||
TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// keyboard_get
|
||||
//--------------------------------------------------------------------+
|
||||
pipe_status_t pipe_status_get_stub(pipe_handle_t pipe_hdl, int num_call)
|
||||
{
|
||||
switch (num_call)
|
||||
{
|
||||
case 0:
|
||||
memcpy(keyboard_info_pool[0].instance[0].buffer, &sample_key[0], sizeof(tusb_keyboard_report_t));
|
||||
return PIPE_STATUS_COMPLETE;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
return PIPE_STATUS_AVAILABLE;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
return PIPE_STATUS_BUSY;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
memcpy(keyboard_info_pool[0].instance[0].buffer, &sample_key[1], sizeof(tusb_keyboard_report_t));
|
||||
return PIPE_STATUS_COMPLETE;
|
||||
break;
|
||||
|
||||
default:
|
||||
return PIPE_STATUS_AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
void test_keyboard_get_invalid_para()
|
||||
{
|
||||
usbh_device_info_get_IgnoreAndReturn(NULL);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(device_hdl, NULL));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(device_hdl, &report));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(0, 0, NULL));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(TUSB_CFG_HOST_DEVICE_MAX, 0, &report));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(0, TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, &report));
|
||||
}
|
||||
|
||||
void test_keyboard_get_class_not_supported()
|
||||
{
|
||||
usbh_device_info_get_StubWithCallback(get_device_class_not_support_stub);
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_keyboard_get(device_hdl, &report));
|
||||
keyboard_info_pool[device_hdl].instance[0].pipe_in = 0;
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
}
|
||||
|
||||
void test_keyboard_get_from_empty_queue()
|
||||
void test_keyboard_get_report_not_available()
|
||||
{
|
||||
usbh_device_info_get_StubWithCallback(get_device_stub);
|
||||
osal_queue_get_IgnoreAndReturn(TUSB_ERROR_OSAL_TIMEOUT);
|
||||
// osal_queue_get_ExpectAndReturn( usbh_device_pool[0].configuration[0].classes.hid_keyboard.qid, );
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_BUSY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, tusbh_keyboard_get(device_hdl, &report));
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_AVAILABLE);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
}
|
||||
|
||||
void test_keyboard_get_ok()
|
||||
{
|
||||
usbh_device_info_get_StubWithCallback(get_device_stub);
|
||||
osal_queue_get_StubWithCallback(queue_get_stub);
|
||||
usbh_pipe_status_get_StubWithCallback(pipe_status_get_stub);
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(device_hdl, &report));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t));
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(device_hdl, &report));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t));
|
||||
}
|
||||
|
||||
|
|
|
@ -55,23 +55,36 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HOST CONFIGURATION
|
||||
//--------------------------------------------------------------------+
|
||||
#define TUSB_CFG_HOST
|
||||
|
||||
//------------- CORE/CONTROLLER -------------//
|
||||
#define TUSB_CFG_HOST_CONTROLLER_NUM 2
|
||||
#define TUSB_CFG_HOST_DEVICE_MAX 2
|
||||
#define TUSB_CFG_CONFIGURATION_MAX 2
|
||||
|
||||
/// Enable Device Support
|
||||
//------------- CLASS -------------//
|
||||
#define TUSB_CFG_HOST_HID_KEYBOARD 1
|
||||
#define TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE 64
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DEVICE CONFIGURATION
|
||||
//--------------------------------------------------------------------+
|
||||
//#define TUSB_CFG_DEVICE
|
||||
|
||||
/// Enable CDC Support
|
||||
//------------- CORE/CONTROLLER -------------//
|
||||
|
||||
//------------- CLASS -------------//
|
||||
//#define TUSB_CFG_DEVICE_CDC
|
||||
|
||||
/// Enable HID Keyboard support
|
||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
|
||||
/// Enable HID Mouse support
|
||||
//#define TUSB_CFG_DEVICE_HID_MOUSE
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// COMMON CONFIGURATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define TUSB_CFG_DEBUG 3
|
||||
|
||||
#define TUSB_CFG_OS TUSB_OS_NONE
|
||||
|
@ -83,7 +96,7 @@
|
|||
#define TUSB_RAM_SECTION ".data.$RAM3"
|
||||
#endif
|
||||
|
||||
#define TUSB_ATTR_RAM_SECTION __attribute__ ((section(TUSB_RAM_SECTION)))
|
||||
#define TUSB_CFG_ATTR_USBRAM __attribute__ ((section(TUSB_RAM_SECTION)))
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* test_osal_none.c
|
||||
*
|
||||
* Created on: Jan 22, 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 "unity.h"
|
||||
#include "osal_none.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_queue_put_invalid_para(void)
|
||||
{
|
||||
// osal_queue_put();
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ void tearDown(void)
|
|||
{
|
||||
}
|
||||
|
||||
void test_()
|
||||
void test_project_memory()
|
||||
{
|
||||
TEST_IGNORE();
|
||||
TEST_IGNORE_MESSAGE("Try to keep project total memory usage up-to-date");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue