提交 | 用户 | age
|
5dd1b7
|
1 |
/* |
Q |
2 |
______ _ |
|
3 |
/ _____) _ | | |
|
4 |
( (____ _____ ____ _| |_ _____ ____| |__ |
|
5 |
\____ \| ___ | (_ _) ___ |/ ___) _ \ |
|
6 |
_____) ) ____| | | || |_| ____( (___| | | | |
|
7 |
(______/|_____)_|_|_| \__)_____)\____)_| |_| |
|
8 |
(C)2013 Semtech |
|
9 |
|
|
10 |
Description: SX126x driver specific target board functions implementation |
|
11 |
|
|
12 |
License: Revised BSD License, see LICENSE.TXT file include in the project |
|
13 |
|
|
14 |
Maintainer: Miguel Luis and Gregory Cristian |
|
15 |
*/ |
|
16 |
#include "stm32f0xx.h" |
|
17 |
#include "delay.h" |
|
18 |
#include "gpio.h" |
|
19 |
#include "spi.h" |
|
20 |
#include "radio.h" |
|
21 |
#include "sx126x.h" |
|
22 |
#include "sx126x-board.h" |
|
23 |
|
|
24 |
|
|
25 |
void SX126xReset( void ) |
|
26 |
{ |
|
27 |
HAL_Delay_nMS( 10 ); |
|
28 |
SetRadionRSTPin_0(); |
|
29 |
HAL_Delay_nMS( 20 ); |
|
30 |
SetRadionRSTPin_1(); |
|
31 |
HAL_Delay_nMS( 10 ); |
|
32 |
} |
|
33 |
|
|
34 |
void SX126xWaitOnBusy( void ) |
|
35 |
{ |
|
36 |
while(GetRadioBusyPin()); |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
void SX126xWakeup( void ) |
|
41 |
{ |
|
42 |
SetRadioNSSPin_0(); |
|
43 |
|
|
44 |
SpiInOut(RADIO_GET_STATUS); |
|
45 |
SpiInOut(0); |
|
46 |
|
|
47 |
SetRadioNSSPin_1(); |
|
48 |
|
|
49 |
// Wait for chip to be ready. |
|
50 |
SX126xWaitOnBusy( ); |
|
51 |
} |
|
52 |
|
|
53 |
void SX126xWriteCommand( RadioCommands_t command, uint8_t *buffer, uint16_t size ) |
|
54 |
{ |
|
55 |
|
|
56 |
SX126xCheckDeviceReady( ); |
|
57 |
|
|
58 |
SetRadioNSSPin_0(); |
|
59 |
|
|
60 |
SpiInOut(( uint8_t )command ); |
|
61 |
|
|
62 |
for( uint16_t i = 0; i < size; i++ ) |
|
63 |
{ |
|
64 |
SpiInOut(buffer[i] ); |
|
65 |
} |
|
66 |
|
|
67 |
SetRadioNSSPin_1(); |
|
68 |
|
|
69 |
if( command != RADIO_SET_SLEEP ) |
|
70 |
{ |
|
71 |
SX126xWaitOnBusy( ); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
void SX126xReadCommand( RadioCommands_t command, uint8_t *buffer, uint16_t size ) |
|
76 |
{ |
|
77 |
SX126xCheckDeviceReady( ); |
|
78 |
|
|
79 |
SetRadioNSSPin_0(); |
|
80 |
|
|
81 |
SpiInOut(( uint8_t )command ); |
|
82 |
SpiInOut(0x00 ); |
|
83 |
for( uint16_t i = 0; i < size; i++ ) |
|
84 |
{ |
|
85 |
buffer[i] = SpiInOut(0 ); |
|
86 |
} |
|
87 |
|
|
88 |
SetRadioNSSPin_1(); |
|
89 |
|
|
90 |
SX126xWaitOnBusy( ); |
|
91 |
} |
|
92 |
|
|
93 |
void SX126xWriteRegisters( uint16_t address, uint8_t *buffer, uint16_t size ) |
|
94 |
{ |
|
95 |
SX126xCheckDeviceReady( ); |
|
96 |
|
|
97 |
SetRadioNSSPin_0(); |
|
98 |
|
|
99 |
SpiInOut(RADIO_WRITE_REGISTER ); |
|
100 |
SpiInOut(( address & 0xFF00 ) >> 8 ); |
|
101 |
SpiInOut( address & 0x00FF ); |
|
102 |
|
|
103 |
for( uint16_t i = 0; i < size; i++ ) |
|
104 |
{ |
|
105 |
SpiInOut(buffer[i] ); |
|
106 |
} |
|
107 |
|
|
108 |
|
|
109 |
SetRadioNSSPin_1(); |
|
110 |
|
|
111 |
SX126xWaitOnBusy( ); |
|
112 |
} |
|
113 |
|
|
114 |
void SX126xWriteRegister( uint16_t address, uint8_t value ) |
|
115 |
{ |
|
116 |
SX126xWriteRegisters( address, &value, 1 ); |
|
117 |
} |
|
118 |
|
|
119 |
void SX126xReadRegisters( uint16_t address, uint8_t *buffer, uint16_t size ) |
|
120 |
{ |
|
121 |
SX126xCheckDeviceReady( ); |
|
122 |
|
|
123 |
SetRadioNSSPin_0(); |
|
124 |
|
|
125 |
SpiInOut(RADIO_READ_REGISTER ); |
|
126 |
SpiInOut(( address & 0xFF00 ) >> 8 ); |
|
127 |
SpiInOut( address & 0x00FF ); |
|
128 |
SpiInOut( 0 ); |
|
129 |
for( uint16_t i = 0; i < size; i++ ) |
|
130 |
{ |
|
131 |
buffer[i] = SpiInOut(0 ); |
|
132 |
} |
|
133 |
|
|
134 |
SetRadioNSSPin_1(); |
|
135 |
|
|
136 |
SX126xWaitOnBusy( ); |
|
137 |
} |
|
138 |
|
|
139 |
uint8_t SX126xReadRegister( uint16_t address ) |
|
140 |
{ |
|
141 |
uint8_t data; |
|
142 |
SX126xReadRegisters( address, &data, 1 ); |
|
143 |
return data; |
|
144 |
} |
|
145 |
|
|
146 |
void SX126xWriteBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) |
|
147 |
{ |
|
148 |
SX126xCheckDeviceReady( ); |
|
149 |
|
|
150 |
SetRadioNSSPin_0(); |
|
151 |
|
|
152 |
SpiInOut( RADIO_WRITE_BUFFER ); |
|
153 |
SpiInOut( offset ); |
|
154 |
for( uint16_t i = 0; i < size; i++ ) |
|
155 |
{ |
|
156 |
SpiInOut( buffer[i] ); |
|
157 |
} |
|
158 |
|
|
159 |
SetRadioNSSPin_1(); |
|
160 |
|
|
161 |
SX126xWaitOnBusy( ); |
|
162 |
} |
|
163 |
|
|
164 |
void SX126xReadBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) |
|
165 |
{ |
|
166 |
SX126xCheckDeviceReady( ); |
|
167 |
|
|
168 |
SetRadioNSSPin_0(); |
|
169 |
|
|
170 |
SpiInOut( RADIO_READ_BUFFER ); |
|
171 |
SpiInOut( offset ); |
|
172 |
SpiInOut( 0 ); |
|
173 |
for( uint16_t i = 0; i < size; i++ ) |
|
174 |
{ |
|
175 |
buffer[i] = SpiInOut( 0 ); |
|
176 |
} |
|
177 |
|
|
178 |
SetRadioNSSPin_1(); |
|
179 |
|
|
180 |
SX126xWaitOnBusy( ); |
|
181 |
} |
|
182 |
|
|
183 |
void SX126xSetRfTxPower( int8_t power ) |
|
184 |
{ |
|
185 |
SX126xSetTxParams( power, RADIO_RAMP_40_US ); |
|
186 |
} |
|
187 |
|
|
188 |
uint8_t SX126xGetPaSelect( uint32_t channel ) |
|
189 |
{ |
|
190 |
// if( GpioRead( &DeviceSel ) == 1 ) |
|
191 |
// { |
|
192 |
// return SX1261; |
|
193 |
// } |
|
194 |
// else |
|
195 |
// { |
|
196 |
// return SX1262; |
|
197 |
// } |
|
198 |
|
|
199 |
return SX1262; |
|
200 |
} |
|
201 |
|
|
202 |
void SX126xAntSwOn( void ) |
|
203 |
{ |
|
204 |
//GpioInit( &AntPow, ANT_SWITCH_POWER, PIN_OUTPUT, PIN_PUSH_PULL, PIN_PULL_UP, 1 ); |
|
205 |
} |
|
206 |
|
|
207 |
void SX126xAntSwOff( void ) |
|
208 |
{ |
|
209 |
// GpioInit( &AntPow, ANT_SWITCH_POWER, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); |
|
210 |
} |
|
211 |
|
|
212 |
bool SX126xCheckRfFrequency( uint32_t frequency ) |
|
213 |
{ |
|
214 |
// Implement check. Currently all frequencies are supported |
|
215 |
return true; |
|
216 |
} |