From 3745c393c82050a64445dbdf4c34836fa8664ce0 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 14 Sep 2021 22:22:17 +0200 Subject: [PATCH] rp2: Add support for Nina-W10 WiFi/BT module. This commit integrates the Nina-W10 driver as an optional component in the rp2 port. --- ports/rp2/CMakeLists.txt | 26 ++++++++++++++++++++++++++ ports/rp2/mpconfigport.h | 20 ++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index e38cd8032d..0b433da53c 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -166,6 +166,7 @@ if(MICROPY_PY_BLUETOOTH) list(APPEND MICROPY_SOURCE_PORT mpbthciport.c) target_compile_definitions(${MICROPY_TARGET} PRIVATE MICROPY_PY_BLUETOOTH=1 + MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS=1 MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE=1 MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING=1 MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS=1 @@ -188,6 +189,31 @@ if(MICROPY_BLUETOOTH_NIMBLE) list(APPEND MICROPY_INC_CORE ${NIMBLE_INCLUDE}) endif() +if (MICROPY_PY_NETWORK_NINAW10) + target_compile_definitions(${MICROPY_TARGET} PRIVATE + MICROPY_PY_NETWORK_NINAW10=1 + ) + + target_include_directories(${MICROPY_TARGET} PRIVATE + ${MICROPY_DIR}/drivers/ninaw10/ + ) + + # Enable NINA-W10 WiFi and Bluetooth drivers. + list(APPEND MICROPY_SOURCE_DRIVERS + ${MICROPY_DIR}/drivers/ninaw10/nina_bt_hci.c + ${MICROPY_DIR}/drivers/ninaw10/nina_wifi_drv.c + ${MICROPY_DIR}/drivers/ninaw10/nina_wifi_bsp.c + ) + + list(APPEND MICROPY_SOURCE_EXTMOD + ${MICROPY_DIR}/extmod/network_ninaw10.c + ) + + list(APPEND MICROPY_SOURCE_QSTR + ${MICROPY_DIR}/extmod/network_ninaw10.c + ) +endif() + # Define mpy-cross flags and frozen manifest set(MICROPY_CROSS_FLAGS -march=armv7m) if (NOT MICROPY_FROZEN_MANIFEST) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index b40e18d2f8..2e8a33a7a7 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -154,6 +154,20 @@ struct _mp_bluetooth_nimble_malloc_t; #define MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE #endif +#if MICROPY_PY_NETWORK_NINAW10 +// This Network interface requires the extended socket state. +#ifndef MICROPY_PY_USOCKET_EXTENDED_STATE +#define MICROPY_PY_USOCKET_EXTENDED_STATE (1) +#endif +// It also requires an additional root pointer for the SPI object. +#define MICROPY_PORT_ROOT_POINTER_NINAW10 struct _machine_spi_obj_t *mp_wifi_spi; +extern const struct _mod_network_nic_type_t mod_network_nic_type_nina; +#define MICROPY_HW_NIC_NINAW10 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) }, +#else +#define MICROPY_HW_NIC_NINAW10 +#define MICROPY_PORT_ROOT_POINTER_NINAW10 +#endif + #define MICROPY_PORT_BUILTIN_MODULES \ { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \ { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \ @@ -163,12 +177,13 @@ struct _mp_bluetooth_nimble_malloc_t; SOCKET_BUILTIN_MODULE \ NETWORK_BUILTIN_MODULE \ +#define MICROPY_PORT_NETWORK_INTERFACES \ + MICROPY_HW_NIC_NINAW10 \ + #ifndef MICROPY_BOARD_ROOT_POINTERS #define MICROPY_BOARD_ROOT_POINTERS #endif -#define MICROPY_PORT_NETWORK_INTERFACES \ - #define MICROPY_PORT_ROOT_POINTERS \ const char *readline_hist[8]; \ void *machine_pin_irq_obj[30]; \ @@ -179,6 +194,7 @@ struct _mp_bluetooth_nimble_malloc_t; void *machine_i2s_obj[2]; \ NETWORK_ROOT_POINTERS \ MICROPY_BOARD_ROOT_POINTERS \ + MICROPY_PORT_ROOT_POINTER_NINAW10 \ MICROPY_PORT_ROOT_POINTER_BLUETOOTH \ MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE \