|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2018 Dan Halbert for Adafruit Industries |
| 7 | + * Copyright (c) 2018 Artur Pacholec |
| 8 | + * Copyright (c) 2016 Glenn Ruben Bakke |
| 9 | + * |
| 10 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | + * of this software and associated documentation files (the "Software"), to deal |
| 12 | + * in the Software without restriction, including without limitation the rights |
| 13 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | + * copies of the Software, and to permit persons to whom the Software is |
| 15 | + * furnished to do so, subject to the following conditions: |
| 16 | + * |
| 17 | + * The above copyright notice and this permission notice shall be included in |
| 18 | + * all copies or substantial portions of the Software. |
| 19 | + * |
| 20 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 26 | + * THE SOFTWARE. |
| 27 | + */ |
| 28 | + |
| 29 | +#ifndef MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H |
| 30 | +#define MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H |
| 31 | + |
| 32 | +#include "py/obj.h" |
| 33 | +#include "py/objtuple.h" |
| 34 | + |
| 35 | +#include "shared-bindings/_bleio/Characteristic.h" |
| 36 | +#include "shared-bindings/_bleio/Connection.h" |
| 37 | +#include "shared-bindings/_bleio/ScanResults.h" |
| 38 | +#include "shared-bindings/busio/UART.h" |
| 39 | +#include "shared-bindings/digitalio/DigitalInOut.h" |
| 40 | + |
| 41 | +#ifndef BLEIO_TOTAL_CONNECTION_COUNT |
| 42 | +#define BLEIO_TOTAL_CONNECTION_COUNT 5 |
| 43 | +#endif |
| 44 | + |
| 45 | +extern bleio_connection_internal_t bleio_connections[BLEIO_TOTAL_CONNECTION_COUNT]; |
| 46 | + |
| 47 | +typedef struct _bleio_adapter_obj_t { |
| 48 | + mp_obj_base_t base; |
| 49 | + bleio_scanresults_obj_t *scan_results; |
| 50 | + mp_obj_t name; |
| 51 | + mp_obj_tuple_t *connection_objs; |
| 52 | + busio_uart_obj_t* hci_uart; |
| 53 | + digitalio_digitalinout_obj_t *rts_digitalinout; |
| 54 | + digitalio_digitalinout_obj_t *cts_digitalinout; |
| 55 | + bool allocated; // True when in use. |
| 56 | + bool now_advertising; |
| 57 | + bool extended_advertising; |
| 58 | + bool circuitpython_advertising; |
| 59 | + bool enabled; |
| 60 | + |
| 61 | + // HCI adapter version info. |
| 62 | + uint8_t hci_version; |
| 63 | + uint8_t lmp_version; |
| 64 | + uint16_t hci_revision; |
| 65 | + uint16_t manufacturer; |
| 66 | + uint16_t lmp_subversion; |
| 67 | + |
| 68 | + // Used to monitor advertising timeout for legacy avertising. |
| 69 | + uint64_t advertising_start_ticks; |
| 70 | + uint64_t advertising_timeout_msecs; // If zero, do not check. |
| 71 | + |
| 72 | + // Generic services characteristics. |
| 73 | + bleio_characteristic_obj_t *device_name_characteristic; |
| 74 | + bleio_characteristic_obj_t *appearance_characteristic; |
| 75 | + bleio_characteristic_obj_t * service_changed_characteristic; |
| 76 | + |
| 77 | + uint16_t max_acl_buffer_len; |
| 78 | + uint16_t max_acl_num_buffers; |
| 79 | + uint16_t max_adv_data_len; |
| 80 | + uint8_t features[8]; // Supported BLE features. |
| 81 | + |
| 82 | + // All the local attributes for this device. The index into the list |
| 83 | + // corresponds to the handle. |
| 84 | + mp_obj_list_t *attributes; |
| 85 | + // Handle for last added service. Characteristics can only be added immediately after |
| 86 | + // the service they belong to. This vets that. |
| 87 | + uint16_t last_added_service_handle; |
| 88 | + uint16_t last_added_characteristic_handle; |
| 89 | +} bleio_adapter_obj_t; |
| 90 | + |
| 91 | +uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute); |
| 92 | +void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self); |
| 93 | +mp_obj_t* bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle); |
| 94 | +uint16_t bleio_adapter_max_attribute_handle(bleio_adapter_obj_t *adapter); |
| 95 | +void bleio_adapter_background(bleio_adapter_obj_t* adapter); |
| 96 | +void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter); |
| 97 | +void bleio_adapter_reset(bleio_adapter_obj_t* adapter); |
| 98 | + |
| 99 | +#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H |
0 commit comments