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

_bleio HCI implementation #3310

Merged
merged 43 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
759929c
hci early wip; refactor supervisor bluetooth.c for nrf: tested
dhalbert Jun 26, 2020
3e616cc
update submodules
dhalbert Jun 26, 2020
57bac9a
update submodules
dhalbert Jun 26, 2020
1bc2e97
wip; compiles; much commented out
dhalbert Jun 26, 2020
f879114
do HCI pin init in Python, not here
dhalbert Jun 26, 2020
11cb3e3
hci skeleton done; not working yet
dhalbert Jul 1, 2020
a5ab282
use zephyr include files; wip: compiles
dhalbert Jul 8, 2020
f03045b
address working; improved pkt dump
dhalbert Jul 9, 2020
f6869c6
wip: advertising; not tested
dhalbert Jul 12, 2020
b08b026
back to working; check for extended advertising support
dhalbert Jul 15, 2020
6494bbd
snapshot
dhalbert Jul 17, 2020
90ae1ef
revamp ACLDATA reassembly
dhalbert Jul 18, 2020
f6f45c8
wip: ATT protocol
dhalbert Jul 23, 2020
9572f30
ATT WIP
dhalbert Jul 28, 2020
0619966
wip
dhalbert Jul 28, 2020
e6bd99a
wip
dhalbert Jul 28, 2020
a76ad34
wip: implementing functionality
dhalbert Jul 31, 2020
0a60aee
wip: compiles
dhalbert Aug 2, 2020
a995a5c
wip: partial discovery responses; compiles; not tested
dhalbert Aug 4, 2020
ac95106
service discovery works; need to work on char and descriptor discovery
dhalbert Aug 4, 2020
0f4b969
discovery of Nordic UART service working
dhalbert Aug 8, 2020
74034d6
characteristic/cccd r/w; not tested
dhalbert Aug 10, 2020
92cf560
blue_uart_echo_test from Bluefruit app is working
dhalbert Aug 11, 2020
06f3b40
fix #3228 for nrf; still needs to be fixed for HCI; tested
dhalbert Aug 11, 2020
44c9c43
ble_uart_echo_test works
dhalbert Aug 13, 2020
d0ffdda
fix reset logic to not do pin ops or heap ops at bad times
dhalbert Aug 13, 2020
1c8e11b
bug in char get_value; raise NotImpl; better arg validation
dhalbert Aug 15, 2020
da48ab0
add generic services
dhalbert Aug 17, 2020
dfe50d0
Fix a few bugs
dhalbert Aug 18, 2020
0e30dd8
merge from upstream; working; includes debug_out code for debugging v…
dhalbert Aug 21, 2020
490380a
remove debugging uart code
dhalbert Aug 21, 2020
097f93a
improve HCI packet error handling
dhalbert Aug 21, 2020
f714f53
Merge remote-tracking branch 'adafruit/main' into ble_hci
dhalbert Aug 21, 2020
c21c39b
merge from upstream; update ulab
dhalbert Aug 21, 2020
58573a7
bring submodules up to date
dhalbert Aug 21, 2020
8d785cb
fix stubs; make translate
dhalbert Aug 21, 2020
6553628
rename hci_include/README.dm to avoid triggering sphinx warning
dhalbert Aug 21, 2020
770c204
sphinx fixes
dhalbert Aug 21, 2020
b27d511
address review; use constructor for HCI Adapter
dhalbert Aug 30, 2020
767f3d0
make translate
dhalbert Aug 30, 2020
6dbd369
merge from upstream
dhalbert Aug 30, 2020
f5a5fc4
Fix stub; mismatched triple quotes
dhalbert Aug 30, 2020
4e3cb55
share more of _bleio dict; fix one doc error
dhalbert Sep 1, 2020
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
958 changes: 958 additions & 0 deletions devices/ble_hci/common-hal/_bleio/Adapter.c

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions devices/ble_hci/common-hal/_bleio/Adapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Dan Halbert for Adafruit Industries
* Copyright (c) 2018 Artur Pacholec
* Copyright (c) 2016 Glenn Ruben Bakke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H
#define MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H

#include "py/obj.h"
#include "py/objtuple.h"

#include "shared-bindings/_bleio/Characteristic.h"
#include "shared-bindings/_bleio/Connection.h"
#include "shared-bindings/_bleio/ScanResults.h"
#include "shared-bindings/busio/UART.h"
#include "shared-bindings/digitalio/DigitalInOut.h"

#ifndef BLEIO_TOTAL_CONNECTION_COUNT
#define BLEIO_TOTAL_CONNECTION_COUNT 5
#endif

extern bleio_connection_internal_t bleio_connections[BLEIO_TOTAL_CONNECTION_COUNT];

typedef struct _bleio_adapter_obj_t {
mp_obj_base_t base;
bleio_scanresults_obj_t *scan_results;
mp_obj_t name;
mp_obj_tuple_t *connection_objs;
busio_uart_obj_t* hci_uart;
digitalio_digitalinout_obj_t *rts_digitalinout;
digitalio_digitalinout_obj_t *cts_digitalinout;
bool allocated; // True when in use.
bool now_advertising;
bool extended_advertising;
bool circuitpython_advertising;
bool enabled;

// HCI adapter version info.
uint8_t hci_version;
uint8_t lmp_version;
uint16_t hci_revision;
uint16_t manufacturer;
uint16_t lmp_subversion;

// Used to monitor advertising timeout for legacy avertising.
uint64_t advertising_start_ticks;
uint64_t advertising_timeout_msecs; // If zero, do not check.

// Generic services characteristics.
bleio_characteristic_obj_t *device_name_characteristic;
bleio_characteristic_obj_t *appearance_characteristic;
bleio_characteristic_obj_t * service_changed_characteristic;

uint16_t max_acl_buffer_len;
uint16_t max_acl_num_buffers;
uint16_t max_adv_data_len;
uint8_t features[8]; // Supported BLE features.

// All the local attributes for this device. The index into the list
// corresponds to the handle.
mp_obj_list_t *attributes;
// Handle for last added service. Characteristics can only be added immediately after
// the service they belong to. This vets that.
uint16_t last_added_service_handle;
uint16_t last_added_characteristic_handle;
} bleio_adapter_obj_t;

uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute);
void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self);
mp_obj_t* bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle);
uint16_t bleio_adapter_max_attribute_handle(bleio_adapter_obj_t *adapter);
void bleio_adapter_background(bleio_adapter_obj_t* adapter);
void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter);
void bleio_adapter_reset(bleio_adapter_obj_t* adapter);

#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H
49 changes: 49 additions & 0 deletions devices/ble_hci/common-hal/_bleio/Attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "py/runtime.h"

#include "shared-bindings/_bleio/Attribute.h"
#include "shared-bindings/_bleio/Characteristic.h"
#include "shared-bindings/_bleio/Descriptor.h"
#include "shared-bindings/_bleio/Service.h"


bleio_uuid_obj_t *bleio_attribute_get_uuid(mp_obj_t *attribute) {
if (MP_OBJ_IS_TYPE(attribute, &bleio_characteristic_type)) {
bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(attribute);
return characteristic->uuid;
}
if (MP_OBJ_IS_TYPE(attribute, &bleio_descriptor_type)) {
bleio_descriptor_obj_t *descriptor = MP_OBJ_TO_PTR(attribute);
return descriptor->uuid;
}
if (MP_OBJ_IS_TYPE(attribute, &bleio_service_type)) {
bleio_service_obj_t *service = MP_OBJ_TO_PTR(attribute);
return service->uuid;
}
mp_raise_RuntimeError(translate("Invalid BLE attribute"));
}
35 changes: 35 additions & 0 deletions devices/ble_hci/common-hal/_bleio/Attribute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ATTRIBUTE_H
#define MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ATTRIBUTE_H

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

bleio_uuid_obj_t *bleio_attribute_get_uuid(mp_obj_t *attribute);

#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ATTRIBUTE_H
Loading