1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-21 12:51:03 +00:00

fixup! feat(core:): introduce BLE driver

This commit is contained in:
tychovrahe 2025-01-03 11:42:09 +01:00
parent bec19dae87
commit 191fa1a026
3 changed files with 16 additions and 11 deletions

View File

@ -57,10 +57,11 @@ typedef struct {
tsqueue_entry_t data_queue_entries[DATA_QUEUE_LEN];
tsqueue_t data_queue;
uint8_t send_buffer[NRF_MAX_TX_DATA_SIZE];
uint8_t send_buffer[SEND_QUEUE_LEN][NRF_MAX_TX_DATA_SIZE];
tsqueue_entry_t send_queue_entries[SEND_QUEUE_LEN];
tsqueue_t send_queue;
systimer_t *timer;
uint16_t ping_cntr;
} ble_driver_t;
@ -84,9 +85,6 @@ static void ble_send_advertising_off(void) {
}
static bool ble_send_erase_bonds(void) {
if (!nrf_is_running()) {
return false;
}
uint8_t cmd = INTERNAL_CMD_ERASE_BONDS;
nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL);
@ -94,9 +92,6 @@ static bool ble_send_erase_bonds(void) {
}
static bool ble_send_disconnect(void) {
if (!nrf_is_running()) {
return false;
}
uint8_t cmd = INTERNAL_CMD_DISCONNECT;
nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL);
@ -205,6 +200,10 @@ static void ble_process_rx_msg_pairing_cancelled(const uint8_t *data,
}
static void ble_process_rx_msg(const uint8_t *data, uint32_t len) {
if (len < 1) {
return;
}
switch (data[0]) {
case INTERNAL_EVENT_STATUS:
ble_process_rx_msg_status(data, len);
@ -300,14 +299,14 @@ void ble_init(void) {
(uint8_t *)drv->send_buffer, NRF_MAX_TX_DATA_SIZE,
SEND_QUEUE_LEN);
systimer_t *timer = systimer_create(ble_loop, NULL);
drv->timer = systimer_create(ble_loop, NULL);
systimer_set_periodic(timer, LOOP_PERIOD_MS);
systimer_set_periodic(drv->timer, LOOP_PERIOD_MS);
nrf_init();
nrf_register_listener(NRF_SERVICE_BLE_MANAGER, ble_process_rx_msg);
nrf_register_listener(NRF_SERVICE_BLE, ble_process_data);
;
drv->initialized = true;
}
@ -318,6 +317,8 @@ void ble_deinit(void) {
return;
}
systimer_delete(drv->timer);
tsqueue_reset(&drv->event_queue);
tsqueue_reset(&drv->data_queue);
tsqueue_reset(&drv->send_queue);

View File

@ -439,6 +439,10 @@ int32_t nrf_send_msg(nrf_service_id_t service, const uint8_t *data,
return -1;
}
if (!nrf_is_running()) {
return -1;
}
int32_t id = 0;
nrf_uart_tx_data_t buffer;

View File

@ -71,7 +71,7 @@ static int32_t get_next_id(tsqueue_t *queue) {
val = queue->next_id;
queue->next_id++;
} else {
queue->next_id = 1;
queue->next_id = 2;
}
return val;
}