@@ -128,6 +128,54 @@ typedef enum
128
128
RF24_FIFO_INVALID,
129
129
} rf24_fifo_state_e;
130
130
131
+ /* *
132
+ * @}
133
+ * @defgroup StatusFlags Status flags
134
+ * @{
135
+ */
136
+
137
+ /* *
138
+ * @brief A bit-field struct to represent the radio's STATUS byte.
139
+ */
140
+ struct StatusFlags
141
+ {
142
+ // starting with bit 0 at the top...
143
+ // / Signifies that the TX FIFO is fully occupied.
144
+ const bool tx_full : 1 ;
145
+ // / @brief Represents the pipe number that received the first available payload in the RX FIFO.
146
+ // / @remark This data shall be considered invalid if the @ref StatusFlags::rx_dr flag is `false`.
147
+ const uint8_t rx_pipe : 3 ;
148
+ // / Represents an event where TX Data Failed to send.
149
+ bool tx_df : 1 ;
150
+ // / Represents an event where TX Data Sent successfully.
151
+ bool tx_ds : 1 ;
152
+ // / Represents an event where RX Data is Ready to `RF24::read()`.
153
+ bool rx_dr : 1 ;
154
+
155
+ /* *
156
+ * @brief Convert this struct to a human understandable string.
157
+ *
158
+ * ```cpp
159
+ * char buf[69] = {0};
160
+ * StatusFlags flags;
161
+ * flags.toString(buf);
162
+ * ```
163
+ *
164
+ * Afterward, printing the string in `buf` should read something similar to:
165
+ *
166
+ * > rx_dr: false, tx_ds: false, tx_df: false, rx_pipe: 7, tx_full: false
167
+ *
168
+ * @param[out] buf The string buffer into which the StatusFlags description is stored.
169
+ * This buffer needs to be at least 69 bytes long.
170
+ * @returns The amount of bytes altered in the given `buf` parameter.
171
+ */
172
+ int toString (char * buf) const ;
173
+
174
+ // / An explicit default initializer for compatibility with C++11 (or newer) standards.
175
+ // / @see Details about `StatusFlags::toString()` show an example output of default values.
176
+ StatusFlags () : tx_full(false ), rx_pipe(7 ), tx_df(false ), tx_ds(false ), rx_dr(false ) {};
177
+ };
178
+
131
179
/* *
132
180
* @}
133
181
* @brief Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver
@@ -1162,6 +1210,78 @@ class RF24
1162
1210
*/
1163
1211
void whatHappened (bool & tx_ok, bool & tx_fail, bool & rx_ready);
1164
1212
1213
+ /* *
1214
+ * Clear all of the StatusFlags that caused an interrupt event.
1215
+ *
1216
+ * @remark This function is similar to `whatHappened()` because it also returns the
1217
+ * StatusFlags that caused the interrupt event. However, this function returns
1218
+ * a 1-byte bit-field struct (@ref StatusFlags) instead of bit-banging 3 1-byte booleans
1219
+ * passed by reference.
1220
+ *
1221
+ * @note When used in an ISR (Interrupt Service routine), there is a chance that the
1222
+ * @ref StatusFlags::rx_pipe information is inaccurate. See available(uint8_t*) (or the
1223
+ * datasheet) for more detail.
1224
+ *
1225
+ * @ingroup StatusFlags
1226
+ */
1227
+ StatusFlags clearStatusFlags ();
1228
+
1229
+ /* *
1230
+ * Clear the specified flags.
1231
+ *
1232
+ * If any of the following flags are `true`, then the flag will be reset:
1233
+ *
1234
+ * - @ref StatusFlags::rx_dr
1235
+ * - @ref StatusFlags::tx_ds
1236
+ * - @ref StatusFlags::tx_df
1237
+ *
1238
+ * @ingroup StatusFlags
1239
+ */
1240
+ void clearStatusFlags (StatusFlags& flags);
1241
+
1242
+ /* *
1243
+ * Set which flags shall be reflected on the radio's IRQ pin.
1244
+ *
1245
+ * This is similar to maskIRQ(), but with a more intuitive API.
1246
+ *
1247
+ * @param flags The configuration of the StatusFlags to influence the radio's IRQ pin.
1248
+ *
1249
+ * If any of the following `flags` are `true`, then the flag's corresponding event will
1250
+ * trigger the IRQ pin active HIGH:
1251
+ *
1252
+ * - @ref StatusFlags::rx_dr
1253
+ * - @ref StatusFlags::tx_ds
1254
+ * - @ref StatusFlags::tx_df
1255
+ *
1256
+ * @ingroup StatusFlags
1257
+ */
1258
+ void setStatusFlags (StatusFlags flags);
1259
+
1260
+ /* *
1261
+ * Get the latest STATUS byte returned from the last SPI transaction.
1262
+ *
1263
+ * @note This does not actually perform any SPI transaction with the radio.
1264
+ * Use `RF24::update()` instead to get a fresh copy of the StatusFlags at
1265
+ * the slight cost of performance.
1266
+ *
1267
+ * @param[out] flags The reference data into which the StatusFlags data is stored.
1268
+ *
1269
+ * In the python wrapper, this function takes no argument and instead
1270
+ * returns an instance of StatusFlags.
1271
+ *
1272
+ * @ingroup StatusFlags
1273
+ */
1274
+ void getStatusFlags (StatusFlags& flags);
1275
+
1276
+ /* *
1277
+ * Get an updated STATUS byte from the radio.
1278
+ *
1279
+ * @returns The StatusFlags fetched directly from the radio.
1280
+ *
1281
+ * @ingroup StatusFlags
1282
+ */
1283
+ StatusFlags update ();
1284
+
1165
1285
/* *
1166
1286
* Non-blocking write to the open writing pipe used for buffered writes
1167
1287
*
0 commit comments