aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/pwm_conf.py
blob: e7ef3abcd6df5fc50e236c9d8d5ccb6c627243ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env python3

import sys
from fractions import Fraction

print("/* THIS IS A GENERATED FILE */\n")
for arg in sys.argv:
	if arg.startswith("-DCONF_PWMLOWSPFACT="):
		fact = arg.split("=")[1].replace('"', '').strip()
		fraction = Fraction(fact).limit_denominator(0xFFFF)
		if not 0 <= fraction.numerator <= 0xFFFF:
			raise Exception("PWM correction factor is out of range.")
		print(f"#define CONF_PWMLOWSPFACT_MUL {fraction.numerator}u")
		print(f"#define CONF_PWMLOWSPFACT_DIV {fraction.denominator}u")
bues.ch cgit interface