|
| 1 | +#include <rtthread.h> |
| 2 | +#include <rtdbg.h> |
| 3 | +#ifdef BSP_USING_RW007 |
| 4 | +#include <rtdevice.h> |
| 5 | +#include <drv_spi.h> |
| 6 | +#include <board.h> |
| 7 | +#include <spi_wifi_rw007.h> |
| 8 | + |
| 9 | +extern void spi_wifi_isr(int vector); |
| 10 | + |
| 11 | +static void rw007_gpio_init(void) |
| 12 | +{ |
| 13 | + /* Configure IO */ |
| 14 | + rt_pin_mode(RA_RW007_RST_PIN, PIN_MODE_OUTPUT); |
| 15 | + rt_pin_mode(RA_RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLDOWN); |
| 16 | + |
| 17 | + /* Reset rw007 and config mode */ |
| 18 | + rt_pin_write(RA_RW007_RST_PIN, PIN_LOW); |
| 19 | + rt_thread_delay(rt_tick_from_millisecond(100)); |
| 20 | + rt_pin_write(RA_RW007_RST_PIN, PIN_HIGH); |
| 21 | + |
| 22 | + /* Wait rw007 ready(exit busy stat) */ |
| 23 | + while (!rt_pin_read(RA_RW007_INT_BUSY_PIN)) |
| 24 | + { |
| 25 | + rt_thread_delay(5); |
| 26 | + } |
| 27 | + |
| 28 | + rt_thread_delay(rt_tick_from_millisecond(200)); |
| 29 | + rt_pin_mode(RA_RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLUP); |
| 30 | +} |
| 31 | + |
| 32 | +int wifi_spi_device_init(void) |
| 33 | +{ |
| 34 | + char sn_version[32]; |
| 35 | + uint32_t cs_pin = RA_RW007_CS_PIN; |
| 36 | + |
| 37 | + rw007_gpio_init(); |
| 38 | + rt_hw_spi_device_attach(RA_RW007_SPI_BUS_NAME, "wspi", cs_pin); |
| 39 | + rt_hw_wifi_init("wspi"); |
| 40 | + |
| 41 | + rt_wlan_set_mode(RT_WLAN_DEVICE_STA_NAME, RT_WLAN_STATION); |
| 42 | + rt_wlan_set_mode(RT_WLAN_DEVICE_AP_NAME, RT_WLAN_AP); |
| 43 | + |
| 44 | + rw007_sn_get(sn_version); |
| 45 | + rt_kprintf("\nrw007 sn: [%s]\n", sn_version); |
| 46 | + rw007_version_get(sn_version); |
| 47 | + rt_kprintf("rw007 ver: [%s]\n\n", sn_version); |
| 48 | + |
| 49 | + return 0; |
| 50 | +} |
| 51 | +INIT_APP_EXPORT(wifi_spi_device_init); |
| 52 | + |
| 53 | +static void int_wifi_irq(void *p) |
| 54 | +{ |
| 55 | + ((void)p); |
| 56 | + spi_wifi_isr(0); |
| 57 | +} |
| 58 | + |
| 59 | +void spi_wifi_hw_init(void) |
| 60 | +{ |
| 61 | + rt_pin_attach_irq(RA_RW007_INT_BUSY_PIN, PIN_IRQ_MODE_FALLING, int_wifi_irq, 0); |
| 62 | + rt_pin_irq_enable(RA_RW007_INT_BUSY_PIN, RT_TRUE); |
| 63 | +} |
| 64 | + |
| 65 | +#endif /* BSP_USING_RW007 */ |
0 commit comments