forked from multigcs/LinuxCNC-RIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.py
108 lines (98 loc) · 3.86 KB
/
plugin.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
class Plugin:
ptype = "vout_sine"
def __init__(self, jdata):
self.jdata = jdata
def setup(self):
return [
{
"basetype": "vout",
"subtype": self.ptype,
"options": {
"name": {
"type": "str",
"name": "pin name",
"comment": "the name of the pin",
"default": "",
},
"net": {
"type": "vtarget",
"name": "net target",
"comment": "the target net of the pin in the hal",
"default": "",
},
"pin": {
"type": "output",
"name": "output pin",
},
},
}
]
def vminmax(self, setup):
return (-100, 100)
def calculation_vout(self, setup, value):
if value != 0:
value = int(self.jdata["clock"]["speed"] / value / 30)
else:
value = 0
return value
def calculation_vout_c(self, setup):
return """
if (value != 0) {
value = PRU_OSC / value / 30;
}
"""
def pinlist(self):
pinlist_out = []
for num, data in enumerate(self.jdata["plugins"]):
if data["type"] == self.ptype:
if "pins" in data:
for pn, pin in enumerate(data["pins"]):
pinlist_out.append((f"VOUT{num}_SINEPWM_{pn}", pin, "OUTPUT"))
else:
pinlist_out.append((f"VOUT{num}_SINEPWM", data["pin"], "OUTPUT"))
return pinlist_out
def voutnames(self):
ret = []
for num, data in enumerate(self.jdata["plugins"]):
if data.get("type") == self.ptype:
name = data.get("name", f"SP.{num}")
nameIntern = name.replace(".", "").replace("-", "_").upper()
data["_name"] = name
data["_prefix"] = nameIntern
ret.append(data)
return ret
def funcs(self):
func_out = []
for num, data in enumerate(self.jdata["plugins"]):
if data["type"] == self.ptype:
name = data.get("name", f"SP.{num}")
nameIntern = name.replace(".", "").replace("-", "_").upper()
frequency = int(data.get("frequency", 25000))
divider = int(self.jdata["clock"]["speed"]) // frequency // 512
if "pins" in data:
pstep = 30 // len(data["pins"])
start = 0
for pn, _pin in enumerate(data["pins"]):
func_out.append(
f" vout_sinepwm #({start}, {divider}) vout_sinepwm{num}_{pn} ("
)
func_out.append(" .clk (sysclk),")
func_out.append(f" .freq ({nameIntern}),")
func_out.append(f" .pwm_out (VOUT{num}_SINEPWM_{pn})")
func_out.append(" );")
start = start + pstep
else:
start = data.get("start", 0)
func_out.append(
f" vout_sinepwm #({start}, {divider}) vout_sinepwm{num} ("
)
func_out.append(" .clk (sysclk),")
func_out.append(f" .freq ({nameIntern}),")
func_out.append(f" .pwm_out (VOUT{num}_SINEPWM)")
func_out.append(" );")
return func_out
def ips(self):
for num, data in enumerate(self.jdata["plugins"]):
if data["type"] == self.ptype:
return ["vout_sinepwm.v"]
return []