/* * Copyright (c) 2022-2023 HPMicro * * SPDX-License-Identifier: BSD-3-Clause * */ #include #if defined(RT_USING_WIFI) && defined(BSP_USING_SPI1) #include #include #include #include #define RW007_AT_MODE 3 #define RW007_SPI_MODE 1 extern void spi_wifi_isr(int vector); static void rw007_spi_cs_control(uint32_t value) { uint32_t gpio_index = RW007_CS_PIN / 32U; uint32_t pin_index = RW007_CS_PIN % 32U; if (value != 0) { RW007_CS_GPIO->DO[gpio_index].SET = (1UL << pin_index); } else { RW007_CS_GPIO->DO[gpio_index].CLEAR = (1UL << pin_index); } } static void rw007_spi_cs_init(void) { HPM_IOC->PAD[RW007_CS_PIN].FUNC_CTL = 0; HPM_IOC->PAD[RW007_CS_PIN].PAD_CTL = IOC_PAD_PAD_CTL_DS_SET(7) | IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1); uint32_t gpio_index = RW007_CS_PIN / 32U; uint32_t pin_index = RW007_CS_PIN % 32U; RW007_CS_GPIO->DO[gpio_index].SET = (1UL << pin_index); RW007_CS_GPIO->OE[gpio_index].SET = (1UL <user_data; set_rw007_mode(RW007_AT_MODE); return 0; } MSH_CMD_EXPORT(rw007_update, rw007_update); static void int_wifi_irq(void * p) { ((void)p); spi_wifi_isr(0); } void spi_wifi_hw_init(void) { rt_pin_attach_irq(RW007_INT_BUSY_PIN, PIN_IRQ_MODE_FALLING, int_wifi_irq, 0); rt_pin_irq_enable(RW007_INT_BUSY_PIN, RT_TRUE); } rt_bool_t spi_wifi_is_busy(void) { return !rt_pin_read(RW007_INT_BUSY_PIN); } void spi_wifi_int_cmd(rt_bool_t cmd) { rt_pin_irq_enable(RW007_INT_BUSY_PIN, cmd); } #endif /* if defined(RT_USING_WIFI) && defined(BSP_USING_SPI1) */