Skip to content

Commit ac11cb2

Browse files
committed
Implement Zephyr bleio connect and disconnect
Rework the conn_handle related functions because they are port-internal API. Signed-off-by: Scott Shawcroft <scott@tannewt.org>
1 parent 2fbc154 commit ac11cb2

File tree

22 files changed

+496
-165
lines changed

22 files changed

+496
-165
lines changed

devices/ble_hci/common-hal/_bleio/Connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct {
6161
uint8_t disconnect_reason;
6262
} bleio_connection_obj_t;
6363

64+
void common_hal_bleio_check_connected(uint16_t conn_handle);
6465
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
6566
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
6667
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);

locale/circuitpython.pot

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ msgstr ""
476476
msgid "AP could not be started"
477477
msgstr ""
478478

479-
#: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c
479+
#: shared-bindings/ipaddress/IPv4Address.c
480480
#, c-format
481481
msgid "Address must be %d bytes long"
482482
msgstr ""
@@ -673,11 +673,6 @@ msgstr ""
673673
msgid "Brightness not adjustable"
674674
msgstr ""
675675

676-
#: shared-bindings/_bleio/UUID.c
677-
#, c-format
678-
msgid "Buffer + offset too small %d %d %d"
679-
msgstr ""
680-
681676
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
682677
msgid "Buffer elements must be 4 bytes long or less"
683678
msgstr ""
@@ -720,10 +715,6 @@ msgstr ""
720715
msgid "Bus pin %d is already in use"
721716
msgstr ""
722717

723-
#: shared-bindings/_bleio/UUID.c
724-
msgid "Byte buffer must be 16 bytes."
725-
msgstr ""
726-
727718
#: shared-bindings/aesio/aes.c
728719
msgid "CBC blocks must be multiples of 16 bytes"
729720
msgstr ""
@@ -1029,12 +1020,18 @@ msgstr ""
10291020
msgid "Failed to buffer the sample"
10301021
msgstr ""
10311022

1023+
#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
1024+
msgid "Failed to connect"
1025+
msgstr ""
1026+
10321027
#: ports/espressif/common-hal/_bleio/Adapter.c
10331028
#: ports/nordic/common-hal/_bleio/Adapter.c
1029+
#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
10341030
msgid "Failed to connect: internal error"
10351031
msgstr ""
10361032

10371033
#: ports/nordic/common-hal/_bleio/Adapter.c
1034+
#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
10381035
msgid "Failed to connect: timeout"
10391036
msgstr ""
10401037

@@ -2247,10 +2244,6 @@ msgstr ""
22472244
msgid "USB error"
22482245
msgstr ""
22492246

2250-
#: shared-bindings/_bleio/UUID.c
2251-
msgid "UUID integer value must be 0-0xffff"
2252-
msgstr ""
2253-
22542247
#: shared-bindings/_bleio/UUID.c
22552248
msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'"
22562249
msgstr ""
@@ -3393,10 +3386,6 @@ msgstr ""
33933386
msgid "initial values must be iterable"
33943387
msgstr ""
33953388

3396-
#: shared-bindings/_bleio/Characteristic.c shared-bindings/_bleio/Descriptor.c
3397-
msgid "initial_value length is wrong"
3398-
msgstr ""
3399-
34003389
#: py/compile.c
34013390
msgid "inline assembler must be a function"
34023391
msgstr ""
@@ -3808,7 +3797,6 @@ msgid "non-hex digit"
38083797
msgstr ""
38093798

38103799
#: ports/nordic/common-hal/_bleio/Adapter.c
3811-
#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
38123800
msgid "non-zero timeout must be > 0.01"
38133801
msgstr ""
38143802

@@ -4292,7 +4280,6 @@ msgid "timeout duration exceeded the maximum supported value"
42924280
msgstr ""
42934281

42944282
#: ports/nordic/common-hal/_bleio/Adapter.c
4295-
#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
42964283
msgid "timeout must be < 655.35 secs"
42974284
msgstr ""
42984285

ports/espressif/common-hal/_bleio/Connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void bleio_connection_clear(bleio_connection_internal_t *self);
6464

6565
int bleio_connection_event_cb(struct ble_gap_event *event, void *connection_in);
6666

67+
void common_hal_bleio_check_connected(uint16_t conn_handle);
6768
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
6869
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
6970
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);

ports/nordic/common-hal/_bleio/Attribute.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
#pragma once
88

9+
#include <stdbool.h>
10+
11+
#include "py/obj.h"
12+
913
#include "shared-module/_bleio/Attribute.h"
1014

1115
extern void bleio_attribute_gatts_set_security_mode(ble_gap_conn_sec_mode_t *perm, bleio_attribute_security_mode_t security_mode);
16+
17+
size_t common_hal_bleio_gatts_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len);
18+
void common_hal_bleio_gatts_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo);
19+
size_t common_hal_bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len);
20+
void common_hal_bleio_gattc_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo, bool write_no_response);

ports/nordic/common-hal/_bleio/Connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef struct {
6565
void bleio_connection_clear(bleio_connection_internal_t *self);
6666
bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in);
6767

68+
void common_hal_bleio_check_connected(uint16_t conn_handle);
6869
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
6970
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
7071
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);

ports/silabs/common-hal/_bleio/Connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ typedef struct
8585

8686
void bleio_connection_clear(bleio_connection_internal_t *self);
8787

88+
void common_hal_bleio_check_connected(uint16_t conn_handle);
8889
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
8990

9091
mp_obj_t bleio_connection_new_from_internal(

ports/zephyr-cp/boards/nrf5340bsim_nrf5340_cpuapp.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ CONFIG_GPIO=y
66
# Enable Bluetooth stack - bsim is for BT simulation
77
CONFIG_BT=y
88
CONFIG_BT_HCI=y
9+
CONFIG_BT_PERIPHERAL=y
10+
CONFIG_BT_CENTRAL=y
911
CONFIG_BT_OBSERVER=y
1012
CONFIG_BT_BROADCASTER=y
1113

14+
CONFIG_BT_L2CAP_TX_MTU=253
15+
CONFIG_BT_BUF_CMD_TX_SIZE=255
16+
CONFIG_BT_BUF_EVT_RX_COUNT=16
17+
CONFIG_BT_BUF_EVT_RX_SIZE=255
18+
CONFIG_BT_BUF_ACL_TX_COUNT=3
19+
CONFIG_BT_BUF_ACL_TX_SIZE=251
20+
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA=1
21+
CONFIG_BT_BUF_ACL_RX_SIZE=255
22+
1223
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
1324
CONFIG_BT_DEVICE_NAME_MAX=28
1425

0 commit comments

Comments
 (0)