Skip to content

Commit 981b8db

Browse files
committed
migrate internal API and expose printStatus()
rm unnecessary ()
1 parent 2da1c23 commit 981b8db

3 files changed

Lines changed: 37 additions & 49 deletions

File tree

RF24.cpp

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,13 @@ uint8_t RF24::flush_tx(void)
483483
return status;
484484
}
485485

486-
/****************************************************************************/
487-
488-
uint8_t RF24::get_status(void)
489-
{
490-
read_register(RF24_NOP, (uint8_t*)nullptr, 0);
491-
return status;
492-
}
493-
494486
/****************************************************************************/
495487
#if !defined(MINIMAL)
496488

497-
void RF24::print_status(uint8_t _status)
489+
void RF24::printStatus(uint8_t flags)
498490
{
499-
printf_P(PSTR("STATUS\t\t= 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"), _status, (_status & _BV(RX_DR)) ? 1 : 0,
500-
(_status & _BV(TX_DS)) ? 1 : 0, (_status & _BV(MAX_RT)) ? 1 : 0, ((_status >> RX_P_NO) & 0x07), (_status & _BV(TX_FULL)) ? 1 : 0);
491+
printf_P(PSTR("STATUS\t\t= 0x%02x RX_DR=%x TX_DS=%x TX_DF=%x RX_PIPE=%x TX_FULL=%x\r\n"), flags, (flags & RF24_RX_DR) ? 1 : 0,
492+
(flags & RF24_TX_DS) ? 1 : 0, (flags & RF24_TX_DF) ? 1 : 0, ((flags >> RX_P_NO) & 0x07), (flags & _BV(TX_FULL)) ? 1 : 0);
501493
}
502494

503495
/****************************************************************************/
@@ -711,7 +703,7 @@ void RF24::printDetails(void)
711703
printf("================ NRF Configuration ================\n");
712704
#endif // defined(RF24_LINUX)
713705

714-
print_status(get_status());
706+
printStatus(update());
715707

716708
print_address_register(PSTR("RX_ADDR_P0-1"), RX_ADDR_P0, 2);
717709
print_byte_register(PSTR("RX_ADDR_P2-5"), RX_ADDR_P2, 4);
@@ -1107,7 +1099,7 @@ bool RF24::_init_radio()
11071099

11081100
// Reset current status
11091101
// Notice reset and flush is the last thing we do
1110-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1102+
write_register(NRF_STATUS, RF24_IRQ_ALL);
11111103

11121104
// Flush buffers
11131105
flush_rx();
@@ -1152,7 +1144,7 @@ void RF24::startListening(void)
11521144
#endif
11531145
config_reg |= _BV(PRIM_RX);
11541146
write_register(NRF_CONFIG, config_reg);
1155-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1147+
write_register(NRF_STATUS, RF24_IRQ_ALL);
11561148
ce(HIGH);
11571149

11581150
// Restore the pipe0 address, if exists
@@ -1248,7 +1240,7 @@ bool RF24::write(const void* buf, uint8_t len, const bool multicast)
12481240
uint32_t timer = millis();
12491241
#endif // defined(FAILURE_HANDLING) || defined(RF24_LINUX)
12501242

1251-
while (!(get_status() & (_BV(TX_DS) | _BV(MAX_RT)))) {
1243+
while (!(update() & (RF24_TX_DS | RF24_TX_DF))) {
12521244
#if defined(FAILURE_HANDLING) || defined(RF24_LINUX)
12531245
if (millis() - timer > 95) {
12541246
errNotify();
@@ -1263,10 +1255,10 @@ bool RF24::write(const void* buf, uint8_t len, const bool multicast)
12631255

12641256
ce(LOW);
12651257

1266-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1258+
write_register(NRF_STATUS, RF24_IRQ_ALL);
12671259

12681260
//Max retries exceeded
1269-
if (status & _BV(MAX_RT)) {
1261+
if (status & RF24_TX_DF) {
12701262
flush_tx(); // Only going to be 1 packet in the FIFO at a time using this method, so just flush
12711263
return 0;
12721264
}
@@ -1291,10 +1283,10 @@ bool RF24::writeBlocking(const void* buf, uint8_t len, uint32_t timeout)
12911283

12921284
uint32_t timer = millis(); // Get the time that the payload transmission started
12931285

1294-
while ((get_status() & (_BV(TX_FULL)))) { // Blocking only if FIFO is full. This will loop and block until TX is successful or timeout
1286+
while (update() & _BV(TX_FULL)) { // Blocking only if FIFO is full. This will loop and block until TX is successful or timeout
12951287

1296-
if (status & _BV(MAX_RT)) { // If MAX Retries have been reached
1297-
reUseTX(); // Set re-transmit and clear the MAX_RT interrupt flag
1288+
if (status & RF24_TX_DF) { // If MAX Retries have been reached
1289+
reUseTX(); // Set re-transmit and clear the MAX_RT interrupt flag
12981290
if (millis() - timer > timeout) {
12991291
return 0; // If this payload has exceeded the user-defined timeout, exit and return 0
13001292
}
@@ -1320,7 +1312,7 @@ bool RF24::writeBlocking(const void* buf, uint8_t len, uint32_t timeout)
13201312
void RF24::reUseTX()
13211313
{
13221314
ce(LOW);
1323-
write_register(NRF_STATUS, _BV(MAX_RT)); //Clear max retry flag
1315+
write_register(NRF_STATUS, RF24_TX_DF); //Clear max retry flag
13241316
read_register(REUSE_TX_PL, (uint8_t*)nullptr, 0);
13251317
IF_RF24_DEBUG(printf_P("[Reusing payload in TX FIFO]"););
13261318
ce(HIGH); //Re-Transfer packet
@@ -1340,8 +1332,8 @@ bool RF24::writeFast(const void* buf, uint8_t len, const bool multicast)
13401332
#endif
13411333

13421334
//Blocking only if FIFO is full. This will loop and block until TX is successful or fail
1343-
while ((get_status() & (_BV(TX_FULL)))) {
1344-
if (status & _BV(MAX_RT)) {
1335+
while (update() & _BV(TX_FULL)) {
1336+
if (status & RF24_TX_DF) {
13451337
return 0; //Return 0. The previous payload has not been retransmitted
13461338
// From the user perspective, if you get a 0, call txStandBy()
13471339
}
@@ -1433,8 +1425,8 @@ bool RF24::txStandBy()
14331425
uint32_t timeout = millis();
14341426
#endif
14351427
while (!(read_register(FIFO_STATUS) & _BV(TX_EMPTY))) {
1436-
if (status & _BV(MAX_RT)) {
1437-
write_register(NRF_STATUS, _BV(MAX_RT));
1428+
if (status & RF24_TX_DF) {
1429+
write_register(NRF_STATUS, RF24_TX_DF);
14381430
ce(LOW);
14391431
flush_tx(); //Non blocking, flush the data
14401432
return 0;
@@ -1465,8 +1457,8 @@ bool RF24::txStandBy(uint32_t timeout, bool startTx)
14651457
uint32_t start = millis();
14661458

14671459
while (!(read_register(FIFO_STATUS) & _BV(TX_EMPTY))) {
1468-
if (status & _BV(MAX_RT)) {
1469-
write_register(NRF_STATUS, _BV(MAX_RT));
1460+
if (status & RF24_TX_DF) {
1461+
write_register(NRF_STATUS, RF24_TX_DF);
14701462
ce(LOW); // Set re-transmit
14711463
ce(HIGH);
14721464
if (millis() - start >= timeout) {
@@ -1526,7 +1518,7 @@ bool RF24::available(void)
15261518
bool RF24::available(uint8_t* pipe_num)
15271519
{
15281520
if (available()) { // if RX FIFO is not empty
1529-
*pipe_num = (get_status() >> RX_P_NO) & 0x07;
1521+
*pipe_num = (update() >> RX_P_NO) & 0x07;
15301522
return 1;
15311523
}
15321524
return 0;
@@ -1541,7 +1533,7 @@ void RF24::read(void* buf, uint8_t len)
15411533
read_payload(buf, len);
15421534

15431535
//Clear the only applicable interrupt flags
1544-
write_register(NRF_STATUS, _BV(RX_DR));
1536+
write_register(NRF_STATUS, RF24_RX_DR);
15451537
}
15461538

15471539
/****************************************************************************/
@@ -1550,12 +1542,12 @@ void RF24::whatHappened(bool& tx_ok, bool& tx_fail, bool& rx_ready)
15501542
{
15511543
// Read the status & reset the status in one easy call
15521544
// Or is that such a good idea?
1553-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1545+
write_register(NRF_STATUS, RF24_IRQ_ALL);
15541546

15551547
// Report to the user what happened
1556-
tx_ok = status & _BV(TX_DS);
1557-
tx_fail = status & _BV(MAX_RT);
1558-
rx_ready = status & _BV(RX_DR);
1548+
tx_ok = status & RF24_TX_DS;
1549+
tx_fail = status & RF24_TX_DF;
1550+
rx_ready = status & RF24_RX_DR;
15591551
}
15601552

15611553
/****************************************************************************/

RF24.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,16 @@ class RF24
652652
*/
653653
void printDetails(void);
654654

655+
/**
656+
* Decode and print the given STATUS byte to stdout.
657+
*
658+
* @param flags The STATUS byte to print.
659+
* This value is fetched with update() or getStatusFlags().
660+
*
661+
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
662+
*/
663+
void printStatus(uint8_t flags);
664+
655665
/**
656666
* Print a giant block of debugging information to stdout. This function
657667
* differs from printDetails() because it makes the information more
@@ -2075,24 +2085,8 @@ class RF24
20752085
*/
20762086
void read_payload(void* buf, uint8_t len);
20772087

2078-
/**
2079-
* Retrieve the current status of the chip
2080-
*
2081-
* @return Current value of status register
2082-
*/
2083-
uint8_t get_status(void);
2084-
20852088
#if !defined(MINIMAL)
20862089

2087-
/**
2088-
* Decode and print the given status to stdout
2089-
*
2090-
* @param status Status value to print
2091-
*
2092-
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
2093-
*/
2094-
void print_status(uint8_t status);
2095-
20962090
/**
20972091
* Decode and print the given 'observe_tx' value to stdout
20982092
*

pyRF24/pyRF24.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ BOOST_PYTHON_MODULE(RF24)
292292
.value("RF24_TX_DS", RF24_TX_DS)
293293
.value("RF24_RX_DR", RF24_RX_DR)
294294
.value("RF24_IRQ_ALL", RF24_IRQ_ALL)
295+
.value("RF24_IRQ_NONE", RF24_IRQ_NONE)
295296
.export_values();
296297

297298
// ******************** RF24 class **************************
@@ -330,6 +331,7 @@ BOOST_PYTHON_MODULE(RF24)
330331
.def("powerDown", &RF24::powerDown)
331332
.def("powerUp", &RF24::powerUp)
332333
.def("printDetails", &RF24::printDetails)
334+
.def("printStatus", &RF24::printStatus)
333335
.def("printPrettyDetails", &RF24::printPrettyDetails)
334336
.def("sprintfPrettyDetails", &sprintfPrettyDetails_wrap)
335337
.def("reUseTX", &RF24::reUseTX)

0 commit comments

Comments
 (0)