diff --git a/src/include/hlib.h b/src/include/hlib.h index 22fd9be..eba70c7 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -18,6 +18,9 @@ #define PAGE_ID(address) (U32(address) >> 12) #define PAGE_OFFSET(address) (U32(address) & 0xFFF) +#define MIN(x, y) (x < y ? (x) : (y)) +#define MAX(x, y) (x < y ? (y) : (x)) + #define NULL PTR(0) extern uint32_t createFunction(char *name, int32_t(handler)(void *, uint32_t)); @@ -62,8 +65,6 @@ extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); -#define MAX(x, y) (x > y ? (x) : (y)) - #define foreach(list, type, varname, ...) \ for (ListElement *current = list; current; current = current->next) { \ type varname = current->data; \ diff --git a/src/include/hlib.h b/src/include/hlib.h index 22fd9be..eba70c7 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -18,6 +18,9 @@ #define PAGE_ID(address) (U32(address) >> 12) #define PAGE_OFFSET(address) (U32(address) & 0xFFF) +#define MIN(x, y) (x < y ? (x) : (y)) +#define MAX(x, y) (x < y ? (y) : (x)) + #define NULL PTR(0) extern uint32_t createFunction(char *name, int32_t(handler)(void *, uint32_t)); @@ -62,8 +65,6 @@ extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); -#define MAX(x, y) (x > y ? (x) : (y)) - #define foreach(list, type, varname, ...) \ for (ListElement *current = list; current; current = current->next) { \ type varname = current->data; \ diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 6e8d468..c3a6350 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -40,18 +40,19 @@ } } -void startCollection(uint32_t data) { +void startCollection(uint32_t data, uint32_t padding) { char *collectionType = "Vendor defined"; if (data < sizeof(collectionTypes) / sizeof(collectionTypes[0])) { collectionType = collectionTypes[data]; } else if (data < 0x80) { collectionType = "Reserved"; } - printf("collection(%s)\n", collectionType); + printf("%pcollection(%s)\n", padding, collectionType); } void parseReportDescriptor(uint8_t *descriptor) { uint8_t *read = descriptor; + uint32_t padding = 0; while (1) { uint8_t item = *read; uint8_t dataSize = item & 0x3; @@ -63,19 +64,21 @@ case 0: return; case 1: - printf("Usage page: %x\n", data); + printf("%pUsage page: %x\n", padding, data); break; case 5: - printf("Logical minimum: %x\n", data); + printf("%pLogical minimum: %x\n", padding, data); break; case 9: - printf("Logical maximum: %x\n", data); + printf("%pLogical maximum: %x\n", padding, data); break; case 0x28: - startCollection(data); + startCollection(data, padding); + padding += 2; break; case 0x30: - printf("End collection\n"); + padding -= 2; + printf("%pEnd collection\n", padding); break; } } diff --git a/src/include/hlib.h b/src/include/hlib.h index 22fd9be..eba70c7 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -18,6 +18,9 @@ #define PAGE_ID(address) (U32(address) >> 12) #define PAGE_OFFSET(address) (U32(address) & 0xFFF) +#define MIN(x, y) (x < y ? (x) : (y)) +#define MAX(x, y) (x < y ? (y) : (x)) + #define NULL PTR(0) extern uint32_t createFunction(char *name, int32_t(handler)(void *, uint32_t)); @@ -62,8 +65,6 @@ extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); -#define MAX(x, y) (x > y ? (x) : (y)) - #define foreach(list, type, varname, ...) \ for (ListElement *current = list; current; current = current->next) { \ type varname = current->data; \ diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 6e8d468..c3a6350 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -40,18 +40,19 @@ } } -void startCollection(uint32_t data) { +void startCollection(uint32_t data, uint32_t padding) { char *collectionType = "Vendor defined"; if (data < sizeof(collectionTypes) / sizeof(collectionTypes[0])) { collectionType = collectionTypes[data]; } else if (data < 0x80) { collectionType = "Reserved"; } - printf("collection(%s)\n", collectionType); + printf("%pcollection(%s)\n", padding, collectionType); } void parseReportDescriptor(uint8_t *descriptor) { uint8_t *read = descriptor; + uint32_t padding = 0; while (1) { uint8_t item = *read; uint8_t dataSize = item & 0x3; @@ -63,19 +64,21 @@ case 0: return; case 1: - printf("Usage page: %x\n", data); + printf("%pUsage page: %x\n", padding, data); break; case 5: - printf("Logical minimum: %x\n", data); + printf("%pLogical minimum: %x\n", padding, data); break; case 9: - printf("Logical maximum: %x\n", data); + printf("%pLogical maximum: %x\n", padding, data); break; case 0x28: - startCollection(data); + startCollection(data, padding); + padding += 2; break; case 0x30: - printf("End collection\n"); + padding -= 2; + printf("%pEnd collection\n", padding); break; } } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 2035921..fa0500a 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -85,6 +85,13 @@ } } +void putPadding(char **write, uintptr_t x) { + x = MIN(x, 10); // max 10 wide padding + for (intptr_t i = 0; i < x; i++) { + addChar(write, ' '); + } +} + uint32_t getInsertLength(char insertType, intptr_t x) { switch (insertType) { case 's': @@ -95,6 +102,8 @@ return 1; case 'i': return intLength(x) + (x < 0); + case 'p': + return x; } return 0; } @@ -122,6 +131,8 @@ return; case 'i': putInt(write, x); + case 'p': + putPadding(write, x); } } uint32_t ioManager, logFunction, keyCallback;