1 /**
2 * Copyright (c) 2017 IpTronix
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #define DT_DRV_COMPAT atmel_winc1500
8
9 #include "wifi_winc1500_nm_bsp_internal.h"
10
11 #include <bsp/include/nm_bsp.h>
12 #include <common/include/nm_common.h>
13
14 #include "wifi_winc1500_config.h"
15
16 const struct winc1500_cfg winc1500_config = {
17 .spi = SPI_DT_SPEC_INST_GET(0, SPI_WORD_SET(8) | SPI_TRANSFER_MSB, 0),
18 .chip_en_gpio = GPIO_DT_SPEC_INST_GET(0, enable_gpios),
19 .irq_gpio = GPIO_DT_SPEC_INST_GET(0, irq_gpios),
20 .reset_gpio = GPIO_DT_SPEC_INST_GET(0, reset_gpios),
21 };
22
23 struct winc1500_device winc1500;
24
25 void (*isr_function)(void);
26
chip_isr(const struct device * port,struct gpio_callback * cb,gpio_port_pins_t pins)27 static inline void chip_isr(const struct device *port,
28 struct gpio_callback *cb,
29 gpio_port_pins_t pins)
30 {
31 if (isr_function) {
32 isr_function();
33 }
34 }
35
nm_bsp_init(void)36 int8_t nm_bsp_init(void)
37 {
38 isr_function = NULL;
39
40 /* Perform chip reset. */
41 nm_bsp_reset();
42
43 return 0;
44 }
45
nm_bsp_deinit(void)46 int8_t nm_bsp_deinit(void)
47 {
48 /* TODO */
49 return 0;
50 }
51
nm_bsp_reset(void)52 void nm_bsp_reset(void)
53 {
54 gpio_pin_set_dt(&winc1500_config.chip_en_gpio, 0);
55 gpio_pin_set_dt(&winc1500_config.reset_gpio, 0);
56 nm_bsp_sleep(100);
57
58 gpio_pin_set_dt(&winc1500_config.chip_en_gpio, 1);
59 nm_bsp_sleep(10);
60
61 gpio_pin_set_dt(&winc1500_config.reset_gpio, 1);
62 nm_bsp_sleep(10);
63 }
64
nm_bsp_sleep(uint32 u32TimeMsec)65 void nm_bsp_sleep(uint32 u32TimeMsec)
66 {
67 k_busy_wait(u32TimeMsec * MSEC_PER_SEC);
68 }
69
nm_bsp_register_isr(void (* isr_fun)(void))70 void nm_bsp_register_isr(void (*isr_fun)(void))
71 {
72 isr_function = isr_fun;
73
74 gpio_init_callback(&winc1500.gpio_cb,
75 chip_isr,
76 BIT(winc1500_config.irq_gpio.pin));
77
78 gpio_add_callback(winc1500_config.irq_gpio.port, &winc1500.gpio_cb);
79 }
80
nm_bsp_interrupt_ctrl(uint8_t enable)81 void nm_bsp_interrupt_ctrl(uint8_t enable)
82 {
83 gpio_pin_interrupt_configure_dt(&winc1500_config.irq_gpio,
84 enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE);
85 }
86