Skip to content

Commit cd8ecfd

Browse files
fix: formatted all files
1 parent 57d91e0 commit cd8ecfd

10 files changed

Lines changed: 311 additions & 227 deletions

File tree

src/ble/profile/legacy.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,34 @@ static gattAttribute_t attr_table[] = {
1717
};
1818

1919
static bStatus_t write_handler(uint16 connHandle, gattAttribute_t *pAttr,
20-
uint8 *pValue, uint16 len, uint16 offset, uint8 method)
20+
uint8 *pValue, uint16 len, uint16 offset, uint8 method)
2121
{
22-
if(gattPermitAuthorWrite(pAttr->permissions)) {
22+
if (gattPermitAuthorWrite(pAttr->permissions))
23+
{
2324
return ATT_ERR_INSUFFICIENT_AUTHOR;
2425
}
2526

2627
uint16_t uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
27-
if(uuid == RxCharUUID) {
28+
if (uuid == RxCharUUID)
29+
{
2830
legacy_ble_rx(pValue, len);
2931
return SUCCESS;
3032
}
3133
return ATT_ERR_ATTR_NOT_FOUND;
3234
}
3335

34-
3536
static gattServiceCBs_t service_handlers = {
3637
NULL,
3738
write_handler,
38-
NULL
39-
};
39+
NULL};
4040

4141
int legacy_registerService()
4242
{
4343
uint8 status = SUCCESS;
4444

4545
status = GATTServApp_RegisterService(attr_table,
46-
GATT_NUM_ATTRS(attr_table),
47-
GATT_MAX_ENCRYPT_KEY_SIZE,
48-
&service_handlers);
46+
GATT_NUM_ATTRS(attr_table),
47+
GATT_MAX_ENCRYPT_KEY_SIZE,
48+
&service_handlers);
4949
return (status);
5050
}

src/ble/profile/ng.c

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,53 @@ static gattAttribute_t attr_table[] = {
3434

3535
#define notiAttr attr_table[4]
3636

37-
3837
static bStatus_t write_handler(uint16 connHandle, gattAttribute_t *pAttr,
39-
uint8 *pValue, uint16 len, uint16 offset, uint8 method)
38+
uint8 *pValue, uint16 len, uint16 offset, uint8 method)
4039
{
4140
PRINT("ble: write_handler(): connHandle: %04X\n", connHandle);
4241

43-
if (!gattPermitWrite(pAttr->permissions)) {
42+
if (!gattPermitWrite(pAttr->permissions))
43+
{
4444
return ATT_ERR_WRITE_NOT_PERMITTED;
4545
}
46-
46+
4747
uint16_t uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
48-
if(uuid == GATT_CLIENT_CHAR_CFG_UUID) {
48+
if (uuid == GATT_CLIENT_CHAR_CFG_UUID)
49+
{
4950
bStatus_t ret = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len,
50-
offset, GATT_CLIENT_CFG_NOTIFY);
51+
offset, GATT_CLIENT_CFG_NOTIFY);
5152
PRINT("ble: CCCD changed: %02X\n", TxCCCD->value);
5253
return ret;
5354
}
5455

55-
if (uuid == RxCharUUID) {
56+
if (uuid == RxCharUUID)
57+
{
5658
return ng_parse(pValue, len);
5759
}
5860

5961
return ATT_ERR_ATTR_NOT_FOUND;
6062
}
6163

6264
static bStatus_t read_handler(uint16_t connHandle, gattAttribute_t *pAttr,
63-
uint8_t *pValue, uint16_t *pLen, uint16_t offset,
64-
uint16_t maxLen, uint8_t method)
65+
uint8_t *pValue, uint16_t *pLen, uint16_t offset,
66+
uint16_t maxLen, uint8_t method)
6567
{
66-
if (!gattPermitRead(pAttr->permissions)) {
68+
if (!gattPermitRead(pAttr->permissions))
69+
{
6770
return ATT_ERR_READ_NOT_PERMITTED;
6871
}
6972

7073
uint16_t uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
71-
if(uuid == GATT_CLIENT_CHAR_CFG_UUID) {
74+
if (uuid == GATT_CLIENT_CHAR_CFG_UUID)
75+
{
7276
*pLen = 2;
7377
tmos_memcpy(pValue, pAttr->pValue, *pLen);
7478
return SUCCESS;
7579
}
7680

77-
if (uuid == TxCharUUID) {
78-
*pLen = MIN(TxLen-offset, maxLen);
81+
if (uuid == TxCharUUID)
82+
{
83+
*pLen = MIN(TxLen - offset, maxLen);
7984
tmos_memcpy(pValue, &pAttr->pValue[offset], *pLen);
8085
return SUCCESS;
8186
}
@@ -86,23 +91,22 @@ static bStatus_t read_handler(uint16_t connHandle, gattAttribute_t *pAttr,
8691
static gattServiceCBs_t service_handlers = {
8792
read_handler,
8893
write_handler,
89-
NULL
90-
};
94+
NULL};
9195

9296
static void connStatus_handler(uint16 connHandle, uint8 changeType)
9397
{
94-
if(connHandle == LOOPBACK_CONNHANDLE)
98+
if (connHandle == LOOPBACK_CONNHANDLE)
9599
return;
96100

97101
// Reset ClientCharConfig if connection has dropped
98-
if((changeType == LINKDB_STATUS_UPDATE_REMOVED)
99-
|| ((changeType == LINKDB_STATUS_UPDATE_STATEFLAGS)
100-
&& (!linkDB_Up(connHandle)))) {
102+
if ((changeType == LINKDB_STATUS_UPDATE_REMOVED) || ((changeType == LINKDB_STATUS_UPDATE_STATEFLAGS) && (!linkDB_Up(connHandle))))
103+
{
101104
GATTServApp_InitCharCfg(connHandle, TxCCCD);
102105
}
103-
if (badge_cfg.ble_always_on) {
104-
PRINT("BLE disconnected, restarting advertising due to Always-On\n");
105-
ble_enable_advertise();
106+
if (badge_cfg.ble_always_on)
107+
{
108+
PRINT("BLE disconnected, restarting advertising due to Always-On\n");
109+
ble_enable_advertise();
106110
}
107111
}
108112

@@ -113,9 +117,9 @@ int ng_registerService()
113117
linkDB_Register(connStatus_handler);
114118

115119
status = GATTServApp_RegisterService(attr_table,
116-
GATT_NUM_ATTRS(attr_table),
117-
GATT_MAX_ENCRYPT_KEY_SIZE,
118-
&service_handlers);
120+
GATT_NUM_ATTRS(attr_table),
121+
GATT_MAX_ENCRYPT_KEY_SIZE,
122+
&service_handlers);
119123
return (status);
120124
}
121125

@@ -127,36 +131,39 @@ static uint8 isNotifyEnabled(uint16 connHandle)
127131
/**
128132
* @brief Send notify to client. Currently support one client connection
129133
* only.
130-
*
134+
*
131135
* @param val Value to be sent
132136
* @param len length of val. This should not be larger than MTU.
133137
* @return bStatus_t
134138
*/
135139
bStatus_t ng_notify(uint8_t *val, uint8_t len)
136140
{
137-
if(!isNotifyEnabled(TxCCCD->connHandle)) {
141+
if (!isNotifyEnabled(TxCCCD->connHandle))
142+
{
138143
PRINT("ble: ng_notify() notify is not enabled\n");
139144
return bleIncorrectMode;
140145
}
141-
if(len > ATT_GetMTU(TxCCCD->connHandle)) {
146+
if (len > ATT_GetMTU(TxCCCD->connHandle))
147+
{
142148
return bleInvalidRange;
143149
}
144150

145151
attHandleValueNoti_t noti = {
146152
.handle = notiAttr.handle,
147-
.len = len
148-
};
153+
.len = len};
149154
noti.pValue = GATT_bm_alloc(TxCCCD->connHandle, ATT_HANDLE_VALUE_NOTI,
150-
len, NULL, 0);
151-
if (noti.pValue == NULL) {
155+
len, NULL, 0);
156+
if (noti.pValue == NULL)
157+
{
152158
return bleMemAllocError;
153159
}
154160

155161
tmos_memcpy(noti.pValue, val, len);
156162

157163
bStatus_t ret = GATT_Notification(TxCCCD->connHandle, &noti, FALSE);
158164
GATT_bm_free((gattMsg_t *)&noti, ATT_HANDLE_VALUE_NOTI);
159-
if (ret != SUCCESS) {
165+
if (ret != SUCCESS)
166+
{
160167
PRINT("ble: noti sending failed\n");
161168
return ret;
162169
}

src/ble/setup.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
#include <memory.h>
2-
#include <stdlib.h>
3-
#include <stdint.h>
4-
#include <string.h>
51
#include "CH58x_common.h"
6-
2+
#include "CH58x_sys.h"
3+
#include "CH58xBLE_LIB.h"
4+
5+
#include "leddrv.h"
6+
#include "button.h"
7+
#include "bmlist.h"
8+
#include "resource.h"
9+
#include "animation.h"
10+
#include "font.h"
11+
12+
#include "power.h"
13+
#include "data.h"
714
#include "config.h"
815
#include "debug.h"
16+
17+
#include "ble/setup.h"
18+
#include "ble/profile.h"
19+
20+
#include "usb/usb.h"
921
#include "legacyctrl.h"
10-
#include "ngctrl.h"
1122

1223
#ifndef BLE_BUFF_LEN
13-
// MTU = 64 but clients should request new MTU, otherwise default will be 23
14-
#define BLE_BUFF_LEN (64 + 4)
24+
#define BLE_BUFF_LEN (64 + 4) // MTU = 64
1525
#endif
1626

1727
#ifndef BLE_TX_NUM_EVENT
18-
#define BLE_TX_NUM_EVENT 1
28+
#define BLE_TX_NUM_EVENT 1
1929
#endif
2030

2131
#ifndef BLE_TX_POWER
22-
#define BLE_TX_POWER LL_TX_POWEER_6_DBM
23-
// #define BLE_TX_POWER LL_TX_POWEER_MINUS_16_DBM
32+
#define BLE_TX_POWER LL_TX_POWEER_6_DBM
33+
// #define BLE_TX_POWER LL_TX_POWER_MINUS_16_DBM
2434
#endif
2535

2636
#ifndef BLE_MEMHEAP_SIZE
27-
#define BLE_MEMHEAP_SIZE (1024 * 6)
37+
#define BLE_MEMHEAP_SIZE (1024 * 6)
2838
#endif
2939

3040
#ifndef CENTRAL_MAX_CONNECTION
31-
#define CENTRAL_MAX_CONNECTION 1
41+
#define CENTRAL_MAX_CONNECTION 1
3242
#endif
3343

3444
#ifndef BLE_BUFF_NUM
35-
// The BLE lib automatically stack up Write Long messages in Write handler.
36-
// A connection will be disconnected if this number is some how not enough.
37-
#define BLE_BUFF_NUM (512 / 23)
45+
#define BLE_BUFF_NUM (512 / 23)
3846
#endif
3947

4048
#ifndef PERIPHERAL_MAX_CONNECTION
41-
#define PERIPHERAL_MAX_CONNECTION 1
49+
#define PERIPHERAL_MAX_CONNECTION 1
4250
#endif
4351

4452
static __attribute__((aligned(4), section(".noinit")))
@@ -74,9 +82,7 @@ void ble_hardwareInit(void)
7482
cfg.TxNumEvent = (uint32_t)BLE_TX_NUM_EVENT;
7583
cfg.TxPower = (uint32_t)BLE_TX_POWER;
7684
cfg.ConnectNumber = (PERIPHERAL_MAX_CONNECTION & 3) | (CENTRAL_MAX_CONNECTION << 2);
77-
7885
cfg.SelRTCClock = 1 << 7;
79-
8086
cfg.rcCB = lsi_calib;
8187

8288
uint8_t m[6];
@@ -92,14 +98,17 @@ void ble_setup(void)
9298
tmos_clockInit();
9399
peripheral_init();
94100

95-
if (badge_cfg.ble_always_on) {
101+
if (badge_cfg.ble_always_on)
102+
{
96103
ble_enable_advertise();
97-
} else {
104+
}
105+
else
106+
{
98107
ble_disable_advertise();
99108
}
100109

101110
devInfo_registerService();
102111
legacy_registerService();
103112
batt_registerService();
104113
ng_registerService();
105-
}
114+
}

src/config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
#define SPLASH_MIN_SPEED_T (10) // ms
1010

11-
#define SPLASH_MAX_WIDTH (48) // pixels
11+
#define SPLASH_MAX_WIDTH (48) // pixels
1212
#define SPLASH_MAX_HEIGHT (44) // pixels
1313
#define SPLASH_MAX_SIZE (ALIGN_1BYTE(SPLASH_MAX_WIDTH) * SPLASH_MAX_HEIGHT)
1414

15-
typedef struct {
15+
typedef struct
16+
{
1617
// Turn on Bluetooth while in Normal mode and disable Downloads mode
1718
uint8_t ble_always_on;
1819
char ble_devname[20];
@@ -33,7 +34,6 @@ typedef struct {
3334
} __attribute__((packed)) badge_cfg_t;
3435

3536
extern badge_cfg_t badge_cfg;
36-
3737
void cfg_init();
3838
int cfg_writeflash(uint16_t flash_offs, badge_cfg_t *cfg);
3939
int cfg_readflash(uint16_t flash_offs, badge_cfg_t *cfg);

0 commit comments

Comments
 (0)