|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2022 Damien P. George |
| 7 | + * Copyright (c) 2022 Jim Mussared |
| 8 | + * |
| 9 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | + * of this software and associated documentation files (the "Software"), to deal |
| 11 | + * in the Software without restriction, including without limitation the rights |
| 12 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | + * copies of the Software, and to permit persons to whom the Software is |
| 14 | + * furnished to do so, subject to the following conditions: |
| 15 | + * |
| 16 | + * The above copyright notice and this permission notice shall be included in |
| 17 | + * all copies or substantial portions of the Software. |
| 18 | + * |
| 19 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | + * THE SOFTWARE. |
| 26 | + */ |
| 27 | +#ifndef MICROPY_INCLUDED_STM32_CYW43_CONFIGPORT_H |
| 28 | +#define MICROPY_INCLUDED_STM32_CYW43_CONFIGPORT_H |
| 29 | + |
| 30 | +// The board-level config will be included here, so it can set some CYW43 values. |
| 31 | +#include "py/mpconfig.h" |
| 32 | +#include "py/mperrno.h" |
| 33 | +#include "py/mphal.h" |
| 34 | +#include "extmod/modnetwork.h" |
| 35 | +#include "pendsv.h" |
| 36 | +#include "sdio.h" |
| 37 | + |
| 38 | +#define CYW43_USE_SPI (0) |
| 39 | +#define CYW43_LWIP (1) |
| 40 | +#define CYW43_USE_STATS (0) |
| 41 | + |
| 42 | +#ifndef CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE |
| 43 | +#define CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE "lib/cyw43-driver/firmware/w4343WA1_7_45_98_50_combined.h" |
| 44 | +#endif |
| 45 | + |
| 46 | +#ifndef CYW43_WIFI_NVRAM_INCLUDE_FILE |
| 47 | +#define CYW43_WIFI_NVRAM_INCLUDE_FILE "lib/cyw43-driver/firmware/wifi_nvram_1dx.h" |
| 48 | +#endif |
| 49 | + |
| 50 | +#define CYW43_IOCTL_TIMEOUT_US (1000000) |
| 51 | +#define CYW43_SLEEP_MAX (50) |
| 52 | +#define CYW43_NETUTILS (1) |
| 53 | +#define CYW43_CLEAR_SDIO_INT (1) |
| 54 | + |
| 55 | +#define CYW43_EPERM MP_EPERM // Operation not permitted |
| 56 | +#define CYW43_EIO MP_EIO // I/O error |
| 57 | +#define CYW43_EINVAL MP_EINVAL // Invalid argument |
| 58 | +#define CYW43_ETIMEDOUT MP_ETIMEDOUT // Connection timed out |
| 59 | + |
| 60 | +#define CYW43_THREAD_ENTER MICROPY_PY_LWIP_ENTER |
| 61 | +#define CYW43_THREAD_EXIT MICROPY_PY_LWIP_EXIT |
| 62 | +#define CYW43_THREAD_LOCK_CHECK |
| 63 | + |
| 64 | +#define CYW43_HOST_NAME mod_network_hostname |
| 65 | + |
| 66 | +#define CYW43_SDPCM_SEND_COMMON_WAIT __WFI(); |
| 67 | +#define CYW43_DO_IOCTL_WAIT __WFI(); |
| 68 | + |
| 69 | +#define CYW43_ARRAY_SIZE(a) MP_ARRAY_SIZE(a) |
| 70 | + |
| 71 | +#define CYW43_HAL_PIN_MODE_INPUT MP_HAL_PIN_MODE_INPUT |
| 72 | +#define CYW43_HAL_PIN_MODE_OUTPUT MP_HAL_PIN_MODE_OUTPUT |
| 73 | +#define CYW43_HAL_PIN_PULL_NONE MP_HAL_PIN_PULL_NONE |
| 74 | +#define CYW43_HAL_PIN_PULL_UP MP_HAL_PIN_PULL_UP |
| 75 | +#define CYW43_HAL_PIN_PULL_DOWN MP_HAL_PIN_PULL_DOWN |
| 76 | + |
| 77 | +#define CYW43_HAL_MAC_WLAN0 MP_HAL_MAC_WLAN0 |
| 78 | + |
| 79 | +#define cyw43_hal_ticks_us mp_hal_ticks_us |
| 80 | +#define cyw43_hal_ticks_ms mp_hal_ticks_ms |
| 81 | + |
| 82 | +#define cyw43_hal_pin_obj_t mp_hal_pin_obj_t |
| 83 | +#define cyw43_hal_pin_read mp_hal_pin_read |
| 84 | +#define cyw43_hal_pin_low mp_hal_pin_low |
| 85 | +#define cyw43_hal_pin_high mp_hal_pin_high |
| 86 | + |
| 87 | +#define cyw43_hal_get_mac mp_hal_get_mac |
| 88 | +#define cyw43_hal_get_mac_ascii mp_hal_get_mac_ascii |
| 89 | +#define cyw43_hal_generate_laa_mac mp_hal_generate_laa_mac |
| 90 | + |
| 91 | +#define cyw43_delay_us mp_hal_delay_us |
| 92 | +#define cyw43_delay_ms mp_hal_delay_ms |
| 93 | + |
| 94 | +#define CYW43_PIN_WL_REG_ON MICROPY_HW_WL_REG_ON |
| 95 | +#define CYW43_PIN_WL_HOST_WAKE MICROPY_HW_WL_HOST_WAKE |
| 96 | +#define CYW43_PIN_WL_SDIO_1 MICROPY_HW_SDIO_D1 |
| 97 | + |
| 98 | +#define CYW43_PIN_BT_REG_ON MICROPY_HW_BT_REG_ON |
| 99 | +#ifdef MICROPY_HW_BT_HOST_WAKE |
| 100 | +#define CYW43_PIN_BT_HOST_WAKE MICROPY_HW_BT_HOST_WAKE |
| 101 | +#endif |
| 102 | +#ifdef MICROPY_HW_BT_DEV_WAKE |
| 103 | +#define CYW43_PIN_BT_DEV_WAKE MICROPY_HW_BT_DEV_WAKE |
| 104 | +#endif |
| 105 | +#ifdef MICROPY_HW_BT_CTS |
| 106 | +#define CYW43_PIN_BT_CTS MICROPY_HW_BT_CTS |
| 107 | +#endif |
| 108 | + |
| 109 | +#if MICROPY_HW_ENABLE_RF_SWITCH |
| 110 | +#define CYW43_PIN_WL_RFSW_VDD pin_WL_RFSW_VDD |
| 111 | +#endif |
| 112 | + |
| 113 | +#define cyw43_schedule_internal_poll_dispatch(func) pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, func) |
| 114 | + |
| 115 | +static inline void cyw43_hal_pin_config(cyw43_hal_pin_obj_t pin, uint8_t mode, uint8_t pull, uint8_t alt) { |
| 116 | + machine_pin_set_mode(pin, mode); |
| 117 | +} |
| 118 | + |
| 119 | +static inline void cyw43_hal_pin_config_irq_falling(cyw43_hal_pin_obj_t pin, int enable) { |
| 120 | + if (enable) { |
| 121 | + machine_pin_config(pin, PIN_MODE_IT_FALLING, PIN_PULL_UP_100K, 0, 0, PIN_AF_MODE_ALT5); |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +static inline void cyw43_sdio_init(void) { |
| 126 | + sdio_init(NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 14, 0)); |
| 127 | +} |
| 128 | + |
| 129 | +static inline void cyw43_sdio_reinit(void) { |
| 130 | + sdio_reenable(); |
| 131 | +} |
| 132 | + |
| 133 | +static inline void cyw43_sdio_deinit(void) { |
| 134 | + sdio_deinit(); |
| 135 | +} |
| 136 | + |
| 137 | +static inline void cyw43_sdio_set_irq(bool enable) { |
| 138 | + sdio_enable_irq(enable); |
| 139 | +} |
| 140 | + |
| 141 | +static inline void cyw43_sdio_enable_high_speed_4bit(void) { |
| 142 | + sdio_enable_high_speed_4bit(); |
| 143 | +} |
| 144 | + |
| 145 | +static inline int cyw43_sdio_transfer(uint32_t cmd, uint32_t arg, uint32_t *resp) { |
| 146 | + return sdio_transfer(cmd, arg, resp); |
| 147 | +} |
| 148 | + |
| 149 | +static inline int cyw43_sdio_transfer_cmd53(bool write, uint32_t block_size, uint32_t arg, size_t len, uint8_t *buf) { |
| 150 | + return sdio_transfer_cmd53(write, block_size, arg, len, buf); |
| 151 | +} |
| 152 | + |
| 153 | +#define CYW43_EVENT_POLL_HOOK MICROPY_EVENT_POLL_HOOK |
| 154 | + |
| 155 | +#endif // MICROPY_INCLUDED_STM32_CYW43_CONFIGPORT_H |
0 commit comments