mirror of https://github.com/Desuuuu/klipper.git
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
|
@ -125,9 +125,9 @@ Handlers.append(HandlerEnumerations)
|
||||||
|
|
||||||
def decode_integer(value):
|
def decode_integer(value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
if len(value) != 7 or value[0] not in '-+':
|
if len(value) != 11 or value[0] not in '-+' or value[1:3] != '0x':
|
||||||
error("Invalid encoded integer '%s'" % (value,))
|
error("Invalid encoded integer '%s'" % (value,))
|
||||||
out = sum([(ord(c) - 48) << (i*6) for i, c in enumerate(value[1:])])
|
out = int(value[1:], 0)
|
||||||
if value[0] == '-':
|
if value[0] == '-':
|
||||||
out -= 1<<32
|
out -= 1<<32
|
||||||
return out
|
return out
|
||||||
|
|
15
src/ctr.h
15
src/ctr.h
|
@ -14,17 +14,20 @@
|
||||||
static char __PASTE(_DECLS_, __LINE__)[] __attribute__((used)) \
|
static char __PASTE(_DECLS_, __LINE__)[] __attribute__((used)) \
|
||||||
__section(".compile_time_request") = (REQUEST)
|
__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
|
// Declare a compile time request with an integer expression
|
||||||
#define DECL_CTR_INT(REQUEST, VALUE) \
|
#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)) \
|
__PASTE(_DECLI_, __LINE__) __attribute__((used)) \
|
||||||
__section(".compile_time_request") = { \
|
__section(".compile_time_request") = { \
|
||||||
REQUEST " ", { \
|
REQUEST " ", { \
|
||||||
(VALUE) < 0 ? '-' : '+', \
|
(VALUE) < 0 ? '-' : '+', '0', 'x', \
|
||||||
CTR_INT((VALUE),0), CTR_INT((VALUE),6), \
|
CTR_INT((VALUE),28), CTR_INT((VALUE),24), \
|
||||||
CTR_INT((VALUE),12), CTR_INT((VALUE),18), \
|
CTR_INT((VALUE),20), CTR_INT((VALUE),16), \
|
||||||
CTR_INT((VALUE),24), CTR_INT((VALUE),30), 0 } }
|
CTR_INT((VALUE),12), CTR_INT((VALUE),8), \
|
||||||
|
CTR_INT((VALUE),4), CTR_INT((VALUE),0), 0 } }
|
||||||
|
|
||||||
#endif // ctr.h
|
#endif // ctr.h
|
||||||
|
|
Loading…
Reference in New Issue