F439_CPP_TX-RX_LoRa_Project
Loading...
Searching...
No Matches
sx1262.h
Go to the documentation of this file.
1
7#ifndef SX1262_H_
8#define SX1262_H_
9
10#pragma once
11
12#include "main.h"
13#include "stm32f4xx_hal.h"
14#include <stdint.h>
15#include <stdbool.h>
16
20typedef struct {
21 SPI_HandleTypeDef *hspi;
22
23 GPIO_TypeDef *NSS_Port;
24 uint16_t NSS_Pin;
25
26 GPIO_TypeDef *RESET_Port;
27 uint16_t RESET_Pin;
28
29 GPIO_TypeDef *BUSY_Port;
30 uint16_t BUSY_Pin;
31
32 GPIO_TypeDef *DIO1_Port;
33 uint16_t DIO1_Pin;
34
35 GPIO_TypeDef *RXEN_Port;
36 uint16_t RXEN_Pin;
37
38 GPIO_TypeDef *TXEN_Port;
39 uint16_t TXEN_Pin;
41
45typedef struct {
46 uint32_t rf_hz;
47 int8_t tx_dbm;
48
49 uint8_t sf; // 7..12
50 uint8_t bw; // 0=125k,1=250k,2=500k
51 uint8_t cr; // 1..4 => 4/5..4/8
52
53 uint16_t preamble_len;
54 bool crc_on;
57
61typedef struct {
62 bool rx_done;
63 bool tx_done;
65 bool timeout;
66
67 int8_t rssi_pkt;
68 int8_t snr_pkt;
69
70 uint8_t payload[256];
71 uint8_t payload_len;
73
82
83
96
109bool SX1262_SendString(SX1262_Handle *sx, const char *s);
139void SX1262_ClearIrq(SX1262_Handle *sx, uint16_t mask);
152bool SX1262_SendBuffer(SX1262_Handle *sx, const char *buf);
159bool SX1262_SendStringPlainText(SX1262_Handle *sx, const char *s);
167bool SX1262_SendBytes(SX1262_Handle *sx, const uint8_t *buf, uint8_t len);
168
169
170/*
171 * Call SX1262_ProcessIrq() when DIO1 interrupt fires.
172 * It reads/clears IRQ status, reads RX payload (if any), and re-arms continuous RX.
173 */
181
182
183
184#endif /* SX1262_H_ */
SX1262_Handle sx
Definition main.c:65
: Header for main.c file.This file contains the common defines of the application.
Hardware binding for a single SX1262 instance.
Definition sx1262.h:20
uint16_t DIO1_Pin
Definition sx1262.h:33
GPIO_TypeDef * NSS_Port
Definition sx1262.h:23
uint16_t BUSY_Pin
Definition sx1262.h:30
GPIO_TypeDef * RXEN_Port
Definition sx1262.h:35
uint16_t NSS_Pin
Definition sx1262.h:24
GPIO_TypeDef * DIO1_Port
Definition sx1262.h:32
SPI_HandleTypeDef * hspi
Definition sx1262.h:21
GPIO_TypeDef * BUSY_Port
Definition sx1262.h:29
uint16_t RESET_Pin
Definition sx1262.h:27
GPIO_TypeDef * RESET_Port
Definition sx1262.h:26
uint16_t TXEN_Pin
Definition sx1262.h:39
GPIO_TypeDef * TXEN_Port
Definition sx1262.h:38
uint16_t RXEN_Pin
Definition sx1262.h:36
IRQ processing result and optional received payload data.
Definition sx1262.h:61
bool timeout
Definition sx1262.h:65
bool crc_error
Definition sx1262.h:64
uint8_t payload_len
Definition sx1262.h:71
bool rx_done
Definition sx1262.h:62
bool tx_done
Definition sx1262.h:63
int8_t snr_pkt
Definition sx1262.h:68
int8_t rssi_pkt
Definition sx1262.h:67
LoRa modem configuration parameters.
Definition sx1262.h:45
uint8_t sf
Definition sx1262.h:49
uint32_t rf_hz
Definition sx1262.h:46
bool crc_on
Definition sx1262.h:54
uint16_t preamble_len
Definition sx1262.h:53
bool iq_invert
Definition sx1262.h:55
uint8_t cr
Definition sx1262.h:51
int8_t tx_dbm
Definition sx1262.h:47
uint8_t bw
Definition sx1262.h:50
bool SX1262_ProcessIrq(SX1262_Handle *sx, SX1262_IrqResult *out)
Process a DIO1-driven IRQ event.
Definition sx1262.c:688
bool SX1262_SendBuffer(SX1262_Handle *sx, const char *buf)
Send a character buffer through the radio.
Definition sx1262.c:603
bool SX1262_SetStandbyRc(SX1262_Handle *sx)
Put the radio into RC standby mode.
Definition sx1262.c:849
uint16_t SX1262_GetIrqStatusRaw(SX1262_Handle *sx)
Read the raw IRQ status bits.
Definition sx1262.c:788
bool SX1262_TxDonePoll(SX1262_Handle *sx)
Poll for TX completion.
uint16_t SX1262_ClearAndReadIrq(SX1262_Handle *sx)
Read and clear IRQ status bits.
bool SX1262_SendString(SX1262_Handle *sx, const char *s)
Send a NUL-terminated string through the radio.
Definition sx1262.c:400
bool SX1262_ConfigureLoRa(SX1262_Handle *sx, const SX1262_LoRaConfig *cfg)
Configure the SX1262 for LoRa operation.
Definition sx1262.c:258
SX1262_TxPollResult
Polling result for TX completion helper logic.
Definition sx1262.h:77
@ SX1262_TXPOLL_TIMEOUT
Definition sx1262.h:80
@ SX1262_TXPOLL_NONE
Definition sx1262.h:78
@ SX1262_TXPOLL_DONE
Definition sx1262.h:79
bool SX1262_SendStringPlainText(SX1262_Handle *sx, const char *s)
Send a plaintext string without RadioLink framing.
Definition sx1262.c:419
bool SX1262_StartRxContinuous(SX1262_Handle *sx)
Enter continuous receive mode.
Definition sx1262.c:388
bool SX1262_SendBytes(SX1262_Handle *sx, const uint8_t *buf, uint8_t len)
Send a raw byte buffer through the radio.
Definition sx1262.c:517
void SX1262_ClearIrq(SX1262_Handle *sx, uint16_t mask)
Clear selected IRQ bits.
Definition sx1262.c:831
uint8_t SX1262_GetStatusRaw(SX1262_Handle *sx)
Read the raw radio status byte.
Definition sx1262.c:766
void SX1262_Init(SX1262_Handle *sx)
Initialize the SX1262 hardware interface.
Definition sx1262.c:228