-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsx126x-board.h
247 lines (208 loc) · 6.97 KB
/
sx126x-board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*!
* \file sx126x-board.h
*
* \brief Target board SX126x driver implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
* ______ _
* / _____) _ | |
* ( (____ _____ ____ _| |_ _____ ____| |__
* \____ \| ___ | (_ _) ___ |/ ___) _ \
* _____) ) ____| | | || |_| ____( (___| | | |
* (______/|_____)_|_|_| \__)_____)\____)_| |_|
* (C)2013-2017 Semtech
*
* \endcode
*
* \author Miguel Luis ( Semtech )
*
* \author Gregory Cristian ( Semtech )
*/
#ifndef __SX126x_BOARD_H__
#define __SX126x_BOARD_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#include <stdbool.h>
#include "sx126x.h"
// Below are the pin numbers for PineDio Stack BL604 with onboard SX1262.
// TODO: Change the pin numbers for your SX1262 connection to BL602 / BL604
#define SX126X_SPI_IDX 0 // SPI Port 0
#define SX126X_SPI_SDI_PIN 0 // SPI Serial Data In Pin (formerly MISO)
#define SX126X_SPI_SDO_PIN 17 // SPI Serial Data Out Pin (formerly MOSI)
#define SX126X_SPI_CLK_PIN 11 // SPI Clock Pin
#define SX126X_SPI_CS_PIN 15 // SPI Chip Select Pin
#define SX126X_SPI_CS_OLD 8 // Unused SPI Chip Select Pin
#define SX126X_NRESET 18 // Reset Pin
#define SX126X_DIO1 19 // DIO1
#define SX126X_BUSY_PIN 10 // Busy Pin
#define SX126X_DEBUG_CS_PIN 5 // Debug Chip Select Pin, mirrors the High / Low State of SX1262 Chip Select Pin. Set to -1 if not needed.
#define SX126X_TCXO_WAKEUP_TIME 5 // Time required for the TCXO to wakeup (milliseconds)
#define SX126X_SPI_BAUDRATE (200 * 1000) // SPI Frequency (200 kHz)
// Timer definition for BL602
#include "nimble_npl.h" // For NimBLE Porting Layer (timer functions)
typedef struct ble_npl_callout TimerEvent_t;
///////////////////////////////////////////////////////////////////////////////
// BL602 Functions
// TODO: Implement critical section functions
#define CRITICAL_SECTION_BEGIN(...)
#define CRITICAL_SECTION_END(...)
/// Initialise a timer
void TimerInit(
struct ble_npl_callout *timer, // The timer to initialize. Cannot be NULL.
ble_npl_event_fn *f); // The timer callback function. Cannot be NULL.
/// Stops a timer from running. Can be called even if timer is not running.
void TimerStop(
struct ble_npl_callout *timer); // Pointer to timer to stop. Cannot be NULL.
/// Sets a timer that will expire ‘usecs’ microseconds from the current time.
void TimerStart(
struct ble_npl_callout *timer, // Pointer to timer. Cannot be NULL.
uint32_t microsecs); // The number of microseconds from now at which the timer will expire.
/// Wait until ‘millisecs’ milliseconds has elapsed. This is a blocking delay.
void DelayMs(uint32_t millisecs); // The number of milliseconds to wait.
/// Return current time in microseconds
uint32_t TimerGetCurrentTime(void);
/// Return elased time in microseconds
uint32_t TimerGetElapsedTime(uint32_t saved_time);
///////////////////////////////////////////////////////////////////////////////
/*!
* \brief Initializes the radio I/Os pins interface
*/
void SX126xIoInit( void );
/*!
* \brief Initializes DIO IRQ handlers
*
* \param [IN] irqHandlers Array containing the IRQ callback functions
*/
void SX126xIoIrqInit( DioIrqHandler dioIrq );
/*!
* \brief De-initializes the radio I/Os pins interface.
*
* \remark Useful when going in MCU low power modes
*/
void SX126xIoDeInit( void );
/*!
* \brief Initializes the TCXO power pin.
*/
void SX126xIoTcxoInit( void );
/*!
* \brief Initializes RF switch control pins.
*/
void SX126xIoRfSwitchInit( void );
/*!
* \brief Initializes the radio debug pins.
*/
void SX126xIoDbgInit( void );
/*!
* \brief HW Reset of the radio
*/
void SX126xReset( void );
/*!
* \brief Blocking loop to wait while the Busy pin in high
*/
void SX126xWaitOnBusy( void );
/*!
* \brief Wakes up the radio
*/
void SX126xWakeup( void );
/*!
* \brief Send a command that write data to the radio
*
* \param [in] opcode Opcode of the command
* \param [in] buffer Buffer to be send to the radio
* \param [in] size Size of the buffer to send
*/
void SX126xWriteCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size );
/*!
* \brief Send a command that read data from the radio
*
* \param [in] opcode Opcode of the command
* \param [out] buffer Buffer holding data from the radio
* \param [in] size Size of the buffer
*
* \retval status Return command radio status
*/
uint8_t SX126xReadCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size );
/*!
* \brief Write a single byte of data to the radio memory
*
* \param [in] address The address of the first byte to write in the radio
* \param [in] value The data to be written in radio's memory
*/
void SX126xWriteRegister( uint16_t address, uint8_t value );
/*!
* \brief Read a single byte of data from the radio memory
*
* \param [in] address The address of the first byte to write in the radio
*
* \retval value The value of the byte at the given address in radio's memory
*/
uint8_t SX126xReadRegister( uint16_t address );
/*!
* \brief Sets the radio output power.
*
* \param [IN] power Sets the RF output power
*/
void SX126xSetRfTxPower( int8_t power );
/*!
* \brief Gets the device ID
*
* \retval id Connected device ID
*/
uint8_t SX126xGetDeviceId( void );
/*!
* \brief Initializes the RF Switch I/Os pins interface
*/
void SX126xAntSwOn( void );
/*!
* \brief De-initializes the RF Switch I/Os pins interface
*
* \remark Needed to decrease the power consumption in MCU low power modes
*/
void SX126xAntSwOff( void );
/*!
* \brief Checks if the given RF frequency is supported by the hardware
*
* \param [IN] frequency RF frequency to be checked
* \retval isSupported [true: supported, false: unsupported]
*/
bool SX126xCheckRfFrequency( uint32_t frequency );
/*!
* \brief Gets the Defines the time required for the TCXO to wakeup [ms].
*
* \retval time Board TCXO wakeup time in ms.
*/
uint32_t SX126xGetBoardTcxoWakeupTime( void );
/*!
* \brief Gets current state of DIO1 pin state.
*
* \retval state DIO1 pin current state.
*/
uint32_t SX126xGetDio1PinState( void );
/*!
* \brief Gets the current Radio OperationMode variable
*
* \retval RadioOperatingModes_t last operating mode
*/
RadioOperatingModes_t SX126xGetOperatingMode( void );
/*!
* \brief Sets/Updates the current Radio OperationMode variable.
*
* \remark WARNING: This function is only required to reflect the current radio
* operating mode when processing interrupts.
*
* \param [in] mode New operating mode
*/
void SX126xSetOperatingMode( RadioOperatingModes_t mode );
/*!
* Radio hardware and global parameters
*/
extern SX126x_t SX126x;
#ifdef __cplusplus
}
#endif
#endif // __SX126x_BOARD_H__