diff options
author | Alex Ong <the.onga@gmail.com> | 2019-01-04 09:43:45 +0100 |
---|---|---|
committer | Alex Ong <the.onga@gmail.com> | 2019-01-04 09:43:45 +0100 |
commit | 2bb2977c133646c4e056960e72029270d77cc1eb (patch) | |
tree | 235d491f992121ac1716c5bf2fafb80983748576 /tmk_core/protocol/arm_atsam/usb/usb_util.c | |
parent | a55c838961c89097ab849ed6cb1f261791e6b9b4 (diff) | |
parent | 47c91fc7f75ae0a477e55b687aa0fc30da0a283c (diff) | |
download | qmk_firmware-2bb2977c133646c4e056960e72029270d77cc1eb.tar.gz qmk_firmware-2bb2977c133646c4e056960e72029270d77cc1eb.tar.xz |
Merge branch 'master' into debounce_refactor
# Conflicts:
# tmk_core/common/keyboard.c
Diffstat (limited to 'tmk_core/protocol/arm_atsam/usb/usb_util.c')
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/usb_util.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tmk_core/protocol/arm_atsam/usb/usb_util.c b/tmk_core/protocol/arm_atsam/usb/usb_util.c new file mode 100644 index 000000000..58b349362 --- /dev/null +++ b/tmk_core/protocol/arm_atsam/usb/usb_util.c @@ -0,0 +1,59 @@ +#include "samd51j18a.h" +#include "string.h" +#include "usb_util.h" + +char digit(int d, int radix) +{ + if (d < 10) + { + return d + '0'; + } + else + { + return d - 10 + 'A'; + } +} + +int UTIL_ltoa_radix(int64_t value, char *dest, int radix) +{ + int64_t original = value; //save original value + char buf[25] = ""; + int c = sizeof(buf)-1; + int last = c; + int d; + int size; + + if (value < 0) //if it's negative, take the absolute value + value = -value; + + do //write least significant digit of value that's left + { + d = (value % radix); + buf[--c] = digit(d, radix); + value /= radix; + } while (value); + + if (original < 0) + buf[--c] = '-'; + + size = last - c + 1; //includes null at end + memcpy(dest, &buf[c], last - c + 1); + + return (size - 1); //without null termination +} + +int UTIL_ltoa(int64_t value, char *dest) +{ + return UTIL_ltoa_radix(value, dest, 10); +} + +int UTIL_itoa(int value, char *dest) +{ + return UTIL_ltoa_radix((int64_t)value, dest, 10); +} + +int UTIL_utoa(uint32_t value, char *dest) +{ + return UTIL_ltoa_radix((int64_t)value, dest, 10); +} + |