-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.sh
executable file
·1227 lines (1105 loc) · 44.5 KB
/
convert.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# EmuFlight definition converter.
# "Usable" since 2023 July.
# Partially Converts Betaflight config.h files to EmuFlight .mk .c .h files.
# Open to receiving more efficient and elegant code.
# July 2023 and later revision requires Internet connection for automated definitions download.
if [[ ! $# -eq 2 ]] 2>/dev/null; then
echo "EmuFlight partial target converter script."
echo "Usage: ${0##*/} <unifiedTargetName> <targetFolder>"
echo " Ex: ${0##*/} TURC-TUNERCF405 ./"
echo " Ex: ${0##*/} DIAT-MAMBAF722_2022B ../EmuFlight/src/main/target/"
echo ""
echo "note: Target definitions will be downloaded from"
echo " https://github.com/betaflight/config/"
echo " and https://github.com/betaflight/unified-targets/"
exit
fi
if [[ ! $( which grep ) ]] ; then
echo 'please install: grep'
exit 1
fi
if [[ ! $( which awk ) ]] ; then
echo 'please install: awk'
exit 1
fi
if [[ ! $( which sed ) ]] ; then
echo 'please install: sed'
exit 1
fi
if [[ ! $( which wc ) ]] ; then
echo 'please install: wc'
exit 1
fi
if [[ ! $( which expr ) ]] ; then
echo 'please install: expr'
exit 1
fi
if [[ ! $( which xargs ) ]] ; then
echo 'please install: xargs'
exit 1
fi
if [[ ! $( which wget ) ]] ; then
echo 'please install: wget'
exit 1
fi
if [[ ! $( which git ) ]] ; then
echo 'please install: git'
exit 1
fi
license='/*
* This file is part of EmuFlight. It is derived from Betaflight.
*
* This is free software. You can redistribute this software
* and/or modify this software under the terms of the GNU General
* Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later
* version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
'
# examples: https://github.com/betaflight/config/raw/master/configs/TUNERCF405/config.h
# https://github.com/betaflight/unified-targets/raw/master/configs/default/TURC-TUNERCF405.config
# https://github.com/betaflight/config/raw/master/configs/MAMBAF722_2022B/config.h
# https://github.com/betaflight/unified-targets/raw/master/configs/default/DIAT-MAMBAF722_2022B.config
echo ""
generatedMessage="This resource file generated using https://github.com/nerdCopter/target-convert"
generatedSHA="Commit: $(git rev-parse --short HEAD)"
generatedDiff="$(git diff --shortstat)"
if [ -n "$generatedDiff" ]; then
generatedSHA+=" +$generatedDiff"
fi
echo "${generatedMessage}"
echo "${generatedSHA}"
echo ""
manufacturer=$(echo ${1} | awk -F'-' '{print $1}')
board=$(echo ${1} | awk -F'-' '{print $2}')
fc="${manufacturer}_${board}"
dest="${2}/${board}"
resources="${dest}/resources"
echo "creating ${fc}"
mkdir ${dest} 2> /dev/null
mkdir ${resources} 2> /dev/null
echo "downloading..."
wget -c -N -nv -P ${resources} "https://github.com/betaflight/config/raw/master/configs/${board}/config.h" || { echo "download failed. aborting." ; rm -rf ${dest} ; exit 1 ; }
wget -c -N -nv -P ${resources} "https://github.com/betaflight/unified-targets/raw/master/configs/default/${1}.config" || { echo "download failed. aborting." ; rm -r ${dest} ; exit 1 ; }
config="${resources}/config.h"
unified="${resources}/${1}.config"
echo "config.h: ${config}"
echo "unified: ${unified}"
mkFile="${dest}/target.mk"
cFile="${dest}/target.c"
hFile="${dest}/target.h"
tFile="${resources}/timers.txt"
function translate () {
local search="$1"
local infile="$2"
local output="$3"
local outfile="$4"
if [[ $(grep "${search}" "${infile}") ]]; then
echo -e "${output}" >> "${outfile}"
fi
}
# create target.mk file
echo "building ${mkFile}"
# setup STM32 type
# BF:
# STM32F405
# STM32F411
# STM32F411DISCOVERY
# STM32F411SX1280
# STM32F4DISCOVERY
# STM32F745
# STM32F7X2
# STM32G47X
# STM32H723
# STM32H730
# STM32H743
# STM32H750
# to Emu:
# F3_TARGETS
# F405_TARGETS
# F411_TARGETS
# F446_TARGETS
# F7X2RE_TARGETS
# F7X5XG_TARGETS
# F7X6XG_TARGETS
# strictly notes / from inav
# F4_TARGETS = $(F405_TARGETS) $(F411_TARGETS) $(F446_TARGETS)
# F7_TARGETS = $(F7X2RE_TARGETS) $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) $(F7X6XG_TARGETS)
# strictly notes / from brainfpv
# 128K_TARGETS = $(F1_TARGETS)
# 256K_TARGETS = $(F3_TARGETS)
# 512K_TARGETS = $(F411_TARGETS) $(F7X2RE_TARGETS) $(F7X5XE_TARGETS) $(F446_TARGETS)
# 1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) $(F7X6XG_TARGETS)
# 2048K_TARGETS = $(F7X5XI_TARGETS)
# BF 4.5 generic TARGET_BOARD_IDENTIFIER ##
# AT32F435G #define TARGET_BOARD_IDENTIFIER "A435"
# AT32F435M #define TARGET_BOARD_IDENTIFIER "A435"
# STM32F405 #define TARGET_BOARD_IDENTIFIER "S405"
# STM32F411 #define TARGET_BOARD_IDENTIFIER "S411"
# STM32F446 #define TARGET_BOARD_IDENTIFIER "S446"
# STM32F745 #define TARGET_BOARD_IDENTIFIER "S745"
# STM32F7X2 #define TARGET_BOARD_IDENTIFIER "S7X2"
# STM32G47X #define TARGET_BOARD_IDENTIFIER "SG47"
# STM32H723 #define TARGET_BOARD_IDENTIFIER "SH72"
# STM32H725 #define TARGET_BOARD_IDENTIFIER "SH72"
# STM32H730 #define TARGET_BOARD_IDENTIFIER "S730"
# STM32H743 #define TARGET_BOARD_IDENTIFIER "SH74"
# STM32H750 #define TARGET_BOARD_IDENTIFIER "S750"
if [[ $(grep STM32F405 $config) ]]; then
echo 'F405_TARGETS += $(TARGET)' > ${mkFile}
TBID="S405"
elif [[ $(grep STM32F411 $config) ]]; then
echo 'F411_TARGETS += $(TARGET)' > ${mkFile}
TBID="S411"
elif [[ $(grep STM32F446 $config) ]]; then
echo 'F446_TARGETS += $(TARGET)' > ${mkFile}
TBID="S446"
elif [[ $(grep STM32F7X2 $config) ]]; then
echo 'F7X2RE_TARGETS += $(TARGET)' > ${mkFile}
TBID="S7X2"
elif [[ $(grep STM32F745 $config) ]]; then
echo 'F7X5XG_TARGETS += $(TARGET)' > ${mkFile}
TBID="S745"
else
echo ' - not an STM32F4 nor an STM32F7.'
echo ' - aborting.'
rm -r ${dest}
exit
fi
# enable flash and drivers
FEATURES='FEATURES += VCP '
if [[ $(grep SDCARD $config) ]]; then
FEATURES+='SDCARD'
else
FEATURES+='ONBOARDFLASH'
fi
echo "${FEATURES}" >> ${mkFile}
echo '' >> ${mkFile}
echo 'TARGET_SRC = \' >> ${mkFile}
# gyros
# EmuFlight supported
#define USE_GYRO_SPI_ICM20601
#define USE_GYRO_SPI_ICM20689
#define USE_GYRO_SPI_MPU6000
#define USE_GYRO_SPI_MPU6500 //physical ICM20602
#define USE_GYRO_SPI_MPU9250
# new
#define USE_GYRO_SPI_ICM42688P
#define USE_ACCGYRO_BMI270
# betaflight
#define USE_GYRO_SPI_ICM20602
#define USE_GYRO_SPI_ICM20689
#define USE_GYRO_SPI_ICM42605
#define USE_GYRO_SPI_ICM42688P
#define USE_GYRO_SPI_MPU6000
#define USE_GYRO_SPI_MPU6500
#define USE_GYRO_SPI_MPU9250
#define USE_ACCGYRO_BMI160
#define USE_ACCGYRO_BMI270
#define USE_ACCGYRO_LSM6DSO
# emuflight supported
# drivers/accgyro/accgyro_fake.c \
# drivers/accgyro/accgyro_imuf9001.c \
# drivers/accgyro/accgyro_mpu6050.c \
# drivers/accgyro/accgyro_mpu6500.c \
# drivers/accgyro/accgyro_mpu.c \
# drivers/accgyro/accgyro_spi_bmi160.c \
# drivers/accgyro/accgyro_spi_icm20689.c
# drivers/accgyro/accgyro_spi_icm426xx.c \
# drivers/accgyro/accgyro_spi_mpu6000.c \
# drivers/accgyro/accgyro_spi_mpu6500.c \
# drivers/accgyro/accgyro_spi_mpu9250.c \
# drivers/accgyro_legacy/accgyro_l3gd20.c \
# drivers/accgyro_legacy/accgyro_lsm303dlhc.c \
echo 'adding drivers'
translate USE_GYRO_SPI_MPU6000 ${config} 'drivers/accgyro/accgyro_spi_mpu6000.c \' ${mkFile}
translate USE_GYRO_SPI_MPU6500 ${config} 'drivers/accgyro/accgyro_mpu6500.c \' ${mkFile}
translate USE_GYRO_SPI_MPU6500 ${config} 'drivers/accgyro/accgyro_spi_mpu6500.c \' ${mkFile}
translate USE_GYRO_SPI_MPU9250 ${config} 'drivers/accgyro/accgyro_spi_mpu9250.c \' ${mkFile}
translate USE_GYRO_SPI_ICM20689 ${config} 'drivers/accgyro/accgyro_spi_icm20689.c \' ${mkFile}
translate USE_GYRO_SPI_ICM20601 ${config} 'drivers/accgyro/accgyro_spi_mpu6500.c \' ${mkFile} #ICM20601 is detected via MPU6500 drivers
translate USE_GYRO_SPI_ICM20602 ${config} 'drivers/accgyro/accgyro_spi_mpu6500.c \' ${mkFile} #ICM20602 is detected via MPU6500 drivers
translate USE_ACC_SPI_ICM426 ${config} 'drivers/accgyro/accgyro_spi_icm426xx.c \' ${mkFile}
translate USE_ACCGYRO_BMI270 ${config} 'drivers/accgyro/accgyro_spi_bmi270.c \' ${mkFile}
# skipping legacy, skipping 6050, skipping non-supported
# FrSky SPI
if [[ $(grep RX_SPI_FRSKY $config) ]] ; then
echo 'drivers/rx/rx_cc2500.c \' >> ${mkFile}
echo 'rx/cc2500_common.c \' >> ${mkFile}
echo 'rx/cc2500_frsky_shared.c \' >> ${mkFile}
echo 'rx/cc2500_frsky_d.c \' >> ${mkFile}
echo 'rx/cc2500_frsky_x.c \' >> ${mkFile}
echo 'rx/cc2500_redpine.c \' >> ${mkFile}
echo 'rx/cc2500_sfhss.c \' >> ${mkFile}
fi
# FlySky SPI
if [[ $(grep RX_SPI_A7105_FLYSKY_2A $config) ]] ; then
echo 'drivers/rx/rx_a7105.c \' >> ${mkFile}
echo 'rx/flysky.c \' >> ${mkFile}
fi
# barometers
# emuflight supported
# USE_BARO_BMP085
# USE_BARO_BMP280
# USE_BARO_DPS310
# USE_BARO_LPS
# USE_BARO_MS5611
# USE_BARO_QMP6988
# USE_BARO_SPI_BMP280
# USE_BARO_SPI_LPS
# USE_BARO_SPI_MS5611
# betaflight
# USE_BARO_BMP085
# USE_BARO_BMP280
# USE_BARO_BMP388
# USE_BARO_BPM085
# USE_BARO_BPM280
# USE_BARO_DPS310
# USE_BARO_LPS
# USE_BARO_MS5611
# USE_BARO_QMP6988
# USE_BARO_SPI_BMP280
# USE_BARO_SPI_DPS310
# USE_BARO_SPI_LPS
# emuflight supported
# drivers/barometer/barometer_bmp085.c
# drivers/barometer/barometer_bmp280.c
# drivers/barometer/barometer_fake.c
# drivers/barometer/barometer_lps.c
# drivers/barometer/barometer_ms5611.c
# drivers/barometer/barometer_qmp6988.c
translate USE_BARO_BMP085 ${config} 'drivers/barometer/barometer_bmp085.c \' ${mkFile}
translate USE_BARO_BMP280 ${config} 'drivers/barometer/barometer_bmp280.c \' ${mkFile}
translate USE_BARO_SPI_BMP280 ${config} 'drivers/barometer/barometer_bmp280.c \' ${mkFile}
translate USE_BARO_LPS ${config} 'drivers/barometer/barometer_lps.c \' ${mkFile}
translate USE_BARO_MS5611 ${config} 'drivers/barometer/barometer_ms5611.c \' ${mkFile}
translate USE_BARO_QMP6988 ${config} 'drivers/barometer/barometer_qmp6988.c \' ${mkFile}
# skipping non-supported
# emuflight src/main/target
# drivers/compass/compass_ak8963.c \
# drivers/compass/compass_ak8975.c \ # not used, afaict.
# drivers/compass/compass_hmc5883l.c \
# drivers/compass/compass_lis3mdl.c \
# drivers/compass/compass_qmc5883l.c \
# commenting out individual MAGs in favor of wildcard
#translate USE_MAG_SPI_AK8963 ${config} 'drivers/compass/compass_ak8963.c \' ${mkFile}
#translate USE_MAG_HMC5883 ${config} 'drivers/compass/compass_hmc5883l.c \' ${mkFile}
#translate USE_MAG_QMC5883 ${config} 'drivers/compass/compass_qmc5883l.c \' ${mkFile}
#translate USE_MAG_LIS3MDL ${config} 'drivers/compass/compass_lis3mdl.c \' ${mkFile}
if [[ $(grep MAG_ $config) ]] ; then
echo '$(addprefix drivers/compass/,$(notdir $(wildcard $(SRC_DIR)/drivers/compass/*.c))) \' >> ${mkFile}
fi
# skipping vtx 6705
echo 'skipping any VTX RTC6705; please manually modify target.mk if necessary.'
# drivers/vtx_rtc6705.c \
# drivers/vtx_rtc6705_soft_spi.c \
# led_strip
translate LED_STRIP ${config} 'drivers/light_led.h \' ${mkFile}
translate LED_STRIP ${config} 'drivers/light_ws2811strip.c \' ${mkFile}
# no good ? -- translate LED_STRIP ${config} 'drivers/light_ws2811strip_hal.c \' ${mkFile}
# pinio
translate PINIO ${config} 'drivers/pinio.c \' ${mkFile}
# OSD is final driver
echo 'drivers/max7456.c \' >> ${mkFile}
# all the baro/mag drivers in case external baro/mag
# echo 'drivers/barometer/barometer_fake.c \' >> ${mkFile}
# echo 'drivers/barometer/barometer_bmp085.c \' >> ${mkFile}
# echo 'drivers/barometer/barometer_bmp280.c \' >> ${mkFile}
# echo 'drivers/barometer/barometer_lps.c \' >> ${mkFile}
# echo 'drivers/barometer/barometer_ms5611.c \' >> ${mkFile}
# echo 'drivers/barometer/barometer_qmp6988.c \' >> ${mkFile}
# echo 'drivers/compass/compass_fake.c \' >> ${mkFile}
# echo 'drivers/compass/compass_ak8963.c \' >> ${mkFile}
# echo 'drivers/compass/compass_ak8975.c \' >> ${mkFile}
# echo 'drivers/compass/compass_hmc5883l.c \' >> ${mkFile}
# echo 'drivers/compass/compass_lis3mdl.c \' >> ${mkFile}
# echo 'drivers/compass/compass_qmc5883l.c \' >> ${mkFile}
echo '' >> ${mkFile}
echo '# notice - this file was programmatically generated and may be incomplete.' >> ${mkFile}
echo '# eg: flash, compass, barometer, vtx6705, ledstrip, pinio, etc. especially mag/baro' >> ${mkFile}
echo '' >> ${mkFile}
echo "# ${generatedMessage}" >> ${mkFile}
echo "# ${generatedSHA}" >> ${mkFile}
# create target.c file
echo "building ${cFile}"
echo "${license}" > ${cFile}
echo "// ${generatedMessage}" >> ${cFile}
echo "// ${generatedSHA}" >> ${cFile}
echo '' >> ${cFile}
echo '#include <stdint.h>' >> ${cFile}
echo '#include "platform.h"' >> ${cFile}
echo '#include "drivers/io.h"' >> ${cFile}
echo '#include "drivers/dma.h"' >> ${cFile}
echo '#include "drivers/timer.h"' >> ${cFile}
echo '#include "drivers/timer_def.h"' >> ${cFile}
echo '' >> ${cFile}
# DEF_TIM
echo 'building DEF_TIM'
pinArray=($(grep "TIM[0-9]* CH" $unified | awk -F' ' '{print $3}' | sed s/://)) #col 3 contains colon to be stripped
timerArray=($(grep "TIM[0-9]* CH" $unified | awk -F' ' '{print $4}'))
channelArray=($(grep "TIM[0-9]* CH" $unified | awk -F' ' '{print $5}'))
pinCount=${#pinArray[@]}
timerCount=${#timerArray[@]}
channelCount=${#channelArray[@]}
# debug to screen
#echo "pinCount: $pinCount"
echo "timerCount: $timerCount"
#echo "channelCount: $channelCount"
#tranlate pin syntax
for (( i = 0; i <= $pinCount-1; i++ ))
do
# specialized 0-trim
convertedPinArray[$i]="P$(echo ${pinArray[$i]} | sed -E 's/^([A-Z])0?([0-9]+)/\1\2/')"
# debug to screen
#echo "pin: ${pinArray[$i]} (${convertedPinArray[$i]}) timer: ${timerArray[$i]} channel: ${channelArray[$i]}"
done
convertedPinArray=("${convertedPinArray[@]}")
convertedPinCount=${#channelArray[@]}
# debug to screen
#echo "convertedPinCountCount: $convertedPinCount"
# debug to screen
# grep 'dma pin ' $unified
motorsArray=($(grep "resource MOTOR " $unified | awk -F' ' '{print $3}'))
motorsPINArray=($(grep "resource MOTOR " $unified | awk -F' ' '{print $4}'))
motorsCount=${#motorsArray[@]}
motorsPINCount=${#motorsPINArray[@]}
# debug to screen
echo "motorsCount: $motorsCount"
#echo "motorsPINCount: $motorsPINCount"
# EmuF TIM_USE_ options:
# TIM_USE_ANY
# TIM_USE_BEEPER
# TIM_USE_LED
# TIM_USE_MOTOR
# TIM_USE_NONE
# TIM_USE_PPM
# TIM_USE_PWM
# TIM_USE_SERVO
# TIM_USE_TRANSPONDER
# above was data reading, so now perform output
echo 'const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {' >> ${cFile}
for (( i = 1; i <= $motorsCount; i++ ))
do
echo "building DEF_TIM for motor $i : ${motorsPINArray[$i-1]}"
timer=""
channel=""
dma=""
for (( j = 0; j <= $pinCount-1; j++ )) ; do
# match motor pin/timer/chan/dma
# debug to screen
#echo "motor $i ${motorsPINArray[$i-1]} (${convertedPinArray[$j]})" #motors[0] is motorNumber1
#echo "${motorsPINArray[$i-1]} == ${pinArray[$j]} ?? >> ${timerArray[$j]} & ${channelArray[$j]}"
if [[ "${motorsPINArray[$i-1]}" == "${pinArray[$j]}" ]] ; then
# debug to screen
#echo "found ^"
timer="${timerArray[$j]}"
channel="${channelArray[$j]}"
dma=$(grep "dma pin ${motorsPINArray[$i-1]}" $unified | awk -F' ' '{print $4}')
if [ -z "$dma" ] ; then
echo ' - error: no associated dma value found. assuming 0. please repair if necessary.'
comment+='; dma 0 assumed, please verify'
dma="0"
fi
break # stop at motor ${j}
fi
done;
echo " DEF_TIM(${timer}, ${channel}, ${convertedPinArray[$j]}, TIM_USE_MOTOR, 0, ${dma}), // motor ${i}" >> ${cFile}
# debug to screen
#echo " DEF_TIM(${timer}, ${channel}, ${convertedPinArray[$j]}, TIM_USE_MOTOR, 0, ${dma}), // motor ${i}"
# remove pin $j (motor $i) we dont need it anymore (syntax: unset 'array[x]')
unset 'pinArray[j]'
unset 'timerArray[j]'
unset 'channelArray[j]'
unset 'convertedPinArray[j]'
done
#compact arrays after unsets / very important
pinArray=("${pinArray[@]}")
timerArray=("${timerArray[@]}")
channelArray=("${channelArray[@]}")
convertedPinArray=("${convertedPinArray[@]}")
#new array sizes
pinCount=${#pinArray[@]}
timerCount=${#timerArray[@]}
channelCount=${#channelArray[@]}
convertedPinCount=${#channelArray[@]}
# debug to screen
#echo "remaining pinCount: $pinCount"
echo "remaining timerCount: $timerCount"
#echo "remaining channelCount: $channelCount"
#echo "remaining convertedPinCountCount: $convertedPinCount"
# build remaining non-motor timers
for (( i = 0; i <= $pinCount-1; i++ ))
do
echo "building DEF_TIM for pin ${pinArray[$i]} (${convertedPinArray[$i]})"
timer="${timerArray[$i]}"
channel="${channelArray[$i]}"
dma=$(grep "dma pin ${pinArray[$i]}" $unified | awk -F' ' '{print $4}')
ppm=$(grep "${pinArray[$i]}" $unified | grep PPM)
led=$(grep "${pinArray[$i]}" $unified | grep LED)
cam=$(grep "${pinArray[$i]}" $unified | grep CAMERA)
baro=$(grep "${pinArray[$i]}" $unified | grep BARO)
pwm=$(grep "${pinArray[$i]}" $unified | grep PWM)
if [[ $ppm ]] ; then
timUse="TIM_USE_PPM"
comment="ppm $(grep -m 1 "PPM_PIN.*${convertedPinArray[$i]}" $config | awk -F' ' '{print $2}')"
elif [[ $led ]] ; then
timUse="TIM_USE_LED"
comment="led"
elif [[ $cam ]] ; then
timUse="TIM_USE_ANY"
comment="cam ctrl"
elif [[ $baro ]] ; then
timUse="TIM_USE_ANY"
comment="baro"
elif [[ $pwm ]] ; then
timUse="TIM_USE_PWM"
comment="pwm $(grep -m 1 "PWM[1-9]_PIN.*${convertedPinArray[$i]}" $config | awk -F' ' '{print $2}')"
else
timUse="TIM_USE_ANY"
comment="could not determine TIM_USE_xxxxx - please check"
fi
if [ -z "$dma" ] ; then
echo ' - error: no associated dma value found. assuming 0. please repair if necessary.'
comment+='; dma 0 assumed, please verify'
dma="0"
fi
echo " DEF_TIM(${timer}, ${channel}, ${convertedPinArray[$i]}, ${timUse}, 0, ${dma}), // ${comment}" >> ${cFile}
# debug to screen
#echo " DEF_TIM(${timer}, ${channel}, ${convertedPinArray[$i]}, ${timUse}, 0, ${dma}), // ${comment}"
done
echo '};' >> ${cFile}
echo '' >> ${cFile}
echo '// notice - DEF_TIM was programmatically generated and may be wrong or incomplete.' >> ${cFile}
echo '// please reference associated unified-target.' >> ${cFile}
echo '// some timers may associate with multiple pins. e.g baro/flash' >> ${cFile}
echo '' >> ${cFile}
echo '// notice - this file was programmatically generated and may be incomplete.' >> ${cFile}
# timers.txt file for quick reference
echo '// timers for target.c' > ${tFile}
echo '// format : DEF_TIM(TIMxx, CHx, Pxx, TIM_USE_xxxxxxx, 0, x), //comment' >> ${tFile}
echo '' >> ${tFile}
echo 'TIM_USE options:' >> ${tFile}
echo 'TIM_USE_ANY' >> ${tFile}
echo 'TIM_USE_BEEPER' >> ${tFile}
echo 'TIM_USE_LED' >> ${tFile}
echo 'TIM_USE_MOTOR' >> ${tFile}
echo 'TIM_USE_NONE' >> ${tFile}
echo 'TIM_USE_PPM' >> ${tFile}
echo 'TIM_USE_PWM' >> ${tFile}
echo 'TIM_USE_SERVO' >> ${tFile}
echo 'TIM_USE_TRANSPONDER' >> ${tFile}
echo '' >> ${tFile}
echo '// config.h timers' >> ${tFile}
grep "MOTOR[[:digit:]]\+_PIN" $config | xargs -d'\n' --replace echo "{}" >> ${tFile}
echo '' >> ${tFile}
grep TIMER_PIN_MAP $config | xargs -d'\n' --replace echo "{}" >> ${tFile}
echo '' >> ${tFile}
echo '// unified timers' >> ${tFile}
echo '# timer' >> ${tFile}
grep -A1 'timer ' $unified | xargs -d'\n' --replace echo "{}" >> ${tFile}
echo '' >> ${tFile}
grep -A1 'dma ADC ' $unified | xargs -d'\n' --replace echo "{}" >> ${tFile}
grep -A1 'dma pin ' $unified | xargs -d'\n' --replace echo "{}" >> ${tFile}
# create target.h file
echo "building ${hFile}"
echo "${license}" > ${hFile}
echo "// ${generatedMessage}" >> ${hFile}
echo "// ${generatedSHA}" >> ${hFile}
echo '' >> ${hFile}
echo '#pragma once' >> ${hFile}
echo '' >> ${hFile}
#translate MANUFACTURER_ID $config "#define TARGET_MANUFACTURER_IDENTIFIER \"$(grep MANUFACTURER_ID $config | awk '{print $3}')\"" ${hFile} #this should be proper but fails to be used
grep "BOARD_NAME" $config >> ${hFile}
grep "MANUFACTURER_ID" $config >> ${hFile}
#translate BOARD_NAME $config "#define USBD_PRODUCT_STRING \"$(grep BOARD_NAME $config | awk '{print $3}')\"" ${hFile} # not needed; this is only the string for the Computer's OS.
echo "#define TARGET_BOARD_IDENTIFIER \"${TBID}\" // generic ID" >> ${hFile} #required; this is essentially mcu-type or custom id
grep "define FC_TARGET_MCU" $config | sed 's/$/ \/\/ not used in EmuF/' >> ${hFile} # not used in EmuF
echo '' >> ${hFile}
# all the USE_ definitions - includes acc, gyro, flash, max, etc
echo "building USE_"
echo " - reference ./info/USE_.txt"
grep "define USE_" $config >> ${hFile}
if [[ $(grep USE_BARO $config) ]] ; then
echo '#define USE_BARO' >> ${hFile}
fi
echo '' >> ${hFile}
echo '#define USE_VCP' >> ${hFile}
if [[ $(grep USE_FLASH $config) ]] ; then
echo '#define USE_FLASHFS' >> ${hFile}
echo '#define USE_FLASH_M25P16 // 16MB Micron M25P16 driver; drives all unless QSPI' >> ${hFile}
echo '//#define USE_FLASH_W25M // 1Gb NAND flash support' >> ${hFile}
echo '//#define USE_FLASH_W25M512 // 16, 32, 64 or 128MB Winbond stacked die support' >> ${hFile}
echo '//#define USE_FLASH_W25Q // 512Kb (256Kb x 2 stacked) NOR flash support' >> ${hFile}
fi
if [[ $(grep USE_MAX7456 $config) ]] ; then
echo '#define USE_OSD' >> ${hFile}
fi
echo '' >> ${hFile}
# led
echo "building LED"
if [[ $(grep LED[0-9]_PIN $config) ]] ; then
echo '#define USE_LED' >> ${hFile}
fi
grep "LED[0-9]_PIN" $config >> ${hFile}
if [[ $(grep 'define[[:space:]\+]LED_STRIP_PIN' $config >> ${hFile}) ]] ; then
echo '#define USE_LED_STRIP' >> ${hFile}
fi
# beeper, cam-control, usb
echo "building beeper, cam, usb"
if [[ $(grep BEEPER_ $config) ]] ; then
echo '#define USE_BEEPER' >> ${hFile}
fi
grep 'define[[:space:]\+]BEEPER_PIN' $config >> ${hFile}
grep BEEPER_INVERTED $config >> ${hFile}
grep CAMERA_CONTROL_PIN $config >> ${hFile}
if [[ $(grep USB_DETECT_PIN $config) ]] ; then
echo '#define USE_USB_DETECT' >> ${hFile}
fi
echo '' >> ${hFile}
# spi
echo "building SPI"
if [[ $(grep SPI $config) ]] ; then
echo '#define USE_SPI' >> ${hFile}
fi
for i in {1..6}
do
if [[ $(grep "SPI${i}_" $config) ]] ; then
echo "#define USE_SPI_DEVICE_${i}" >> ${hFile}
fi
grep SPI${i}_SCK_PIN $config >> ${hFile}
translate SPI${i}_SDI_PIN $config "#define SPI${i}_MISO_PIN $(grep SPI${i}_SDI_PIN $config | awk '{print $3}')" ${hFile}
translate SPI${i}_SDO_PIN $config "#define SPI${i}_MOSI_PIN $(grep SPI${i}_SDO_PIN $config | awk '{print $3}')" ${hFile}
done
echo '' >> ${hFile}
# gyro defines
echo "building GYRO"
if [[ $(grep GYRO_SPI $config) ]] ; then
echo '#define USE_SPI_GYRO' >> $hFile
echo ' - defined USE_SPI_GYRO'
fi;
# exti
if [[ $(grep "GYRO_[1-2]_EXTI_PIN" $config) ]] ; then
echo '#define USE_EXTI' >> $hFile
echo '#define USE_GYRO_EXTI' >> $hFile
echo ' - defined USE_EXTI and USE_GYRO_EXTI'
echo '' >> ${hFile}
fi
# mpu
if [[ $(grep SPI_MPU $config) ]] ; then
echo '#define USE_MPU_DATA_READY_SIGNAL' >> ${hFile}
grep ENSURE_MPU_DATA_READY_IS_LOW $config >> ${hFile}
echo ' - defined MPU ready'
echo '' >> ${hFile}
fi
G1_csPin=$(grep -w GYRO_1_CS_PIN $config | awk -F' ' '{print $3}')
G1_extiPin=$(grep -w GYRO_1_EXTI_PIN $config | awk -F' ' '{print $3}')
G1_spi=$(grep -w GYRO_1_SPI_INSTANCE $config | awk -F' ' '{print $3}')
if [[ ! $(grep "GYRO_2_" $config) ]] ; then
if [[ $(grep GYRO_1_EXTI_PIN $config) ]] ; then
echo "#define MPU_INT_EXTI ${G1_extiPin}" >> $hFile
echo ' - defined MPU_INT_EXTI'
# gyro 2 will be gyro_2_, no need for another MPU_INT_EXTI
# echo '// notice - GYRO_1_EXTI_PIN and MPU_INT_EXTI may be used interchangeably; there is no other [gyroModel]_EXTI_PIN at this time. (ref: https://github.com/emuflight/EmuFlight/blob/master/src/main/sensors/gyro.c)' >> ${hFile}
echo '' >> ${hFile}
fi
fi
if [[ $(grep -w GYRO_1_ALIGN $config) ]] ; then
G1_align=$(grep -w GYRO_1_ALIGN $config | awk -F' ' '{print $3}')
else
G1_align='CW0_DEG' # default
fi
if [[ $(grep "GYRO_2_" $config) ]] ; then # only define GYRO_1 when GYRO_2 exists; will otherwise define actual GYRO
echo "#define ACC_1_ALIGN ${G1_align}" >> ${hFile}
echo "#define GYRO_1_ALIGN ${G1_align}" >> ${hFile}
grep GYRO_1_CS_PIN $config >> ${hFile}
grep GYRO_1_EXTI_PIN $config >> ${hFile}
grep GYRO_1_SPI_INSTANCE $config >> ${hFile}
echo ' - defined GYRO_1'
echo '' >> ${hFile}
fi
# dual gyro
if [[ $(grep "GYRO_2_" $config) ]] ; then
echo '#define USE_DUAL_GYRO' >> ${hFile}
echo '' >> ${hFile}
fi
if [[ $(grep "GYRO_2_" $config) ]] ; then
translate "DEFAULT_GYRO_TO_USE" $config "#define GYRO_CONFIG_USE_GYRO_DEFAULT $(grep "DEFAULT_GYRO_TO_USE" $config | awk '{print $3}')" ${hFile}
fi
if [[ $(grep -w GYRO_2_ALIGN $config) ]] ; then
G2_align=$(grep -w GYRO_2_ALIGN $config | awk -F' ' '{print $3}')
elif [[ $(grep GYRO_2 $config) ]] ; then
G2_align='CW0_DEG' # default
fi
if [[ $(grep "GYRO_2_" $config) ]] ; then
echo "#define ACC_2_ALIGN ${G2_align}" >> ${hFile}
echo "#define GYRO_2_ALIGN ${G2_align}" >> ${hFile}
grep GYRO_2_CS_PIN $config >> ${hFile}
grep GYRO_2_EXTI_PIN $config >> ${hFile}
grep GYRO_2_SPI_INSTANCE $config >> ${hFile}
echo ' - defined GYRO_2'
echo '' >> ${hFile}
else #individual gyro/all defines
#MPU9250
#define USE_GYRO_SPI_MPU9250
#define USE_ACC_SPI_MPU9250
if [[ $(grep SPI_MPU9250 $config) ]] ; then
# convert gyro1 > mpu -- this may need changing later
if [[ $(grep GYRO_1_SPI_INSTANCE $config) ]] ; then
echo "#define ACC_MPU9250_ALIGN ${G1_align}" >> $hFile
echo "#define GYRO_MPU9250_ALIGN ${G1_align}" >> $hFile
echo "#define MPU9250_CS_PIN ${G1_csPin}" >> $hFile
echo "#define MPU9250_SPI_INSTANCE ${G1_spi}" >> $hFile
echo ' - defined MPU9250'
fi
echo '' >> ${hFile}
fi
# MPU6000
#define USE_ACC_SPI_MPU6000
#define USE_GYRO_SPI_MPU6000
if [[ $(grep SPI_MPU6000 $config) ]] ; then
# convert gyro1 > mpu -- this may need changing later
if [[ $(grep GYRO_1_SPI_INSTANCE $config) ]] ; then
echo "#define ACC_MPU6000_ALIGN ${G1_align}" >> $hFile
echo "#define GYRO_MPU6000_ALIGN ${G1_align}" >> $hFile
echo "#define MPU6000_CS_PIN ${G1_csPin}" >> $hFile
echo "#define MPU6000_SPI_INSTANCE ${G1_spi}" >> $hFile
echo ' - defined MPU6000'
fi
echo '' >> ${hFile}
fi
# MPU6500 / ICM2060x
#define USE_ACC_SPI_MPU6500
#define USE_GYRO_SPI_MPU6500
#define USE_ACC_SPI_ICM20601
#define USE_GYRO_SPI_ICM20601
#define USE_ACC_SPI_ICM20602
#define USE_GYRO_SPI_ICM20602
if [[ $(grep SPI_MPU6500 $config) ]] || [[ $(grep SPI_ICM2060[1-2] $config) ]] ; then
if [[ $(grep SPI_ICM2060[1-2] $config) ]] ; then
echo "// ICM2060x detected by MPU6500 driver" >> $hFile
fi;
# convert gyro1 > mpu -- this may need changing later
if [[ $(grep GYRO_1_SPI_INSTANCE $config) ]] ; then
echo "#define ACC_MPU6500_ALIGN ${G1_align}" >> $hFile
echo "#define GYRO_MPU6500_ALIGN ${G1_align}" >> $hFile
echo "#define MPU6500_CS_PIN ${G1_csPin}" >> $hFile
echo "#define MPU6500_SPI_INSTANCE ${G1_spi}" >> $hFile
echo ' - defined MPU6500 (maybe ICM2060x)'
fi
echo '' >> ${hFile}
fi
# ICM20689
#define USE_ACC_SPI_ICM20689
#define USE_GYRO_SPI_ICM20689
if [[ $(grep SPI_ICM20689 $config) ]] ; then
# convert gyro1 > icm -- this may need changing later
if [[ $(grep GYRO_1_SPI_INSTANCE $config) ]] ; then
echo "#define ACC_ICM20689_ALIGN ${G1_align}" >> $hFile
echo "#define GYRO_ICM20689_ALIGN ${G1_align}" >> $hFile
echo "#define ICM20689_CS_PIN ${G1_csPin}" >> $hFile
echo "#define ICM20689_SPI_INSTANCE ${G1_spi}" >> $hFile
echo ' - defined ICM20689'
fi
echo '' >> ${hFile}
fi
# ICM42688P
#define USE_GYRO_SPI_ICM42688P
#define USE_ACC_SPI_ICM42688P
if [[ $(grep SPI_ICM42688P $config) ]] ; then
# convert gyro1 > icm -- this may need changing later
if [[ $(grep GYRO_1_SPI_INSTANCE $config) ]] ; then
echo "#define ACC_ICM42688P_ALIGN ${G1_align}" >> $hFile
echo "#define GYRO_ICM42688P_ALIGN ${G1_align}" >> $hFile
echo "#define ICM42688P_CS_PIN ${G1_csPin}" >> $hFile
echo "#define ICM42688P_SPI_INSTANCE ${G1_spi}" >> $hFile
echo ' - defined ICM42688P'
fi
echo '' >> ${hFile}
fi
# BMI270
#define USE_ACCGYRO_BMI270
#define USE_SPI_GYRO
if [[ $(grep ACCGYRO_BMI270 $config) ]] ; then
# convert gyro1 > icm -- this may need changing later
echo '#define USE_SPI_GYRO' >> $hFile
if [[ $(grep GYRO_1_SPI_INSTANCE $config) ]] ; then
echo "#define ACC_BMI270_ALIGN ${G1_align}" >> $hFile
echo "#define GYRO_BMI270_ALIGN ${G1_align}" >> $hFile
echo "#define BMI270_CS_PIN ${G1_csPin}" >> $hFile
echo "#define BMI270_SPI_INSTANCE ${G1_spi}" >> $hFile
echo ' - defined BMI270'
fi
echo '' >> ${hFile}
fi
fi
## vcp, uarts, softserial
echo "building UART(RX/TX), VCP, and serial-count"
vcpserial=1
hardserial=0
for ((i=1; i<=10; i++)) #only seen 8 in EmuF, saw 10 in BF
do
if [[ $(grep "UART${i}_[TR]X_PIN" $config) ]] ; then
echo "#define USE_UART${i}" >> ${hFile}
grep "define[[:space:]\+]UART${i}_[TR]X_PIN" $config >> ${hFile}
((hardserial++))
fi
done
softserial=0
for ((i=1; i<=2; i++)) # only seen 2 in both EmuF and BF
do
if [[ $(grep "SOFTSERIAL${i}_[TR]X_PIN" $config) ]] ; then
echo "#define USE_SOFTSERIAL${i}" >> ${hFile}
grep "SOFTSERIAL${i}_[TR]X_PIN" $config >> ${hFile}
((softserial++))
fi
done
# RX_PPM_PIN not used in EmuF; (ref: https://github.com/emuflight/EmuFlight/blob/master/src/main/pg/rx_pwm.c)
#grep 'RX_PPM_PIN' $config | sed 's/^/\/\//' | sed 's/$/ \/\/ not used in EmuF/'
grep "INVERTER_PIN_UART" $config >> ${hFile}
grep "USART" $config >> ${hFile}
totalserial=$(expr $hardserial + $softserial)
echo "#define SERIAL_PORT_COUNT $(expr $vcpserial + $totalserial)" >> ${hFile}
echo '// notice - UART/USART were programmatically generated - please verify UART/USART.' >> ${hFile}
echo '// notice - may need "#define SERIALRX_UART SERIAL_PORT_USART_"' >> ${hFile}
echo '// notice - for any iterim non-defined TX/RX _PIN, may need to define as NONE and also include any USE_UARTx involved.' >> ${hFile}
echo '// notice - please verify serial count. VCP+UARTs+SOFTSERIALs (uncertain about skipped UARTs and USARTs)' >> ${hFile}
echo '' >> ${hFile}
# BF config.h:
# USE_RX_SPI
# RX_SPI_BIND
# RX_SPI_BIND_PIN
# RX_SPI_CC2500_ANT_SEL_PIN
# RX_SPI_CC2500_LNA_EN_PIN
# RX_SPI_CC2500_TX_EN_PIN
# RX_SPI_CS
# RX_SPI_CS_PIN
# RX_SPI_DEFAULT_PROTOCOL
# RX_SPI_EXPRESSLRS_BUSY_PIN
# RX_SPI_EXPRESSLRS_RESET_PIN
# RX_SPI_EXTI
# RX_SPI_EXTI_PIN
# RX_SPI_INSTANCE
# RX_SPI_LED
# RX_SPI_LED_INVERTED
# RX_SPI_LED_PIN
# RX_SPI_PROTOCOL
#
# to EmuF:
# USE_RX_SPI
# USE_RX_FLYSKY
# USE_RX_FLYSKY_SPI_LED
# USE_RX_FRSKY_SPI
# USE_RX_FRSKY_SPI_D
# USE_RX_FRSKY_SPI_TELEMETRY
# USE_RX_FRSKY_SPI_X
# BINDPLUG_PIN
# DMA_SPI_RX_DMA_CHANNEL
# DMA_SPI_RX_DMA_FLAG_ALL
# DMA_SPI_RX_DMA_FLAG_GL
# DMA_SPI_RX_DMA_FLAG_TC
# DMA_SPI_RX_DMA_HANDLER
# DMA_SPI_RX_DMA_IRQn
# DMA_SPI_RX_DMA_STREAM
# RX_CC2500_SPI_ANT_SEL_PIN
# RX_CC2500_SPI_GDO_0_PIN
# RX_CC2500_SPI_LED_PIN
# RX_CC2500_SPI_LNA_EN_PIN
# RX_CC2500_SPI_TX_EN_PIN
# RX_FLYSKY_SPI_LED_PIN
# RX_FRSKY_SPI_LED_PIN_INVERTED
# RX_NSS_PIN
# RX_SPI_DEFAULT_PROTOCOL
# RX_SPI_INSTANCE
# RX_SPI_LED_PIN
# SPI1_NSS_PIN
# SPI2_NSS_PIN
# SPI3_NSS_PIN
# SPI4_NSS_PIN
# SPI5_NSS_PIN
# SPI_RX_CS_PIN
# RX SPI vs SERIAL
if [[ $(grep 'RX_SPI_' $config) ]] ; then
featureRX='FEATURE_RX_SPI'
if [[ $(grep 'RX_SPI_FRSKY_X' $config) ]] ; then
echo '#define RX_SPI_DEFAULT_PROTOCOL RX_SPI_FRSKY_X' >> ${hFile}
fi
if [[ $(grep 'RX_SPI_FRSKY_D' $config) ]] ; then
echo '#define RX_SPI_DEFAULT_PROTOCOL RX_SPI_FRSKY_D' >> ${hFile}
fi
grep 'RX_SPI_' $config >> ${hFile}
grep 'RX_CC2500_SPI_' $config >> ${hFile}
sed -i 's/RX_SPI_CC2500_/RX_CC2500_SPI_/g' ${hFile} #translate the transposed defines
translate 'RX_SPI_BIND_PIN' $config "#define BINDPLUG_PIN $(grep 'RX_SPI_BIND_PIN' $config | awk -F' ' '{print $3}' )" ${hFile}
grep 'USE_RX_FRSKY_SPI_TELEMETRY' $config >> ${hFile}
grep 'USE_TELEMETRY_FRSKY_HUB' $config >> ${hFile}
grep 'RX_FRSKY_SPI_LED_PIN_INVERTED' $config >> ${hFile}
if [[ $(grep 'RX_SPI_A7105_FLYSKY_2A' $config) ]] ; then
echo '#define USE_RX_FLYSKY' >> ${hFile}
echo '#define RX_SPI_DEFAULT_PROTOCOL RX_SPI_A7105_FLYSKY_2A' >> ${hFile}
fi
echo 'skipping some SPI based RX. please define all RX_SPI_ manually; too complex for automation; ELRS not supported by EmuFlight.'
echo '// notice - please manually add all SPI based receiver definitions. complexity for these is currently beyond scope of automation.' >> ${hFile}
echo '// e.g. USE_RX_CC2500_*, RX_CC2500_SPI_*' >> ${hFile}
echo '// e.g. FLYSKY_2A_CHANNEL_COUNT, USE_RX_FLYSKY_SPI_LED, RX_FLYSKY_SPI_LED_PIN' >> ${hFile}
echo '' >> ${hFile}
else
featureRX='FEATURE_RX_SERIAL'
fi
# i2c/baro/mag/etc
echo 'building I2C (BARO, MAG, etc)'
echo ' - not all baro are supported by EmuFlight'
echo ' - BARO/MAG likely incomplete - please inspect and rectify.'
# BARO
# EmuF
#define DEFAULT_BARO_BMP280
#define DEFAULT_BARO_QMP6988
#define DEFAULT_BARO_SPI_BMP280
#define DEFAULT_BARO_SPI_LPS
# BF
#define DEFAULT_BARO_DEVICE BARO_BMP280
#define DEFAULT_BARO_DEVICE BARO_NONE
#in BF config.h
#define DEFAULT_BARO_DEVICE _____
#define DEFAULT_BARO_I2C_ADDRESS xxx
#BARO_CS_PIN
#BARO_I2C_INSTANCE #would be duplicated by grep I2CDEV_${i}
grep BARO_CS_PIN $config >> ${hFile}
grep BARO_SPI_INSTANCE $config >> ${hFile}
if [[ $(grep USE_BARO_.*BMP280 $config) ]] && [[ $(grep BARO_CS_PIN $config) ]] ; then
BARO_CS=$(grep -w BARO_CS_PIN $config | awk -F' ' '{print $3}')
BARO_SPI=$(grep -w BARO_SPI_INSTANCE $config | awk -F' ' '{print $3}')
echo "#define BMP280_CS_PIN ${BARO_CS}" >> ${hFile}
echo "#define BMP280_SPI_INSTANCE ${BARO_SPI}" >> ${hFile}
fi
# MAG
#USE_MAG_SPI_AK8963
#USE_MAG_AK8975
#USE_MAG_HMC5883
#USE_MAG_QMC5883
#USE_MAG_LIS3MDL
#MAG_HMC5883_ALIGN
#MAG_QMC5883L_ALIGN
#MAG_AK8975_ALIGN
#MAG_AK8963_ALIGN
#HMC5883_SPI_INSTANCE