sx126x.h 的完整代码
时间: 2023-12-21 22:05:45 浏览: 112
新一代Lora芯片sx126x的驱动源码
由于sx126x.h是Semtech SX126x系列芯片的头文件,其完整代码需要Semtech提供的SDK才能获得。以下是一个可供参考的sx126x.h文件的代码示例,但这并不是完整的代码:
```c
#ifndef __SX126X_H__
#define __SX126X_H__
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
typedef void (*DioIrqHandler)(void);
typedef struct sx126x_s
{
uint8_t spiIndex;
uint8_t chipSelectPin;
uint8_t busyPin;
uint8_t dio1Pin;
uint8_t dio2Pin;
uint8_t dio3Pin;
uint8_t antSwitchTxPin;
uint8_t antSwitchRxPin;
uint32_t txTimeout;
uint32_t rxTimeout;
uint32_t rxDelay;
bool tcxoOn;
bool debug;
bool initialized;
} sx126x_t;
typedef enum sx126x_status_e
{
SX126X_STATUS_OK,
SX126X_STATUS_ERROR,
SX126X_STATUS_BUSY,
SX126X_STATUS_TIMEOUT,
SX126X_STATUS_UNSUPPORTED_FEATURE,
SX126X_STATUS_DEVICE_NOT_FOUND,
} sx126x_status_t;
typedef enum sx126x_pa_cfg_e
{
SX126X_PA_CFG_HP,
SX126X_PA_CFG_LP,
} sx126x_pa_cfg_t;
typedef enum sx126x_lna_cfg_e
{
SX126X_LNA_CFG_LF,
SX126X_LNA_CFG_HF,
} sx126x_lna_cfg_t;
typedef enum sx126x_rx_bw_e
{
SX126X_RX_BW_200_0_KHZ,
SX126X_RX_BW_400_0_KHZ,
SX126X_RX_BW_600_0_KHZ,
SX126X_RX_BW_800_0_KHZ,
SX126X_RX_BW_1000_0_KHZ,
SX126X_RX_BW_1200_0_KHZ,
SX126X_RX_BW_1400_0_KHZ,
SX126X_RX_BW_1600_0_KHZ,
SX126X_RX_BW_1800_0_KHZ,
SX126X_RX_BW_2000_0_KHZ,
SX126X_RX_BW_2200_0_KHZ,
SX126X_RX_BW_2400_0_KHZ,
SX126X_RX_BW_2600_0_KHZ,
SX126X_RX_BW_2800_0_KHZ,
SX126X_RX_BW_3000_0_KHZ,
} sx126x_rx_bw_t;
typedef enum sx126x_tx_bw_e
{
SX126X_TX_BW_200_0_KHZ,
SX126X_TX_BW_400_0_KHZ,
SX126X_TX_BW_600_0_KHZ,
SX126X_TX_BW_800_0_KHZ,
SX126X_TX_BW_1000_0_KHZ,
SX126X_TX_BW_1200_0_KHZ,
SX126X_TX_BW_1400_0_KHZ,
SX126X_TX_BW_1600_0_KHZ,
SX126X_TX_BW_1800_0_KHZ,
SX126X_TX_BW_2000_0_KHZ,
SX126X_TX_BW_2200_0_KHZ,
SX126X_TX_BW_2400_0_KHZ,
SX126X_TX_BW_2600_0_KHZ,
SX126X_TX_BW_2800_0_KHZ,
SX126X_TX_BW_3000_0_KHZ,
} sx126x_tx_bw_t;
typedef enum sx126x_sf_e
{
SX126X_SF5,
SX126X_SF6,
SX126X_SF7,
SX126X_SF8,
SX126X_SF9,
SX126X_SF10,
SX126X_SF11,
SX126X_SF12,
} sx126x_sf_t;
typedef enum sx126x_cr_e
{
SX126X_CR_4_5,
SX126X_CR_4_6,
SX126X_CR_4_7,
SX126X_CR_4_8,
SX126X_CR_LI_4_5,
SX126X_CR_LI_4_6,
SX126X_CR_LI_4_7,
SX126X_CR_LI_4_8,
} sx126x_cr_t;
typedef enum sx126x_ldro_e
{
SX126X_LDRO_DEFAULT,
SX126X_LDRO_ON,
SX126X_LDRO_OFF,
} sx126x_ldro_t;
typedef enum sx126x_pa_ramp_e
{
SX126X_PA_RAMP_10_US,
SX126X_PA_RAMP_20_US,
SX126X_PA_RAMP_40_US,
SX126X_PA_RAMP_80_US,
SX126X_PA_RAMP_200_US,
SX126X_PA_RAMP_800_US,
SX126X_PA_RAMP_1700_US,
} sx126x_pa_ramp_t;
typedef enum sx126x_clk_out_e
{
SX126X_CLK_OUT_OFF,
SX126X_CLK_OUT_32_MHZ,
SX126X_CLK_OUT_16_MHZ,
SX126X_CLK_OUT_8_MHZ,
SX126X_CLK_OUT_4_MHZ,
} sx126x_clk_out_t;
typedef enum sx126x_gfsk_bt_e
{
SX126X_GFSK_BT_0_5,
SX126X_GFSK_BT_0_6,
SX126X_GFSK_BT_0_7,
SX126X_GFSK_BT_0_8,
SX126X_GFSK_BT_1_0,
SX126X_GFSK_BT_1_2,
SX126X_GFSK_BT_1_5,
SX126X_GFSK_BT_2_0,
} sx126x_gfsk_bt_t;
typedef enum sx126x_packet_e
{
SX126X_PACKET_TYPE_GFSK,
SX126X_PACKET_TYPE_LORA,
} sx126x_packet_t;
typedef struct sx126x_gfsk_pkt_params_s
{
uint8_t preambleLength;
sx126x_sync_word_length_t syncWordLength;
sx126x_crc_type_t crcType;
sx126x_whitening_t whitening;
sx126x_gfsk_bt_t bt;
uint16_t headerLength;
uint16_t payloadLength;
uint8_t crcSeed;
bool fixedLength;
bool crcAutoClearOff;
bool dcFree;
} sx126x_gfsk_pkt_params_t;
typedef enum sx126x_lora_pkt_len_mode_e
{
SX126X_LORA_PKT_FIXED_LEN,
SX126X_LORA_PKT_VARIABLE_LEN,
} sx126x_lora_pkt_len_mode_t;
typedef struct sx126x_lora_pkt_params_s
{
sx126x_lora_pkt_len_mode_t lenMode;
uint8_t preambleLength;
sx126x_sync_word_length_t syncWordLength;
sx126x_crc_type_t crcType;
uint32_t payloadLength;
uint8_t preambleSymbolLength;
bool invertIQ;
} sx126x_lora_pkt_params_t;
typedef struct sx126x_pkt_params_s
{
sx126x_packet_t pktType;
union
{
sx126x_gfsk_pkt_params_t gfsk;
sx126x_lora_pkt_params_t lora;
} params;
} sx126x_pkt_params_t;
typedef enum sx126x_tx_done_e
{
SX126X_TX_DONE,
SX126X_TX_ERR,
} sx126x_tx_done_t;
typedef struct sx126x_packet_status_s
{
sx126x_rx_bw_t bw;
sx126x_sf_t sf;
sx126x_cr_t cr;
bool crcOk;
bool iqInverted;
uint8_t rxChain;
} sx126x_packet_status_t;
sx126x_status_t sx126x_init(sx126x_t* sx126x);
sx126x_status_t sx126x_reset(sx126x_t* sx126x);
sx126x_status_t sx126x_get_status(sx126x_t* sx126x);
sx126x_status_t sx126x_set_packet_type(sx126x_t* sx126x, sx126x_packet_t packetType);
sx126x_status_t sx126x_set_rf_freq(sx126x_t* sx126x, uint32_t frequency);
sx126x_status_t sx126x_set_tx_params(sx126x_t* sx126x, int8_t power, sx126x_pa_cfg_t paConfig, sx126x_pa_ramp_t paRamp, uint32_t timeout);
sx126x_status_t sx126x_set_rx_params(sx126x_t* sx126x, sx126x_rx_bw_t bw, sx126x_sf_t sf, sx126x_cr_t cr, sx126x_ldro_t ldro, uint16_t symbTimeout, uint32_t preambleLength);
sx126x_status_t sx126x_set_gfsk_pkt_params(sx126x_t* sx126x, sx126x_gfsk_pkt_params_t* pktParams);
sx126x_status_t sx126x_set_lora_pkt_params(sx126x_t* sx126x, sx126x_lora_pkt_params_t* pktParams);
sx126x_status_t sx126x_send_payload(sx126x_t* sx126x, uint8_t* payload, uint8_t size, uint32_t timeout);
sx126x_status_t sx126x_set_dio_irq_params(sx126x_t* sx126x, uint16_t irqMask, uint16_t dio1Mask, DioIrqHandler irqHandler);
sx126x_status_t sx126x_clear_irq_status(sx126x_t* sx126x, uint16_t irqMask);
sx126x_status_t sx126x_get_packet_status(sx126x_t* sx126x, sx126x_packet_status_t* pktStatus);
#endif
```
注意:这只是一个示例代码,其中的具体实现细节和函数定义可能与Semtech提供的SDK不完全相同。建议在实际使用中参考Semtech提供的官方文档和示例代码。
阅读全文