aboutsummaryrefslogtreecommitdiff
path: root/src/kern/lib.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-11-24 13:46:41 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-11-24 13:46:41 -0700
commit93b063fedfcf7409a67df035170ea5670cad22e1 (patch)
treea23321a7465d966b1ccf196ca00e65a70c9f9110 /src/kern/lib.c
parentb040195d31df6ad759f16ea3456471897f55daa1 (diff)
downloadstm32l4-93b063fedfcf7409a67df035170ea5670cad22e1.tar.gz
stm32l4-93b063fedfcf7409a67df035170ea5670cad22e1.tar.bz2
stm32l4-93b063fedfcf7409a67df035170ea5670cad22e1.zip
Moved action to top level.
Removed old iterations of the project and moved the files from 02-usart to the root directory since that's the sole place where the action is and that subproject has outgrown its initial title.
Diffstat (limited to 'src/kern/lib.c')
-rw-r--r--src/kern/lib.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/kern/lib.c b/src/kern/lib.c
new file mode 100644
index 0000000..88188cc
--- /dev/null
+++ b/src/kern/lib.c
@@ -0,0 +1,56 @@
+#include "kern/lib.h"
+
+#define nybble_to_hex(n) \
+ ((n) < 10 ? 0x30 + (n) : ('A' + ((n) - 10)))
+
+void hexify(uint32_t v, char* into)
+{
+ into += 8;
+
+ *(into--) = 0;
+
+ *(into--) = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+ *(into--) = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+ *(into--) = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+ *(into--) = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+
+ *(into--) = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+ *(into--) = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+ *(into--) = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+ *into = nybble_to_hex(v & 0x0F);
+ v >>= 4;
+}
+
+void decimalify(int v, char* into)
+{
+ int c = 0;
+ int i;
+
+ if (v == 0) {
+ *(into ++) = '0';
+ *into = 0;
+ return;
+ } else {
+ while (v > 0) {
+ *(into ++) = 0x30 + (v % 10);
+ v /= 10;
+ ++ c;
+ }
+ }
+ *into = 0;
+
+ into -= c;
+ for (i = 0; i < c / 2; ++ i) {
+ char tmp = into[i];
+ into[i] = into[c - i - 1];
+ into[c - i - 1] = tmp;
+ }
+
+}