From 300beb79aa87e037e5017da5693eac9e57aa28d5 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 11 Mar 2021 17:29:21 +0100 Subject: [PATCH] pkg: add driver_sx126x package driver --- pkg/driver_sx126x/Kconfig | 20 ++++ pkg/driver_sx126x/Makefile | 9 ++ pkg/driver_sx126x/Makefile.dep | 7 ++ pkg/driver_sx126x/Makefile.include | 3 + pkg/driver_sx126x/contrib/Makefile | 3 + pkg/driver_sx126x/contrib/driver_sx126x_hal.c | 98 ++++++++++++++++++ pkg/driver_sx126x/doc.txt | 7 ++ pkg/driver_sx126x/driver_sx126x.mk | 3 + .../patches/0001-adapt-to-RIOT.patch | Bin 0 -> 1721 bytes 9 files changed, 150 insertions(+) create mode 100644 pkg/driver_sx126x/Kconfig create mode 100644 pkg/driver_sx126x/Makefile create mode 100644 pkg/driver_sx126x/Makefile.dep create mode 100644 pkg/driver_sx126x/Makefile.include create mode 100644 pkg/driver_sx126x/contrib/Makefile create mode 100644 pkg/driver_sx126x/contrib/driver_sx126x_hal.c create mode 100644 pkg/driver_sx126x/doc.txt create mode 100644 pkg/driver_sx126x/driver_sx126x.mk create mode 100644 pkg/driver_sx126x/patches/0001-adapt-to-RIOT.patch diff --git a/pkg/driver_sx126x/Kconfig b/pkg/driver_sx126x/Kconfig new file mode 100644 index 0000000000..8233a61e51 --- /dev/null +++ b/pkg/driver_sx126x/Kconfig @@ -0,0 +1,20 @@ +# Copyright (c) 2021 Inria +# +# 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. +# + +config PACKAGE_DRIVER_SX126X + bool "LLCC68 driver package" + depends on TEST_KCONFIG + depends on HAS_PERIPH_SPI + select MODULE_PERIPH_SPI + select MODULE_ZTIMER + select MODULE_ZTIMER_USEC + select MODULE_DRIVER_SX126X_HAL + +config MODULE_DRIVER_SX126X_HAL + bool + help + HAL implementation for the SX126X LoRa radio driver. diff --git a/pkg/driver_sx126x/Makefile b/pkg/driver_sx126x/Makefile new file mode 100644 index 0000000000..4f18518f0c --- /dev/null +++ b/pkg/driver_sx126x/Makefile @@ -0,0 +1,9 @@ +PKG_NAME=driver_sx126x +PKG_URL=https://github.com/Lora-net/sx126x_driver +PKG_VERSION=ba61312213450ae94a4293d75285c1d8f30c04b3 +PKG_LICENSE=BSD + +include $(RIOTBASE)/pkg/pkg.mk + +all: + $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/src -f $(CURDIR)/$(PKG_NAME).mk diff --git a/pkg/driver_sx126x/Makefile.dep b/pkg/driver_sx126x/Makefile.dep new file mode 100644 index 0000000000..7445a56abe --- /dev/null +++ b/pkg/driver_sx126x/Makefile.dep @@ -0,0 +1,7 @@ +# module dependencies +USEMODULE += driver_sx126x_hal +USEMODULE += ztimer +USEMODULE += ztimer_usec + +# required features +FEATURES_REQUIRED += periph_spi diff --git a/pkg/driver_sx126x/Makefile.include b/pkg/driver_sx126x/Makefile.include new file mode 100644 index 0000000000..1dc9126938 --- /dev/null +++ b/pkg/driver_sx126x/Makefile.include @@ -0,0 +1,3 @@ +INCLUDES += -I$(PKGDIRBASE)/driver_sx126x/src + +DIRS += $(RIOTBASE)/pkg/driver_sx126x/contrib diff --git a/pkg/driver_sx126x/contrib/Makefile b/pkg/driver_sx126x/contrib/Makefile new file mode 100644 index 0000000000..0ee8bc8c92 --- /dev/null +++ b/pkg/driver_sx126x/contrib/Makefile @@ -0,0 +1,3 @@ +MODULE = driver_sx126x_hal + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/driver_sx126x/contrib/driver_sx126x_hal.c b/pkg/driver_sx126x/contrib/driver_sx126x_hal.c new file mode 100644 index 0000000000..4d789469cb --- /dev/null +++ b/pkg/driver_sx126x/contrib/driver_sx126x_hal.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2021 Inria + * + * 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 pkg_driver_sx126x + * @{ + * + * @file + * @brief HAL implementation for the SX1261/2 LoRa radio driver + * + * @author Alexandre Abadie + * + * @} + */ + +#include "ztimer.h" + +#include "periph/gpio.h" +#include "periph/spi.h" + +#include "sx126x.h" +#include "sx126x_hal.h" + +#define ENABLE_DEBUG 0 +#include "debug.h" + +#define SX126X_SPI_SPEED (SPI_CLK_1MHZ) +#define SX126X_SPI_MODE (SPI_MODE_0) + +sx126x_hal_status_t sx126x_hal_write(const void *context, + const uint8_t *command, const uint16_t command_length, + const uint8_t *data, const uint16_t data_length) +{ + (void)data; + (void)data_length; + sx126x_t *dev = (sx126x_t *)context; + + /* wait for the device to not be busy anymore */ + while (gpio_read(dev->params->busy_pin)) {} + + spi_acquire(dev->params->spi, SPI_CS_UNDEF, SX126X_SPI_MODE, SX126X_SPI_SPEED); + spi_transfer_bytes(dev->params->spi, dev->params->nss_pin, data_length != 0, command, NULL, + command_length); + if (data_length) { + spi_transfer_bytes(dev->params->spi, dev->params->nss_pin, false, data, NULL, data_length); + } + spi_release(dev->params->spi); + return 0; +} + +sx126x_hal_status_t sx126x_hal_read(const void *context, + const uint8_t *command, const uint16_t command_length, + uint8_t *data, const uint16_t data_length) +{ + sx126x_t *dev = (sx126x_t *)context; + + /* wait for the device to not be busy anymore */ + while (gpio_read(dev->params->busy_pin)) {} + + spi_acquire(dev->params->spi, SPI_CS_UNDEF, SX126X_SPI_MODE, SX126X_SPI_SPEED); + spi_transfer_bytes(dev->params->spi, dev->params->nss_pin, true, command, NULL, command_length); + spi_transfer_bytes(dev->params->spi, dev->params->nss_pin, false, NULL, data, data_length); + spi_release(dev->params->spi); + return 0; +} + +sx126x_hal_status_t sx126x_hal_reset(const void *context) +{ + DEBUG("[sx126x_hal] reset\n"); + sx126x_t *dev = (sx126x_t *)context; + + gpio_set(dev->params->reset_pin); + gpio_clear(dev->params->reset_pin); + /* it takes 100us for the radio to be ready after reset */ + ztimer_sleep(ZTIMER_USEC, 100); + gpio_set(dev->params->reset_pin); + return 0; +} + +sx126x_hal_status_t sx126x_hal_wakeup(const void *context) +{ + DEBUG("[sx126x_hal] wakeup\n"); + sx126x_t *dev = (sx126x_t *)context; + + spi_acquire(dev->params->spi, SPI_CS_UNDEF, SX126X_SPI_MODE, SX126X_SPI_SPEED); + gpio_clear(dev->params->nss_pin); + gpio_set(dev->params->nss_pin); + spi_release(dev->params->spi); + + /* it takes 500us for the radio device to be ready after waking up */ + ztimer_sleep(ZTIMER_USEC, 500); + return 0; +} diff --git a/pkg/driver_sx126x/doc.txt b/pkg/driver_sx126x/doc.txt new file mode 100644 index 0000000000..aeaca868d8 --- /dev/null +++ b/pkg/driver_sx126x/doc.txt @@ -0,0 +1,7 @@ +/** + * @defgroup pkg_driver_sx126x SX1261/2 LoRa radio driver + * @ingroup pkg + * @brief This package is an implementation of the SX1261/2 LoRa radio driver. + * + * @see https://github.com/Lora-net/sx126x_driver + */ diff --git a/pkg/driver_sx126x/driver_sx126x.mk b/pkg/driver_sx126x/driver_sx126x.mk new file mode 100644 index 0000000000..0ed96f8ba2 --- /dev/null +++ b/pkg/driver_sx126x/driver_sx126x.mk @@ -0,0 +1,3 @@ +MODULE = driver_sx126x + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/driver_sx126x/patches/0001-adapt-to-RIOT.patch b/pkg/driver_sx126x/patches/0001-adapt-to-RIOT.patch new file mode 100644 index 0000000000000000000000000000000000000000..ae478f0b8bfab2b59bd95d597b225a31d403bf87 GIT binary patch literal 1721 zcmb_c+iu!G5PjdT7*SOsF*d$&RU1JAG)PT}Filfcm9^}y@m9tl+eAc3{=H*kb4{9u z*79X{cIJ3z&Y2xVi#f1*Q#3`x<`x%*Y1Np`n?{qj>a~U?EKArXo3d%chU-NLj#z@x z09|iqH<-F^kO9K9p&N)b4S6J>JEdF-_&^JbMl(xChLNP27hRAZO+*_e{;C3o0oOD_ zB-23Xwq9@B7AU%*>%>`2e+!nh;pa_va(M+t)%XRJ(`5q50>;D9gb-C#3B(br#%sf@ zuQdj5Tu)$wq7+e&d6*9$FJLovc_i;er1{T#NKa75C=AR0mdCk~n8n&@aBhEwC(sF4 z;K@M5zKTDZgmf;ly#Bt!a;x?JMgKQlfr zDB;rcKvicl0a`sM(3K@lf3S;cO$or}ap@y_R{UzgD(WinYr?mZ1wA}#~NZcpHTA^CYaPVh&Sjgi1J z3RZ;Ji`Wb5W|YZ)o3L_f+)t#MX%hNaz<*a}+LEsv3&pXr-`BYU@}*OCrUy--!XtSW VF}ZkO(rDp==L<14v!UsP`~fyI=q3OF literal 0 HcmV?d00001