Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
a7e5c836
Commit
a7e5c836
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
change(mp-ble): Streamline epic API
parent
cf22dd80
No related branches found
No related tags found
No related merge requests found
Pipeline
#5115
passed
4 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
epicardium/ble/epic_att_api.c
+24
-18
24 additions, 18 deletions
epicardium/ble/epic_att_api.c
epicardium/epicardium.h
+3
-3
3 additions, 3 deletions
epicardium/epicardium.h
pycardium/modules/modbluetooth_card10.c
+17
-23
17 additions, 23 deletions
pycardium/modules/modbluetooth_card10.c
with
44 additions
and
44 deletions
epicardium/ble/epic_att_api.c
+
24
−
18
View file @
a7e5c836
...
...
@@ -15,6 +15,14 @@
#include
<stdio.h>
#include
<string.h>
/* We allow up to 10 dynamically defined services */
#define ATTS_DYN_GROUP_COUNT 10
#define ATTS_DYN_START_HANDLE 0x200
static
void
*
dyn_groups
[
ATTS_DYN_GROUP_COUNT
]
=
{};
static
int
next_dyn_group
=
0
;
static
int
next_handle
=
ATTS_DYN_START_HANDLE
;
void
ble_epic_att_api_event
(
attEvt_t
*
att_event
)
{
attEvt_t
*
e
=
WsfBufAlloc
(
sizeof
(
*
e
));
...
...
@@ -70,25 +78,16 @@ static uint8_t DynAttsWriteCback(
return
AttsSetAttr
(
handle
,
len
,
pValue
);
}
/* We allow up to 10 dynamically defined services */
#define ATTS_DYN_GROUP_COUNT 10
#define ATTS_DYN_START_HANDLE 0x200
static
int
next_start_handle
=
ATTS_DYN_START_HANDLE
;
static
void
*
dyn_groups
[
ATTS_DYN_GROUP_COUNT
]
=
{};
static
int
next_dyn_group
=
0
;
int
epic_atts_dyn_create_service
(
const
uint8_t
*
uuid
,
uint8_t
uuid_len
,
uint16_t
group_size
,
void
**
pSvcHandle
,
uint16_t
*
start_handle
void
**
pSvcHandle
)
{
*
start_handle
=
next_start_handle
;
int
end_handle
=
*
start_handle
+
group_size
-
1
;
next_start_handle
+=
group_size
;
uint16_t
start_handle
=
next_handle
;
uint16_t
end_handle
=
start_handle
+
group_size
-
1
;
*
pSvcHandle
=
AttsDynCreateGroup
(
*
start_handle
,
end_handle
);
*
pSvcHandle
=
AttsDynCreateGroup
(
start_handle
,
end_handle
);
dyn_groups
[
next_dyn_group
++
]
=
*
pSvcHandle
;
AttsDynRegister
(
*
pSvcHandle
,
NULL
,
DynAttsWriteCback
);
...
...
@@ -102,6 +101,7 @@ int epic_atts_dyn_create_service(
0
,
ATTS_PERMIT_READ
);
next_handle
++
;
// TODO: validate parameters and pointer and current service count
return
0
;
...
...
@@ -113,7 +113,7 @@ int epic_atts_dyn_add_characteristic(
uint8_t
uuid_len
,
uint8_t
flags
,
uint16_t
maxLen
,
uint16_t
current
_handle
uint16_t
*
value
_handle
)
{
uint8_t
settings
=
ATTS_SET_VARIABLE_LEN
;
if
(
flags
&
ATT_PROP_WRITE
)
{
...
...
@@ -129,7 +129,7 @@ int epic_atts_dyn_add_characteristic(
}
uint8_t
characteristic
[
1
+
2
+
16
]
=
{
flags
,
UINT16_TO_BYTES
(
curren
t_handle
+
1
)
flags
,
UINT16_TO_BYTES
(
nex
t_handle
+
1
)
};
memcpy
(
characteristic
+
3
,
uuid
,
uuid_len
);
uint8_t
characteristic_len
=
1
+
2
+
uuid_len
;
...
...
@@ -144,8 +144,10 @@ int epic_atts_dyn_add_characteristic(
0
,
ATTS_PERMIT_READ
);
next_handle
++
;
/* Value */
*
value_handle
=
next_handle
;
if
((
flags
&
ATT_PROP_READ
)
==
0
)
{
AttsDynAddAttrDynConst
(
pSvcHandle
,
...
...
@@ -169,6 +171,7 @@ int epic_atts_dyn_add_characteristic(
permissions
);
}
next_handle
++
;
return
0
;
}
...
...
@@ -179,7 +182,8 @@ int epic_ble_atts_dyn_add_descriptor(
uint8_t
flags
,
const
uint8_t
*
value
,
uint16_t
value_len
,
uint16_t
maxLen
uint16_t
maxLen
,
uint16_t
*
descriptor_handle
)
{
uint8_t
settings
=
0
;
if
(
flags
&
ATT_PROP_WRITE
)
{
...
...
@@ -194,6 +198,7 @@ int epic_ble_atts_dyn_add_descriptor(
permissions
|=
ATTS_PERMIT_WRITE
;
}
*
descriptor_handle
=
next_handle
;
AttsDynAddAttrDyn
(
pSvcHandle
,
uuid
,
...
...
@@ -204,6 +209,7 @@ int epic_ble_atts_dyn_add_descriptor(
settings
,
permissions
);
next_handle
++
;
return
0
;
}
...
...
@@ -228,7 +234,7 @@ int epic_ble_atts_dyn_delete_groups(void)
}
}
next_dyn_group
=
0
;
next_
start_
handle
=
ATTS_DYN_START_HANDLE
;
next_handle
=
ATTS_DYN_START_HANDLE
;
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
epicardium/epicardium.h
+
3
−
3
View file @
a7e5c836
...
...
@@ -2640,12 +2640,12 @@ 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_ATTS_DYN_CREATE_GROUP
,
int
epic_atts_dyn_create_service
(
const
uint8_t
*
uuid
,
uint8_t
uuid_len
,
uint16_t
group_size
,
void
**
pSvcHandle
,
uint16_t
*
start_handle
));
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
));
API
(
API_BLE_ATTS_DYN_ADD_
DESCRIPTOR
,
int
epic_
ble_
atts_dyn_add_
descriptor
(
void
*
pSvcHandle
,
const
uint8_t
*
uuid
,
uint8_t
uuid_len
,
uint8_t
flags
,
const
uint
8
_t
*
value
,
uint16_t
value_
len
,
uint16_t
maxLen
));
API
(
API_BLE_ATTS_DYN_ADD_
CHARACTERISTIC
,
int
epic_atts_dyn_add_
characteristic
(
void
*
pSvcHandle
,
const
uint8_t
*
uuid
,
uint8_t
uuid_len
,
uint8_t
flags
,
uint16_t
maxLen
,
uint16_t
current
_handle
));
API
(
API_BLE_ATTS_DYN_ADD_
CHARACTERISTIC
,
int
epic_atts_dyn_add_
characteristic
(
void
*
pSvcHandle
,
const
uint8_t
*
uuid
,
uint8_t
uuid_len
,
uint8_t
flags
,
uint
16
_t
maxLen
,
uint16_t
*
value_
handle
));
API
(
API_BLE_ATTS_DYN_ADD_
DESCRIPTOR
,
int
epic_
ble_
atts_dyn_add_
descriptor
(
void
*
pSvcHandle
,
const
uint8_t
*
uuid
,
uint8_t
uuid_len
,
uint8_t
flags
,
const
uint8_t
*
value
,
uint16_t
value_len
,
uint16_t
maxLen
,
uint16_t
*
descriptor
_handle
));
API
(
API_BLE_ATTS_SEND_SERVICE_CHANGED_IND
,
int
epic_atts_dyn_send_service_changed_ind
(
void
));
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/modbluetooth_card10.c
+
17
−
23
View file @
a7e5c836
...
...
@@ -395,21 +395,14 @@ int mp_bluetooth_gatts_register_service(
const
uint16_t
numHandles
=
1
+
num_characteristics
*
2
+
num_ccds
+
num_descriptors_total
;
uint16_t
startHandle
;
uint8_t
uuid_len
=
service_uuid
->
type
==
MP_BLUETOOTH_UUID_TYPE_16
?
2
:
16
;
// TODO: handle error
epic_atts_dyn_create_service
(
service_uuid
->
data
,
uuid_len
,
numHandles
,
&
pSvcHandle
,
&
startHandle
service_uuid
->
data
,
uuid_len
,
numHandles
,
&
pSvcHandle
);
uint16_t
currentHandle
=
startHandle
;
size_t
descriptor_index
=
0
;
size_t
handle_index
=
0
;
...
...
@@ -418,28 +411,26 @@ int mp_bluetooth_gatts_register_service(
mp_obj_bluetooth_uuid_t
*
uuid
=
characteristic_uuids
[
i
];
uuid_len
=
uuid
->
type
==
MP_BLUETOOTH_UUID_TYPE_16
?
2
:
16
;
currentH
andle
++
;
uint16_t
value_h
andle
;
epic_atts_dyn_add_characteristic
(
pSvcHandle
,
uuid
->
data
,
uuid_len
,
flags
,
MP_BLUETOOTH_DEFAULT_ATTR_LEN
,
currentH
andle
&
value_h
andle
);
currentHandle
++
;
;
handles
[
handle_index
]
=
currentH
andle
;
handles
[
handle_index
]
=
value_h
andle
;
mp_bluetooth_gatts_db_create_entry
(
GATTS_DB
,
currentH
andle
,
MP_BLUETOOTH_DEFAULT_ATTR_LEN
GATTS_DB
,
value_h
andle
,
MP_BLUETOOTH_DEFAULT_ATTR_LEN
);
gatts_status_create_entry
(
GATTS_STATUS
,
currentH
andle
);
gatts_status_create_entry
(
GATTS_STATUS
,
value_h
andle
);
if
((
flags
&
MP_BLUETOOTH_CHARACTERISTIC_FLAG_NOTIFY
)
||
flags
&
(
MP_BLUETOOTH_CHARACTERISTIC_FLAG_INDICATE
))
{
/* CCCD */
currentHandle
++
;
uint8_t
cccd_buf
[
2
]
=
{};
// TODO: Handle CCC data.
// Until then: activate notification/indications by default.
...
...
@@ -450,6 +441,7 @@ int mp_bluetooth_gatts_register_service(
cccd_buf
[
0
]
|=
0x02
;
}
uint16_t
cccd_handle
;
uint8_t
ccc_uuid
[]
=
{
0x02
,
0x29
};
uint8_t
flags
=
MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ
|
MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE
;
...
...
@@ -460,17 +452,16 @@ int mp_bluetooth_gatts_register_service(
flags
,
cccd_buf
,
sizeof
(
cccd_buf
),
sizeof
(
cccd_buf
)
);
epic_ble_atts_set_attr
(
currentHandle
,
cccd_buf
,
sizeof
(
cccd_buf
)
sizeof
(
cccd_buf
),
&
cccd_handle
);
mp_bluetooth_gatts_db_create_entry
(
GATTS_DB
,
c
urrentH
andle
,
sizeof
(
cccd_buf
)
GATTS_DB
,
c
ccd_h
andle
,
sizeof
(
cccd_buf
)
);
int
ret
=
mp_bluetooth_gatts_db_write
(
GATTS_DB
,
c
urrentH
andle
,
c
ccd_h
andle
,
cccd_buf
,
sizeof
(
cccd_buf
)
);
...
...
@@ -488,6 +479,7 @@ int mp_bluetooth_gatts_register_service(
uuid_len
=
uuid
->
type
==
MP_BLUETOOTH_UUID_TYPE_16
?
2
:
16
;
uint16_t
descriptor_handle
;
epic_ble_atts_dyn_add_descriptor
(
pSvcHandle
,
uuid
->
data
,
...
...
@@ -495,12 +487,14 @@ int mp_bluetooth_gatts_register_service(
flags
,
NULL
,
0
,
MP_BLUETOOTH_DEFAULT_ATTR_LEN
MP_BLUETOOTH_DEFAULT_ATTR_LEN
,
&
descriptor_handle
);
handles
[
handle_index
]
=
descriptor_handle
;
mp_bluetooth_gatts_db_create_entry
(
GATTS_DB
,
handles
[
handle_index
]
,
descriptor_handle
,
MP_BLUETOOTH_DEFAULT_ATTR_LEN
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment