1 /* 2 * Copyright (c) 2019 Manivannan Sadhasivam 3 * Copyright (c) 2020 Andreas Sandberg 4 * Copyright (c) 2021 Fabio Baltieri 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #ifndef ZEPHYR_DRIVERS_SX126X_COMMON_H_ 10 #define ZEPHYR_DRIVERS_SX126X_COMMON_H_ 11 12 #include <zephyr/types.h> 13 #include <zephyr/drivers/gpio.h> 14 #include <zephyr/drivers/lora.h> 15 #include <zephyr/drivers/spi.h> 16 17 #include <sx126x/sx126x.h> 18 #include <sx126x-board.h> 19 20 #if DT_HAS_COMPAT_STATUS_OKAY(semtech_sx1261) 21 #define DT_DRV_COMPAT semtech_sx1261 22 #define SX126X_DEVICE_ID SX1261 23 #elif DT_HAS_COMPAT_STATUS_OKAY(semtech_sx1262) 24 #define DT_DRV_COMPAT semtech_sx1262 25 #define SX126X_DEVICE_ID SX1262 26 #elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32wl_subghz_radio) 27 #define DT_DRV_COMPAT st_stm32wl_subghz_radio 28 #define SX126X_DEVICE_ID SX1262 29 #else 30 #error No SX126x instance in device tree. 31 #endif 32 33 #define HAVE_GPIO_ANTENNA_ENABLE \ 34 DT_INST_NODE_HAS_PROP(0, antenna_enable_gpios) 35 #define HAVE_GPIO_TX_ENABLE DT_INST_NODE_HAS_PROP(0, tx_enable_gpios) 36 #define HAVE_GPIO_RX_ENABLE DT_INST_NODE_HAS_PROP(0, rx_enable_gpios) 37 38 struct sx126x_config { 39 struct spi_dt_spec bus; 40 #if HAVE_GPIO_ANTENNA_ENABLE 41 struct gpio_dt_spec antenna_enable; 42 #endif 43 #if HAVE_GPIO_TX_ENABLE 44 struct gpio_dt_spec tx_enable; 45 #endif 46 #if HAVE_GPIO_RX_ENABLE 47 struct gpio_dt_spec rx_enable; 48 #endif 49 }; 50 51 struct sx126x_data { 52 struct gpio_callback dio1_irq_callback; 53 struct k_work dio1_irq_work; 54 DioIrqHandler *radio_dio_irq; 55 RadioOperatingModes_t mode; 56 }; 57 58 void sx126x_reset(struct sx126x_data *dev_data); 59 60 bool sx126x_is_busy(struct sx126x_data *dev_data); 61 62 uint32_t sx126x_get_dio1_pin_state(struct sx126x_data *dev_data); 63 64 void sx126x_dio1_irq_enable(struct sx126x_data *dev_data); 65 66 void sx126x_dio1_irq_disable(struct sx126x_data *dev_data); 67 68 void sx126x_set_tx_params(int8_t power, RadioRampTimes_t ramp_time); 69 70 int sx126x_variant_init(const struct device *dev); 71 72 #endif /* ZEPHYR_DRIVERS_SX126X_COMMON_H_ */ 73