Fix bthci compilation issue (#3201)
Manifests as multiple definition of esp_event_send during compilation, as bthci triggers inclusion of `event_loop.c`. Also improved lbth_init() to support BTDM or BLE_ONLY controller modes.
This commit is contained in:
parent
084d6cabc5
commit
7774b5fa30
|
@ -16,6 +16,7 @@
|
|||
#include "sdkconfig.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "flash_api.h"
|
||||
|
||||
|
@ -35,10 +36,11 @@
|
|||
static task_handle_t esp_event_task;
|
||||
static QueueHandle_t esp_event_queue;
|
||||
|
||||
// We provide our own esp_event_send which hooks into the NodeMCU task
|
||||
// task framework, and ensures all events are handled in the same context
|
||||
// as the LVM, making life as easy as possible for us.
|
||||
esp_err_t esp_event_send (system_event_t *event)
|
||||
|
||||
// The callback happens in the wrong task context, so we bounce the event
|
||||
// into our own queue so they all get handled in the same context as the
|
||||
// LVM, making life as easy as possible for us.
|
||||
esp_err_t bounce_events(void *ignored_ctx, system_event_t *event)
|
||||
{
|
||||
if (!event)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
|
@ -68,10 +70,6 @@ static void handle_esp_event (task_param_t param, task_prio_t prio)
|
|||
system_event_t evt;
|
||||
while (xQueueReceive (esp_event_queue, &evt, 0) == pdPASS)
|
||||
{
|
||||
esp_err_t ret = esp_event_process_default (&evt);
|
||||
if (ret != ESP_OK)
|
||||
NODE_ERR("default event handler failed for %d", evt.event_id);
|
||||
|
||||
nodemcu_esp_event_reg_t *evregs;
|
||||
for (evregs = &esp_event_cb_table; evregs->callback; ++evregs)
|
||||
{
|
||||
|
@ -154,6 +152,8 @@ void app_main (void)
|
|||
|
||||
input_task = task_get_id (handle_input);
|
||||
|
||||
esp_event_loop_init(bounce_events, NULL);
|
||||
|
||||
ConsoleSetup_t cfg;
|
||||
cfg.bit_rate = CONFIG_CONSOLE_BIT_RATE;
|
||||
cfg.data_bits = CONSOLE_NUM_BITS_8;
|
||||
|
|
|
@ -42,6 +42,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <esp_log.h>
|
||||
#define TAG "bthci"
|
||||
|
||||
#define BD_ADDR_LEN 6
|
||||
typedef uint8_t bd_addr_t[BD_ADDR_LEN];
|
||||
|
||||
|
@ -331,8 +334,26 @@ static int lbthci_init (lua_State *L)
|
|||
cmd_q[i].cb_ref = LUA_NOREF;
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
esp_bt_controller_init (&bt_cfg);
|
||||
esp_bt_controller_enable (ESP_BT_MODE_BTDM);
|
||||
|
||||
esp_err_t ret;
|
||||
if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BTDM_CONTROLLER_MODE_BTDM
|
||||
esp_bt_mode_t mode = ESP_BT_MODE_BTDM;
|
||||
#elif defined CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY
|
||||
esp_bt_mode_t mode = ESP_BT_MODE_BLE;
|
||||
#else
|
||||
ESP_LOGE(TAG, "%s configuration mismatch. Select BLE Only or BTDM mode from menuconfig", __func__);
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
if ((ret = esp_bt_controller_enable(mode)) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
|
||||
return -1;
|
||||
}
|
||||
|
||||
esp_vhci_host_register_callback (&bthci_callbacks);
|
||||
|
||||
|
|
Loading…
Reference in New Issue