aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2017-08-23 10:50:43 +0200
committerjaseg <git@jaseg.net>2017-08-23 10:50:43 +0200
commitabdf02426f5471348061f2130cace9078eb572f4 (patch)
tree398e4ba0f069567e779bbf1a876eeeaf144f161f
parent95e1a0364847919a36cba5352e82ad56c9950251 (diff)
download7seg-abdf02426f5471348061f2130cace9078eb572f4.tar.gz
7seg-abdf02426f5471348061f2130cace9078eb572f4.tar.bz2
7seg-abdf02426f5471348061f2130cace9078eb572f4.zip
Add cmsis export generator
-rw-r--r--fw/.gitignore2
-rw-r--r--fw/gen_cmsis_exports.py30
2 files changed, 32 insertions, 0 deletions
diff --git a/fw/.gitignore b/fw/.gitignore
index 2d9d6e6..9c55c38 100644
--- a/fw/.gitignore
+++ b/fw/.gitignore
@@ -7,4 +7,6 @@
*.bin
*.hex
*.pp
+
transpose.elf
+cmsis_exports.c
diff --git a/fw/gen_cmsis_exports.py b/fw/gen_cmsis_exports.py
new file mode 100644
index 0000000..ba3422b
--- /dev/null
+++ b/fw/gen_cmsis_exports.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+import re
+import os
+
+if __name__ == '__main__':
+ import argparse
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument('cmsis_device_header', nargs='+', type=argparse.FileType('rb'))
+ args = parser.parse_args()
+
+ print('#ifndef __GENERATED_CMSIS_HEADER_EXPORTS__')
+ print('#define __GENERATED_CMSIS_HEADER_EXPORTS__')
+ print()
+ for header in args.cmsis_device_header:
+ lines = header.readlines()
+ name = os.path.basename(header.name)
+ print('#include <{}>'.format(name))
+ print()
+
+ print('/* {} */'.format(name))
+ for l in lines:
+ match = re.match(b'^#define (\w+)\s+\W*(\w+_TypeDef|\w+_Type).*$', l)
+ if match:
+ inst, typedef = match.groups()
+ inst, typedef = inst.decode(), typedef.decode()
+ print('{} *{} = {};'.format(typedef, inst.lower(), inst))
+ print()
+ print('#endif//__GENERATED_CMSIS_HEADER_EXPORTS__')
+