sx1261/2 driver
Dependents: alarm_slave iq_sx126x sx126x_simple_TX_shield_2020a sx126x_simple_RX_shield_2020a ... more
Driver for SX1261 or SX1262
sx12xx.h@11:1cd95e76519a, 2020-03-04 (annotated)
- Committer:
- dudmuck
- Date:
- Wed Mar 04 19:59:06 2020 +0000
- Revision:
- 11:1cd95e76519a
- Parent:
- 10:8905722dd5e6
- Child:
- 12:7a3ec8bb8407
add sigma-delta mode register for transmitting 500KHz-sf12 LoRa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
1:497af0bd9e53 | 1 | #include "mbed.h" |
Wayne Roberts |
1:497af0bd9e53 | 2 | #ifndef SX126x_H |
Wayne Roberts |
1:497af0bd9e53 | 3 | #define SX126x_H |
Wayne Roberts |
1:497af0bd9e53 | 4 | |
Wayne Roberts |
1:497af0bd9e53 | 5 | #define RC_TICKS_PER_MS 0.015625 /* 64KHz */ |
Wayne Roberts |
1:497af0bd9e53 | 6 | #define RC_TICKS_PER_US 15.625 /* 64KHz */ |
Wayne Roberts |
1:497af0bd9e53 | 7 | |
Wayne Roberts |
2:e6e159c8ab4d | 8 | #define XTAL_FREQ_HZ 32000000 |
Wayne Roberts |
1:497af0bd9e53 | 9 | #define FREQ_DIV 33554432 |
Wayne Roberts |
1:497af0bd9e53 | 10 | #define FREQ_STEP 0.95367431640625 // ( ( double )( XTAL_FREQ / ( double )FREQ_DIV ) ) |
Wayne Roberts |
2:e6e159c8ab4d | 11 | #define MHZ_TO_FRF 1048576 // = (1<<25) / Fxtal_MHz |
Wayne Roberts |
2:e6e159c8ab4d | 12 | #define KHZ_TO_FRF 1048.576 |
Wayne Roberts |
7:fe8c0186ee50 | 13 | #define HZ_TO_FRF 1.048576 // = (1<<25) / Fxtal_Hz |
Wayne Roberts |
1:497af0bd9e53 | 14 | |
Wayne Roberts |
1:497af0bd9e53 | 15 | /***************************************************************/ |
Wayne Roberts |
10:8905722dd5e6 | 16 | #define OPCODE_RESET_STATS 0x00 |
Wayne Roberts |
1:497af0bd9e53 | 17 | #define OPCODE_CLEAR_IRQ_STATUS 0x02 |
Wayne Roberts |
1:497af0bd9e53 | 18 | #define OPCODE_CLEAR_DEVICE_ERRORS 0x07 |
Wayne Roberts |
1:497af0bd9e53 | 19 | #define OPCODE_SET_DIO_IRQ_PARAMS 0x08 |
Wayne Roberts |
1:497af0bd9e53 | 20 | #define OPCODE_WRITE_REGISTER 0x0d |
Wayne Roberts |
1:497af0bd9e53 | 21 | #define OPCODE_WRITE_BUFFER 0x0e |
Wayne Roberts |
10:8905722dd5e6 | 22 | #define OPCODE_GET_STATS 0x10 |
Wayne Roberts |
1:497af0bd9e53 | 23 | #define OPCODE_GET_PACKET_TYPE 0x11 |
Wayne Roberts |
1:497af0bd9e53 | 24 | #define OPCODE_GET_IRQ_STATUS 0x12 |
Wayne Roberts |
1:497af0bd9e53 | 25 | #define OPCODE_GET_RX_BUFFER_STATUS 0x13 |
Wayne Roberts |
1:497af0bd9e53 | 26 | #define OPCODE_GET_PACKET_STATUS 0x14 |
Wayne Roberts |
1:497af0bd9e53 | 27 | #define OPCODE_GET_RSSIINST 0x15 |
Wayne Roberts |
1:497af0bd9e53 | 28 | #define OPCODE_GET_DEVICE_ERRORS 0x17 |
Wayne Roberts |
1:497af0bd9e53 | 29 | #define OPCODE_READ_REGISTER 0x1d |
Wayne Roberts |
1:497af0bd9e53 | 30 | #define OPCODE_READ_BUFFER 0x1e |
Wayne Roberts |
1:497af0bd9e53 | 31 | #define OPCODE_SET_STANDBY 0x80 |
Wayne Roberts |
1:497af0bd9e53 | 32 | #define OPCODE_SET_RX 0x82 |
Wayne Roberts |
1:497af0bd9e53 | 33 | #define OPCODE_SET_TX 0x83 |
Wayne Roberts |
1:497af0bd9e53 | 34 | #define OPCODE_SET_SLEEP 0x84 |
Wayne Roberts |
1:497af0bd9e53 | 35 | #define OPCODE_SET_RF_FREQUENCY 0x86 |
Wayne Roberts |
8:66d3e344d61c | 36 | #define OPCODE_SET_CAD_PARAM 0x88 |
Wayne Roberts |
1:497af0bd9e53 | 37 | #define OPCODE_CALIBRATE 0x89 |
Wayne Roberts |
1:497af0bd9e53 | 38 | #define OPCODE_SET_PACKET_TYPE 0x8a |
Wayne Roberts |
1:497af0bd9e53 | 39 | #define OPCODE_SET_MODULATION_PARAMS 0x8b |
Wayne Roberts |
1:497af0bd9e53 | 40 | #define OPCODE_SET_PACKET_PARAMS 0x8c |
Wayne Roberts |
1:497af0bd9e53 | 41 | #define OPCODE_SET_TX_PARAMS 0x8e |
Wayne Roberts |
1:497af0bd9e53 | 42 | #define OPCODE_SET_BUFFER_BASE_ADDR 0x8f |
Wayne Roberts |
10:8905722dd5e6 | 43 | #define OPCODE_SET_FALLBACK_MODE 0x93 |
Wayne Roberts |
10:8905722dd5e6 | 44 | #define OPCODE_SET_RX_DUTY_CYCLE 0x94 |
Wayne Roberts |
1:497af0bd9e53 | 45 | #define OPCODE_SET_PA_CONFIG 0x95 |
Wayne Roberts |
1:497af0bd9e53 | 46 | #define OPCODE_SET_REGULATOR_MODE 0x96 |
Wayne Roberts |
1:497af0bd9e53 | 47 | #define OPCODE_SET_DIO3_AS_TCXO_CTRL 0x97 |
Wayne Roberts |
10:8905722dd5e6 | 48 | #define OPCODE_CALIBRATE_IMAGE 0x98 |
Wayne Roberts |
1:497af0bd9e53 | 49 | #define OPCODE_SET_DIO2_AS_RFSWITCH 0x9d |
Wayne Roberts |
10:8905722dd5e6 | 50 | #define OPCODE_STOP_TIMER_ON_PREAMBLE 0x9f |
Wayne Roberts |
1:497af0bd9e53 | 51 | #define OPCODE_SET_LORA_SYMBOL_TIMEOUT 0xa0 |
Wayne Roberts |
1:497af0bd9e53 | 52 | #define OPCODE_GET_STATUS 0xc0 |
Wayne Roberts |
4:b941bceb401d | 53 | #define OPCODE_SET_FS 0xc1 |
Wayne Roberts |
8:66d3e344d61c | 54 | #define OPCODE_SET_CAD 0xc5 |
Wayne Roberts |
5:8b75387af4e0 | 55 | #define OPCODE_SET_TX_CARRIER 0xd1 |
Wayne Roberts |
5:8b75387af4e0 | 56 | #define OPCODE_SET_TX_PREAMBLE 0xd2 |
Wayne Roberts |
1:497af0bd9e53 | 57 | /***************************************************************/ |
Wayne Roberts |
3:f6f2f8adcd22 | 58 | #define PACKET_TYPE_GFSK 0 |
Wayne Roberts |
1:497af0bd9e53 | 59 | #define PACKET_TYPE_LORA 1 |
Wayne Roberts |
1:497af0bd9e53 | 60 | |
Wayne Roberts |
1:497af0bd9e53 | 61 | #define HEADER_TYPE_VARIABLE_LENGTH 0 |
Wayne Roberts |
1:497af0bd9e53 | 62 | #define HEADER_TYPE_FIXED_LENGTH 1 |
Wayne Roberts |
1:497af0bd9e53 | 63 | |
Wayne Roberts |
5:8b75387af4e0 | 64 | #define LROA_CRC_OFF 0 |
Wayne Roberts |
5:8b75387af4e0 | 65 | #define LORA_CRC_ON 1 |
Wayne Roberts |
1:497af0bd9e53 | 66 | |
Wayne Roberts |
1:497af0bd9e53 | 67 | #define STANDARD_IQ 0 |
Wayne Roberts |
1:497af0bd9e53 | 68 | #define INVERTED_IQ 1 |
Wayne Roberts |
1:497af0bd9e53 | 69 | |
Wayne Roberts |
1:497af0bd9e53 | 70 | /* direct register access */ |
Wayne Roberts |
2:e6e159c8ab4d | 71 | #define REG_ADDR_IRQ_STATUS 0x58a // 16bit |
Wayne Roberts |
2:e6e159c8ab4d | 72 | #define REG_ADDR_IRQ_MASK 0x58c // 16bit |
Wayne Roberts |
2:e6e159c8ab4d | 73 | #define REG_ADDR_MODCFG 0x680 // 8bit |
Wayne Roberts |
2:e6e159c8ab4d | 74 | #define REG_ADDR_BITRATE 0x6a1 // 24bit fsk |
Wayne Roberts |
2:e6e159c8ab4d | 75 | #define REG_ADDR_FREQDEV 0x6a4 // 18bit fsk |
Wayne Roberts |
2:e6e159c8ab4d | 76 | #define REG_ADDR_SHAPECFG 0x6a7 // 5bit |
Wayne Roberts |
7:fe8c0186ee50 | 77 | #define REG_ADDR_FSK_DEMOD_CFO 0x6b0 // 12bit center frequency offset |
Wayne Roberts |
2:e6e159c8ab4d | 78 | #define REG_ADDR_FSK_PKTCTRL0 0x6b3 // 8bit |
Wayne Roberts |
2:e6e159c8ab4d | 79 | #define REG_ADDR_FSK_PKTCTRL1 0x6b4 // 3bit |
Wayne Roberts |
2:e6e159c8ab4d | 80 | #define REG_ADDR_FSK_PREAMBLE_TXLEN 0x6b5 // 16bit |
Wayne Roberts |
2:e6e159c8ab4d | 81 | #define REG_ADDR_FSK_SYNC_LEN 0x6b7 // 7bit |
Wayne Roberts |
5:8b75387af4e0 | 82 | #define REG_ADDR_FSK_PKTCTRL1A 0x6b8 // 14bit 5bits+9bits |
Wayne Roberts |
2:e6e159c8ab4d | 83 | #define REG_ADDR_FSK_PKTCTRL2 0x6ba // 8bit |
Wayne Roberts |
2:e6e159c8ab4d | 84 | #define REG_ADDR_FSK_PAYLOAD_LEN 0x6bb // 8bit |
Wayne Roberts |
5:8b75387af4e0 | 85 | #define REG_ADDR_FSK_CRCINIT 0x6bc // 16bit |
Wayne Roberts |
5:8b75387af4e0 | 86 | #define REG_ADDR_FSK_CRCPOLY 0x6be // 16bit |
Wayne Roberts |
2:e6e159c8ab4d | 87 | #define REG_ADDR_SYNCADDR 0x6c0 // 64bit fsk |
Wayne Roberts |
2:e6e159c8ab4d | 88 | #define REG_ADDR_NODEADDR 0x6cd // 8bit fsk |
Wayne Roberts |
5:8b75387af4e0 | 89 | #define REG_ADDR_BROADCAST 0x6ce // 8bit fsk |
Wayne Roberts |
2:e6e159c8ab4d | 90 | #define REG_ADDR_NODEADDRCOMP 0x6cf // 2bit fsk |
Wayne Roberts |
2:e6e159c8ab4d | 91 | |
Wayne Roberts |
2:e6e159c8ab4d | 92 | #define REG_ADDR_LORA_TXPKTLEN 0x702 // 8bit |
Wayne Roberts |
2:e6e159c8ab4d | 93 | #define REG_ADDR_LORA_CONFIG0 0x703 // 8bit bw/sf |
Wayne Roberts |
2:e6e159c8ab4d | 94 | #define REG_ADDR_LORA_CONFIG1 0x704 // 8bit ppm_offset, fixlen, invertiq, cr |
Wayne Roberts |
2:e6e159c8ab4d | 95 | #define REG_ADDR_LORA_CONFIG2 0x705 // 8bit crcType |
Wayne Roberts |
2:e6e159c8ab4d | 96 | #define REG_ADDR_LORA_IRQ_MASK 0x70a // 24bit |
Wayne Roberts |
8:66d3e344d61c | 97 | #define REG_ADDR_LORA_CONFIG9 0x724 // 8bit |
Wayne Roberts |
2:e6e159c8ab4d | 98 | #define REG_ADDR_LORA_PREAMBLE_SYMBNB 0x73a // 16bit |
Wayne Roberts |
8:66d3e344d61c | 99 | #define REG_ADDR_LORA_CAD_PN_RATIO 0x73e // 8bit |
Wayne Roberts |
8:66d3e344d61c | 100 | #define REG_ADDR_LORA_CAD_MINPEAK 0x73f // 8bit |
Wayne Roberts |
2:e6e159c8ab4d | 101 | #define REG_ADDR_LORA_SYNC 0x740 // config22, config23: frame sync peak position |
Wayne Roberts |
7:fe8c0186ee50 | 102 | #define REG_ADDR_LORA_STATUS 0x76b // |
Wayne Roberts |
2:e6e159c8ab4d | 103 | |
Wayne Roberts |
2:e6e159c8ab4d | 104 | #define REG_ADDR_DIGFECTL 0x804 // 6bits |
Wayne Roberts |
2:e6e159c8ab4d | 105 | #define REG_ADDR_BWSEL 0x807 // 5bits |
Wayne Roberts |
2:e6e159c8ab4d | 106 | #define REG_ADDR_RANDOM 0x819 // ro |
Wayne Roberts |
5:8b75387af4e0 | 107 | #define REG_ADDR_PA_CTRL0 0x880 // 8bits |
Wayne Roberts |
5:8b75387af4e0 | 108 | #define REG_ADDR_PA_CTRL1 0x881 // 8bits |
Wayne Roberts |
5:8b75387af4e0 | 109 | #define REG_ADDR_DIG_CTRL 0x882 // 8bits |
Wayne Roberts |
5:8b75387af4e0 | 110 | #define REG_ADDR_PWR_CTRL 0x883 // 8bits |
Wayne Roberts |
5:8b75387af4e0 | 111 | #define REG_ADDR_I_GAIN 0x884 // 8bits integral gain in pi filter |
Wayne Roberts |
5:8b75387af4e0 | 112 | #define REG_ADDR_P_GAIN 0x885 // 8bits proportional gain in pi filter |
dudmuck | 11:1cd95e76519a | 113 | #define REG_ADDR_SDCFG0 0x889 // |
Wayne Roberts |
2:e6e159c8ab4d | 114 | #define REG_ADDR_RFFREQ 0x88b // 31bits |
Wayne Roberts |
2:e6e159c8ab4d | 115 | #define REG_ADDR_FREQ_OFFSET 0x88f // 19bits |
Wayne Roberts |
2:e6e159c8ab4d | 116 | #define REG_ADDR_ANACTRL6 0x8d7 // 6bits |
Wayne Roberts |
2:e6e159c8ab4d | 117 | #define REG_ADDR_ANACTRL7 0x8d8 // 6bits |
Wayne Roberts |
2:e6e159c8ab4d | 118 | #define REG_ADDR_ANACTRL15 0x8e1 // 7bits |
Wayne Roberts |
9:34f1f2bbe7b3 | 119 | #define REG_ADDR_ANACTRL16 0x8e2 |
Wayne Roberts |
5:8b75387af4e0 | 120 | #define REG_ADDR_PA_CTRL1B 0x8e6 |
Wayne Roberts |
5:8b75387af4e0 | 121 | #define REG_ADDR_OCP 0x8e7 // 6bits Imax 2.5mA steps |
Wayne Roberts |
5:8b75387af4e0 | 122 | #define REG_ADDR_IMAX_OFFSET 0x8e8 // 5bits OCP offset |
Wayne Roberts |
9:34f1f2bbe7b3 | 123 | #define REG_ADDR_XTA_TRIM 0x911 // crystal trim only in xosc |
Wayne Roberts |
9:34f1f2bbe7b3 | 124 | #define REG_ADDR_XTB_TRIM 0x912 // crystal trim only in xosc |
Wayne Roberts |
2:e6e159c8ab4d | 125 | #define REG_ADDR_ 0x |
Wayne Roberts |
2:e6e159c8ab4d | 126 | |
Wayne Roberts |
2:e6e159c8ab4d | 127 | /**********************************************/ |
Wayne Roberts |
1:497af0bd9e53 | 128 | |
Wayne Roberts |
1:497af0bd9e53 | 129 | #define SET_RAMP_10U 0x00 |
Wayne Roberts |
1:497af0bd9e53 | 130 | #define SET_RAMP_20U 0x01 |
Wayne Roberts |
1:497af0bd9e53 | 131 | #define SET_RAMP_40U 0x02 |
Wayne Roberts |
1:497af0bd9e53 | 132 | #define SET_RAMP_80U 0x03 |
Wayne Roberts |
1:497af0bd9e53 | 133 | #define SET_RAMP_200U 0x04 |
Wayne Roberts |
1:497af0bd9e53 | 134 | #define SET_RAMP_800U 0x05 |
Wayne Roberts |
1:497af0bd9e53 | 135 | #define SET_RAMP_1700U 0x06 |
Wayne Roberts |
1:497af0bd9e53 | 136 | #define SET_RAMP_3400U 0x07 |
Wayne Roberts |
1:497af0bd9e53 | 137 | |
Wayne Roberts |
1:497af0bd9e53 | 138 | |
Wayne Roberts |
1:497af0bd9e53 | 139 | |
Wayne Roberts |
1:497af0bd9e53 | 140 | typedef union { |
Wayne Roberts |
1:497af0bd9e53 | 141 | struct { |
Wayne Roberts |
1:497af0bd9e53 | 142 | uint8_t rtcWakeup : 1; // 0 |
Wayne Roberts |
1:497af0bd9e53 | 143 | uint8_t rfu : 1; // 1 |
Wayne Roberts |
1:497af0bd9e53 | 144 | uint8_t warmStart : 1; // 2 |
Wayne Roberts |
1:497af0bd9e53 | 145 | } bits; |
Wayne Roberts |
1:497af0bd9e53 | 146 | uint8_t octet; |
Wayne Roberts |
1:497af0bd9e53 | 147 | } sleepConfig_t; |
Wayne Roberts |
1:497af0bd9e53 | 148 | |
Wayne Roberts |
1:497af0bd9e53 | 149 | typedef union { |
Wayne Roberts |
1:497af0bd9e53 | 150 | struct { |
Wayne Roberts |
1:497af0bd9e53 | 151 | uint8_t PreambleLengthHi; // param1 |
Wayne Roberts |
1:497af0bd9e53 | 152 | uint8_t PreambleLengthLo; // param2 |
Wayne Roberts |
1:497af0bd9e53 | 153 | uint8_t HeaderType; // param3 |
Wayne Roberts |
1:497af0bd9e53 | 154 | uint8_t PayloadLength; // param4 |
Wayne Roberts |
1:497af0bd9e53 | 155 | uint8_t CRCType; // param5 |
Wayne Roberts |
1:497af0bd9e53 | 156 | uint8_t InvertIQ; // param6 |
Wayne Roberts |
1:497af0bd9e53 | 157 | uint8_t unused[2]; |
Wayne Roberts |
1:497af0bd9e53 | 158 | } lora; |
Wayne Roberts |
1:497af0bd9e53 | 159 | struct { |
Wayne Roberts |
1:497af0bd9e53 | 160 | uint8_t PreambleLengthHi; // param1 |
Wayne Roberts |
1:497af0bd9e53 | 161 | uint8_t PreambleLengthLo; // param2 |
Wayne Roberts |
1:497af0bd9e53 | 162 | uint8_t PreambleDetectorLength; // param3 |
Wayne Roberts |
1:497af0bd9e53 | 163 | uint8_t SyncWordLength; // param4 |
Wayne Roberts |
1:497af0bd9e53 | 164 | uint8_t AddrComp; // param5 |
Wayne Roberts |
1:497af0bd9e53 | 165 | uint8_t PacketType; // param6 |
Wayne Roberts |
1:497af0bd9e53 | 166 | uint8_t PayloadLength; // param7 |
Wayne Roberts |
1:497af0bd9e53 | 167 | uint8_t CRCType; // param8 |
Wayne Roberts |
2:e6e159c8ab4d | 168 | uint8_t Whitening; // param9 |
Wayne Roberts |
1:497af0bd9e53 | 169 | } gfsk; |
Wayne Roberts |
6:cd4b02a7e65d | 170 | uint8_t buf[9]; |
Wayne Roberts |
1:497af0bd9e53 | 171 | } PacketParams_t; |
Wayne Roberts |
1:497af0bd9e53 | 172 | |
dudmuck | 11:1cd95e76519a | 173 | typedef union { |
dudmuck | 11:1cd95e76519a | 174 | struct { |
dudmuck | 11:1cd95e76519a | 175 | uint8_t phase_step: 2; // 0,1 |
dudmuck | 11:1cd95e76519a | 176 | uint8_t sd_mode: 1; // 2 |
dudmuck | 11:1cd95e76519a | 177 | uint8_t sd_en: 1; // 3 |
dudmuck | 11:1cd95e76519a | 178 | uint8_t div_ratio_edge: 1; // 4 |
dudmuck | 11:1cd95e76519a | 179 | uint8_t reserved: 3; // 5,6,7 |
dudmuck | 11:1cd95e76519a | 180 | } bits; |
dudmuck | 11:1cd95e76519a | 181 | uint8_t octet; |
dudmuck | 11:1cd95e76519a | 182 | } sdCfg0_t; // at 0x889 |
Wayne Roberts |
1:497af0bd9e53 | 183 | |
Wayne Roberts |
1:497af0bd9e53 | 184 | #define LORA_BW_7 0x00 // 7.81 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 185 | #define LORA_BW_10 0x08 // 10.42 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 186 | #define LORA_BW_15 0x01 // 15.63 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 187 | #define LORA_BW_20 0x09 // 20.83 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 188 | #define LORA_BW_31 0x02 // 31.25 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 189 | #define LORA_BW_41 0x0A // 41.67 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 190 | #define LORA_BW_62 0x03 // 62.50 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 191 | #define LORA_BW_125 0x04 // 125 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 192 | #define LORA_BW_250 0x05 // 250 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 193 | #define LORA_BW_500 0x06 // 500 kHz real |
Wayne Roberts |
1:497af0bd9e53 | 194 | |
Wayne Roberts |
1:497af0bd9e53 | 195 | #define LORA_CR_4_5 1 |
Wayne Roberts |
1:497af0bd9e53 | 196 | #define LORA_CR_4_6 2 |
Wayne Roberts |
1:497af0bd9e53 | 197 | #define LORA_CR_4_7 3 |
Wayne Roberts |
1:497af0bd9e53 | 198 | #define LORA_CR_4_8 4 |
Wayne Roberts |
1:497af0bd9e53 | 199 | |
Wayne Roberts |
1:497af0bd9e53 | 200 | #define GFSK_PREAMBLE_DETECTOR_OFF 0x00 |
Wayne Roberts |
1:497af0bd9e53 | 201 | #define GFSK_PREAMBLE_DETECTOR_LENGTH_8BITS 0x04 |
Wayne Roberts |
1:497af0bd9e53 | 202 | #define GFSK_PREAMBLE_DETECTOR_LENGTH_16BITS 0x05 |
Wayne Roberts |
1:497af0bd9e53 | 203 | #define GFSK_PREAMBLE_DETECTOR_LENGTH_24BITS 0x06 |
Wayne Roberts |
1:497af0bd9e53 | 204 | #define GFSK_PREAMBLE_DETECTOR_LENGTH_32BITS 0x07 |
Wayne Roberts |
1:497af0bd9e53 | 205 | |
Wayne Roberts |
2:e6e159c8ab4d | 206 | #define GFSK_WHITENING_OFF 0 |
Wayne Roberts |
2:e6e159c8ab4d | 207 | #define GFSK_WHITENING_ON 1 |
Wayne Roberts |
2:e6e159c8ab4d | 208 | |
Wayne Roberts |
1:497af0bd9e53 | 209 | #define GFSK_CRC_OFF 0x01 |
Wayne Roberts |
1:497af0bd9e53 | 210 | #define GFSK_CRC_1_BYTE 0x00 |
Wayne Roberts |
1:497af0bd9e53 | 211 | #define GFSK_CRC_2_BYTE 0x02 |
Wayne Roberts |
1:497af0bd9e53 | 212 | #define GFSK_CRC_1_BYTE_INV 0x04 |
Wayne Roberts |
1:497af0bd9e53 | 213 | #define GFSK_CRC_2_BYTE_INV 0x06 |
Wayne Roberts |
1:497af0bd9e53 | 214 | |
Wayne Roberts |
1:497af0bd9e53 | 215 | #define GFSK_RX_BW_4800 0x1F |
Wayne Roberts |
1:497af0bd9e53 | 216 | #define GFSK_RX_BW_5800 0x17 |
Wayne Roberts |
1:497af0bd9e53 | 217 | #define GFSK_RX_BW_7300 0x0F |
Wayne Roberts |
1:497af0bd9e53 | 218 | #define GFSK_RX_BW_9700 0x1E |
Wayne Roberts |
1:497af0bd9e53 | 219 | #define GFSK_RX_BW_11700 0x16 |
Wayne Roberts |
1:497af0bd9e53 | 220 | #define GFSK_RX_BW_14600 0x0E |
Wayne Roberts |
1:497af0bd9e53 | 221 | #define GFSK_RX_BW_19500 0x1D |
Wayne Roberts |
1:497af0bd9e53 | 222 | #define GFSK_RX_BW_23400 0x15 |
Wayne Roberts |
1:497af0bd9e53 | 223 | #define GFSK_RX_BW_29300 0x0D |
Wayne Roberts |
1:497af0bd9e53 | 224 | #define GFSK_RX_BW_39000 0x1C |
Wayne Roberts |
1:497af0bd9e53 | 225 | #define GFSK_RX_BW_46900 0x14 |
Wayne Roberts |
1:497af0bd9e53 | 226 | #define GFSK_RX_BW_58600 0x0C |
Wayne Roberts |
1:497af0bd9e53 | 227 | #define GFSK_RX_BW_78200 0x1B |
Wayne Roberts |
1:497af0bd9e53 | 228 | #define GFSK_RX_BW_93800 0x13 |
Wayne Roberts |
1:497af0bd9e53 | 229 | #define GFSK_RX_BW_117300 0x0B |
Wayne Roberts |
1:497af0bd9e53 | 230 | #define GFSK_RX_BW_156200 0x1A |
Wayne Roberts |
1:497af0bd9e53 | 231 | #define GFSK_RX_BW_187200 0x12 |
Wayne Roberts |
1:497af0bd9e53 | 232 | #define GFSK_RX_BW_234300 0x0A |
Wayne Roberts |
1:497af0bd9e53 | 233 | #define GFSK_RX_BW_312000 0x19 |
Wayne Roberts |
1:497af0bd9e53 | 234 | #define GFSK_RX_BW_373600 0x11 |
Wayne Roberts |
1:497af0bd9e53 | 235 | #define GFSK_RX_BW_467000 0x09 |
Wayne Roberts |
1:497af0bd9e53 | 236 | |
Wayne Roberts |
1:497af0bd9e53 | 237 | #define GFSK_SHAPE_NONE 0x00 |
Wayne Roberts |
1:497af0bd9e53 | 238 | #define GFSK_SHAPE_BT0_3 0x08 |
Wayne Roberts |
1:497af0bd9e53 | 239 | #define GFSK_SHAPE_BT0_5 0x09 |
Wayne Roberts |
1:497af0bd9e53 | 240 | #define GFSK_SHAPE_BT0_7 0x0a |
Wayne Roberts |
1:497af0bd9e53 | 241 | #define GFSK_SHAPE_BT1_0 0x0b |
Wayne Roberts |
1:497af0bd9e53 | 242 | |
Wayne Roberts |
1:497af0bd9e53 | 243 | typedef enum { |
Wayne Roberts |
1:497af0bd9e53 | 244 | STBY_RC = 0, |
Wayne Roberts |
1:497af0bd9e53 | 245 | STBY_XOSC |
Wayne Roberts |
1:497af0bd9e53 | 246 | } stby_t; |
Wayne Roberts |
1:497af0bd9e53 | 247 | |
Wayne Roberts |
2:e6e159c8ab4d | 248 | #define MOD_TYPE_IQ 0 |
Wayne Roberts |
2:e6e159c8ab4d | 249 | #define MOD_TYPE_FSK 1 |
Wayne Roberts |
2:e6e159c8ab4d | 250 | #define MOD_TYPE_MSK 2 |
Wayne Roberts |
2:e6e159c8ab4d | 251 | #define MOD_TYPE_LORA 3 |
Wayne Roberts |
2:e6e159c8ab4d | 252 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 253 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 254 | uint8_t mod_order : 2; // 0,1 modulation size 2points to 16points |
Wayne Roberts |
2:e6e159c8ab4d | 255 | uint8_t mod_type : 2; // 2,3 IQ, FSK, MSK, LoRa |
Wayne Roberts |
2:e6e159c8ab4d | 256 | uint8_t data_src : 1; // 4 |
Wayne Roberts |
2:e6e159c8ab4d | 257 | uint8_t clk_src : 2; // 5,6 |
Wayne Roberts |
2:e6e159c8ab4d | 258 | uint8_t mod_en : 1; // 7 |
Wayne Roberts |
2:e6e159c8ab4d | 259 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 260 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 261 | } modCfg_t; // at 0x680 fsk |
Wayne Roberts |
2:e6e159c8ab4d | 262 | |
Wayne Roberts |
2:e6e159c8ab4d | 263 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 264 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 265 | uint8_t bt : 2; // 0,1 0=BT0.3 1=BT0.5 2=BT0.7 3=BT1.0 |
Wayne Roberts |
2:e6e159c8ab4d | 266 | uint8_t double_rate : 1; // 2 double oversampling rate |
Wayne Roberts |
2:e6e159c8ab4d | 267 | uint8_t pulse_shape : 2; // 3,4 0=noFilter 1=gaussian 2=RRC |
Wayne Roberts |
2:e6e159c8ab4d | 268 | uint8_t res : 3; // 5,6,7 |
Wayne Roberts |
2:e6e159c8ab4d | 269 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 270 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 271 | } shapeCfg_t; // at 0x6a7 fsk |
Wayne Roberts |
2:e6e159c8ab4d | 272 | |
Wayne Roberts |
2:e6e159c8ab4d | 273 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 274 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 275 | uint8_t pkt_start_p : 1; // 0 ros1 |
Wayne Roberts |
2:e6e159c8ab4d | 276 | uint8_t pkt_abort_p : 1; // 1 ros1 |
Wayne Roberts |
2:e6e159c8ab4d | 277 | uint8_t pkt_sw_clr_p : 1; // 2 ros1 |
Wayne Roberts |
2:e6e159c8ab4d | 278 | uint8_t crl_status_p : 1; // 3 ros1 |
Wayne Roberts |
2:e6e159c8ab4d | 279 | uint8_t clk_en : 1; // 4 ro |
Wayne Roberts |
2:e6e159c8ab4d | 280 | uint8_t pkt_rx_ntx : 1; // 5 |
Wayne Roberts |
2:e6e159c8ab4d | 281 | uint8_t pkt_len_format : 1; // 6 |
Wayne Roberts |
2:e6e159c8ab4d | 282 | uint8_t cont_rx : 1; // 7 |
Wayne Roberts |
2:e6e159c8ab4d | 283 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 284 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 285 | } pktCtrl0_t; // at 0x6b3 fsk |
Wayne Roberts |
2:e6e159c8ab4d | 286 | |
Wayne Roberts |
2:e6e159c8ab4d | 287 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 288 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 289 | uint8_t preamble_len_rx : 2; // 0,1 number of preamble bits detected |
Wayne Roberts |
5:8b75387af4e0 | 290 | uint8_t preamble_det_on : 1; // 2 enable rx-sde preamble detector |
Wayne Roberts |
5:8b75387af4e0 | 291 | uint8_t res : 5; // 7 |
Wayne Roberts |
2:e6e159c8ab4d | 292 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 293 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 294 | } pktCtrl1_t; // at 0x6b4 fsk |
Wayne Roberts |
2:e6e159c8ab4d | 295 | |
Wayne Roberts |
2:e6e159c8ab4d | 296 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 297 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 298 | uint16_t whit_init_val : 9; // 0...8 at 0x6b9 |
Wayne Roberts |
5:8b75387af4e0 | 299 | uint16_t infinite_seq_en : 1; // 9 |
Wayne Roberts |
5:8b75387af4e0 | 300 | uint16_t infinite_seq_select : 2; // 10,11 |
Wayne Roberts |
5:8b75387af4e0 | 301 | uint16_t cont_tx : 1; // 12 |
Wayne Roberts |
5:8b75387af4e0 | 302 | uint16_t sync_det_on : 1; // 13 |
Wayne Roberts |
5:8b75387af4e0 | 303 | uint16_t res : 2; // 14,15 |
Wayne Roberts |
5:8b75387af4e0 | 304 | } bits; |
Wayne Roberts |
5:8b75387af4e0 | 305 | uint16_t word; |
Wayne Roberts |
5:8b75387af4e0 | 306 | } PktCtrl1a_t; // at 0x6b8 |
Wayne Roberts |
5:8b75387af4e0 | 307 | |
Wayne Roberts |
5:8b75387af4e0 | 308 | typedef union { |
Wayne Roberts |
5:8b75387af4e0 | 309 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 310 | uint8_t crc_disable : 1; // 0 |
Wayne Roberts |
2:e6e159c8ab4d | 311 | uint8_t crc_len : 1; // 1 0=1byte 1=2byte |
Wayne Roberts |
2:e6e159c8ab4d | 312 | uint8_t crc_inv : 1; // 2 |
Wayne Roberts |
2:e6e159c8ab4d | 313 | uint8_t crc_in_fifo : 1; // 3 |
Wayne Roberts |
2:e6e159c8ab4d | 314 | uint8_t whit_enable : 1; // 4 |
Wayne Roberts |
2:e6e159c8ab4d | 315 | uint8_t manchester_en : 1; // 5 |
Wayne Roberts |
2:e6e159c8ab4d | 316 | uint8_t rssi_mode : 2; // 6,7 |
Wayne Roberts |
2:e6e159c8ab4d | 317 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 318 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 319 | } pktCtrl2_t; // at 0x6ba fsk |
Wayne Roberts |
2:e6e159c8ab4d | 320 | |
Wayne Roberts |
2:e6e159c8ab4d | 321 | |
Wayne Roberts |
2:e6e159c8ab4d | 322 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 323 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 324 | uint8_t modem_sf: 4; // 0,1,2,3 |
Wayne Roberts |
2:e6e159c8ab4d | 325 | uint8_t modem_bw: 4; // 4,5,6,7 |
Wayne Roberts |
2:e6e159c8ab4d | 326 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 327 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 328 | } loraConfig0_t; // at 0x703 |
Wayne Roberts |
2:e6e159c8ab4d | 329 | |
Wayne Roberts |
2:e6e159c8ab4d | 330 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 331 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 332 | uint8_t tx_coding_rate : 3; // 0,1,2 |
Wayne Roberts |
2:e6e159c8ab4d | 333 | uint8_t ppm_offset : 2; // 3,4 aka long range mode |
Wayne Roberts |
2:e6e159c8ab4d | 334 | uint8_t tx_mode : 1; // 5 |
Wayne Roberts |
2:e6e159c8ab4d | 335 | uint8_t rx_invert_iq : 1; // 6 |
Wayne Roberts |
2:e6e159c8ab4d | 336 | uint8_t implicit_header : 1; // 7 0=variable length packet |
Wayne Roberts |
2:e6e159c8ab4d | 337 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 338 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 339 | } loraConfig1_t; // at 0x704 |
Wayne Roberts |
2:e6e159c8ab4d | 340 | |
Wayne Roberts |
2:e6e159c8ab4d | 341 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 342 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 343 | uint8_t cad_rxtx : 2; // 0,1 |
Wayne Roberts |
2:e6e159c8ab4d | 344 | uint8_t tx_payload_crc16_en : 1; // 2 |
Wayne Roberts |
2:e6e159c8ab4d | 345 | uint8_t cont_rx : 1; // 3 |
Wayne Roberts |
2:e6e159c8ab4d | 346 | uint8_t freeze_dagc_upon_synch : 2; // 4,5 |
Wayne Roberts |
2:e6e159c8ab4d | 347 | uint8_t fine_sync_en : 1; // 6 |
Wayne Roberts |
2:e6e159c8ab4d | 348 | uint8_t res : 1; // 7 |
Wayne Roberts |
2:e6e159c8ab4d | 349 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 350 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 351 | } loraConfig2_t; // at 0x705 |
Wayne Roberts |
2:e6e159c8ab4d | 352 | |
Wayne Roberts |
2:e6e159c8ab4d | 353 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 354 | struct { |
Wayne Roberts |
7:fe8c0186ee50 | 355 | uint32_t est_freq_error :20; // 0..19 |
Wayne Roberts |
7:fe8c0186ee50 | 356 | uint32_t header_crc16_en : 1; // 20 |
Wayne Roberts |
7:fe8c0186ee50 | 357 | uint32_t rf_en_request : 2; // 21,22 |
Wayne Roberts |
7:fe8c0186ee50 | 358 | uint32_t raw_ranging_result_available : 1; // 23 |
Wayne Roberts |
7:fe8c0186ee50 | 359 | uint32_t unused : 8; // 24..31 |
Wayne Roberts |
7:fe8c0186ee50 | 360 | } bits; |
Wayne Roberts |
7:fe8c0186ee50 | 361 | uint32_t dword; |
Wayne Roberts |
7:fe8c0186ee50 | 362 | } loraStatus1_t; // at 0x76b |
Wayne Roberts |
7:fe8c0186ee50 | 363 | |
Wayne Roberts |
7:fe8c0186ee50 | 364 | typedef union { |
Wayne Roberts |
7:fe8c0186ee50 | 365 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 366 | uint8_t inv_edge : 1; // 0 |
Wayne Roberts |
2:e6e159c8ab4d | 367 | uint8_t swap_iq : 1; // 1 |
Wayne Roberts |
2:e6e159c8ab4d | 368 | uint8_t dig_fe_clear : 1; // 2 |
Wayne Roberts |
2:e6e159c8ab4d | 369 | uint8_t lora_ngfsk : 1; // 3 data buffer selection lora/gfsk |
Wayne Roberts |
2:e6e159c8ab4d | 370 | uint8_t adc_from_dio : 1; // 4 |
Wayne Roberts |
2:e6e159c8ab4d | 371 | uint8_t lora_pre_cf_en : 1; // 5 |
Wayne Roberts |
2:e6e159c8ab4d | 372 | uint8_t res : 2; // 6,7 |
Wayne Roberts |
2:e6e159c8ab4d | 373 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 374 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 375 | } digFeCtrl_t; // at 0x804 |
Wayne Roberts |
2:e6e159c8ab4d | 376 | |
Wayne Roberts |
2:e6e159c8ab4d | 377 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 378 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 379 | uint8_t exp : 3; // 0,1,2 |
Wayne Roberts |
2:e6e159c8ab4d | 380 | uint8_t mant : 2; // 3,4 |
Wayne Roberts |
2:e6e159c8ab4d | 381 | uint8_t res : 3; // 5,6,7 |
Wayne Roberts |
2:e6e159c8ab4d | 382 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 383 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 384 | } bwSel_t; // at 0x807 rx_bw |
Wayne Roberts |
2:e6e159c8ab4d | 385 | |
Wayne Roberts |
2:e6e159c8ab4d | 386 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 387 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 388 | uint8_t reg_pa_discharge_en : 1; // 0 |
Wayne Roberts |
5:8b75387af4e0 | 389 | uint8_t reg_pa_boost_en : 1; // 1 |
Wayne Roberts |
5:8b75387af4e0 | 390 | uint8_t dac_pol : 2; // 2,3 |
Wayne Roberts |
5:8b75387af4e0 | 391 | } bits; |
Wayne Roberts |
5:8b75387af4e0 | 392 | uint8_t octet; |
Wayne Roberts |
5:8b75387af4e0 | 393 | } paCtrl0_t; // at 0x880 |
Wayne Roberts |
5:8b75387af4e0 | 394 | |
Wayne Roberts |
5:8b75387af4e0 | 395 | typedef union { |
Wayne Roberts |
5:8b75387af4e0 | 396 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 397 | uint8_t boost_delay : 6; // 0,1,2,3,4,5 |
Wayne Roberts |
5:8b75387af4e0 | 398 | uint8_t boost_width : 2; // 6,7 |
Wayne Roberts |
5:8b75387af4e0 | 399 | } bits; |
Wayne Roberts |
5:8b75387af4e0 | 400 | uint8_t octet; |
Wayne Roberts |
5:8b75387af4e0 | 401 | } paCtrl1_t; // at 0x881 |
Wayne Roberts |
5:8b75387af4e0 | 402 | |
Wayne Roberts |
5:8b75387af4e0 | 403 | typedef union { |
Wayne Roberts |
5:8b75387af4e0 | 404 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 405 | uint8_t ramp_on : 1; // 0 |
Wayne Roberts |
5:8b75387af4e0 | 406 | uint8_t ramp_down : 1; // 1 |
Wayne Roberts |
5:8b75387af4e0 | 407 | uint8_t ramp_up : 1; // 2 |
Wayne Roberts |
5:8b75387af4e0 | 408 | uint8_t ramp_status : 1; // 3 |
Wayne Roberts |
5:8b75387af4e0 | 409 | uint8_t force_dac_code_en : 1; // 4 |
Wayne Roberts |
5:8b75387af4e0 | 410 | uint8_t pa_mod_en : 1; // 5 |
Wayne Roberts |
5:8b75387af4e0 | 411 | } bits; |
Wayne Roberts |
5:8b75387af4e0 | 412 | uint8_t octet; |
Wayne Roberts |
5:8b75387af4e0 | 413 | } DigCtrl_t; // at 0x882 |
Wayne Roberts |
5:8b75387af4e0 | 414 | |
Wayne Roberts |
5:8b75387af4e0 | 415 | typedef union { |
Wayne Roberts |
5:8b75387af4e0 | 416 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 417 | uint8_t tx_pwr : 5; // 0,1,2,3,4 |
Wayne Roberts |
5:8b75387af4e0 | 418 | uint8_t ramp_time : 3; // 5,6,7 |
Wayne Roberts |
5:8b75387af4e0 | 419 | } bits; |
Wayne Roberts |
5:8b75387af4e0 | 420 | uint8_t octet; |
Wayne Roberts |
5:8b75387af4e0 | 421 | } PwrCtrl_t; // at 0x883 |
Wayne Roberts |
5:8b75387af4e0 | 422 | |
Wayne Roberts |
5:8b75387af4e0 | 423 | |
Wayne Roberts |
5:8b75387af4e0 | 424 | |
Wayne Roberts |
5:8b75387af4e0 | 425 | |
Wayne Roberts |
5:8b75387af4e0 | 426 | typedef union { |
Wayne Roberts |
5:8b75387af4e0 | 427 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 428 | uint8_t pa_hp_ena_ana : 1; // 0 |
Wayne Roberts |
2:e6e159c8ab4d | 429 | uint8_t tx_ena_bat : 1; // 1 |
Wayne Roberts |
5:8b75387af4e0 | 430 | uint8_t pa_dctrim_select_ana : 4; // 2,3,4,5 paDutyCycle |
Wayne Roberts |
2:e6e159c8ab4d | 431 | uint8_t res : 2; // 6,7 |
Wayne Roberts |
2:e6e159c8ab4d | 432 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 433 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 434 | } AnaCtrl6_t; // at 0x8d7 |
Wayne Roberts |
2:e6e159c8ab4d | 435 | |
Wayne Roberts |
2:e6e159c8ab4d | 436 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 437 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 438 | uint8_t pa_lp_ena_ana : 1; // 0 |
Wayne Roberts |
2:e6e159c8ab4d | 439 | uint8_t pa_clamp_code_bat : 3; // 1,2,3 |
Wayne Roberts |
2:e6e159c8ab4d | 440 | uint8_t pa_clamp_override_bat : 1; // 4 |
Wayne Roberts |
5:8b75387af4e0 | 441 | uint8_t pa_hp_sel_ana : 3; // 5,6,7 hpMax |
Wayne Roberts |
2:e6e159c8ab4d | 442 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 443 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 444 | } AnaCtrl7_t; // at 0x8d8 |
Wayne Roberts |
2:e6e159c8ab4d | 445 | |
Wayne Roberts |
2:e6e159c8ab4d | 446 | typedef union { |
Wayne Roberts |
2:e6e159c8ab4d | 447 | struct { |
Wayne Roberts |
2:e6e159c8ab4d | 448 | uint8_t reg_pa_comp_poarity_ana : 1; // 0 |
Wayne Roberts |
2:e6e159c8ab4d | 449 | uint8_t reg_pa_comp_en_ana : 1; // 1 |
Wayne Roberts |
2:e6e159c8ab4d | 450 | uint8_t fir_dac_sign_ana : 2; // 2,3 |
Wayne Roberts |
2:e6e159c8ab4d | 451 | uint8_t fir_dac_pole_ana : 3; // 4,5,6 |
Wayne Roberts |
2:e6e159c8ab4d | 452 | uint8_t res : 1; // 7 |
Wayne Roberts |
2:e6e159c8ab4d | 453 | } bits; |
Wayne Roberts |
2:e6e159c8ab4d | 454 | uint8_t octet; |
Wayne Roberts |
2:e6e159c8ab4d | 455 | } AnaCtrl15_t; // at 0x8e1 |
Wayne Roberts |
2:e6e159c8ab4d | 456 | |
Wayne Roberts |
1:497af0bd9e53 | 457 | typedef union { |
Wayne Roberts |
1:497af0bd9e53 | 458 | struct { |
Wayne Roberts |
5:8b75387af4e0 | 459 | uint8_t force_ref : 1; // 0 |
Wayne Roberts |
5:8b75387af4e0 | 460 | uint8_t pa_voltage_lim_en : 1; // 1 |
Wayne Roberts |
5:8b75387af4e0 | 461 | uint8_t pa_current_lim_en : 1; // 2 |
Wayne Roberts |
5:8b75387af4e0 | 462 | uint8_t tx_mode_bat : 1; // 3 deviceSel 0=hipower 1=lopower take precedence over hpp_mode |
Wayne Roberts |
5:8b75387af4e0 | 463 | uint8_t hp_mode : 1; // 4 hi-power submode 0=14dBm LUT, 1=20dBm LUT |
Wayne Roberts |
5:8b75387af4e0 | 464 | } bits; |
Wayne Roberts |
5:8b75387af4e0 | 465 | uint8_t octet; |
Wayne Roberts |
5:8b75387af4e0 | 466 | } PaCtrl1b_t; // at 0x8e6 |
Wayne Roberts |
5:8b75387af4e0 | 467 | |
Wayne Roberts |
5:8b75387af4e0 | 468 | typedef union { |
Wayne Roberts |
5:8b75387af4e0 | 469 | struct { |
Wayne Roberts |
1:497af0bd9e53 | 470 | uint8_t spreadingFactor; // param1 |
Wayne Roberts |
1:497af0bd9e53 | 471 | uint8_t bandwidth; // param2 |
Wayne Roberts |
1:497af0bd9e53 | 472 | uint8_t codingRate; // param3 |
Wayne Roberts |
1:497af0bd9e53 | 473 | uint8_t LowDatarateOptimize; // param4 |
Wayne Roberts |
1:497af0bd9e53 | 474 | } lora; |
Wayne Roberts |
1:497af0bd9e53 | 475 | struct { |
Wayne Roberts |
1:497af0bd9e53 | 476 | uint8_t bitrateHi; // param1 |
Wayne Roberts |
1:497af0bd9e53 | 477 | uint8_t bitrateMid; // param2 |
Wayne Roberts |
1:497af0bd9e53 | 478 | uint8_t bitrateLo; // param3 |
Wayne Roberts |
1:497af0bd9e53 | 479 | uint8_t PulseShape; // param4 |
Wayne Roberts |
2:e6e159c8ab4d | 480 | uint8_t bandwidth; // param5 |
Wayne Roberts |
2:e6e159c8ab4d | 481 | uint8_t fdevHi; // param6 |
Wayne Roberts |
1:497af0bd9e53 | 482 | uint8_t fdevMid; // param7 |
Wayne Roberts |
2:e6e159c8ab4d | 483 | uint8_t fdevLo; // param8 |
Wayne Roberts |
1:497af0bd9e53 | 484 | } gfsk; |
Wayne Roberts |
1:497af0bd9e53 | 485 | uint8_t buf[8]; |
Wayne Roberts |
1:497af0bd9e53 | 486 | } ModulationParams_t; |
Wayne Roberts |
1:497af0bd9e53 | 487 | |
Wayne Roberts |
1:497af0bd9e53 | 488 | typedef union { |
Wayne Roberts |
1:497af0bd9e53 | 489 | struct { // |
Wayne Roberts |
3:f6f2f8adcd22 | 490 | uint16_t TxDone : 1; // 0 |
Wayne Roberts |
3:f6f2f8adcd22 | 491 | uint16_t RxDone : 1; // 1 |
Wayne Roberts |
3:f6f2f8adcd22 | 492 | uint16_t PreambleDetected : 1; // 2 |
Wayne Roberts |
3:f6f2f8adcd22 | 493 | uint16_t SyncWordValid : 1; // 3 |
Wayne Roberts |
3:f6f2f8adcd22 | 494 | uint16_t HeaderValid : 1; // 4 |
Wayne Roberts |
3:f6f2f8adcd22 | 495 | uint16_t HeaderErr : 1; // 5 |
Wayne Roberts |
3:f6f2f8adcd22 | 496 | uint16_t CrCerr : 1; // 6 |
Wayne Roberts |
3:f6f2f8adcd22 | 497 | uint16_t CadDone : 1; // 7 |
Wayne Roberts |
3:f6f2f8adcd22 | 498 | uint16_t CadDetected : 1; // 8 |
Wayne Roberts |
3:f6f2f8adcd22 | 499 | uint16_t Timeout : 1; // 9 |
Wayne Roberts |
3:f6f2f8adcd22 | 500 | uint16_t res : 6; // 10,11,12,13,14,15 |
Wayne Roberts |
1:497af0bd9e53 | 501 | } bits; |
Wayne Roberts |
1:497af0bd9e53 | 502 | uint16_t word; |
Wayne Roberts |
1:497af0bd9e53 | 503 | } IrqFlags_t; |
Wayne Roberts |
1:497af0bd9e53 | 504 | |
Wayne Roberts |
1:497af0bd9e53 | 505 | typedef union { |
Wayne Roberts |
1:497af0bd9e53 | 506 | struct { // |
Wayne Roberts |
1:497af0bd9e53 | 507 | uint8_t _reserved : 1; // 0 |
Wayne Roberts |
1:497af0bd9e53 | 508 | uint8_t cmdStatus : 3; // 1,2,3 |
Wayne Roberts |
1:497af0bd9e53 | 509 | uint8_t chipMode : 3; // 4,5,6 |
Wayne Roberts |
1:497af0bd9e53 | 510 | uint8_t reserved_ : 1; // 7 |
Wayne Roberts |
1:497af0bd9e53 | 511 | } bits; |
Wayne Roberts |
1:497af0bd9e53 | 512 | uint8_t octet; |
Wayne Roberts |
1:497af0bd9e53 | 513 | } status_t; |
Wayne Roberts |
1:497af0bd9e53 | 514 | |
Wayne Roberts |
1:497af0bd9e53 | 515 | typedef enum { |
Wayne Roberts |
1:497af0bd9e53 | 516 | CHIPMODE_NONE = 0, |
Wayne Roberts |
1:497af0bd9e53 | 517 | CHIPMODE_RX, |
Wayne Roberts |
1:497af0bd9e53 | 518 | CHIPMODE_TX |
Wayne Roberts |
1:497af0bd9e53 | 519 | } chipMote_e; |
Wayne Roberts |
1:497af0bd9e53 | 520 | |
Wayne Roberts |
1:497af0bd9e53 | 521 | class SX126x { |
Wayne Roberts |
1:497af0bd9e53 | 522 | public: |
Wayne Roberts |
1:497af0bd9e53 | 523 | SX126x(SPI&, PinName nss, PinName busy, PinName dio1); |
Wayne Roberts |
1:497af0bd9e53 | 524 | |
Wayne Roberts |
1:497af0bd9e53 | 525 | |
Wayne Roberts |
1:497af0bd9e53 | 526 | void hw_reset(PinName nrst); |
Wayne Roberts |
2:e6e159c8ab4d | 527 | void xfer(uint8_t opcode, uint8_t writeLen, uint8_t readLen, uint8_t* buf); |
Wayne Roberts |
1:497af0bd9e53 | 528 | void setPacketType(uint8_t); |
Wayne Roberts |
3:f6f2f8adcd22 | 529 | uint8_t getPacketType(void); |
Wayne Roberts |
1:497af0bd9e53 | 530 | uint8_t setMHz(float); |
Wayne Roberts |
2:e6e159c8ab4d | 531 | float getMHz(void); |
Wayne Roberts |
1:497af0bd9e53 | 532 | |
Wayne Roberts |
1:497af0bd9e53 | 533 | /* start_tx and start_rx assumes DIO1 is connected, and only pin used to generate radio interrupt */ |
Wayne Roberts |
1:497af0bd9e53 | 534 | void start_tx(uint8_t pktLen); // tx_buf must be filled prior to calling |
Wayne Roberts |
1:497af0bd9e53 | 535 | |
Wayne Roberts |
1:497af0bd9e53 | 536 | #define RX_TIMEOUT_SINGLE 0x000000 /* stop RX after first packet */ |
Wayne Roberts |
1:497af0bd9e53 | 537 | #define RX_TIMEOUT_CONTINUOUS 0xffffff /* keep RXing */ |
Wayne Roberts |
1:497af0bd9e53 | 538 | void start_rx(unsigned); |
Wayne Roberts |
1:497af0bd9e53 | 539 | |
Wayne Roberts |
2:e6e159c8ab4d | 540 | void ReadBuffer(uint8_t size, uint8_t offset); |
Wayne Roberts |
1:497af0bd9e53 | 541 | void SetDIO2AsRfSwitchCtrl(uint8_t); |
Wayne Roberts |
1:497af0bd9e53 | 542 | void set_tx_dbm(bool is1262, int8_t dbm); |
Wayne Roberts |
1:497af0bd9e53 | 543 | uint32_t readReg(uint16_t addr, uint8_t len); |
Wayne Roberts |
1:497af0bd9e53 | 544 | void writeReg(uint16_t addr, uint32_t data, uint8_t len); |
Wayne Roberts |
1:497af0bd9e53 | 545 | void setStandby(stby_t); |
Wayne Roberts |
1:497af0bd9e53 | 546 | void setSleep(bool warmStart, bool rtcWakeup); |
Wayne Roberts |
4:b941bceb401d | 547 | void setFS(void); |
Wayne Roberts |
8:66d3e344d61c | 548 | void setCAD(void); |
Wayne Roberts |
5:8b75387af4e0 | 549 | void setBufferBase(uint8_t txAddr, uint8_t rxAddr); |
Wayne Roberts |
1:497af0bd9e53 | 550 | |
Wayne Roberts |
1:497af0bd9e53 | 551 | static Callback<void()> dio1_topHalf; // low latency ISR context |
Wayne Roberts |
1:497af0bd9e53 | 552 | void service(void); |
Wayne Roberts |
1:497af0bd9e53 | 553 | Callback<void()> txDone; // user context |
Wayne Roberts |
4:b941bceb401d | 554 | Callback<void()> chipModeChange; // read chipMode_e chipMode |
Wayne Roberts |
1:497af0bd9e53 | 555 | void (*rxDone)(uint8_t size, float rssi, float snr); // user context |
Wayne Roberts |
1:497af0bd9e53 | 556 | void (*timeout)(bool tx); // user context |
Wayne Roberts |
8:66d3e344d61c | 557 | void (*cadDone)(bool detected); // user context |
Wayne Roberts |
10:8905722dd5e6 | 558 | void (*preambleDetected)(void); // user context |
Wayne Roberts |
1:497af0bd9e53 | 559 | |
Wayne Roberts |
1:497af0bd9e53 | 560 | //! RF transmit packet buffer |
Wayne Roberts |
1:497af0bd9e53 | 561 | uint8_t tx_buf[256]; // lora fifo size |
Wayne Roberts |
1:497af0bd9e53 | 562 | |
Wayne Roberts |
1:497af0bd9e53 | 563 | //! RF receive packet buffer |
Wayne Roberts |
1:497af0bd9e53 | 564 | uint8_t rx_buf[256]; // lora fifo size |
Wayne Roberts |
1:497af0bd9e53 | 565 | |
Wayne Roberts |
1:497af0bd9e53 | 566 | /** Test if dio1 pin is asserted |
Wayne Roberts |
1:497af0bd9e53 | 567 | */ |
Wayne Roberts |
1:497af0bd9e53 | 568 | inline bool getDIO1(void) { return dio1.read(); } |
Wayne Roberts |
1:497af0bd9e53 | 569 | void PrintChipStatus(status_t); |
Wayne Roberts |
1:497af0bd9e53 | 570 | chipMote_e chipMode; |
Wayne Roberts |
1:497af0bd9e53 | 571 | |
Wayne Roberts |
1:497af0bd9e53 | 572 | private: |
Wayne Roberts |
1:497af0bd9e53 | 573 | SPI& spi; |
Wayne Roberts |
1:497af0bd9e53 | 574 | DigitalOut nss; |
Wayne Roberts |
1:497af0bd9e53 | 575 | DigitalIn busy; |
Wayne Roberts |
1:497af0bd9e53 | 576 | InterruptIn dio1; |
Wayne Roberts |
1:497af0bd9e53 | 577 | static void dio1isr(void); |
Wayne Roberts |
1:497af0bd9e53 | 578 | bool sleeping; |
Wayne Roberts |
1:497af0bd9e53 | 579 | }; |
Wayne Roberts |
1:497af0bd9e53 | 580 | |
Wayne Roberts |
1:497af0bd9e53 | 581 | #endif /* SX126x_H */ |
Wayne Roberts |
1:497af0bd9e53 | 582 |