2017-05-03 15:09:29 +08:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2017 IpTronix
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wifi_winc1500_nm_bsp_internal.h"
|
|
|
|
|
|
|
|
#include <bsp/include/nm_bsp.h>
|
|
|
|
#include <common/include/nm_common.h>
|
|
|
|
|
|
|
|
#include "wifi_winc1500_config.h"
|
|
|
|
|
|
|
|
struct winc1500_device winc1500;
|
|
|
|
|
|
|
|
void (*isr_function)(void);
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static inline void chip_isr(const struct device *port,
|
2017-05-03 15:09:29 +08:00
|
|
|
struct gpio_callback *cb,
|
2020-01-24 16:24:59 +08:00
|
|
|
gpio_port_pins_t pins)
|
2017-05-03 15:09:29 +08:00
|
|
|
{
|
|
|
|
if (isr_function) {
|
|
|
|
isr_function();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
int8_t nm_bsp_init(void)
|
2017-05-03 15:09:29 +08:00
|
|
|
{
|
|
|
|
isr_function = NULL;
|
|
|
|
|
|
|
|
/* Perform chip reset. */
|
|
|
|
nm_bsp_reset();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
int8_t nm_bsp_deinit(void)
|
2017-05-03 15:09:29 +08:00
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nm_bsp_reset(void)
|
|
|
|
{
|
2020-01-24 16:24:59 +08:00
|
|
|
gpio_pin_set_raw(winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].dev,
|
|
|
|
winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].pin, 0);
|
|
|
|
gpio_pin_set_raw(winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].dev,
|
|
|
|
winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].pin, 0);
|
2017-05-03 15:09:29 +08:00
|
|
|
nm_bsp_sleep(100);
|
|
|
|
|
2020-01-24 16:24:59 +08:00
|
|
|
gpio_pin_set_raw(winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].dev,
|
|
|
|
winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].pin, 1);
|
2017-05-03 15:09:29 +08:00
|
|
|
nm_bsp_sleep(10);
|
|
|
|
|
2020-01-24 16:24:59 +08:00
|
|
|
gpio_pin_set_raw(winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].dev,
|
|
|
|
winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].pin, 1);
|
2017-05-03 15:09:29 +08:00
|
|
|
nm_bsp_sleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nm_bsp_sleep(uint32 u32TimeMsec)
|
|
|
|
{
|
|
|
|
k_busy_wait(u32TimeMsec * MSEC_PER_SEC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nm_bsp_register_isr(void (*isr_fun)(void))
|
|
|
|
{
|
|
|
|
isr_function = isr_fun;
|
|
|
|
|
|
|
|
gpio_init_callback(&winc1500.gpio_cb,
|
|
|
|
chip_isr,
|
2017-11-02 19:07:25 +08:00
|
|
|
BIT(winc1500.gpios[WINC1500_GPIO_IDX_IRQN].pin));
|
2017-05-03 15:09:29 +08:00
|
|
|
|
2017-11-02 19:07:25 +08:00
|
|
|
gpio_add_callback(winc1500.gpios[WINC1500_GPIO_IDX_IRQN].dev,
|
2017-05-03 15:09:29 +08:00
|
|
|
&winc1500.gpio_cb);
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
void nm_bsp_interrupt_ctrl(uint8_t enable)
|
2017-05-03 15:09:29 +08:00
|
|
|
{
|
2020-01-24 16:24:59 +08:00
|
|
|
gpio_pin_interrupt_configure(
|
|
|
|
winc1500.gpios[WINC1500_GPIO_IDX_IRQN].dev,
|
|
|
|
winc1500.gpios[WINC1500_GPIO_IDX_IRQN].pin,
|
|
|
|
enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE);
|
2017-05-03 15:09:29 +08:00
|
|
|
}
|