mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 03:35:20 +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
|
||||
|
||||
/**
|
||||
* @brief Indicates HCI transport enters/exits Sleep mode
|
||||
* @format 1
|
||||
* @param active
|
||||
*/
|
||||
#define HCI_EVENT_TRANSPORT_SLEEP_MODE 0x66
|
||||
|
||||
/**
|
||||
* @brief Outgoing packet
|
||||
*/
|
||||
|
@ -943,6 +943,16 @@ static inline uint8_t btstack_event_discoverable_enabled_get_discoverable(const
|
||||
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
|
||||
* @param event packet
|
||||
|
@ -333,6 +333,19 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||
|
||||
#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){
|
||||
hci_transport_h4_ehcill_reset_statemachine();
|
||||
|
||||
@ -412,6 +425,7 @@ static void hci_transport_h4_ehcill_trigger_wakeup(void){
|
||||
break;
|
||||
}
|
||||
// UART needed again
|
||||
hci_transport_h4_ehcill_emit_sleep_state(0);
|
||||
if (btstack_uart_sleep_mode){
|
||||
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){
|
||||
case EHCILL_WAKE_UP_IND:
|
||||
ehcill_state = EHCILL_STATE_AWAKE;
|
||||
hci_transport_h4_ehcill_emit_sleep_state(0);
|
||||
#ifdef ENABLE_LOG_EHCILL
|
||||
log_info("eHCILL: Received WAKE_UP_IND RX");
|
||||
#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){
|
||||
btstack_uart->set_sleep(btstack_uart_sleep_mode);
|
||||
}
|
||||
hci_transport_h4_ehcill_emit_sleep_state(1);
|
||||
}
|
||||
// already packet ready? then start wakeup
|
||||
if (hci_transport_h4_ehcill_outgoing_packet_ready()){
|
||||
hci_transport_h4_ehcill_emit_sleep_state(0);
|
||||
if (btstack_uart_sleep_mode){
|
||||
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;
|
||||
}
|
||||
|
||||
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){
|
||||
|
||||
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){
|
||||
log_info("link: received sleep message. Enabling UART Sleep.");
|
||||
btstack_uart->set_sleep(btstack_uart_sleep_mode);
|
||||
hci_transport_h5_emit_sleep_state(1);
|
||||
} else {
|
||||
log_info("link: received sleep message. UART Sleep not supported");
|
||||
}
|
||||
@ -710,6 +724,7 @@ static void hci_transport_h5_block_sent(void){
|
||||
} else {
|
||||
log_info("link: sent sleep message. UART Sleep not supported");
|
||||
}
|
||||
hci_transport_h5_emit_sleep_state(1);
|
||||
}
|
||||
|
||||
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
|
||||
if (link_peer_asleep){
|
||||
hci_transport_h5_emit_sleep_state(0);
|
||||
if (btstack_uart_sleep_mode){
|
||||
log_info("h5: disable UART sleep");
|
||||
btstack_uart->set_sleep(BTSTACK_UART_SLEEP_OFF);
|
||||
|
Loading…
x
Reference in New Issue
Block a user