add tud_hid_set_idle_cb
- rename tud_hid_mode_changed_cb to tud_hid_mode_changed_cb - add mouse ac pan descriptor template support
This commit is contained in:
		@@ -155,7 +155,7 @@ 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;
 | 
			
		||||
  int8_t  pan;     // using AC Pan
 | 
			
		||||
} hid_mouse_report_t;
 | 
			
		||||
 | 
			
		||||
/// Standard Mouse Buttons Bitmap
 | 
			
		||||
 
 | 
			
		||||
@@ -47,6 +47,9 @@ typedef struct
 | 
			
		||||
{
 | 
			
		||||
  uint8_t itf_num;
 | 
			
		||||
  uint8_t ep_in;
 | 
			
		||||
  uint8_t ep_out; // optional
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  uint8_t boot_protocol; // Boot mouse or keyboard
 | 
			
		||||
  bool    boot_mode;
 | 
			
		||||
 | 
			
		||||
@@ -132,16 +135,15 @@ bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycod
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// MOUSE APPLICATION API
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan)
 | 
			
		||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
 | 
			
		||||
{
 | 
			
		||||
  (void) pan;
 | 
			
		||||
  hid_mouse_report_t report =
 | 
			
		||||
  {
 | 
			
		||||
    .buttons = buttons,
 | 
			
		||||
    .x       = x,
 | 
			
		||||
    .y       = y,
 | 
			
		||||
    .wheel   = scroll,
 | 
			
		||||
    //.pan     = pan
 | 
			
		||||
    .wheel   = vertical,
 | 
			
		||||
    .pan     = horizontal
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  uint8_t itf = 0;
 | 
			
		||||
@@ -158,12 +160,12 @@ bool tud_hid_mouse_move(uint8_t report_id, int8_t x, int8_t y)
 | 
			
		||||
  return tud_hid_mouse_report(report_id, button, x, y, 0, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool tud_hid_mouse_scroll(uint8_t report_id, int8_t scroll, int8_t pan)
 | 
			
		||||
bool tud_hid_mouse_scroll(uint8_t report_id, int8_t vertical, int8_t horizontal)
 | 
			
		||||
{
 | 
			
		||||
  uint8_t itf = 0;
 | 
			
		||||
  uint8_t const button = _hidd_itf[itf].mouse_button;
 | 
			
		||||
 | 
			
		||||
  return tud_hid_mouse_report(report_id, button, 0, 0, scroll, pan);
 | 
			
		||||
  return tud_hid_mouse_report(report_id, button, 0, 0, vertical, horizontal);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
@@ -257,8 +259,13 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
      case HID_REQ_CONTROL_SET_IDLE:
 | 
			
		||||
        // TODO idle rate of report
 | 
			
		||||
        p_hid->idle_rate = tu_u16_high(p_request->wValue);
 | 
			
		||||
        if ( tud_hid_set_idle_cb )
 | 
			
		||||
        {
 | 
			
		||||
          // stall request if callback return false
 | 
			
		||||
          if ( !tud_hid_set_idle_cb(p_hid->idle_rate) ) return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        usbd_control_status(rhport, p_request);
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
@@ -277,7 +284,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
 | 
			
		||||
      case HID_REQ_CONTROL_SET_PROTOCOL:
 | 
			
		||||
        p_hid->boot_mode = 1 - p_request->wValue; // 0 is Boot, 1 is Report protocol
 | 
			
		||||
 | 
			
		||||
        if (tud_hid_mode_changed_cb) tud_hid_mode_changed_cb(p_hid->boot_mode);
 | 
			
		||||
        if (tud_hid_boot_mode_cb) tud_hid_boot_mode_cb(p_hid->boot_mode);
 | 
			
		||||
 | 
			
		||||
        usbd_control_status(rhport, p_request);
 | 
			
		||||
      break;
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,6 @@
 | 
			
		||||
// Class Driver Default Configure & Validation
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// Application API
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
@@ -64,7 +63,11 @@ uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type,
 | 
			
		||||
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
 | 
			
		||||
 | 
			
		||||
// Invoked when host switch mode Boot <-> Report via SET_PROTOCOL request
 | 
			
		||||
ATTR_WEAK void tud_hid_mode_changed_cb(uint8_t boot_mode);
 | 
			
		||||
ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
 | 
			
		||||
 | 
			
		||||
// Invoked when host send SET_IDLE request
 | 
			
		||||
// return false will stall the request
 | 
			
		||||
ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// KEYBOARD API
 | 
			
		||||
@@ -85,9 +88,9 @@ static inline bool tud_hid_keyboard_key_release(uint8_t report_id)
 | 
			
		||||
// layout report as defined by hid_mouse_report_t
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
 | 
			
		||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan);
 | 
			
		||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
 | 
			
		||||
bool tud_hid_mouse_move(uint8_t report_id, int8_t x, int8_t y);
 | 
			
		||||
bool tud_hid_mouse_scroll(uint8_t report_id, int8_t scroll, int8_t pan);
 | 
			
		||||
bool tud_hid_mouse_scroll(uint8_t report_id, int8_t vertical, int8_t horizontal);
 | 
			
		||||
 | 
			
		||||
static inline bool tud_hid_mouse_button_press(uint8_t report_id, uint8_t buttons)
 | 
			
		||||
{
 | 
			
		||||
@@ -160,42 +163,50 @@ static inline bool tud_hid_mouse_button_release(uint8_t report_id)
 | 
			
		||||
 | 
			
		||||
// Mouse Report Descriptor Template
 | 
			
		||||
#define TUD_HID_REPORT_DESC_MOUSE(...) \
 | 
			
		||||
  HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP      )                    ,\
 | 
			
		||||
  HID_USAGE      ( HID_USAGE_DESKTOP_MOUSE     )                    ,\
 | 
			
		||||
  HID_COLLECTION ( HID_COLLECTION_APPLICATION  )                    ,\
 | 
			
		||||
  HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP      )                   ,\
 | 
			
		||||
  HID_USAGE      ( HID_USAGE_DESKTOP_MOUSE     )                   ,\
 | 
			
		||||
  HID_COLLECTION ( HID_COLLECTION_APPLICATION  )                   ,\
 | 
			
		||||
    __VA_ARGS__ \
 | 
			
		||||
    HID_USAGE      ( HID_USAGE_DESKTOP_POINTER )                    ,\
 | 
			
		||||
    HID_COLLECTION ( HID_COLLECTION_PHYSICAL   )                    ,\
 | 
			
		||||
      HID_USAGE_PAGE  ( HID_USAGE_PAGE_BUTTON  )                    ,\
 | 
			
		||||
        HID_USAGE_MIN    ( 1                                      ) ,\
 | 
			
		||||
        HID_USAGE_MAX    ( 3                                      ) ,\
 | 
			
		||||
        HID_LOGICAL_MIN  ( 0                                      ) ,\
 | 
			
		||||
        HID_LOGICAL_MAX  ( 1                                      ) ,\
 | 
			
		||||
        /* Left, Right, Middle, Backward, Forward mouse buttons */   \
 | 
			
		||||
        HID_REPORT_COUNT ( 3                                      ) ,\
 | 
			
		||||
        HID_REPORT_SIZE  ( 1                                      ) ,\
 | 
			
		||||
        HID_INPUT        ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
 | 
			
		||||
    HID_USAGE      ( HID_USAGE_DESKTOP_POINTER )                   ,\
 | 
			
		||||
    HID_COLLECTION ( HID_COLLECTION_PHYSICAL   )                   ,\
 | 
			
		||||
      HID_USAGE_PAGE  ( HID_USAGE_PAGE_BUTTON  )                   ,\
 | 
			
		||||
        HID_USAGE_MIN   ( 1                                      ) ,\
 | 
			
		||||
        HID_USAGE_MAX   ( 5                                      ) ,\
 | 
			
		||||
        HID_LOGICAL_MIN ( 0                                      ) ,\
 | 
			
		||||
        HID_LOGICAL_MAX ( 1                                      ) ,\
 | 
			
		||||
        /* Left, Right, Middle, Backward, Forward buttons */ \
 | 
			
		||||
        HID_REPORT_COUNT( 5                                      ) ,\
 | 
			
		||||
        HID_REPORT_SIZE ( 1                                      ) ,\
 | 
			
		||||
        HID_INPUT       ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
 | 
			
		||||
        /* 3 bit padding */ \
 | 
			
		||||
        HID_REPORT_COUNT ( 1                                      ) ,\
 | 
			
		||||
        HID_REPORT_SIZE  ( 5                                      ) ,\
 | 
			
		||||
        HID_INPUT        ( HID_CONSTANT                           ) ,\
 | 
			
		||||
      HID_USAGE_PAGE  ( HID_USAGE_PAGE_DESKTOP )                    ,\
 | 
			
		||||
        HID_REPORT_COUNT( 1                                      ) ,\
 | 
			
		||||
        HID_REPORT_SIZE ( 3                                      ) ,\
 | 
			
		||||
        HID_INPUT       ( HID_CONSTANT                           ) ,\
 | 
			
		||||
      HID_USAGE_PAGE  ( HID_USAGE_PAGE_DESKTOP )                   ,\
 | 
			
		||||
        /* X, Y position [-127, 127] */ \
 | 
			
		||||
        HID_USAGE        ( HID_USAGE_DESKTOP_X                    ) ,\
 | 
			
		||||
        HID_USAGE        ( HID_USAGE_DESKTOP_Y                    ) ,\
 | 
			
		||||
        HID_LOGICAL_MIN  ( 0x81                                   ) ,\
 | 
			
		||||
        HID_LOGICAL_MAX  ( 0x7f                                   ) ,\
 | 
			
		||||
        HID_REPORT_COUNT ( 2                                      ) ,\
 | 
			
		||||
        HID_REPORT_SIZE  ( 8                                      ) ,\
 | 
			
		||||
        HID_INPUT        ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
 | 
			
		||||
        /* Mouse scroll [-127, 127] */ \
 | 
			
		||||
        HID_USAGE       ( HID_USAGE_DESKTOP_X                    ) ,\
 | 
			
		||||
        HID_USAGE       ( HID_USAGE_DESKTOP_Y                    ) ,\
 | 
			
		||||
        HID_LOGICAL_MIN ( 0x81                                   ) ,\
 | 
			
		||||
        HID_LOGICAL_MAX ( 0x7f                                   ) ,\
 | 
			
		||||
        HID_REPORT_COUNT( 2                                      ) ,\
 | 
			
		||||
        HID_REPORT_SIZE ( 8                                      ) ,\
 | 
			
		||||
        HID_INPUT       ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
 | 
			
		||||
        /* Verital wheel scroll [-127, 127] */ \
 | 
			
		||||
        HID_USAGE       ( HID_USAGE_DESKTOP_WHEEL                )  ,\
 | 
			
		||||
        HID_LOGICAL_MIN ( 0x81                                   )  ,\
 | 
			
		||||
        HID_LOGICAL_MAX ( 0x7f                                   )  ,\
 | 
			
		||||
        HID_REPORT_COUNT( 1                                      )  ,\
 | 
			
		||||
        HID_REPORT_SIZE ( 8                                      )  ,\
 | 
			
		||||
        HID_INPUT       ( HID_DATA | HID_VARIABLE | HID_RELATIVE )  ,\
 | 
			
		||||
    HID_COLLECTION_END                                              ,\
 | 
			
		||||
      HID_USAGE_PAGE  ( HID_USAGE_PAGE_CONSUMER ), \
 | 
			
		||||
       /* Horizontal wheel scroll [-127, 127] */ \
 | 
			
		||||
        HID_USAGE_N     ( HID_USAGE_CONSUMER_AC_PAN, 2           ), \
 | 
			
		||||
        HID_LOGICAL_MIN ( 0x81                                   ), \
 | 
			
		||||
        HID_LOGICAL_MAX ( 0x7f                                   ), \
 | 
			
		||||
        HID_REPORT_COUNT( 1                                      ), \
 | 
			
		||||
        HID_REPORT_SIZE ( 8                                      ), \
 | 
			
		||||
        HID_INPUT       ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), \
 | 
			
		||||
    HID_COLLECTION_END                                            , \
 | 
			
		||||
  HID_COLLECTION_END \
 | 
			
		||||
 | 
			
		||||
// Consumer Control Report Descriptor Template
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user