mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-21 21:58:05 -06:00
ctr: Encode integers in hex
Replace the custom encoding with a hex encoding. This makes it a little easier to inspect the CTR conversions. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
69fc1e63b4
commit
e59d875256
2 changed files with 11 additions and 8 deletions
15
src/ctr.h
15
src/ctr.h
|
@ -14,17 +14,20 @@
|
|||
static char __PASTE(_DECLS_, __LINE__)[] __attribute__((used)) \
|
||||
__section(".compile_time_request") = (REQUEST)
|
||||
|
||||
#define CTR_INT(V, S) ((((uint32_t)(V) >> S) & 0x3f) + 48)
|
||||
// Helper macros for encoding an integer
|
||||
#define CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0')
|
||||
#define CTR_INT(V, S) CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f)
|
||||
|
||||
// Declare a compile time request with an integer expression
|
||||
#define DECL_CTR_INT(REQUEST, VALUE) \
|
||||
static struct { char _r[sizeof(REQUEST)]; char _v[8]; } \
|
||||
static struct { char _r[sizeof(REQUEST)]; char _v[12]; } \
|
||||
__PASTE(_DECLI_, __LINE__) __attribute__((used)) \
|
||||
__section(".compile_time_request") = { \
|
||||
REQUEST " ", { \
|
||||
(VALUE) < 0 ? '-' : '+', \
|
||||
CTR_INT((VALUE),0), CTR_INT((VALUE),6), \
|
||||
CTR_INT((VALUE),12), CTR_INT((VALUE),18), \
|
||||
CTR_INT((VALUE),24), CTR_INT((VALUE),30), 0 } }
|
||||
(VALUE) < 0 ? '-' : '+', '0', 'x', \
|
||||
CTR_INT((VALUE),28), CTR_INT((VALUE),24), \
|
||||
CTR_INT((VALUE),20), CTR_INT((VALUE),16), \
|
||||
CTR_INT((VALUE),12), CTR_INT((VALUE),8), \
|
||||
CTR_INT((VALUE),4), CTR_INT((VALUE),0), 0 } }
|
||||
|
||||
#endif // ctr.h
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue