feat: add shared LLCC68 Zephyr module
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#include "llcc68_raw.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
#define DT_DRV_COMPAT semtech_llcc68
|
||||
|
||||
static void dio1_irq_trampoline(const struct device *port, struct gpio_callback *cb, uint32_t pins) {
|
||||
ARG_UNUSED(port);
|
||||
|
||||
struct llcc68_data *data = CONTAINER_OF(cb, struct llcc68_data, dio1_irq_callback);
|
||||
const struct llcc68_config *config = data->self->config;
|
||||
|
||||
if ((pins & BIT(config->dio1_gpio.pin)) != 0U && data->dio1_user_handler != NULL) {
|
||||
data->dio1_user_handler(data->self, data->dio1_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
int llcc68_init(const struct device *dev) {
|
||||
const struct llcc68_config *config = dev->config;
|
||||
struct llcc68_data *data = dev->data;
|
||||
|
||||
if (config->tx_enable_gpio.port != NULL) {
|
||||
gpio_pin_configure_dt(&config->tx_enable_gpio, GPIO_OUTPUT_INACTIVE);
|
||||
}
|
||||
|
||||
if (config->rx_enable_gpio.port != NULL) {
|
||||
gpio_pin_configure_dt(&config->rx_enable_gpio, GPIO_OUTPUT_INACTIVE);
|
||||
}
|
||||
|
||||
gpio_pin_configure_dt(&config->reset_gpio, GPIO_OUTPUT_INACTIVE);
|
||||
gpio_pin_configure_dt(&config->busy_gpio, GPIO_INPUT);
|
||||
gpio_pin_configure_dt(&config->dio1_gpio, GPIO_INPUT);
|
||||
|
||||
data->self = dev;
|
||||
gpio_init_callback(&data->dio1_irq_callback, dio1_irq_trampoline, BIT(config->dio1_gpio.pin));
|
||||
if (gpio_add_callback(config->dio1_gpio.port, &data->dio1_irq_callback) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
gpio_pin_interrupt_configure_dt(&config->dio1_gpio, GPIO_INT_DISABLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define LLCC68_DEFINE(inst) \
|
||||
static struct llcc68_data llcc68_data_##inst; \
|
||||
static const struct llcc68_config llcc68_config_##inst = \
|
||||
{ \
|
||||
.spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8) | SPI_TRANSFER_MSB, 100), \
|
||||
.reset_gpio = GPIO_DT_SPEC_INST_GET(inst, reset_gpios), \
|
||||
.busy_gpio = GPIO_DT_SPEC_INST_GET(inst, busy_gpios), \
|
||||
.dio1_gpio = GPIO_DT_SPEC_INST_GET(inst, dio1_gpios), \
|
||||
.tx_enable_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, tx_enable_gpios, {.port = NULL}), \
|
||||
.rx_enable_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, rx_enable_gpios, {.port = NULL}), \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(inst, \
|
||||
llcc68_init, \
|
||||
NULL, \
|
||||
&llcc68_data_##inst, \
|
||||
&llcc68_config_##inst, \
|
||||
POST_KERNEL, \
|
||||
CONFIG_LLCC68_INIT_PRIORITY, \
|
||||
NULL)
|
||||
|
||||
BUILD_ASSERT(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT),
|
||||
"No status=okay nodes for DT_DRV_COMPAT; check compatible/status");
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(LLCC68_DEFINE)
|
||||
|
||||
Reference in New Issue
Block a user