Merge pull request #9222 from tannewt/esp_ble_server

Add ESP BLE GATT server support
This commit is contained in:
Dan Halbert 2024-05-17 17:24:45 -04:00 committed by GitHub
commit 6c4bfd6738
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
105 changed files with 1183 additions and 210 deletions

View file

@ -37,6 +37,9 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_ob
}
}
void common_hal_bleio_service_deinit(bleio_service_obj_t *self) {
}
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection) {
self->handle = 0xFFFF;
self->uuid = NULL;

@ -1 +1 @@
Subproject commit 5393f8ddbc2036ee587536d0f9329fbfbdf399d0
Subproject commit ccc7a36043e055ded1f478a979a303e694123187

View file

@ -6,7 +6,10 @@
include ../../py/circuitpy_mkenv.mk
ifeq ($(IDF_TARGET),esp32c3)
ifeq ($(IDF_TARGET),esp32c2)
IDF_TARGET_ARCH = riscv
CROSS_COMPILE = riscv32-esp-elf-
else ifeq ($(IDF_TARGET),esp32c3)
IDF_TARGET_ARCH = riscv
CROSS_COMPILE = riscv32-esp-elf-
else ifeq ($(IDF_TARGET),esp32c6)
@ -50,7 +53,9 @@ INC += \
-isystem esp-idf/components/bt/host/nimble/esp-hci/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/controller/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/ans/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/gap/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/gatt/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/util/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/transport/include \
@ -205,6 +210,12 @@ LDFLAGS += \
-T$(IDF_TARGET).rom.newlib-data.ld \
-T$(IDF_TARGET).rom.newlib-funcs.ld \
-T$(IDF_TARGET).rom.spiflash.ld
else ifeq ($(IDF_TARGET),esp32c2)
LDFLAGS += \
-Tesp32c2.rom.heap.ld \
-Tesp32c2.rom.newlib.ld \
-Tesp32c2.rom.version.ld
CFLAGS += -DSOC_XTAL_FREQ_MHZ=CONFIG_XTAL_FREQ
else ifeq ($(IDF_TARGET),esp32c3)
LDFLAGS += \
-Tesp32c3.rom.newlib.ld \
@ -246,6 +257,8 @@ endif
# Always add these because we might be doing host.
ifeq ($(IDF_TARGET),esp32)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32
else ifeq ($(IDF_TARGET),esp32c2)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C2
else ifeq ($(IDF_TARGET),esp32c3)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C3
else ifeq ($(IDF_TARGET),esp32c6)
@ -390,10 +403,14 @@ else
UF2_BOOTLOADER ?= $(CIRCUITPY_USB_DEVICE)
ifeq ($(UF2_BOOTLOADER), 1)
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE).defaults
else
ifeq ($(CIRCUITPY_ESP_FLASH_SIZE), 4MB)
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE)-no-ota-no-uf2.defaults
else
FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE)-no-uf2.defaults
endif
endif
endif
FLASH_MODE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_MODE).defaults
FLASH_SPEED_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_FREQ).defaults
@ -451,11 +468,15 @@ update-all-sdkconfigs: $(BUILD)/esp-idf/config/sdkconfig.h
update-board-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h
python tools/update_sdkconfig.py --board=$(BOARD) --debug=$(DEBUG)
BINARY_WIFI_BLOBS = libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libwapi.a
BINARY_WIFI_BLOBS = libcore.a libespnow.a libnet80211.a libpp.a libsmartconfig.a
BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a
ifneq ($(CIRCUITPY_WIFI),0)
BINARY_BLOBS += esp-idf/components/esp_coex/lib/$(IDF_TARGET)/libcoexist.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS))
ifneq ($(IDF_TARGET),esp32c2)
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, libmesh.a libwapi.a)
endif
endif
ifeq ($(IDF_TARGET),esp32)
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
endif
@ -475,6 +496,9 @@ ifneq ($(CIRCUITPY_BLEIO),0)
ESP_IDF_COMPONENTS_LINK += bt
ifeq ($(BLE_IMPL),esp32)
# BLE will hang the ESP32 and trigger an interrupt watchdog without this undefined symbol at
# link because a weak version of the interrupt that BLE uses will be linked incorrectly.
LDFLAGS += -u ld_include_hli_vectors_bt
BINARY_BLOBS += esp-idf/components/bt/controller/lib_esp32/$(IDF_TARGET)/libbtdm_app.a
endif
@ -526,6 +550,8 @@ ifeq ($(IDF_TARGET),esp32)
BOOTLOADER_OFFSET = 0x1000
else ifeq ($(IDF_TARGET),esp32h2)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32c2)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32c3)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32c6)

View file

@ -11,6 +11,7 @@ Support Status:
ESP32, "beta"
ESP32-H2, "alpha"
ESP32-C2, "alpha"
ESP32-C3, "beta"
ESP32-C6, "alpha"
ESP32-S2, "stable"

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -7,4 +7,5 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,6 +7,11 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1
# Not enough pins.

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

View file

@ -8,4 +8,9 @@ CIRCUITPY_ESP_FLASH_MODE=qio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -6,6 +6,8 @@ IDF_TARGET = esp32
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 8MB
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0
# Include these Python libraries in firmware

View file

@ -10,3 +10,8 @@ CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -10,3 +10,8 @@ CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -14,6 +14,11 @@ CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = opi
CIRCUITPY_ESP_PSRAM_FREQ = 80m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_CODEOP = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -9,4 +9,10 @@ IDF_TARGET = esp32s2
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -13,3 +13,8 @@ CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_PSRAM_SIZE = 2MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -7,3 +7,8 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESPCAMERA = 0
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -13,6 +13,11 @@ CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 40m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_CANIO = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PIXELBUF = 0

View file

@ -11,4 +11,9 @@ CIRCUITPY_ESP_PSRAM_SIZE = 4MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 40m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

View file

@ -6,3 +6,9 @@ IDF_TARGET = esp32c6
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_AUDIOMP3 = 0

View file

@ -0,0 +1,29 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Scott Shawcroft 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 "supervisor/board.h"
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

View file

@ -0,0 +1,41 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft 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.
*/
// Micropython setup
#define MICROPY_HW_BOARD_NAME "ESP8684-DevKitC-02-N4"
#define MICROPY_HW_MCU_NAME "ESP32C2"
#define CIRCUITPY_RGB_STATUS_INVERTED_PWM
#define CIRCUITPY_RGB_STATUS_R (&pin_GPIO0)
#define CIRCUITPY_RGB_STATUS_G (&pin_GPIO1)
#define CIRCUITPY_RGB_STATUS_B (&pin_GPIO8)
#define DEFAULT_UART_BUS_RX (&pin_GPIO19)
#define DEFAULT_UART_BUS_TX (&pin_GPIO20)
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX

View file

@ -0,0 +1,8 @@
CIRCUITPY_CREATOR_ID = 0x000C303A
CIRCUITPY_CREATION_ID = 0x00C20000
IDF_TARGET = esp32c2
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 60m
CIRCUITPY_ESP_FLASH_SIZE = 4MB

View file

@ -0,0 +1,30 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View file

@ -0,0 +1,40 @@
#
# Espressif IoT Development Framework Configuration
#
#
# Serial flasher config
#
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
# end of Serial flasher config
#
# Component config
#
#
# Hardware Settings
#
#
# Main XTAL Config
#
CONFIG_XTAL_FREQ_26=y
# CONFIG_XTAL_FREQ_40 is not set
CONFIG_XTAL_FREQ=26
# end of Main XTAL Config
# end of Hardware Settings
#
# ESP System Settings
#
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
# end of ESP System Settings
#
# LWIP
#
CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp8684"
# end of LWIP
# end of Component config
# end of Espressif IoT Development Framework Configuration

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE=qio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -7,6 +7,11 @@ CIRCUITPY_ESP_FLASH_MODE=qio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1
# Include these Python libraries in firmware.

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE=dio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE=dio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESPCAMERA = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE=qio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

View file

@ -8,4 +8,9 @@ CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESPCAMERA = 0
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
SRC_C += pmic/axp192/axp192.c

View file

@ -8,4 +8,9 @@ CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESPCAMERA = 0
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
SRC_C += pmic/axp192/axp192.c

View file

@ -10,3 +10,8 @@ CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = opi
CIRCUITPY_ESP_PSRAM_FREQ = 80m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE=dio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -8,4 +8,9 @@ CIRCUITPY_ESP_FLASH_MODE=dio
CIRCUITPY_ESP_FLASH_FREQ=40m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
IDF_TARGET = esp32

View file

@ -7,4 +7,9 @@ CIRCUITPY_ESP_FLASH_MODE=qio
CIRCUITPY_ESP_FLASH_FREQ=80m
CIRCUITPY_ESP_FLASH_SIZE=4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

View file

@ -8,3 +8,8 @@ CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESPCAMERA = 0
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -10,3 +10,8 @@ CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -10,3 +10,8 @@ CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 80m
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -6,3 +6,9 @@ IDF_TARGET = esp32c6
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_AUDIOMP3 = 0

View file

@ -8,3 +8,8 @@ CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB
CIRCUITPY_ESPCAMERA = 0
# Override partition layout to preserve compatibility because the default has changed.
FLASH_SIZE_SDKCONFIG = esp-idf-config/sdkconfig-flash-4MB-no-uf2.defaults
CIRCUITPY_DUALBANK = 1
CIRCUITPY_BLEIO = 0

View file

@ -31,16 +31,16 @@
#include "nimble/nimble_port_freertos.h"
#include "host/ble_gap.h"
#include "host/util/util.h"
#include "services/ans/ble_svc_ans.h"
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
#include "bindings/espidf/__init__.h"
#include "common-hal/_bleio/Connection.h"
#include "esp_bt.h"
#include "esp_nimble_hci.h"
#if CIRCUITPY_TINYUSB
#include "supervisor/usb.h"
#endif
#include "nvs_flash.h"
#if CIRCUITPY_OS_GETENV
#include "shared-module/os/__init__.h"
@ -78,11 +78,25 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
}
if (enabled) {
nimble_port_init();
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
// NVS partition was truncated and needs to be erased
// Retry nvs_flash_init
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK(err);
CHECK_ESP_RESULT(nimble_port_init());
// ble_hs_cfg.reset_cb = blecent_on_reset;
ble_hs_cfg.sync_cb = _on_sync;
// ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
ble_svc_gap_init();
ble_svc_gatt_init();
ble_svc_ans_init();
#if CIRCUITPY_OS_GETENV
char ble_name[1 + MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH];
os_getenv_err_t result = common_hal_os_getenv_str("CIRCUITPY_BLE_NAME", ble_name, sizeof(ble_name));
@ -107,12 +121,18 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
// Wait for sync.
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(200));
} else {
nimble_port_stop();
int ret = nimble_port_stop();
while (xTaskGetHandle("nimble_host") != NULL) {
vTaskDelay(pdMS_TO_TICKS(2));
}
if (ret == 0) {
nimble_port_deinit();
}
}
}
bool common_hal_bleio_adapter_get_enabled(bleio_adapter_obj_t *self) {
return xTaskGetHandle("ble") != NULL;
return xTaskGetHandle("nimble_host") != NULL;
}
bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *self) {
@ -181,6 +201,7 @@ static int _scan_event(struct ble_gap_event *event, void *scan_results_in) {
disc->data,
disc->length_data);
} else {
#if MYNEWT_VAL(BLE_EXT_ADV)
// Extended advertisement
struct ble_gap_ext_disc_desc *disc = &event->ext_disc;
shared_module_bleio_scanresults_append(scan_results,
@ -192,6 +213,7 @@ static int _scan_event(struct ble_gap_event *event, void *scan_results_in) {
disc->addr.type,
disc->data,
disc->length_data);
#endif
}
return 0;
@ -383,6 +405,7 @@ mp_obj_t common_hal_bleio_adapter_connect(bleio_adapter_obj_t *self, bleio_addre
return mp_const_none;
}
#if MYNEWT_VAL(BLE_EXT_ADV)
typedef struct {
struct os_mbuf mbuf;
struct os_mbuf_pkthdr hdr;
@ -402,25 +425,35 @@ STATIC void _wrap_in_mbuf(const uint8_t *data, uint16_t len, os_mbuf_t *buf) {
// is ignored.
mbuf->om_omp = NULL;
}
#endif
static int _advertising_event(struct ble_gap_event *event, void *self_in) {
bleio_adapter_obj_t *self = (bleio_adapter_obj_t *)self_in;
#if CIRCUITPY_VERBOSE_BLE
mp_printf(&mp_plat_print, "Advertising event: %d\n", event->type);
#endif
switch (event->type) {
case BLE_GAP_EVENT_CONNECT:
// Spurious connect events can happen.
#if !MYNEWT_VAL(BLE_EXT_ADV)
if (event->connect.status == NIMBLE_OK) {
_new_connection(event->connect.conn_handle);
// Set connections objs back to NULL since we have a new
// connection and need a new tuple.
self->connection_objs = NULL;
}
common_hal_bleio_adapter_stop_advertising(self);
#endif
break;
case BLE_GAP_EVENT_ADV_COMPLETE:
#if MYNEWT_VAL(BLE_EXT_ADV)
if (event->adv_complete.reason == NIMBLE_OK) {
_new_connection(event->adv_complete.conn_handle);
// Set connections objs back to NULL since we have a new
// connection and need a new tuple.
self->connection_objs = NULL;
}
#endif
// Other statuses indicate timeout or preemption.
common_hal_bleio_adapter_stop_advertising(self);
break;
@ -446,8 +479,6 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
}
uint32_t rc;
bool extended = advertising_data_len > BLE_ADV_LEGACY_DATA_MAX_LEN ||
scan_response_data_len > BLE_ADV_LEGACY_DATA_MAX_LEN;
ble_addr_t peer;
if (directed_to != NULL) {
@ -464,6 +495,10 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
bool high_duty_directed = directed_to != NULL && interval <= 3.5 && timeout <= 1.3;
#if MYNEWT_VAL(BLE_EXT_ADV)
bool extended = advertising_data_len > BLE_ADV_LEGACY_DATA_MAX_LEN ||
scan_response_data_len > BLE_ADV_LEGACY_DATA_MAX_LEN;
struct ble_gap_ext_adv_params adv_params = {
.connectable = connectable,
.scannable = scan_response_data_len > 0,
@ -514,11 +549,40 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
}
rc = ble_gap_ext_adv_start(0, timeout / 10, 0);
#else
uint8_t conn_mode = connectable ? BLE_GAP_CONN_MODE_UND : BLE_GAP_CONN_MODE_NON;
if (directed_to != NULL) {
conn_mode = BLE_GAP_CONN_MODE_DIR;
}
struct ble_gap_adv_params adv_params = {
.conn_mode = conn_mode,
.disc_mode = BLE_GAP_DISC_MODE_GEN,
.itvl_min = SEC_TO_UNITS(interval, UNIT_0_625_MS) + 0.5f,
.itvl_max = SEC_TO_UNITS(interval, UNIT_0_625_MS) + 0.5f,
.channel_map = 0,
.filter_policy = BLE_HCI_CONN_FILT_NO_WL,
.high_duty_cycle = high_duty_directed,
};
rc = ble_gap_adv_set_data(advertising_data, advertising_data_len);
if (rc != NIMBLE_OK) {
return rc;
}
return NIMBLE_OK;
if (scan_response_data_len > 0) {
rc = ble_gap_adv_rsp_set_data(scan_response_data, scan_response_data_len);
if (rc != NIMBLE_OK) {
return rc;
}
}
rc = ble_gap_adv_start(own_addr_type, directed_to != NULL ? &peer: NULL,
timeout / 10,
&adv_params,
_advertising_event, self);
#endif
return rc;
}
STATIC void check_data_fit(size_t data_len, bool connectable) {
@ -575,11 +639,15 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
}
void common_hal_bleio_adapter_stop_advertising(bleio_adapter_obj_t *self) {
self->user_advertising = false;
if (!common_hal_bleio_adapter_get_advertising(self)) {
return;
}
#if MYNEWT_VAL(BLE_EXT_ADV)
int err_code = ble_gap_ext_adv_stop(0);
self->user_advertising = false;
#else
int err_code = ble_gap_adv_stop();
#endif
if ((err_code != NIMBLE_OK) &&
(err_code != BLE_HS_EALREADY) &&

View file

@ -10,12 +10,18 @@
#include "shared-bindings/_bleio/__init__.h"
#include "shared-bindings/_bleio/Characteristic.h"
#include "shared-bindings/_bleio/CharacteristicBuffer.h"
#include "shared-bindings/_bleio/Descriptor.h"
#include "shared-bindings/_bleio/PacketBuffer.h"
#include "shared-bindings/_bleio/Service.h"
#include "common-hal/_bleio/Adapter.h"
#include "common-hal/_bleio/Service.h"
// #include "common-hal/_bleio/bonding.h"
STATIC int characteristic_on_ble_gap_evt(struct ble_gap_event *event, void *param);
void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_service_obj_t *service,
uint16_t handle, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props,
bleio_attribute_security_mode_t read_perm, bleio_attribute_security_mode_t write_perm,
@ -29,23 +35,42 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
self->props = props;
self->read_perm = read_perm;
self->write_perm = write_perm;
self->observer = NULL;
// Map CP's property values to Nimble's flag values.
self->flags = 0;
if ((props & CHAR_PROP_BROADCAST) != 0) {
self->flags |= BLE_GATT_CHR_F_BROADCAST;
}
if ((props & CHAR_PROP_INDICATE) != 0) {
self->flags |= BLE_GATT_CHR_F_INDICATE;
}
if ((props & CHAR_PROP_NOTIFY) != 0) {
self->flags |= BLE_GATT_CHR_F_NOTIFY;
}
if ((props & CHAR_PROP_READ) != 0) {
self->flags |= BLE_GATT_CHR_F_READ;
}
if ((props & CHAR_PROP_WRITE) != 0) {
self->flags |= BLE_GATT_CHR_F_WRITE;
}
if ((props & CHAR_PROP_WRITE_NO_RESPONSE) != 0) {
self->flags |= BLE_GATT_CHR_F_WRITE_NO_RSP;
}
if (initial_value_bufinfo != NULL) {
// Copy the initial value if it's on the heap. Otherwise it's internal and we may not be able
// to allocate.
self->current_value_len = initial_value_bufinfo->len;
if (gc_alloc_possible()) {
self->current_value = m_malloc(max_length);
self->current_value_alloc = max_length;
if (gc_nbytes(initial_value_bufinfo->buf) > 0) {
uint8_t *initial_value = m_malloc(self->current_value_len);
self->current_value_alloc = self->current_value_len;
memcpy(initial_value, initial_value_bufinfo->buf, self->current_value_len);
self->current_value = initial_value;
} else {
self->current_value_alloc = 0;
self->current_value = initial_value_bufinfo->buf;
memcpy(self->current_value, initial_value_bufinfo->buf, self->current_value_len);
}
} else {
self->current_value = initial_value_bufinfo->buf;
assert(self->current_value_len == max_length);
}
}
@ -59,7 +84,9 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
self->fixed_length = fixed_length;
if (service->is_remote) {
// If the service is remote, we're buffering incoming notifications and indications.
self->handle = handle;
ble_event_add_handler_entry(&self->event_handler_entry, characteristic_on_ble_gap_evt, self);
} else {
common_hal_bleio_service_add_characteristic(self->service, self, initial_value_bufinfo, user_description);
}
@ -195,6 +222,89 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self,
}
}
// Used when we're the client.
STATIC int characteristic_on_ble_gap_evt(struct ble_gap_event *event, void *param) {
bleio_characteristic_obj_t *self = (bleio_characteristic_obj_t *)param;
switch (event->type) {
case BLE_GAP_EVENT_NOTIFY_RX: {
// A remote service wrote to this characteristic.
// Must be a notification, and event handle must match the handle for my characteristic.
if (event->notify_rx.indication == 0 &&
event->notify_rx.attr_handle == self->handle) {
if (self->observer == mp_const_none) {
return 0;
}
const struct os_mbuf *m = event->notify_rx.om;
uint16_t packet_len = OS_MBUF_PKTLEN(m);
uint8_t temp_full_packet[packet_len];
int rc = ble_hs_mbuf_to_flat(m, temp_full_packet, packet_len, NULL);
if (rc != 0) {
return rc;
}
if (mp_obj_is_type(self->observer, &bleio_characteristic_buffer_type)) {
bleio_characteristic_buffer_extend(MP_OBJ_FROM_PTR(self->observer), temp_full_packet, packet_len);
} else if (mp_obj_is_type(self->observer, &bleio_packet_buffer_type)) {
bleio_packet_buffer_extend(MP_OBJ_FROM_PTR(self->observer), event->notify_rx.conn_handle, temp_full_packet, packet_len);
}
}
break;
}
case BLE_GAP_EVENT_SUBSCRIBE:
break;
default:
return 0;
break;
}
return 0;
}
// Used when we're the server.
int bleio_characteristic_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg) {
bleio_characteristic_obj_t *self = (bleio_characteristic_obj_t *)arg;
int rc;
switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_CHR:
if (attr_handle == self->handle) {
rc = os_mbuf_append(ctxt->om,
self->current_value,
self->current_value_len);
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
return BLE_ATT_ERR_UNLIKELY;
case BLE_GATT_ACCESS_OP_WRITE_CHR:
if (attr_handle == self->handle) {
uint16_t om_len = OS_MBUF_PKTLEN(ctxt->om);
if (om_len > self->max_length || (self->fixed_length && om_len != self->max_length)) {
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
self->current_value_len = om_len;
rc = ble_hs_mbuf_to_flat(ctxt->om, self->current_value, om_len, NULL);
if (rc != 0) {
return rc;
}
if (self->observer != mp_const_none) {
if (mp_obj_is_type(self->observer, &bleio_characteristic_buffer_type)) {
bleio_characteristic_buffer_extend(MP_OBJ_FROM_PTR(self->observer), self->current_value, self->current_value_len);
} else if (mp_obj_is_type(self->observer, &bleio_packet_buffer_type)) {
bleio_packet_buffer_extend(MP_OBJ_FROM_PTR(self->observer), conn_handle, self->current_value, self->current_value_len);
}
}
return rc;
}
return BLE_ATT_ERR_UNLIKELY;
default:
return BLE_ATT_ERR_UNLIKELY;
}
return BLE_ATT_ERR_UNLIKELY;
}
bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self) {
return self->uuid;
}
@ -205,10 +315,19 @@ bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties
void common_hal_bleio_characteristic_add_descriptor(bleio_characteristic_obj_t *self,
bleio_descriptor_obj_t *descriptor) {
// TODO: Implement this.
size_t i = self->descriptor_list->len;
mp_obj_list_append(MP_OBJ_FROM_PTR(self->descriptor_list),
MP_OBJ_FROM_PTR(descriptor));
descriptor->dsc_def = &self->dsc_defs[i];
struct ble_gatt_dsc_def *dsc_def = descriptor->dsc_def;
dsc_def->uuid = &descriptor->uuid->nimble_ble_uuid.u;
dsc_def->att_flags = descriptor->flags;
dsc_def->min_key_size = 16;
dsc_def->access_cb = bleio_descriptor_access_cb;
dsc_def->arg = descriptor;
bleio_service_readd(self->service);
}
void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) {
@ -232,3 +351,11 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
xTaskNotifyWait(0, 0, (uint32_t *)&error_code, 200);
CHECK_BLE_ERROR(error_code);
}
void bleio_characteristic_set_observer(bleio_characteristic_obj_t *self, mp_obj_t observer) {
self->observer = observer;
}
void bleio_characteristic_clear_observer(bleio_characteristic_obj_t *self) {
self->observer = mp_const_none;
}

View file

@ -5,20 +5,25 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CHARACTERISTIC_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CHARACTERISTIC_H
#pragma once
#include "shared-bindings/_bleio/Attribute.h"
#include "common-hal/_bleio/Descriptor.h"
#include "shared-module/_bleio/Characteristic.h"
#include "common-hal/_bleio/ble_events.h"
#include "common-hal/_bleio/Service.h"
#include "common-hal/_bleio/UUID.h"
#include "host/ble_gatt.h"
#define MAX_DESCRIPTORS 2
typedef struct _bleio_characteristic_obj {
mp_obj_base_t base;
// Will be MP_OBJ_NULL before being assigned to a Service.
bleio_service_obj_t *service;
bleio_uuid_obj_t *uuid;
mp_obj_t observer;
uint8_t *current_value;
uint16_t current_value_len;
// Our internal allocation length. If > 0, then current_value is managed by
@ -27,6 +32,7 @@ typedef struct _bleio_characteristic_obj {
uint16_t max_length;
uint16_t def_handle;
uint16_t handle;
ble_gatt_chr_flags flags;
bleio_characteristic_properties_t props;
bleio_attribute_security_mode_t read_perm;
bleio_attribute_security_mode_t write_perm;
@ -34,7 +40,17 @@ typedef struct _bleio_characteristic_obj {
uint16_t user_desc_handle;
uint16_t cccd_handle;
uint16_t sccd_handle;
ble_event_handler_entry_t event_handler_entry;
// The actual structure is managed by the service because it needs to have
// an array.
struct ble_gatt_chr_def *chr_def;
struct ble_gatt_dsc_def dsc_defs[MAX_DESCRIPTORS + 1];
bool fixed_length;
} bleio_characteristic_obj_t;
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CHARACTERISTIC_H
int bleio_characteristic_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg);
void bleio_characteristic_set_observer(bleio_characteristic_obj_t *self, mp_obj_t observer);
void bleio_characteristic_clear_observer(bleio_characteristic_obj_t *self);

View file

@ -21,43 +21,18 @@
#include "common-hal/_bleio/ble_events.h"
STATIC int characteristic_buffer_on_ble_evt(struct ble_gap_event *event, void *param) {
bleio_characteristic_buffer_obj_t *self = (bleio_characteristic_buffer_obj_t *)param;
switch (event->type) {
case BLE_GAP_EVENT_NOTIFY_RX: {
// A remote service wrote to this characteristic.
// Must be a notification, and event handle must match the handle for my characteristic.
if (event->notify_rx.indication == 0 &&
event->notify_rx.attr_handle == self->characteristic->handle) {
const struct os_mbuf *m = event->notify_rx.om;
while (m != NULL) {
const uint8_t *data = m->om_data;
uint16_t len = m->om_len;
if (self->watch_for_interrupt_char) {
for (uint16_t i = 0; i < len; i++) {
if (data[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt();
} else {
ringbuf_put(&self->ringbuf, data[i]);
}
}
} else {
ringbuf_put_n(&self->ringbuf, data, len);
}
m = SLIST_NEXT(m, om_next);
}
void bleio_characteristic_buffer_extend(bleio_characteristic_buffer_obj_t *self, const uint8_t *data, size_t len) {
if (self->watch_for_interrupt_char) {
for (uint16_t i = 0; i < len; i++) {
if (data[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt();
} else {
ringbuf_put(&self->ringbuf, data[i]);
}
break;
}
default:
#if CIRCUITPY_VERBOSE_BLE
mp_printf(&mp_plat_print, "Unhandled gap event %d\n", event->type);
#endif
return 0;
break;
} else {
ringbuf_put_n(&self->ringbuf, data, len);
}
return 0;
}
void _common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buffer_obj_t *self,
@ -70,12 +45,7 @@ void _common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buff
self->timeout_ms = timeout * 1000;
self->watch_for_interrupt_char = watch_for_interrupt_char;
ringbuf_init(&self->ringbuf, buffer, buffer_size);
if (static_handler_entry != NULL) {
ble_event_add_handler_entry((ble_event_handler_entry_t *)static_handler_entry, characteristic_buffer_on_ble_evt, self);
} else {
ble_event_add_handler(characteristic_buffer_on_ble_evt, self);
}
bleio_characteristic_set_observer(characteristic, self);
}
// Assumes that timeout and buffer_size have been validated before call.
@ -121,11 +91,12 @@ bool common_hal_bleio_characteristic_buffer_deinited(bleio_characteristic_buffer
}
void common_hal_bleio_characteristic_buffer_deinit(bleio_characteristic_buffer_obj_t *self) {
if (!common_hal_bleio_characteristic_buffer_deinited(self)) {
ble_event_remove_handler(characteristic_buffer_on_ble_evt, self);
self->characteristic = NULL;
ringbuf_deinit(&self->ringbuf);
if (common_hal_bleio_characteristic_buffer_deinited(self)) {
return;
}
bleio_characteristic_clear_observer(self->characteristic);
self->characteristic = NULL;
ringbuf_deinit(&self->ringbuf);
}
bool common_hal_bleio_characteristic_buffer_connected(bleio_characteristic_buffer_obj_t *self) {

View file

@ -4,8 +4,7 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H
#pragma once
#include <stdbool.h>
@ -21,4 +20,5 @@ typedef struct {
bool watch_for_interrupt_char;
} bleio_characteristic_buffer_obj_t;
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H
void bleio_characteristic_buffer_extend(bleio_characteristic_buffer_obj_t *self, const uint8_t *buffer, size_t len);

View file

@ -5,8 +5,7 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CONNECTION_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CONNECTION_H
#pragma once
#include <stdbool.h>
@ -68,5 +67,3 @@ int bleio_connection_event_cb(struct ble_gap_event *event, void *connection_in);
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *connection);
bleio_connection_internal_t *bleio_conn_handle_to_connection(uint16_t conn_handle);
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CONNECTION_H

View file

@ -6,6 +6,7 @@
//
// SPDX-License-Identifier: MIT
#include "py/obj.h"
#include "py/runtime.h"
#include "shared-bindings/_bleio/__init__.h"
@ -74,3 +75,34 @@ void common_hal_bleio_descriptor_set_value(bleio_descriptor_obj_t *self, mp_buff
}
}
int bleio_descriptor_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg) {
bleio_descriptor_obj_t *self = arg;
const ble_uuid_t *uuid;
int rc;
switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_DSC:
uuid = ctxt->dsc->uuid;
if (ble_uuid_cmp(uuid, &self->uuid->nimble_ble_uuid.u) == 0) {
mp_buffer_info_t bufinfo;
if (!mp_get_buffer(self->initial_value, &bufinfo, MP_BUFFER_READ)) {
return BLE_ATT_ERR_UNLIKELY;
}
rc = os_mbuf_append(ctxt->om,
bufinfo.buf,
bufinfo.len);
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
return BLE_ATT_ERR_UNLIKELY;
case BLE_GATT_ACCESS_OP_WRITE_DSC:
return BLE_ATT_ERR_UNLIKELY;
default:
return BLE_ATT_ERR_UNLIKELY;
}
return BLE_ATT_ERR_UNLIKELY;
}

View file

@ -6,8 +6,7 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_DESCRIPTOR_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_DESCRIPTOR_H
#pragma once
#include "py/obj.h"
@ -27,9 +26,11 @@ typedef struct _bleio_descriptor_obj {
uint16_t max_length;
bool fixed_length;
uint16_t handle;
struct ble_gatt_dsc_def def;
struct ble_gatt_dsc_def *dsc_def;
uint8_t flags;
bleio_attribute_security_mode_t read_perm;
bleio_attribute_security_mode_t write_perm;
} bleio_descriptor_obj_t;
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_DESCRIPTOR_H
int bleio_descriptor_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg);

View file

@ -23,8 +23,11 @@
#include "host/ble_att.h"
STATIC void write_to_ringbuf(bleio_packet_buffer_obj_t *self, const struct os_mbuf *mbuf) {
size_t len = OS_MBUF_PKTLEN(mbuf);
void bleio_packet_buffer_extend(bleio_packet_buffer_obj_t *self, uint16_t conn_handle, const uint8_t *data, size_t len) {
if (self->conn_handle != conn_handle) {
return;
}
if (len + sizeof(uint16_t) > ringbuf_size(&self->ringbuf)) {
// This shouldn't happen but can if our buffer size was much smaller than
// the writes the client actually makes.
@ -40,10 +43,7 @@ STATIC void write_to_ringbuf(bleio_packet_buffer_obj_t *self, const struct os_mb
// set an overflow flag?
}
ringbuf_put_n(&self->ringbuf, (uint8_t *)&len, sizeof(uint16_t));
while (mbuf != NULL) {
ringbuf_put_n(&self->ringbuf, mbuf->om_data, mbuf->om_len);
mbuf = SLIST_NEXT(mbuf, om_next);
}
ringbuf_put_n(&self->ringbuf, data, len);
}
STATIC int packet_buffer_on_ble_client_evt(struct ble_gap_event *event, void *param);
@ -77,7 +77,7 @@ STATIC int queue_next_write(bleio_packet_buffer_obj_t *self) {
self->characteristic->handle,
self->outgoing[self->pending_index],
self->pending_size);
// We don't set packet_queued because we NimBLE will buffer our
// We don't set packet_queued because NimBLE will buffer our
// outgoing packets.
} else {
err_code = ble_gattc_write_flat(conn_handle,
@ -88,10 +88,33 @@ STATIC int queue_next_write(bleio_packet_buffer_obj_t *self) {
self->pending_index = (self->pending_index + 1) % 2;
self->packet_queued = true;
}
self->pending_size = 0;
} else {
// TODO: Notify because we're the server.
// Allocate an mbuf because the functions below consume it.
struct os_mbuf *om = ble_hs_mbuf_from_flat(self->outgoing[self->pending_index], self->pending_size);
if (om == NULL) {
return BLE_HS_ENOMEM;
}
size_t pending_size = self->pending_size;
self->pending_size = 0;
if (self->write_type == CHAR_PROP_NOTIFY) {
err_code = ble_gatts_notify_custom(conn_handle, self->characteristic->handle, om);
} else if (self->write_type == CHAR_PROP_INDICATE) {
err_code = ble_gatts_indicate_custom(conn_handle, self->characteristic->handle, om);
self->pending_index = (self->pending_index + 1) % 2;
self->packet_queued = true;
} else {
// Placeholder error.
err_code = BLE_HS_EUNKNOWN;
}
// Undo our queueing if it fails. We need to do it early because we may recurse back
// to here from the above ble_gatts functions.
if (err_code != NIMBLE_OK) {
self->pending_index = (self->pending_index + 1) % 2;
self->packet_queued = false;
self->pending_size = pending_size;
}
}
self->pending_size = 0;
if (err_code != NIMBLE_OK) {
// On error, simply skip updating the pending buffers so that the next HVC or WRITE
// complete event triggers another attempt.
@ -101,28 +124,33 @@ STATIC int queue_next_write(bleio_packet_buffer_obj_t *self) {
return NIMBLE_OK;
}
// This is called from the nimble task. *Not* CircuitPython's.
STATIC int packet_buffer_on_ble_client_evt(struct ble_gap_event *event, void *param) {
bleio_packet_buffer_obj_t *self = (bleio_packet_buffer_obj_t *)param;
if (event->type == BLE_GAP_EVENT_DISCONNECT && self->conn_handle == event->disconnect.conn.conn_handle) {
self->conn_handle = BLEIO_HANDLE_INVALID;
return false;
}
switch (event->type) {
case BLE_GAP_EVENT_NOTIFY_RX: {
if (event->notify_rx.conn_handle != self->conn_handle) {
if (event->type == BLE_GAP_EVENT_SUBSCRIBE) {
if (self->conn_handle == BLEIO_HANDLE_INVALID && (event->subscribe.cur_notify == 1 || event->subscribe.cur_indicate == 1)) {
self->conn_handle = event->subscribe.conn_handle;
} else if (self->conn_handle == event->subscribe.conn_handle && event->subscribe.cur_notify == 0 && event->subscribe.cur_indicate == 0) {
self->conn_handle = BLEIO_HANDLE_INVALID;
}
return false;
}
if (event->type == BLE_GAP_EVENT_NOTIFY_TX) {
if (self->conn_handle == event->notify_tx.conn_handle && self->characteristic->handle == event->notify_tx.attr_handle) {
if (event->notify_tx.indication == 1 && event->notify_tx.status == 0) {
// The indicate has been queued.
return false;
}
// Must be a notification, and event handle must match the handle for my characteristic.
if (event->notify_rx.attr_handle == self->characteristic->handle) {
write_to_ringbuf(self, event->notify_rx.om);
}
break;
}
default:
queue_next_write(self);
return false;
break;
}
}
return true;
// Notify and indicate events are managed by the characteristic.
return false;
}
void _common_hal_bleio_packet_buffer_construct(
@ -156,12 +184,13 @@ void _common_hal_bleio_packet_buffer_construct(
self->outgoing[0] = outgoing_buffer1;
self->outgoing[1] = outgoing_buffer2;
if (static_handler_entry != NULL) {
ble_event_add_handler_entry((ble_event_handler_entry_t *)static_handler_entry, packet_buffer_on_ble_client_evt, self);
} else {
ble_event_add_handler(packet_buffer_on_ble_client_evt, self);
}
bleio_characteristic_set_observer(self->characteristic, self);
if (self->client) {
if (static_handler_entry != NULL) {
ble_event_add_handler_entry((ble_event_handler_entry_t *)static_handler_entry, packet_buffer_on_ble_client_evt, self);
} else {
ble_event_add_handler(packet_buffer_on_ble_client_evt, self);
}
if (incoming) {
// Prefer notify if both are available.
if (incoming & CHAR_PROP_NOTIFY) {
@ -177,7 +206,12 @@ void _common_hal_bleio_packet_buffer_construct(
}
}
} else {
// TODO: Setup for server.
if (outgoing) {
self->write_type = CHAR_PROP_NOTIFY;
if (outgoing & CHAR_PROP_INDICATE) {
self->write_type = CHAR_PROP_INDICATE;
}
}
}
}
@ -199,7 +233,8 @@ void common_hal_bleio_packet_buffer_construct(
size_t incoming_buffer_size = 0;
uint32_t *incoming_buffer = NULL;
if (incoming) {
ringbuf_init(&self->ringbuf, (uint8_t *)incoming_buffer, incoming_buffer_size);
incoming_buffer_size = buffer_size * (sizeof(uint16_t) + max_packet_size);
incoming_buffer = m_malloc(incoming_buffer_size);
}
uint32_t *outgoing1 = NULL;
@ -208,10 +243,9 @@ void common_hal_bleio_packet_buffer_construct(
outgoing1 = m_malloc(max_packet_size);
// Only allocate the second buffer if we are doing writes with responses.
// Without responses, we just write as quickly as we can.
if (outgoing == CHAR_PROP_WRITE) {
if (outgoing == CHAR_PROP_WRITE || outgoing == CHAR_PROP_INDICATE) {
outgoing2 = m_malloc(max_packet_size);
}
}
_common_hal_bleio_packet_buffer_construct(self, characteristic,
incoming_buffer, incoming_buffer_size,
@ -391,8 +425,10 @@ bool common_hal_bleio_packet_buffer_deinited(bleio_packet_buffer_obj_t *self) {
}
void common_hal_bleio_packet_buffer_deinit(bleio_packet_buffer_obj_t *self) {
if (!common_hal_bleio_packet_buffer_deinited(self)) {
ble_event_remove_handler(packet_buffer_on_ble_client_evt, self);
ringbuf_deinit(&self->ringbuf);
if (common_hal_bleio_packet_buffer_deinited(self)) {
return;
}
bleio_characteristic_clear_observer(self->characteristic);
ble_event_remove_handler(packet_buffer_on_ble_client_evt, self);
ringbuf_deinit(&self->ringbuf);
}

View file

@ -4,8 +4,7 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_PACKETBUFFER_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_PACKETBUFFER_H
#pragma once
#include "py/ringbuf.h"
#include "shared-bindings/_bleio/Characteristic.h"
@ -29,4 +28,4 @@ typedef struct {
bool packet_queued;
} bleio_packet_buffer_obj_t;
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_PACKETBUFFER_H
void bleio_packet_buffer_extend(bleio_packet_buffer_obj_t *self, uint16_t conn_handle, const uint8_t *buffer, size_t len);

View file

@ -21,15 +21,30 @@ uint32_t _common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uu
self->is_remote = false;
self->connection = NULL;
self->is_secondary = is_secondary;
self->service_def.type = is_secondary? BLE_GATT_SVC_TYPE_SECONDARY : BLE_GATT_SVC_TYPE_PRIMARY;
self->service_def.uuid = &uuid->nimble_ble_uuid.u;
self->service_def.includes = NULL;
self->service_def.characteristics = self->chr_defs;
self->next_svc_type = 0;
// Don't add the service yet because we don't have any characteristics.
return 0;
}
void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary) {
mp_raise_NotImplementedError(NULL);
_common_hal_bleio_service_construct(self, uuid, is_secondary,
mp_obj_new_list(0, NULL));
}
void common_hal_bleio_service_deinit(bleio_service_obj_t *self) {
// Delete the old version of the service.
if (self->characteristic_list->len > 1) {
ble_gatts_delete_svc(&self->uuid->nimble_ble_uuid.u);
}
self->service_def.type = 0;
}
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection) {
self->handle = BLEIO_HANDLE_INVALID;
self->uuid = NULL;
@ -55,14 +70,37 @@ bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) {
return self->is_secondary;
}
// Used by characteristics to update their descriptors.
void bleio_service_readd(bleio_service_obj_t *self) {
// Delete the old version of the service.
if (self->characteristic_list->len > 1) {
ble_gatts_delete_svc(&self->uuid->nimble_ble_uuid.u);
}
CHECK_NIMBLE_ERROR(ble_gatts_add_dynamic_svcs(&self->service_def));
}
void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
bleio_characteristic_obj_t *characteristic,
mp_buffer_info_t *initial_value_bufinfo,
const char *user_description) {
#if CIRCUITPY_VERBOSE_BLE
mp_printf(&mp_plat_print, "Char handle %x user %x cccd %x sccd %x\n", characteristic->handle, characteristic->user_desc_handle, characteristic->cccd_handle, characteristic->sccd_handle);
#endif
mp_obj_list_append(self->characteristic_list, MP_OBJ_FROM_PTR(characteristic));
// Delete the old version of the service.
if (self->characteristic_list->len > 1) {
ble_gatts_delete_svc(&self->uuid->nimble_ble_uuid.u);
}
size_t i = self->characteristic_list->len - 1;
self->chr_defs[i].uuid = &characteristic->uuid->nimble_ble_uuid.u;
self->chr_defs[i].access_cb = bleio_characteristic_access_cb;
self->chr_defs[i].arg = characteristic;
self->chr_defs[i].descriptors = characteristic->dsc_defs;
self->chr_defs[i].flags = characteristic->flags;
self->chr_defs[i].min_key_size = 16;
self->chr_defs[i].val_handle = &characteristic->handle;
self->chr_defs[i].cpfd = NULL;
self->chr_defs[i + 1].uuid = NULL;
characteristic->chr_def = &self->chr_defs[i];
CHECK_NIMBLE_ERROR(ble_gatts_add_dynamic_svcs(&self->service_def));
}

View file

@ -5,12 +5,15 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_SERVICE_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_SERVICE_H
#pragma once
#include "py/objlist.h"
#include "common-hal/_bleio/UUID.h"
#define MAX_CHARACTERISTIC_COUNT 10
#include "host/ble_gatt.h"
typedef struct bleio_service_obj {
mp_obj_base_t base;
// Handle for the local service.
@ -26,8 +29,11 @@ typedef struct bleio_service_obj {
// Range of attribute handles of this remote service.
uint16_t start_handle;
uint16_t end_handle;
struct ble_gatt_svc_def service_def;
// Include a spot for terminating the service def array.
uint8_t next_svc_type;
struct ble_gatt_chr_def chr_defs[MAX_CHARACTERISTIC_COUNT + 1];
} bleio_service_obj_t;
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection);
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_SERVICE_H
void bleio_service_readd(bleio_service_obj_t *self);

View file

@ -6,8 +6,7 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_UUID_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_UUID_H
#pragma once
#include "py/obj.h"
@ -25,5 +24,3 @@ typedef struct {
void bleio_uuid_construct_from_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_uuid);
void bleio_uuid_convert_to_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_uuid);
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_UUID_H

View file

@ -4,10 +4,9 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_INIT_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_INIT_H
#pragma once
#include "FreeRTOS.h"
#include "freertos/FreeRTOS.h" // IWYU pragma: keep; for BaseType_t
void bleio_background(void);
@ -40,5 +39,3 @@ void check_notify(BaseType_t result);
#define UNIT_1_MS (1000)
#define UNIT_1_25_MS (1250)
#define UNIT_10_MS (10000)
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_INIT_H

View file

@ -6,8 +6,7 @@
//
// SPDX-License-Identifier: MIT
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL__BLEIO_BLE_EVENTS_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL__BLEIO_BLE_EVENTS_H
#pragma once
#include <stdbool.h>
@ -28,5 +27,3 @@ void ble_event_remove_handler(ble_gap_event_fn *func, void *param);
void ble_event_add_handler_entry(ble_event_handler_entry_t *entry, ble_gap_event_fn *func, void *param);
int ble_event_run_handlers(struct ble_gap_event *event);
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL__BLEIO_BLE_EVENTS_H

View file

@ -33,7 +33,7 @@
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
#define ADC_RESULT_BYTE 2
#define ADC_CONV_LIMIT_EN 0
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
#elif defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
#define ADC_RESULT_BYTE 4
#define ADC_CONV_LIMIT_EN 0
#elif defined(CONFIG_IDF_TARGET_ESP32S3)

View file

@ -26,6 +26,8 @@
#define ATTENUATION ADC_ATTEN_DB_11
#if defined(CONFIG_IDF_TARGET_ESP32)
#define DATA_WIDTH ADC_BITWIDTH_12
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
#define DATA_WIDTH ADC_BITWIDTH_12
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#define DATA_WIDTH ADC_BITWIDTH_12
#elif defined(CONFIG_IDF_TARGET_ESP32C6)
@ -71,7 +73,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
.unit_id = self->pin->adc_index,
.ulp_mode = ADC_ULP_MODE_DISABLE
};
cp_check_esp_error(adc_oneshot_new_unit(&adc_config, &adc_handle));
CHECK_ESP_RESULT(adc_oneshot_new_unit(&adc_config, &adc_handle));
adc_oneshot_chan_cfg_t channel_config = {
.atten = ATTENUATION,

View file

@ -143,15 +143,15 @@ void common_hal_dotclockframebuffer_framebuffer_construct(dotclockframebuffer_fr
cfg->flags.fb_in_psram = 1; // allocate frame buffer in PSRAM
esp_err_t ret = esp_lcd_new_rgb_panel(&self->panel_config, &self->panel_handle);
cp_check_esp_error(ret);
cp_check_esp_error(esp_lcd_panel_reset(self->panel_handle));
cp_check_esp_error(esp_lcd_panel_init(self->panel_handle));
CHECK_ESP_RESULT(ret);
CHECK_ESP_RESULT(esp_lcd_panel_reset(self->panel_handle));
CHECK_ESP_RESULT(esp_lcd_panel_init(self->panel_handle));
uint16_t color = 0;
cp_check_esp_error(self->panel_handle->draw_bitmap(self->panel_handle, 0, 0, 1, 1, &color));
CHECK_ESP_RESULT(self->panel_handle->draw_bitmap(self->panel_handle, 0, 0, 1, 1, &color));
void *fb;
cp_check_esp_error(esp_lcd_rgb_panel_get_frame_buffer(self->panel_handle, 1, &fb));
CHECK_ESP_RESULT(esp_lcd_rgb_panel_get_frame_buffer(self->panel_handle, 1, &fb));
self->frequency = frequency;
self->width = width;

View file

@ -89,6 +89,22 @@ static const uint64_t pin_mask_reset_forbidden =
// SPI flash and PSRAM pins are protected at runtime in supervisor/port.c.
#endif // ESP32
#if defined(CONFIG_IDF_TARGET_ESP32C2)
// Never ever reset pins used to communicate with SPI flash.
GPIO_SEL_11 | // VDD_SPI
GPIO_SEL_12 | // SPIHD
GPIO_SEL_13 | // SPIWP
GPIO_SEL_14 | // SPICS0
GPIO_SEL_15 | // SPICLK
GPIO_SEL_16 | // SPID
GPIO_SEL_17 | // SPIQ
#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) && CONFIG_ESP_CONSOLE_UART_DEFAULT && CONFIG_ESP_CONSOLE_UART_NUM == 0
// Never reset debug UART/console pins.
GPIO_SEL_19 |
GPIO_SEL_20 |
#endif
#endif // ESP32C2
#if defined(CONFIG_IDF_TARGET_ESP32C3)
// Never ever reset pins used to communicate with SPI flash.
GPIO_SEL_11 | // VDD_SPI

View file

@ -61,6 +61,8 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
uint32_t mac_address_part = REG_READ(EFUSE_BLK0_RDATA1_REG);
#elif defined(CONFIG_IDF_TARGET_ESP32H2)
uint32_t mac_address_part = REG_READ(EFUSE_RD_MAC_SYS_0_REG);
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
uint32_t mac_address_part = REG_READ(EFUSE_RD_BLK2_DATA0_REG);
#else
uint32_t mac_address_part = REG_READ(EFUSE_RD_MAC_SPI_SYS_0_REG);
#endif
@ -78,6 +80,8 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
mac_address_part = REG_READ(EFUSE_BLK0_RDATA2_REG);
#elif defined(CONFIG_IDF_TARGET_ESP32H2)
mac_address_part = REG_READ(EFUSE_RD_MAC_SYS_1_REG);
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
mac_address_part = REG_READ(EFUSE_RD_BLK2_DATA1_REG);
#else
mac_address_part = REG_READ(EFUSE_RD_MAC_SPI_SYS_1_REG);
#endif

View file

@ -27,6 +27,9 @@
#if defined(CONFIG_IDF_TARGET_ESP32)
#include "soc/rtc_cntl_reg.h"
#include "esp32/rom/rtc.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
#include "soc/rtc_cntl_reg.h"
#include "esp32c2/rom/rtc.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#include "soc/rtc_cntl_reg.h"
#include "esp32c3/rom/rtc.h"

@ -1 +1 @@
Subproject commit 722fba96a17fba2809434e01d65b6ce88ec4ca2e
Subproject commit da9dc379bede0bd684ddf7d95be4630897ca522e

View file

@ -0,0 +1,7 @@
# Name, Type, SubType, Offset, Size
# bootloader, app, boot, 0x1000/0x0, 28/32K
# partition_table, data, table, 0x8000, 4K
nvs, data, nvs, 0x9000, 20K
otadata, data, ota, 0xe000, 8K
ota_0, app, ota_0, 0x10000, 2048K
user_fs, data, fat, 0x210000, 1984K
1 # Name Type SubType Offset Size
2 # bootloader app boot 0x1000/0x0 28/32K
3 # partition_table data table 0x8000 4K
4 nvs data nvs 0x9000 20K
5 otadata data ota 0xe000 8K
6 ota_0 app ota_0 0x10000 2048K
7 user_fs data fat 0x210000 1984K

View file

@ -14,22 +14,18 @@ CONFIG_BT_NIMBLE_ENABLED=y
#
CONFIG_BT_NIMBLE_LOG_LEVEL_NONE=y
CONFIG_BT_NIMBLE_NVS_PERSIST=y
CONFIG_BT_NIMBLE_DYNAMIC_SERVICE=y
#
# Memory Settings
#
CONFIG_BT_NIMBLE_ACL_BUF_COUNT=20
CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70
CONFIG_BT_NIMBLE_TRANSPORT_ACL_FROM_LL_COUNT=20
CONFIG_BT_NIMBLE_TRANSPORT_EVT_SIZE=70
# end of Memory Settings
CONFIG_BT_NIMBLE_EXT_ADV=y
# CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV is not set
CONFIG_BT_NIMBLE_HIGH_DUTY_ADV_ITVL=y
# end of NimBLE Options
#
# Controller Options
#
# CONFIG_BT_CTRL_BLE_SCAN_DUPL is not set
# end of Controller Options
# end of Bluetooth
# end of Component config

View file

@ -4,6 +4,24 @@
#
# Component config
#
#
# Bluetooth
#
#
# NimBLE Options
#
CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y
# end of NimBLE Options
#
# Controller Options
#
CONFIG_BTDM_CTRL_PINNED_TO_CORE_1=y
# CONFIG_BTDM_BLE_SCAN_DUPL is not set
# end of Controller Options
# end of Bluetooth
#
# Driver Configurations
#
@ -40,7 +58,7 @@ CONFIG_ESP_IPC_TASK_STACK_SIZE=1536
#
# Wi-Fi
#
# CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is not set
# CONFIG_ESP_WIFI_IRAM_OPT is not set
# end of Wi-Fi
#

View file

@ -0,0 +1,49 @@
#
# Espressif IoT Development Framework Configuration
#
#
# Component config
#
#
# Bluetooth
#
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
#
# NimBLE Options
#
CONFIG_BT_NIMBLE_LOG_LEVEL_NONE=y
CONFIG_BT_NIMBLE_NVS_PERSIST=y
#
# Memory Settings
#
CONFIG_BT_NIMBLE_TRANSPORT_ACL_FROM_LL_COUNT=20
CONFIG_BT_NIMBLE_TRANSPORT_EVT_SIZE=70
# end of Memory Settings
CONFIG_BT_NIMBLE_EXT_ADV=y
# end of NimBLE Options
#
# Controller Options
#
# CONFIG_BT_CTRL_BLE_SCAN_DUPL is not set
# end of Controller Options
# end of Bluetooth
#
# Wi-Fi
#
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=4
# end of Wi-Fi
#
# Newlib
#
CONFIG_NEWLIB_NANO_FORMAT=y
# end of Newlib
# end of Component config
# end of Espressif IoT Development Framework Configuration

View file

@ -1,4 +1,7 @@
#
# Espressif IoT Development Framework Configuration
#
#
# Serial flasher config
#
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
@ -6,13 +9,17 @@
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE="16MB"
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
# end of Serial flasher config
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="esp-idf-config/partitions-16MB-no-uf2.csv"
#
# Partition Table
#
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="esp-idf-config/partitions-16MB-no-uf2.csv"
CONFIG_PARTITION_TABLE_FILENAME="esp-idf-config/partitions-16MB-no-uf2.csv"
# end of Partition Table
# end of Espressif IoT Development Framework Configuration

View file

@ -0,0 +1,25 @@
#
# Espressif IoT Development Framework Configuration
#
#
# Serial flasher config
#
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
# end of Serial flasher config
#
# Partition Table
#
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="esp-idf-config/partitions-4MB-no-ota-no-uf2.csv"
CONFIG_PARTITION_TABLE_FILENAME="esp-idf-config/partitions-4MB-no-ota-no-uf2.csv"
# end of Partition Table
# end of Espressif IoT Development Framework Configuration

View file

@ -0,0 +1,14 @@
# CONFIG_ESPTOOLPY_FLASHFREQ_120M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_64M is not set
CONFIG_ESPTOOLPY_FLASHFREQ_60M=y
# CONFIG_ESPTOOLPY_FLASHFREQ_48M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_32M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_30M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_24M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_16M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_15M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_80M_DEFAULT is not set

View file

@ -25,7 +25,7 @@
// Nearly all boards have this because it is used to enter the ROM bootloader.
#ifndef CIRCUITPY_BOOT_BUTTON
#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)
#elif !defined(CONFIG_IDF_TARGET_ESP32)
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)

View file

@ -22,10 +22,10 @@ CIRCUITPY_ANALOGBUFIO ?= 1
CIRCUITPY_AUDIOBUSIO ?= 1
CIRCUITPY_AUDIOBUSIO_PDMIN ?= 0
CIRCUITPY_AUDIOIO ?= 0
CIRCUITPY_BLEIO ?= 1
CIRCUITPY_BLEIO_HCI = 0
CIRCUITPY_CANIO ?= 1
CIRCUITPY_COUNTIO ?= 1
CIRCUITPY_DUALBANK ?= 1
CIRCUITPY_ESPCAMERA ?= 1
CIRCUITPY_ESPIDF ?= 1
CIRCUITPY_ESPULP ?= 1
@ -49,14 +49,50 @@ CIRCUITPY_WIFI ?= 1
ifeq ($(IDF_TARGET),esp32)
# Modules
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_BLEIO = 0
# Features
CIRCUITPY_USB_DEVICE = 0
else ifeq ($(IDF_TARGET),esp32c2)
# C2 ROM spits out the UART at 74880 when connected to a 26mhz crystal! Debug
# prints will default to that too.
# Modules
CIRCUITPY_ALARM = 0
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_ESPULP = 0
CIRCUITPY_MEMORYMAP = 0
# No I80 support from the IDF
CIRCUITPY_PARALLELDISPLAYBUS = 0
# No PCNT peripheral
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_ROTARYIO = 0
# No two wire automotive
CIRCUITPY_CANIO = 0
# No DMA from ADC
CIRCUITPY_ANALOGBUFIO = 0
# No I2S
CIRCUITPY_AUDIOBUSIO = 0
# No RMT
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PULSEIO = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_TOUCHIO ?= 1
CIRCUITPY_TOUCHIO_USE_NATIVE = 0
# Features
CIRCUITPY_USB_DEVICE = 0
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0
else ifeq ($(IDF_TARGET),esp32c3)
# Modules
CIRCUITPY_ALARM = 0
CIRCUITPY_BLEIO ?= 0
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_ESPULP = 0
CIRCUITPY_MEMORYMAP = 0
@ -78,7 +114,6 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1
else ifeq ($(IDF_TARGET),esp32c6)
# Modules
CIRCUITPY_ALARM = 0
CIRCUITPY_BLEIO ?= 0
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_ESPULP = 0
CIRCUITPY_MEMORYMAP = 0
@ -99,7 +134,6 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1
else ifeq ($(IDF_TARGET),esp32h2)
# Modules
CIRCUITPY_ALARM = 0
CIRCUITPY_BLEIO ?= 1
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_ESPULP = 0
CIRCUITPY_MEMORYMAP = 0
@ -131,9 +165,7 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 0
# No room for _bleio on boards with 4MB flash
ifeq ($(CIRCUITPY_ESP_FLASH_SIZE),4MB)
CIRCUITPY_BLEIO ?= 0
else
CIRCUITPY_BLEIO ?= 1
CIRCUITPY_BLEIO = 0
endif
endif
@ -142,10 +174,9 @@ endif
ifeq ($(CIRCUITPY_ESP_FLASH_SIZE),4MB)
CIRCUITPY_BITMAPFILTER ?= 0
OPTIMIZATION_FLAGS ?= -Os
# Until the 4MB C6 partition table is updated, disable mp3 on the 4MB C6 parts
ifeq ($(IDF_TARGET),esp32c6)
CIRCUITPY_AUDIOMP3 ?= 0
endif
CIRCUITPY_DUALBANK ?= 0
else
CIRCUITPY_DUALBANK ?= 1
endif
# No room for dualbank or mp3 on boards with 2MB flash
@ -153,6 +184,7 @@ ifeq ($(CIRCUITPY_ESP_FLASH_SIZE),2MB)
CIRCUITPY_BITMAPFILTER ?= 0
CIRCUITPY_DUALBANK = 0
CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_BLEIO = 0
endif
# Modules dependent on other modules

View file

@ -10,6 +10,8 @@
#if defined(CONFIG_IDF_TARGET_ESP32)
#include "components/esp_rom/include/esp32/rom/ets_sys.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
#include "components/esp_rom/include/esp32c2/rom/ets_sys.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#include "components/esp_rom/include/esp32c3/rom/ets_sys.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C6)

View file

@ -0,0 +1,42 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 microDev
*
* 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 "peripherals/pins.h"
const mcu_pin_obj_t pin_GPIO0 = PIN(0, ADC_UNIT_1, ADC_CHANNEL_0, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO1 = PIN(1, ADC_UNIT_1, ADC_CHANNEL_1, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO2 = PIN(2, ADC_UNIT_1, ADC_CHANNEL_2, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO3 = PIN(3, ADC_UNIT_1, ADC_CHANNEL_3, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO4 = PIN(4, ADC_UNIT_1, ADC_CHANNEL_4, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO5 = PIN(5, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO6 = PIN(6, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO7 = PIN(7, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO8 = PIN(8, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO9 = PIN(9, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO10 = PIN(10, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO18 = PIN(18, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO19 = PIN(19, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
const mcu_pin_obj_t pin_GPIO20 = PIN(20, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);

View file

@ -0,0 +1,60 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 microDev
*
* 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.
*/
// DO NOT include this file directly.
// Use shared-bindings/microcontroller/Pin.h instead.
// This ensures that all necessary includes are already included.
#pragma once
#define GPIO0_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO0;
#define GPIO1_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO1;
#define GPIO2_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO2;
#define GPIO3_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO3;
#define GPIO4_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO4;
#define GPIO5_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO5;
#define GPIO6_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO6;
#define GPIO7_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO7;
#define GPIO8_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO8;
#define GPIO9_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO9;
#define GPIO10_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO10;
#define GPIO18_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO18;
#define GPIO19_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO19;
#define GPIO20_EXISTS 1
extern const mcu_pin_obj_t pin_GPIO20;

View file

@ -34,10 +34,12 @@ esp_err_t peripherals_i2c_init(i2c_port_t num, const i2c_config_t *i2c_conf) {
}
size_t rx_buf_len = 0;
size_t tx_buf_len = 0;
#ifdef SOC_I2C_SUPPORT_SLAVE
if (i2c_conf->mode == I2C_MODE_SLAVE) {
rx_buf_len = 256;
tx_buf_len = 256;
}
#endif
return i2c_driver_install(num, i2c_conf->mode, rx_buf_len, tx_buf_len, 0);
}

View file

@ -47,6 +47,8 @@ extern const mp_obj_type_t mcu_pin_type;
// Choose based on chip
#if defined(CONFIG_IDF_TARGET_ESP32)
#include "esp32/pins.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
#include "esp32c2/pins.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#include "esp32c3/pins.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C6)

View file

@ -116,6 +116,9 @@ with open(sys.argv[1], "rb") as stream:
offset = section["sh_offset"]
if not size or not start:
continue
if section.name.endswith("dummy"):
# print("Skipping dummy section", section.name)
continue
# This handles sections that span two memory regions, not more than that.
# print(start, size, offset, section.name)
region = find_region(start)

View file

@ -16,9 +16,16 @@ while True:
addresses = input("? ")
if addresses.startswith("Backtrace:"):
addresses = addresses[len("Backtrace:") :]
if addresses.startswith("Stack memory:"):
addresses = addresses[len("Stack memory:") :]
addresses = addresses.strip().split()
addresses = [address.split(":")[0] for address in addresses]
subprocess.run(
["xtensa-esp32s2-elf-addr2line", "-aipfe", "build-{}/firmware.elf".format(board)]
+ addresses
)
for address in addresses:
result = subprocess.run(
["xtensa-esp32s2-elf-addr2line", "-aipfe", "build-{}/firmware.elf".format(board)]
+ [address],
capture_output=True,
)
stdout = result.stdout.decode("utf-8")
if "?? ??" not in stdout:
print(stdout.strip())

View file

@ -176,12 +176,9 @@ def update(debug, board, update_all):
if key == "IDF_TARGET":
target = value
if uf2_bootloader is None:
uf2_bootloader = target not in ("esp32", "esp32c3", "esp32c6", "esp32h2")
uf2_bootloader = target in ("esp32s2", "esp32s3")
if ble_enabled is None:
ble_enabled = target not in (
"esp32",
"esp32s2",
) # ESP32 is disabled by us. S2 doesn't support it.
ble_enabled = target not in ("esp32s2",) # S2 doesn't support it.
elif key == "CIRCUITPY_ESP_FLASH_SIZE":
flash_size = value
elif key == "CIRCUITPY_ESP_FLASH_MODE":

View file

@ -57,6 +57,9 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_ob
mp_obj_new_list(0, NULL)));
}
void common_hal_bleio_service_deinit(bleio_service_obj_t *self) {
}
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection) {
self->handle = 0xFFFF;
self->uuid = NULL;

View file

@ -109,6 +109,9 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self,
mp_obj_new_list(0, NULL));
}
void common_hal_bleio_service_deinit(bleio_service_obj_t *self) {
}
// Get service from connection
void bleio_service_from_connection(bleio_service_obj_t *self,
mp_obj_t connection) {

View file

@ -95,7 +95,7 @@ def preprocess():
def run(files):
completed = subprocess.run(args.pp + flags + files, stdout=subprocess.PIPE)
if completed.returncode != 0:
raise RuntimeError()
raise RuntimeError(" ".join(args.pp + flags + files))
return completed.stdout
return run

View file

@ -75,7 +75,7 @@ NORETURN void nlr_jump(void *val) {
"ret \n"
:
: "r" (top)
:
: "memory"
);
MP_UNREACHABLE

View file

@ -78,7 +78,7 @@ NORETURN void nlr_jump(void *val) {
"nop \n"
:
: "r" (top)
:
: "memory"
);
MP_UNREACHABLE
}

View file

@ -114,7 +114,7 @@ NORETURN void nlr_jump(void *val) {
"blr ;"
:
: "r" (&top->regs)
:
: "memory"
);
MP_UNREACHABLE;
@ -203,7 +203,7 @@ NORETURN void nlr_jump(void *val) {
"blr ;"
:
: "r" (&top->regs)
:
: "memory"
);
MP_UNREACHABLE;

View file

@ -133,7 +133,7 @@ NORETURN void nlr_jump(void *val) {
"bx lr \n" // return
: // output operands
: "r" (top) // input operands
: // clobbered registers
: "memory" // clobbered registers
);
MP_UNREACHABLE

View file

@ -123,7 +123,7 @@ NORETURN void nlr_jump(void *val) {
"ret \n" // return
: // output operands
: "r" (top) // input operands
: // clobbered registers
: "memory" // clobbered registers
);
MP_UNREACHABLE

View file

@ -95,7 +95,7 @@ NORETURN void nlr_jump(void *val) {
"ret \n" // return
: // output operands
: "r" (top) // input operands
: // clobbered registers
: "memory" // clobbered registers
);
MP_UNREACHABLE

Some files were not shown because too many files have changed in this diff Show more