Loading...
Searching...
No Matches
lora.h
1
6
7#ifndef _LORA_H
8#define _LORA_H
9
10#include "stm32f439xx.h"
11#include "string.h"
12
13#include "devices.h"
14#include "spi.h"
15
16#define LORA_REG_FIFO 0x00
17#define LORA_REG_FIFO_ADDR_PTR 0x0D
18#define LORA_REG_FIFO_TX_BASE_ADDR 0x0E
19#define LORA_REG_FIFO_RX_BASE_ADDR 0x0F
20#define LORA_REG_FIFO_RX_CURR_ADDR 0x10
21#define LORA_REG_IRQ_FLAGS_MASK 0x11
22#define LORA_REG_IRQ_FLAGS 0x12
23
24#define LORA_REG_OP_MODE 0x01
25#define LORA_REG_OP_MODE_LONG_RANGE_Pos 0x07
26#define LORA_REG_OP_MODE_MODE_Pos 0x00
27
28#define LORA_REG_MODEM_CONFIG1 0x1D
29#define LORA_REG_MODEM_CONFIG1_BW_Pos 0x06
30#define LORA_REG_MODEM_CONFIG1_CR_Pos 0x03
31#define LORA_REG_MODEM_CONFIG1_CRC_Pos 0x01
32
33#define LORA_REG_MODEM_CONFIG2 0x1E
34#define LORA_REG_MODEM_CONFIG2_SF_Pos 0x04
35
36#define LORA_REG_PAYLOAD_LENGTH 0x22
37#define LORA_REG_MAX_PAYLOAD_LENGTH 0x23
38
39#define RegSymbTimeoutLsb 0x1F
40#define RegPreambleMsb 0x20
41#define RegPreambleLsb 0x21
42#define RegHopPeriod 0x24
43#define RegFifoRxByteAddr 0x25
44#define RegDioMapping1 0x40
45#define RegDioMapping2 0x41
46
47#define LORA_MSG_LENGTH 0x20
48#define LORA_MSG_PAYLOAD_LENGTH (LORA_MSG_LENGTH - 1)
49
54
55typedef enum {
56 BW125,
57 BW250,
58 BW500,
59} Bandwidth;
60
61typedef enum {
62 CR5 = 1,
63 CR6,
64 CR7,
65 CR8,
66} CodingRate;
67
68typedef enum {
69 SF6 = 6,
70 SF7,
71 SF8,
72 SF9,
73 SF10,
74 SF11,
75 SF12,
76} SpreadingFactor;
77
78typedef enum {
79 SLEEP,
80 STDBY,
81 FSTX,
82 TX,
83 FSRX,
84 RXCONTINUOUS,
85 RXSINGLE,
86 CAD
87} Mode;
88
89typedef struct {
90 uint8_t id;
91 uint8_t data[LORA_MSG_PAYLOAD_LENGTH];
93
95typedef struct LoRa {
97 void (*transmit)(struct LoRa *, uint8_t *);
98} LoRa;
99
100DeviceHandle_t LoRa_init(LoRa *, char[DEVICE_NAME_LENGTH], GPIO_TypeDef *, unsigned long, Bandwidth, SpreadingFactor, CodingRate);
101void LoRa_transmit(LoRa *, uint8_t *);
102void LoRa_writeRegister(LoRa *, uint8_t, uint8_t);
103uint8_t LoRa_readRegister(LoRa *, uint8_t);
104
106 uint8_t,
107 uint8_t,
108 uint8_t *,
109 uint8_t *,
110 uint8_t,
111 uint8_t *,
112 uint8_t,
113 float,
114 float
115);
116LoRa_Packet LoRa_GPSData(uint8_t, char *, char *, uint8_t);
117LoRa_Packet LoRa_PayloadData(uint8_t, uint8_t, uint8_t *, uint8_t);
118
119void _LoRa_setMode(LoRa *, Mode);
120
122#endif
uint8_t id
Packet header ID.
Definition lora.h:90
uint8_t data[LORA_MSG_PAYLOAD_LENGTH]
Packet payload.
Definition lora.h:91
DeviceHandle_t LoRa_init(LoRa *, char[DEVICE_NAME_LENGTH], GPIO_TypeDef *, unsigned long, Bandwidth, SpreadingFactor, CodingRate)
Initializes the LoRa module with specified configuration parameters.
Definition lora.c:37
LoRa_Packet LoRa_GPSData(uint8_t, char *, char *, uint8_t)
Definition lora.c:162
void _LoRa_setMode(LoRa *, Mode)
Sets the operational mode of the LoRa module.
Definition lora.c:94
LoRa_Packet LoRa_AVData(uint8_t, uint8_t, uint8_t *, uint8_t *, uint8_t, uint8_t *, uint8_t, float, float)
Constructs a LoRa packet with accelerometer and gyroscope data, altitude, and velocity for transmissi...
Definition lora.c:122
void LoRa_transmit(LoRa *, uint8_t *)
Transmits data using the LoRa module.
Definition lora.c:207
Definition lora.h:95
void(* transmit)(struct LoRa *, uint8_t *)
LoRa transmit method.
Definition lora.h:97
SPI base
Parent SPI interface.
Definition lora.h:96
Struct definition for SPI interface. Provides the interface for API consumers to interact with the SP...
Definition spi.h:49