LibDriver NRF905
Loading...
Searching...
No Matches
driver_nrf905_basic.c
Go to the documentation of this file.
1
36
37#include "driver_nrf905_basic.h"
38
39static nrf905_handle_t gs_handle;
40
49{
50 if (nrf905_irq_handler(&gs_handle) != 0)
51 {
52 return 1;
53 }
54 else
55 {
56 return 0;
57 }
58}
59
69uint8_t nrf905_basic_init(nrf905_mode_t mode, void (*callback)(uint8_t type, uint8_t *buf, uint8_t len))
70{
71 uint8_t res;
72 uint16_t reg;
73 uint8_t addr[4] = NRF905_BASIC_DEFAULT_RX_ADDR;
74
75 /* link function */
93 DRIVER_NRF905_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
94
95 /* init */
96 res = nrf905_init(&gs_handle);
97 if (res != 0)
98 {
99 nrf905_interface_debug_print("nrf905: init failed.\n");
100
101 return 1;
102 }
103
104 /* power up the chip */
105 res = nrf905_set_power_up(&gs_handle, NRF905_BOOL_TRUE);
106 if (res != 0)
107 {
108 nrf905_interface_debug_print("nrf905: power up failed.\n");
109 (void)nrf905_deinit(&gs_handle);
110
111 return 1;
112 }
113
114 /* disable the chip */
115 res = nrf905_set_enable(&gs_handle, NRF905_BOOL_FALSE);
116 if (res != 0)
117 {
118 nrf905_interface_debug_print("nrf905: set enable failed.\n");
119 (void)nrf905_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* set the pll mode */
126 if (res != 0)
127 {
128 nrf905_interface_debug_print("nrf905: set pll mode failed.\n");
129 (void)nrf905_deinit(&gs_handle);
130
131 return 1;
132 }
133
134 /* set the output power */
136 if (res != 0)
137 {
138 nrf905_interface_debug_print("nrf905: set output power failed.\n");
139 (void)nrf905_deinit(&gs_handle);
140
141 return 1;
142 }
143
144 /* set the rx mode */
146 if (res != 0)
147 {
148 nrf905_interface_debug_print("nrf905: set rx mode failed.\n");
149 (void)nrf905_deinit(&gs_handle);
150
151 return 1;
152 }
153
154 /* set the auto retransmit */
156 if (res != 0)
157 {
158 nrf905_interface_debug_print("nrf905: set auto retransmit failed.\n");
159 (void)nrf905_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* set the rx address width */
166 if (res != 0)
167 {
168 nrf905_interface_debug_print("nrf905: set rx address width failed.\n");
169 (void)nrf905_deinit(&gs_handle);
170
171 return 1;
172 }
173
174 /* set the tx address width */
176 if (res != 0)
177 {
178 nrf905_interface_debug_print("nrf905: set tx address width failed.\n");
179 (void)nrf905_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* set the rx payload width */
186 if (res != 0)
187 {
188 nrf905_interface_debug_print("nrf905: set rx payload width failed.\n");
189 (void)nrf905_deinit(&gs_handle);
190
191 return 1;
192 }
193
194 /* set the tx payload width */
196 if (res != 0)
197 {
198 nrf905_interface_debug_print("nrf905: set tx payload width failed.\n");
199 (void)nrf905_deinit(&gs_handle);
200
201 return 1;
202 }
203
204 /* set the rx address */
205 res = nrf905_set_rx_address(&gs_handle, (uint8_t *)addr);
206 if (res != 0)
207 {
208 nrf905_interface_debug_print("nrf905: set rx address failed.\n");
209 (void)nrf905_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* set output clock frequency */
216 if (res != 0)
217 {
218 nrf905_interface_debug_print("nrf905: set output clock frequency failed.\n");
219 (void)nrf905_deinit(&gs_handle);
220
221 return 1;
222 }
223
224 /* set the output clock */
226 if (res != 0)
227 {
228 nrf905_interface_debug_print("nrf905: set output clock failed.\n");
229 (void)nrf905_deinit(&gs_handle);
230
231 return 1;
232 }
233
234 /* set the crystal oscillator frequency */
236 if (res != 0)
237 {
238 nrf905_interface_debug_print("nrf905: set crystal oscillator frequency failed.\n");
239 (void)nrf905_deinit(&gs_handle);
240
241 return 1;
242 }
243
244 /* set the crc */
245 res = nrf905_set_crc(&gs_handle, NRF905_BASIC_DEFAULT_CRC);
246 if (res != 0)
247 {
248 nrf905_interface_debug_print("nrf905: set crc failed.\n");
249 (void)nrf905_deinit(&gs_handle);
250
251 return 1;
252 }
253
254 /* set the crc mode */
256 if (res != 0)
257 {
258 nrf905_interface_debug_print("nrf905: set crc mode failed.\n");
259 (void)nrf905_deinit(&gs_handle);
260
261 return 1;
262 }
263
264 /* 433 MHz */
266 if (res != 0)
267 {
268 nrf905_interface_debug_print("nrf905: frequency convert to register failed.\n");
269 (void)nrf905_deinit(&gs_handle);
270
271 return 1;
272 }
273
274 /* set the frequency */
275 res = nrf905_set_frequency(&gs_handle, reg);
276 if (res != 0)
277 {
278 nrf905_interface_debug_print("nrf905: set frequency failed.\n");
279 (void)nrf905_deinit(&gs_handle);
280
281 return 1;
282 }
283
284 /* write the conf */
285 res = nrf905_write_conf(&gs_handle);
286 if (res != 0)
287 {
288 nrf905_interface_debug_print("nrf905: write conf failed.\n");
289 (void)nrf905_deinit(&gs_handle);
290
291 return 1;
292 }
293
294 if (mode == NRF905_MODE_TX)
295 {
296 return 0;
297 }
298 else
299 {
300 /* set rx mode */
301 res = nrf905_set_mode(&gs_handle, NRF905_MODE_RX);
302 if (res != 0)
303 {
304 nrf905_interface_debug_print("nrf905: set mode failed.\n");
305 (void)nrf905_deinit(&gs_handle);
306
307 return 1;
308 }
309
310 /* enable the chip */
311 res = nrf905_set_enable(&gs_handle, NRF905_BOOL_TRUE);
312 if (res != 0)
313 {
314 nrf905_interface_debug_print("nrf905: set enable failed.\n");
315 (void)nrf905_deinit(&gs_handle);
316
317 return 1;
318 }
319
320 return 0;
321 }
322}
323
332{
333 if (nrf905_deinit(&gs_handle) != 0)
334 {
335 return 1;
336 }
337 else
338 {
339 return 0;
340 }
341}
342
353uint8_t nrf905_basic_send(uint8_t *addr, uint8_t *buf, uint8_t len)
354{
355 uint8_t res;
356
357 /* set tx address */
358 res = nrf905_set_tx_address(&gs_handle, addr, 4);
359 if (res != 0)
360 {
361 return 1;
362 }
363
364 /* send data */
365 res = nrf905_send(&gs_handle, (uint8_t *)buf, len);
366 if (res != 0)
367 {
368 return 1;
369 }
370
371 return 0;
372}
driver nrf905 basic header file
uint8_t nrf905_set_output_clock(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the output clock
uint8_t nrf905_set_frequency(nrf905_handle_t *handle, uint16_t freq)
set the frequency
uint8_t nrf905_set_tx_payload_width(nrf905_handle_t *handle, uint8_t width)
set the tx payload width
uint8_t nrf905_init(nrf905_handle_t *handle)
initialize the chip
uint8_t nrf905_frequency_convert_to_register(nrf905_handle_t *handle, float mhz, uint16_t *reg)
convert the frequency to the register raw data
uint8_t nrf905_set_crc_mode(nrf905_handle_t *handle, nrf905_crc_mode_t mode)
set the crc mode
uint8_t nrf905_set_pll_mode(nrf905_handle_t *handle, nrf905_pll_mode_t mode)
set the pll mode
nrf905_mode_t
nrf905 mode enumeration definition
uint8_t nrf905_set_output_power(nrf905_handle_t *handle, nrf905_output_power_t output_power)
set the output power
uint8_t nrf905_set_enable(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the chip
uint8_t nrf905_set_rx_payload_width(nrf905_handle_t *handle, uint8_t width)
set the rx payload width
uint8_t nrf905_set_power_up(nrf905_handle_t *handle, nrf905_bool_t enable)
set the power up
uint8_t nrf905_set_rx_address_width(nrf905_handle_t *handle, nrf905_address_width_t width)
set the rx address width
uint8_t nrf905_send(nrf905_handle_t *handle, uint8_t *buf, uint8_t len)
send data
uint8_t nrf905_set_crystal_oscillator_frequency(nrf905_handle_t *handle, nrf905_crystal_oscillator_frequency_t freq)
set the crystal oscillator frequency
uint8_t nrf905_set_rx_address(nrf905_handle_t *handle, uint8_t addr[4])
set the rx address
uint8_t nrf905_set_tx_address_width(nrf905_handle_t *handle, nrf905_address_width_t width)
set the tx address width
uint8_t nrf905_set_tx_address(nrf905_handle_t *handle, uint8_t *addr, uint8_t len)
set the tx address
uint8_t nrf905_set_rx_mode(nrf905_handle_t *handle, nrf905_rx_mode_t mode)
set the rx mode
uint8_t nrf905_write_conf(nrf905_handle_t *handle)
write the conf
uint8_t nrf905_irq_handler(nrf905_handle_t *handle)
irq handler
uint8_t nrf905_set_auto_retransmit(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the auto retransmit
uint8_t nrf905_set_output_clock_frequency(nrf905_handle_t *handle, nrf905_output_clock_frequency_t freq)
set the output clock frequency
uint8_t nrf905_set_mode(nrf905_handle_t *handle, nrf905_mode_t mode)
set the mode
struct nrf905_handle_s nrf905_handle_t
nrf905 handle structure definition
uint8_t nrf905_set_crc(nrf905_handle_t *handle, nrf905_bool_t enable)
enable or disable the crc
uint8_t nrf905_deinit(nrf905_handle_t *handle)
close the chip
@ NRF905_MODE_RX
@ NRF905_MODE_TX
@ NRF905_BOOL_FALSE
@ NRF905_BOOL_TRUE
#define NRF905_BASIC_DEFAULT_CRYSTAL_OSCILLATOR_FREQUENCY
#define NRF905_BASIC_DEFAULT_RX_ADDRESS_WIDTH
#define NRF905_BASIC_DEFAULT_RX_PAYLOAD_WIDTH
#define NRF905_BASIC_DEFAULT_PLL_MODE
nrf905 basic example default definition
#define NRF905_BASIC_DEFAULT_OUTPUT_CLOCK_FREQUENCY
#define NRF905_BASIC_DEFAULT_AUTO_RETRANSMIT
uint8_t nrf905_basic_deinit(void)
basic example deinit
#define NRF905_BASIC_DEFAULT_OUTPUT_POWER
#define NRF905_BASIC_DEFAULT_RX_MODE
uint8_t nrf905_basic_send(uint8_t *addr, uint8_t *buf, uint8_t len)
basic example send
#define NRF905_BASIC_DEFAULT_TX_PAYLOAD_WIDTH
#define NRF905_BASIC_DEFAULT_CRC_MODE
#define NRF905_BASIC_DEFAULT_TX_ADDRESS_WIDTH
#define NRF905_BASIC_DEFAULT_RX_ADDR
#define NRF905_BASIC_DEFAULT_CRC
uint8_t nrf905_interrupt_irq_handler(void)
nrf905 irq
uint8_t nrf905_basic_init(nrf905_mode_t mode, void(*callback)(uint8_t type, uint8_t *buf, uint8_t len))
basic example init
#define NRF905_BASIC_DEFAULT_OUTPUT_CLOCK
#define NRF905_BASIC_DEFAULT_FREQUENCY
uint8_t nrf905_interface_spi_deinit(void)
interface spi bus deinit
uint8_t nrf905_interface_spi_init(void)
interface spi bus init
uint8_t nrf905_interface_spi_transmit(uint8_t *tx, uint8_t *rx, uint16_t len)
interface spi bus transmit
void nrf905_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t nrf905_interface_ce_gpio_init(void)
interface ce gpio init
uint8_t nrf905_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t nrf905_interface_pwr_up_gpio_init(void)
interface pwr up gpio init
void nrf905_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t nrf905_interface_pwr_up_gpio_write(uint8_t data)
interface pwr up gpio write
uint8_t nrf905_interface_tx_en_gpio_write(uint8_t data)
interface tx en gpio write
uint8_t nrf905_interface_pwr_up_gpio_deinit(void)
interface pwr up gpio deinit
uint8_t nrf905_interface_ce_gpio_write(uint8_t data)
interface ce gpio write
uint8_t nrf905_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t nrf905_interface_tx_en_gpio_init(void)
interface tx en gpio init
uint8_t nrf905_interface_ce_gpio_deinit(void)
interface ce gpio deinit
uint8_t nrf905_interface_tx_en_gpio_deinit(void)
interface tx en gpio deinit