summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--extmod/btstack/btstack.mk48
-rw-r--r--extmod/btstack/btstack_config.h44
-rw-r--r--extmod/btstack/modbluetooth_btstack.c128
-rw-r--r--extmod/btstack/modbluetooth_btstack.h30
4 files changed, 250 insertions, 0 deletions
diff --git a/extmod/btstack/btstack.mk b/extmod/btstack/btstack.mk
new file mode 100644
index 0000000000..0a6876b227
--- /dev/null
+++ b/extmod/btstack/btstack.mk
@@ -0,0 +1,48 @@
+# Makefile directives for BlueKitchen BTstack
+
+ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
+
+BTSTACK_EXTMOD_DIR = extmod/btstack
+
+EXTMOD_SRC_C += extmod/btstack/modbluetooth_btstack.c
+
+INC += -I$(TOP)/$(BTSTACK_EXTMOD_DIR)
+
+CFLAGS_MOD += -DMICROPY_BLUETOOTH_BTSTACK=1
+
+BTSTACK_DIR = $(TOP)/lib/btstack
+
+include $(BTSTACK_DIR)/src/Makefile.inc
+include $(BTSTACK_DIR)/src/ble/Makefile.inc
+
+INC += -I$(BTSTACK_DIR)/src
+INC += -I$(BTSTACK_DIR)/3rd-party/bluedroid/decoder/include
+INC += -I$(BTSTACK_DIR)/3rd-party/bluedroid/encoder/include
+INC += -I$(BTSTACK_DIR)/3rd-party/md5
+INC += -I$(BTSTACK_DIR)/3rd-party/yxml
+
+SRC_BTSTACK = \
+ $(addprefix lib/btstack/src/, $(SRC_FILES)) \
+ $(addprefix lib/btstack/src/ble/, $(filter-out %_tlv.c, $(SRC_BLE_FILES))) \
+ lib/btstack/platform/embedded/btstack_run_loop_embedded.c \
+
+ifeq ($MICROPY_BLUETOOTH_BTSTACK_ENABLE_CLASSIC,1)
+include $(BTSTACK_DIR)/src/classic/Makefile.inc
+SRC_BTSTACK += \
+ $(addprefix lib/btstack/src/classic/, $(SRC_CLASSIC_FILES))
+endif
+
+SRC_LIB += $(SRC_BTSTACK)
+
+#$(BUILD)/lib/btstack/src/classic/btstack_link_key_db_static.o: CFLAGS += -Wno-error=pointer-arith
+
+# Incorrect %u, should be %lu.
+$(BUILD)/lib/btstack/src/classic/a2dp_source.o: CFLAGS += -Wno-error=format=
+$(BUILD)/lib/btstack/src/classic/btstack_sbc_decoder_bluedroid.o: CFLAGS += -Wno-error=format=
+$(BUILD)/lib/btstack/src/classic/btstack_link_key_db_tlv.o: CFLAGS += -Wno-error=format=
+$(BUILD)/lib/btstack/src/classic/goep_client.o: CFLAGS += -Wno-error=format=
+$(BUILD)/lib/btstack/src/ble/le_device_db_tlv.o: CFLAGS += -Wno-error=format=
+
+
+
+endif
diff --git a/extmod/btstack/btstack_config.h b/extmod/btstack/btstack_config.h
new file mode 100644
index 0000000000..0976bbe728
--- /dev/null
+++ b/extmod/btstack/btstack_config.h
@@ -0,0 +1,44 @@
+#ifndef MICROPY_INCLUDED_EXTMOD_BTSTACK_BTSTACK_CONFIG_H
+#define MICROPY_INCLUDED_EXTMOD_BTSTACK_BTSTACK_CONFIG_H
+
+// BTstack features that can be enabled
+#define ENABLE_BLE
+#define ENABLE_LE_PERIPHERAL
+#define ENABLE_LE_CENTRAL
+// #define ENABLE_CLASSIC
+#define ENABLE_LE_DATA_CHANNELS
+// #define ENABLE_LOG_INFO
+#define ENABLE_LOG_ERROR
+
+// BTstack configuration. buffers, sizes, ...
+#define HCI_ACL_PAYLOAD_SIZE 1021
+#define MAX_NR_GATT_CLIENTS 1
+#define MAX_NR_HCI_CONNECTIONS 1
+#define MAX_NR_L2CAP_SERVICES 3
+#define MAX_NR_L2CAP_CHANNELS 3
+#define MAX_NR_RFCOMM_MULTIPLEXERS 1
+#define MAX_NR_RFCOMM_SERVICES 1
+#define MAX_NR_RFCOMM_CHANNELS 1
+#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 2
+#define MAX_NR_BNEP_SERVICES 1
+#define MAX_NR_BNEP_CHANNELS 1
+#define MAX_NR_HFP_CONNECTIONS 1
+#define MAX_NR_WHITELIST_ENTRIES 1
+#define MAX_NR_SM_LOOKUP_ENTRIES 3
+#define MAX_NR_SERVICE_RECORD_ITEMS 1
+#define MAX_NR_AVDTP_STREAM_ENDPOINTS 1
+#define MAX_NR_AVDTP_CONNECTIONS 1
+#define MAX_NR_AVRCP_CONNECTIONS 1
+
+#define MAX_NR_LE_DEVICE_DB_ENTRIES 4
+
+// Link Key DB and LE Device DB using TLV on top of Flash Sector interface
+// #define NVM_NUM_DEVICE_DB_ENTRIES 16
+
+// We don't give btstack a malloc, so use a fixed-size ATT DB.
+#define MAX_ATT_DB_SIZE 512
+
+// BTstack HAL configuration
+#define HAVE_EMBEDDED_TIME_MS
+
+#endif // MICROPY_INCLUDED_EXTMOD_BTSTACK_BTSTACK_CONFIG_H
diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c
new file mode 100644
index 0000000000..73f28ffad3
--- /dev/null
+++ b/extmod/btstack/modbluetooth_btstack.c
@@ -0,0 +1,128 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Damien P. George
+ *
+ * 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.
+ */
+
+#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK
+
+#include "extmod/btstack/modbluetooth_btstack.h"
+#include "extmod/modbluetooth.h"
+
+int mp_bluetooth_init(void) {
+ return 0;
+}
+
+void mp_bluetooth_deinit(void) {
+}
+
+bool mp_bluetooth_is_enabled(void) {
+ return false;
+}
+
+void mp_bluetooth_get_device_addr(uint8_t *addr) {
+ mp_hal_get_mac(MP_HAL_MAC_BDADDR, addr);
+}
+
+int mp_bluetooth_gap_advertise_start(bool connectable, int32_t interval_us, const uint8_t *adv_data, size_t adv_data_len, const uint8_t *sr_data, size_t sr_data_len) {
+ return 0;
+}
+
+void mp_bluetooth_gap_advertise_stop(void) {
+}
+
+int mp_bluetooth_gatts_register_service_begin(bool append) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_register_service(mp_obj_bluetooth_uuid_t *service_uuid, mp_obj_bluetooth_uuid_t **characteristic_uuids, uint8_t *characteristic_flags, mp_obj_bluetooth_uuid_t **descriptor_uuids, uint8_t *descriptor_flags, uint8_t *num_descriptors, uint16_t *handles, size_t num_characteristics) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_register_service_end(void) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_read(uint16_t value_handle, uint8_t **value, size_t *value_len) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_write(uint16_t value_handle, const uint8_t *value, size_t value_len) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_notify(uint16_t conn_handle, uint16_t value_handle) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_notify_send(uint16_t conn_handle, uint16_t value_handle, const uint8_t *value, size_t *value_len) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_indicate(uint16_t conn_handle, uint16_t value_handle) {
+ return 0;
+}
+
+int mp_bluetooth_gatts_set_buffer(uint16_t value_handle, size_t len, bool append) {
+ return 0;
+}
+
+int mp_bluetooth_gap_disconnect(uint16_t conn_handle) {
+ return 0;
+}
+
+#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
+int mp_bluetooth_gap_scan_start(int32_t duration_ms, int32_t interval_us, int32_t window_us) {
+ return 0;
+}
+
+int mp_bluetooth_gap_scan_stop(void) {
+ return 0;
+}
+
+int mp_bluetooth_gap_peripheral_connect(uint8_t addr_type, const uint8_t *addr, int32_t duration_ms) {
+ return 0;
+}
+
+int mp_bluetooth_gattc_discover_primary_services(uint16_t conn_handle) {
+ return 0;
+}
+
+int mp_bluetooth_gattc_discover_characteristics(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle) {
+ return 0;
+}
+
+int mp_bluetooth_gattc_discover_descriptors(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle) {
+ return 0;
+}
+
+int mp_bluetooth_gattc_read(uint16_t conn_handle, uint16_t value_handle) {
+ return 0;
+}
+
+int mp_bluetooth_gattc_write(uint16_t conn_handle, uint16_t value_handle, const uint8_t *value, size_t *value_len, unsigned int mode) {
+ return 0;
+}
+#endif
+
+#endif // MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK
diff --git a/extmod/btstack/modbluetooth_btstack.h b/extmod/btstack/modbluetooth_btstack.h
new file mode 100644
index 0000000000..f58d307480
--- /dev/null
+++ b/extmod/btstack/modbluetooth_btstack.h
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Damien P. George
+ *
+ * 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_EXTMOD_BTSTACK_MODBLUETOOTH_BTSTACK_H
+#define MICROPY_INCLUDED_EXTMOD_BTSTACK_MODBLUETOOTH_BTSTACK_H
+
+#endif // MICROPY_INCLUDED_EXTMOD_BTSTACK_MODBLUETOOTH_BTSTACK_H