Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: add ATWINC15x0 WiFi netdev driver #13754

Merged
merged 9 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boards/arduino-mkr1000/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
USEMODULE += boards_common_arduino-mkr

ifneq (,$(filter gnrc_netdev_default,$(USEMODULE)))
USEMODULE += atwinc15x0
endif

include $(RIOTBOARD)/common/arduino-mkr/Makefile.dep
12 changes: 12 additions & 0 deletions boards/arduino-mkr1000/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ extern "C" {
#define LED0_NAME "LED(Green)"
/** @} */

/**
* @name Board configuration for ATWINC15x0 WiFi netdev driver
* @{
*/
#define ATWINC15X0_PARAM_SPI SPI_DEV(1)
#define ATWINC15X0_PARAM_SSN_PIN GPIO_PIN(0, 14)
#define ATWINC15X0_PARAM_RESET_PIN GPIO_PIN(0, 27)
#define ATWINC15X0_PARAM_CHIP_EN_PIN GPIO_PIN(0, 28)
#define ATWINC15X0_PARAM_WAKE_PIN GPIO_PIN(1, 8)
#define ATWINC15X0_PARAM_IRQ_PIN GPIO_PIN(1, 9)
/** @} */

aabadie marked this conversation as resolved.
Show resolved Hide resolved
#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions boards/feather-m0/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif

ifneq (,$(filter feather-m0-wifi,$(USEMODULE)))
ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE)))
USEMODULE += atwinc15x0
endif
endif

# use arduino-bootloader only if no other stdio_% other than stdio_cdc_acm
# is requested
ifeq (,$(filter-out stdio_cdc_acm,$(filter stdio_% slipdev_stdio,$(USEMODULE))))
Expand Down
2 changes: 2 additions & 0 deletions boards/feather-m0/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PSEUDOMODULES += feather-m0-wifi

PORT_LINUX ?= /dev/ttyACM0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*)))

Expand Down
22 changes: 18 additions & 4 deletions boards/feather-m0/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ All the feather M0 boards are built based on the same Atmel SAMD21G18A
microcontroller. See @ref cpu_samd21.

Several types of Feather M0 boards exist:
* [Feather M0 WiFi](https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500/)
* [Feather M0 BLE](https://learn.adafruit.com/adafruit-feather-m0-bluefruit-le/overview)
* [Feather M0 Adalogger](https://learn.adafruit.com/adafruit-feather-m0-adalogger/)
* [Feather M0 LoRa](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module)
- [Feather M0 WiFi](https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500/)
- [Feather M0 BLE](https://learn.adafruit.com/adafruit-feather-m0-bluefruit-le/overview)
- [Feather M0 Adalogger](https://learn.adafruit.com/adafruit-feather-m0-adalogger/)
- [Feather M0 LoRa](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module)

The different modules used to differentiate the boards (ATWINC1500 WiFi,
Bluefruit LE, SD card, LoRa) are connected via SPI (SPI_DEV(0)) to the
Expand Down Expand Up @@ -52,6 +52,20 @@ Example with `hello-world` application:
bootloader mode by double tapping the reset button before running the
flash command.

### Using the WiFi interface

To enable the WiFi interface of the Feather M0 WiFi variant of the board
automatically for networking applications, add `USEMODULE=atwin1x0` to
the `make` command and define the required parameters, for example:
```
USEMODULE='feather-m0-wifi' \
CFLAGS='-DWIFI_SSID=\"<ssid>\" -DWIFI_PASS=\"<pass>\"' \
make BOARD=feather-m0 -C examples/gnrc_networking
```

For detailed information about the parameters, see section
@ref drivers_atwinc15x0.

### Accessing STDIO via UART

STDIO of RIOT is directly available over the USB port.
Expand Down
12 changes: 12 additions & 0 deletions boards/feather-m0/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ extern "C" {
#define LED0_TOGGLE (LED_PORT.OUTTGL.reg = LED0_MASK)
/** @} */

/**
* @name Configuration for Feather M0 WiFi and the ATWINC15x0 WiFi netdev
* @{
*/
#define ATWINC15X0_PARAM_SPI SPI_DEV(0)
#define ATWINC15X0_PARAM_SSN_PIN GPIO_PIN(0, 6)
#define ATWINC15X0_PARAM_RESET_PIN GPIO_PIN(0, 8)
#define ATWINC15X0_PARAM_CHIP_EN_PIN GPIO_PIN(0, 14)
#define ATWINC15X0_PARAM_IRQ_PIN GPIO_PIN(0, 21)
#define ATWINC15X0_PARAM_WAKE_PIN GPIO_UNDEF
/** @} */

/**
* @brief Initialize board specific hardware, including clock, LEDs and std-IO
*/
Expand Down
10 changes: 10 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ ifneq (,$(filter ata8520e,$(USEMODULE)))
FEATURES_REQUIRED += periph_spi
endif

ifneq (,$(filter atwinc15x0,$(USEMODULE)))
USEMODULE += luid
USEMODULE += netdev_eth
USEMODULE += xtimer
USEPKG += driver_atwinc15x0
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_gpio_irq
FEATURES_REQUIRED += periph_spi
endif

ifneq (,$(filter bh1750fvi,$(USEMODULE)))
USEMODULE += xtimer
FEATURES_REQUIRED += periph_i2c
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ ifneq (,$(filter ata8520e,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/ata8520e/include
endif

ifneq (,$(filter atwinc15x0,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/atwinc15x0/include
endif

ifneq (,$(filter bh1750fvi,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/bh1750fvi/include
endif
Expand Down
1 change: 1 addition & 0 deletions drivers/atwinc15x0/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
98 changes: 98 additions & 0 deletions drivers/atwinc15x0/atwinc15x0_bsp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2020 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_atwinc15x0
* @{
*
* @file
* @brief RIOT BSP API implementation
*
* @author Gunar Schorcht <gunar@schorcht.net>
*
* @}
*/

#include "atwinc15x0_internal.h"
#include "mutex.h"
#include "periph/spi.h"
#include "xtimer.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

void atwinc15x0_isr(void *arg)
{
(void)arg;
if (atwinc15x0->bsp_isr != NULL && atwinc15x0->bsp_irq_enabled) {
atwinc15x0->bsp_isr();
}
atwinc15x0_irq();
}

sint8 nm_bsp_init(void)
{
assert(atwinc15x0);
assert(atwinc15x0->params.reset_pin != GPIO_UNDEF);
assert(atwinc15x0->params.irq_pin != GPIO_UNDEF);

gpio_init(atwinc15x0->params.reset_pin, GPIO_OUT);
gpio_set(atwinc15x0->params.reset_pin);

gpio_init_int(atwinc15x0->params.irq_pin, GPIO_IN_PU, GPIO_FALLING,
atwinc15x0_isr, NULL);

if (atwinc15x0->params.chip_en_pin != GPIO_UNDEF) {
gpio_init(atwinc15x0->params.chip_en_pin, GPIO_OUT);
gpio_set(atwinc15x0->params.chip_en_pin);
}

if (atwinc15x0->params.wake_pin != GPIO_UNDEF) {
gpio_init(atwinc15x0->params.wake_pin, GPIO_OUT);
gpio_set(atwinc15x0->params.wake_pin);
}

return 0;
}

sint8 nm_bsp_deinit(void)
{
return 0;
}

void nm_bsp_reset(void)
{
assert(atwinc15x0);
gpio_clear(atwinc15x0->params.reset_pin);
nm_bsp_sleep(100);
gpio_set(atwinc15x0->params.reset_pin);
nm_bsp_sleep(100);
}

void nm_bsp_sleep(uint32 u32TimeMsec)
{
xtimer_usleep(u32TimeMsec * US_PER_MS);
}

void nm_bsp_register_isr(tpfNmBspIsr pfIsr)
{
assert(atwinc15x0);

DEBUG("%s %p\n", __func__, pfIsr);

atwinc15x0->bsp_isr = pfIsr;
}

void nm_bsp_interrupt_ctrl(uint8 u8Enable)
{
assert(atwinc15x0);

DEBUG("%s %u\n", __func__, u8Enable);

atwinc15x0->bsp_irq_enabled = u8Enable;
}
88 changes: 88 additions & 0 deletions drivers/atwinc15x0/atwinc15x0_bus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2020 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_atwinc15x0
* @{
*
* @file
* @brief RIOT bus wrapper API implementation
*
* @author Gunar Schorcht <gunar@schorcht.net>
*
* @}
*/

#include "atwinc15x0_internal.h"
#include "bus_wrapper/include/nm_bus_wrapper.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

#define NM_BUS_MAX_TRX_SZ 256

tstrNmBusCapabilities egstrNmBusCapabilities =
{
NM_BUS_MAX_TRX_SZ
};

sint8 nm_bus_init(void *arg)
{
(void)arg;

assert(atwinc15x0);
assert(atwinc15x0->params.ssn_pin != GPIO_UNDEF);

gpio_init(atwinc15x0->params.ssn_pin, GPIO_OUT);
gpio_set(atwinc15x0->params.ssn_pin);

nm_bsp_reset();
nm_bsp_sleep(1);

return 0;
}

sint8 nm_bus_ioctl(uint8 cmd, void* params)
{
assert(atwinc15x0);

sint8 res = 0;
tstrNmSpiRw *spi_params = (tstrNmSpiRw *)params;

switch (cmd)
{
case NM_BUS_IOCTL_RW:
spi_acquire(atwinc15x0->params.spi, atwinc15x0->params.ssn_pin,
SPI_MODE_0, atwinc15x0->params.spi_clk);
spi_transfer_bytes(atwinc15x0->params.spi,
atwinc15x0->params.ssn_pin, 0,
spi_params->pu8InBuf,
spi_params->pu8OutBuf,
spi_params->u16Sz);
spi_release(atwinc15x0->params.spi);
break;

default:
res = M2M_ERR_BUS_FAIL;
DEBUG("invalid ioctl cmd\n");
break;
}

return res;
}

sint8 nm_bus_deinit(void)
{
return 0;
}

sint8 nm_bus_reinit(void *arg)
{
(void)arg;
return 0;
}
Loading