1
0
mirror of https://github.com/bluekitchen/btstack.git synced 2025-03-25 16:43:28 +00:00

esp32: Use generic transport instead

This commit is contained in:
Matt Kelly 2017-02-21 23:03:36 -05:00 committed by Matthias Ringwald
parent 040f5acd38
commit e4eb95214f
2 changed files with 78 additions and 81 deletions
port/esp32/main

@ -1,71 +0,0 @@
#include "hal_uart_dma.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "bt.h"
void dummy_handler(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");
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");
tx_done_handler = block_handler;
}
int hal_uart_dma_set_baud(uint32_t baud){
printf("hal_uart_dma_set_baud\n");
return -1;
}
void hal_uart_dma_send_block(const uint8_t *buffer, uint16_t length){
printf("hal_uart_dma_send_block\n");
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);
}

@ -50,18 +50,88 @@
#include "hci_dump.h"
#include "bt.h"
static void hw_setup(void){
// @TODO
static int can_send_packet_now = 0;
static void (*transport_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
static void host_send_pkt_available_cb(void)
{
printf("host_send_pkt_available_cb\n");
can_send_packet_now = 1;
}
static hci_transport_config_uart_t config = {
HCI_TRANSPORT_CONFIG_UART,
115200,
1000000, // main baudrate
1, // flow control
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");
transport_packet_handler(HCI_EVENT_PACKET, data, len);
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,
};
/**
* init transport
* @param transport_config
*/
static void transport_init(const void *transport_config){
esp_vhci_host_register_callback(&vhci_host_cb);
}
/**
* open transport connection
*/
static int transport_open(void){
return 0;
}
/**
* close transport connection
*/
static int transport_close(void){
return 0;
}
/**
* register packet handler for HCI packets: ACL, SCO, and Events
*/
static void transport_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
transport_packet_handler = handler;
}
static int transport_can_send_packet_now(uint8_t packet_type) {
return can_send_packet_now;
}
static int transport_send_packet(uint8_t packet_type, uint8_t *packet, int size){
(void)packet_type;
esp_vhci_host_send_packet(packet, size);
return 0;
}
static const hci_transport_t transport = {
"VHCI",
&transport_init,
&transport_open,
&transport_close,
&transport_register_packet_handler,
&transport_can_send_packet_now,
&transport_send_packet,
NULL,
NULL,
NULL,
};
static const hci_transport_t * transport_get_instance(void){
return &transport;
}
static btstack_packet_callback_registration_t hci_event_callback_registration;
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
@ -90,7 +160,7 @@ static void btstack_setup(void){
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_init(transport_get_instance(), NULL);
//hci_set_link_key_db(btstack_link_key_db_memory_instance()); // @TODO
//hci_set_chipset(btstack_chipset_cc256x_instance()); // @TODO
@ -104,8 +174,6 @@ extern int btstack_main(int argc, const char * argv[]);
// main
int app_main(void){
hw_setup();
esp_bt_controller_init();
btstack_setup();