diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index 7f591df..6ddfa08 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -28,8 +28,10 @@ extern void free(void *); extern void _printf(void *(malloc)(uint32_t), const char *format, ...); +extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); #define printf(...) _printf(malloc, __VA_ARGS__) +#define asprintf(...) _asprintf(malloc, __VA_ARGS__) #ifdef ALLOC_MAIN #undef ALLOC_MAIN diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index 7f591df..6ddfa08 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -28,8 +28,10 @@ extern void free(void *); extern void _printf(void *(malloc)(uint32_t), const char *format, ...); +extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); #define printf(...) _printf(malloc, __VA_ARGS__) +#define asprintf(...) _asprintf(malloc, __VA_ARGS__) #ifdef ALLOC_MAIN #undef ALLOC_MAIN diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index dbed8fc..a7516d9 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -33,7 +33,7 @@ state->totalBits += state->reportSize; } -void input(ReportParserState *state, uint32_t data, ListElement **inputGroups) { +char *ioParameter(uint32_t data) { // https://www.usb.org/sites/default/files/hid1_11.pdf // page 38, section 6.2.2.4, Main items table char *constant = data >> 0 & 1 ? "Constant" : "Data"; @@ -44,9 +44,7 @@ char *prefered = data >> 5 & 1 ? "NoPreferredState" : "PreferredState"; char *null = data >> 6 & 1 ? "NullState" : "NoNullState"; char *bitField = data >> 8 & 1 ? "BufferedBytes" : "BitField"; - - printf("%pInput(%x => %s, %s, %s, %s, %s, %s, %s, %s)\n", - state->padding, + return asprintf("%x => %s, %s, %s, %s, %s, %s, %s, %s", data, constant, array, @@ -56,7 +54,13 @@ prefered, null, bitField - ); + ); +} + +void input(ReportParserState *state, uint32_t data, ListElement **inputGroups) { + char *parameters = ioParameter(data); + printf("%pInput(%s)\n", state->padding, parameters); + free(parameters); InputGroup *group = malloc(sizeof(InputGroup)); // signed integers are represented as 2s-complement