针对digital amp主要利用ini里的内容。driver code会依据ini format type去 parser内容给digital amp。
下面是mtkparser的格式
[INIT_TABLE]
IniFormatType = x // MtkParser 目前固定填 0 即可
count = xx; // xx 是后面部分 index 总数
index_x = AA, BB, CC; // x: 命令 index 值,从 0 开始;AA: data length,BB: I2C address CC: data
下面是声学文件cfg的格式样本。有用的字段是去除#号,干掉第一列及第二列的剩余两列。
#RESET
w 58 00 00
w 58 7f 00
w 58 03 02
w 58 01 11
w 58 00 00
w 58 00 00
w 58 00 00
w 58 00 00
w 58 00 00
w 58 7f 00
w 58 03 02
##d 5
w 58 00 00
w 58 7f 00
w 58 03 00
w 58 00 00
w 58 7f 00
w 58 46 01
## 111
w 58 00 00
w 58 7f 00
w 58 03 02
w 58 00 00
w 58 7f 00
w 58 78 80
## 11
w 58 00 00
w 58 7f 00
w 58 61 0b
w 58 60 01
w 58 7d 11
w 58 7e ff
w 58 00 01
w 58 51 05
通过5805cfg2ini_dts.sh脚本把cfg转成ini。
须转换成功最重要的是burst_page字段及grp_size字段填对。
首先看grp_size字段。从cfg文件中捞出"00 2x"字段的数据。将"00 2x"在grp_size中标记为1,cfg中第一列递增为连续的数据,所以1后面跟连续数据长度,连续被中断再次计数,直到碰到"00 2x"为止。
再看burst_page字段,以"60 01" "02 00"开头,从cfg文件中罗列出"7f 8c" "7f aa"字段后紧跟的"00 2x"数据。罗列出来的数据在grp_size中去掉1,计算grp_size中对应被去1的"00 2x" 间的数据个数,有多少个数在bust_page中补多少"x"。
凡是burst_page中有字串的,不用在grp_size中补1,在grp_size中写字串后的length长度。如"60 01" "02 00" "00 29"在grp_size中不用补1,只填字串后的length。
#!/bin/sh
# Useage: $ sh 5805cfg2ini_dts.sh file
#
# Output file: audio_amp_device_ti5805.ini
line_num=1;
index=0;
burst_page=(
"60 01"
"02 00"
"00 29"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"00 24"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"x"
"00 2b"
"x"
"x"
"00 2e"
"x"
"x"
"x"
"x"
"x"
"00 2d"
"00 2a"
"x"
"x"
"x"
"x"
"00 2e"
"x"
"x"
"x")
grp_size=(2 2 16 1 8 4 1 24 8 8 8 20 4 1 24 1 4 104 1 120 1 120 1 120 1 120 1 16 1 4 1 16 20 1 20 39 1 41 20 1 20 20 1 20 40 36 1 4 1 20 4 4 4 12)
cp $1 pre_process.ini
function pre_process()
{
#echo "1. pre_process";
#Remove line with '#' beginning
sed -i '/^\#/d' pre_process.ini
#Remove line with no content
sed -i '/^$/d' pre_process.ini
#Remove the beginning four charactor
sed -r -i 's/.{4}//' pre_process.ini
#cp pre_process.ini input.ini
}
#input line num to deal
#deal with tmp2.ini for the specific lines
#update file
# 1. pre_process.ini -> continue to deal with
# 2. tmp1.ini for final pre-output file.
function process_burst_reg()
{
head -n $1 tmp2.ini > tmp3.ini
tail -n +$1 tmp2.ini > tmp4.ini
sed -i '1d' tmp4.ini
mv tmp4.ini pre_process.ini
#deal with tmp3.ini(burst value)->tmp1.ini
echo 'index_'$index'='$1 >> tmp4.ini
((index++));
#echo $1 > tmp4.ini #record strength
head -n +1 tmp3.ini >> tmp4.ini
#cp tmp4.ini input2.ini
#sed -i 's/^[ \t]*//g' tmp4.ini #remove first space
sed -i '1d' tmp3.ini
sed -r 's/.{3}//' tmp3.ini >> tmp4.ini
sed -i ':a;N;$!ba;s/\n//g' tmp4.ini #remove \n
cat tmp4.ini >> tmp1.ini
#cp tmp1.ini input3.ini
rm tmp2.ini
rm tmp3.ini
rm tmp4.ini
return 0;
}
# input str
# get 1.line num of input str in pre_process.ini
# 2.the content file tmp1.ini before line_num
# 3.the content file tmp2.ini after line_num
function process_basic()
{
echo 'Transforming ...input:$1'
#echo 'Start Finding page pos of burst reg : ' $1
line_num=1
echo " line = $line input:$1"
if [[ x == $1 ]]
then
#echo "match x"
tail -n +$line_num pre_process.ini > tmp2.ini
return 0;
fi
while read line
do
echo 'index_'$index'=1 '$line >> tmp1.ini
((index++));
if [[ $line =~ $1 ]]
then
echo "index=$index line = $line "
break;
fi
((line_num++));
done < pre_process.ini
echo "index=$index line_num = $line_num "
tail -n +$line_num pre_process.ini > tmp2.ini
sed -i '1d' tmp2.ini
return 0;
}
function process_start()
{
for i in "${!burst_page[@]}"
do
#echo "${burst_page[$i]}"
process_basic "${burst_page[$i]}"; #deal with main ch input mixer, len 16
process_burst_reg ${grp_size[$i]}
done
#handle the end of the content(index not covered in burst_page) of pre_process.ini
while read line
do
echo 'index_'$index'=1 '$line >> tmp1.ini
((index++));
done < pre_process.ini
rm pre_process.ini
return 0;
}
#handle tmp1.ini and convert to final ini
function pos_process()
{
#replace " " with ", 0x"
sed -i 's/[[:space:]]/,0x/g' tmp1.ini
cp tmp1.ini input4.ini
#replace "=" with " = "
#sed -i 's/=/ = /g' tmp1.ini
cp tmp1.ini input5.ini
#add ; at the end
sed -i 's/$/&;/g' tmp1.ini
#replace ", 0x;" with ";"
sed -i 's/[[:space:]]/,0x/g' tmp1.ini
#replace ",0x;" with ";"
sed -i 's/,0x;/;/g' tmp1.ini
#replace ",0x," with ","
sed -i 's/,0x,/,/g' tmp1.ini
echo '[INIT_TABLE]' > audio_amp_device_ti5805.ini
echo '####################################################################################' >> audio_amp_device_ti5805.ini
echo '#IniFormatType value: 0, 1' >> audio_amp_device_ti5805.ini
echo '#E_AMP_DEVICE_INI_FORMAT_TYPE_0 = 0, // Support Single REG, Multi-REG format' >> audio_amp_device_ti5805.ini
echo '# // NOT SUPPORT single RAM, Multi-RAM format' >> audio_amp_device_ti5805.ini
echo '#E_AMP_DEVICE_INI_FORMAT_TYPE_1 = 1, // Support Single REG, Multi-RAM format' >> audio_amp_device_ti5805.ini
echo '# // NOT SUPPORT Multi-REG format' >> audio_amp_device_ti5805.ini
echo '####################################################################################' >> audio_amp_device_ti5805.ini
echo 'IniFormatType = 0' >> audio_amp_device_ti5805.ini
echo 'count = '$index';' >> audio_amp_device_ti5805.ini
echo >> audio_amp_device_ti5805.ini
cat tmp1.ini >> audio_amp_device_ti5805.ini
rm tmp1.ini
return 0;
}
pre_process;
process_start;
pos_process;
exit 0;
标签:mtkparser,58,process,cfg,00,音频文件,ini,line,echo From: https://www.cnblogs.com/bubble1223/p/18153478