1818#include "sdp.h"
1919#include "att.h"
2020#include "../util.h"
21+ #include "debug.h"
2122
2223//#define H4_TRACE /* Display packet dump that can be parsed by wireshark/text2pcap */
24+ //#define BT_DBG /* Run bt_host_dbg function after HID channels are setup */
2325
2426#define BT_TX 0
2527#define BT_RX 1
3234 /* BT CTRL flags */
3335 BT_CTRL_READY ,
3436 BT_HOST_DISCONN_SW_INHIBIT ,
37+ BT_HOST_DBG_MODE ,
3538};
3639
3740struct bt_host_link_keys {
@@ -316,6 +319,12 @@ static int bt_host_rx_pkt(uint8_t *data, uint16_t len) {
316319 bt_h4_trace (data , len , BT_RX );
317320#endif /* H4_TRACE */
318321
322+ #ifdef BT_DBG
323+ if (atomic_test_bit (& bt_flags , BT_HOST_DBG_MODE )) {
324+ bt_dbg (data , len );
325+ }
326+ else {
327+ #endif
319328 switch (bt_hci_pkt -> h4_hdr .type ) {
320329 case BT_HCI_H4_TYPE_ACL :
321330 bt_host_acl_hdlr (bt_hci_pkt , len );
@@ -327,6 +336,9 @@ static int bt_host_rx_pkt(uint8_t *data, uint16_t len) {
327336 printf ("# %s unsupported packet type: 0x%02X\n" , __FUNCTION__ , bt_hci_pkt -> h4_hdr .type );
328337 break ;
329338 }
339+ #ifdef BT_DBG
340+ }
341+ #endif
330342
331343 return 0 ;
332344}
@@ -406,6 +418,16 @@ int32_t bt_host_init(void) {
406418 io_conf .pull_up_en = GPIO_PULLUP_ENABLE ;
407419 gpio_config (& io_conf );
408420
421+ #ifdef BT_DBG
422+ io_conf .intr_type = GPIO_PIN_INTR_DISABLE ;
423+ io_conf .mode = GPIO_MODE_OUTPUT ;
424+ io_conf .pull_down_en = GPIO_PULLDOWN_DISABLE ;
425+ io_conf .pull_up_en = GPIO_PULLUP_ENABLE ;
426+ io_conf .pin_bit_mask = 1ULL << 26 ;
427+ gpio_config (& io_conf );
428+ gpio_set_level (26 , 1 );
429+ #endif
430+
409431 bt_host_load_bdaddr_from_file ();
410432
411433 esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT ();
@@ -478,6 +500,10 @@ int32_t bt_host_store_link_key(struct bt_hci_evt_link_key_notify *link_key_notif
478500}
479501
480502void bt_host_bridge (struct bt_dev * device , uint8_t report_id , uint8_t * data , uint32_t len ) {
503+ #ifdef BT_DBG
504+ atomic_set_bit (& bt_flags , BT_HOST_DBG_MODE );
505+ bt_dbg_init (device -> type );
506+ #else
481507 if (device -> type == HID_GENERIC ) {
482508 uint32_t i = 0 ;
483509 for (; i < REPORT_MAX ; i ++ ) {
@@ -499,4 +525,5 @@ void bt_host_bridge(struct bt_dev *device, uint8_t report_id, uint8_t *data, uin
499525 adapter_bridge (& bt_adapter .data [device -> id ]);
500526 }
501527 bt_adapter .data [device -> id ].report_cnt ++ ;
528+ #endif
502529}
0 commit comments