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
20 typedef 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;
40} SX1262_Handle;
41
45 typedef 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;
55 bool iq_invert;
56} SX1262_LoRaConfig;
57
61 typedef struct {
62 bool rx_done;
63 bool tx_done;
64 bool crc_error;
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;
72} SX1262_IrqResult;
73
77 typedef enum {
78 SX1262_TXPOLL_NONE = 0,
79 SX1262_TXPOLL_DONE,
80 SX1262_TXPOLL_TIMEOUT
81} SX1262_TxPollResult;
82
83
88 void SX1262_Init(SX1262_Handle *sx);
95 bool SX1262_ConfigureLoRa(SX1262_Handle *sx, const SX1262_LoRaConfig *cfg);
96
102 bool SX1262_StartRxContinuous(SX1262_Handle *sx);
109 bool SX1262_SendString(SX1262_Handle *sx, const char *s);
115uint8_t SX1262_GetStatusRaw(SX1262_Handle *sx);
121uint16_t SX1262_GetIrqStatusRaw(SX1262_Handle *sx);
127uint16_t SX1262_ClearAndReadIrq(SX1262_Handle *sx);
133 bool SX1262_TxDonePoll(SX1262_Handle *sx);
139 void SX1262_ClearIrq(SX1262_Handle *sx, uint16_t mask);
145 bool SX1262_SetStandbyRc(SX1262_Handle *sx);
152 bool SX1262_SendBuffer(SX1262_Handle *sx, const char *buf);
159 bool SX1262_SendStringPlainText(SX1262_Handle *sx, const char *s);
167 bool 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 */
180 bool SX1262_ProcessIrq(SX1262_Handle *sx, SX1262_IrqResult *out);
181
182
183
184#endif /* SX1262_H_ */
sx
SX1262_Handle sx
Definition main.c:65
main.h
: Header for main.c file.This file contains the common defines of the application.
SX1262_Handle
Hardware binding for a single SX1262 instance.
Definition sx1262.h:20
SX1262_Handle::DIO1_Pin
uint16_t DIO1_Pin
Definition sx1262.h:33
SX1262_Handle::NSS_Port
GPIO_TypeDef * NSS_Port
Definition sx1262.h:23
SX1262_Handle::BUSY_Pin
uint16_t BUSY_Pin
Definition sx1262.h:30
SX1262_Handle::RXEN_Port
GPIO_TypeDef * RXEN_Port
Definition sx1262.h:35
SX1262_Handle::NSS_Pin
uint16_t NSS_Pin
Definition sx1262.h:24
SX1262_Handle::DIO1_Port
GPIO_TypeDef * DIO1_Port
Definition sx1262.h:32
SX1262_Handle::hspi
SPI_HandleTypeDef * hspi
Definition sx1262.h:21
SX1262_Handle::BUSY_Port
GPIO_TypeDef * BUSY_Port
Definition sx1262.h:29
SX1262_Handle::RESET_Pin
uint16_t RESET_Pin
Definition sx1262.h:27
SX1262_Handle::RESET_Port
GPIO_TypeDef * RESET_Port
Definition sx1262.h:26
SX1262_Handle::TXEN_Pin
uint16_t TXEN_Pin
Definition sx1262.h:39
SX1262_Handle::TXEN_Port
GPIO_TypeDef * TXEN_Port
Definition sx1262.h:38
SX1262_Handle::RXEN_Pin
uint16_t RXEN_Pin
Definition sx1262.h:36
SX1262_IrqResult
IRQ processing result and optional received payload data.
Definition sx1262.h:61
SX1262_IrqResult::timeout
bool timeout
Definition sx1262.h:65
SX1262_IrqResult::crc_error
bool crc_error
Definition sx1262.h:64
SX1262_IrqResult::payload_len
uint8_t payload_len
Definition sx1262.h:71
SX1262_IrqResult::rx_done
bool rx_done
Definition sx1262.h:62
SX1262_IrqResult::tx_done
bool tx_done
Definition sx1262.h:63
SX1262_IrqResult::snr_pkt
int8_t snr_pkt
Definition sx1262.h:68
SX1262_IrqResult::rssi_pkt
int8_t rssi_pkt
Definition sx1262.h:67
SX1262_LoRaConfig
LoRa modem configuration parameters.
Definition sx1262.h:45
SX1262_LoRaConfig::sf
uint8_t sf
Definition sx1262.h:49
SX1262_LoRaConfig::rf_hz
uint32_t rf_hz
Definition sx1262.h:46
SX1262_LoRaConfig::crc_on
bool crc_on
Definition sx1262.h:54
SX1262_LoRaConfig::preamble_len
uint16_t preamble_len
Definition sx1262.h:53
SX1262_LoRaConfig::iq_invert
bool iq_invert
Definition sx1262.h:55
SX1262_LoRaConfig::cr
uint8_t cr
Definition sx1262.h:51
SX1262_LoRaConfig::tx_dbm
int8_t tx_dbm
Definition sx1262.h:47
SX1262_LoRaConfig::bw
uint8_t bw
Definition sx1262.h:50
SX1262_ProcessIrq
bool SX1262_ProcessIrq(SX1262_Handle *sx, SX1262_IrqResult *out)
Process a DIO1-driven IRQ event.
Definition sx1262.c:688
SX1262_SendBuffer
bool SX1262_SendBuffer(SX1262_Handle *sx, const char *buf)
Send a character buffer through the radio.
Definition sx1262.c:603
SX1262_SetStandbyRc
bool SX1262_SetStandbyRc(SX1262_Handle *sx)
Put the radio into RC standby mode.
Definition sx1262.c:849
SX1262_GetIrqStatusRaw
uint16_t SX1262_GetIrqStatusRaw(SX1262_Handle *sx)
Read the raw IRQ status bits.
Definition sx1262.c:788
SX1262_TxDonePoll
bool SX1262_TxDonePoll(SX1262_Handle *sx)
Poll for TX completion.
SX1262_ClearAndReadIrq
uint16_t SX1262_ClearAndReadIrq(SX1262_Handle *sx)
Read and clear IRQ status bits.
SX1262_SendString
bool SX1262_SendString(SX1262_Handle *sx, const char *s)
Send a NUL-terminated string through the radio.
Definition sx1262.c:400
SX1262_ConfigureLoRa
bool SX1262_ConfigureLoRa(SX1262_Handle *sx, const SX1262_LoRaConfig *cfg)
Configure the SX1262 for LoRa operation.
Definition sx1262.c:258
SX1262_TxPollResult
SX1262_TxPollResult
Polling result for TX completion helper logic.
Definition sx1262.h:77
SX1262_TXPOLL_TIMEOUT
@ SX1262_TXPOLL_TIMEOUT
Definition sx1262.h:80
SX1262_TXPOLL_NONE
@ SX1262_TXPOLL_NONE
Definition sx1262.h:78
SX1262_TXPOLL_DONE
@ SX1262_TXPOLL_DONE
Definition sx1262.h:79
SX1262_SendStringPlainText
bool SX1262_SendStringPlainText(SX1262_Handle *sx, const char *s)
Send a plaintext string without RadioLink framing.
Definition sx1262.c:419
SX1262_StartRxContinuous
bool SX1262_StartRxContinuous(SX1262_Handle *sx)
Enter continuous receive mode.
Definition sx1262.c:388
SX1262_SendBytes
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
SX1262_ClearIrq
void SX1262_ClearIrq(SX1262_Handle *sx, uint16_t mask)
Clear selected IRQ bits.
Definition sx1262.c:831
SX1262_GetStatusRaw
uint8_t SX1262_GetStatusRaw(SX1262_Handle *sx)
Read the raw radio status byte.
Definition sx1262.c:766
SX1262_Init
void SX1262_Init(SX1262_Handle *sx)
Initialize the SX1262 hardware interface.
Definition sx1262.c:228