|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <driver/spi_master.h>
|
|
|
|
#include <driver/gpio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#define SX127X_MAX_TRANSFER (256)
|
|
|
|
|
|
|
|
// carrier frequency type
|
|
|
|
typedef uint64_t sx127x_freq_t;
|
|
|
|
|
|
|
|
#define SX127X_FREQ_433 ((sx127x_freq_t)433E6)
|
|
|
|
#define SX127X_FREQ_915 ((sx127x_freq_t)915E6)
|
|
|
|
|
|
|
|
// signal bandwidth type
|
|
|
|
typedef uint64_t sx127x_bw_t;
|
|
|
|
// spreading factor type
|
|
|
|
typedef uint8_t sx127x_sf_t;
|
|
|
|
|
|
|
|
typedef enum sx127x_pa_boost {
|
|
|
|
SX127X_PA_BOOST_DISABLED = 0,
|
|
|
|
SX127X_PA_BOOST_ENABLED = 1,
|
|
|
|
} sx127x_pa_boost_t;
|
|
|
|
|
|
|
|
typedef enum sx127x_crc {
|
|
|
|
SX127X_CRC_DISABLED = 0,
|
|
|
|
SX127X_CRC_ENABLED = 1,
|
|
|
|
} sx127x_crc_t;
|
|
|
|
|
|
|
|
// low data rate optimization
|
|
|
|
typedef enum sx127x_ldo {
|
|
|
|
SX127X_LDO_DISABLED = 0,
|
|
|
|
SX127X_LDO_ENABLED = 1,
|
|
|
|
} sx127x_ldo_t;
|
|
|
|
|
|
|
|
typedef struct sx127x_config {
|
|
|
|
spi_host_device_t spi_host;
|
|
|
|
gpio_num_t mosi_io_num;
|
|
|
|
gpio_num_t miso_io_num;
|
|
|
|
gpio_num_t sck_io_num;
|
|
|
|
gpio_num_t cs_io_num;
|
|
|
|
gpio_num_t rst_io_num;
|
|
|
|
gpio_num_t irq_io_num;
|
|
|
|
uint8_t tx_power;
|
|
|
|
sx127x_freq_t frequency;
|
|
|
|
sx127x_bw_t signal_bandwidth;
|
|
|
|
sx127x_sf_t spreading_factor;
|
|
|
|
uint8_t sync_word;
|
|
|
|
sx127x_crc_t crc;
|
|
|
|
sx127x_ldo_t ldo;
|
|
|
|
} sx127x_config_t;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
#define SX127X_CONFIG_DEFAULT \
|
|
|
|
{ \
|
|
|
|
.spi_host = VSPI_HOST, \
|
|
|
|
.mosi_io_num = 27, \
|
|
|
|
.miso_io_num = 19, \
|
|
|
|
.sck_io_num = 5, \
|
|
|
|
.cs_io_num = 18, \
|
|
|
|
.rst_io_num = 14, \
|
|
|
|
.irq_io_num = 26, \
|
|
|
|
.tx_power = 17, \
|
|
|
|
.frequency = SX127X_FREQ_433, \
|
|
|
|
.signal_bandwidth = 125E3, \
|
|
|
|
.spreading_factor = 11, \
|
|
|
|
.sync_word = 0x34, \
|
|
|
|
.crc = SX127X_CRC_ENABLED, \
|
|
|
|
.ldo = SX127X_LDO_DISABLED \
|
|
|
|
}
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
typedef struct sx127x sx127x_t;
|
|
|
|
|
|
|
|
esp_err_t sx127x_init(sx127x_config_t *config, sx127x_t **handle_ptr);
|
|
|
|
|
|
|
|
esp_err_t sx127x_free(sx127x_t *handle);
|
|
|
|
|
|
|
|
esp_err_t sx127x_set_frequency(sx127x_t *handle, uint64_t frequency);
|
|
|
|
|
|
|
|
esp_err_t sx127x_set_tx_power(sx127x_t *handle, uint8_t tx_power, sx127x_pa_boost_t pa_boost);
|
|
|
|
|
|
|
|
esp_err_t sx127x_set_spreading_factor(sx127x_t *handle, uint8_t spreading_factor);
|
|
|
|
|
|
|
|
esp_err_t sx127x_set_signal_bandwidth(sx127x_t *handle, uint64_t signal_bandwidth);
|
|
|
|
|
|
|
|
esp_err_t sx127x_set_sync_word(sx127x_t *handle, uint8_t sync_word);
|
|
|
|
|
|
|
|
esp_err_t sx127x_set_crc(sx127x_t *handle, sx127x_crc_t crc);
|
|
|
|
|
|
|
|
esp_err_t sx127x_sleep(sx127x_t *handle);
|
|
|
|
|
|
|
|
esp_err_t sx127x_standby(sx127x_t *handle);
|
|
|
|
|
|
|
|
esp_err_t sx127x_start(sx127x_t *handle);
|
|
|
|
|
|
|
|
esp_err_t sx127x_stop(sx127x_t *handle);
|