HAL_ChibiOS: prevent duplicate sensors in hwdef.dat

throw an error on configure if there is a duplicate
This commit is contained in:
Andrew Tridgell 2019-09-04 21:23:05 +10:00
parent 2c5c8106a5
commit b344946300

View File

@ -797,12 +797,20 @@ def parse_i2c_device(dev):
busnum = int(a[1]) busnum = int(a[1])
return ('', 'GET_I2C_DEVICE(%u,0x%02x)' % (busnum, busaddr)) return ('', 'GET_I2C_DEVICE(%u,0x%02x)' % (busnum, busaddr))
def seen_str(dev):
'''return string representation of device for checking for duplicates'''
return str(dev[:2])
def write_IMU_config(f): def write_IMU_config(f):
'''write IMU config defines''' '''write IMU config defines'''
global imu_list global imu_list
devlist = [] devlist = []
wrapper = '' wrapper = ''
seen = set()
for dev in imu_list: for dev in imu_list:
if seen_str(dev) in seen:
error("Duplicate IMU: %s" % seen_str(dev))
seen.add(seen_str(dev))
driver = dev[0] driver = dev[0]
for i in range(1,len(dev)): for i in range(1,len(dev)):
if dev[i].startswith("SPI:"): if dev[i].startswith("SPI:"):
@ -818,10 +826,14 @@ def write_IMU_config(f):
f.write('#define HAL_INS_PROBE_LIST %s\n\n' % ';'.join(devlist)) f.write('#define HAL_INS_PROBE_LIST %s\n\n' % ';'.join(devlist))
def write_MAG_config(f): def write_MAG_config(f):
'''write IMU config defines''' '''write MAG config defines'''
global compass_list global compass_list
devlist = [] devlist = []
seen = set()
for dev in compass_list: for dev in compass_list:
if seen_str(dev) in seen:
error("Duplicate MAG: %s" % seen_str(dev))
seen.add(seen_str(dev))
driver = dev[0] driver = dev[0]
probe = 'probe' probe = 'probe'
wrapper = '' wrapper = ''
@ -846,7 +858,11 @@ def write_BARO_config(f):
'''write barometer config defines''' '''write barometer config defines'''
global baro_list global baro_list
devlist = [] devlist = []
seen = set()
for dev in baro_list: for dev in baro_list:
if seen_str(dev) in seen:
error("Duplicate BARO: %s" % seen_str(dev))
seen.add(seen_str(dev))
driver = dev[0] driver = dev[0]
probe = 'probe' probe = 'probe'
wrapper = '' wrapper = ''