HAL_ChibiOS: support I2C sensor config in hwdef.dat

This commit is contained in:
Andrew Tridgell 2019-05-30 09:20:32 +10:00
parent 4c5b651296
commit b47ab5c8a9
1 changed files with 14 additions and 1 deletions

View File

@ -767,8 +767,19 @@ def write_SPI_config(f):
def parse_spi_device(dev):
'''parse a SPI:xxx device item'''
a = dev.split(':')
if len(a) != 2:
error("Bad SPI device: %s" % dev)
return 'hal.spi->get_device("%s")' % a[1]
def parse_i2c_device(dev):
'''parse a I2C:xxx:xxx device item'''
a = dev.split(':')
if len(a) != 3:
error("Bad I2C device: %s" % dev)
busnum = int(a[1])
busaddr = int(a[2],base=0)
return 'hal.i2c_mgr->get_device(%u,0x%02x)' % (busnum, busaddr)
def write_IMU_config(f):
'''write IMU config defines'''
global imu_list
@ -826,10 +837,12 @@ def write_BARO_config(f):
dev[i] = parse_spi_device(dev[i])
elif dev[i].startswith("I2C:"):
dev[i] = parse_i2c_device(dev[i])
if dev[i].startswith('hal.i2c_mgr'):
dev[i] = 'std::move(%s)' % dev[i]
n = len(devlist)+1
devlist.append('HAL_BARO_PROBE%u' % n)
f.write(
'#define HAL_BARO_PROBE%u ADD_BACKEND(AP_Baro_%s::%s(*this, std::move(%s)))\n'
'#define HAL_BARO_PROBE%u ADD_BACKEND(AP_Baro_%s::%s(*this,%s))\n'
% (n, driver, probe, ','.join(dev[1:])))
f.write('#define HAL_BARO_PROBE_LIST %s\n\n' % ';'.join(devlist))