Blame view
220222_final/EP/pwm_cli.py
2.19 KB
35833671e
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#!/usr/bin/env python3 import sys from litex import RemoteClient import argparse def pwm_cli_handler(dict_cfg): wb = RemoteClient() wb.open() print(wb) print(wb.regs.pwm0_period.read()) print(wb.regs.pwm0_duty.read()) print(wb.regs.pwm0_enable.read()) if "period" in dict_cfg: period = int(float(dict_cfg["period"])) print(f"period {period}") wb.regs.pwm0_period.write(period) print(wb.regs.pwm0_period.read()) if "duty" in dict_cfg: duty = int(float(dict_cfg["duty"])) print(f"duty {duty}") wb.regs.pwm0_duty.write(duty) print(wb.regs.pwm0_duty.read()) if "oneshot" in dict_cfg: oneshot = int(float(dict_cfg["oneshot"])) print(f"oneshot {oneshot}") wb.regs.pwm0_period_oneshot.write(int(oneshot)) if "enable" in dict_cfg and dict_cfg["enable"]: print("enable") period = wb.regs.pwm0_period.read() duty = wb.regs.pwm0_duty.read() if period == 0 or duty == 0: print("Error: period and/or duty must be configured before enable output") return wb.regs.pwm0_enable.write(1) print(wb.regs.pwm0_enable.read()) if "disable" in dict_cfg and dict_cfg["disable"]: print("disable") wb.regs.pwm0_enable.write(0) if __name__ == '__main__': parser = argparse.ArgumentParser(description="pwm CLI") parser.add_argument("--enable", action="store_true", help="enable PWM output") parser.add_argument("--disable", action="store_true", help="disable PWM output") parser.add_argument("--period", help="period (in clock cycle)") parser.add_argument("--duty", help="duty cycle (in clock cycle)") parser.add_argument("--oneshot", help="period correction (in clock cycle)") args = parser.parse_args() dict_cfg = {} if args.period: dict_cfg["period"] = args.period if args.duty: dict_cfg["duty"] = args.duty if args.oneshot: dict_cfg["oneshot"] = args.oneshot if args.enable: dict_cfg["enable"] = True if args.disable: dict_cfg["disable"] = True pwm_cli_handler(dict_cfg) |