From 866d5133bed8c2ebd914f0dc6e121922b39ec272 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Fri, 2 Apr 2021 20:41:58 +0200
Subject: [PATCH] change(ble): Introduce epic_ble_(de)init

---
 epicardium/ble/epic_ble_api.c           | 12 ++++++++++++
 epicardium/epicardium.h                 |  5 +++++
 pycardium/modules/modbluetooth_card10.c |  4 ++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/epicardium/ble/epic_ble_api.c b/epicardium/ble/epic_ble_api.c
index 3b39a7c0a..c812c9b92 100644
--- a/epicardium/ble/epic_ble_api.c
+++ b/epicardium/ble/epic_ble_api.c
@@ -147,6 +147,18 @@ int epic_ble_is_connection_open(void)
 	return AppConnIsOpen();
 }
 
+int epic_ble_init(void)
+{
+	epic_interrupt_enable(EPIC_INT_BLE);
+	return 0;
+}
+
+int epic_ble_deinit(void)
+{
+	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);
diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h
index 33edc9e61..ceacfdf03 100644
--- a/epicardium/epicardium.h
+++ b/epicardium/epicardium.h
@@ -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));
diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c
index 52f630acf..932930d8b 100644
--- a/pycardium/modules/modbluetooth_card10.c
+++ b/pycardium/modules/modbluetooth_card10.c
@@ -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;
 }
 
-- 
GitLab