forked from ziutek/ftdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (70 loc) · 1.46 KB
/
main.go
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
package main
import (
"flag"
"fmt"
"github.com/ziutek/ftdi"
"os"
)
func checkErr(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
var (
set = flag.Bool("set", false, "Set EEPROM variables")
vendor = flag.Int("vendor", 0x0403, "PCI vendor id")
product = flag.Int("product", 0x6001, "PCI product id")
invert = flag.Int(
"invert",
0,
"Set invert flags (use 0x15 to set all lines down)",
)
cbusFunction = flag.Int(
"cbus",
int(ftdi.CBusIOMode),
"Function id for all CBUS lines",
)
maxCurrent = flag.Int("maxI", 200, "Maximum USB current (mA)")
highCurrent = flag.Bool("highDrive", false, "Set high current drive flag")
)
func main() {
flag.Parse()
d, err := ftdi.OpenFirst(*vendor, *product, ftdi.ChannelAny)
checkErr(err)
defer d.Close()
e := d.EEPROM()
checkErr(e.Read())
checkErr(e.Decode())
fmt.Println(e)
if !*set {
return
}
modified := false
if e.Invert() != *invert {
e.SetInvert(*invert)
modified = true
}
if e.MaxPower() != *maxCurrent {
e.SetMaxPower(*maxCurrent)
modified = true
}
cbusf := ftdi.CBusFunction(*cbusFunction)
for n := 0; n < 4; n++ {
if e.CBusFunction(n) != cbusf {
e.SetCBusFunction(n, cbusf)
modified = true
}
}
if e.HighCurrent(ftdi.ChannelAny) != *highCurrent {
e.SetHighCurrent(ftdi.ChannelAny, *highCurrent)
modified = true
}
if modified {
checkErr(e.Build())
checkErr(e.Write())
checkErr(e.Read())
checkErr(e.Decode())
fmt.Println(e)
}
}