drivers: lora: Move sx1276 pin helpers to sx12xx common
The new sx1276 pin configuration helpers can be used by the sx126x driver as well. Move them to sx126xx_common.{c,h} to facilitate reuse. Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
This commit is contained in:
parent
6dc38b570c
commit
23e4a8b64e
3 changed files with 45 additions and 37 deletions
|
@ -445,57 +445,26 @@ const struct Radio_s Radio = {
|
||||||
.SetTxContinuousWave = SX1276SetTxContinuousWave,
|
.SetTxContinuousWave = SX1276SetTxContinuousWave,
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int __sx1276_configure_pin(struct device **dev,
|
|
||||||
const char *controller,
|
|
||||||
gpio_pin_t pin, gpio_flags_t flags)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
*dev = device_get_binding(controller);
|
|
||||||
if (!(*dev)) {
|
|
||||||
LOG_ERR("Cannot get pointer to %s device", controller);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = gpio_pin_configure(*dev, pin, flags);
|
|
||||||
if (err) {
|
|
||||||
LOG_ERR("Cannot configure gpio %s %d: %d", controller, pin,
|
|
||||||
err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define sx1276_configure_pin(_name, _flags) \
|
|
||||||
COND_CODE_1(DT_INST_NODE_HAS_PROP(0, _name##_gpios), \
|
|
||||||
(__sx1276_configure_pin(&dev_data._name, \
|
|
||||||
DT_INST_GPIO_LABEL(0, _name##_gpios), \
|
|
||||||
DT_INST_GPIO_PIN(0, _name##_gpios), \
|
|
||||||
DT_INST_GPIO_FLAGS(0, _name##_gpios) | \
|
|
||||||
_flags)), \
|
|
||||||
(0))
|
|
||||||
|
|
||||||
static int sx1276_antenna_configure(void)
|
static int sx1276_antenna_configure(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = sx1276_configure_pin(antenna_enable, GPIO_OUTPUT_INACTIVE);
|
ret = sx12xx_configure_pin(antenna_enable, GPIO_OUTPUT_INACTIVE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sx1276_configure_pin(rfi_enable, GPIO_OUTPUT_INACTIVE);
|
ret = sx12xx_configure_pin(rfi_enable, GPIO_OUTPUT_INACTIVE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sx1276_configure_pin(rfo_enable, GPIO_OUTPUT_INACTIVE);
|
ret = sx12xx_configure_pin(rfo_enable, GPIO_OUTPUT_INACTIVE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sx1276_configure_pin(pa_boost_enable, GPIO_OUTPUT_INACTIVE);
|
ret = sx12xx_configure_pin(pa_boost_enable, GPIO_OUTPUT_INACTIVE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -538,13 +507,13 @@ static int sx1276_lora_init(struct device *dev)
|
||||||
dev_data.spi_cfg.cs = &spi_cs;
|
dev_data.spi_cfg.cs = &spi_cs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = sx1276_configure_pin(tcxo_power, GPIO_OUTPUT_INACTIVE);
|
ret = sx12xx_configure_pin(tcxo_power, GPIO_OUTPUT_INACTIVE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup Reset gpio and perform soft reset */
|
/* Setup Reset gpio and perform soft reset */
|
||||||
ret = sx1276_configure_pin(reset, GPIO_OUTPUT_ACTIVE);
|
ret = sx12xx_configure_pin(reset, GPIO_OUTPUT_ACTIVE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 Manivannan Sadhasivam
|
* Copyright (c) 2019 Manivannan Sadhasivam
|
||||||
|
* Copyright (c) 2020 Grinn
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <drivers/gpio.h>
|
||||||
#include <drivers/lora.h>
|
#include <drivers/lora.h>
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
|
@ -11,6 +13,8 @@
|
||||||
/* LoRaMac-node specific includes */
|
/* LoRaMac-node specific includes */
|
||||||
#include <radio.h>
|
#include <radio.h>
|
||||||
|
|
||||||
|
#include "sx12xx_common.h"
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(sx12xx_common, CONFIG_LORA_LOG_LEVEL);
|
LOG_MODULE_REGISTER(sx12xx_common, CONFIG_LORA_LOG_LEVEL);
|
||||||
|
|
||||||
static struct sx12xx_data {
|
static struct sx12xx_data {
|
||||||
|
@ -22,6 +26,27 @@ static struct sx12xx_data {
|
||||||
int16_t rssi;
|
int16_t rssi;
|
||||||
} dev_data;
|
} dev_data;
|
||||||
|
|
||||||
|
int __sx12xx_configure_pin(struct device **dev, const char *controller,
|
||||||
|
gpio_pin_t pin, gpio_flags_t flags)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
*dev = device_get_binding(controller);
|
||||||
|
if (!(*dev)) {
|
||||||
|
LOG_ERR("Cannot get pointer to %s device", controller);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gpio_pin_configure(*dev, pin, flags);
|
||||||
|
if (err) {
|
||||||
|
LOG_ERR("Cannot configure gpio %s %d: %d", controller, pin,
|
||||||
|
err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void sx12xx_ev_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
|
static void sx12xx_ev_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
|
||||||
int8_t snr)
|
int8_t snr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 Andreas Sandberg
|
* Copyright (c) 2020 Andreas Sandberg
|
||||||
|
* Copyright (c) 2020 Grinn
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -8,9 +9,22 @@
|
||||||
#define ZEPHYR_DRIVERS_SX12XX_COMMON_H_
|
#define ZEPHYR_DRIVERS_SX12XX_COMMON_H_
|
||||||
|
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
|
#include <drivers/gpio.h>
|
||||||
#include <drivers/lora.h>
|
#include <drivers/lora.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
|
||||||
|
int __sx12xx_configure_pin(struct device **dev, const char *controller,
|
||||||
|
gpio_pin_t pin, gpio_flags_t flags);
|
||||||
|
|
||||||
|
#define sx12xx_configure_pin(_name, _flags) \
|
||||||
|
COND_CODE_1(DT_INST_NODE_HAS_PROP(0, _name##_gpios), \
|
||||||
|
(__sx12xx_configure_pin(&dev_data._name, \
|
||||||
|
DT_INST_GPIO_LABEL(0, _name##_gpios), \
|
||||||
|
DT_INST_GPIO_PIN(0, _name##_gpios), \
|
||||||
|
DT_INST_GPIO_FLAGS(0, _name##_gpios) | \
|
||||||
|
_flags)), \
|
||||||
|
(0))
|
||||||
|
|
||||||
int sx12xx_lora_send(struct device *dev, uint8_t *data, uint32_t data_len);
|
int sx12xx_lora_send(struct device *dev, uint8_t *data, uint32_t data_len);
|
||||||
|
|
||||||
int sx12xx_lora_recv(struct device *dev, uint8_t *data, uint8_t size,
|
int sx12xx_lora_recv(struct device *dev, uint8_t *data, uint8_t size,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue