mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 21:35:16 +00:00
Merge branch 'master' of https://github.com/bluekitchen/btstack
This commit is contained in:
commit
911bc0f1af
@ -47,7 +47,7 @@
|
||||
|
||||
#include <stddef.h> /* NULL */
|
||||
#include <stdio.h>
|
||||
#include <string.h> /* memcpy */
|
||||
#include <string.h> /* memcpy */
|
||||
#include "hci.h"
|
||||
#include "debug.h"
|
||||
|
||||
@ -95,6 +95,15 @@ static int stlc2500d_baudrate_cmd(void * config, uint32_t baudrate, uint8_t *hci
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stlc2500d_set_bd_addr_cmd(void * config, bd_addr_t addr, uint8_t *hci_cmd_buffer){
|
||||
bt_store_16(hci_cmd_buffer, 0, OPCODE(OGF_VENDOR, 0x22));
|
||||
hci_cmd_buffer[2] = 0x08;
|
||||
hci_cmd_buffer[3] = 254;
|
||||
hci_cmd_buffer[4] = 0x06;
|
||||
bt_flip_addr(&hci_cmd_buffer[5], addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// MARK: const structs
|
||||
static const bt_control_t bt_control_stlc2500d = {
|
||||
NULL, // on
|
||||
@ -107,7 +116,7 @@ static const bt_control_t bt_control_stlc2500d = {
|
||||
NULL, // next_cmd
|
||||
NULL, // register_for_power_notifications
|
||||
NULL, // hw_error
|
||||
NULL, // set_bd_addr_cmd
|
||||
stlc2500d_set_bd_addr_cmd, // set_bd_addr_cmd
|
||||
};
|
||||
|
||||
// MARK: public API
|
||||
|
@ -80,7 +80,7 @@ static void sigint_handler(int param){
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static led_state = 0;
|
||||
static int led_state = 0;
|
||||
void hal_led_toggle(){
|
||||
led_state = 1 - led_state;
|
||||
printf("LED State %u\n", led_state);
|
||||
|
54
src/hci.c
54
src/hci.c
@ -854,7 +854,7 @@ static void hci_initializing_run(){
|
||||
case HCI_INIT_SEND_READ_LOCAL_VERSION_INFORMATION:
|
||||
hci_send_cmd(&hci_read_local_version_information);
|
||||
hci_stack->substate = HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION;
|
||||
break;
|
||||
break;
|
||||
case HCI_INIT_SEND_RESET_CSR_WARM_BOOT:
|
||||
hci_state_reset();
|
||||
// prepare reset if command complete not received in 100ms
|
||||
@ -865,6 +865,18 @@ static void hci_initializing_run(){
|
||||
hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT;
|
||||
hci_send_cmd(&hci_reset);
|
||||
break;
|
||||
case HCI_INIT_SEND_RESET_ST_WARM_BOOT:
|
||||
hci_state_reset();
|
||||
hci_stack->substate = HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT;
|
||||
hci_send_cmd(&hci_reset);
|
||||
break;
|
||||
case HCI_INIT_SET_BD_ADDR:
|
||||
log_info("Set Public BD ADDR to %s", bd_addr_to_str(hci_stack->custom_bd_addr));
|
||||
hci_stack->control->set_bd_addr_cmd(hci_stack->config, hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer);
|
||||
hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0);
|
||||
hci_stack->substate = HCI_INIT_W4_SET_BD_ADDR;
|
||||
hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]);
|
||||
break;
|
||||
case HCI_INIT_SEND_BAUD_CHANGE:
|
||||
hci_stack->control->baudrate_cmd(hci_stack->config, ((hci_uart_config_t *)hci_stack->config)->baudrate_main, hci_stack->hci_packet_buffer);
|
||||
hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0);
|
||||
@ -877,13 +889,6 @@ static void hci_initializing_run(){
|
||||
run_loop_add_timer(&hci_stack->timeout);
|
||||
}
|
||||
break;
|
||||
case HCI_INIT_SET_BD_ADDR:
|
||||
log_info("Set Public BD ADDR to %s", bd_addr_to_str(hci_stack->custom_bd_addr));
|
||||
hci_stack->control->set_bd_addr_cmd(hci_stack->config, hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer);
|
||||
hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0);
|
||||
hci_stack->substate = HCI_INIT_W4_SET_BD_ADDR;
|
||||
hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]);
|
||||
break;
|
||||
case HCI_INIT_CUSTOM_INIT:
|
||||
log_info("Custom init");
|
||||
// Custom initialization
|
||||
@ -1044,16 +1049,38 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
||||
run_loop_remove_timer(&hci_stack->timeout);
|
||||
break;
|
||||
case HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION:
|
||||
if (need_addr_change){
|
||||
hci_stack->substate = HCI_INIT_SET_BD_ADDR;
|
||||
return;
|
||||
}
|
||||
// skipping addr change
|
||||
if (need_baud_change){
|
||||
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE;
|
||||
return;
|
||||
}
|
||||
// also skip baud change
|
||||
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
|
||||
return;
|
||||
case HCI_INIT_W4_SET_BD_ADDR:
|
||||
// for STLC2500D, bd addr change only gets active after sending reset command
|
||||
if (hci_stack->manufacturer == 0x0030){
|
||||
hci_stack->substate = HCI_INIT_SEND_RESET_ST_WARM_BOOT;
|
||||
return;
|
||||
}
|
||||
// skipping warm boot on STLC2500D
|
||||
if (need_baud_change){
|
||||
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE;
|
||||
return;
|
||||
}
|
||||
// skipping baud change
|
||||
if (need_addr_change){
|
||||
hci_stack->substate = HCI_INIT_SET_BD_ADDR;
|
||||
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
|
||||
return;
|
||||
case HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT:
|
||||
if (need_baud_change){
|
||||
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE;
|
||||
return;
|
||||
}
|
||||
// also skip set bd addr
|
||||
// skipping baud change
|
||||
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
|
||||
return;
|
||||
case HCI_INIT_W4_SEND_BAUD_CHANGE:
|
||||
@ -1064,11 +1091,6 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
|
||||
log_info("Local baud rate change to %u", new_baud);
|
||||
hci_stack->hci_transport->set_baudrate(new_baud);
|
||||
}
|
||||
if (need_addr_change){
|
||||
hci_stack->substate = HCI_INIT_SET_BD_ADDR;
|
||||
return;
|
||||
}
|
||||
// skipping addr change
|
||||
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
|
||||
return;
|
||||
case HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT:
|
||||
|
@ -534,10 +534,14 @@ typedef enum hci_init_state{
|
||||
HCI_INIT_SEND_READ_LOCAL_VERSION_INFORMATION,
|
||||
HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION,
|
||||
|
||||
HCI_INIT_SEND_BAUD_CHANGE,
|
||||
HCI_INIT_W4_SEND_BAUD_CHANGE,
|
||||
HCI_INIT_SET_BD_ADDR,
|
||||
HCI_INIT_W4_SET_BD_ADDR,
|
||||
|
||||
HCI_INIT_SEND_RESET_ST_WARM_BOOT,
|
||||
HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT,
|
||||
|
||||
HCI_INIT_SEND_BAUD_CHANGE,
|
||||
HCI_INIT_W4_SEND_BAUD_CHANGE,
|
||||
HCI_INIT_CUSTOM_INIT,
|
||||
HCI_INIT_W4_CUSTOM_INIT,
|
||||
HCI_INIT_SEND_RESET_CSR_WARM_BOOT,
|
||||
|
Loading…
x
Reference in New Issue
Block a user