Commit dfcb2590 authored by schneider's avatar schneider
Browse files

Merge branch 'schneider/ble-use-open-connection' into 'master'

BLE: Re-use open connection in pycardium

See merge request !461
parents ce5d890c 1aa04cf5
Pipeline #5168 passed with stages
in 1 minute and 13 seconds
......@@ -10,6 +10,7 @@
#include "FreeRTOS.h"
#include "queue.h"
#include "timers.h"
#include <stdint.h>
#include <string.h>
......@@ -24,8 +25,11 @@ static StaticQueue_t ble_event_queue_data;
static uint8_t adv_data_buf[HCI_ADV_DATA_LEN];
static uint8_t sr_data_buf[HCI_ADV_DATA_LEN];
static dmEvt_t connection_open_event;
static TimerHandle_t dm_timer;
static StaticTimer_t dm_timer_data;
static dmEvt_t connection_open_event;
static bool connection_open;
int epic_ble_free_event(struct epic_ble_event *e)
......@@ -147,6 +151,43 @@ int epic_ble_is_connection_open(void)
return AppConnIsOpen();
}
void vDmTimerCallback()
{
send_dm_event(&connection_open_event);
}
int epic_ble_init(void)
{
if (dm_timer == NULL) {
dm_timer = xTimerCreateStatic(
"dmtimer",
1,
pdFALSE, /* one-shot */
0,
vDmTimerCallback,
&dm_timer_data);
}
epic_interrupt_enable(EPIC_INT_BLE);
if (connection_open) {
// Give pycardium a bit of time and then let it
// know that there already is an open connection
int millis = 100;
int ticks = millis * (configTICK_RATE_HZ / 1000);
xTimerChangePeriod(dm_timer, ticks, 0);
}
return 0;
}
int epic_ble_deinit(void)
{
xTimerStop(dm_timer, 0);
epic_interrupt_disable(EPIC_INT_BLE);
return 0;
}
int epic_ble_set_device_name(const uint8_t *buf, uint16_t len)
{
return epic_ble_atts_set_attr(GAP_DN_HDL, buf, len);
......
......@@ -189,6 +189,9 @@ typedef _Bool bool;
#define API_BLE_ATTC_WRITE_NO_RSP 0x18B
#define API_BLE_ATTC_WRITE 0x18C
#define API_BLE_INIT 0x190
#define API_BLE_DEINIT 0x191
/* clang-format on */
typedef uint32_t api_int_id_t;
......@@ -2658,6 +2661,8 @@ API(API_BLE_HID_SEND_REPORT, int epic_ble_hid_send_report(uint8_t report_id, uin
*
* The MicroPython Bluetooth module is still in flux so this API will continue to change as well.
*/
API(API_BLE_INIT, int epic_ble_init(void));
API(API_BLE_DEINIT, int epic_ble_deinit(void));
API(API_BLE_ATTS_DYN_CREATE_GROUP, int epic_atts_dyn_create_service(const uint8_t *uuid, uint8_t uuid_len, uint16_t group_size, void **pSvcHandle));
//API(API_BLE_ATTS_DYN_DELETE_GROUP, void AttsDynDeleteGroup(void *pSvcHandle));
API(API_BLE_ATTS_DYN_DELETE_GROUPS, int epic_ble_atts_dyn_delete_groups(void));
......
......@@ -438,7 +438,7 @@ int mp_bluetooth_init(void)
MP_ROM_INT(EPIC_INT_BLE), (mp_obj_t *)&ble_event_obj
);
clear_events();
epic_interrupt_enable(EPIC_INT_BLE);
epic_ble_init();
active = true;
return 0;
}
......@@ -446,7 +446,7 @@ int mp_bluetooth_init(void)
// Disables the Bluetooth stack. Is a no-op when not enabled.
void mp_bluetooth_deinit(void)
{
epic_interrupt_disable(EPIC_INT_BLE);
epic_ble_deinit();
active = false;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment