summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-07-24 00:45:07 +0700
committerhathach <[email protected]>2018-07-24 00:45:07 +0700
commit3400dfdf4ea478894b2a96ac0bd27868c052fbeb (patch)
treedd125486da17644a8929da89fec079a47f3757af
parent546f2a1165555819bf3ef09fe1afcfbcbb084dd9 (diff)
nrf52840 boot mouse does not work, need more work
-rw-r--r--examples/device/nrf52840/src/main.c32
-rw-r--r--src/class/hid/hid.h9
-rw-r--r--src/class/hid/hid_device.c2
-rw-r--r--src/class/hid/hid_device.h8
-rw-r--r--src/device/usbd_desc.c54
5 files changed, 64 insertions, 41 deletions
diff --git a/examples/device/nrf52840/src/main.c b/examples/device/nrf52840/src/main.c
index cc18cce24..1f7f5b22e 100644
--- a/examples/device/nrf52840/src/main.c
+++ b/examples/device/nrf52840/src/main.c
@@ -98,29 +98,25 @@ void virtual_com_task(void)
}
//--------------------------------------------------------------------+
-// USB CDC
+// USB HID
//--------------------------------------------------------------------+
void usb_hid_task(void)
{
if ( tud_mounted() )
{
- if ( !tud_hid_keyboard_busy() )
- {
- // Poll every 10ms
- static tu_timeout_t tm = { .start = 0, .interval = 10 };
- if ( !tu_timeout_expired(&tm) ) return; // not enough time
- tu_timeout_reset(&tm);
-
- uint32_t bt = board_buttons();
- if ( bt )
+ /*------------- Keyboard -------------*/
+/*
+ if ( !tud_hid_keyboard_busy() )
+ {
+ if ( btn )
{
uint8_t keycode[6] = { 0 };
for(uint8_t i=0; i < 6; i++)
{
- if ( bt & (1 << i) ) keycode[i] = HID_KEY_A + i;
+ if ( btn & (1 << i) ) keycode[i] = HID_KEY_A + i;
}
tud_hid_keyboard_send_keycode(0, keycode);
@@ -130,10 +126,24 @@ void usb_hid_task(void)
tud_hid_keyboard_send_report(NULL);
}
}
+*/
+ /*------------- Mouse -------------*/
if ( !tud_hid_mouse_busy() )
{
+ // Poll every 10ms
+ static tu_timeout_t tm = { .start = 0, .interval = 10 };
+ if ( !tu_timeout_expired(&tm) ) return; // not enough time
+ tu_timeout_reset(&tm);
+
+ uint32_t const btn = board_buttons();
+
+ if ( btn )
+ {
+ hid_mouse_report_t report = { .buttons = 0, .x = 10, .y = 0, .wheel = 0 };
+ tud_hid_mouse_send_report(&report);
+ }
}
}
diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h
index c898b09d4..9872172a9 100644
--- a/src/class/hid/hid.h
+++ b/src/class/hid/hid.h
@@ -167,14 +167,17 @@ typedef struct ATTR_PACKED
int8_t x; /**< Current delta x movement of the mouse. */
int8_t y; /**< Current delta y movement on the mouse. */
int8_t wheel; /**< Current delta wheel movement on the mouse. */
+// int8_t pan;
} hid_mouse_report_t;
/// Standard Mouse Buttons Bitmap
typedef enum
{
- MOUSE_BUTTON_LEFT = BIT_(0), ///< Left button
- MOUSE_BUTTON_RIGHT = BIT_(1), ///< Right button
- MOUSE_BUTTON_MIDDLE = BIT_(2) ///< Middle button
+ MOUSE_BUTTON_LEFT = BIT_(0), ///< Left button
+ MOUSE_BUTTON_RIGHT = BIT_(1), ///< Right button
+ MOUSE_BUTTON_MIDDLE = BIT_(2), ///< Middle button
+ MOUSE_BUTTON_BACKWARD = BIT_(3), ///< Backward button,
+ MOUSE_BUTTON_FORWARD = BIT_(4), ///< Forward button,
}hid_mouse_button_bm_t;
/// @}
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 7aca8ef8e..1efceafd0 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -167,7 +167,7 @@ bool tud_hid_mouse_busy(void)
return dcd_edpt_busy(TUD_OPT_RHPORT, _mse_itf.ep_in);
}
-bool tud_hid_mouse_send(hid_mouse_report_t const *p_report)
+bool tud_hid_mouse_send_report(hid_mouse_report_t const *p_report)
{
VERIFY( tud_mounted() && !tud_hid_mouse_busy() );
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index 21561041a..1293d212d 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -65,7 +65,7 @@ bool tud_hid_keyboard_busy(void);
/** \brief Send a keyboard report
* \param[in,out] p_report Report data, if NULL, an empty report (all zeroes) is used
- * \returns true on success, false otherwise (not mounted or busy)
+ * \returns true on success, false otherwise (not mounted or busy)
*/
bool tud_hid_keyboard_send_report(hid_keyboard_report_t const *p_report);
@@ -127,10 +127,10 @@ ATTR_WEAK void tud_hid_keyboard_set_report_cb(hid_report_type_t report_type, uin
bool tud_hid_mouse_busy(void);
/** \brief Perform transfer queuing
- * \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_ATTR_USBRAM)
- * \returns true on success, false otherwise (not mounted or busy)
+ * \param[in,out] p_report Report data, if NULL, an empty report (all zeroes) is used
+ * \returns true on success, false otherwise (not mounted or busy)
*/
-bool tud_hid_mouse_send(hid_mouse_report_t const *p_report);
+bool tud_hid_mouse_send_report(hid_mouse_report_t const *p_report);
/*------------- Callbacks -------------*/
diff --git a/src/device/usbd_desc.c b/src/device/usbd_desc.c
index 452a6674e..27bf272b2 100644
--- a/src/device/usbd_desc.c
+++ b/src/device/usbd_desc.c
@@ -123,39 +123,45 @@ uint8_t const _desc_auto_hid_kbd_report[] = {
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ),
+ // 8 bits Modifier Keys (Shfit, Control, Alt)
HID_USAGE_MIN ( 224 ),
HID_USAGE_MAX ( 231 ),
HID_LOGICAL_MIN ( 0 ),
HID_LOGICAL_MAX ( 1 ),
+ HID_REPORT_COUNT ( 8 ),
HID_REPORT_SIZE ( 1 ),
- HID_REPORT_COUNT ( 8 ), /* 8 bits */
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* maskable modifier key */
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
- HID_REPORT_SIZE ( 8 ),
+ // 8 bit reserved
HID_REPORT_COUNT ( 1 ),
- HID_INPUT ( HID_CONSTANT ), /* reserved */
+ HID_REPORT_SIZE ( 8 ),
+ HID_INPUT ( HID_CONSTANT ),
+
+ // 6-byte Keycodes
+ HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
+ HID_USAGE_MIN ( 0 ),
+ HID_USAGE_MAX ( 255 ),
+ HID_LOGICAL_MIN ( 0 ),
+ HID_LOGICAL_MAX ( 255 ),
+
+ HID_REPORT_COUNT ( 6 ),
+ HID_REPORT_SIZE ( 8 ),
+ HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ),
+ // LED Indicator Kana | Compose | Scroll Lock | CapsLock | NumLock
HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
+ /* 5-bit Led report */
HID_USAGE_MIN ( 1 ),
HID_USAGE_MAX ( 5 ),
HID_REPORT_COUNT ( 5 ),
HID_REPORT_SIZE ( 1 ),
- HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* 5-bit Led report */
+ HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
- HID_REPORT_SIZE ( 3 ), /* led padding */
+ /* led padding */
HID_REPORT_COUNT ( 1 ),
+ HID_REPORT_SIZE ( 3 ),
HID_OUTPUT ( HID_CONSTANT ),
-
- HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
- HID_USAGE_MIN ( 0 ),
- HID_USAGE_MAX ( 101 ),
- HID_LOGICAL_MIN ( 0 ),
- HID_LOGICAL_MAX ( 101 ),
-
- HID_REPORT_SIZE ( 8 ),
- HID_REPORT_COUNT ( 6 ),
- HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ), /* keycodes array 6 items */
HID_COLLECTION_END
};
#endif
@@ -173,29 +179,33 @@ uint8_t const _desc_auto_hid_mse_report[] = {
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ),
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ),
HID_USAGE_MIN ( 1 ),
- HID_USAGE_MAX ( 3 ),
+ HID_USAGE_MAX ( 5 ),
HID_LOGICAL_MIN ( 0 ),
HID_LOGICAL_MAX ( 1 ),
+ // Left, Right, Middle, Backward, Forward mouse buttons
+ HID_REPORT_COUNT ( 5 ),
HID_REPORT_SIZE ( 1 ),
- HID_REPORT_COUNT ( 3 ), /* Left, Right and Middle mouse*/
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
- HID_REPORT_SIZE ( 5 ),
+ // 3 bit padding
+ HID_REPORT_SIZE ( 3 ),
HID_REPORT_COUNT ( 1 ),
- HID_INPUT ( HID_CONSTANT ), /* 5 bit padding followed 3 bit buttons */
+ HID_INPUT ( HID_CONSTANT ),
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
+ /* X, Y position */
HID_USAGE ( HID_USAGE_DESKTOP_X ),
HID_USAGE ( HID_USAGE_DESKTOP_Y ),
HID_LOGICAL_MIN ( 0x81 ), /* -127 */
HID_LOGICAL_MAX ( 0x7f ), /* 127 */
+ HID_REPORT_COUNT ( 2 ),
HID_REPORT_SIZE ( 8 ),
- HID_REPORT_COUNT ( 2 ), /* X, Y position */
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), /* relative values */
- HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ), /* mouse scroll */
+ /* mouse scroll */
+ HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ),
HID_LOGICAL_MIN ( 0x81 ), /* -127 */
HID_LOGICAL_MAX ( 0x7f ), /* 127 */
HID_REPORT_COUNT( 1 ),