1515#include "zephyr/gatt.h"
1616#include "adapter/hid_parser.h"
1717#include "adapter/mapping_quirks.h"
18+ #include "hidp/sw2.h"
1819
1920enum {
2021 BT_ATT_HID_DEVICE_NAME = 0 ,
@@ -471,9 +472,14 @@ static void bt_att_hid_process_current_state(struct bt_dev *device,
471472
472473static void bt_att_hid_start_next_state (struct bt_dev * device ,
473474 struct bt_att_hid * hid_data ) {
474- device -> hid_state ++ ;
475- if (device -> hid_state < BT_ATT_HID_STATE_MAX && start_state_func [device -> hid_state ]) {
476- start_state_func [device -> hid_state ](device , hid_data );
475+ if (device -> ids .type == BT_SW2 && !atomic_test_bit (& device -> flags , BT_DEV_HID_INIT_DONE )) {
476+ bt_hid_sw2_init (device );
477+ }
478+ else {
479+ device -> hid_state ++ ;
480+ if (device -> hid_state < BT_ATT_HID_STATE_MAX && start_state_func [device -> hid_state ]) {
481+ start_state_func [device -> hid_state ](device , hid_data );
482+ }
477483 }
478484}
479485
@@ -487,9 +493,14 @@ static int32_t bt_att_get_report_index(struct bt_att_hid *hid_data, uint8_t repo
487493}
488494
489495void bt_att_hid_init (struct bt_dev * device ) {
490- struct bt_att_hid * hid_data = & att_hid [device -> ids .id ];
491- memset ((uint8_t * )hid_data , 0 , sizeof (* hid_data ));
492- bt_att_cmd_mtu_req (device -> acl_handle , bt_att_get_le_max_mtu ());
496+ if (!atomic_test_bit (& device -> flags , BT_DEV_HID_INTR_PENDING )) {
497+ struct bt_att_hid * hid_data = & att_hid [device -> ids .id ];
498+
499+ atomic_set_bit (& device -> flags , BT_DEV_HID_INTR_PENDING );
500+
501+ memset ((uint8_t * )hid_data , 0 , sizeof (* hid_data ));
502+ bt_att_cmd_mtu_req (device -> acl_handle , bt_att_get_le_max_mtu ());
503+ }
493504}
494505
495506void bt_att_write_hid_report (struct bt_dev * device , uint8_t report_id , uint8_t * data , uint32_t len ) {
@@ -530,19 +541,7 @@ void bt_att_hid_hdlr(struct bt_dev *device, struct bt_hci_pkt *bt_hci_acl_pkt, u
530541 if (!atomic_test_bit (& device -> flags , BT_DEV_HID_INTR_READY )) {
531542 bt_hci_stop_inquiry ();
532543
533- if (device -> ids .type == BT_SW2 ) {
534- uint16_t data = BT_GATT_CCC_NOTIFY ;
535- uint8_t led [16 ] = {
536- 0x09 , 0x91 , 0x00 , 0x07 , 0x00 , 0x08 , 0x00 , 0x00 ,
537- bt_hid_led_dev_id_map [device -> ids .out_idx ],
538- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
539- bt_att_cmd_write_req (device -> acl_handle , 0x001b , (uint8_t * )& data , sizeof (data ));
540- bt_att_cmd_write_cmd (device -> acl_handle , 0x0014 , (uint8_t * )& led , sizeof (led ));
541- bt_att_cmd_write_req (device -> acl_handle , 0x000b , (uint8_t * )& data , sizeof (data ));
542- }
543- else {
544- bt_att_hid_start_first_state (device , hid_data );
545- }
544+ bt_att_hid_start_first_state (device , hid_data );
546545 }
547546 break ;
548547 }
@@ -675,27 +674,18 @@ void bt_att_hid_hdlr(struct bt_dev *device, struct bt_hci_pkt *bt_hci_acl_pkt, u
675674 {
676675 struct bt_att_notify * notify = (struct bt_att_notify * )bt_hci_acl_pkt -> att_data ;
677676
678- if (device -> ids .type == BT_SW2 ) {
679- bt_host_bridge (device , 1 , notify -> value , att_len - sizeof (notify -> handle ));
680- }
681- else {
682- for (uint32_t i = 0 ; i < HID_MAX_REPORT ; i ++ ) {
683- if (notify -> handle == hid_data -> reports [i ].report_hdl ) {
684- #ifdef CONFIG_BLUERETRO_ADAPTER_RUMBLE_TEST
685- struct bt_hidp_xb1_rumble rumble = {
686- .enable = 0x03 ,
687- .duration = 0xFF ,
688- .cnt = 0x00 ,
689- };
690- rumble .mag_r = bt_hci_acl_pkt -> hidp_data [11 ];
691- rumble .mag_l = bt_hci_acl_pkt -> hidp_data [9 ];
692- bt_hid_cmd_xbox_rumble (device , & rumble );
693- #else
694- bt_host_bridge (device , hid_data -> reports [i ].id , notify -> value , att_len - sizeof (notify -> handle ));
695- #endif
696- break ;
677+ switch (device -> ids .type ) {
678+ case BT_SW2 :
679+ bt_hid_sw2_hdlr (device , notify -> handle , notify -> value , att_len - sizeof (notify -> handle ));
680+ break ;
681+ default :
682+ for (uint32_t i = 0 ; i < HID_MAX_REPORT ; i ++ ) {
683+ if (notify -> handle == hid_data -> reports [i ].report_hdl ) {
684+ bt_host_bridge (device , hid_data -> reports [i ].id , notify -> value , att_len - sizeof (notify -> handle ));
685+ break ;
686+ }
697687 }
698- }
688+ break ;
699689 }
700690 break ;
701691 }
0 commit comments