bluetooth tinkering

This commit is contained in:
demik 2020-12-30 19:51:03 +01:00
parent 99f1f997bc
commit 4a9ef9a75f
4 changed files with 109 additions and 64 deletions

View File

@ -47,7 +47,7 @@ void hidh_callback(void *handler_args, esp_event_base_t base, int32_t id, void *
const uint8_t *bda = NULL;
/*
* bda = esp_hidh_event_data_t = union
* esp_hidh_event_data_t = union
*
* struct {
* esp_hidh_dev_t *dev; // HID Remote bluetooth device
@ -113,11 +113,7 @@ void hidh_callback(void *handler_args, esp_event_base_t base, int32_t id, void *
break;
}
case ESP_HIDH_CLOSE_EVENT: {
bda = esp_hidh_dev_bda_get(param->close.dev);
ESP_LOGI(TAG, "closed connection with device " ESP_BD_ADDR_STR ", reason: %s", ESP_BD_ADDR_HEX(bda),
esp_hid_disconnect_reason_str(esp_hidh_dev_transport_get(param->close.dev), param->close.reason));
esp_hidh_dev_free(param->close.dev);
xTaskNotify(t_blue, LED_SLOW, eSetValueWithOverwrite);
blue_close(param);
break;
}
default:
@ -152,15 +148,42 @@ void blue_init(void)
xTaskNotify(t_green, LED_ON, eSetValueWithOverwrite);
xTaskNotify(t_blue, LED_SLOW, eSetValueWithOverwrite);
xTaskCreatePinnedToCore(&blue_scan, "hid_task", 6 * 1024, NULL, 2, NULL, 0);
xTaskCreatePinnedToCore(&blue_scan, "blue_scan", 6 * 1024, NULL, 2, NULL, 0);
}
void blue_close(esp_hidh_event_data_t *p) {
const uint8_t *bda = NULL;
configASSERT(p != NULL);
bda = esp_hidh_dev_bda_get(p->close.dev);
ESP_LOGI(TAG, "closed connection with device " ESP_BD_ADDR_STR ", reason: %s", ESP_BD_ADDR_HEX(bda),
esp_hid_disconnect_reason_str(esp_hidh_dev_transport_get(p->close.dev), p->close.reason));
esp_hidh_dev_free(p->close.dev);
xTaskNotify(t_blue, LED_SLOW, eSetValueWithOverwrite);
}
void blue_open(esp_hidh_event_data_t *p) {
const uint8_t *bda = NULL;
configASSERT(p != NULL);
bda = esp_hidh_dev_bda_get(p->open.dev);
ESP_LOGI(TAG, "opened connection with " ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(bda));
esp_hidh_dev_dump(p->open.dev, stdout);
//fprintf(fp, "BDA:" ESP_BD_ADDR_STR ", Status: %s, Connected: %s, Handle: %d, Usage: %s\n", ESP_BD_ADDR_HEX(dev->bda), s_bta_hh_status_names[dev->status], dev->connected ? "YES" : "NO", dev->bt.handle, esp_hid_usage_str(dev->usage));
//ESP_LOGI(TAG, "opened connection with "
// ESP_LOGI(TAG, "PID: 0x%04x, VID: 0x%04x, VERSION: 0x%04x\n", p->open.dev->config.product_id, p->open.dev->config.vendor_id, p->open.dev->config.version);
//fprintf(fp, "Report Map Length: %d\n", dev->config.report_maps[0].len);
//esp_hidh_dev_report_t *report = dev->reports;
//while (report) {
// fprintf(fp, " %8s %7s %6s, ID: %3u, Length: %3u\n",
// esp_hid_usage_str(report->usage), esp_hid_report_type_str(report->report_type), esp_hid_protocol_mode_str(report->protocol_mode),
// report->report_id, report->value_len);
// report = report->next;
//}
// (p->open.dev, stdout);
xTaskNotify(t_blue, LED_ON, eSetValueWithOverwrite);
gpio_output_enable();
}
@ -205,3 +228,14 @@ void blue_scan(void *pvParameters) {
vTaskDelete(NULL);
}
/*
* /!\ crap below /!\
* This is needed to link bluedroid without BLE
* esp-idf/components/bt/host/bluedroid/api/esp_gap_ble_api.c:386:
* undefined reference to `BTM_CheckAdvData'
*/
//unsigned char *BTM_CheckAdvData(unsigned char *p_adv, unsigned char type, unsigned char *p_length) {
// return (unsigned char *)"";
//}

View File

@ -26,10 +26,11 @@
#define BLUE_H
/* defines */
#define BLUE_SCAN_DURATION 6
#define BLUE_SCAN_DURATION 8
/* prototypes */
void blue_init(void);
void blue_close(esp_hidh_event_data_t *p);
void blue_open(esp_hidh_event_data_t *p);
void blue_scan(void *pvParameters);

View File

@ -51,21 +51,21 @@ void gpio_output_enable(void);
* - GPIO17
*/
#define GPIO_ADB 4
#define GPIO_CLICK 2
#define GPIO_QX1 12
#define GPIO_QX2 13
#define GPIO_QY1 14
#define GPIO_QY2 15
#define GPIO_ADB 4
#define GPIO_CLICK 2
#define GPIO_QX1 12
#define GPIO_QX2 13
#define GPIO_QY1 14
#define GPIO_QY2 15
#define GPIO_OE 22
#define GPIO_ADBSRC 32
#define GPIO_BTOFF 33
#define GPIO_OE 22
#define GPIO_ADBSRC 32
#define GPIO_BTOFF 33
#define GPIO_GREENLED 21
#define GPIO_BLUELED 25
#define GPIO_YELLOWLED 26
#define GPIO_REDLED 27
#define GPIO_REDLED 27
#endif

100
sdkconfig
View File

@ -177,7 +177,8 @@ CONFIG_BTDM_CTRL_PCM_POLAR_FALLING_EDGE=y
# CONFIG_BTDM_CTRL_PCM_POLAR_RISING_EDGE is not set
CONFIG_BTDM_CTRL_PCM_ROLE_EFF=0
CONFIG_BTDM_CTRL_PCM_POLAR_EFF=0
# CONFIG_BTDM_CTRL_AUTO_LATENCY is not set
CONFIG_BTDM_CTRL_AUTO_LATENCY=y
CONFIG_BTDM_CTRL_AUTO_LATENCY_EFF=y
CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT=y
CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF=y
CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=3
@ -207,10 +208,8 @@ CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE=y
CONFIG_BTDM_SCAN_DUPL_TYPE=0
CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=200
# CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN is not set
CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED=y
CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
# CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED is not set
# CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP is not set
# end of Bluetooth controller
CONFIG_BT_BLUEDROID_ENABLED=y
@ -501,26 +500,36 @@ CONFIG_ESP_TLS_USING_MBEDTLS=y
#
# ESP32-specific
#
CONFIG_ESP32_REV_MIN_0=y
# CONFIG_ESP32_REV_MIN_1 is not set
# CONFIG_ESP32_REV_MIN_0 is not set
CONFIG_ESP32_REV_MIN_1=y
# CONFIG_ESP32_REV_MIN_2 is not set
# CONFIG_ESP32_REV_MIN_3 is not set
CONFIG_ESP32_REV_MIN=0
CONFIG_ESP32_REV_MIN=1
CONFIG_ESP32_DPORT_WORKAROUND=y
# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set
CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_80=y
# CONFIG_ESP32_DEFAULT_CPU_FREQ_160 is not set
# CONFIG_ESP32_DEFAULT_CPU_FREQ_240 is not set
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=80
# CONFIG_ESP32_SPIRAM_SUPPORT is not set
# CONFIG_ESP32_TRAX is not set
CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0
# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO=y
# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR is not set
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=2
# CONFIG_ESP32_ULP_COPROC_ENABLED is not set
CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=0
CONFIG_ESP32_DEBUG_OCDAWARE=y
# CONFIG_ESP32_BROWNOUT_DET is not set
CONFIG_ESP32_BROWNOUT_DET=y
CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_1 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_2 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_3 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_4 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_5 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_6 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set
CONFIG_ESP32_BROWNOUT_DET_LVL=0
# CONFIG_ESP32_REDUCE_PHY_TX_POWER is not set
CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
@ -582,10 +591,8 @@ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_ESP_PANIC_HANDLER_IRAM is not set
CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT_OFFSET=2
CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT_OFFSET=1
# end of Common ESP-related
#
@ -645,7 +652,7 @@ CONFIG_HTTPD_PURGE_BUF_LEN=32
CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120
CONFIG_ESP_NETIF_TCPIP_LWIP=y
# CONFIG_ESP_NETIF_LOOPBACK is not set
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=y
# CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER is not set
# end of ESP NETIF Adapter
#
@ -678,8 +685,7 @@ CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
# CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP32_WIFI_RX_BA_WIN=6
# CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED is not set
# CONFIG_ESP32_WIFI_NVS_ENABLED is not set
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
@ -746,21 +752,19 @@ CONFIG_FATFS_PER_FILE_CACHE=y
# Modbus configuration
#
CONFIG_FMB_COMM_MODE_RTU_EN=y
CONFIG_FMB_COMM_MODE_ASCII_EN=y
# CONFIG_FMB_COMM_MODE_ASCII_EN is not set
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=150
CONFIG_FMB_MASTER_DELAY_MS_CONVERT=200
CONFIG_FMB_QUEUE_LENGTH=20
CONFIG_FMB_SERIAL_TASK_STACK_SIZE=2048
CONFIG_FMB_SERIAL_BUF_SIZE=256
CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB=8
CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS=1000
CONFIG_FMB_SERIAL_TASK_PRIO=10
# CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT is not set
CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT=20
CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE=20
CONFIG_FMB_CONTROLLER_STACK_SIZE=4096
CONFIG_FMB_EVENT_QUEUE_TIMEOUT=20
CONFIG_FMB_TIMER_PORT_ENABLED=y
# CONFIG_FMB_TIMER_PORT_ENABLED is not set
CONFIG_FMB_TIMER_GROUP=0
CONFIG_FMB_TIMER_INDEX=0
# CONFIG_FMB_TIMER_ISR_IN_IRAM is not set
@ -805,12 +809,13 @@ CONFIG_FREERTOS_DEBUG_OCDAWARE=y
#
# Heap memory debugging
#
CONFIG_HEAP_POISONING_DISABLED=y
# CONFIG_HEAP_POISONING_LIGHT is not set
# CONFIG_HEAP_POISONING_DISABLED is not set
CONFIG_HEAP_POISONING_LIGHT=y
# CONFIG_HEAP_POISONING_COMPREHENSIVE is not set
CONFIG_HEAP_TRACING_OFF=y
# CONFIG_HEAP_TRACING_STANDALONE is not set
# CONFIG_HEAP_TRACING_TOHOST is not set
# CONFIG_HEAP_TASK_TRACKING is not set
# CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS is not set
# end of Heap memory debugging
@ -863,8 +868,7 @@ CONFIG_LWIP_IP6_FRAG=y
# CONFIG_LWIP_IP_FORWARD is not set
# CONFIG_LWIP_STATS is not set
# CONFIG_LWIP_ETHARP_TRUST_IP_MAC is not set
CONFIG_LWIP_ESP_GRATUITOUS_ARP=y
CONFIG_LWIP_GARP_TMR_INTERVAL=60
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
@ -878,8 +882,7 @@ CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8
# CONFIG_LWIP_AUTOIP is not set
# CONFIG_LWIP_IPV6_AUTOCONFIG is not set
CONFIG_LWIP_NETIF_LOOPBACK=y
CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8
# CONFIG_LWIP_NETIF_LOOPBACK is not set
#
# TCP
@ -940,7 +943,7 @@ CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1
CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000
# end of SNTP
CONFIG_LWIP_ESP_LWIP_ASSERT=y
# CONFIG_LWIP_ESP_LWIP_ASSERT is not set
# end of LWIP
#
@ -1232,14 +1235,14 @@ CONFIG_WL_SECTOR_SIZE=4096
#
# Wi-Fi Provisioning Manager
#
CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16
CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=8
CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30
# end of Wi-Fi Provisioning Manager
#
# Supplicant
#
CONFIG_WPA_MBEDTLS_CRYPTO=y
# CONFIG_WPA_MBEDTLS_CRYPTO is not set
# CONFIG_WPA_DEBUG_PRINT is not set
# CONFIG_WPA_TESTING_OPTIONS is not set
# CONFIG_WPA_WPS_WARS is not set
@ -1312,10 +1315,8 @@ CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR=y
CONFIG_SCAN_DUPLICATE_TYPE=0
CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
# CONFIG_BLE_MESH_SCAN_DUPLICATE_EN is not set
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM=100
CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
# CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED is not set
# CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED is not set
CONFIG_BLUEDROID_ENABLED=y
# CONFIG_NIMBLE_ENABLED is not set
CONFIG_BTC_TASK_STACK_SIZE=3072
@ -1503,12 +1504,22 @@ CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30
CONFIG_ADC2_DISABLE_DAC=y
# CONFIG_SPIRAM_SUPPORT is not set
CONFIG_TRACEMEM_RESERVE_DRAM=0x0
# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
CONFIG_TWO_UNIVERSAL_MAC_ADDRESS=y
# CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS is not set
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=2
# CONFIG_ULP_COPROC_ENABLED is not set
CONFIG_ULP_COPROC_RESERVE_MEM=0
# CONFIG_BROWNOUT_DET is not set
CONFIG_BROWNOUT_DET=y
CONFIG_BROWNOUT_DET_LVL_SEL_0=y
# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set
CONFIG_BROWNOUT_DET_LVL=0
# CONFIG_REDUCE_PHY_TX_POWER is not set
CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set
# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC is not set
@ -1554,7 +1565,7 @@ CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT=20
CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE=20
CONFIG_MB_CONTROLLER_STACK_SIZE=4096
CONFIG_MB_EVENT_QUEUE_TIMEOUT=20
CONFIG_MB_TIMER_PORT_ENABLED=y
# CONFIG_MB_TIMER_PORT_ENABLED is not set
CONFIG_MB_TIMER_GROUP=0
CONFIG_MB_TIMER_INDEX=0
# CONFIG_SUPPORT_STATIC_ALLOCATION is not set
@ -1563,8 +1574,7 @@ CONFIG_TIMER_TASK_STACK_DEPTH=2048
CONFIG_TIMER_QUEUE_LENGTH=10
# CONFIG_L2_TO_L3_COPY is not set
# CONFIG_USE_ONLY_LWIP_SELECT is not set
CONFIG_ESP_GRATUITOUS_ARP=y
CONFIG_GARP_TMR_INTERVAL=60
# CONFIG_ESP_GRATUITOUS_ARP is not set
CONFIG_TCPIP_RECVMBOX_SIZE=32
CONFIG_TCP_MAXRTX=12
CONFIG_TCP_SYNMAXRTX=6