1 /*!
2  * \file      sx1276-board.h
3  *
4  * \brief     Target board SX1276 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 __SX1276_BOARD_H__
24 #define __SX1276_BOARD_H__
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 #include "sx1276/sx1276.h"
34 
35 /*!
36  * \brief Radio hardware registers initialization definition
37  *
38  * \remark Can be automatically generated by the SX1276 GUI (not yet implemented)
39  */
40 #define RADIO_INIT_REGISTERS_VALUE                \
41 {                                                 \
42     { MODEM_FSK , REG_LNA                , 0x23 },\
43     { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
44     { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
45     { MODEM_FSK , REG_AFCFEI             , 0x01 },\
46     { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
47     { MODEM_FSK , REG_OSC                , 0x07 },\
48     { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
49     { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
50     { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
51     { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
52     { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
53     /* FIFO threshold set to 32 (31+1) */         \
54     { MODEM_FSK , REG_FIFOTHRESH         , 0x9F },\
55     { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
56     { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
57     { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
58     { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
59 }                                                 \
60 
61 #define RF_MID_BAND_THRESH                          525000000
62 
63 /*!
64  * \brief Initializes the radio I/Os pins interface
65  */
66 void SX1276IoInit( void );
67 
68 /*!
69  * \brief Initializes DIO IRQ handlers
70  *
71  * \param [IN] irqHandlers Array containing the IRQ callback functions
72  */
73 void SX1276IoIrqInit( DioIrqHandler **irqHandlers );
74 
75 /*!
76  * \brief De-initializes the radio I/Os pins interface.
77  *
78  * \remark Useful when going in MCU low power modes
79  */
80 void SX1276IoDeInit( void );
81 
82 /*!
83  * \brief Initializes the TCXO power pin.
84  */
85 void SX1276IoTcxoInit( void );
86 
87 /*!
88  * \brief Initializes the radio debug pins.
89  */
90 void SX1276IoDbgInit( void );
91 
92 /*!
93  * \brief Resets the radio
94  */
95 void SX1276Reset( void );
96 
97 /*!
98  * \brief Sets the radio output power.
99  *
100  * \param [IN] power Sets the RF output power
101  */
102 void SX1276SetRfTxPower( int8_t power );
103 
104 /*!
105  * \brief Set the RF Switch I/Os pins in low power mode
106  *
107  * \param [IN] status enable or disable
108  */
109 void SX1276SetAntSwLowPower( bool status );
110 
111 /*!
112  * \brief Initializes the RF Switch I/Os pins interface
113  */
114 void SX1276AntSwInit( void );
115 
116 /*!
117  * \brief De-initializes the RF Switch I/Os pins interface
118  *
119  * \remark Needed to decrease the power consumption in MCU low power modes
120  */
121 void SX1276AntSwDeInit( void );
122 
123 /*!
124  * \brief Controls the antenna switch if necessary.
125  *
126  * \remark see errata note
127  *
128  * \param [IN] opMode Current radio operating mode
129  */
130 void SX1276SetAntSw( uint8_t opMode );
131 
132 /*!
133  * \brief Checks if the given RF frequency is supported by the hardware
134  *
135  * \param [IN] frequency RF frequency to be checked
136  * \retval isSupported [true: supported, false: unsupported]
137  */
138 bool SX1276CheckRfFrequency( uint32_t frequency );
139 
140 /*!
141  * \brief Enables/disables the TCXO if available on board design.
142  *
143  * \param [IN] state TCXO enabled when true and disabled when false.
144  */
145 void SX1276SetBoardTcxo( uint8_t state );
146 
147 /*!
148  * \brief Gets the Defines the time required for the TCXO to wakeup [ms].
149  *
150  * \retval time Board TCXO wakeup time in ms.
151  */
152 uint32_t SX1276GetBoardTcxoWakeupTime( void );
153 
154 /*!
155  * \brief Gets current state of DIO1 pin state (FifoLevel).
156  *
157  * \retval state DIO1 pin current state.
158  */
159 uint32_t SX1276GetDio1PinState( void );
160 
161 /*!
162  * \brief Writes new Tx debug pin state
163  *
164  * \param [IN] state Debug pin state
165  */
166 void SX1276DbgPinTxWrite( uint8_t state );
167 
168 /*!
169  * \brief Writes new Rx debug pin state
170  *
171  * \param [IN] state Debug pin state
172  */
173 void SX1276DbgPinRxWrite( uint8_t state );
174 
175 /*!
176  * Radio hardware and global parameters
177  */
178 extern SX1276_t SX1276;
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif // __SX1276_BOARD_H__
185