aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrey Smirnov2012-11-06 16:48:40 -0800
committerAndrey Smirnov2012-11-06 16:48:40 -0800
commit12e178686331fd0a8e3564a9f0e77fece4a04617 (patch)
tree9b55dbd2d16e6950f564ebcfcb4b03898f8a0d6d /lib
parent7a5da60e2669c57d7b615aabe16ab851606f8bf1 (diff)
Add a desig_get_unique_id_as_string
This commit adds desig_get_unique_id_as_string which is useful if one wants to use device ID as USB serial number(iSerialNumber), for example.
Diffstat (limited to 'lib')
-rw-r--r--lib/stm32/f1/desig.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/stm32/f1/desig.c b/lib/stm32/f1/desig.c
index 7ae968e..7f213fa 100644
--- a/lib/stm32/f1/desig.c
+++ b/lib/stm32/f1/desig.c
@@ -35,3 +35,25 @@ void desig_get_unique_id(u32 result[])
result[1] = bits63_32;
result[2] = bits31_16 << 16 | bits15_0;
}
+
+void desig_get_unique_id_as_string(char *string,
+ unsigned int string_len)
+{
+ int i, len;
+ u8 device_id[12];
+ static const char chars[] = "0123456789ABCDEF";
+
+ desig_get_unique_id((u32 *)device_id);
+
+ /* Each byte produces two characters */
+ len = (2 * sizeof(device_id) < string_len) ?
+ 2 * sizeof(device_id) : string_len - 1;
+
+ for (i = 0; i < len; i += 2) {
+ string[i] = chars[(device_id[i / 2] >> 0) & 0x0F];
+ string[i + 1] = chars[(device_id[i / 2] >> 4) & 0x0F];
+ }
+
+ string[len] = '\0';
+}
+