Skip to content

Commit bb537a4

Browse files
committed
pbdrv/bluetooth: Debugging changes for virtualhub.
- Implements HCI logging in bluetooth BTStack. - Adds a stderr version of uart_debug_first_port. - (Revert?) Enables debug logging for virtualhub bluetooth.
1 parent 78534ab commit bb537a4

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/pbio/drv/bluetooth/bluetooth_btstack.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,27 @@
5353
#define HUB_VARIANT 0x0000
5454
#endif
5555

56-
#define DEBUG 0
56+
#define DEBUG 1
5757

5858
#if DEBUG
5959
#include <pbdrv/../../drv/uart/uart_debug_first_port.h>
6060
#define DEBUG_PRINT pbdrv_uart_debug_printf
61+
#include <pbdrv/../../drv/uart/uart_debug_first_port.h>
62+
#define DEBUG_PRINT pbdrv_uart_debug_printf
63+
static void pbdrv_hci_dump_reset(void) {
64+
}
65+
static void pbdrv_hci_dump_log_packet(uint8_t packet_type, uint8_t in, uint8_t* packet, uint16_t len) {
66+
pbdrv_uart_debug_printf("HCI %s packet type: %02x, len: %u\n", in ? "in" : "out", packet_type, len);
67+
}
68+
static void pbdrv_hci_dump_log_message(int log_level, const char* format, va_list argptr) {
69+
pbdrv_uart_debug_vprintf(format, argptr);
70+
pbdrv_uart_debug_printf("\n");
71+
}
72+
static const hci_dump_t bluetooth_btstack_classic_hci_dump = {
73+
.reset = pbdrv_hci_dump_reset,
74+
.log_packet = pbdrv_hci_dump_log_packet,
75+
.log_message = pbdrv_hci_dump_log_message,
76+
};
6177
#else
6278
#define DEBUG_PRINT(...)
6379
#endif
@@ -1213,6 +1229,15 @@ void pbdrv_bluetooth_init_hci(void) {
12131229
btstack_run_loop_init(&bluetooth_btstack_run_loop);
12141230

12151231
hci_init(pdata->transport_instance(), pdata->transport_config());
1232+
1233+
#if DEBUG
1234+
hci_dump_init(&bluetooth_btstack_classic_hci_dump);
1235+
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_INFO, true);
1236+
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_ERROR, true);
1237+
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_DEBUG, true);
1238+
hci_dump_enable_packet_log(true);
1239+
#endif
1240+
12161241
if (pdata->chipset_instance != NULL) {
12171242
hci_set_chipset(pdata->chipset_instance());
12181243
}

lib/pbio/drv/uart/uart_debug_first_port.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@ void pbdrv_uart_debug_init(void);
2121

2222
#else // PBDRV_CONFIG_UART_DEBUG_FIRST_PORT
2323

24+
#if PBDRV_CONFIG_UART_DEBUG_FIRST_PORT_IS_STDERR
25+
26+
#include <stdio.h>
27+
28+
#define pbdrv_uart_debug_printf(...) fprintf(stderr, __VA_ARGS__)
29+
#define pbdrv_uart_debug_vprintf(format, argptr) vfprintf(stderr, format, argptr)
30+
31+
#else
32+
2433
#define pbdrv_uart_debug_printf(...)
2534
#define pbdrv_uart_debug_vprintf(format, argptr)
2635

36+
#endif // PBDRV_CONFIG_UART_DEBUG_FIRST_PORT_IS_STDERR
37+
2738
#define pbdrv_uart_debug_is_done() (true)
2839

2940
#define pbdrv_uart_debug_init()

lib/pbio/platform/virtual_hub/pbdrvconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define PBDRV_CONFIG_MOTOR_DRIVER_NUM_DEV (6)
4242
#define PBDRV_CONFIG_MOTOR_DRIVER_VIRTUAL_SIMULATION (1)
4343

44+
#define PBDRV_CONFIG_UART_DEBUG_FIRST_PORT_IS_STDERR (1)
45+
4446
#define PBDRV_CONFIG_HAS_PORT_A (1)
4547
#define PBDRV_CONFIG_HAS_PORT_B (1)
4648
#define PBDRV_CONFIG_HAS_PORT_C (1)

0 commit comments

Comments
 (0)