Skip to content

Commit

Permalink
Force a recompile to rerun compile actions and not get 1gb od logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenceKonde committed Oct 12, 2023
1 parent c446e9e commit f547bfa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 36 deletions.
42 changes: 27 additions & 15 deletions megaavr/cores/dxcore/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,32 @@ class HardwareSerial : public Stream {
void begin(uint32_t baud, uint16_t options);
void end();
// printHex!
void printHex(const uint8_t b);
void printHex(const int8_t b) {printHex((uint8_t ) b); }
void printHex(const char b) {printHex((uint8_t ) b); }
void printHex(const uint16_t w, bool s = 0);
void printHex(const int16_t w, bool s = 0) {printHex((uint16_t)w, s); }
void printHex(const uint32_t l, bool s = 0);
void printHex(const int32_t l, bool s = 0) {printHex((uint32_t)l, s); }
void printHexln(const int8_t b) {printHex((uint8_t ) b); println();}
void printHexln(const char b) {printHex((uint8_t ) b); println();}
void printHexln(const uint8_t b) {printHex( b); println();}
void printHexln(const uint16_t w, bool s = 0) {printHex( w, s); println();}
void printHexln(const uint32_t l, bool s = 0) {printHex( l, s); println();}
void printHexln(const int16_t w, bool s = 0) {printHex((uint16_t)w, s); println();}
void printHexln(const int32_t l, bool s = 0) {printHex((uint32_t)l, s); println();}
// The pointer-versions for mass printing uint8_t and uint16_t arrays.
void printHex(const uint8_t b); // in the cpp
void printHex(const int8_t b) {printHex((uint8_t ) b); }
void printHex(const char b) {printHex((uint8_t ) b); }
void printHex(const uint16_t w, bool s = 0); // in the cpp
void printHex(const int16_t w, bool s = 0) {printHex((uint16_t) w, s); }
void printHex(const uint32_t l, bool s = 0) {_prtHxdw((uint8_t *) &l, s); } // this lets all three 4-byte datatypes
void printHex(const int32_t d, bool s = 0) {_prtHxdw((uint8_t *) &d, s); } // share the body
void printHex(const float f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); }
void printHex(const double f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); } // _prtHxdw (Internal printHex for dword, but spelled so it lines up)
// printHexln! - like printHex() now with added newlines!
void printHexln(const char b) {printHex((uint8_t ) b); println();}
void printHexln(const int8_t b) {printHex((uint8_t ) b); println();}
void printHexln(const uint8_t b) {printHex( b); println();}
void printHexln(const int16_t w, bool s = 0) {printHex((uint16_t ) w, s); println();}
void printHexln(const uint16_t w, bool s = 0) {printHex( w, s); println();}
void printHexln(const float f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); println();}
void printHexln(const double f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); println();} // per usual, they all get newline versions.
void printHexln(const int32_t d, bool s = 0) {_prtHxdw((uint8_t *) &d, s); println();} // share the body
void printHexln(const uint32_t l, bool s = 0) {_prtHxdw((uint8_t *) &l, s); println();}
// The pointer using versions that take a pointer, gnaw off a byte or two, and return the new pointer to the caller
// typically called in a loop for a counted number of iterations (frequently, 4, 8, 16, 32 or 64) to dump the entire contents of a peripheral struct.
// Below 4, the loop and pointer loses to brute force, and though these parts have some xmega lineage, nothing has had enough registers for them to
// need to do a 128b peripheral yet. I'm pretty sure xMega did (and for the sake of real oddball stuff, not normal reasonable things.)
// registers that lord knows who uses for lord knows what. That's one thing that I always disliked about the Microchip appnotes - you might be able
// to find one embodiment of the design, but what you don't get is guidance as to what the hell they think you're going to use this thing for. For
// some of the "64b peripherals - heavyweights like TCE, TCA, TCD"
uint8_t * printHex( uint8_t* p, uint8_t len, char sep = 0 );
uint16_t * printHex( uint16_t* p, uint8_t len, char sep = 0, bool s = 0);
volatile uint8_t * printHex(volatile uint8_t* p, uint8_t len, char sep = 0 );
Expand Down Expand Up @@ -340,6 +351,7 @@ class HardwareSerial : public Stream {
#endif

private:
void _prtHxdw(uint8_t* p, bool s = 0); // internal, takes a pointer to a 32-bit type of any sort, reads it as bytes and prints.
void _poll_tx_data_empty(void);
/* These all concern pin set handling */
static void _set_pins(uint8_t* pinInfo, uint8_t mux_count, uint8_t mux_setting, uint8_t enmask);
Expand Down
3 changes: 1 addition & 2 deletions megaavr/cores/dxcore/UART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,7 @@
}
}

void HardwareSerial::printHex(const uint32_t l, bool swaporder) {
uint8_t *ptr = (uint8_t *) &l;
void HardwareSerial::_prtHxdw(uint8_t * ptr, bool swaporder) {
if (swaporder) {
printHex(*(ptr++));
printHex(*(ptr++));
Expand Down
44 changes: 25 additions & 19 deletions megaavr/extras/Ref_Serial.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,34 @@ Obviously this begs the question of how any of the devices involved are supposed
One extremely common task in embedded programming, particularly debugging embedded code, is printing data out as hexadecimal numbers. There is of course, `Serial.print(number,HEX)`, but not only does that burn more flash, it doesn't add an appropriate number of leading zeros (making it hard to read). It's designed to print numbers in the way that programmers would want them printed - the number of leading zeros will match the data type, ie if you print an unsigned long, with 1 in the low byte and 0's in the other three, it will print 00000001, not 1. As you would expect, printHexln() does the same thing and adds a newline.
Below is an unabridged list of the versions:
```c++
void printHex(const uint8_t b);
void printHex(const uint16_t w, bool s = 0);
void printHex(const uint32_t l, bool s = 0);
void printHex(const int8_t b) {printHex((uint8_t ) b); }
void printHex(const char b) {printHex((uint8_t ) b); }
void printHex(const int16_t w, bool s = 0) {printHex((uint16_t)w, s); }
void printHex(const int32_t l, bool s = 0) {printHex((uint32_t)l, s); }
void printHexln(const int8_t b) {printHex((uint8_t )b ); println();}
void printHexln(const char b) {printHex((uint8_t )b ); println();}
void printHexln(const uint8_t b) {printHex( b ); println();}
void printHexln(const uint16_t w, bool s = 0) {printHex( w, s); println();}
void printHexln(const uint32_t l, bool s = 0) {printHex( l, s); println();}
void printHexln(const int16_t w, bool s = 0) {printHex((uint16_t)w, s); println();}
void printHexln(const int32_t l, bool s = 0) {printHex((uint32_t)l, s); println();}
uint8_t * printHex( uint8_t* p, uint8_t len, char sep = 0 );
uint16_t * printHex( uint16_t* p, uint8_t len, char sep = 0, bool s = 0);
volatile uint8_t * printHex(volatile uint8_t* p, uint8_t len, char sep = 0 );
volatile uint16_t * printHex(volatile uint16_t* p, uint8_t len, char sep = 0, bool s = 0);
void printHex(const uint8_t b);
void printHex(const uint16_t w, bool s = 0);
void printHex(const int8_t b) {printHex((uint8_t ) b); }
void printHex(const char b) {printHex((uint8_t ) b); }
void printHex(const int16_t w, bool s = 0) {printHex((uint16_t ) w, s); }
void printHex(const uint32_t l, bool s = 0) {_prtHxdw((uint8_t *) &l, s); } // _prtHxdw() is a private member function
void printHex(const int32_t d, bool s = 0) {_prtHxdw((uint8_t *) &d, s); } // that prints a 4 byte type from a pointer,
void printHex(const float f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); } // and these function definitions pick
void printHex(const double f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); } // out the argument types it can use and
void printHexln(const int8_t b) {printHex((uint8_t )b ); println();} // make them pointy.
void printHexln(const char b) {printHex((uint8_t )b ); println();}
void printHexln(const uint8_t b) {printHex( b ); println();}
void printHexln(const uint16_t w, bool s = 0) {printHex( w, s); println();}
void printHexln(const int16_t w, bool s = 0) {printHex((uint16_t)w, s); println();}
void printHexln(const float f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); println();} // Why float and double? Apparently, the
void printHexln(const double f, bool s = 0) {_prtHxdw((uint8_t *) &f, s); println();} // compiler knows the difference.
void printHexln(const int32_t d, bool s = 0) {_prtHxdw((uint8_t *) &d, s); println();} // with just float, it can't tell if an
void printHexln(const uint32_t l, bool s = 0) {_prtHxdw((uint8_t *) &l, s); println();} // a "long" "unsigned long" or "float"
uint8_t * printHex( uint8_t* p, uint8_t len, char sep = 0 ); // is intended when passing a floating point literal.
uint16_t * printHex( uint16_t* p, uint8_t len, char sep = 0, bool s = 0); // But it works if we provide a copy of printHex for double
volatile uint8_t * printHex(volatile uint8_t* p, uint8_t len, char sep = 0 ); // Anomalies were observed with the above when used on the
volatile uint16_t * printHex(volatile uint16_t* p, uint8_t len, char sep = 0, bool s = 0); // extended I/O space. Nothing definitive was found.
```
There are two particular features worth noting in addition to the correct number of leading zeros, and the fact that it is not horrendously bloated like full serial print.
1. For 16 and 32-bit datatypes, you can pass a boolean as the second argument. If it is true, the endianness will be reversed.
2. You can also pass a pointer to either a uint8_t or a uint16_t variable. In this case the arguments are:
2. You can also pass a pointer to either a uint8_t or a uint16_t variable (likely part of an array). In this case the arguments are:
```c
uint8_t * printHex(uint8_t * p, uint8_t len, char sep = 0);
uint16_t * printHex(uint16_t* p, uint8_t len, char sep = 0, bool s = 0);
Expand Down Expand Up @@ -203,6 +207,8 @@ Many peripherals have a couple of 16-bit registers, amongst a sea of 8-bit ones.
00:00:00:00:00:00
*/
```
Finally, as of 1.5.12-dev, we threw in a version that takes a float and prints out it's binary representation (not the decimal value).
### Serial.begin(uint32_t baud, uint16_t options)
This starts the serial port. Options should be made by combining the constant referring to the desired character size, parity and stop bit length, zero or more of the modifiers below
Expand Down

0 comments on commit f547bfa

Please sign in to comment.