22
22
23
23
#include " RF24.h"
24
24
25
- static uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID };
26
- static uint8_t MY_RF24_NODE_ADDRESS = AUTO;
25
+ LOCAL uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID };
26
+ LOCAL uint8_t MY_RF24_NODE_ADDRESS = AUTO;
27
27
28
- void RF24_csn (bool level) {
28
+ LOCAL void RF24_csn (bool level) {
29
29
digitalWrite (MY_RF24_CS_PIN, level);
30
30
}
31
31
32
- void RF24_ce (bool level) {
32
+ LOCAL void RF24_ce (bool level) {
33
33
digitalWrite (MY_RF24_CE_PIN, level);
34
34
}
35
35
36
- uint8_t RF24_spiMultiByteTransfer (uint8_t cmd, uint8_t * buf, uint8_t len, bool aReadMode) {
36
+ LOCAL uint8_t RF24_spiMultiByteTransfer (uint8_t cmd, uint8_t * buf, uint8_t len, bool aReadMode) {
37
37
uint8_t * current = buf;
38
38
#if !defined(MY_SOFTSPI)
39
39
_SPI.beginTransaction (SPISettings (MY_RF24_SPI_MAX_SPEED, MY_RF24_SPI_DATA_ORDER, MY_RF24_SPI_DATA_MODE));
@@ -57,43 +57,43 @@ uint8_t RF24_spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool a
57
57
return status;
58
58
}
59
59
60
- uint8_t RF24_spiByteTransfer (uint8_t cmd) {
60
+ LOCAL uint8_t RF24_spiByteTransfer (uint8_t cmd) {
61
61
return RF24_spiMultiByteTransfer ( cmd, NULL , 0 , false );
62
62
}
63
63
64
- uint8_t RF24_RAW_readByteRegister (uint8_t cmd) {
64
+ LOCAL uint8_t RF24_RAW_readByteRegister (uint8_t cmd) {
65
65
uint8_t value = RF24_spiMultiByteTransfer ( cmd, NULL , 1 , true );
66
66
RF24_DEBUG (PSTR (" read register, reg=%d, value=%d\n " ), cmd & (R_REGISTER ^ 0xFF ), value);
67
67
return value;
68
68
}
69
69
70
- uint8_t RF24_RAW_writeByteRegister (uint8_t cmd, uint8_t value) {
70
+ LOCAL uint8_t RF24_RAW_writeByteRegister (uint8_t cmd, uint8_t value) {
71
71
RF24_DEBUG (PSTR (" write register, reg=%d, value=%d\n " ), cmd & (W_REGISTER ^ 0xFF ), value);
72
72
return RF24_spiMultiByteTransfer ( cmd , &value, 1 , false );
73
73
}
74
74
75
- void RF24_flushRX (void ) {
75
+ LOCAL void RF24_flushRX (void ) {
76
76
RF24_DEBUG (PSTR (" RF24_flushRX\n " ));
77
77
RF24_spiByteTransfer ( FLUSH_RX );
78
78
}
79
79
80
- void RF24_flushTX (void ) {
80
+ LOCAL void RF24_flushTX (void ) {
81
81
RF24_DEBUG (PSTR (" RF24_flushTX\n " ));
82
82
RF24_spiByteTransfer ( FLUSH_TX );
83
83
}
84
84
85
- uint8_t RF24_getStatus (void ) {
85
+ LOCAL uint8_t RF24_getStatus (void ) {
86
86
return RF24_spiByteTransfer ( NOP );
87
87
}
88
88
89
- void RF24_openWritingPipe (uint8_t recipient) {
89
+ LOCAL void RF24_openWritingPipe (uint8_t recipient) {
90
90
RF24_DEBUG (PSTR (" open writing pipe, recipient=%d\n " ), recipient);
91
91
// only write LSB of RX0 and TX pipe
92
92
RF24_writeByteRegister (RX_ADDR_P0, recipient);
93
93
RF24_writeByteRegister (TX_ADDR, recipient);
94
94
}
95
95
96
- void RF24_startListening (void ) {
96
+ LOCAL void RF24_startListening (void ) {
97
97
RF24_DEBUG (PSTR (" start listening\n " ));
98
98
// toggle PRX
99
99
RF24_writeByteRegister (NRF_CONFIG, MY_RF24_CONFIGURATION | _BV (PWR_UP) | _BV (PRIM_RX) );
@@ -103,7 +103,7 @@ void RF24_startListening(void) {
103
103
RF24_ce (HIGH);
104
104
}
105
105
106
- void RF24_stopListening (void ) {
106
+ LOCAL void RF24_stopListening (void ) {
107
107
RF24_DEBUG (PSTR (" stop listening\n " ));
108
108
RF24_ce (LOW);
109
109
// timing
@@ -113,13 +113,13 @@ void RF24_stopListening(void) {
113
113
delayMicroseconds (100 );
114
114
}
115
115
116
- void RF24_powerDown (void ) {
116
+ LOCAL void RF24_powerDown (void ) {
117
117
RF24_ce (LOW);
118
118
RF24_writeByteRegister (NRF_CONFIG, 0x00 );
119
119
RF24_DEBUG (PSTR (" power down\n " ));
120
120
}
121
121
122
- bool RF24_sendMessage ( uint8_t recipient, const void * buf, uint8_t len ) {
122
+ LOCAL bool RF24_sendMessage ( uint8_t recipient, const void * buf, uint8_t len ) {
123
123
uint8_t status;
124
124
125
125
RF24_stopListening ();
@@ -153,7 +153,7 @@ bool RF24_sendMessage( uint8_t recipient, const void* buf, uint8_t len ) {
153
153
return (status & _BV (TX_DS));
154
154
}
155
155
156
- uint8_t RF24_getDynamicPayloadSize (void ) {
156
+ LOCAL uint8_t RF24_getDynamicPayloadSize (void ) {
157
157
uint8_t result = RF24_spiMultiByteTransfer (R_RX_PL_WID,NULL ,1 ,true );
158
158
// check if payload size invalid
159
159
if (result > 32 ) {
@@ -165,7 +165,7 @@ uint8_t RF24_getDynamicPayloadSize(void) {
165
165
}
166
166
167
167
168
- bool RF24_isDataAvailable (uint8_t * to) {
168
+ LOCAL bool RF24_isDataAvailable (uint8_t * to) {
169
169
uint8_t pipe_num = ( RF24_getStatus () >> RX_P_NO ) & 0b0111 ;
170
170
#if defined(MY_DEBUG_VERBOSE_RF24)
171
171
if (pipe_num <= 5 )
@@ -179,7 +179,7 @@ bool RF24_isDataAvailable(uint8_t* to) {
179
179
}
180
180
181
181
182
- uint8_t RF24_readMessage ( void * buf) {
182
+ LOCAL uint8_t RF24_readMessage ( void * buf) {
183
183
uint8_t len = RF24_getDynamicPayloadSize ();
184
184
RF24_DEBUG (PSTR (" read message, len=%d\n " ), len);
185
185
RF24_spiMultiByteTransfer ( R_RX_PAYLOAD , (uint8_t *)buf, len, true );
@@ -188,7 +188,7 @@ uint8_t RF24_readMessage( void* buf) {
188
188
return len;
189
189
}
190
190
191
- void RF24_setNodeAddress (uint8_t address) {
191
+ LOCAL void RF24_setNodeAddress (uint8_t address) {
192
192
if (address!=AUTO){
193
193
MY_RF24_NODE_ADDRESS = address;
194
194
// enable node pipe
@@ -198,11 +198,11 @@ void RF24_setNodeAddress(uint8_t address) {
198
198
}
199
199
}
200
200
201
- uint8_t RF24_getNodeID (void ) {
201
+ LOCAL uint8_t RF24_getNodeID (void ) {
202
202
return MY_RF24_NODE_ADDRESS;
203
203
}
204
204
205
- bool RF24_initialize (void ) {
205
+ LOCAL bool RF24_initialize (void ) {
206
206
// Initialize pins
207
207
pinMode (MY_RF24_CE_PIN,OUTPUT);
208
208
pinMode (MY_RF24_CS_PIN,OUTPUT);
0 commit comments