Skip to content

Commit d7dc1a6

Browse files
committed
replace migrate internal API and expose printStatus()
1 parent f1393d1 commit d7dc1a6

File tree

3 files changed

+40
-52
lines changed

3 files changed

+40
-52
lines changed

RF24.cpp

+28-36
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ const uint8_t StatusFlags::rx_pipe() const
3737

3838
const bool StatusFlags::tx_df() const
3939
{
40-
return value & _BV(MAX_RT);
40+
return value & RF24_TX_DF;
4141
}
4242

4343
/****************************************************************************/
4444

4545
const bool StatusFlags::tx_ds() const
4646
{
47-
return value & _BV(TX_DS);
47+
return value & RF24_TX_DS;
4848
}
4949

5050
/****************************************************************************/
5151

5252
const bool StatusFlags::rx_dr() const
5353
{
54-
return value & _BV(RX_DR);
54+
return value & RF24_RX_DR;
5555
}
5656

5757
/****************************************************************************/
@@ -527,21 +527,13 @@ uint8_t RF24::flush_tx(void)
527527
return status;
528528
}
529529

530-
/****************************************************************************/
531-
532-
uint8_t RF24::get_status(void)
533-
{
534-
read_register(RF24_NOP, (uint8_t*)nullptr, 0);
535-
return status;
536-
}
537-
538530
/****************************************************************************/
539531
#if !defined(MINIMAL)
540532

541-
void RF24::print_status(uint8_t _status)
533+
void RF24::printStatus(uint8_t flags)
542534
{
543-
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,
544-
(_status & _BV(TX_DS)) ? 1 : 0, (_status & _BV(MAX_RT)) ? 1 : 0, ((_status >> RX_P_NO) & 0x07), (_status & _BV(TX_FULL)) ? 1 : 0);
535+
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,
536+
(flags & RF24_TX_DS) ? 1 : 0, (flags & RF24_TX_DF) ? 1 : 0, ((flags >> RX_P_NO) & 0x07), (flags & _BV(TX_FULL)) ? 1 : 0);
545537
}
546538

547539
/****************************************************************************/
@@ -755,7 +747,7 @@ void RF24::printDetails(void)
755747
printf("================ NRF Configuration ================\n");
756748
#endif // defined(RF24_LINUX)
757749

758-
print_status(get_status());
750+
printStatus(update());
759751

760752
print_address_register(PSTR("RX_ADDR_P0-1"), RX_ADDR_P0, 2);
761753
print_byte_register(PSTR("RX_ADDR_P2-5"), RX_ADDR_P2, 4);
@@ -1151,7 +1143,7 @@ bool RF24::_init_radio()
11511143

11521144
// Reset current status
11531145
// Notice reset and flush is the last thing we do
1154-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1146+
write_register(NRF_STATUS, RF24_IRQ_ALL);
11551147

11561148
// Flush buffers
11571149
flush_rx();
@@ -1196,7 +1188,7 @@ void RF24::startListening(void)
11961188
#endif
11971189
config_reg |= _BV(PRIM_RX);
11981190
write_register(NRF_CONFIG, config_reg);
1199-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1191+
write_register(NRF_STATUS, RF24_IRQ_ALL);
12001192
ce(HIGH);
12011193

12021194
// Restore the pipe0 address, if exists
@@ -1292,7 +1284,7 @@ bool RF24::write(const void* buf, uint8_t len, const bool multicast)
12921284
uint32_t timer = millis();
12931285
#endif // defined(FAILURE_HANDLING) || defined(RF24_LINUX)
12941286

1295-
while (!(get_status() & (_BV(TX_DS) | _BV(MAX_RT)))) {
1287+
while (!(update() & (RF24_TX_DS | RF24_TX_DF))) {
12961288
#if defined(FAILURE_HANDLING) || defined(RF24_LINUX)
12971289
if (millis() - timer > 95) {
12981290
errNotify();
@@ -1307,10 +1299,10 @@ bool RF24::write(const void* buf, uint8_t len, const bool multicast)
13071299

13081300
ce(LOW);
13091301

1310-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1302+
write_register(NRF_STATUS, RF24_IRQ_ALL);
13111303

13121304
//Max retries exceeded
1313-
if (status & _BV(MAX_RT)) {
1305+
if (status & RF24_TX_DF) {
13141306
flush_tx(); // Only going to be 1 packet in the FIFO at a time using this method, so just flush
13151307
return 0;
13161308
}
@@ -1335,10 +1327,10 @@ bool RF24::writeBlocking(const void* buf, uint8_t len, uint32_t timeout)
13351327

13361328
uint32_t timer = millis(); // Get the time that the payload transmission started
13371329

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

1340-
if (status & _BV(MAX_RT)) { // If MAX Retries have been reached
1341-
reUseTX(); // Set re-transmit and clear the MAX_RT interrupt flag
1332+
if (status & RF24_TX_DF) { // If MAX Retries have been reached
1333+
reUseTX(); // Set re-transmit and clear the MAX_RT interrupt flag
13421334
if (millis() - timer > timeout) {
13431335
return 0; // If this payload has exceeded the user-defined timeout, exit and return 0
13441336
}
@@ -1364,7 +1356,7 @@ bool RF24::writeBlocking(const void* buf, uint8_t len, uint32_t timeout)
13641356
void RF24::reUseTX()
13651357
{
13661358
ce(LOW);
1367-
write_register(NRF_STATUS, _BV(MAX_RT)); //Clear max retry flag
1359+
write_register(NRF_STATUS, RF24_TX_DF); //Clear max retry flag
13681360
read_register(REUSE_TX_PL, (uint8_t*)nullptr, 0);
13691361
IF_RF24_DEBUG(printf_P("[Reusing payload in TX FIFO]"););
13701362
ce(HIGH); //Re-Transfer packet
@@ -1384,8 +1376,8 @@ bool RF24::writeFast(const void* buf, uint8_t len, const bool multicast)
13841376
#endif
13851377

13861378
//Blocking only if FIFO is full. This will loop and block until TX is successful or fail
1387-
while ((get_status() & (_BV(TX_FULL)))) {
1388-
if (status & _BV(MAX_RT)) {
1379+
while ((update() & (_BV(TX_FULL)))) {
1380+
if (status & RF24_TX_DF) {
13891381
return 0; //Return 0. The previous payload has not been retransmitted
13901382
// From the user perspective, if you get a 0, call txStandBy()
13911383
}
@@ -1477,8 +1469,8 @@ bool RF24::txStandBy()
14771469
uint32_t timeout = millis();
14781470
#endif
14791471
while (!(read_register(FIFO_STATUS) & _BV(TX_EMPTY))) {
1480-
if (status & _BV(MAX_RT)) {
1481-
write_register(NRF_STATUS, _BV(MAX_RT));
1472+
if (status & RF24_TX_DF) {
1473+
write_register(NRF_STATUS, RF24_TX_DF);
14821474
ce(LOW);
14831475
flush_tx(); //Non blocking, flush the data
14841476
return 0;
@@ -1509,8 +1501,8 @@ bool RF24::txStandBy(uint32_t timeout, bool startTx)
15091501
uint32_t start = millis();
15101502

15111503
while (!(read_register(FIFO_STATUS) & _BV(TX_EMPTY))) {
1512-
if (status & _BV(MAX_RT)) {
1513-
write_register(NRF_STATUS, _BV(MAX_RT));
1504+
if (status & RF24_TX_DF) {
1505+
write_register(NRF_STATUS, RF24_TX_DF);
15141506
ce(LOW); // Set re-transmit
15151507
ce(HIGH);
15161508
if (millis() - start >= timeout) {
@@ -1570,7 +1562,7 @@ bool RF24::available(void)
15701562
bool RF24::available(uint8_t* pipe_num)
15711563
{
15721564
if (available()) { // if RX FIFO is not empty
1573-
*pipe_num = (get_status() >> RX_P_NO) & 0x07;
1565+
*pipe_num = (update() >> RX_P_NO) & 0x07;
15741566
return 1;
15751567
}
15761568
return 0;
@@ -1585,7 +1577,7 @@ void RF24::read(void* buf, uint8_t len)
15851577
read_payload(buf, len);
15861578

15871579
//Clear the only applicable interrupt flags
1588-
write_register(NRF_STATUS, _BV(RX_DR));
1580+
write_register(NRF_STATUS, RF24_RX_DR);
15891581
}
15901582

15911583
/****************************************************************************/
@@ -1594,12 +1586,12 @@ void RF24::whatHappened(bool& tx_ok, bool& tx_fail, bool& rx_ready)
15941586
{
15951587
// Read the status & reset the status in one easy call
15961588
// Or is that such a good idea?
1597-
write_register(NRF_STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));
1589+
write_register(NRF_STATUS, RF24_IRQ_ALL);
15981590

15991591
// Report to the user what happened
1600-
tx_ok = status & _BV(TX_DS);
1601-
tx_fail = status & _BV(MAX_RT);
1602-
rx_ready = status & _BV(RX_DR);
1592+
tx_ok = status & RF24_TX_DS;
1593+
tx_fail = status & RF24_TX_DF;
1594+
rx_ready = status & RF24_RX_DR;
16031595
}
16041596

16051597
/****************************************************************************/

RF24.h

+10-16
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,16 @@ class RF24
713713
*/
714714
void printDetails(void);
715715

716+
/**
717+
* Decode and print the given STATUS byte to stdout.
718+
*
719+
* @param flags The STATUS byte to print.
720+
* This value is fetched with update() or getStatusFlags().
721+
*
722+
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
723+
*/
724+
void printStatus(uint8_t flags);
725+
716726
/**
717727
* Print a giant block of debugging information to stdout. This function
718728
* differs from printDetails() because it makes the information more
@@ -2136,24 +2146,8 @@ class RF24
21362146
*/
21372147
void read_payload(void* buf, uint8_t len);
21382148

2139-
/**
2140-
* Retrieve the current status of the chip
2141-
*
2142-
* @return Current value of status register
2143-
*/
2144-
uint8_t get_status(void);
2145-
21462149
#if !defined(MINIMAL)
21472150

2148-
/**
2149-
* Decode and print the given status to stdout
2150-
*
2151-
* @param status Status value to print
2152-
*
2153-
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
2154-
*/
2155-
void print_status(uint8_t status);
2156-
21572151
/**
21582152
* Decode and print the given 'observe_tx' value to stdout
21592153
*

pyRF24/pyRF24.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ BOOST_PYTHON_MODULE(RF24)
303303
.value("RF24_TX_DS", RF24_TX_DS)
304304
.value("RF24_RX_DR", RF24_RX_DR)
305305
.value("RF24_IRQ_ALL", RF24_IRQ_ALL)
306+
.value("RF24_IRQ_NONE", RF24_IRQ_NONE)
306307
.export_values();
307308

308309
bp::class_<StatusFlags>("StatusFlags", bp::init<>())
@@ -350,6 +351,7 @@ BOOST_PYTHON_MODULE(RF24)
350351
.def("powerDown", &RF24::powerDown)
351352
.def("powerUp", &RF24::powerUp)
352353
.def("printDetails", &RF24::printDetails)
354+
.def("printStatus", &RF24::printStatus)
353355
.def("printPrettyDetails", &RF24::printPrettyDetails)
354356
.def("sprintfPrettyDetails", &sprintfPrettyDetails_wrap)
355357
.def("reUseTX", &RF24::reUseTX)

0 commit comments

Comments
 (0)