AP_HAL: move parsing of BARO lines up to AP_HAL hwdef.py

This commit is contained in:
Peter Barker 2025-02-21 21:05:31 +11:00 committed by Peter Barker
parent b9ad86943d
commit 34735b30df
2 changed files with 35 additions and 1 deletions

View File

@ -26,7 +26,6 @@
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NONE
// nothing to do here
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD
#define HAL_BARO_PROBE_LIST PROBE_BARO_SPI(MS56XX, "ms5611")
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
#define HAL_BARO_PROBE_LIST PROBE_BARO_I2C(MS56XX, 1, 0x77, AP_Baro_MS56XX::BARO_MS5607)
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_VNAV

View File

@ -44,6 +44,7 @@ class HWDef:
# sensor lists
self.imu_list = []
self.compass_list = []
self.baro_list = []
def is_int(self, str):
'''check if a string is an integer'''
@ -204,6 +205,9 @@ class HWDef:
elif a[0] == 'COMPASS':
self.compass_list.append(a[1:])
elif a[0] == 'BARO':
self.baro_list.append(a[1:])
def process_line_undef(self, line, depth, a):
for u in a[1:]:
self.progress("Removing %s" % u)
@ -217,6 +221,8 @@ class HWDef:
self.imu_list = []
if u == 'COMPASS':
self.compass_list = []
if u == 'BARO':
self.baro_list = []
def process_line_env(self, line, depth, a):
self.progress("Adding environment %s" % ' '.join(a[1:]))
@ -340,3 +346,32 @@ class HWDef:
% (n, wrapper, driver, driver, probe, ','.join(dev[1:])))
if len(devlist) > 0:
f.write('#define HAL_MAG_PROBE_LIST %s\n\n' % ';'.join(devlist))
def write_BARO_config(self, f):
'''write barometer config defines'''
devlist = []
seen = set()
for dev in self.baro_list:
if self.seen_str(dev) in seen:
self.error("Duplicate BARO: %s" % self.seen_str(dev))
seen.add(self.seen_str(dev))
driver = dev[0]
probe = 'probe'
wrapper = ''
a = driver.split(':')
driver = a[0]
if len(a) > 1 and a[1].startswith('probe'):
probe = a[1]
for i in range(1, len(dev)):
if dev[i].startswith("SPI:"):
dev[i] = self.parse_spi_device(dev[i])
elif dev[i].startswith("I2C:"):
(wrapper, dev[i]) = self.parse_i2c_device(dev[i])
n = len(devlist)+1
devlist.append('HAL_BARO_PROBE%u' % n)
args = ['*this'] + dev[1:]
f.write(
'#define HAL_BARO_PROBE%u %s ADD_BACKEND(AP_Baro_%s::%s(%s))\n'
% (n, wrapper, driver, probe, ','.join(args)))
if len(devlist) > 0:
f.write('#define HAL_BARO_PROBE_LIST %s\n\n' % ';'.join(devlist))