zephyr/drivers/lora/sx126x_standalone.c
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00

85 lines
2.2 KiB
C

/*
* Copyright (c) 2019 Manivannan Sadhasivam
* Copyright (c) 2020 Andreas Sandberg
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#include "sx126x_common.h"
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(sx126x, CONFIG_LORA_LOG_LEVEL);
static const struct gpio_dt_spec sx126x_gpio_reset = GPIO_DT_SPEC_INST_GET(
0, reset_gpios);
static const struct gpio_dt_spec sx126x_gpio_busy = GPIO_DT_SPEC_INST_GET(
0, busy_gpios);
static const struct gpio_dt_spec sx126x_gpio_dio1 = GPIO_DT_SPEC_INST_GET(
0, dio1_gpios);
void sx126x_reset(struct sx126x_data *dev_data)
{
gpio_pin_set_dt(&sx126x_gpio_reset, 1);
k_sleep(K_MSEC(20));
gpio_pin_set_dt(&sx126x_gpio_reset, 0);
k_sleep(K_MSEC(10));
}
bool sx126x_is_busy(struct sx126x_data *dev_data)
{
return gpio_pin_get_dt(&sx126x_gpio_busy);
}
uint32_t sx126x_get_dio1_pin_state(struct sx126x_data *dev_data)
{
return gpio_pin_get_dt(&sx126x_gpio_dio1) > 0 ? 1U : 0U;
}
void sx126x_dio1_irq_enable(struct sx126x_data *dev_data)
{
gpio_pin_interrupt_configure_dt(&sx126x_gpio_dio1,
GPIO_INT_EDGE_TO_ACTIVE);
}
void sx126x_dio1_irq_disable(struct sx126x_data *dev_data)
{
gpio_pin_interrupt_configure_dt(&sx126x_gpio_dio1,
GPIO_INT_DISABLE);
}
static void sx126x_dio1_irq_callback(const struct device *dev,
struct gpio_callback *cb, uint32_t pins)
{
struct sx126x_data *dev_data = CONTAINER_OF(cb, struct sx126x_data,
dio1_irq_callback);
if (pins & BIT(sx126x_gpio_dio1.pin)) {
k_work_submit(&dev_data->dio1_irq_work);
}
}
int sx126x_variant_init(const struct device *dev)
{
struct sx126x_data *dev_data = dev->data;
if (gpio_pin_configure_dt(&sx126x_gpio_reset, GPIO_OUTPUT_ACTIVE) ||
gpio_pin_configure_dt(&sx126x_gpio_busy, GPIO_INPUT) ||
gpio_pin_configure_dt(&sx126x_gpio_dio1, GPIO_INPUT)) {
LOG_ERR("GPIO configuration failed.");
return -EIO;
}
gpio_init_callback(&dev_data->dio1_irq_callback,
sx126x_dio1_irq_callback, BIT(sx126x_gpio_dio1.pin));
if (gpio_add_callback(sx126x_gpio_dio1.port,
&dev_data->dio1_irq_callback) < 0) {
LOG_ERR("Could not set GPIO callback for DIO1 interrupt.");
return -EIO;
}
return 0;
}