summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-01-27 12:18:01 +0700
committerhathach <[email protected]>2013-01-27 12:18:01 +0700
commit5feb1c90b41b2da4667b9e1f1fde069b6e1bfdcc (patch)
tree1f5cc4f36ffdb402b4a61c28aebafba6dedc3f6b
parentd286c957655d432424c8a7ff509bd040fd773572 (diff)
add class_hid_keyboard_init and test code
add define _TINY_USB_SOURCE_FILE_ to hide internal API from application
-rw-r--r--tests/project.yml1
-rw-r--r--tests/test/host/test_hid_host_keyboard.c12
-rw-r--r--tinyusb/class/hid_host.c14
-rw-r--r--tinyusb/class/hid_host.h7
-rw-r--r--tinyusb/host/usbd_host.h18
5 files changed, 43 insertions, 9 deletions
diff --git a/tests/project.yml b/tests/project.yml
index be644f147..c33818a15 100644
--- a/tests/project.yml
+++ b/tests/project.yml
@@ -48,6 +48,7 @@
- MCU=MCU_LPC43XX
- CORE_M4
- __CODE_RED
+ - _TINY_USB_SOURCE_FILE_
:test_preprocess:
- *common_defines
- _TEST_
diff --git a/tests/test/host/test_hid_host_keyboard.c b/tests/test/host/test_hid_host_keyboard.c
index 39e4303ac..aab1636fe 100644
--- a/tests/test/host/test_hid_host_keyboard.c
+++ b/tests/test/host/test_hid_host_keyboard.c
@@ -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
//--------------------------------------------------------------------+
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index d71aa8d52..3853f2538 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -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
-
diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h
index 0dab9f08b..a34a813d9 100644
--- a/tinyusb/class/hid_host.h
+++ b/tinyusb/class/hid_host.h
@@ -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
diff --git a/tinyusb/host/usbd_host.h b/tinyusb/host/usbd_host.h
index 26e0b2ccf..8fb76a5a9 100644
--- a/tinyusb/host/usbd_host.h
+++ b/tinyusb/host/usbd_host.h
@@ -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;
+
+typedef uint32_t tusb_handle_device_t;
//--------------------------------------------------------------------+
-// Structures & Types
+// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-typedef uint32_t tusb_handle_device_t;
//--------------------------------------------------------------------+
// 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