diff options
Diffstat (limited to 'driver_fw')
-rw-r--r-- | driver_fw/.gdbinit | 20 | ||||
-rw-r--r-- | driver_fw/tools/template_wave_tables.py | 68 |
2 files changed, 88 insertions, 0 deletions
diff --git a/driver_fw/.gdbinit b/driver_fw/.gdbinit new file mode 100644 index 0000000..082e6a7 --- /dev/null +++ b/driver_fw/.gdbinit @@ -0,0 +1,20 @@ + +target extended-remote 192.168.1.93:2022 +set print pretty on +set print elements 512 + +# Update GDB's Python paths with the `sys.path` values of the local Python installation, +# whether that is brew'ed Python, a virtualenv, or another system python. + +# Convert GDB to interpret in Python +python +import os,subprocess,sys +# Execute a Python using the user's shell and pull out the sys.path (for site-packages) +paths = subprocess.check_output('python -c "import os,sys;print(os.linesep.join(sys.path).strip())"',shell=True).decode("utf-8").split() +# Extend GDB's Python's search path +sys.path.extend(paths) +end + +source ~/ref/PyCortexMDebug/cmdebug/svd_gdb.py +svd_load ~/ref/stm32square/svd/STM32G070.svd + diff --git a/driver_fw/tools/template_wave_tables.py b/driver_fw/tools/template_wave_tables.py new file mode 100644 index 0000000..ec60de0 --- /dev/null +++ b/driver_fw/tools/template_wave_tables.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import datetime +import math +import numpy as np +import uuid + +def transition(n): + return (1 - np.cos(np.linspace(0, np.pi, n)))/2 + +def template_var(ctype, name, value): + value = list(value) + yield f'const {ctype} {name}[{len(value)}] = {{' + for elem in value: + yield f' {elem},' + yield '};' + +def quantize(fun, maxval): + for val in fun: + yield round(val*maxval) + +def template(ctype, n, erange): + yield '' + yield '/* AUTO-GENERATED SOURCE! DO NOT MODIFY! */' + yield f'/* Generated on {datetime.datetime.now()} by {Path(__file__).name} */' + yield '' + yield "#include <stdint.h>" + yield '' + vals = [x for e in transition(n) for x in [e, e]] + yield from template_var(ctype, 'waveform_zero_one', quantize(vals, erange)) + yield '' + vals = reversed(vals) + yield from template_var(ctype, 'waveform_one_zero', quantize(vals, erange)) + yield '' + +def header(ctype, n, erange): + macro = f'__GEN_WAVE_TABLES_{str(uuid.uuid4()).upper().replace("-", "_")}__' + yield f'#ifndef {macro}' + yield f'#define {macro}' + yield '' + yield '/* AUTO-GENERATED SOURCE! DO NOT MODIFY! */' + yield f'/* Generated on {datetime.datetime.now()} by {Path(__file__).name} */' + yield '' + yield "#include <stdint.h>" + yield '' + yield f'#define WAVEFORM_CONST_ZERO {0}' + yield f'#define WAVEFORM_CONST_ONE 0x{erange:x}' + yield '' + yield f'extern const {ctype} waveform_zero_one[{2*n}];' + yield f'extern const {ctype} waveform_one_zero[{2*n}];' + yield '' + yield f'#endif /* {macro} */' + +if __name__ == '__main__': + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('--table-size', type=int, default=256) + parser.add_argument('--range', type=int, default=256) + parser.add_argument('--header', action='store_true') + parser.add_argument('--storage-type', type=str, default='uint16_t') + parser.add_argument('outfile', type=argparse.FileType('w')) + args = parser.parse_args() + + if args.header: + args.outfile.write('\n'.join(header(args.storage_type, args.table_size, args.range)) + '\n') + else: + args.outfile.write('\n'.join(template(args.storage_type, args.table_size, args.range)) + '\n') |