sx1280.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Inria
3  * Copyright (C) 2020-2022 Université Grenoble Alpes
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
10 #pragma once
11 
26 #include <assert.h>
27 
28 #include "sx1280_driver/src/sx1280_hal.h"
29 #include "sx1280_driver/src/sx1280.h"
30 #include "smtc_ral/src/ral.h"
31 #include "smtc_ral/src/ral_defs.h"
32 
33 #include "net/netdev.h"
34 
35 #include "periph/gpio.h"
36 #include "periph/spi.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
46 #define SX1280_CHANNEL_DEFAULT (2403000000UL)
47 #define SX1280_RADIO_TX_POWER (SX1280_PWR_MAX)
53 typedef struct sx1280 sx1280_t;
54 
58 typedef struct {
59  spi_t spi;
62  gpio_t nss_pin;
63  gpio_t reset_pin;
64  gpio_t busy_pin;
65  gpio_t dio0_pin;
66  gpio_t dio1_pin;
67  sx1280_reg_mod_t regulator;
69 
73 struct sx1280 {
75  ral_t ral;
76  ral_params_lora_t ral_params_lora;
78  sx1280_hal_operating_mode_t mode;
79 };
80 
89 void sx1280_setup(sx1280_t *dev, const sx1280_params_t *params, uint8_t index);
90 
99 
107 uint32_t sx1280_get_channel(const sx1280_t *dev);
108 
116 uint32_t sx1280_random(const sx1280_t *dev);
123 void sx1280_set_channel(sx1280_t *dev, uint32_t freq);
124 
132 uint32_t sx1280_get_bandwidth(const sx1280_t *dev);
133 
140 void sx1280_set_bandwidth(sx1280_t *dev, uint16_t bandwidth);
141 
150 
157 void sx1280_set_spreading_factor(sx1280_t *dev, uint8_t sf);
158 
166 uint8_t sx1280_get_coding_rate(const sx1280_t *dev);
167 
174 void sx1280_set_coding_rate(sx1280_t *dev, uint8_t cr);
175 
184 
191 void sx1280_set_lora_payload_length(sx1280_t *dev, uint8_t len);
192 
200 bool sx1280_get_lora_crc(const sx1280_t *dev);
201 
208 void sx1280_set_lora_crc(sx1280_t *dev, bool crc);
209 
218 
226 
235 
242 void sx1280_set_lora_preamble_length(sx1280_t *dev, uint16_t preamble);
243 
252 
259 void sx1280_set_lora_iq_invert(sx1280_t *dev, bool iq_invert);
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 
POSIX.1-2008 compliant version of the assert macro.
spi_clk_t
Definition: periph_cpu.h:351
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
uint32_t sx1280_get_bandwidth(const sx1280_t *dev)
Gets the LoRa bandwidth.
uint32_t sx1280_get_channel(const sx1280_t *dev)
Gets the channel RF frequency.
bool sx1280_get_lora_iq_invert(const sx1280_t *dev)
Checks if the LoRa inverted IQ mode is enabled/disabled.
void sx1280_setup(sx1280_t *dev, const sx1280_params_t *params, uint8_t index)
Setup the radio device.
bool sx1280_get_lora_crc(const sx1280_t *dev)
Checks if CRC verification mode is enabled.
void sx1280_set_channel(sx1280_t *dev, uint32_t freq)
Sets the channel RF frequency.
uint32_t sx1280_random(const sx1280_t *dev)
Gets a random number.
uint8_t sx1280_get_lora_payload_length(const sx1280_t *dev)
Gets the payload length.
void sx1280_set_lora_payload_length(sx1280_t *dev, uint8_t len)
Sets the payload length.
void sx1280_set_bandwidth(sx1280_t *dev, uint16_t bandwidth)
Sets the LoRa bandwidth.
bool sx1280_get_lora_implicit_header(const sx1280_t *dev)
Gets the LoRa implicit header mode.
void sx1280_set_lora_preamble_length(sx1280_t *dev, uint16_t preamble)
Sets the LoRa preamble length.
uint8_t sx1280_get_coding_rate(const sx1280_t *dev)
Gets the LoRa coding rate.
uint8_t sx1280_get_spreading_factor(const sx1280_t *dev)
Gets the LoRa spreading factor.
void sx1280_set_lora_iq_invert(sx1280_t *dev, bool iq_invert)
Enable/disable the LoRa IQ inverted mode.
int sx1280_init(sx1280_t *dev)
Initialize the given device.
void sx1280_set_spreading_factor(sx1280_t *dev, uint8_t sf)
Sets the LoRa spreading factor.
void sx1280_set_lora_crc(sx1280_t *dev, bool crc)
Enable/Disable CRC verification mode.
void sx1280_set_lora_implicit_header(sx1280_t *dev, bool mode)
Sets LoRa implicit header mode.
void sx1280_set_coding_rate(sx1280_t *dev, uint8_t cr)
Sets the LoRa coding rate.
uint16_t sx1280_get_lora_preamble_length(const sx1280_t *dev)
Gets the LoRa preamble length.
spi_mode_t
Support SPI modes.
Definition: periph_cpu.h:42
Low-level SPI peripheral driver interface definition.
Structure to hold driver state.
Definition: netdev.h:364
Device initialization parameters.
Definition: sx1280.h:58
gpio_t busy_pin
Busy pin.
Definition: sx1280.h:64
sx1280_reg_mod_t regulator
Power regulator mode.
Definition: sx1280.h:67
spi_t spi
SPI device.
Definition: sx1280.h:59
spi_clk_t spi_clk
SPI clk.
Definition: sx1280.h:61
gpio_t nss_pin
SPI NSS pin.
Definition: sx1280.h:62
gpio_t dio0_pin
Dio0 pin.
Definition: sx1280.h:65
gpio_t dio1_pin
Dio1 pin.
Definition: sx1280.h:66
gpio_t reset_pin
Reset pin.
Definition: sx1280.h:63
spi_mode_t spi_mode
SPI mode.
Definition: sx1280.h:60
Device descriptor for the driver.
Definition: sx1280.h:73
sx1280_params_t * params
Initialization parameters.
Definition: sx1280.h:77
sx1280_hal_operating_mode_t mode
Operating Mode.
Definition: sx1280.h:78
ral_params_lora_t ral_params_lora
LoRa modulation parameters.
Definition: sx1280.h:76
ral_t ral
Radio abstraction.
Definition: sx1280.h:75
netdev_t netdev
Netdev parent struct.
Definition: sx1280.h:74