-
Notifications
You must be signed in to change notification settings - Fork 1
/
adprog.sh
134 lines (113 loc) · 2.33 KB
/
adprog.sh
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
echo 30 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio30/direction
sleep 1
echo low > /sys/class/gpio/gpio30/direction
modprobe i2c-dev
I2CBUS="1"
I2CADDR="0x49"
function h2d() {
echo $((16#$1))
}
function d2h() {
printf "%02X" $1
}
function hex_seq() {
for i in $( seq $( h2d $1 ) $( h2d $2 ) )
do
printf "%04X\n" $i
done
}
function set_data() {
page=${1:0:2}
addr=${1:2:2}
data=$2
echo "Setting page $page addr $addr to $data"
i2cset -y $I2CBUS $I2CADDR "0x${1:0:2}" "0x${1:2:2}" "0x$data" i
}
function transfer() {
for index in $( hex_seq $1 $2 )
do
echo $index
data=${map[$index]}
if [ -z "$data" ]; then continue; fi
echo "$index $data"
set_data $index $data
done
}
function io_update {
echo "Updating I/O"
i2cset -y $I2CBUS $I2CADDR "0x0" "0x5" "0x1" i
sleep 1
}
function calibrate {
echo "Calibrating"
i2cset -y $I2CBUS $I2CADDR "0x0A" "0x02" "0x1" i
io_update
i2cset -y $I2CBUS $I2CADDR "0x0A" "0x02" "0x0" i
io_update
}
function sync_distribution {
echo "Syncronising distribution"
i2cset -y $I2CBUS $I2CADDR "0x0A" "0x02" "0x2" i
io_update
i2cset -y $I2CBUS $I2CADDR "0x0A" "0x02" "0x0" i
io_update
}
function write_eeprom {
echo "Writing eeprom"
i2cset -y $I2CBUS $I2CADDR "0x0E" "0x00" "0x1" i
io_update
i2cset -y $I2CBUS $I2CADDR "0x0E" "0x02" "0x1" i
io_update
res=1
while [[ ! "$res" -eq "0" ]]; do
i2cset -y $I2CBUS $I2CADDR "0x0D" "0x00" i
res=$(i2cget -y $I2CBUS $I2CADDR)
echo $res
done
i2cset -y $I2CBUS $I2CADDR "0x0E" "0x00" "0x0" i
io_update
}
if [[ $# -eq 0 ]];
then
exit;
fi
cmd_regex="&h([0-9a-zA-Z]?)([0-9a-zA-Z]{1,2}),&b([01]{8})\s+;([0-9a-zA-Z]{2}) Hex, ([0-9]+) Dec"
declare -A map
while read line
do
if [[ $line =~ $cmd_regex ]]; then
page=${BASH_REMATCH[1]}
if [ -z "$page" ]; then page=0; fi
addr=${BASH_REMATCH[2]}
data=${BASH_REMATCH[4]}
index=$( printf "%02X%02X" $((16#$page)) $((16#$addr)) )
map["$index"]=$data
echo "$index $data"
fi
done < $1
#for index in ${!map[@]}
#do
# echo "$index ${map[$index]}"
#done
transfer 100 108
io_update
calibrate
transfer 200 214
transfer 300 31B
transfer 400 419
io_update
transfer 500 507
transfer 600 663
transfer 680 6e3
transfer 700 763
transfer 780 7e3
io_update
transfer a00 a10
sync_distribution
io_update
if [ "$2" == "eeprom" ]; then
transfer e10 e3f
write_eeprom
fi