Skip to content

Commit 8121adb

Browse files
committed
less reliant on StatusFlags struct
1 parent 82e1736 commit 8121adb

File tree

3 files changed

+38
-70
lines changed

3 files changed

+38
-70
lines changed

RF24.cpp

+14-24
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ int StatusFlags::toString(char* buf) const
2121

2222
/****************************************************************************/
2323

24-
bool StatusFlags::tx_full() const
24+
const bool StatusFlags::tx_full() const
2525
{
2626
return value & _BV(TX_FULL);
2727
}
2828

2929
/****************************************************************************/
3030

31-
uint8_t StatusFlags::rx_pipe() const
31+
const uint8_t StatusFlags::rx_pipe() const
3232
{
3333
return (value >> RX_P_NO) & 7;
3434
}
3535

3636
/****************************************************************************/
3737

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

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

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

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

52-
bool StatusFlags::rx_dr() const
52+
const bool StatusFlags::rx_dr() const
5353
{
5454
return value & _BV(RX_DR);
5555
}
@@ -1603,43 +1603,33 @@ void RF24::whatHappened(bool& tx_ok, bool& tx_fail, bool& rx_ready)
16031603

16041604
/****************************************************************************/
16051605

1606-
StatusFlags RF24::clearStatusFlags()
1606+
uint8_t RF24::clearStatusFlags(uint8_t flags)
16071607
{
1608-
write_register(NRF_STATUS, RF24_IRQ_ALL);
1609-
StatusFlags flags(status);
1610-
return flags;
1611-
}
1612-
1613-
/****************************************************************************/
1614-
1615-
void RF24::clearStatusFlags(StatusFlags& flags)
1616-
{
1617-
write_register(NRF_STATUS, flags.value & RF24_IRQ_ALL);
1618-
flags.value = status;
1608+
write_register(NRF_STATUS, flags & RF24_IRQ_ALL);
1609+
return status;
16191610
}
16201611

16211612
/****************************************************************************/
16221613

1623-
void RF24::setStatusFlags(StatusFlags flags)
1614+
void RF24::setStatusFlags(uint8_t flags)
16241615
{
16251616
// flip the flags to translate from "human understanding"
1626-
write_register(NRF_CONFIG, ~flags.value & RF24_IRQ_ALL);
1617+
write_register(NRF_CONFIG, ~flags & RF24_IRQ_ALL);
16271618
}
16281619

16291620
/****************************************************************************/
16301621

1631-
void RF24::getStatusFlags(StatusFlags& flags)
1622+
uint8_t RF24::getStatusFlags()
16321623
{
1633-
flags = StatusFlags(status);
1624+
return status;
16341625
}
16351626

16361627
/****************************************************************************/
16371628

1638-
StatusFlags RF24::update()
1629+
uint8_t RF24::update()
16391630
{
16401631
read_register(RF24_NOP, (uint8_t*)nullptr, 0);
1641-
StatusFlags flags(status);
1642-
return flags;
1632+
return status;
16431633
}
16441634

16451635
/****************************************************************************/

RF24.h

+19-35
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ struct StatusFlags
157157
{
158158
// starting with bit 0 at the top...
159159
/// Signifies that the TX FIFO is fully occupied.
160-
bool tx_full() const;
160+
const bool tx_full() const;
161161
/// @brief Represents the pipe number that received the first available payload in the RX FIFO.
162162
/// @remark This data shall be considered invalid if the @ref StatusFlags::rx_dr flag is `false`.
163-
uint8_t rx_pipe() const;
163+
const uint8_t rx_pipe() const;
164164
/// Represents an event where TX Data Failed to send.
165-
bool tx_df() const;
165+
const bool tx_df() const;
166166
/// Represents an event where TX Data Sent successfully.
167-
bool tx_ds() const;
167+
const bool tx_ds() const;
168168
/// Represents an event where RX Data is Ready to `RF24::read()`.
169-
bool rx_dr() const;
169+
const bool rx_dr() const;
170170

171171
/**
172172
* @brief Convert this struct to a human understandable string.
@@ -208,8 +208,7 @@ struct StatusFlags
208208
StatusFlags(uint8_t bits) : value(bits) {};
209209

210210
private:
211-
friend class RF24;
212-
uint8_t value;
211+
const uint8_t value;
213212
};
214213

215214
/**
@@ -1263,51 +1262,36 @@ class RF24
12631262
void whatHappened(bool& tx_ok, bool& tx_fail, bool& rx_ready);
12641263

12651264
/**
1266-
* Clear all of the StatusFlags that caused an interrupt event.
1265+
* Clear the StatusFlags that caused an interrupt event.
12671266
*
12681267
* @remark This function is similar to `whatHappened()` because it also returns the
12691268
* StatusFlags that caused the interrupt event. However, this function returns
1270-
* a 1-byte bit-field struct (@ref StatusFlags) instead of bit-banging 3 1-byte booleans
1269+
* a 1-byte struct (@ref StatusFlags) instead of bit-banging 3 1-byte booleans
12711270
* passed by reference.
12721271
*
12731272
* @note When used in an ISR (Interrupt Service routine), there is a chance that the
1274-
* @ref StatusFlags::rx_pipe information is inaccurate. See available(uint8_t*) (or the
1273+
* @ref StatusFlags::rx_pipe() information is inaccurate. See available(uint8_t*) (or the
12751274
* datasheet) for more detail.
12761275
*
1277-
* @ingroup StatusFlags
1278-
*/
1279-
StatusFlags clearStatusFlags();
1280-
1281-
/**
1282-
* Clear the specified flags.
1283-
*
1284-
* If any of the following flags are `true`, then the flag will be reset:
1285-
*
1286-
* - @ref StatusFlags::rx_dr
1287-
* - @ref StatusFlags::tx_ds
1288-
* - @ref StatusFlags::tx_df
1276+
* @param flags The IRQ flags to clear. Default value is all of them (@ref RF24_IRQ_ALL).
1277+
* Multiple flags can be cleared by OR-ing @ref rf24_irq_flags_e values together.
12891278
*
12901279
* @ingroup StatusFlags
12911280
*/
1292-
void clearStatusFlags(StatusFlags& flags);
1281+
uint8_t clearStatusFlags(uint8_t flags = RF24_IRQ_ALL);
12931282

12941283
/**
12951284
* Set which flags shall be reflected on the radio's IRQ pin.
12961285
*
1297-
* This is similar to maskIRQ(), but with a more intuitive API.
1298-
*
1299-
* @param flags The configuration of the StatusFlags to influence the radio's IRQ pin.
1300-
*
1301-
* If any of the following `flags` are `true`, then the flag's corresponding event will
1302-
* trigger the IRQ pin active HIGH:
1286+
* This is similar to maskIRQ(), but with less confusing parameters.
13031287
*
1304-
* - @ref StatusFlags::rx_dr
1305-
* - @ref StatusFlags::tx_ds
1306-
* - @ref StatusFlags::tx_df
1288+
* @param flags The value of @ref rf24_irq_flags_e to influence the radio's IRQ pin.
1289+
* The default value `0` will disable the radio's IRQ pin.
1290+
* Multiple events can be enabled by OR-ing @ref rf24_irq_flags_e values together.
13071291
*
13081292
* @ingroup StatusFlags
13091293
*/
1310-
void setStatusFlags(StatusFlags flags);
1294+
void setStatusFlags(uint8_t flags = 0);
13111295

13121296
/**
13131297
* Get the latest STATUS byte returned from the last SPI transaction.
@@ -1323,7 +1307,7 @@ class RF24
13231307
*
13241308
* @ingroup StatusFlags
13251309
*/
1326-
void getStatusFlags(StatusFlags& flags);
1310+
uint8_t getStatusFlags();
13271311

13281312
/**
13291313
* Get an updated STATUS byte from the radio.
@@ -1332,7 +1316,7 @@ class RF24
13321316
*
13331317
* @ingroup StatusFlags
13341318
*/
1335-
StatusFlags update();
1319+
uint8_t update();
13361320

13371321
/**
13381322
* Non-blocking write to the open writing pipe used for buffered writes

pyRF24/pyRF24.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ bp::tuple whatHappened_wrap(RF24& ref)
113113
return bp::make_tuple(tx_ok, tx_fail, tx_ready);
114114
}
115115

116-
StatusFlags getStatusFlags_wrap(RF24& ref)
117-
{
118-
StatusFlags flags;
119-
ref.getStatusFlags(flags);
120-
return flags;
121-
}
122-
123116
std::string reprStatusFlags(StatusFlags& self)
124117
{
125118
char* buf = new char[69];
@@ -383,10 +376,11 @@ BOOST_PYTHON_MODULE(RF24)
383376
.def("setRadiation", &RF24::setRadiation)
384377
.def("txStandBy", (bool(::RF24::*)(::uint32_t, bool))(&RF24::txStandBy), txStandBy_wrap1(bp::args("timeout", "startTx")))
385378
.def("whatHappened", &whatHappened_wrap)
386-
.def("setStatusFlags", &RF24::setStatusFlags, (bp::arg("flags")))
387-
.def("clearStatusFlags", (StatusFlags(::RF24::*)(void))(&RF24::clearStatusFlags))
388-
.def("clearStatusFlags", (void(::RF24::*)(StatusFlags&))(&RF24::clearStatusFlags), (bp::arg("flags")))
389-
.def("getStatusFlags", &getStatusFlags_wrap)
379+
.def("setStatusFlags", (uint8_t(::RF24::*)(void))(&RF24::setStatusFlags))
380+
.def("setStatusFlags", (uint8_t(::RF24::*)(uint8_t&))(&RF24::setStatusFlags), (bp::arg("flags")))
381+
.def("clearStatusFlags", (uint8_t(::RF24::*)(void))(&RF24::clearStatusFlags))
382+
.def("clearStatusFlags", (uint8_t(::RF24::*)(uint8_t&))(&RF24::clearStatusFlags), (bp::arg("flags")))
383+
.def("getStatusFlags", &RF24::getStatusFlags)
390384
.def("update", &RF24::update)
391385
.def("startConstCarrier", &RF24::startConstCarrier, (bp::arg("level"), bp::arg("channel")))
392386
.def("stopConstCarrier", &RF24::stopConstCarrier)

0 commit comments

Comments
 (0)