From 399c10dc28eba4ddd163dd0e930529f1b81d514a Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 3 Mar 2025 17:32:41 +0100 Subject: [PATCH 1/4] mimxrt/machine_uart: Enable CTS SION so it can be read. The new CYW43 BTHCI UART backend requires CTS pin to be defined and readable. This patch enables the CTS pin SION bit to allow it to be read regardless of mux mode. Signed-off-by: iabdalkader --- ports/mimxrt/machine_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/mimxrt/machine_uart.c b/ports/mimxrt/machine_uart.c index 4dcaf72f9862a..107af72297d4f 100644 --- a/ports/mimxrt/machine_uart.c +++ b/ports/mimxrt/machine_uart.c @@ -136,7 +136,7 @@ bool lpuart_set_iomux_cts(int8_t uart) { int index = (uart - 1) * 2; if (CTS.muxRegister != 0) { - IOMUXC_SetPinMux(CTS.muxRegister, CTS.muxMode, CTS.inputRegister, CTS.inputDaisy, CTS.configRegister, 0U); + IOMUXC_SetPinMux(CTS.muxRegister, CTS.muxMode, CTS.inputRegister, CTS.inputDaisy, CTS.configRegister, 1U); IOMUXC_SetPinConfig(CTS.muxRegister, CTS.muxMode, CTS.inputRegister, CTS.inputDaisy, CTS.configRegister, pin_generate_config(PIN_PULL_UP_100K, PIN_MODE_IN, PIN_DRIVE_6, CTS.configRegister)); return true; From 3bbed952fdc884d85112a15715152c9c4f558c14 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 3 Mar 2025 17:46:56 +0100 Subject: [PATCH 2/4] mimxrt/cyw43_configport: Update cyw43 config to use new BTHCI UART. Update the cyw43 configuration to use the new BTHCI UART backend provided by cyw43-driver. Signed-off-by: iabdalkader --- ports/mimxrt/Makefile | 1 - ports/mimxrt/cyw43_configport.h | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index c0358387f975f..7788b54ca57ff 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -280,7 +280,6 @@ endif ifeq ($(MICROPY_PY_BLUETOOTH),1) SRC_C += mpbthciport.c -DRIVERS_SRC_C += drivers/cyw43/cywbt.c endif # MICROPY_PY_BLUETOOTH ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) diff --git a/ports/mimxrt/cyw43_configport.h b/ports/mimxrt/cyw43_configport.h index ab535a477763d..cf2f5d4b9fb55 100644 --- a/ports/mimxrt/cyw43_configport.h +++ b/ports/mimxrt/cyw43_configport.h @@ -32,10 +32,12 @@ #include "py/mperrno.h" #include "py/mphal.h" #include "extmod/modnetwork.h" +#include "extmod/mpbthci.h" #include "pendsv.h" #include "sdio.h" #define CYW43_USE_SPI (0) +#define CYW43_ENABLE_BLUETOOTH_OVER_UART (1) #define CYW43_LWIP (1) #define CYW43_USE_STATS (0) @@ -47,6 +49,18 @@ #define CYW43_WIFI_NVRAM_INCLUDE_FILE "lib/cyw43-driver/firmware/wifi_nvram_1dx.h" #endif +#ifndef CYW43_BT_FIRMWARE_INCLUDE_FILE +#define CYW43_BT_FIRMWARE_INCLUDE_FILE "lib/cyw43-driver/firmware/cyw43_btfw_4343A1.h" +#endif + +#ifdef MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY +#define CYW43_BT_UART_BAUDRATE_ACTIVE_USE MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY +#endif + +#ifdef MICROPY_HW_BLE_UART_BAUDRATE_DOWNLOAD_FIRMWARE +#define CYW43_BT_UART_BAUDRATE_DOWNLOAD_FIRMWARE MICROPY_HW_BLE_UART_BAUDRATE_DOWNLOAD_FIRMWARE +#endif + #define CYW43_IOCTL_TIMEOUT_US (1000000) #define CYW43_SLEEP_MAX (50) #define CYW43_NETUTILS (1) @@ -75,6 +89,7 @@ #define CYW43_HAL_PIN_PULL_DOWN MP_HAL_PIN_PULL_DOWN #define CYW43_HAL_MAC_WLAN0 MP_HAL_MAC_WLAN0 +#define CYW43_HAL_MAC_BDADDR MP_HAL_MAC_BDADDR #define cyw43_hal_ticks_us mp_hal_ticks_us #define cyw43_hal_ticks_ms mp_hal_ticks_ms @@ -88,9 +103,19 @@ #define cyw43_hal_get_mac_ascii mp_hal_get_mac_ascii #define cyw43_hal_generate_laa_mac mp_hal_generate_laa_mac +#define cyw43_hal_uart_set_baudrate mp_bluetooth_hci_uart_set_baudrate +#define cyw43_hal_uart_write mp_bluetooth_hci_uart_write +#define cyw43_hal_uart_readchar mp_bluetooth_hci_uart_readchar + #define cyw43_delay_us mp_hal_delay_us #define cyw43_delay_ms mp_hal_delay_ms +#define cyw43_bluetooth_controller_init mp_bluetooth_hci_controller_init +#define cyw43_bluetooth_controller_deinit mp_bluetooth_hci_controller_deinit +#define cyw43_bluetooth_controller_woken mp_bluetooth_hci_controller_woken +#define cyw43_bluetooth_controller_wakeup mp_bluetooth_hci_controller_wakeup +#define cyw43_bluetooth_controller_sleep_maybe mp_bluetooth_hci_controller_sleep_maybe + #define CYW43_PIN_WL_REG_ON MICROPY_HW_WL_REG_ON #define CYW43_PIN_WL_HOST_WAKE MICROPY_HW_WL_HOST_WAKE #define CYW43_PIN_WL_SDIO_1 MICROPY_HW_SDIO_D1 From 0f360880aa01ca87c637eaa3517a90a78c2dbfd2 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 30 Mar 2025 09:29:57 +0200 Subject: [PATCH 3/4] stm32/cyw43_configport: Update cyw43 config to use new BTHCI UART. Update the cyw43 configuration to use the new BTHCI UART backend provided by cyw43-driver. Signed-off-by: iabdalkader --- ports/stm32/Makefile | 1 - ports/stm32/boards/PYBD_SF2/f722_qspi.ld | 2 +- ports/stm32/cyw43_configport.h | 27 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index c938dcbda7d6d..8ac9a8af03d1a 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -432,7 +432,6 @@ endif ifeq ($(MICROPY_PY_BLUETOOTH),1) SRC_C += mpbthciport.c -DRIVERS_SRC_C += drivers/cyw43/cywbt.c ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) SRC_C += mpnimbleport.c diff --git a/ports/stm32/boards/PYBD_SF2/f722_qspi.ld b/ports/stm32/boards/PYBD_SF2/f722_qspi.ld index f5e6769834a09..354c1919b41a3 100644 --- a/ports/stm32/boards/PYBD_SF2/f722_qspi.ld +++ b/ports/stm32/boards/PYBD_SF2/f722_qspi.ld @@ -54,7 +54,7 @@ SECTIONS *lib/mbedtls/*(.text* .rodata*) *lib/mynewt-nimble/*(.text* .rodata*) *lib/cyw43-driver/*(.rodata.w4343*_combined) - *drivers/cyw43/*(.rodata.cyw43_btfw_*) + *lib/cyw43-driver/*(.rodata.cyw43_btfw_*) . = ALIGN(4); } >FLASH_EXT } diff --git a/ports/stm32/cyw43_configport.h b/ports/stm32/cyw43_configport.h index 595051180336e..c26c55476167c 100644 --- a/ports/stm32/cyw43_configport.h +++ b/ports/stm32/cyw43_configport.h @@ -32,11 +32,13 @@ #include "py/mperrno.h" #include "py/mphal.h" #include "extmod/modnetwork.h" +#include "extmod/mpbthci.h" #include "extint.h" #include "pendsv.h" #include "sdio.h" #define CYW43_USE_SPI (0) +#define CYW43_ENABLE_BLUETOOTH_OVER_UART (1) #define CYW43_LWIP (1) #define CYW43_USE_STATS (0) @@ -48,6 +50,18 @@ #define CYW43_WIFI_NVRAM_INCLUDE_FILE "lib/cyw43-driver/firmware/wifi_nvram_1dx.h" #endif +#ifndef CYW43_BT_FIRMWARE_INCLUDE_FILE +#define CYW43_BT_FIRMWARE_INCLUDE_FILE "lib/cyw43-driver/firmware/cyw43_btfw_4343A1.h" +#endif + +#ifdef MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY +#define CYW43_BT_UART_BAUDRATE_ACTIVE_USE MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY +#endif + +#ifdef MICROPY_HW_BLE_UART_BAUDRATE_DOWNLOAD_FIRMWARE +#define CYW43_BT_UART_BAUDRATE_DOWNLOAD_FIRMWARE MICROPY_HW_BLE_UART_BAUDRATE_DOWNLOAD_FIRMWARE +#endif + #define CYW43_IOCTL_TIMEOUT_US (1000000) #define CYW43_SLEEP_MAX (50) #define CYW43_NETUTILS (1) @@ -66,6 +80,7 @@ #define CYW43_SDPCM_SEND_COMMON_WAIT __WFI(); #define CYW43_DO_IOCTL_WAIT __WFI(); +#define CYW43_HAL_UART_READCHAR_BLOCKING_WAIT __WFI() #define CYW43_ARRAY_SIZE(a) MP_ARRAY_SIZE(a) @@ -76,6 +91,7 @@ #define CYW43_HAL_PIN_PULL_DOWN MP_HAL_PIN_PULL_DOWN #define CYW43_HAL_MAC_WLAN0 MP_HAL_MAC_WLAN0 +#define CYW43_HAL_MAC_BDADDR MP_HAL_MAC_BDADDR #define cyw43_hal_ticks_us mp_hal_ticks_us #define cyw43_hal_ticks_ms mp_hal_ticks_ms @@ -90,6 +106,16 @@ #define cyw43_hal_get_mac_ascii mp_hal_get_mac_ascii #define cyw43_hal_generate_laa_mac mp_hal_generate_laa_mac +#define cyw43_hal_uart_set_baudrate mp_bluetooth_hci_uart_set_baudrate +#define cyw43_hal_uart_write mp_bluetooth_hci_uart_write +#define cyw43_hal_uart_readchar mp_bluetooth_hci_uart_readchar + +#define cyw43_bluetooth_controller_init mp_bluetooth_hci_controller_init +#define cyw43_bluetooth_controller_deinit mp_bluetooth_hci_controller_deinit +#define cyw43_bluetooth_controller_woken mp_bluetooth_hci_controller_woken +#define cyw43_bluetooth_controller_wakeup mp_bluetooth_hci_controller_wakeup +#define cyw43_bluetooth_controller_sleep_maybe mp_bluetooth_hci_controller_sleep_maybe + #define CYW43_PIN_WL_REG_ON pyb_pin_WL_REG_ON #define CYW43_PIN_WL_HOST_WAKE pyb_pin_WL_HOST_WAKE #define CYW43_PIN_WL_SDIO_1 pyb_pin_WL_SDIO_1 @@ -103,6 +129,7 @@ #if MICROPY_HW_ENABLE_RF_SWITCH #define CYW43_PIN_RFSW_VDD pyb_pin_WL_RFSW_VDD +#define CYW43_PIN_RFSW_SELECT pyb_pin_WL_GPIO_1 #endif #define cyw43_schedule_internal_poll_dispatch(func) pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, func) From 0b729623366dab3aa2575eeab934b2629f8e52c5 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 30 Mar 2025 09:31:26 +0200 Subject: [PATCH 4/4] drivers/cyw43: Remove old BTHCI UART backend. It has been completely replaced by equivalent code in cyw43-driver. Signed-off-by: iabdalkader --- drivers/cyw43/README.md | 17 --- drivers/cyw43/cywbt.c | 304 ---------------------------------------- 2 files changed, 321 deletions(-) delete mode 100644 drivers/cyw43/README.md delete mode 100644 drivers/cyw43/cywbt.c diff --git a/drivers/cyw43/README.md b/drivers/cyw43/README.md deleted file mode 100644 index 5af6f65580668..0000000000000 --- a/drivers/cyw43/README.md +++ /dev/null @@ -1,17 +0,0 @@ -CYW43xx WiFi SoC driver -======================= - -This is a driver for the CYW43xx WiFi SoC. - -There are four layers to the driver: - -1. SDIO bus interface, provided by the host device/system. - -2. Low-level CYW43xx interface, managing the bus, control messages, Ethernet - frames and asynchronous events. Includes download of SoC firmware. The - header file `cyw43_ll.h` defines the interface to this layer. - -3. Mid-level CYW43xx control, to control and set WiFi parameters and manage - events. See `cyw43_ctrl.c`. - -4. TCP/IP bindings to lwIP. See `cyw43_lwip.c`. diff --git a/drivers/cyw43/cywbt.c b/drivers/cyw43/cywbt.c deleted file mode 100644 index 0ee69a07ecd2c..0000000000000 --- a/drivers/cyw43/cywbt.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019-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. - */ - -#include -#include - -#include "py/runtime.h" -#include "py/mphal.h" -#include "extmod/mpbthci.h" - -#if MICROPY_PY_NETWORK_CYW43 - -#include "lib/cyw43-driver/src/cyw43_config.h" -#include "lib/cyw43-driver/firmware/cyw43_btfw_4343A1.h" - -// Provided by the port, and also possibly shared with the stack. -extern uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; - -/******************************************************************************/ -// CYW BT HCI low-level driver - -#ifdef CYW43_PIN_BT_CTS -// This code is not portable and currently only builds on stm32 port. - -#include "pin_static_af.h" -#include "uart.h" - -// Provided by the port. -extern machine_uart_obj_t mp_bluetooth_hci_uart_obj; - -static void cywbt_wait_cts_low(void) { - mp_hal_pin_config(CYW43_PIN_BT_CTS, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_UP, 0); - for (int i = 0; i < 200; ++i) { - if (mp_hal_pin_read(CYW43_PIN_BT_CTS) == 0) { - break; - } - mp_hal_delay_ms(1); - } - mp_hal_pin_config_alt(CYW43_PIN_BT_CTS, MP_HAL_PIN_MODE_ALT, - MP_HAL_PIN_PULL_UP, AF_FN_UART, mp_bluetooth_hci_uart_obj.uart_id); -} -#endif - -static int cywbt_hci_cmd_raw(size_t len, uint8_t *buf) { - mp_bluetooth_hci_uart_write((void *)buf, len); - for (int c, i = 0; i < 6; ++i) { - while ((c = mp_bluetooth_hci_uart_readchar()) == -1) { - mp_event_wait_indefinite(); - } - buf[i] = c; - } - - // expect a command complete event (event 0x0e) - if (buf[0] != 0x04 || buf[1] != 0x0e) { - printf("unknown response: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]); - return -1; - } - - /* - if buf[3:6] != cmd[:3]: - print('response doesn\'t match cmd:', cmd, ev) - return b'' - */ - - int sz = buf[2] - 3; - for (int c, i = 0; i < sz; ++i) { - while ((c = mp_bluetooth_hci_uart_readchar()) == -1) { - mp_event_wait_indefinite(); - } - buf[i] = c; - } - - return 0; -} - -static int cywbt_hci_cmd(int ogf, int ocf, size_t param_len, const uint8_t *param_buf) { - uint8_t *buf = mp_bluetooth_hci_cmd_buf; - buf[0] = 0x01; - buf[1] = ocf; - buf[2] = ogf << 2 | ocf >> 8; - buf[3] = param_len; - if (param_len) { - memcpy(buf + 4, param_buf, param_len); - } - return cywbt_hci_cmd_raw(4 + param_len, buf); -} - -static void put_le16(uint8_t *buf, uint16_t val) { - buf[0] = val; - buf[1] = val >> 8; -} - -static void put_le32(uint8_t *buf, uint32_t val) { - buf[0] = val; - buf[1] = val >> 8; - buf[2] = val >> 16; - buf[3] = val >> 24; -} - -static int cywbt_set_baudrate(uint32_t baudrate) { - uint8_t buf[6]; - put_le16(buf, 0); - put_le32(buf + 2, baudrate); - return cywbt_hci_cmd(0x3f, 0x18, 6, buf); -} - -// download firmware -static int cywbt_download_firmware(const uint8_t *firmware) { - cywbt_hci_cmd(0x3f, 0x2e, 0, NULL); - - bool last_packet = false; - while (!last_packet) { - uint8_t *buf = mp_bluetooth_hci_cmd_buf; - memcpy(buf + 1, firmware, 3); - firmware += 3; - last_packet = buf[1] == 0x4e; - if (buf[2] != 0xfc) { - printf("fail1 %02x\n", buf[2]); - break; - } - uint8_t len = buf[3]; - - memcpy(buf + 4, firmware, len); - firmware += len; - - buf[0] = 1; - cywbt_hci_cmd_raw(4 + len, buf); - if (buf[0] != 0) { - printf("fail3 %02x\n", buf[0]); - break; - } - } - - // RF switch must select high path during BT patch boot - #if MICROPY_HW_ENABLE_RF_SWITCH - mp_hal_pin_config(CYW43_PIN_WL_GPIO_1, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_UP, 0); - #endif - mp_hal_delay_ms(10); // give some time for CTS to go high - #ifdef CYW43_PIN_BT_CTS - cywbt_wait_cts_low(); - #endif - #if MICROPY_HW_ENABLE_RF_SWITCH - // Select chip antenna (could also select external) - mp_hal_pin_config(CYW43_PIN_WL_GPIO_1, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_DOWN, 0); - #endif - - mp_bluetooth_hci_uart_set_baudrate(115200); - cywbt_set_baudrate(MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY); - mp_bluetooth_hci_uart_set_baudrate(MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY); - - return 0; -} - -int mp_bluetooth_hci_controller_init(void) { - // This is called immediately after the UART is initialised during stack initialisation. - - mp_hal_pin_output(CYW43_PIN_BT_REG_ON); - mp_hal_pin_low(CYW43_PIN_BT_REG_ON); - #ifdef CYW43_PIN_BT_HOST_WAKE - mp_hal_pin_input(CYW43_PIN_BT_HOST_WAKE); - #endif - #ifdef CYW43_PIN_BT_DEV_WAKE - mp_hal_pin_output(CYW43_PIN_BT_DEV_WAKE); - mp_hal_pin_low(CYW43_PIN_BT_DEV_WAKE); - #endif - - #if MICROPY_HW_ENABLE_RF_SWITCH - // TODO don't select antenna if wifi is enabled - mp_hal_pin_config(CYW43_PIN_WL_GPIO_4, MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_NONE, 0); // RF-switch power - mp_hal_pin_high(CYW43_PIN_WL_GPIO_4); // Turn the RF-switch on - #endif - - uint8_t buf[256]; - - mp_hal_pin_low(CYW43_PIN_BT_REG_ON); - mp_bluetooth_hci_uart_set_baudrate(115200); - mp_hal_delay_ms(100); - mp_hal_pin_high(CYW43_PIN_BT_REG_ON); - #ifdef CYW43_PIN_BT_CTS - cywbt_wait_cts_low(); - #else - mp_hal_delay_ms(100); - #endif - - // Reset - cywbt_hci_cmd(0x03, 0x0003, 0, NULL); - - #ifdef MICROPY_HW_BLE_UART_BAUDRATE_DOWNLOAD_FIRMWARE - // Change baudrate - cywbt_set_baudrate(MICROPY_HW_BLE_UART_BAUDRATE_DOWNLOAD_FIRMWARE); - mp_bluetooth_hci_uart_set_baudrate(MICROPY_HW_BLE_UART_BAUDRATE_DOWNLOAD_FIRMWARE); - #endif - - cywbt_download_firmware((const uint8_t *)&cyw43_btfw_4343A1[0]); - - // Reset - cywbt_hci_cmd(0x03, 0x0003, 0, NULL); - - // Set BD_ADDR (sent as little endian) - uint8_t bdaddr[6]; - mp_hal_get_mac(MP_HAL_MAC_BDADDR, bdaddr); - buf[0] = bdaddr[5]; - buf[1] = bdaddr[4]; - buf[2] = bdaddr[3]; - buf[3] = bdaddr[2]; - buf[4] = bdaddr[1]; - buf[5] = bdaddr[0]; - cywbt_hci_cmd(0x3f, 0x0001, 6, buf); - - // Set local name - // memset(buf, 0, 248); - // memcpy(buf, "PYBD-BLE", 8); - // cywbt_hci_cmd(0x03, 0x0013, 248, buf); - - // Configure sleep mode - cywbt_hci_cmd(0x3f, 0x27, 12, (const uint8_t *)"\x01\x02\x02\x00\x00\x00\x01\x00\x00\x00\x00\x00"); - - // HCI_Write_LE_Host_Support - cywbt_hci_cmd(3, 109, 2, (const uint8_t *)"\x01\x00"); - - #ifdef CYW43_PIN_BT_DEV_WAKE - mp_hal_pin_high(CYW43_PIN_BT_DEV_WAKE); // let sleep - #endif - - return 0; -} - -int mp_bluetooth_hci_controller_deinit(void) { - mp_hal_pin_low(CYW43_PIN_BT_REG_ON); - - return 0; -} - -#ifdef CYW43_PIN_BT_DEV_WAKE -static uint32_t bt_sleep_ticks; -#endif - -int mp_bluetooth_hci_controller_sleep_maybe(void) { - #ifdef CYW43_PIN_BT_DEV_WAKE - if (mp_hal_pin_read(CYW43_PIN_BT_DEV_WAKE) == 0) { - if (mp_hal_ticks_ms() - bt_sleep_ticks > 500) { - mp_hal_pin_high(CYW43_PIN_BT_DEV_WAKE); // let sleep - } - } - #endif - return 0; -} - -bool mp_bluetooth_hci_controller_woken(void) { - #ifdef CYW43_PIN_BT_HOST_WAKE - bool host_wake = mp_hal_pin_read(CYW43_PIN_BT_HOST_WAKE); - /* - // this is just for info/tracing purposes - static bool last_host_wake = false; - if (host_wake != last_host_wake) { - printf("HOST_WAKE change %d -> %d\n", last_host_wake, host_wake); - last_host_wake = host_wake; - } - */ - return host_wake; - #else - return true; - #endif -} - -int mp_bluetooth_hci_controller_wakeup(void) { - #ifdef CYW43_PIN_BT_DEV_WAKE - bt_sleep_ticks = mp_hal_ticks_ms(); - - if (mp_hal_pin_read(CYW43_PIN_BT_DEV_WAKE) == 1) { - mp_hal_pin_low(CYW43_PIN_BT_DEV_WAKE); // wake up - // Use delay_us rather than delay_ms to prevent running the scheduler (which - // might result in more BLE operations). - mp_hal_delay_us(5000); // can't go lower than this - } - #endif - - return 0; -} - -#endif pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy