Blame view

emetteur/SX1276Lib/sx1276/sx1276-hal.h 6.17 KB
64abd45d   rcavalie   arrangements fich...
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
  /*
   / _____)             _              | |
  ( (____  _____ ____ _| |_ _____  ____| |__
   \____ \| ___ |    (_   _) ___ |/ ___)  _ \
   _____) ) ____| | | || |_| ____( (___| | | |
  (______/|_____)_|_|_| \__)_____)\____)_| |_|
      (C) 2014 Semtech
  
  Description: -
  
  License: Revised BSD License, see LICENSE.TXT file include in the project
  
  Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  */
  #ifndef __SX1276_HAL_H__
  #define __SX1276_HAL_H__
  #include "sx1276.h"
  
  /*!
   * @brief Radio hardware registers initialization definition
   *
   * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
   */
  #define RADIO_INIT_REGISTERS_VALUE                \
  {                                                 \
      { MODEM_FSK , REG_LNA                , 0x23 },\
      { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
      { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
      { MODEM_FSK , REG_AFCFEI             , 0x01 },\
      { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
      { MODEM_FSK , REG_OSC                , 0x07 },\
      { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
      { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
      { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
      { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
      { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
      { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
      { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
      { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
      { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
      { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
  }                                                 \
  
  /*! 
   * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
   */
  class SX1276MB1xAS : public SX1276
  {
  protected:
      /*!
       * Antenna switch GPIO pins objects
       */
      DigitalInOut AntSwitch;
      DigitalIn Fake;
  
  private:
      static const RadioRegisters_t RadioRegsInit[];
  
  public:
      SX1276MB1xAS( RadioEvents_t *events,
              PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
              PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
              PinName antSwitch ); 
  
      SX1276MB1xAS( RadioEvents_t *events );
  
      virtual ~SX1276MB1xAS( ) { };
  
  protected:
      /*!
       * @brief Initializes the radio I/Os pins interface
       */
      virtual void IoInit( void );
  
      /*!
       *  @brief Initializes the radio registers
       */
      virtual void RadioRegistersInit( );
      
      /*!
       * @brief Initializes the radio SPI
       */
      virtual void SpiInit( void );
  
      /*!
       * @brief Initializes DIO IRQ handlers
       *
       * @param [IN] irqHandlers Array containing the IRQ callback functions
       */
      virtual void IoIrqInit( DioIrqHandler *irqHandlers );
  
      /*!
       * @brief De-initializes the radio I/Os pins interface. 
       *
       * \remark Useful when going in MCU lowpower modes
       */
      virtual void IoDeInit( void );
  
      /*!
       * \brief Sets the radio output power.
       *
       * @param [IN] power Sets the RF output power
       */
      virtual void SetRfTxPower( int8_t power );
  
      /*!
       * @brief Gets the board PA selection configuration
       *
       * @param [IN] channel Channel frequency in Hz
       * @retval PaSelect RegPaConfig PaSelect value
       */
      virtual uint8_t GetPaSelect( uint32_t channel );
  
      /*!
       * @brief Set the RF Switch I/Os pins in Low Power mode
       *
       * @param [IN] status enable or disable
       */
      virtual void SetAntSwLowPower( bool status );
  
      /*!
       * @brief Initializes the RF Switch I/Os pins interface
       */
      virtual void AntSwInit( void );
  
      /*!
       * @brief De-initializes the RF Switch I/Os pins interface 
       *
       * @remark Needed to decrease the power consumption in MCU lowpower modes
       */
      virtual void AntSwDeInit( void );
  
      /*!
       * @brief Controls the antena switch if necessary.
       *
       * @remark see errata note
       *
       * @param [IN] opMode Current radio operating mode
       */
      virtual void SetAntSw( uint8_t opMode );
  
  public:
      /*!
       * @brief Detect the board connected by reading the value of the antenna switch pin
       */
      virtual uint8_t DetectBoardType( 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]
       */
      virtual bool CheckRfFrequency( uint32_t frequency );
  
      /*!
       * @brief Writes the radio register at the specified address
       *
       * @param [IN]: addr Register address
       * @param [IN]: data New register value
       */
      virtual void virtual void Write ( uint8_t addr, uint8_t data ) ; ( uint8_t addr, uint8_t data ) virtual void Write ( uint8_t addr, uint8_t data ) ;
  
      /*!
       * @brief Reads the radio register at the specified address
       *
       * @param [IN]: addr Register address
       * @retval data Register value
       */
      virtual uint8_t virtual uint8_t Read ( uint8_t addr ) ; ( uint8_t addr ) virtual uint8_t Read ( uint8_t addr ) ;
  
      /*!
       * @brief Writes multiple radio registers starting at address
       *
       * @param [IN] addr   First Radio register address
       * @param [IN] buffer Buffer containing the new register's values
       * @param [IN] size   Number of registers to be written
       */
      virtual void virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;( uint8_t addr, uint8_t *buffer, uint8_t size ) virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
  
      /*!
       * @brief Reads multiple radio registers starting at address
       *
       * @param [IN] addr First Radio register address
       * @param [OUT] buffer Buffer where to copy the registers data
       * @param [IN] size Number of registers to be read
       */
      virtual void virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ; ( uint8_t addr, uint8_t *buffer, uint8_t size ) virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
  
      /*!
       * @brief Writes the buffer contents to the SX1276 FIFO
       *
       * @param [IN] buffer Buffer containing data to be put on the FIFO.
       * @param [IN] size Number of bytes to be written to the FIFO
       */
      virtual void virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;( uint8_t *buffer, uint8_t size ) virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
  
      /*!
       * @brief Reads the contents of the SX1276 FIFO
       *
       * @param [OUT] buffer Buffer where to copy the FIFO read data.
       * @param [IN] size Number of bytes to be read from the FIFO
       */
      virtual void virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;( uint8_t *buffer, uint8_t size ) virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
  
      /*!
       * @brief Reset the SX1276
       */
      virtual void Reset( void );
  };
  
  #endif // __SX1276_HAL_H__