-
Notifications
You must be signed in to change notification settings - Fork 96
/
nrf24.h
116 lines (96 loc) · 4.14 KB
/
nrf24.h
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
/*
* ----------------------------------------------------------------------------
* “THE COFFEEWARE LICENSE” (Revision 1):
* <[email protected]> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a coffee in return.
* -----------------------------------------------------------------------------
* This library is based on this library:
* https://github.com/aaronds/arduino-nrf24l01
* Which is based on this library:
* http://www.tinkerer.eu/AVRLib/nRF24L01
* -----------------------------------------------------------------------------
*/
#ifndef NRF24
#define NRF24
#include "nRF24L01.h"
#include <stdint.h>
#define LOW 0
#define HIGH 1
#define nrf24_ADDR_LEN 5
#define nrf24_CONFIG ((1<<EN_CRC)|(0<<CRCO))
#define NRF24_TRANSMISSON_OK 0
#define NRF24_MESSAGE_LOST 1
/* adjustment functions */
void nrf24_init();
void nrf24_rx_address(uint8_t* adr);
void nrf24_tx_address(uint8_t* adr);
void nrf24_config(uint8_t channel, uint8_t pay_length);
/* state check functions */
uint8_t nrf24_dataReady();
uint8_t nrf24_isSending();
uint8_t nrf24_getStatus();
uint8_t nrf24_rxFifoEmpty();
/* core TX / RX functions */
void nrf24_send(uint8_t* value);
void nrf24_getData(uint8_t* data);
/* use in dynamic length mode */
uint8_t nrf24_payloadLength();
/* post transmission analysis */
uint8_t nrf24_lastMessageStatus();
uint8_t nrf24_retransmissionCount();
/* Returns the payload length */
uint8_t nrf24_payload_length();
/* power management */
void nrf24_powerUpRx();
void nrf24_powerUpTx();
void nrf24_powerDown();
/* low level interface ... */
uint8_t spi_transfer(uint8_t tx);
void nrf24_transmitSync(uint8_t* dataout,uint8_t len);
void nrf24_transferSync(uint8_t* dataout,uint8_t* datain,uint8_t len);
void nrf24_configRegister(uint8_t reg, uint8_t value);
void nrf24_readRegister(uint8_t reg, uint8_t* value, uint8_t len);
void nrf24_writeRegister(uint8_t reg, uint8_t* value, uint8_t len);
/* -------------------------------------------------------------------------- */
/* You should implement the platform spesific functions in your code */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* In this function you should do the following things:
* - Set MISO pin input
* - Set MOSI pin output
* - Set SCK pin output
* - Set CSN pin output
* - Set CE pin output */
/* -------------------------------------------------------------------------- */
extern void nrf24_setupPins();
/* -------------------------------------------------------------------------- */
/* nrf24 CE pin control function
* - state:1 => Pin HIGH
* - state:0 => Pin LOW */
/* -------------------------------------------------------------------------- */
extern void nrf24_ce_digitalWrite(uint8_t state);
/* -------------------------------------------------------------------------- */
/* nrf24 CE pin control function
* - state:1 => Pin HIGH
* - state:0 => Pin LOW */
/* -------------------------------------------------------------------------- */
extern void nrf24_csn_digitalWrite(uint8_t state);
/* -------------------------------------------------------------------------- */
/* nrf24 SCK pin control function
* - state:1 => Pin HIGH
* - state:0 => Pin LOW */
/* -------------------------------------------------------------------------- */
extern void nrf24_sck_digitalWrite(uint8_t state);
/* -------------------------------------------------------------------------- */
/* nrf24 MOSI pin control function
* - state:1 => Pin HIGH
* - state:0 => Pin LOW */
/* -------------------------------------------------------------------------- */
extern void nrf24_mosi_digitalWrite(uint8_t state);
/* -------------------------------------------------------------------------- */
/* nrf24 MISO pin read function
/* - returns: Non-zero if the pin is high */
/* -------------------------------------------------------------------------- */
extern uint8_t nrf24_miso_digitalRead();
#endif