esp32: More hacks to get send/receive somewhat working

This commit is contained in:
Matt Kelly 2017-02-21 22:18:19 -05:00 committed by Matthias Ringwald
parent 84784df65f
commit 040f5acd38
6 changed files with 62 additions and 36 deletions

View File

@ -11,7 +11,7 @@ BTSTACK_ROOT := ../../..
# Examples
#include ${BTSTACK_ROOT}/example/Makefile.inc
COMPONENT_ADD_LDFLAGS := -l$(COMPONENT_NAME) $(COMPONENT_PATH)/../components/libbtdm_app/libbtdm_app.a $(COMPONENT_PATH)/../components/libcoexist/libcoexist.a
#COMPONENT_ADD_LDFLAGS := -l$(COMPONENT_NAME) $(COMPONENT_PATH)/../components/libbtdm_app/libbtdm_app.a $(COMPONENT_PATH)/../components/libcoexist/libcoexist.a $(COMPONENT_PATH)/../components/libphy/libphy.a
COMPONENT_ADD_INCLUDEDIRS := $(BTSTACK_ROOT)/src/ble $(BTSTACK_ROOT)/src $(BTSTACK_ROOT)/platform/embedded .

View File

@ -2,37 +2,55 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "esp_err.h"
#include "esp_coexist.h"
#include "freertos/FreeRTOS.h"
#include "bt.h"
/* VHCI function interface */
typedef struct vhci_host_callback {
void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */
int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< callback used to notify that the controller has a packet to send to the host*/
} vhci_host_callback_t;
void dummy_handler(void){};
extern bool API_vhci_host_check_send_available(void);
extern void API_vhci_host_send_packet(uint8_t *data, uint16_t len);
extern void API_vhci_host_register_callback(const vhci_host_callback_t *callback);
extern void btdm_controller_init(void);
// handlers
static void (*rx_done_handler)(void) = dummy_handler;
static void (*tx_done_handler)(void) = dummy_handler;
static uint8_t _data[1024];
static uint16_t _data_len;
static void host_send_pkt_available_cb(void)
{
printf("host_send_pkt_available_cb\n");
}
static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
{
printf("host_recv_pkt_cb: len = %u, data = [", len);
for (size_t i = 0; i < len; i++) {
printf("%02X ", data[i]);
}
printf("]\n");
memcpy(_data, data, len);
_data_len = len;
rx_done_handler();
return 0;
}
static const esp_vhci_host_callback_t vhci_host_cb = {
.notify_host_send_available = host_send_pkt_available_cb,
.notify_host_recv = host_recv_pkt_cb,
};
void hal_uart_dma_init(void){
printf("hal_uart_dma_init\n");
btdm_controller_init();
esp_vhci_host_register_callback(&vhci_host_cb);
}
void hal_uart_dma_set_block_received( void (*block_handler)(void)){
printf("hal_uart_dma_set_block_received\n");
rx_done_handler = block_handler;
}
void hal_uart_dma_set_block_sent( void (*block_handler)(void)){
printf("hal_uart_dma_set_block_sent\n");
}
void hal_uart_dma_set_csr_irq_handler( void (*csr_irq_handler)(void)){
printf("hal_uart_dma_set_csr_irq_handler\n");
tx_done_handler = block_handler;
}
int hal_uart_dma_set_baud(uint32_t baud){
@ -42,13 +60,12 @@ int hal_uart_dma_set_baud(uint32_t baud){
void hal_uart_dma_send_block(const uint8_t *buffer, uint16_t length){
printf("hal_uart_dma_send_block\n");
API_vhci_host_send_packet(buffer, length);
esp_vhci_host_send_packet(buffer, length);
tx_done_handler();
}
void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len){
printf("hal_uart_dma_receive_block\n");
memcpy(buffer, _data, _data_len);
}
void hal_uart_dma_set_sleep(uint8_t sleep){
printf("hal_uart_dma_set_sleep\n");
}

View File

@ -30,31 +30,25 @@
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
// *****************************************************************************
//
// spp_counter demo - it provides an SPP and sends a counter every second
//
// it doesn't use the LCD to get down to a minimal memory footprint
//
// *****************************************************************************
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "btstack_config.h"
#include "btstack_event.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "btstack_run_loop_embedded.h"
//#include "classic/btstack_link_key_db.h"
#include "hci.h"
#include "hci_dump.h"
#include "bt.h"
static void hw_setup(void){
// @TODO
@ -88,15 +82,18 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
}
static void btstack_setup(void){
hci_dump_open(NULL, HCI_DUMP_STDOUT);
/// GET STARTED with BTstack ///
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
// init HCI
hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), &config);
//hci_set_link_key_db(btstack_link_key_db_memory_instance()); // @TODO
//hci_set_chipset(btstack_chipset_cc256x_instance()); // @TODO
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
@ -109,6 +106,8 @@ int app_main(void){
hw_setup();
esp_bt_controller_init();
btstack_setup();
btstack_main(0, NULL);

View File

@ -89,8 +89,10 @@ CONFIG_OPTIMIZATION_LEVEL_DEBUG=y
#
# Component config
#
# CONFIG_BT_ENABLED is not set
CONFIG_BT_RESERVE_DRAM=0
CONFIG_BT_ENABLED=y
CONFIG_BTC_TASK_STACK_SIZE=3072
# CONFIG_BLUEDROID_MEM_DEBUG is not set
CONFIG_BT_RESERVE_DRAM=0x10000
#
# ESP32-specific
@ -136,6 +138,14 @@ CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0
# CONFIG_WIFI_ENABLED is not set
CONFIG_PHY_ENABLED=y
#
# PHY
#
CONFIG_ESP32_PHY_AUTO_INIT=y
# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set
CONFIG_ESP32_PHY_MAX_TX_POWER=20
# CONFIG_ETHERNET is not set
#