Skip to content

Commit

Permalink
drivers/wifi: Switch WINC1500 to new GPIO API
Browse files Browse the repository at this point in the history
Fixes zephyrproject-rtos#20017

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
  • Loading branch information
Tomasz Bursztyka authored and pabigot committed Jan 29, 2020
1 parent ac84dc3 commit 7762175
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 89 deletions.
31 changes: 13 additions & 18 deletions drivers/wifi/winc1500/wifi_winc1500_nm_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void (*isr_function)(void);

static inline void chip_isr(struct device *port,
struct gpio_callback *cb,
uint32_t pins)
gpio_port_pins_t pins)
{
if (isr_function) {
isr_function();
Expand All @@ -42,18 +42,18 @@ s8_t nm_bsp_deinit(void)

void nm_bsp_reset(void)
{
gpio_pin_write(winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].dev,
winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].pin, 0);
gpio_pin_write(winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].dev,
winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].pin, 0);
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);
nm_bsp_sleep(100);

gpio_pin_write(winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].dev,
winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].pin, 1);
gpio_pin_set_raw(winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].dev,
winc1500.gpios[WINC1500_GPIO_IDX_CHIP_EN].pin, 1);
nm_bsp_sleep(10);

gpio_pin_write(winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].dev,
winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].pin, 1);
gpio_pin_set_raw(winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].dev,
winc1500.gpios[WINC1500_GPIO_IDX_RESET_N].pin, 1);
nm_bsp_sleep(10);
}

Expand All @@ -76,13 +76,8 @@ void nm_bsp_register_isr(void (*isr_fun)(void))

void nm_bsp_interrupt_ctrl(u8_t enable)
{
if (enable) {
gpio_pin_enable_callback(
winc1500.gpios[WINC1500_GPIO_IDX_IRQN].dev,
winc1500.gpios[WINC1500_GPIO_IDX_IRQN].pin);
} else {
gpio_pin_disable_callback(
winc1500.gpios[WINC1500_GPIO_IDX_IRQN].dev,
winc1500.gpios[WINC1500_GPIO_IDX_IRQN].pin);
}
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);
}
13 changes: 13 additions & 0 deletions drivers/wifi/winc1500/wifi_winc1500_nm_bsp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ extern tstrNmBusCapabilities egstrNmBusCapabilities;
#define NM_DEBUG CONF_WINC_DEBUG
#define NM_BSP_PRINTF CONF_WINC_PRINTF

enum winc1500_gpio_index {
WINC1500_GPIO_IDX_CHIP_EN = 0,
WINC1500_GPIO_IDX_IRQN,
WINC1500_GPIO_IDX_RESET_N,

WINC1500_GPIO_IDX_MAX
};

struct winc1500_gpio_configuration {
struct device *dev;
u32_t pin;
};

struct winc1500_device {
struct winc1500_gpio_configuration *gpios;
struct gpio_callback gpio_cb;
Expand Down
38 changes: 38 additions & 0 deletions drivers/wifi/winc1500/wifi_winc1500_nm_bus_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ LOG_MODULE_REGISTER(winc1500);

#include "wifi_winc1500_config.h"

static
struct winc1500_gpio_configuration winc1500_gpios[WINC1500_GPIO_IDX_MAX] = {
{ .dev = NULL, .pin = DT_INST_0_ATMEL_WINC1500_ENABLE_GPIOS_PIN },
{ .dev = NULL, .pin = DT_INST_0_ATMEL_WINC1500_IRQ_GPIOS_PIN },
{ .dev = NULL, .pin = DT_INST_0_ATMEL_WINC1500_RESET_GPIOS_PIN },
};

#define NM_BUS_MAX_TRX_SZ 256

tstrNmBusCapabilities egstrNmBusCapabilities = {
Expand Down Expand Up @@ -87,6 +94,37 @@ static s8_t spi_rw(u8_t *mosi, u8_t *miso, u16_t size)

#endif

struct winc1500_gpio_configuration *winc1500_configure_gpios(void)
{
struct device *gpio_en, *gpio_irq, *gpio_reset;

gpio_en = device_get_binding(
DT_INST_0_ATMEL_WINC1500_ENABLE_GPIOS_CONTROLLER);
gpio_irq = device_get_binding(
DT_INST_0_ATMEL_WINC1500_IRQ_GPIOS_CONTROLLER);
gpio_reset = device_get_binding(
DT_INST_0_ATMEL_WINC1500_RESET_GPIOS_CONTROLLER);

gpio_pin_configure(gpio_en,
winc1500_gpios[WINC1500_GPIO_IDX_CHIP_EN].pin,
GPIO_OUTPUT |
DT_INST_0_ATMEL_WINC1500_ENABLE_GPIOS_FLAGS);
gpio_pin_configure(gpio_irq,
winc1500_gpios[WINC1500_GPIO_IDX_IRQN].pin,
GPIO_INPUT |
DT_INST_0_ATMEL_WINC1500_IRQ_GPIOS_FLAGS);
gpio_pin_configure(gpio_reset,
winc1500_gpios[WINC1500_GPIO_IDX_RESET_N].pin,
GPIO_OUTPUT |
DT_INST_0_ATMEL_WINC1500_RESET_GPIOS_FLAGS);

winc1500_gpios[WINC1500_GPIO_IDX_CHIP_EN].dev = gpio_en;
winc1500_gpios[WINC1500_GPIO_IDX_IRQN].dev = gpio_irq;
winc1500_gpios[WINC1500_GPIO_IDX_RESET_N].dev = gpio_reset;

return winc1500_gpios;
}

s8_t nm_bus_init(void *pvinit)
{
/* configure GPIOs */
Expand Down
27 changes: 0 additions & 27 deletions include/drivers/wifi/winc1500.h

This file was deleted.

44 changes: 0 additions & 44 deletions samples/net/wifi/src/wifi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,6 @@
#include <zephyr.h>
#include <errno.h>

#ifdef CONFIG_WIFI_WINC1500

#include <device.h>
#include <drivers/gpio.h>
#include <drivers/wifi/winc1500.h>

static
struct winc1500_gpio_configuration winc1500_gpios[WINC1500_GPIO_IDX_MAX] = {
{ .dev = NULL, .pin = DT_INST_0_ATMEL_WINC1500_ENABLE_GPIOS_PIN },
{ .dev = NULL, .pin = DT_INST_0_ATMEL_WINC1500_IRQ_GPIOS_PIN },
{ .dev = NULL, .pin = DT_INST_0_ATMEL_WINC1500_RESET_GPIOS_PIN },
};

struct winc1500_gpio_configuration *winc1500_configure_gpios(void)
{
const int flags_int_in = (GPIO_DIR_IN | GPIO_INT |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE |
GPIO_INT_EDGE);
const int flags_noint_out = GPIO_DIR_OUT;
struct device *gpio_en, *gpio_irq, *gpio_reset;

gpio_en = device_get_binding(DT_INST_0_ATMEL_WINC1500_ENABLE_GPIOS_CONTROLLER);
gpio_irq = device_get_binding(DT_INST_0_ATMEL_WINC1500_IRQ_GPIOS_CONTROLLER);
gpio_reset = device_get_binding(DT_INST_0_ATMEL_WINC1500_RESET_GPIOS_CONTROLLER);

gpio_pin_configure(gpio_en,
winc1500_gpios[WINC1500_GPIO_IDX_CHIP_EN].pin,
flags_noint_out);
gpio_pin_configure(gpio_irq,
winc1500_gpios[WINC1500_GPIO_IDX_IRQN].pin,
flags_int_in);
gpio_pin_configure(gpio_reset,
winc1500_gpios[WINC1500_GPIO_IDX_RESET_N].pin,
flags_noint_out);

winc1500_gpios[WINC1500_GPIO_IDX_CHIP_EN].dev = gpio_en;
winc1500_gpios[WINC1500_GPIO_IDX_IRQN].dev = gpio_irq;
winc1500_gpios[WINC1500_GPIO_IDX_RESET_N].dev = gpio_reset;

return winc1500_gpios;
}

#endif /* CONFIG_WIFI_WINC1500 */

void main(void)
{

Expand Down

0 comments on commit 7762175

Please sign in to comment.