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/sx1280: add driver for SX1280 transceiver v2 #18033

Merged
merged 4 commits into from
May 18, 2022
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
1 change: 1 addition & 0 deletions drivers/Kconfig.net
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ rsource "slipdev/Kconfig"
rsource "$(RIOTCPU)/native/socket_zep/Kconfig"
rsource "sx126x/Kconfig"
rsource "sx127x/Kconfig"
rsource "sx1280/Kconfig"
rsource "tja1042/Kconfig"
endmenu # Network Device Drivers
1 change: 1 addition & 0 deletions drivers/include/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ typedef enum {
NETDEV_NRF24L01P_NG,
NETDEV_SOCKET_ZEP,
NETDEV_SX126X,
NETDEV_SX1280,
NETDEV_CC2420,
NETDEV_ETHOS,
NETDEV_SLIPDEV,
Expand Down
267 changes: 267 additions & 0 deletions drivers/include/sx1280.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
* Copyright (C) 2022 Inria
* Copyright (C) 2020-2022 Université Grenoble Alpes
*
* 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.
*/

/**
* @defgroup drivers_sx1280 LoRa radio driver
* @ingroup drivers_netdev
* @brief Driver for the sx1280 LoRa radio device
*
* @{
*
* @file
*
* @author Francisco Molina <francois-xavier.molina@inria.fr>
* @author Aymeric Brochier <aymeric.brochier@univ-grenoble-alpes.fr>
*
*/

#ifndef SX1280_H
#define SX1280_H

#include <assert.h>

#include "sx1280_driver/src/sx1280_hal.h"
#include "sx1280_driver/src/sx1280.h"
#include "smtc_ral/src/ral.h"
#include "smtc_ral/src/ral_defs.h"

#include "net/netdev.h"

#include "periph/gpio.h"
#include "periph/spi.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name SX1280 device default configuration
* @{
*/
#define SX1280_CHANNEL_DEFAULT (2403000000UL) /**< Default channel frequency, 2403MHz */
#define SX1280_RADIO_TX_POWER (SX1280_PWR_MAX) /**< Radio power in dBm */
/** @} */

/**
* * @note Forward declaration of the sx1280 device descriptor
*/
typedef struct sx1280 sx1280_t;

/**
* @brief Device initialization parameters
*/
typedef struct {
spi_t spi; /**< SPI device */
spi_mode_t spi_mode; /**< SPI mode */
spi_clk_t spi_clk; /**< SPI clk */
gpio_t nss_pin; /**< SPI NSS pin */
gpio_t reset_pin; /**< Reset pin */
gpio_t busy_pin; /**< Busy pin */
gpio_t dio0_pin; /**< Dio0 pin */
gpio_t dio1_pin; /**< Dio1 pin */
sx1280_reg_mod_t regulator; /**< Power regulator mode */
} sx1280_params_t;

/**
* @brief Device descriptor for the driver
*/
struct sx1280 {
netdev_t netdev; /**< Netdev parent struct */
ral_t ral; /**< Radio abstraction */
ral_params_lora_t ral_params_lora; /**< LoRa modulation parameters */
sx1280_params_t *params; /**< Initialization parameters */
sx1280_hal_operating_mode_t mode; /**< Operating Mode */
};

/**
* @brief Setup the radio device
*
* @param[in] dev Device descriptor
* @param[in] params Parameters for device initialization
* @param[in] index Index of @p params in a global parameter struct array.
* If initialized manually, pass a unique identifier instead.
*/
void sx1280_setup(sx1280_t *dev, const sx1280_params_t *params, uint8_t index);

/**
* @brief Initialize the given device
*
* @param[inout] dev Device descriptor of the driver
*
* @return 0 on success
*/
int sx1280_init(sx1280_t *dev);

/**
* @brief Gets the channel RF frequency.
*
* @param[in] dev Device descriptor of the driver
*
* @return The channel frequency
*/
uint32_t sx1280_get_channel(const sx1280_t *dev);

/**
* @brief Gets a random number
*
* @param[in] dev Device descriptor of the driver
*
* @return a random number
*/
uint32_t sx1280_random(const sx1280_t *dev);
/**
* @brief Sets the channel RF frequency.
*
* @param[in] dev Device descriptor of the driver
* @param[in] freq Channel RF frequency
*/
void sx1280_set_channel(sx1280_t *dev, uint32_t freq);

/**
* @brief Gets the LoRa bandwidth
*
* @param[in] dev Device descriptor of the driver
*
* @return the bandwidth
*/
uint32_t sx1280_get_bandwidth(const sx1280_t *dev);

/**
* @brief Sets the LoRa bandwidth
*
* @param[in] dev Device descriptor of the driver
* @param[in] bandwidth The new bandwidth
*/
void sx1280_set_bandwidth(sx1280_t *dev, uint16_t bandwidth);

/**
* @brief Gets the LoRa spreading factor
*
* @param[in] dev Device descriptor of the driver
*
* @return the spreading factor
*/
uint8_t sx1280_get_spreading_factor(const sx1280_t *dev);

/**
* @brief Sets the LoRa spreading factor
*
* @param[in] dev Device descriptor of the driver
* @param[in] sf The spreading factor
*/
void sx1280_set_spreading_factor(sx1280_t *dev, uint8_t sf);

/**
* @brief Gets the LoRa coding rate
*
* @param[in] dev Device descriptor of the driver
*
* @return the current LoRa coding rate
*/
uint8_t sx1280_get_coding_rate(const sx1280_t *dev);

/**
* @brief Sets the LoRa coding rate
*
* @param[in] dev Device descriptor of the driver
* @param[in] cr The LoRa coding rate
*/
void sx1280_set_coding_rate(sx1280_t *dev, uint8_t cr);

/**
* @brief Gets the payload length
*
* @param[in] dev Device descriptor of the driver
*
* @return the payload length
*/
uint8_t sx1280_get_lora_payload_length(const sx1280_t *dev);

/**
* @brief Sets the payload length
*
* @param[in] dev Device descriptor of the driver
* @param[in] len The payload len
*/
void sx1280_set_lora_payload_length(sx1280_t *dev, uint8_t len);

/**
* @brief Checks if CRC verification mode is enabled
*
* @param[in] dev Device descriptor of the driver
*
* @return the LoRa single mode
*/
bool sx1280_get_lora_crc(const sx1280_t *dev);

/**
* @brief Enable/Disable CRC verification mode
*
* @param[in] dev Device descriptor of the driver
* @param[in] crc The CRC check mode
*/
void sx1280_set_lora_crc(sx1280_t *dev, bool crc);

/**
* @brief Gets the LoRa implicit header mode
*
* @param[in] dev Device descriptor of the driver
*
* @return the LoRa implicit mode
*/
bool sx1280_get_lora_implicit_header(const sx1280_t *dev);

/**
* @brief Sets LoRa implicit header mode
*
* @param[in] dev Device descriptor of the driver
* @param[in] mode The header mode
*/
void sx1280_set_lora_implicit_header(sx1280_t *dev, bool mode);

/**
* @brief Gets the LoRa preamble length
*
* @param[in] dev Device descriptor of the driver
*
* @return the preamble length
*/
uint16_t sx1280_get_lora_preamble_length(const sx1280_t *dev);

/**
* @brief Sets the LoRa preamble length
*
* @param[in] dev Device descriptor of the driver
* @param[in] preamble The LoRa preamble length
*/
void sx1280_set_lora_preamble_length(sx1280_t *dev, uint16_t preamble);

/**
* @brief Checks if the LoRa inverted IQ mode is enabled/disabled
*
* @param[in] dev Device descriptor of the driver
*
* @return the LoRa IQ inverted mode
*/
bool sx1280_get_lora_iq_invert(const sx1280_t *dev);

/**
* @brief Enable/disable the LoRa IQ inverted mode
*
* @param[in] dev Device descriptor of the driver
* @param[in] iq_invert The LoRa IQ inverted mode
*/
void sx1280_set_lora_iq_invert(sx1280_t *dev, bool iq_invert);

#ifdef __cplusplus
}
#endif

#endif /* SX1280_H */
/** @} */
17 changes: 17 additions & 0 deletions drivers/sx1280/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2022 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 MODULE_SX1280
bool "LoRa 2.4Ghz SX1280 Driver" if !(HAVE_SX1280 && MODULE_NETDEV_DEFAULT)
default y if (HAVE_SX1280 && MODULE_NETDEV_DEFAULT)
depends on TEST_KCONFIG
select PACKAGE_LORABASICS
select MODULE_LORABASICS_SX1280_DRIVER

config HAVE_SX1280
bool
help
Indicates that an sx1280 2.4Ghz transceiver is present.
1 change: 1 addition & 0 deletions drivers/sx1280/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
2 changes: 2 additions & 0 deletions drivers/sx1280/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USEPKG += lorabasics
USEMODULE += lorabasics_sx1280_driver
7 changes: 7 additions & 0 deletions drivers/sx1280/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USEMODULE_INCLUDES_sx1280 := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_sx1280)

# Overide defaults see See https://lora-developers.semtech.com/documentation/tech-papers-and-guides/physical-layer-proposal-2.4ghz/
CFLAGS += -DCONFIG_LORA_BW_DEFAULT_800=1
CFLAGS += -DCONFIG_LORA_SF_DEFAULT_SF12=1
CFLAGS += -DCONFIG_LORA_CR_DEFAULT_CR_LI_4_8=1
75 changes: 75 additions & 0 deletions drivers/sx1280/include/sx1280_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2022 Inria
* Copyright (C) 2020-2022 Université Grenoble Alpes
*
* 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_sx1280
* @{
*
* @file
* @brief Internal addresses, registers and constants
*
* @author Aymeric Brochier <aymeric.brochier@univ-grenoble-alpes.fr>
*
*/

#ifndef SX1280_CONSTANTS_H
#define SX1280_CONSTANTS_H

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief SX1280 Single RX mode.
*
* sx1280_set_rx constant to be in single mode
*
* There is a known issue about this in some circonstances described in section 16.1 of the datasheet:
* https://manualzz.com/doc/55353537/semtech-sx1280-2.4-ghz-transceiver-datasheet
*
* When subjected to a high co-channel traffic conditions
* (for example in BLE mode when the SX1280 receives more than 220 packets per second)
* and only when configured in continuous receiver
* The SX1280 busy line will remain high and the radio unresponsive.
*
* If the radio may be subject to high levels of BLE traffic, to allow the radio to remain in operation RX single mode must be used
*/
#define SX1280_RX_SINGLE_MODE 0x0000

/**
* @brief SX1280 Continuous RX mode.
*
* @note This addresses a known issue detailed in section 16.1 of the datasheet, see
* @ref SX1280_RX_SINGLE_MODE for more details.
*
* sx1280_set_rx require this constant to be in continuous mode
*
*/
#define SX1280_RX_CONTINUOUS_MODE 0xFFFF

/**
* @brief SX1280 wakeup time in ms
* @note From the datasheet wakeup time is usually 1200us but rounded up to 2 to only use the ZTIMER_MSEC
*
*/
#define SX1280_WAKEUP_TIME_MS 2

/**
* @brief SX1280 reset time in ms
* hold NRST pin low for 1ms, nothing is specified in the datasheet, 1ms worked fine
*
*/
#define SX1280_RESET_MS 1

#ifdef __cplusplus
}
#endif

#endif /* SX1280_CONSTANTS_H */
/** @} */
Loading