Introduce MY_DEBUG_VERBOSE to reduce binary size

Define MY_DEBUG_VERBOSE to have verbose debugging output (dumping NRF24
registers on startup).
This commit is contained in:
Yveaux
2015-10-04 12:12:00 +02:00
parent b9b0540f67
commit f748d15adb
3 changed files with 78 additions and 64 deletions
+4 -1
View File
@@ -26,6 +26,10 @@
// to see what is actually is happening when developing
#define DEBUG
// Enable MY_DEBUG_VERBOSE flag for verbose debug prints. Requires DEBUG to be enabled.
// This will add even more to the size of the final sketch!
//#define MY_DEBUG_VERBOSE
// Disable this line, If you are using TX(1), RX(0) as normal I/O pin
#define ENABLED_SERIAL
@@ -145,5 +149,4 @@
//#define RFM69_ENABLE_ENCRYPTION
#define RFM69_ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#endif
+50 -39
View File
@@ -10,7 +10,18 @@
#include "RF24_config.h"
#include "RF24.h"
// Save some bytes by reusing strings.
static const char space_str_P[] PROGMEM = " ";
/****************************************************************************/
static void print_hex( uint8_t v, const bool prefix0x = false )
{
if (prefix0x)
Serial.print(F("0x"));
Serial.print(v >> 4, HEX);
Serial.print(v & 0x0F, HEX);
}
void RF24::csn(bool mode)
{
@@ -286,52 +297,61 @@ uint8_t RF24::get_status(void)
}
/****************************************************************************/
void RF24::print_feature(void)
{
#ifdef DEBUG
void RF24::print_hex( uint8_t v, const bool prefix0x )
{
if (prefix0x)
Serial.print(F("0x"));
Serial.print(v >> 4, HEX);
Serial.print(v & 0x0F, HEX);
}
Serial.print(F("FEATURE="));
print_hex(read_register(FEATURE), true);
Serial.println(space_str_P);
#endif
}
void RF24::print_status(uint8_t status)
/****************************************************************************/
void RF24::print_status(uint8_t status) const
{
#ifdef MY_DEBUG_VERBOSE
const uint8_t one = uint8_t(1);
const uint8_t zero = uint8_t(0);
print_hex(status, true);
Serial.print(F(" RX_DR=")); Serial.print((status & _BV(RX_DR))?uint8_t(1):uint8_t(0));
Serial.print(F(" TX_DS=")); Serial.print((status & _BV(TX_DS))?uint8_t(1):uint8_t(0));
Serial.print(F(" MAX_RT=")); Serial.print((status & _BV(MAX_RT))?uint8_t(1):uint8_t(0));
Serial.print(F(" RX_DR=")); Serial.print((status & _BV(RX_DR)) ? one : zero );
Serial.print(F(" TX_DS=")); Serial.print((status & _BV(TX_DS)) ? one : zero );
Serial.print(F(" MAX_RT=")); Serial.print((status & _BV(MAX_RT)) ? one : zero );
Serial.print(F(" RX_P_NO=")); Serial.print((status >> RX_P_NO) & uint8_t(B111));
Serial.print(F(" TX_FULL=")); Serial.println((status & _BV(TX_FULL))?uint8_t(1):uint8_t(0));
Serial.print(F(" TX_FULL=")); Serial.println((status & _BV(TX_FULL)) ? one : zero );
#endif
}
/****************************************************************************/
void RF24::print_observe_tx(uint8_t value)
void RF24::print_observe_tx(uint8_t value) const
{
#ifdef MY_DEBUG_VERBOSE
print_hex(value, true);
Serial.print(F(": POLS_CNT=")); Serial.print((value >> PLOS_CNT) & uint8_t(B1111));
Serial.print(F(" ARC_CNT=")); Serial.println((value >> ARC_CNT) & uint8_t(B1111));
Serial.print(F(": POLS_CNT=")); Serial.print((value >> PLOS_CNT) & uint8_t(B1111));
Serial.print(F(" ARC_CNT=")); Serial.println((value >> ARC_CNT) & uint8_t(B1111));
#endif
}
/****************************************************************************/
void RF24::print_byte_register(uint8_t reg, uint8_t qty)
{
#ifdef MY_DEBUG_VERBOSE
bool prefix0x = true;
while (qty--)
{
print_hex(read_register(reg++), prefix0x);
Serial.print(F(" "));
Serial.print(space_str_P);
prefix0x = false;
}
Serial.println(F(""));
Serial.println(space_str_P);
#endif
}
/****************************************************************************/
void RF24::print_address_register(uint8_t reg, uint8_t qty)
{
#ifdef MY_DEBUG_VERBOSE
bool prefix0x = true;
while (qty--)
{
@@ -344,11 +364,11 @@ void RF24::print_address_register(uint8_t reg, uint8_t qty)
print_hex(read_register(*bufptr), prefix0x);
prefix0x = false;
}
Serial.print(F(" "));
Serial.print(space_str_P);
}
Serial.println(F(""));
}
Serial.println(space_str_P);
#endif
}
/****************************************************************************/
RF24::RF24(uint8_t _cepin, uint8_t _cspin):
@@ -380,8 +400,7 @@ uint8_t RF24::getPayloadSize(void)
}
/****************************************************************************/
#ifdef DEBUG
#ifdef MY_DEBUG_VERBOSE
static const char rf24_datarate_e_str_0[] PROGMEM = "1MBPS";
static const char rf24_datarate_e_str_1[] PROGMEM = "2MBPS";
static const char rf24_datarate_e_str_2[] PROGMEM = "250KBPS";
@@ -414,6 +433,7 @@ static const char * const rf24_pa_dbm_e_str_P[] PROGMEM = {
rf24_pa_dbm_e_str_2,
rf24_pa_dbm_e_str_3,
};
#endif
#if (INTPTR_MAX == INT16_MAX)
// 16-bit architecture -> read word from flash and cast to ptr
@@ -427,6 +447,7 @@ static const char * const rf24_pa_dbm_e_str_P[] PROGMEM = {
void RF24::printDetails(void)
{
#ifdef MY_DEBUG_VERBOSE
Serial.print(F("STATUS\t\t")); print_status(get_status());
Serial.print(F("RX_ADDR_P0-1\t")); print_address_register(RX_ADDR_P0,2);
Serial.print(F("RX_ADDR_P2-5\t")); print_byte_register(RX_ADDR_P2,4);
@@ -444,8 +465,8 @@ void RF24::printDetails(void)
Serial.print(F("Model\t\t")); Serial.println(PGM_READ_PTR(&rf24_model_e_str_P[isPVariant()]));
Serial.print(F("CRC Length\t")); Serial.println(PGM_READ_PTR(&rf24_crclength_e_str_P[getCRCLength()]));
Serial.print(F("PA Power\t")); Serial.println(PGM_READ_PTR(&rf24_pa_dbm_e_str_P[getPALevel()]));
}
#endif
}
/****************************************************************************/
void RF24::begin(void)
@@ -521,10 +542,8 @@ void RF24::begin(void)
// PTX should use only 22uA of power
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );
#ifdef DEBUG
// Dump register values
printDetails();
#endif
}
/****************************************************************************/
@@ -1062,16 +1081,13 @@ void RF24::toggle_features(void)
}
/****************************************************************************/
void RF24::enableDynamicPayloads(void)
{
// Enable dynamic payload throughout the system
toggle_features();
write_register(FEATURE,read_register(FEATURE) | _BV(EN_DPL) );
print_feature();
#ifdef DEBUG
Serial.print(F("FEATURE=")); print_hex(read_register(FEATURE), true); Serial.println(F(""));
#endif
// Enable dynamic payload on all pipes
//
// Not sure the use case of only having dynamic payload on certain
@@ -1090,10 +1106,8 @@ void RF24::enableAckPayload(void)
//
toggle_features();
write_register(FEATURE,read_register(FEATURE) | _BV(EN_ACK_PAY) | _BV(EN_DPL) );
print_feature();
#ifdef DEBUG
Serial.print(F("FEATURE=")); print_hex(read_register(FEATURE), true); Serial.println(F(""));
#endif
//
// Enable dynamic payload on pipes 0 & 1
//
@@ -1108,12 +1122,9 @@ void RF24::enableDynamicAck(void){
//
// enable dynamic ack features
//
toggle_features();
write_register(FEATURE,read_register(FEATURE) | _BV(EN_DYN_ACK) );
#ifdef DEBUG
Serial.print(F("FEATURE=")); print_hex(read_register(FEATURE), true); Serial.println(F(""));
#endif
toggle_features();
write_register(FEATURE,read_register(FEATURE) | _BV(EN_DYN_ACK) );
print_feature();
}
/****************************************************************************/
+24 -24
View File
@@ -210,9 +210,9 @@ public:
/**@{*/
/**
* Print a giant block of debugging information to stdout
* Print a giant block of debugging information to serial
*
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
* @warning Does nothing if MY_DEBUG_VERBOSE is not defined
*/
void printDetails(void);
@@ -922,60 +922,60 @@ private:
* @return Current value of status register
*/
uint8_t get_status(void);
#ifdef DEBUG
/**
* Decode and print the given status to stdout
* Print the current feature register value to serial
*
* @warning Does nothing if DEBUG is not defined
*/
void print_feature(void);
/**
* Decode and print the given status to serial
*
* @warning Does nothing if MY_DEBUG_VERBOSE is not defined
*
* @param status Status value to print
*
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
*/
void print_status(uint8_t status);
void print_status(uint8_t status) const;
/**
* Decode and print the given 'observe_tx' value to stdout
* Decode and print the given 'observe_tx' value to serial
*
* @warning Does nothing if MY_DEBUG_VERBOSE is not defined
*
* @param value The observe_tx value to print
*
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
*/
void print_observe_tx(uint8_t value);
void print_observe_tx(uint8_t value) const;
/**
* Print the value of an 8-bit register to stdout
* Print the value of an 8-bit register to serial
*
* Optionally it can print some quantity of successive
* registers on the same line. This is useful for printing a group
* of related registers on one line.
*
* @warning Does nothing if MY_DEBUG_VERBOSE is not defined
*
* @param reg Which register. Use constants from nRF24L01.h
* @param qty How many successive registers to print
*/
void print_byte_register(uint8_t reg, uint8_t qty = 1);
/**
* Print the value of a 40-bit address register to stdout
* Print the value of a 40-bit address register to serial
*
* Optionally it can print some quantity of successive
* registers on the same line. This is useful for printing a group
* of related registers on one line.
*
* @warning Does nothing if MY_DEBUG_VERBOSE is not defined
*
* @param reg Which register. Use constants from nRF24L01.h
* @param qty How many successive registers to print
*/
void print_address_register(uint8_t reg, uint8_t qty = 1);
/**
* Print a value in hex to serial output.
*
* For values < 16 a leading 0 will be printed.
*
* @param v Value to print in hex.
*/
void print_hex( uint8_t v, const bool prefix0x = false );
#endif
/**
* Turn on or off the special features of the chip
*