1 | /*
|
2 | * ----------------------------------------------------------------------------
|
3 | * “THE COFFEEWARE LICENSE” (Revision 1):
|
4 | * <ihsan@kehribar.me> wrote this file. As long as you retain this notice you
|
5 | * can do whatever you want with this stuff. If we meet some day, and you think
|
6 | * this stuff is worth it, you can buy me a coffee in return.
|
7 | * -----------------------------------------------------------------------------
|
8 | * This library is based on this library:
|
9 | * https://github.com/aaronds/arduino-nrf24l01
|
10 | * Which is based on this library:
|
11 | * http://www.tinkerer.eu/AVRLib/nRF24L01
|
12 | * -----------------------------------------------------------------------------
|
13 | */
|
14 | #ifndef NRF24
|
15 | #define NRF24
|
16 |
|
17 | #include "nRF24L01.h"
|
18 | #include <stdint.h>
|
19 | #include <avr/io.h>
|
20 |
|
21 | // Pin definitions for chip select and chip enabled of the wl-module
|
22 | #define CE PB0
|
23 | #define CSN PB1
|
24 |
|
25 | // Definitions for selecting and enabling wl_module module
|
26 | #define wl_module_CSN_hi PORTB |= (1<<CSN);
|
27 | #define wl_module_CSN_lo PORTB &= ~(1<<CSN);
|
28 | #define wl_module_CE_hi PORTB |= (1<<CE);
|
29 | #define wl_module_CE_lo PORTB &= ~(1<<CE);
|
30 | /* ------------------------------------------------------------------------- */
|
31 |
|
32 | #define nrf24_ADDR_LEN 5
|
33 | #define nrf24_CONFIG ((1<<EN_CRC)|(0<<CRCO))
|
34 |
|
35 | #define NRF24_TRANSMISSON_OK 0
|
36 | #define NRF24_MESSAGE_LOST 1
|
37 |
|
38 | /* adjustment functions */
|
39 | void nrf24_init();
|
40 | void nrf24_rx_address(uint8_t* adr);
|
41 | void nrf24_tx_address(uint8_t* adr);
|
42 | void nrf24_config(uint8_t channel, uint8_t pay_length);
|
43 |
|
44 | /* state check functions */
|
45 | uint8_t nrf24_dataReady();
|
46 | uint8_t nrf24_isSending();
|
47 | uint8_t nrf24_getStatus();
|
48 | uint8_t nrf24_rxFifoEmpty();
|
49 |
|
50 | /* core TX / RX functions */
|
51 | void nrf24_send(uint8_t* value);
|
52 | void nrf24_getData(uint8_t* data);
|
53 |
|
54 | /* use in dynamic length mode */
|
55 | uint8_t nrf24_payloadLength();
|
56 |
|
57 | /* post transmission analysis */
|
58 | uint8_t nrf24_lastMessageStatus();
|
59 | uint8_t nrf24_retransmissionCount();
|
60 |
|
61 | /* Returns the payload length */
|
62 | uint8_t nrf24_payload_length();
|
63 |
|
64 | /* power management */
|
65 | void nrf24_powerUpRx();
|
66 | void nrf24_powerUpTx();
|
67 | void nrf24_powerDown();
|
68 |
|
69 | /* low level interface ... */
|
70 | extern void spi_init();
|
71 | extern uint8_t spi_fast_shift(uint8_t tx);
|
72 | extern void spi_transmit_sync(uint8_t* dataout,uint8_t len);
|
73 | extern void spi_transfer_sync(uint8_t* dataout,uint8_t* datain,uint8_t len);
|
74 | void nrf24_configRegister(uint8_t reg, uint8_t value);
|
75 | void nrf24_readRegister(uint8_t reg, uint8_t* value, uint8_t len);
|
76 | void nrf24_writeRegister(uint8_t reg, uint8_t* value, uint8_t len);
|
77 |
|
78 | /* -------------------------------------------------------------------------- */
|
79 |
|
80 | #endif
|