hwdef: added BOARD_MATCH() support for IMUs

allow hwdef.dat to specify list of IMUs which match a specific board
type
This commit is contained in:
Andrew Tridgell 2022-07-19 08:32:13 +10:00 committed by Randy Mackay
parent dc3a215214
commit 9755f5bf7b

View File

@ -1408,8 +1408,10 @@ def parse_i2c_device(dev):
def seen_str(dev):
'''return string representation of device for checking for duplicates'''
return str(dev[:2])
ret = dev[:2]
if dev[-1].startswith("BOARD_MATCH("):
ret.append(dev[-1])
return str(ret)
def write_IMU_config(f):
'''write IMU config defines'''
@ -1429,9 +1431,14 @@ def write_IMU_config(f):
(wrapper, dev[i]) = parse_i2c_device(dev[i])
n = len(devlist)+1
devlist.append('HAL_INS_PROBE%u' % n)
f.write(
'#define HAL_INS_PROBE%u %s ADD_BACKEND(AP_InertialSensor_%s::probe(*this,%s))\n'
% (n, wrapper, driver, ','.join(dev[1:])))
if dev[-1].startswith("BOARD_MATCH("):
f.write(
'#define HAL_INS_PROBE%u %s ADD_BACKEND_BOARD_MATCH(%s, AP_InertialSensor_%s::probe(*this,%s))\n'
% (n, wrapper, dev[-1], driver, ','.join(dev[1:-1])))
else:
f.write(
'#define HAL_INS_PROBE%u %s ADD_BACKEND(AP_InertialSensor_%s::probe(*this,%s))\n'
% (n, wrapper, driver, ','.join(dev[1:])))
if len(devlist) > 0:
if len(devlist) < 3:
f.write('#define INS_MAX_INSTANCES %u\n' % len(devlist))