-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathamp-c.sh
executable file
·81 lines (71 loc) · 1.74 KB
/
amp-c.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
#!/usr/bin/env bash
set -e
if [ ! -f "$1" ]
then
echo "$0 [amp.txt]" >&2
exit 1
fi
page="00"
function s {
reg="$1"
shift
if [[ "$reg" = "00" ]]
then
echo -en "\tres = tas5825m_set_page(dev, 0x$@);\n"
echo -en "\tif (res < 0)\n"
echo -en "\t\treturn res;\n\n"
page="$@"
elif [[ "$page" = "00" && "$reg" = "7F" ]]
then
echo -en "\tres = tas5825m_set_book(dev, 0x$@);\n"
echo -en "\tif (res < 0)\n"
echo -en "\t\treturn res;\n\n"
else
if [[ "$#" = "1" ]]
then
echo -en "\tres = tas5825m_write_at(dev, 0x$reg, 0x$@);\n"
echo -en "\tif (res < 0)\n"
echo -en "\t\treturn res;\n\n"
else
echo -en "\t{\n"
echo -en "\t\tconst uint8_t values[] = {"
i="0"
for arg in "$@"
do
if [[ "$i" = "0" ]]
then
echo -en "\n\t\t\t"
else
echo -n ", "
fi
echo -n "0x$arg"
i="$(("$i" + 1))"
if [[ "$i" = "8" ]]
then
i="0"
echo -n ","
fi
done
echo -en "\n\t\t};\n"
echo -en "\t\tres = tas5825m_write_block_at(dev, 0x$reg, values, ARRAY_SIZE(values));\n"
echo -en "\t\tif (res < 0)\n"
echo -en "\t\t\treturn res;\n"
echo -en "\t}\n\n"
fi
fi
}
cat <<"EOF"
/* SPDX-License-Identifier: GPL-2.0-only */
#include <drivers/i2c/tas5825m/tas5825m.h>
int tas5825m_setup(struct device *dev, int id)
{
int res;
EOF
cat "$1" | while read line
do
s $line
done
cat <<"EOF"
return 0;
}
EOF