mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-23 22:43:49 +00:00
add class_hid_keyboard_init and test code
add define _TINY_USB_SOURCE_FILE_ to hide internal API from application
This commit is contained in:
parent
d286c95765
commit
5feb1c90b4
@ -48,6 +48,7 @@
|
||||
- MCU=MCU_LPC43XX
|
||||
- CORE_M4
|
||||
- __CODE_RED
|
||||
- _TINY_USB_SOURCE_FILE_
|
||||
:test_preprocess:
|
||||
- *common_defines
|
||||
- _TEST_
|
||||
|
@ -90,7 +90,7 @@ void tearDown(void)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// keyboard_install, keyboard_no_instances
|
||||
// keyboard_install, keyboard_no_instances, keybaord_init
|
||||
//--------------------------------------------------------------------+
|
||||
void test_keyboard_no_instances_invalid_para(void)
|
||||
{
|
||||
@ -107,6 +107,16 @@ void test_keyboard_install_ok(void)
|
||||
TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
}
|
||||
|
||||
void test_keyboard_init(void)
|
||||
{
|
||||
class_hid_keyboard_info_t keyboard_info_zero[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
memset(&keyboard_info_zero, 0, sizeof(class_hid_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||
|
||||
class_hid_keyboard_init();
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY(keyboard_info_zero, keyboard_info_pool, sizeof(class_hid_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// keyboard_get
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -39,6 +39,8 @@
|
||||
|
||||
#if defined TUSB_CFG_HOST && defined DEVICE_CLASS_HID
|
||||
|
||||
#define _TINY_USB_SOURCE_FILE_
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
@ -55,7 +57,7 @@ class_hid_keyboard_info_t keyboard_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// IMPLEMENTATION
|
||||
// PUBLIC API
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8_t instance_num, tusb_keyboard_report_t * const report)
|
||||
{
|
||||
@ -83,6 +85,14 @@ uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl)
|
||||
return keyboard_info_pool[device_hdl].instance_count;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS-USBD API
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_error_t class_hid_keyboard_init(void)
|
||||
{
|
||||
memset(&keyboard_info_pool, 0, sizeof(class_hid_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||
}
|
||||
|
||||
tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor)
|
||||
{
|
||||
keyboard_info_pool[0].instance_count++;
|
||||
@ -90,6 +100,4 @@ tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *d
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -67,19 +67,24 @@ tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const handle, uint8_t i
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL API
|
||||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
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
|
||||
typedef struct {
|
||||
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_init(void);
|
||||
tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -55,8 +55,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "hcd.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
enum {
|
||||
TUSB_FLAGS_CLASS_UNSPECIFIED = BIT_(0) , ///< 0
|
||||
TUSB_FLAGS_CLASS_AUDIO = BIT_(1) , ///< 1
|
||||
@ -116,10 +122,11 @@ typedef enum {
|
||||
PIPE_STATUS_BUSY,
|
||||
PIPE_STATUS_COMPLETE
|
||||
} pipe_status_t;
|
||||
//--------------------------------------------------------------------+
|
||||
// Structures & Types
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
typedef uint32_t tusb_handle_device_t;
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
@ -129,13 +136,16 @@ void tusbh_device_mounted_cb (tusb_error_t const error, tusb_handle_devi
|
||||
tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, uint8_t const configure_number);
|
||||
|
||||
|
||||
// TODO hiding from application include
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS API
|
||||
// CLASS-USBD API
|
||||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
bool usbh_device_is_plugged(tusb_handle_device_t const device_hdl);
|
||||
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user