From 1dc7d758f96dd2b9bd7b03f01ca032d68b696cf0 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 2 Nov 2014 10:14:39 +0000 Subject: fish --- libopencm3/scripts/data/lpc43xx/csv2yaml.py | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 libopencm3/scripts/data/lpc43xx/csv2yaml.py (limited to 'libopencm3/scripts/data/lpc43xx/csv2yaml.py') diff --git a/libopencm3/scripts/data/lpc43xx/csv2yaml.py b/libopencm3/scripts/data/lpc43xx/csv2yaml.py new file mode 100755 index 0000000..1ec9a41 --- /dev/null +++ b/libopencm3/scripts/data/lpc43xx/csv2yaml.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import sys +import yaml +import csv +from collections import OrderedDict +import yaml_odict + +def convert_file(fname): + reader = csv.reader(open(fname, 'r')) + + registers = OrderedDict() + for register_name, lsb, width, field_name, description, reset_value, access in reader: + if register_name not in registers: + registers[register_name] = { + 'fields': OrderedDict(), + } + + register = registers[register_name] + fields = register['fields'] + if field_name in fields: + raise RuntimeError('Duplicate field name "%s" in register "%s"' % + field_name, register_name) + else: + fields[field_name] = { + 'lsb': int(lsb), + 'width': int(width), + 'description': description, + 'reset_value': reset_value, + 'access': access, + } + + with open(fname.replace('.csv', '.yaml'), 'w') as out_file: + yaml.dump(registers, out_file, default_flow_style=False) + +for fname in sys.argv[1:]: + convert_file(fname) -- cgit v1.2.3