mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 21:35:16 +00:00
h4_ehcill/h5: provide HCI_EVENT_TRANSPORT_SLEEP_MODE event that indicates to app if it can put device into deep sleep
This commit is contained in:
parent
43b285efe5
commit
62ca45d755
@ -365,6 +365,13 @@ typedef uint8_t sm_key_t[16];
|
|||||||
|
|
||||||
// additional HCI events
|
// additional HCI events
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indicates HCI transport enters/exits Sleep mode
|
||||||
|
* @format 1
|
||||||
|
* @param active
|
||||||
|
*/
|
||||||
|
#define HCI_EVENT_TRANSPORT_SLEEP_MODE 0x66
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Outgoing packet
|
* @brief Outgoing packet
|
||||||
*/
|
*/
|
||||||
|
@ -943,6 +943,16 @@ static inline uint8_t btstack_event_discoverable_enabled_get_discoverable(const
|
|||||||
return event[2];
|
return event[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get field active from event HCI_EVENT_TRANSPORT_SLEEP_MODE
|
||||||
|
* @param event packet
|
||||||
|
* @return active
|
||||||
|
* @note: btstack_type 1
|
||||||
|
*/
|
||||||
|
static inline uint8_t hci_event_transport_sleep_mode_get_active(const uint8_t * event){
|
||||||
|
return event[2];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get field handle from event HCI_EVENT_SCO_CAN_SEND_NOW
|
* @brief Get field handle from event HCI_EVENT_SCO_CAN_SEND_NOW
|
||||||
* @param event packet
|
* @param event packet
|
||||||
|
@ -333,6 +333,19 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
|||||||
|
|
||||||
#ifdef ENABLE_EHCILL
|
#ifdef ENABLE_EHCILL
|
||||||
|
|
||||||
|
static void hci_transport_h4_ehcill_emit_sleep_state(int sleep_active){
|
||||||
|
static int last_state = 0;
|
||||||
|
if (sleep_active == last_state) return;
|
||||||
|
last_state = sleep_active;
|
||||||
|
|
||||||
|
log_info("hci_transport_h4_ehcill_emit_sleep_state: %u", sleep_active);
|
||||||
|
uint8_t event[3];
|
||||||
|
event[0] = HCI_EVENT_TRANSPORT_SLEEP_MODE;
|
||||||
|
event[1] = sizeof(event) - 2;
|
||||||
|
event[2] = sleep_active;
|
||||||
|
packet_handler(HCI_EVENT_PACKET, &event[0], sizeof(event));
|
||||||
|
}
|
||||||
|
|
||||||
static void hci_transport_h4_ehcill_open(void){
|
static void hci_transport_h4_ehcill_open(void){
|
||||||
hci_transport_h4_ehcill_reset_statemachine();
|
hci_transport_h4_ehcill_reset_statemachine();
|
||||||
|
|
||||||
@ -412,6 +425,7 @@ static void hci_transport_h4_ehcill_trigger_wakeup(void){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// UART needed again
|
// UART needed again
|
||||||
|
hci_transport_h4_ehcill_emit_sleep_state(0);
|
||||||
if (btstack_uart_sleep_mode){
|
if (btstack_uart_sleep_mode){
|
||||||
btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF);
|
btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF);
|
||||||
}
|
}
|
||||||
@ -461,6 +475,7 @@ static void hci_transport_h4_ehcill_handle_command(uint8_t action){
|
|||||||
switch(action){
|
switch(action){
|
||||||
case EHCILL_WAKE_UP_IND:
|
case EHCILL_WAKE_UP_IND:
|
||||||
ehcill_state = EHCILL_STATE_AWAKE;
|
ehcill_state = EHCILL_STATE_AWAKE;
|
||||||
|
hci_transport_h4_ehcill_emit_sleep_state(0);
|
||||||
#ifdef ENABLE_LOG_EHCILL
|
#ifdef ENABLE_LOG_EHCILL
|
||||||
log_info("eHCILL: Received WAKE_UP_IND RX");
|
log_info("eHCILL: Received WAKE_UP_IND RX");
|
||||||
#endif
|
#endif
|
||||||
@ -524,9 +539,11 @@ static void hci_transport_h4_ehcill_handle_ehcill_command_sent(void){
|
|||||||
if (btstack_uart_sleep_mode != BTSTACK_UART_SLEEP_OFF){
|
if (btstack_uart_sleep_mode != BTSTACK_UART_SLEEP_OFF){
|
||||||
btstack_uart->set_sleep(btstack_uart_sleep_mode);
|
btstack_uart->set_sleep(btstack_uart_sleep_mode);
|
||||||
}
|
}
|
||||||
|
hci_transport_h4_ehcill_emit_sleep_state(1);
|
||||||
}
|
}
|
||||||
// already packet ready? then start wakeup
|
// already packet ready? then start wakeup
|
||||||
if (hci_transport_h4_ehcill_outgoing_packet_ready()){
|
if (hci_transport_h4_ehcill_outgoing_packet_ready()){
|
||||||
|
hci_transport_h4_ehcill_emit_sleep_state(0);
|
||||||
if (btstack_uart_sleep_mode){
|
if (btstack_uart_sleep_mode){
|
||||||
btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF);
|
btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF);
|
||||||
}
|
}
|
||||||
|
@ -479,6 +479,19 @@ static void hci_transport_h5_queue_packet(uint8_t packet_type, uint8_t *packet,
|
|||||||
hci_packet_size = size;
|
hci_packet_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_transport_h5_emit_sleep_state(int sleep_active){
|
||||||
|
static int last_state = 0;
|
||||||
|
if (sleep_active == last_state) return;
|
||||||
|
last_state = sleep_active;
|
||||||
|
|
||||||
|
log_info("hci_transport_h5_emit_sleep_state: %u", sleep_active);
|
||||||
|
uint8_t event[3];
|
||||||
|
event[0] = HCI_EVENT_TRANSPORT_SLEEP_MODE;
|
||||||
|
event[1] = sizeof(event) - 2;
|
||||||
|
event[2] = sleep_active;
|
||||||
|
packet_handler(HCI_EVENT_PACKET, &event[0], sizeof(event));
|
||||||
|
}
|
||||||
|
|
||||||
static void hci_transport_h5_process_frame(uint16_t frame_size){
|
static void hci_transport_h5_process_frame(uint16_t frame_size){
|
||||||
|
|
||||||
if (frame_size < 4) return;
|
if (frame_size < 4) return;
|
||||||
@ -619,6 +632,7 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){
|
|||||||
if (btstack_uart_sleep_mode){
|
if (btstack_uart_sleep_mode){
|
||||||
log_info("link: received sleep message. Enabling UART Sleep.");
|
log_info("link: received sleep message. Enabling UART Sleep.");
|
||||||
btstack_uart->set_sleep(btstack_uart_sleep_mode);
|
btstack_uart->set_sleep(btstack_uart_sleep_mode);
|
||||||
|
hci_transport_h5_emit_sleep_state(1);
|
||||||
} else {
|
} else {
|
||||||
log_info("link: received sleep message. UART Sleep not supported");
|
log_info("link: received sleep message. UART Sleep not supported");
|
||||||
}
|
}
|
||||||
@ -710,6 +724,7 @@ static void hci_transport_h5_block_sent(void){
|
|||||||
} else {
|
} else {
|
||||||
log_info("link: sent sleep message. UART Sleep not supported");
|
log_info("link: sent sleep message. UART Sleep not supported");
|
||||||
}
|
}
|
||||||
|
hci_transport_h5_emit_sleep_state(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
hci_transport_link_run();
|
hci_transport_link_run();
|
||||||
@ -798,6 +813,7 @@ static int hci_transport_h5_send_packet(uint8_t packet_type, uint8_t *packet, in
|
|||||||
|
|
||||||
// send wakeup first
|
// send wakeup first
|
||||||
if (link_peer_asleep){
|
if (link_peer_asleep){
|
||||||
|
hci_transport_h5_emit_sleep_state(0);
|
||||||
if (btstack_uart_sleep_mode){
|
if (btstack_uart_sleep_mode){
|
||||||
log_info("h5: disable UART sleep");
|
log_info("h5: disable UART sleep");
|
||||||
btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF);
|
btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user