@@ -44,6 +44,21 @@ extern "C" {
4444/** Length of encoded HID Information. */
4545#define BT_HIDS_INFORMATION_LEN 4
4646
47+ /** Maximum number of connection interval groups in HID SCI Information. */
48+ #define BT_HIDS_SCI_INFORMATION_MAX_GROUPS BT_CONN_LE_MAX_CONN_INTERVAL_GROUPS
49+
50+ /** Max length of encoded HID SCI Information based on the HIDS specification:
51+ * Minimum supported conn interval (1 B) + Num groups (1 B) +
52+ * Num groups * (Group Min (2 B) + Group Max (2 B) + Group Stride (2 B)).
53+ */
54+ #define BT_HIDS_SCI_INFORMATION_MAX_LEN (1 + 1 + BT_HIDS_SCI_INFORMATION_MAX_GROUPS * (2 + 2 + 2))
55+ #define BT_HIDS_SCI_INFORMATION_MIN_LEN 2
56+
57+ /** The transport interval which the device must support to be compliant
58+ * with the HID over GATT Profile specification (chapter 7.4).
59+ */
60+ #define BT_HIDS_MAX_MINIMAL_TRANSPORT_INTERVAL_US 1250
61+
4762/**
4863 * @brief Declare a HIDS instance.
4964 *
@@ -116,15 +131,37 @@ enum bt_hids_flags {
116131 BT_HIDS_REMOTE_WAKE = BIT (0 ),
117132 /** Device advertises when bonded but not connected. */
118133 BT_HIDS_NORMALLY_CONNECTABLE = BIT (1 ),
134+ /** Device is capable of supporting the HID SCI feature */
135+ BT_HIDS_SCI_SUPPORTED = BIT (2 ),
136+ /** Device is capable of supporting the HID SCI Low Power mode feature */
137+ BT_HIDS_SCI_LOW_POWER_MODE_SUPPORTED = BIT (3 ),
119138};
120139
121- /** @brief HID Control Point settings. */
122- enum bt_hids_control_point {
140+ /**
141+ * @brief HID Control Point settings.
142+ *
143+ * @deprecated Use @ref bt_hids_cp_evt instead
144+ */
145+ __deprecated enum bt_hids_control_point {
123146 /** Suspend value for Control Point. */
124147 BT_HIDS_CONTROL_POINT_SUSPEND = 0x00 ,
125148
126149 /** Exit suspend value for Control Point.*/
127- BT_HIDS_CONTROL_POINT_EXIT_SUSPEND = 0x01
150+ BT_HIDS_CONTROL_POINT_EXIT_SUSPEND = 0x01 ,
151+ };
152+
153+ /** @brief HID SCI Mode values */
154+ enum bt_hids_sci_mode_value {
155+ /** SCI None mode. */
156+ BT_HIDS_SCI_MODE_NONE = 0x00 ,
157+ /** SCI Default mode. */
158+ BT_HIDS_SCI_MODE_DEFAULT = 0x02 ,
159+ /** SCI Fast mode. */
160+ BT_HIDS_SCI_MODE_FAST = 0x03 ,
161+ /** SCI Low Power mode. */
162+ BT_HIDS_SCI_MODE_LOW_POWER = 0x04 ,
163+ /** SCI Full Range mode. */
164+ BT_HIDS_SCI_MODE_FULL_RANGE = 0x05 ,
128165};
129166
130167/** HID Service Protocol Mode events. */
@@ -137,10 +174,18 @@ enum bt_hids_pm_evt {
137174
138175/** HID Service Control Point events. */
139176enum bt_hids_cp_evt {
140- /** Suspend command received. */
141- BT_HIDS_CP_EVT_HOST_SUSP ,
142- /** Exit suspend command received. */
143- BT_HIDS_CP_EVT_HOST_EXIT_SUSP ,
177+ /** Suspend command. */
178+ BT_HIDS_CP_EVT_HOST_SUSP = 0x00 ,
179+ /** Exit suspend command. */
180+ BT_HIDS_CP_EVT_HOST_EXIT_SUSP = 0x01 ,
181+ /** SCI Default mode request. */
182+ BT_HIDS_CP_EVT_HOST_SCI_DEFAULT_REQ = 0x02 ,
183+ /** SCI Fast mode request. */
184+ BT_HIDS_CP_EVT_HOST_SCI_FAST_REQ = 0x03 ,
185+ /** SCI Low Power mode request. */
186+ BT_HIDS_CP_EVT_HOST_SCI_LOW_POWER_REQ = 0x04 ,
187+ /** SCI Full Range mode request. */
188+ BT_HIDS_CP_EVT_HOST_SCI_FULL_RANGE_REQ = 0x05 ,
144189};
145190
146191/** HID notification events. */
@@ -377,12 +422,22 @@ struct bt_hids_pm_data {
377422};
378423
379424/** @brief HID Control Point event handler.
425+ *
426+ * @deprecated Use @ref bt_hids_conn_cp_evt_handler_t instead
380427 *
381428 * @param evt Event indicating that the Control Point value has changed.
382429 * (see @ref bt_hids_cp_evt).
383430 */
384431typedef void (* bt_hids_cp_evt_handler_t ) (enum bt_hids_cp_evt evt );
385432
433+ /** @brief HID Control Point event handler.
434+ *
435+ * @param evt Event indicating that the Control Point value has changed.
436+ * (see @ref bt_hids_cp_evt).
437+ * @param conn Pointer to Connection Object.
438+ */
439+ typedef void (* bt_hids_conn_cp_evt_handler_t ) (enum bt_hids_cp_evt evt , struct bt_conn * conn );
440+
386441/** @brief Control Point.
387442 */
388443struct bt_hids_cp {
@@ -391,8 +446,24 @@ struct bt_hids_cp {
391446
392447 /** Callback with new Control Point state.*/
393448 bt_hids_cp_evt_handler_t evt_handler ;
449+
450+ /** Callback with new Control Point state.*/
451+ bt_hids_conn_cp_evt_handler_t conn_evt_handler ;
394452};
395453
454+ #if defined(CONFIG_BT_HIDS_SCI )
455+ /** @brief SCI mode.
456+ */
457+ struct bt_hids_sci_mode_data {
458+ /** CCC descriptor. */
459+ struct bt_gatt_ccc_managed_user_data ccc ;
460+
461+ /** Index in the service attribute array. */
462+ uint8_t att_ind ;
463+ };
464+
465+ #endif /* CONFIG_BT_HIDS_SCI */
466+
396467/** @brief HID initialization.
397468 */
398469struct bt_hids_init_param {
@@ -414,9 +485,15 @@ struct bt_hids_init_param {
414485 /** Callback for Protocol Mode characteristic. */
415486 bt_hids_pm_evt_handler_t pm_evt_handler ;
416487
417- /** Callback for Control Point characteristic. */
488+ /** Callback for Control Point event.
489+ *
490+ * @deprecated Use @ref conn_cp_evt_handler instead
491+ */
418492 bt_hids_cp_evt_handler_t cp_evt_handler ;
419493
494+ /** Callback for Control Point event. */
495+ bt_hids_conn_cp_evt_handler_t conn_cp_evt_handler ;
496+
420497 /** Callback for Boot Mouse Input Report. */
421498 bt_hids_notify_handler_t boot_mouse_notif_handler ;
422499
@@ -466,6 +543,10 @@ struct bt_hids {
466543 /** Control Point. */
467544 struct bt_hids_cp cp ;
468545
546+ #if defined(CONFIG_BT_HIDS_SCI )
547+ /** SCI mode data. */
548+ struct bt_hids_sci_mode_data sci_mode_data ;
549+ #endif
469550 /** Buffer with encoded HID Information. */
470551 uint8_t info [BT_HIDS_INFORMATION_LEN ];
471552
@@ -502,6 +583,14 @@ struct bt_hids_conn_data {
502583
503584 /** Pointer to Feature Reports Context data. */
504585 uint8_t * feat_rep_ctx ;
586+
587+ #if defined(CONFIG_BT_HIDS_SCI )
588+ /** Pending SCI mode value. */
589+ uint8_t pending_sci_mode ;
590+
591+ /** SCI mode value. */
592+ uint8_t sci_mode ;
593+ #endif
505594};
506595
507596
@@ -631,6 +720,51 @@ int bt_hids_boot_kb_inp_rep_send(struct bt_hids *hids_obj, struct bt_conn *conn,
631720 uint8_t const * rep , uint16_t len ,
632721 bt_gatt_complete_func_t cb );
633722
723+ /** @brief Request a new HID SCI mode.
724+ * This function will request connection parameters for the mode.
725+ * The user of the API must call @ref bt_hids_sci_conn_rate_changed to apply the new mode
726+ * when the connection rate change event is received from the Bluetooth stack
727+ * (conn_rate_changed callback).
728+ *
729+ * @note The function is not thread safe.
730+ *
731+ * @param conn Pointer to Connection Object.
732+ * @param mode New SCI mode.
733+ *
734+ * @return 0 If the operation was successful.
735+ * Otherwise, a (negative) error code is returned.
736+ */
737+ int bt_hids_sci_mode_change_request (struct bt_conn * conn ,
738+ enum bt_hids_sci_mode_value mode );
739+
740+ /** @brief Handle a SCI connection rate change.
741+ * This function will validate the new connection parameters
742+ * to the SCI mode pending from a previous call to @ref bt_hids_sci_mode_change_request
743+ * and apply the new mode on success.
744+ * If the connection parameters do not match the pending mode
745+ * the mode will be set to NONE.
746+ * If no pending mode is set, the current mode will be validated against the new
747+ * connection parameters.
748+ * The new SCI mode will be returned in the new_mode parameter.
749+ * Calling this function with status != BT_HCI_ERR_SUCCESS will clear the pending mode.
750+ *
751+ * @note The function is not thread safe.
752+ * @note As the HID SCI mode must be the same for all HID services,
753+ * this function does not require the bt_hids object parameter.
754+ * It will update the mode for all registered services.
755+ *
756+ * @param conn Pointer to Connection Object.
757+ * @param status Status of the connection rate change.
758+ * @param params Parameters of the connection rate change.
759+ * @param new_mode Output parameter for the new SCI mode.
760+ *
761+ * @return 0 if the mode was updated to the pending mode
762+ * -EPIPE if the mode defaulted to NONE due to parameters validation error.
763+ * Otherwise, a (negative) error code is returned.
764+ */
765+ int bt_hids_sci_conn_rate_changed (struct bt_conn * conn , uint8_t status ,
766+ const struct bt_conn_le_conn_rate_changed * params ,
767+ enum bt_hids_sci_mode_value * new_mode );
634768
635769#ifdef __cplusplus
636770}
0 commit comments