summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-11-07 12:03:46 -0800
committerGitHub <noreply@github.com>2018-11-07 12:03:46 -0800
commitd08747d374057b24803b429bbf6474a2e4dcea5c (patch)
treec3bfee81668dbd842039c178222fda9df77a9b76 /shared-module
parent283e07254e9eb50e52d6f07b7ac177feeef02d83 (diff)
parent64d457dad9bb3843ee468136022996ecb91a98df (diff)
Merge pull request #1319 from dhalbert/origin/arturo182_bleio_pr_1289
Resubmit PR #1289, "WIP: bleio rewrite" by @arturo182
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/bleio/Address.h40
-rw-r--r--shared-module/bleio/AdvertisementData.h85
-rw-r--r--shared-module/bleio/Characteristic.h52
-rw-r--r--shared-module/bleio/Device.h45
-rw-r--r--shared-module/bleio/ScanEntry.h40
-rw-r--r--shared-module/bleio/Scanner.h39
-rw-r--r--shared-module/bleio/Service.h44
7 files changed, 345 insertions, 0 deletions
diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h
new file mode 100644
index 000000000..f0998c163
--- /dev/null
+++ b/shared-module/bleio/Address.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Artur Pacholec
+ *
+ * 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_SHARED_MODULE_BLEIO_ADDRESS_H
+#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H
+
+#include "shared-bindings/bleio/AddressType.h"
+
+#define BLEIO_ADDRESS_BYTES 6
+
+typedef struct {
+ mp_obj_base_t base;
+ bleio_address_type_t type;
+ uint8_t value[BLEIO_ADDRESS_BYTES];
+} bleio_address_obj_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H
diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h
new file mode 100644
index 000000000..738d53b23
--- /dev/null
+++ b/shared-module/bleio/AdvertisementData.h
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Artur Pacholec
+ *
+ * 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_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H
+#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H
+
+#include "py/obj.h"
+
+// Taken from https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
+enum {
+ AdFlags = 0x01,
+ AdIncompleteListOf16BitServiceClassUUIDs = 0x02,
+ AdCompleteListOf16BitServiceClassUUIDs = 0x03,
+ AdIncompleteListOf32BitServiceClassUUIDs = 0x04,
+ AdCompleteListOf32BitServiceClassUUIDs = 0x05,
+ AdIncompleteListOf128BitServiceClassUUIDs = 0x06,
+ AdCompleteListOf128BitServiceClassUUIDs = 0x07,
+ AdShortenedLocalName = 0x08,
+ AdCompleteLocalName = 0x09,
+ AdTxPowerLevel = 0x0A,
+ AdClassOfDevice = 0x0D,
+ AdSimplePairingHashC = 0x0E,
+ AdSimplePairingRandomizerR = 0x0F,
+ AdSecurityManagerTKValue = 0x10,
+ AdSecurityManagerOOBFlags = 0x11,
+ AdSlaveConnectionIntervalRange = 0x12,
+ AdListOf16BitServiceSolicitationUUIDs = 0x14,
+ AdListOf128BitServiceSolicitationUUIDs = 0x15,
+ AdServiceData = 0x16,
+ AdPublicTargetAddress = 0x17,
+ AdRandomTargetAddress = 0x18,
+ AdAppearance = 0x19,
+ AdAdvertisingInterval = 0x1A,
+ AdLEBluetoothDeviceAddress = 0x1B,
+ AdLERole = 0x1C,
+ AdSimplePairingHashC256 = 0x1D,
+ AdSimplePairingRandomizerR256 = 0x1E,
+ AdListOf32BitServiceSolicitationUUIDs = 0x1F,
+ AdServiceData32BitUUID = 0x20,
+ AdServiceData128BitUUID = 0x21,
+ AdLESecureConnectionsConfirmationValue = 0x22,
+ AdLESecureConnectionsRandomValue = 0x23,
+ AdURI = 0x24,
+ AdIndoorPositioning = 0x25,
+ AdTransportDiscoveryData = 0x26,
+ AdLESupportedFeatures = 0x27,
+ AdChannelMapUpdateIndication = 0x28,
+ AdPBADV = 0x29,
+ AdMeshMessage = 0x2A,
+ AdMeshBeacon = 0x2B,
+ Ad3DInformationData = 0x3D,
+ AdManufacturerSpecificData = 0xFF,
+};
+
+typedef struct {
+ mp_obj_t device_name;
+ mp_obj_t services;
+ mp_obj_t data;
+ bool connectable;
+} bleio_advertisement_data_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H
diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h
new file mode 100644
index 000000000..94c43f81e
--- /dev/null
+++ b/shared-module/bleio/Characteristic.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Artur Pacholec
+ *
+ * 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_SHARED_MODULE_BLEIO_CHARACTERISTIC_H
+#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H
+
+#include "shared-module/bleio/Service.h"
+#include "common-hal/bleio/UUID.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ bleio_service_obj_t *service;
+ bleio_uuid_obj_t *uuid;
+ mp_obj_t value_data;
+ uint16_t handle;
+ struct {
+ bool broadcast : 1;
+ bool read : 1;
+ bool write_wo_resp : 1;
+ bool write : 1;
+ bool notify : 1;
+ bool indicate : 1;
+ } props;
+ uint16_t user_desc_handle;
+ uint16_t cccd_handle;
+ uint16_t sccd_handle;
+} bleio_characteristic_obj_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H
diff --git a/shared-module/bleio/Device.h b/shared-module/bleio/Device.h
new file mode 100644
index 000000000..8d9ece5ef
--- /dev/null
+++ b/shared-module/bleio/Device.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Artur Pacholec
+ *
+ * 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_SHARED_MODULE_BLEIO_DEVICE_H
+#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H
+
+#include <stdbool.h>
+
+#include "shared-module/bleio/Address.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ bool is_peripheral;
+ mp_obj_t name;
+ bleio_address_obj_t address;
+ volatile uint16_t conn_handle;
+ mp_obj_t service_list;
+ mp_obj_t notif_handler;
+ mp_obj_t conn_handler;
+} bleio_device_obj_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H
diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h
new file mode 100644
index 000000000..2f01669e2
--- /dev/null
+++ b/shared-module/bleio/ScanEntry.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Artur Pacholec
+ *
+ * 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_SHARED_MODULE_BLEIO_SCANENTRY_H
+#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H
+
+#include "shared-module/bleio/Address.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ bleio_address_obj_t address;
+ bool connectable;
+ int8_t rssi;
+ mp_obj_t data;
+} bleio_scanentry_obj_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H
diff --git a/shared-module/bleio/Scanner.h b/shared-module/bleio/Scanner.h
new file mode 100644
index 000000000..76f5e5866
--- /dev/null
+++ b/shared-module/bleio/Scanner.h
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Artur Pacholec
+ *
+ * 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_SHARED_MODULE_BLEIO_SCANNER_H
+#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ mp_obj_t adv_reports;
+ uint16_t interval;
+ uint16_t window;
+} bleio_scanner_obj_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
diff --git a/shared-module/bleio/Service.h b/shared-module/bleio/Service.h
new file mode 100644
index 000000000..ff506d3f3
--- /dev/null
+++ b/shared-module/bleio/Service.h
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Artur Pacholec
+ *
+ * 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_SHARED_MODULE_BLEIO_SERVICE_H
+#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H
+
+#include "common-hal/bleio/UUID.h"
+#include "shared-module/bleio/Device.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ uint16_t handle;
+ bool is_secondary;
+ bleio_uuid_obj_t *uuid;
+ bleio_device_obj_t *device;
+ mp_obj_t char_list;
+ uint16_t start_handle;
+ uint16_t end_handle;
+} bleio_service_obj_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H