Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable a BLE workflow #4918

Merged
merged 1 commit into from
Jun 24, 2021
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
run: |
echo "Uploading dev release to PyPi"
python setup.py sdist
twine upload dist/*
[ -z "$TWINE_USERNAME" ] || twine upload dist/*

mpy-cross-mac:
runs-on: macos-10.15
Expand Down
14 changes: 11 additions & 3 deletions devices/ble_hci/common-hal/_bleio/Adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,11 @@ STATIC void check_data_fit(size_t data_len, bool connectable) {
// return true;
// }

uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool connectable, bool anonymous, uint32_t timeout, float interval, uint8_t *advertising_data, uint16_t advertising_data_len, uint8_t *scan_response_data, uint16_t scan_response_data_len, mp_int_t tx_power) {
uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
bool connectable, bool anonymous, uint32_t timeout, float interval,
const uint8_t *advertising_data, uint16_t advertising_data_len,
const uint8_t *scan_response_data, uint16_t scan_response_data_len,
mp_int_t tx_power, const bleio_address_obj_t *directed_to) {
check_enabled(self);

if (self->now_advertising) {
Expand Down Expand Up @@ -769,7 +773,11 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
return 0;
}

void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool connectable, bool anonymous, uint32_t timeout, mp_float_t interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo, mp_int_t tx_power) {
void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
bool connectable, bool anonymous, uint32_t timeout, mp_float_t interval,
mp_buffer_info_t *advertising_data_bufinfo,
mp_buffer_info_t *scan_response_data_bufinfo,
mp_int_t tx_power, const bleio_address_obj_t *directed_to) {
check_enabled(self);

// interval value has already been validated.
Expand Down Expand Up @@ -803,7 +811,7 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
advertising_data_bufinfo->len,
scan_response_data_bufinfo->buf,
scan_response_data_bufinfo->len,
tx_power);
tx_power, directed_to);

if (result) {
mp_raise_bleio_BluetoothError(translate("Already advertising"));
Expand Down
3 changes: 2 additions & 1 deletion devices/ble_hci/common-hal/_bleio/PacketBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self
return ret;
}

mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, uint8_t *data, size_t len, uint8_t *header, size_t header_len) {
mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self,
const uint8_t *data, size_t len, uint8_t *header, size_t header_len) {
if (self->outgoing[0] == NULL) {
mp_raise_bleio_BluetoothError(translate("Writes not supported on Characteristic"));
}
Expand Down
13 changes: 8 additions & 5 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,6 @@ msgstr ""
msgid "Buffer must be at least length 1"
msgstr ""

#: ports/nrf/common-hal/_bleio/PacketBuffer.c
msgid "Buffer too large and unable to allocate"
msgstr ""

#: shared-bindings/_bleio/PacketBuffer.c
#, c-format
msgid "Buffer too short by %d bytes"
Expand Down Expand Up @@ -873,6 +869,10 @@ msgstr ""
msgid "Data chunk must follow fmt chunk"
msgstr ""

#: ports/nrf/common-hal/_bleio/Adapter.c
msgid "Data not supported with directed advertising"
msgstr ""

#: ports/nrf/common-hal/_bleio/Adapter.c
msgid "Data too large for advertisement packet"
msgstr ""
Expand Down Expand Up @@ -1667,7 +1667,6 @@ msgstr ""
msgid "Not a valid IP string"
msgstr ""

#: ports/nrf/common-hal/_bleio/PacketBuffer.c
#: ports/nrf/common-hal/_bleio/__init__.c
#: shared-bindings/_bleio/CharacteristicBuffer.c
msgid "Not connected"
Expand Down Expand Up @@ -1710,6 +1709,10 @@ msgid ""
"Only Windows format, uncompressed BMP supported: given header size is %d"
msgstr ""

#: shared-bindings/_bleio/Adapter.c
msgid "Only connectable advertisements can be directed"
msgstr ""

#: ports/stm/common-hal/alarm/pin/PinAlarm.c
msgid "Only edge detection is available on this hardware"
msgstr ""
Expand Down
5 changes: 5 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ int __attribute__((used)) main(void) {

stack_init();

#if CIRCUITPY_BLEIO
// Early init so that a reset press can cause BLE public advertising.
supervisor_bluetooth_init();
#endif

// Create a new filesystem only if we're not in a safe mode.
// A power brownout here could make it appear as if there's
// no SPI flash filesystem, and we might erase the existing one.
Expand Down
30 changes: 22 additions & 8 deletions ports/nrf/bluetooth/ble_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "py/mpstate.h"

#include "supervisor/shared/bluetooth.h"
#include "supervisor/bluetooth.h"

nrf_nvic_state_t nrf_nvic_state = { 0 };

Expand All @@ -56,6 +55,14 @@ void ble_drv_reset() {
}

void ble_drv_add_event_handler_entry(ble_drv_evt_handler_entry_t *entry, ble_drv_evt_handler_t func, void *param) {
ble_drv_evt_handler_entry_t *it = MP_STATE_VM(ble_drv_evt_handler_entries);
while (it != NULL) {
// If event handler and its corresponding param are already on the list, don't add again.
if ((it->func == func) && (it->param == param)) {
return;
}
it = it->next;
}
entry->next = MP_STATE_VM(ble_drv_evt_handler_entries);
entry->param = param;
entry->func = func;
Expand Down Expand Up @@ -85,6 +92,8 @@ void ble_drv_remove_event_handler(ble_drv_evt_handler_t func, void *param) {
if ((it->func == func) && (it->param == param)) {
// Splice out the matching handler.
*prev = it->next;
// Clear next of the removed node so it's clearly not in a list.
it->next = NULL;
return;
}
prev = &(it->next);
Expand Down Expand Up @@ -138,21 +147,26 @@ void SD_EVT_IRQHandler(void) {

ble_evt_t *event = (ble_evt_t *)m_ble_evt_buf;
#if CIRCUITPY_VERBOSE_BLE
mp_printf(&mp_plat_print, "BLE event: 0x%04x\n", event->header.evt_id);
#endif

if (supervisor_bluetooth_hook(event)) {
continue;
size_t eid = event->header.evt_id;
if (eid != 0x1d) {
if (BLE_GAP_EVT_BASE <= eid && eid <= BLE_GAP_EVT_LAST) {
mp_printf(&mp_plat_print, "BLE GAP event: %d\n", eid - BLE_GAP_EVT_BASE);
} else {
mp_printf(&mp_plat_print, "BLE event: 0x%04x\n", event->header.evt_id);
}
}
#endif

ble_drv_evt_handler_entry_t *it = MP_STATE_VM(ble_drv_evt_handler_entries);
bool done = false;
while (it != NULL) {
#if CIRCUITPY_VERBOSE_BLE
// mp_printf(&mp_plat_print, " calling handler: 0x%08lx, param: 0x%08lx\n", it->func-1, it->param);
// mp_printf(&mp_plat_print, " calling handler: 0x%08lx, param: 0x%08lx\n", it->func - 1, it->param);
#endif
// Capture next before calling the function in case it removes itself from the list.
ble_drv_evt_handler_entry_t *next = it->next;
done = it->func(event, it->param) || done;
it = it->next;
it = next;
}
#if CIRCUITPY_VERBOSE_BLE
if (event->header.evt_id == BLE_GATTS_EVT_WRITE) {
Expand Down
Loading