mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-20 18:40:31 +00:00
hci_transport: cleanup struct, add init(void *transport_config)
This commit is contained in:
parent
67e0331a16
commit
24b3c62931
@ -173,7 +173,7 @@ static client_state_t * client_for_connection(connection_t *connection);
|
||||
|
||||
|
||||
// MARK: globals
|
||||
static hci_transport_t * transport;
|
||||
static const hci_transport_t * transport;
|
||||
static hci_transport_config_uart_t hci_transport_config_uart;
|
||||
static btstack_timer_source_t timeout;
|
||||
static uint8_t timeout_active = 0;
|
||||
|
@ -106,12 +106,11 @@ static int h4_process(struct btstack_data_source *ds);
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
static void h4_block_received(void);
|
||||
static void h4_block_sent(void);
|
||||
static int h4_open(void *transport_config);
|
||||
static int h4_close(void *transport_config);
|
||||
static int h4_open(void);
|
||||
static int h4_close(void);
|
||||
static void h4_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
||||
static const char * h4_get_transport_name(void);
|
||||
static int h4_set_baudrate(uint32_t baudrate);
|
||||
static int h4_can_send_packet_now(uint8_t packet_type);
|
||||
static int h4_set_baudrate(uint32_t baudrate);
|
||||
|
||||
static int ehcill_send_packet(uint8_t packet_type, uint8_t *packet, int size);
|
||||
static void ehcill_uart_dma_receive_block(uint8_t *buffer, uint16_t size);
|
||||
@ -155,13 +154,14 @@ static btstack_data_source_t hci_transport_h4_dma_ds = {
|
||||
// hci_transport for use by hci
|
||||
static const hci_transport_h4_t hci_transport_h4_ehcill_dma = {
|
||||
{
|
||||
/* .transport.name = */ "H4_EHCILL_EMBEDDED",
|
||||
/* .transport.init = */ NULL,
|
||||
/* .transport.open = */ h4_open,
|
||||
/* .transport.close = */ h4_close,
|
||||
/* .transport.send_packet = */ ehcill_send_packet,
|
||||
/* .transport.register_packet_handler = */ h4_register_packet_handler,
|
||||
/* .transport.get_transport_name = */ h4_get_transport_name,
|
||||
/* .transport.set_baudrate = */ h4_set_baudrate,
|
||||
/* .transport.can_send_packet_now = */ h4_can_send_packet_now,
|
||||
/* .transport.send_packet = */ ehcill_send_packet,
|
||||
/* .transport.set_baudrate = */ h4_set_baudrate,
|
||||
},
|
||||
/* .ds = */ &hci_transport_h4_dma_ds
|
||||
};
|
||||
@ -170,10 +170,6 @@ static const hci_transport_h4_t hci_transport_h4_ehcill_dma = {
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||
}
|
||||
|
||||
static const char * h4_get_transport_name(void){
|
||||
return "H4_EHCILL_DMA";
|
||||
}
|
||||
|
||||
// get h4 singleton
|
||||
hci_transport_t * hci_transport_h4_instance(void){
|
||||
return (hci_transport_t *) &hci_transport_h4_ehcill_dma;
|
||||
@ -190,7 +186,7 @@ static void h4_register_packet_handler(void (*handler)(uint8_t packet_type, uint
|
||||
packet_handler = handler;
|
||||
}
|
||||
|
||||
static int h4_open(const void *transport_config){
|
||||
static int h4_open(void){
|
||||
|
||||
// open uart
|
||||
hal_uart_dma_init();
|
||||
|
@ -83,13 +83,12 @@ static int h4_process(struct btstack_data_source *ds);
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
static void h4_block_received(void);
|
||||
static void h4_block_sent(void);
|
||||
static int h4_open(void *transport_config);
|
||||
static int h4_close(void *transport_config);
|
||||
static int h4_open(void);
|
||||
static int h4_close(void);
|
||||
static void h4_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
||||
static int h4_send_packet(uint8_t packet_type, uint8_t *packet, int size);
|
||||
static const char * h4_get_transport_name(void);
|
||||
static int h4_set_baudrate(uint32_t baudrate);
|
||||
static int h4_can_send_packet_now(uint8_t packet_type);
|
||||
static int h4_send_packet(uint8_t packet_type, uint8_t *packet, int size);
|
||||
static int h4_set_baudrate(uint32_t baudrate);
|
||||
|
||||
// packet reader state machine
|
||||
static H4_STATE h4_state;
|
||||
@ -112,19 +111,22 @@ static btstack_data_source_t hci_transport_h4_dma_ds = {
|
||||
/* .process = */ h4_process
|
||||
};
|
||||
|
||||
static hci_transport_h4_t hci_transport_h4_dma = {
|
||||
// hci_transport for use by hci
|
||||
static const hci_transport_h4_t hci_transport_h4_dma = {
|
||||
{
|
||||
/* .transport.name = */ "H4_EMBEDDED",
|
||||
/* .transport.init = */ NULL,
|
||||
/* .transport.open = */ h4_open,
|
||||
/* .transport.close = */ h4_close,
|
||||
/* .transport.send_packet = */ h4_send_packet,
|
||||
/* .transport.register_packet_handler = */ h4_register_packet_handler,
|
||||
/* .transport.get_transport_name = */ h4_get_transport_name,
|
||||
/* .transport.set_baudrate = */ h4_set_baudrate,
|
||||
/* .transport.can_send_packet_now = */ h4_can_send_packet_now,
|
||||
/* .transport.send_packet = */ ehcill_send_packet,
|
||||
/* .transport.set_baudrate = */ h4_set_baudrate,
|
||||
},
|
||||
/* .ds = */ &hci_transport_h4_dma_ds
|
||||
};
|
||||
|
||||
|
||||
static void h4_init_sm(void){
|
||||
h4_state = H4_W4_PACKET_TYPE;
|
||||
read_pos = 0;
|
||||
@ -133,7 +135,7 @@ static void h4_init_sm(void){
|
||||
}
|
||||
|
||||
|
||||
static int h4_open(const void *transport_config){
|
||||
static int h4_open(void){
|
||||
|
||||
// open uart
|
||||
hal_uart_dma_init();
|
||||
@ -150,7 +152,7 @@ static int h4_open(const void *transport_config){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h4_close(const void *transport_config){
|
||||
static int h4_close(void){
|
||||
// first remove run loop handler
|
||||
btstack_run_loop_remove_data_source(&hci_transport_h4_dma_ds);
|
||||
|
||||
@ -284,10 +286,6 @@ static int h4_can_send_packet_now(uint8_t packet_type){
|
||||
|
||||
}
|
||||
|
||||
static const char * h4_get_transport_name(void){
|
||||
return "H4_DMA";
|
||||
}
|
||||
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,8 @@ typedef struct hci_transport_h4 {
|
||||
// single instance
|
||||
static hci_transport_h4_t * hci_transport_h4 = NULL;
|
||||
|
||||
static hci_transport_config_uart_t * hci_transport_config_uart = NULL;
|
||||
|
||||
static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = dummy_handler;
|
||||
|
||||
// packet reader state machine
|
||||
@ -131,20 +133,21 @@ static int h4_set_baudrate(uint32_t baudrate){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h4_open(const void *transport_config){
|
||||
|
||||
static void h4_init(const void * transport_config){
|
||||
// check for hci_transport_config_uart_t
|
||||
if (!transport_config) {
|
||||
log_error("hci_transport_h4_posix: no config!");
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
if (((hci_transport_config_t*)transport_config)->type != HCI_TRANSPORT_CONFIG_UART) {
|
||||
log_error("hci_transport_h4_posix: config not of type != HCI_TRANSPORT_CONFIG_UART!");
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
hci_transport_config_uart_t * hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config;
|
||||
|
||||
hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config;
|
||||
}
|
||||
|
||||
static int h4_open(void){
|
||||
|
||||
struct termios toptions;
|
||||
int flags = O_RDWR | O_NOCTTY | O_NONBLOCK;
|
||||
int fd = open(hci_transport_config_uart->device_name, flags);
|
||||
@ -205,7 +208,7 @@ static int h4_open(const void *transport_config){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h4_close(const void *transport_config){
|
||||
static int h4_close(void){
|
||||
// first remove run loop handler
|
||||
btstack_run_loop_remove_data_source(hci_transport_h4->ds);
|
||||
|
||||
@ -339,25 +342,23 @@ static int h4_process(struct btstack_data_source *ds) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char * h4_get_transport_name(void){
|
||||
return "H4";
|
||||
}
|
||||
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||
}
|
||||
|
||||
// get h4 singleton
|
||||
hci_transport_t * hci_transport_h4_instance() {
|
||||
const hci_transport_t * hci_transport_h4_instance() {
|
||||
if (hci_transport_h4 == NULL) {
|
||||
hci_transport_h4 = (hci_transport_h4_t*)malloc( sizeof(hci_transport_h4_t));
|
||||
memset(hci_transport_h4, 0, sizeof(hci_transport_h4_t));
|
||||
hci_transport_h4->ds = NULL;
|
||||
hci_transport_h4->transport.name = "H4_POSIX";
|
||||
hci_transport_h4->transport.init = h4_init;
|
||||
hci_transport_h4->transport.open = h4_open;
|
||||
hci_transport_h4->transport.close = h4_close;
|
||||
hci_transport_h4->transport.send_packet = h4_send_packet;
|
||||
hci_transport_h4->transport.register_packet_handler = h4_register_packet_handler;
|
||||
hci_transport_h4->transport.get_transport_name = h4_get_transport_name;
|
||||
hci_transport_h4->transport.set_baudrate = h4_set_baudrate;
|
||||
hci_transport_h4->transport.can_send_packet_now = NULL;
|
||||
hci_transport_h4->transport.send_packet = h4_send_packet;
|
||||
hci_transport_h4->transport.set_baudrate = h4_set_baudrate;
|
||||
}
|
||||
return (hci_transport_t *) hci_transport_h4;
|
||||
return (const hci_transport_t *) hci_transport_h4;
|
||||
}
|
||||
|
@ -84,7 +84,19 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, int size);
|
||||
|
||||
static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, int size) = dummy_handler;
|
||||
|
||||
// prototypes
|
||||
static void h5_init(const void * transport_config){
|
||||
// check for hci_transport_config_uart_t
|
||||
if (!transport_config) {
|
||||
log_error("hci_transport_h4_posix: no config!");
|
||||
return;
|
||||
}
|
||||
if (((hci_transport_config_t*)transport_config)->type != HCI_TRANSPORT_CONFIG_UART) {
|
||||
log_error("hci_transport_h4_posix: config not of type != HCI_TRANSPORT_CONFIG_UART!");
|
||||
return;
|
||||
}
|
||||
hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config;
|
||||
}
|
||||
|
||||
static int h5_open(const void *transport_config){
|
||||
// check for hci_transport_config_uart_t
|
||||
if (!transport_config) {
|
||||
@ -302,17 +314,19 @@ static void dummy_handler(uint8_t *packet, int size){
|
||||
}
|
||||
|
||||
// get h5 singleton
|
||||
hci_transport_t * hci_transport_h5_instance() {
|
||||
if (hci_transport_h5 == NULL) {
|
||||
hci_transport_h5 = malloc( sizeof(hci_transport_h5_t));
|
||||
hci_transport_h5->ds = NULL;
|
||||
hci_transport_h5->transport.open = h5_open;
|
||||
hci_transport_h5->transport.close = h5_close;
|
||||
hci_transport_h5->transport.send_packet = h5_send_packet;
|
||||
hci_transport_h5->transport.register_packet_handler = h5_register_event_packet_handler;
|
||||
hci_transport_h5->transport.get_transport_name = h5_get_transport_name;
|
||||
hci_transport_h5->transport.set_baudrate = NULL;
|
||||
hci_transport_h5->transport.can_send_packet_now = NULL;
|
||||
const hci_transport_t * hci_transport_h5_instance() {
|
||||
if (hci_transport_h4 == NULL) {
|
||||
hci_transport_h4 = (hci_transport_h4_t*)malloc( sizeof(hci_transport_h4_t));
|
||||
memset(hci_transport_h4, 0, sizeof(hci_transport_h4_t));
|
||||
hci_transport_h4->ds = NULL;
|
||||
hci_transport_h4->transport.name = "H5_POSIX";
|
||||
hci_transport_h4->transport.init = h4_init;
|
||||
hci_transport_h4->transport.open = h4_open;
|
||||
hci_transport_h4->transport.close = h4_close;
|
||||
hci_transport_h4->transport.register_packet_handler = h4_register_packet_handler;
|
||||
hci_transport_h4->transport.can_send_packet_now = NULL;
|
||||
hci_transport_h4->transport.send_packet = h4_send_packet;
|
||||
hci_transport_h4->transport.set_baudrate = h4_set_baudrate;
|
||||
}
|
||||
return (hci_transport_t *) hci_transport_h5;
|
||||
return (const hci_transport_t *) hci_transport_h4;
|
||||
}
|
||||
|
@ -748,7 +748,7 @@ void BTstackManager::setup(void){
|
||||
btstack_memory_init();
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
hci_init(transport, NULL, NULL);
|
||||
hci_set_chipset(btstack_chipset_em9301_instance());
|
||||
|
||||
|
@ -98,7 +98,7 @@ int main(void)
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, &config, remote_db);
|
||||
hci_set_chipset(btstack_chipset_cc256x_instance());
|
||||
|
@ -133,10 +133,21 @@ static int read_pos;
|
||||
|
||||
static uint8_t hci_packet[1+HCI_PACKET_BUFFER_SIZE]; // packet type + max(acl header + acl payload, event header + event data)
|
||||
|
||||
static int h4_open(const void *transport_config)
|
||||
{
|
||||
hci_transport_config_uart = (hci_transport_config_uart_t *) transport_config;
|
||||
static void h4_init(const void * transport_config){
|
||||
// check for hci_transport_config_uart_t
|
||||
if (!transport_config) {
|
||||
log_error("hci_transport_h4_posix: no config!");
|
||||
return;
|
||||
}
|
||||
if (((hci_transport_config_t*)transport_config)->type != HCI_TRANSPORT_CONFIG_UART) {
|
||||
log_error("hci_transport_h4_posix: config not of type != HCI_TRANSPORT_CONFIG_UART!");
|
||||
return;
|
||||
}
|
||||
hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config;
|
||||
}
|
||||
|
||||
static int h4_open(void)
|
||||
{
|
||||
int fd = socket(PF_NETGRAPH, SOCK_STREAM, NG_CONTROL);
|
||||
log_info("h4_open: open socket(%u, %u, %u) %d", PF_NETGRAPH, SOCK_STREAM, NG_CONTROL, fd);
|
||||
if (fd < 0) {
|
||||
@ -235,7 +246,7 @@ err_out0:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int h4_close(const void *transport_config){
|
||||
static int h4_close(){
|
||||
// first remove run loop handler
|
||||
btstack_run_loop_remove_data_source(hci_transport_h4->ds);
|
||||
|
||||
@ -345,8 +356,8 @@ static int h4_process(struct btstack_data_source *ds) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void h4_enforce_wake_on(void)
|
||||
{
|
||||
static void h4_enforce_wake_on(void){
|
||||
|
||||
if (!enforce_wake_device) return;
|
||||
|
||||
if (!enforce_wake_fd) {
|
||||
@ -359,8 +370,8 @@ static void h4_enforce_wake_on(void)
|
||||
btstack_run_loop_add_timer(&hci_transport_h4->sleep_timer);
|
||||
}
|
||||
|
||||
static void h4_enforce_wake_off(void)
|
||||
{
|
||||
static void h4_enforce_wake_off(void){
|
||||
|
||||
btstack_run_loop_remove_timer(&hci_transport_h4->sleep_timer);
|
||||
|
||||
if (enforce_wake_fd) {
|
||||
@ -369,32 +380,29 @@ static void h4_enforce_wake_off(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void h4_enforce_wake_timeout(struct btstack_timer_source *ts)
|
||||
{
|
||||
static void h4_enforce_wake_timeout(struct btstack_timer_source *ts){
|
||||
h4_enforce_wake_off();
|
||||
}
|
||||
|
||||
static const char * h4_get_transport_name(void){
|
||||
return "H4_IPHONE";
|
||||
}
|
||||
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||
}
|
||||
|
||||
// get h4 singleton
|
||||
hci_transport_t * hci_transport_h4_instance(void){
|
||||
const hci_transport_t * hci_transport_h4_instance() {
|
||||
if (hci_transport_h4 == NULL) {
|
||||
hci_transport_h4 = malloc( sizeof(hci_transport_h4_t));
|
||||
hci_transport_h4 = (hci_transport_h4_t*)malloc( sizeof(hci_transport_h4_t));
|
||||
memset(hci_transport_h4, 0, sizeof(hci_transport_h4_t));
|
||||
hci_transport_h4->ds = NULL;
|
||||
hci_transport_h4->transport.name = "H4_IPHONE";
|
||||
hci_transport_h4->transport.init = h4_init;
|
||||
hci_transport_h4->transport.open = h4_open;
|
||||
hci_transport_h4->transport.close = h4_close;
|
||||
hci_transport_h4->transport.send_packet = h4_send_packet;
|
||||
hci_transport_h4->transport.register_packet_handler = h4_register_packet_handler;
|
||||
hci_transport_h4->transport.get_transport_name = h4_get_transport_name;
|
||||
hci_transport_h4->transport.set_baudrate = NULL;
|
||||
hci_transport_h4->transport.can_send_packet_now = NULL;
|
||||
hci_transport_h4->transport.send_packet = h4_send_packet;
|
||||
hci_transport_h4->transport.set_baudrate = NULL;
|
||||
}
|
||||
return (hci_transport_t *) hci_transport_h4;
|
||||
return (const hci_transport_t *) hci_transport_h4;
|
||||
}
|
||||
|
||||
void hci_transport_h4_iphone_set_enforce_wake_device(char *path){
|
||||
|
@ -91,7 +91,7 @@ int main(int argc, const char * argv[]){
|
||||
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_usb_instance();
|
||||
cosnt hci_transport_t * transport = hci_transport_usb_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs;
|
||||
hci_init(transport, NULL, remote_db);
|
||||
|
||||
|
@ -375,7 +375,7 @@ int main(void){
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, &config, remote_db);
|
||||
hci_set_chipset(btstack_chipset_cc256x_instance());
|
||||
|
@ -98,7 +98,7 @@ static void btstack_setup(void){
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, &config, remote_db);
|
||||
hci_set_chipset(btstack_chipset_cc256x_instance());
|
||||
|
@ -105,7 +105,7 @@ static void btstack_setup(void){
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, &config, remote_db);
|
||||
hci_set_chipset(btstack_chipset_cc256x_instance());
|
||||
|
@ -225,7 +225,7 @@ void BTSTACK_Initialize ( void )
|
||||
|
||||
hci_dump_open(NULL, HCI_DUMP_STDOUT);
|
||||
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
hci_init(transport, &config, NULL);
|
||||
hci_set_chipset(btstack_chipset_csr_instance());
|
||||
|
||||
|
@ -153,7 +153,7 @@ int main(int argc, const char * argv[]){
|
||||
config.device_name = "/dev/tty.usbserial-A900K0VK";
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs;
|
||||
hci_init(transport, (void*) &config, remote_db);
|
||||
|
||||
|
@ -424,7 +424,7 @@ int main(void)
|
||||
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, (void*) &config, remote_db);
|
||||
hci_set_chipset(btstack_chipset_cc256x_instance());
|
||||
|
@ -92,7 +92,7 @@ void application_start(void){
|
||||
// hci_dump_open(NULL, HCI_DUMP_STDOUT);
|
||||
|
||||
// init HCI
|
||||
hci_transport_t * transport = hci_transport_h4_instance();
|
||||
const hci_transport_t * transport = hci_transport_h4_instance();
|
||||
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
|
||||
hci_init(transport, (void*) &hci_transport_config_uart, remote_db);
|
||||
hci_set_chipset(btstack_chipset_bcm_instance());
|
||||
|
@ -68,9 +68,9 @@ typedef struct {
|
||||
/**
|
||||
* init driver
|
||||
* allows to reset init script index
|
||||
* @param config
|
||||
* @param transport_config
|
||||
*/
|
||||
void (*init)(const void * config);
|
||||
void (*init)(const void * transport_config);
|
||||
|
||||
/**
|
||||
* support custom init sequences after RESET command
|
||||
|
15
src/hci.c
15
src/hci.c
@ -1894,7 +1894,7 @@ static void hci_state_reset(void){
|
||||
hci_stack->le_connection_parameter_range.le_supervision_timeout_max = 3200;
|
||||
}
|
||||
|
||||
void hci_init(hci_transport_t *transport, void *config, remote_device_db_t const* remote_device_db){
|
||||
void hci_init(const hci_transport_t *transport, void *config, remote_device_db_t const* remote_device_db){
|
||||
|
||||
#ifdef HAVE_MALLOC
|
||||
if (!hci_stack) {
|
||||
@ -2024,13 +2024,18 @@ static int hci_power_control_on(void){
|
||||
return err;
|
||||
}
|
||||
|
||||
// reset chipset driver
|
||||
// int chipset driver
|
||||
if (hci_stack->chipset && hci_stack->chipset->init){
|
||||
hci_stack->chipset->init(hci_stack->config);
|
||||
}
|
||||
|
||||
// open low-level device
|
||||
err = hci_stack->hci_transport->open(hci_stack->config);
|
||||
// init transport
|
||||
if (hci_stack->hci_transport->init){
|
||||
hci_stack->hci_transport->init(hci_stack->config);
|
||||
}
|
||||
|
||||
// open transport
|
||||
err = hci_stack->hci_transport->open();
|
||||
if (err){
|
||||
log_error( "HCI_INIT failed, turning Bluetooth off again");
|
||||
if (hci_stack->control && hci_stack->control->off){
|
||||
@ -2047,7 +2052,7 @@ static void hci_power_control_off(void){
|
||||
log_info("hci_power_control_off");
|
||||
|
||||
// close low-level device
|
||||
hci_stack->hci_transport->close(hci_stack->config);
|
||||
hci_stack->hci_transport->close();
|
||||
|
||||
log_info("hci_power_control_off - hci_transport closed");
|
||||
|
||||
|
@ -763,7 +763,7 @@ void hci_local_bd_addr(bd_addr_t address_buffer);
|
||||
/**
|
||||
* @brief Set up HCI. Needs to be called before any other function.
|
||||
*/
|
||||
void hci_init(hci_transport_t *transport, void *config, remote_device_db_t const* remote_device_db);
|
||||
void hci_init(const hci_transport_t *transport, void *config, remote_device_db_t const* remote_device_db);
|
||||
|
||||
/**
|
||||
* @brief Configure Bluetooth chipset driver. Has to be called before power on, or right after receiving the local version information.
|
||||
|
@ -57,15 +57,47 @@ extern "C" {
|
||||
|
||||
/* HCI packet types */
|
||||
typedef struct {
|
||||
int (*open)(const void *transport_config);
|
||||
int (*close)(const void *transport_config);
|
||||
int (*send_packet)(uint8_t packet_type, uint8_t *packet, int size);
|
||||
/**
|
||||
* transport name
|
||||
*/
|
||||
const char * name;
|
||||
|
||||
/**
|
||||
* init transport
|
||||
* @param transport_config
|
||||
*/
|
||||
void (*init) (const void *transport_config);
|
||||
|
||||
/**
|
||||
* open transport connection
|
||||
*/
|
||||
int (*open)(void);
|
||||
|
||||
/**
|
||||
* close transport connection
|
||||
*/
|
||||
int (*close)(void);
|
||||
|
||||
/**
|
||||
* register packet handler for HCI packets: ACL, SCO, and Events
|
||||
*/
|
||||
void (*register_packet_handler)(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
||||
const char * (*get_transport_name)(void);
|
||||
// custom extension for UART transport implementations
|
||||
int (*set_baudrate)(uint32_t baudrate);
|
||||
// support async transport layers, e.g. IRQ driven without buffers
|
||||
|
||||
/**
|
||||
* support async transport layers, e.g. IRQ driven without buffers
|
||||
*/
|
||||
int (*can_send_packet_now)(uint8_t packet_type);
|
||||
|
||||
/**
|
||||
* send packet
|
||||
*/
|
||||
int (*send_packet)(uint8_t packet_type, uint8_t *packet, int size);
|
||||
|
||||
/**
|
||||
* extension for UART transport implementations
|
||||
*/
|
||||
int (*set_baudrate)(uint32_t baudrate);
|
||||
|
||||
} hci_transport_t;
|
||||
|
||||
typedef enum {
|
||||
@ -91,12 +123,12 @@ typedef struct {
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
extern hci_transport_t * hci_transport_h4_instance(void);
|
||||
extern const hci_transport_t * hci_transport_h4_instance(void);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
extern hci_transport_t * hci_transport_usb_instance(void);
|
||||
extern const hci_transport_t * hci_transport_usb_instance(void);
|
||||
|
||||
|
||||
/* API_END */
|
||||
|
Loading…
x
Reference in New Issue
Block a user