From 6b973d4c4f06fabfbb9bb85008f22fcb25a61d62 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:02:38 +0100 Subject: [PATCH 1/3] Handle ICM42688P gyro --- src/utils/bf2inav.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/utils/bf2inav.py b/src/utils/bf2inav.py index 3d8b31a2e55..ecd0fdf39b8 100755 --- a/src/utils/bf2inav.py +++ b/src/utils/bf2inav.py @@ -1,5 +1,3 @@ -#!/usr/bin/python3 -# Betaflight unified config to INAV target converter # # This script can be used to Generate a basic working target from a Betaflight Configuration. # The idea is that this target can be used as a starting point for full INAV target. @@ -29,7 +27,7 @@ def translateFunctionName(bffunction, index): return bffunction + '_' + index def translatePin(bfpin): - pin = re.sub("^([A-Z])0*(\d+)$", r'P\1\2', bfpin) + pin = re.sub(r'^([A-Z])0*(\d+)$', r'P\1\2', bfpin) return pin def mcu2target(mcu): @@ -157,7 +155,7 @@ def writeCmakeLists(outputFolder, map): def findPinsByFunction(function, map): result = [] for func in map['funcs']: - pattern = "^%s" % (function) + pattern = r"^%s" % (function) if re.search(pattern, func): #print ("%s: %s" % (function, func)) result.append(map['funcs'][func]) @@ -180,7 +178,7 @@ def getPwmOutputCount(map): def getGyroAlign(map): bfalign = map['defines'].get('GYRO_1_ALIGN', 'CW0_DEG') return bfalign - #m = re.search("^CW(\d+)(FLIP)?$", bfalign) + #m = re.search(r"^CW(\d+)(FLIP)?$", bfalign) #if m: # deg = m.group(1) # flip = m.group(2) @@ -436,7 +434,7 @@ def writeTargetH(folder, map): file.write("#define USE_BARO\n") if 'BARO_I2C_INSTANCE' in map['defines']: file.write("#define USE_BARO_ALL\n") - m = re.search('I2CDEV_(\d+)', map['defines']['BARO_I2C_INSTANCE']) + m = re.search(r'I2CDEV_(\d+)', map['defines']['BARO_I2C_INSTANCE']) if m: file.write("#define BARO_I2C_BUS BUS_I2C%s\n" % (m.group(1))) if 'BARO_SPI_INSTANCE' in map['defines']: @@ -767,9 +765,9 @@ def buildMap(inputFile): m = re.search(r'^#define\s+(\w+)\s*$', l) if m: - map['empty_defines'].append(m.group(1)) + map['empty_defines'].append(re.sub('ICM42688P', 'ICM42605', m.group(1))) - m = re.search('^\s*#define\s+DEFAULT_FEATURES\s+\((.+?)\)\s*$', l) + m = re.search(r'^\s*#define\s+DEFAULT_FEATURES\s+\((.+?)\)\s*$', l) if m: features = m.group(1).split('|') for feat in features: @@ -799,7 +797,7 @@ def buildMap(inputFile): } - m = re.search('^\s*#define\s+(\w+)_PIN\s+([A-Z0-9]+)\s*$', l) + m = re.search(r'^\s*#define\s+(\w+)_PIN\s+([A-Z0-9]+)\s*$', l) if m: pin = m.group(2) func = m.group(1) From 5c54dbe6f8f4a3847aefbbafe6cc956ec4f5f39d Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:33:35 +0100 Subject: [PATCH 2/3] Fix MISO / MOSI swap --- src/utils/bf2inav.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/bf2inav.py b/src/utils/bf2inav.py index ecd0fdf39b8..ac5e3785f34 100755 --- a/src/utils/bf2inav.py +++ b/src/utils/bf2inav.py @@ -343,9 +343,9 @@ def writeTargetH(folder, map): if sckpin: file.write("#define SPI%i_SCK_PIN %s\n" % (i, sckpin)) if misopin: - file.write("#define SPI%i_MISO_PIN %s\n" % (i, misopin)) + file.write("#define SPI%i_MOSI_PIN %s\n" % (i, misopin)) if mosipin: - file.write("#define SPI%i_MOSI_PIN %s\n" % (i, mosipin)) + file.write("#define SPI%i_MISO_PIN %s\n" % (i, mosipin)) use_i2c_defined = False for i in range(1, 9): From 85b4a828d4c8f806f12f5bb8c64c47351e47b359 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:40:20 +0100 Subject: [PATCH 3/3] fix mosi/miso trad icm42688p as icm42605 --- src/utils/bf2inav.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/bf2inav.py b/src/utils/bf2inav.py index ac5e3785f34..aaf6ad22157 100755 --- a/src/utils/bf2inav.py +++ b/src/utils/bf2inav.py @@ -332,8 +332,8 @@ def writeTargetH(folder, map): use_spi_defined = False for i in range(1, 9): sckpin = findPinByFunction("SPI%i_SCK" % (i), map) - misopin = findPinByFunction("SPI%i_SDO" % (i), map) - mosipin = findPinByFunction("SPI%i_SDI" % (i), map) + misopin = findPinByFunction("SPI%i_SDI" % (i), map) + mosipin = findPinByFunction("SPI%i_SDO" % (i), map) if (sckpin or misopin or mosipin): if (not use_spi_defined): use_spi_defined = True @@ -343,9 +343,9 @@ def writeTargetH(folder, map): if sckpin: file.write("#define SPI%i_SCK_PIN %s\n" % (i, sckpin)) if misopin: - file.write("#define SPI%i_MOSI_PIN %s\n" % (i, misopin)) + file.write("#define SPI%i_MISO_PIN %s\n" % (i, misopin)) if mosipin: - file.write("#define SPI%i_MISO_PIN %s\n" % (i, mosipin)) + file.write("#define SPI%i_MOSI_PIN %s\n" % (i, mosipin)) use_i2c_defined = False for i in range(1, 9):