1 /*!
2  * \file      sx126x-board.h
3  *
4  * \brief     Target board SX126x driver implementation
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  */
23 #ifndef __SX126x_BOARD_H__
24 #define __SX126x_BOARD_H__
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 #include "sx126x/sx126x.h"
34 
35 /*!
36  * \brief Initializes the radio I/Os pins interface
37  */
38 void SX126xIoInit( void );
39 
40 /*!
41  * \brief Initializes DIO IRQ handlers
42  *
43  * \param [IN] irqHandlers Array containing the IRQ callback functions
44  */
45 void SX126xIoIrqInit( DioIrqHandler dioIrq );
46 
47 /*!
48  * \brief De-initializes the radio I/Os pins interface.
49  *
50  * \remark Useful when going in MCU low power modes
51  */
52 void SX126xIoDeInit( void );
53 
54 /*!
55  * \brief Initializes the TCXO power pin.
56  */
57 void SX126xIoTcxoInit( void );
58 
59 /*!
60  * \brief Initializes RF switch control pins.
61  */
62 void SX126xIoRfSwitchInit( void );
63 
64 /*!
65  * \brief Initializes the radio debug pins.
66  */
67 void SX126xIoDbgInit( void );
68 
69 /*!
70  * \brief HW Reset of the radio
71  */
72 void SX126xReset( void );
73 
74 /*!
75  * \brief Blocking loop to wait while the Busy pin in high
76  */
77 void SX126xWaitOnBusy( void );
78 
79 /*!
80  * \brief Wakes up the radio
81  */
82 void SX126xWakeup( void );
83 
84 /*!
85  * \brief Send a command that write data to the radio
86  *
87  * \param [in]  opcode        Opcode of the command
88  * \param [in]  buffer        Buffer to be send to the radio
89  * \param [in]  size          Size of the buffer to send
90  */
91 void SX126xWriteCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size );
92 
93 /*!
94  * \brief Send a command that read data from the radio
95  *
96  * \param [in]  opcode        Opcode of the command
97  * \param [out] buffer        Buffer holding data from the radio
98  * \param [in]  size          Size of the buffer
99  *
100  * \retval status Return command radio status
101  */
102 uint8_t SX126xReadCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size );
103 
104 /*!
105  * \brief Write a single byte of data to the radio memory
106  *
107  * \param [in]  address       The address of the first byte to write in the radio
108  * \param [in]  value         The data to be written in radio's memory
109  */
110 void SX126xWriteRegister( uint16_t address, uint8_t value );
111 
112 /*!
113  * \brief Read a single byte of data from the radio memory
114  *
115  * \param [in]  address       The address of the first byte to write in the radio
116  *
117  * \retval      value         The value of the byte at the given address in radio's memory
118  */
119 uint8_t SX126xReadRegister( uint16_t address );
120 
121 /*!
122  * \brief Sets the radio output power.
123  *
124  * \param [IN] power Sets the RF output power
125  */
126 void SX126xSetRfTxPower( int8_t power );
127 
128 /*!
129  * \brief Gets the device ID
130  *
131  * \retval id Connected device ID
132  */
133 uint8_t SX126xGetDeviceId( void );
134 
135 /*!
136  * \brief Initializes the RF Switch I/Os pins interface
137  */
138 void SX126xAntSwOn( void );
139 
140 /*!
141  * \brief De-initializes the RF Switch I/Os pins interface
142  *
143  * \remark Needed to decrease the power consumption in MCU low power modes
144  */
145 void SX126xAntSwOff( void );
146 
147 /*!
148  * \brief Checks if the given RF frequency is supported by the hardware
149  *
150  * \param [IN] frequency RF frequency to be checked
151  * \retval isSupported [true: supported, false: unsupported]
152  */
153 bool SX126xCheckRfFrequency( uint32_t frequency );
154 
155 /*!
156  * \brief Gets the Defines the time required for the TCXO to wakeup [ms].
157  *
158  * \retval time Board TCXO wakeup time in ms.
159  */
160 uint32_t SX126xGetBoardTcxoWakeupTime( void );
161 
162 /*!
163  * \brief Gets current state of DIO1 pin state.
164  *
165  * \retval state DIO1 pin current state.
166  */
167 uint32_t SX126xGetDio1PinState( void );
168 
169 /*!
170  * \brief Gets the current Radio OperationMode variable
171  *
172  * \retval      RadioOperatingModes_t last operating mode
173  */
174 RadioOperatingModes_t SX126xGetOperatingMode( void );
175 
176 /*!
177  * \brief Sets/Updates the current Radio OperationMode variable.
178  *
179  * \remark WARNING: This function is only required to reflect the current radio
180  *                  operating mode when processing interrupts.
181  *
182  * \param [in] mode           New operating mode
183  */
184 void SX126xSetOperatingMode( RadioOperatingModes_t mode );
185 
186 /*!
187  * Radio hardware and global parameters
188  */
189 extern SX126x_t SX126x;
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif // __SX126x_BOARD_H__
196