diff options
| author | François Cartegnie <281376+fcartegnie@users.noreply.github.com> | 2024-07-09 08:46:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-09 08:46:19 +0200 |
| commit | a6c62295e92b3d960700508a445be1fba71a3cc2 (patch) | |
| tree | 35c825b6551afad7688813d7de510111a67bf007 /src/ble/setup.c | |
| parent | 69b530cbbb72ad9e4b9a7a6c4742f29540664d00 (diff) | |
| parent | 8274cab154f198447f12028e1686bbe2a6de6ebd (diff) | |
Merge pull request #30 from kienvo/ble-init
feat: Bluetooth LE initial setup
Diffstat (limited to 'src/ble/setup.c')
| -rw-r--r-- | src/ble/setup.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/ble/setup.c b/src/ble/setup.c new file mode 100644 index 0000000..7049acb --- /dev/null +++ b/src/ble/setup.c @@ -0,0 +1,72 @@ +#include <memory.h>
+#include <stdlib.h>
+
+#include "setup.h"
+#include "CH58xBLE_LIB.h"
+#include "CH58x_common.h"
+
+#ifndef BLE_BUFF_LEN
+#define BLE_BUFF_LEN 27
+#endif
+#ifndef BLE_BUFF_NUM
+#define BLE_BUFF_NUM 5
+#endif
+#ifndef BLE_TX_NUM_EVENT
+#define BLE_TX_NUM_EVENT 1
+#endif
+#ifndef BLE_TX_POWER
+#define BLE_TX_POWER LL_TX_POWEER_6_DBM
+#endif
+#ifndef BLE_MEMHEAP_SIZE
+#define BLE_MEMHEAP_SIZE (1024*6)
+#endif
+#ifndef CENTRAL_MAX_CONNECTION
+#define CENTRAL_MAX_CONNECTION 3
+#endif
+#ifndef PERIPHERAL_MAX_CONNECTION
+#define PERIPHERAL_MAX_CONNECTION 1
+#endif
+
+static __attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
+
+static void lsi_calib(void)
+{
+ Calibration_LSI(Level_128);
+}
+
+void tmos_clockInit(void)
+{
+ sys_safe_access_enable();
+ R8_CK32K_CONFIG &= ~(RB_CLK_OSC32K_XT | RB_CLK_XT32K_PON);
+ sys_safe_access_enable();
+ R8_CK32K_CONFIG |= RB_CLK_INT32K_PON;
+ sys_safe_access_disable();
+ lsi_calib();
+
+ RTC_InitTime(2020, 1, 1, 0, 0, 0);
+ TMOS_TimerInit(0);
+}
+
+void ble_hardwareInit(void)
+{
+ bleConfig_t cfg;
+ memset(&cfg, 0, sizeof(bleConfig_t));
+
+ cfg.MEMAddr = (uint32_t)MEM_BUF;
+ cfg.MEMLen = (uint32_t)BLE_MEMHEAP_SIZE;
+ cfg.BufMaxLen = (uint32_t)BLE_BUFF_LEN;
+ cfg.BufNumber = (uint32_t)BLE_BUFF_NUM;
+ cfg.TxNumEvent = (uint32_t)BLE_TX_NUM_EVENT;
+ cfg.TxPower = (uint32_t)BLE_TX_POWER;
+ cfg.ConnectNumber = (PERIPHERAL_MAX_CONNECTION & 3) | (CENTRAL_MAX_CONNECTION << 2);
+
+ cfg.SelRTCClock = 1 << 7;
+
+ cfg.rcCB = lsi_calib;
+
+ uint8_t m[6];
+ GetMACAddress(m);
+ memcpy(cfg.MacAddr, m, 6);
+
+ BLE_LibInit(&cfg);
+}
|