summaryrefslogtreecommitdiff
path: root/src/class/hid
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-03-27 08:52:25 -0700
committerGitHub <[email protected]>2019-03-27 08:52:25 -0700
commit86c24b310509a368cc6a9dfbec43ce531e71d598 (patch)
tree81fec0b3724083a3515ef09e0b7d601ce01ec621 /src/class/hid
parent547cc045fa1d8862e7e00c1d7b4a0026531d0098 (diff)
parent38f7d281d44c69593f1de3885a292ee7c5c39355 (diff)
Merge pull request #49 from hathach/develop
clean up porting API
Diffstat (limited to 'src/class/hid')
-rw-r--r--src/class/hid/hid_device.c54
-rw-r--r--src/class/hid/hid_device.h4
-rw-r--r--src/class/hid/hid_host.c4
-rw-r--r--src/class/hid/hid_host.h6
4 files changed, 12 insertions, 56 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 73af0c9a2..3a20a9cc8 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -28,7 +28,6 @@
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_HID)
-#define _TINY_USB_SOURCE_FILE_
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
@@ -43,7 +42,6 @@
// Max report len is keyboard's one with 8 byte + 1 byte report id
#define REPORT_BUFSIZE 12
-
#define ITF_IDX_BOOT_KBD 0
#define ITF_IDX_BOOT_MSE ( ITF_IDX_BOOT_KBD + (CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT) )
#define ITF_IDX_GENERIC ( ITF_IDX_BOOT_MSE + (CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT) )
@@ -70,8 +68,10 @@ typedef struct
typedef struct
{
- uint8_t usage; // HID_USAGE_*
- uint8_t idle_rate; // in unit of 4 ms
+ uint8_t usage; // HID_USAGE_*
+ uint8_t idle_rate; // Idle Rate = 0 : only send report if there is changes, i.e skip duplication
+ // Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
+ // If idle time is less than interrupt polling then use the polling.
uint8_t report_id;
uint8_t report_len;
@@ -91,7 +91,6 @@ static hidd_report_t _mse_rpt;
#endif
/*------------- Helpers -------------*/
-
static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
{
for (uint8_t i=0; i < ITF_COUNT; i++ )
@@ -151,19 +150,14 @@ static bool hidd_kbd_report(hid_keyboard_report_t const *p_report)
hidd_interface_t * p_hid = _kbd_rpt.itf;
- // Idle Rate = 0 : only send report if there is changes, i.e skip duplication
- // Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
- // If idle time is less than interrupt polling then use the polling.
- static tu_timeout_t idle_tm = { 0, 0 };
-
- if ( (_kbd_rpt.idle_rate == 0) || !tu_timeout_expired(&idle_tm) )
- {
- if ( 0 == memcmp(p_hid->report_buf, p_report, sizeof(hid_keyboard_report_t)) ) return true;
- }
-
- tu_timeout_set(&idle_tm, _kbd_rpt.idle_rate * 4);
+ // only send report if there is changes, i.e skip duplication
+// if ( _kbd_rpt.idle_rate == 0 )
+// {
+// if ( 0 == memcmp(p_hid->report_buf, p_report, sizeof(hid_keyboard_report_t)) ) return true;
+// }
memcpy(p_hid->report_buf, p_report, sizeof(hid_keyboard_report_t));
+
return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, sizeof(hid_keyboard_report_t));
}
@@ -195,33 +189,6 @@ bool tud_hid_keyboard_key_press(char ch)
return tud_hid_keyboard_keycode(modifier, keycode);
}
-#if 0 // should be at application
-bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms)
-{
- // Send each key in string
- char ch;
- while( (ch = *str++) != 0 )
- {
- char lookahead = *str;
-
- tud_hid_keyboard_key_press(ch);
-
- // Blocking delay
- tu_timeout_wait(interval_ms);
-
- /* Only need to empty report if the next character is NULL or the same with
- * the current one, else no need to send */
- if ( lookahead == ch || lookahead == 0 )
- {
- tud_hid_keyboard_key_release();
- tu_timeout_wait(interval_ms);
- }
- }
-
- return true;
-}
-#endif
-
#endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
#endif // CFG_TUD_HID_KEYBOARD
@@ -246,6 +213,7 @@ static bool hidd_mouse_report(hid_mouse_report_t const *p_report)
TU_VERIFY( tud_hid_mouse_ready() );
hidd_interface_t * p_hid = _mse_rpt.itf;
+// only send report if there is changes, i.e skip duplication
memcpy(p_hid->report_buf, p_report, sizeof(hid_mouse_report_t));
return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, sizeof(hid_mouse_report_t));
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index e0d8907de..096daad18 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -361,8 +361,6 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t
//--------------------------------------------------------------------+
// INTERNAL API
//--------------------------------------------------------------------+
-#ifdef _TINY_USB_SOURCE_FILE_
-
void hidd_init(void);
bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request);
@@ -370,8 +368,6 @@ bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const
bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
void hidd_reset(uint8_t rhport);
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index a52cf64b3..5aabbc01f 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -28,10 +28,6 @@
#if (TUSB_OPT_HOST_ENABLED && HOST_CLASS_HID)
-#define _TINY_USB_SOURCE_FILE_
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
#include "common/tusb_common.h"
#include "hid_host.h"
diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h
index 0e5e48c64..8fa974c92 100644
--- a/src/class/hid/hid_host.h
+++ b/src/class/hid/hid_host.h
@@ -193,10 +193,8 @@ void tuh_hid_generic_isr(uint8_t dev_addr, xfer_result_t event);
/** @} */ // ClassDriver_HID_Generic
//--------------------------------------------------------------------+
-// USBH-CLASS DRIVER API
+// Internal Class Driver API
//--------------------------------------------------------------------+
-#ifdef _TINY_USB_SOURCE_FILE_
-
typedef struct {
pipe_handle_t pipe_hdl;
uint16_t report_size;
@@ -208,8 +206,6 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
void hidh_close(uint8_t dev_addr);
-#endif
-
#ifdef __cplusplus
}
#endif