Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devices/ble_hci/common-hal/_bleio/Characteristic.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
}

const uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
common_hal_bleio_check_connected(conn_handle);
bleio_check_connected(conn_handle);

uint16_t cccd_value =
(notify ? CCCD_NOTIFY : 0) |
Expand Down
1 change: 1 addition & 0 deletions devices/ble_hci/common-hal/_bleio/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct {
uint8_t disconnect_reason;
} bleio_connection_obj_t;

void bleio_check_connected(uint16_t conn_handle);
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);
Expand Down
2 changes: 1 addition & 1 deletion devices/ble_hci/common-hal/_bleio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bleio_adapter_obj_t *common_hal_bleio_allocate_adapter_or_raise(void) {
return &common_hal_bleio_adapter_obj;
}

void common_hal_bleio_check_connected(uint16_t conn_handle) {
void bleio_check_connected(uint16_t conn_handle) {
if (conn_handle == BLE_CONN_HANDLE_INVALID) {
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
}
Expand Down
27 changes: 7 additions & 20 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ msgstr ""
msgid "AP could not be started"
msgstr ""

#: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c
#: shared-bindings/ipaddress/IPv4Address.c
#, c-format
msgid "Address must be %d bytes long"
msgstr ""
Expand Down Expand Up @@ -673,11 +673,6 @@ msgstr ""
msgid "Brightness not adjustable"
msgstr ""

#: shared-bindings/_bleio/UUID.c
#, c-format
msgid "Buffer + offset too small %d %d %d"
msgstr ""

#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Buffer elements must be 4 bytes long or less"
msgstr ""
Expand Down Expand Up @@ -720,10 +715,6 @@ msgstr ""
msgid "Bus pin %d is already in use"
msgstr ""

#: shared-bindings/_bleio/UUID.c
msgid "Byte buffer must be 16 bytes."
msgstr ""

#: shared-bindings/aesio/aes.c
msgid "CBC blocks must be multiples of 16 bytes"
msgstr ""
Expand Down Expand Up @@ -1029,12 +1020,18 @@ msgstr ""
msgid "Failed to buffer the sample"
msgstr ""

#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
msgid "Failed to connect"
msgstr ""

#: ports/espressif/common-hal/_bleio/Adapter.c
#: ports/nordic/common-hal/_bleio/Adapter.c
#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
msgid "Failed to connect: internal error"
msgstr ""

#: ports/nordic/common-hal/_bleio/Adapter.c
#: ports/zephyr-cp/common-hal/_bleio/Adapter.c
msgid "Failed to connect: timeout"
msgstr ""

Expand Down Expand Up @@ -2247,10 +2244,6 @@ msgstr ""
msgid "USB error"
msgstr ""

#: shared-bindings/_bleio/UUID.c
msgid "UUID integer value must be 0-0xffff"
msgstr ""

#: shared-bindings/_bleio/UUID.c
msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'"
msgstr ""
Expand Down Expand Up @@ -3393,10 +3386,6 @@ msgstr ""
msgid "initial values must be iterable"
msgstr ""

#: shared-bindings/_bleio/Characteristic.c shared-bindings/_bleio/Descriptor.c
msgid "initial_value length is wrong"
msgstr ""

#: py/compile.c
msgid "inline assembler must be a function"
msgstr ""
Expand Down Expand Up @@ -3808,7 +3797,6 @@ msgid "non-hex digit"
msgstr ""

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

Expand Down Expand Up @@ -4292,7 +4280,6 @@ msgid "timeout duration exceeded the maximum supported value"
msgstr ""

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

Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/_bleio/Characteristic.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
}

const uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
common_hal_bleio_check_connected(conn_handle);
bleio_check_connected(conn_handle);

uint16_t cccd_value =
(notify ? 1 << 0 : 0) |
Expand Down
1 change: 1 addition & 0 deletions ports/espressif/common-hal/_bleio/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void bleio_connection_clear(bleio_connection_internal_t *self);

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

void bleio_check_connected(uint16_t conn_handle);
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/_bleio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void check_notify(BaseType_t result) {
mp_raise_msg(&mp_type_TimeoutError, NULL);
}

void common_hal_bleio_check_connected(uint16_t conn_handle) {
void bleio_check_connected(uint16_t conn_handle) {
if (conn_handle == BLEIO_HANDLE_INVALID) {
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
}
Expand Down
9 changes: 9 additions & 0 deletions ports/nordic/common-hal/_bleio/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

#pragma once

#include <stdbool.h>

#include "py/obj.h"

#include "shared-module/_bleio/Attribute.h"

extern void bleio_attribute_gatts_set_security_mode(ble_gap_conn_sec_mode_t *perm, bleio_attribute_security_mode_t security_mode);

size_t bleio_gatts_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len);
void bleio_gatts_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo);
size_t bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len);
void bleio_gattc_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo, bool write_no_response);
10 changes: 5 additions & 5 deletions ports/nordic/common-hal/_bleio/Characteristic.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *sel
if (self->handle != BLE_GATT_HANDLE_INVALID) {
uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
if (common_hal_bleio_service_get_is_remote(self->service)) {
return common_hal_bleio_gattc_read(self->handle, conn_handle, buf, len);
return bleio_gattc_read(self->handle, conn_handle, buf, len);
} else {
// conn_handle is ignored for non-system attributes.
return common_hal_bleio_gatts_read(self->handle, conn_handle, buf, len);
return bleio_gatts_read(self->handle, conn_handle, buf, len);
}
}

Expand All @@ -159,7 +159,7 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self,
if (common_hal_bleio_service_get_is_remote(self->service)) {
uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
// Last argument is true if write-no-reponse desired.
common_hal_bleio_gattc_write(self->handle, conn_handle, bufinfo,
bleio_gattc_write(self->handle, conn_handle, bufinfo,
(self->props & CHAR_PROP_WRITE_NO_RESPONSE));
} else {
// Validate data length for local characteristics only.
Expand All @@ -172,7 +172,7 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self,

// Always write the value locally even if no connections are active.
// conn_handle is ignored for non-system attributes, so we use BLE_CONN_HANDLE_INVALID.
common_hal_bleio_gatts_write(self->handle, BLE_CONN_HANDLE_INVALID, bufinfo);
bleio_gatts_write(self->handle, BLE_CONN_HANDLE_INVALID, bufinfo);
// Check to see if we need to notify or indicate any active connections.
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
bleio_connection_internal_t *connection = &bleio_connections[i];
Expand Down Expand Up @@ -255,7 +255,7 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
}

const uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
common_hal_bleio_check_connected(conn_handle);
bleio_check_connected(conn_handle);

uint16_t cccd_value =
(notify ? BLE_GATT_HVX_NOTIFICATION : 0) |
Expand Down
1 change: 1 addition & 0 deletions ports/nordic/common-hal/_bleio/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef struct {
void bleio_connection_clear(bleio_connection_internal_t *self);
bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in);

void bleio_check_connected(uint16_t conn_handle);
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);
8 changes: 4 additions & 4 deletions ports/nordic/common-hal/_bleio/Descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ size_t common_hal_bleio_descriptor_get_value(bleio_descriptor_obj_t *self, uint8
if (self->handle != BLE_GATT_HANDLE_INVALID) {
uint16_t conn_handle = bleio_connection_get_conn_handle(self->characteristic->service->connection);
if (common_hal_bleio_service_get_is_remote(self->characteristic->service)) {
return common_hal_bleio_gattc_read(self->handle, conn_handle, buf, len);
return bleio_gattc_read(self->handle, conn_handle, buf, len);
} else {
return common_hal_bleio_gatts_read(self->handle, conn_handle, buf, len);
return bleio_gatts_read(self->handle, conn_handle, buf, len);
}
}

Expand All @@ -58,7 +58,7 @@ void common_hal_bleio_descriptor_set_value(bleio_descriptor_obj_t *self, mp_buff
uint16_t conn_handle = bleio_connection_get_conn_handle(self->characteristic->service->connection);
if (common_hal_bleio_service_get_is_remote(self->characteristic->service)) {
// false means WRITE_REQ, not write-no-response
common_hal_bleio_gattc_write(self->handle, conn_handle, bufinfo, false);
bleio_gattc_write(self->handle, conn_handle, bufinfo, false);
} else {
// Validate data length for local descriptors only.
if (self->fixed_length && bufinfo->len != self->max_length) {
Expand All @@ -68,7 +68,7 @@ void common_hal_bleio_descriptor_set_value(bleio_descriptor_obj_t *self, mp_buff
mp_raise_ValueError(MP_ERROR_TEXT("Value length > max_length"));
}

common_hal_bleio_gatts_write(self->handle, conn_handle, bufinfo);
bleio_gatts_write(self->handle, conn_handle, bufinfo);
}
}

Expand Down
16 changes: 8 additions & 8 deletions ports/nordic/common-hal/_bleio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ void bleio_reset(void) {
// It currently only has properties and no state. Inited by bleio_reset
bleio_adapter_obj_t common_hal_bleio_adapter_obj;

void common_hal_bleio_check_connected(uint16_t conn_handle) {
void bleio_check_connected(uint16_t conn_handle) {
if (conn_handle == BLE_CONN_HANDLE_INVALID) {
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
}
}

// GATTS read of a Characteristic or Descriptor.
size_t common_hal_bleio_gatts_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len) {
size_t bleio_gatts_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len) {
// conn_handle is ignored unless this is a system attribute.
// If we're not connected, that's OK, because we can still read and write the local value.

Expand All @@ -133,7 +133,7 @@ size_t common_hal_bleio_gatts_read(uint16_t handle, uint16_t conn_handle, uint8_
return gatts_value.len;
}

void common_hal_bleio_gatts_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo) {
void bleio_gatts_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo) {
// conn_handle is ignored unless this is a system attribute.
// If we're not connected, that's OK, because we can still read and write the local value.

Expand Down Expand Up @@ -188,8 +188,8 @@ static bool _on_gattc_read_rsp_evt(ble_evt_t *ble_evt, void *param) {
return true;
}

size_t common_hal_bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len) {
common_hal_bleio_check_connected(conn_handle);
size_t bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_t *buf, size_t len) {
bleio_check_connected(conn_handle);

read_info_t read_info;
read_info.buf = buf;
Expand All @@ -213,15 +213,15 @@ size_t common_hal_bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_
RUN_BACKGROUND_TASKS;
}
// Test if we were disconnected while reading
common_hal_bleio_check_connected(read_info.conn_handle);
bleio_check_connected(read_info.conn_handle);

ble_drv_remove_event_handler(_on_gattc_read_rsp_evt, &read_info);
check_gatt_status(read_info.status);
return read_info.final_len;
}

void common_hal_bleio_gattc_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo, bool write_no_response) {
common_hal_bleio_check_connected(conn_handle);
void bleio_gattc_write(uint16_t handle, uint16_t conn_handle, mp_buffer_info_t *bufinfo, bool write_no_response) {
bleio_check_connected(conn_handle);

ble_gattc_write_params_t write_params = {
.write_op = write_no_response ? BLE_GATT_OP_WRITE_CMD: BLE_GATT_OP_WRITE_REQ,
Expand Down
2 changes: 1 addition & 1 deletion ports/silabs/common-hal/_bleio/Characteristic.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,

const uint16_t conn_handle = bleio_connection_get_conn_handle(
self->service->connection);
common_hal_bleio_check_connected(conn_handle);
bleio_check_connected(conn_handle);
notify = 1;
indicate = 0;
if (notify) {
Expand Down
1 change: 1 addition & 0 deletions ports/silabs/common-hal/_bleio/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef struct

void bleio_connection_clear(bleio_connection_internal_t *self);

void bleio_check_connected(uint16_t conn_handle);
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);

mp_obj_t bleio_connection_new_from_internal(
Expand Down
2 changes: 1 addition & 1 deletion ports/silabs/common-hal/_bleio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void check_ble_error(int error_code) {
}
}

void common_hal_bleio_check_connected(uint16_t conn_handle) {
void bleio_check_connected(uint16_t conn_handle) {
if (conn_handle == BLEIO_HANDLE_INVALID) {
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
}
Expand Down
13 changes: 13 additions & 0 deletions ports/zephyr-cp/boards/nrf5340bsim_nrf5340_cpuapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ CONFIG_GPIO=y
# Enable Bluetooth stack - bsim is for BT simulation
CONFIG_BT=y
CONFIG_BT_HCI=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y

CONFIG_BT_L2CAP_TX_MTU=253
CONFIG_BT_BUF_CMD_TX_COUNT=2
CONFIG_BT_BUF_CMD_TX_SIZE=255
CONFIG_BT_HCI_VS=y
CONFIG_BT_BUF_EVT_RX_COUNT=16
CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_COUNT=3
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA=1
CONFIG_BT_BUF_ACL_RX_SIZE=255

CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=28

Expand Down
Loading