From 4fcf70aa5ca36a9d7212d7cdc8b9b5b704ea6924 Mon Sep 17 00:00:00 2001 From: Ray Morris Date: Sun, 9 Jul 2023 18:33:06 -0500 Subject: [PATCH 1/8] Extend from 4 ADC channels to 6 (Matek H743 and others) --- src/main/drivers/adc.c | 38 ++++++++++++++++++++++++++++++++-- src/main/drivers/adc.h | 4 +++- src/main/drivers/pwm_mapping.c | 10 +++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/main/drivers/adc.c b/src/main/drivers/adc.c index eeb65acfab9..679723e0a83 100644 --- a/src/main/drivers/adc.c +++ b/src/main/drivers/adc.c @@ -47,6 +47,13 @@ #ifndef ADC_CHANNEL_4_INSTANCE #define ADC_CHANNEL_4_INSTANCE ADC_INSTANCE #endif +#ifndef ADC_CHANNEL_5_INSTANCE +#define ADC_CHANNEL_5_INSTANCE ADC_INSTANCE +#endif +#ifndef ADC_CHANNEL_6_INSTANCE +#define ADC_CHANNEL_6_INSTANCE ADC_INSTANCE +#endif + #ifdef USE_ADC @@ -99,7 +106,7 @@ uint16_t adcGetChannel(uint8_t function) } } -#if defined(ADC_CHANNEL_1_PIN) || defined(ADC_CHANNEL_2_PIN) || defined(ADC_CHANNEL_3_PIN) || defined(ADC_CHANNEL_4_PIN) +#if defined(ADC_CHANNEL_1_PIN) || defined(ADC_CHANNEL_2_PIN) || defined(ADC_CHANNEL_3_PIN) || defined(ADC_CHANNEL_4_PIN) || defined(ADC_CHANNEL_5_PIN) || defined(ADC_CHANNEL_6_PIN) static bool isChannelInUse(int channel) { for (int i = 0; i < ADC_FUNCTION_COUNT; i++) { @@ -111,7 +118,7 @@ static bool isChannelInUse(int channel) } #endif -#if !defined(ADC_CHANNEL_1_PIN) || !defined(ADC_CHANNEL_2_PIN) || !defined(ADC_CHANNEL_3_PIN) || !defined(ADC_CHANNEL_4_PIN) +#if !defined(ADC_CHANNEL_1_PIN) || !defined(ADC_CHANNEL_2_PIN) || !defined(ADC_CHANNEL_3_PIN) || !defined(ADC_CHANNEL_4_PIN) || !defined(ADC_CHANNEL_5_PIN) || !defined(ADC_CHANNEL_6_PIN) static void disableChannelMapping(int channel) { for (int i = 0; i < ADC_FUNCTION_COUNT; i++) { @@ -192,6 +199,33 @@ void adcInit(drv_adc_config_t *init) disableChannelMapping(ADC_CHN_4); #endif +#ifdef ADC_CHANNEL_5_PIN + if (isChannelInUse(ADC_CHN_5)) { + adcConfig[ADC_CHN_5].adcDevice = adcDeviceByInstance(ADC_CHANNEL_5_INSTANCE); + if (adcConfig[ADC_CHN_5].adcDevice != ADCINVALID) { + adcConfig[ADC_CHN_5].tag = IO_TAG(ADC_CHANNEL_5_PIN); +#if defined(USE_ADC_AVERAGING) + activeChannelCount[adcConfig[ADC_CHN_5].adcDevice] += 1; +#endif + } + } +#else + disableChannelMapping(ADC_CHN_5); +#endif + +#ifdef ADC_CHANNEL_6_PIN + if (isChannelInUse(ADC_CHN_6)) { + adcConfig[ADC_CHN_6].adcDevice = adcDeviceByInstance(ADC_CHANNEL_6_INSTANCE); + if (adcConfig[ADC_CHN_6].adcDevice != ADCINVALID) { + adcConfig[ADC_CHN_6].tag = IO_TAG(ADC_CHANNEL_6_PIN); +#if defined(USE_ADC_AVERAGING) + activeChannelCount[adcConfig[ADC_CHN_6].adcDevice] += 1; +#endif + } + } +#else + disableChannelMapping(ADC_CHN_6); +#endif adcHardwareInit(init); } diff --git a/src/main/drivers/adc.h b/src/main/drivers/adc.h index 5ba4b999da0..1749c9fa63e 100644 --- a/src/main/drivers/adc.h +++ b/src/main/drivers/adc.h @@ -33,7 +33,9 @@ typedef enum { ADC_CHN_2, ADC_CHN_3, ADC_CHN_4, - ADC_CHN_MAX = ADC_CHN_4, + ADC_CHN_5, + ADC_CHN_6, + ADC_CHN_MAX = ADC_CHN_6, ADC_CHN_COUNT } adcChannel_e; diff --git a/src/main/drivers/pwm_mapping.c b/src/main/drivers/pwm_mapping.c index eb14d6772b6..e3acc6d1a0f 100644 --- a/src/main/drivers/pwm_mapping.c +++ b/src/main/drivers/pwm_mapping.c @@ -195,6 +195,16 @@ static bool checkPwmTimerConflicts(const timerHardware_t *timHw) return true; } #endif +#if defined(ADC_CHANNEL_5_PIN) + if (timHw->tag == IO_TAG(ADC_CHANNEL_6_PIN)) { + return true; + } +#endif +#if defined(ADC_CHANNEL_6_PIN) + if (timHw->tag == IO_TAG(ADC_CHANNEL_6_PIN)) { + return true; + } +#endif #endif return false; From 571fcb53bff9514ae84582c1d457520d910acc90 Mon Sep 17 00:00:00 2001 From: Ray Morris Date: Mon, 17 Jul 2023 21:05:00 -0500 Subject: [PATCH 2/8] pwm_mapping.c: Fix typo ADC_CHANNEL_5, not ADC_CHANNEL_6 --- src/main/drivers/pwm_mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/drivers/pwm_mapping.c b/src/main/drivers/pwm_mapping.c index e3acc6d1a0f..4fc5a00b83e 100644 --- a/src/main/drivers/pwm_mapping.c +++ b/src/main/drivers/pwm_mapping.c @@ -196,7 +196,7 @@ static bool checkPwmTimerConflicts(const timerHardware_t *timHw) } #endif #if defined(ADC_CHANNEL_5_PIN) - if (timHw->tag == IO_TAG(ADC_CHANNEL_6_PIN)) { + if (timHw->tag == IO_TAG(ADC_CHANNEL_5_PIN)) { return true; } #endif From ed1e750830def3036bda117676972bf48765ad95 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:59:54 +0200 Subject: [PATCH 3/8] Initial fix for m8 gps. Will setup some hardware on my bench to diagnose further --- src/main/io/gps_ublox.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/io/gps_ublox.c b/src/main/io/gps_ublox.c index ea202797539..b7abae42d76 100755 --- a/src/main/io/gps_ublox.c +++ b/src/main/io/gps_ublox.c @@ -997,6 +997,10 @@ STATIC_PROTOTHREAD(gpsProtocolStateThread) // Try sending baud rate switch command at all common baud rates gpsSetProtocolTimeout((GPS_BAUD_CHANGE_DELAY + 50) * (GPS_BAUDRATE_COUNT)); for (gpsState.autoBaudrateIndex = 0; gpsState.autoBaudrateIndex < GPS_BAUDRATE_COUNT; gpsState.autoBaudrateIndex++) { + if((gpsState.autoBaudrateIndex >= GPS_BAUDRATE_460800) && (gpsState.baudrateIndex < GPS_BAUDRATE_460800)) { + // trying higher baud rates fails on m8 gps + break; + } // 2. Set serial port to baud rate and send an $UBX command to switch the baud rate specified by portConfig [baudrateIndex] serialSetBaudRate(gpsState.gpsPort, baudRates[gpsToSerialBaudRate[gpsState.autoBaudrateIndex]]); serialPrint(gpsState.gpsPort, baudInitDataNMEA[gpsState.baudrateIndex]); From 8d20a44b954f7fffebb66349bf5c635677188560 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sun, 6 Aug 2023 14:25:15 +0200 Subject: [PATCH 4/8] Add variable for max autobaud baud rate. Some old devices seem to reset if set to too high of a baud rate. A particular old m8 devices tops up at 115200. INAV 6.0 used to go all the way up to 230400 --- docs/Settings.md | 10 ++++++++++ src/main/fc/settings.yaml | 10 ++++++++++ src/main/io/gps.c | 10 +++++++--- src/main/io/gps.h | 2 ++ src/main/io/gps_ublox.c | 5 +++-- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index dda075cee64..f65f2e40e21 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -1372,6 +1372,16 @@ Automatic configuration of GPS baudrate(The specified baudrate in configured in --- +### gps_auto_baud_max + +Max baudrate supported by GPS unit. This is used during autobaud. M8 supports up to 460400, M10 supports up to 921600 and 230400 is the value used before INAV 7.0 + +| Default | Min | Max | +| --- | --- | --- | +| 230400 | | | + +--- + ### gps_auto_config Enable automatic configuration of UBlox GPS receivers. diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index a0904af6f32..b11169b6acc 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -190,6 +190,9 @@ tables: - name: nav_fw_wp_turn_smoothing values: ["OFF", "ON", "ON-CUT"] enum: wpFwTurnSmoothing_e + - name: gps_auto_baud_max + values: [ '115200', '57600', '38400', '19200', '9600', '230400', '460800', '921600'] + enum: gpsBaudRate_e constants: RPYL_PID_MIN: 0 @@ -1501,6 +1504,7 @@ groups: min: 1 max: 3000 - name: PG_GPS_CONFIG + headers: [ "io/gps.h" ] type: gpsConfig_t condition: USE_GPS members: @@ -1532,6 +1536,12 @@ groups: default_value: ON field: autoBaud type: bool + - name: gps_auto_baud_max_supported + description: "Max baudrate supported by GPS unit. This is used during autobaud. M8 supports up to 460400, M10 supports up to 921600 and 230400 is the value used before INAV 7.0" + default_value: "230400" + table: gps_auto_baud_max + field: autoBaudMax + type: uint8_t - name: gps_ublox_use_galileo description: "Enable use of Galileo satellites. This is at the expense of other regional constellations, so benefit may also be regional. Requires M8N and Ublox firmware 3.x (or later) [OFF/ON]." default_value: OFF diff --git a/src/main/io/gps.c b/src/main/io/gps.c index a66409d5651..03f8ca829d3 100755 --- a/src/main/io/gps.c +++ b/src/main/io/gps.c @@ -128,10 +128,9 @@ PG_RESET_TEMPLATE(gpsConfig_t, gpsConfig, .ubloxNavHz = SETTING_GPS_UBLOX_NAV_HZ_DEFAULT ); - -int getGpsBaudrate(void) +int gpsBaudRateToInt(gpsBaudRate_e baudrate) { - switch(gpsState.baudrateIndex) + switch(baudrate) { case GPS_BAUDRATE_115200: return 115200; @@ -154,6 +153,11 @@ int getGpsBaudrate(void) } } +int getGpsBaudrate(void) +{ + return gpsBaudRateToInt(gpsState.baudrateIndex); +} + const char *getGpsHwVersion(void) { switch(gpsState.hwVersion) diff --git a/src/main/io/gps.h b/src/main/io/gps.h index 9f06e21f722..99b6aafbdf0 100755 --- a/src/main/io/gps.h +++ b/src/main/io/gps.h @@ -99,6 +99,7 @@ typedef struct gpsConfig_s { bool ubloxUseGlonass; uint8_t gpsMinSats; uint8_t ubloxNavHz; + gpsBaudRate_e autoBaudMax; } gpsConfig_t; PG_DECLARE(gpsConfig_t, gpsConfig); @@ -175,6 +176,7 @@ uint8_t getGpsProtoMajorVersion(void); uint8_t getGpsProtoMinorVersion(void); int getGpsBaudrate(void); +int gpsBaudRateToInt(gpsBaudRate_e baudrate); #if defined(USE_GPS_FAKE) void gpsFakeSet( diff --git a/src/main/io/gps_ublox.c b/src/main/io/gps_ublox.c index b7abae42d76..f2ad3da5720 100755 --- a/src/main/io/gps_ublox.c +++ b/src/main/io/gps_ublox.c @@ -997,9 +997,10 @@ STATIC_PROTOTHREAD(gpsProtocolStateThread) // Try sending baud rate switch command at all common baud rates gpsSetProtocolTimeout((GPS_BAUD_CHANGE_DELAY + 50) * (GPS_BAUDRATE_COUNT)); for (gpsState.autoBaudrateIndex = 0; gpsState.autoBaudrateIndex < GPS_BAUDRATE_COUNT; gpsState.autoBaudrateIndex++) { - if((gpsState.autoBaudrateIndex >= GPS_BAUDRATE_460800) && (gpsState.baudrateIndex < GPS_BAUDRATE_460800)) { + if (gpsBaudRateToInt(gpsState.autoBaudrateIndex) > gpsBaudRateToInt(gpsState.gpsConfig->autoBaudMax)) { // trying higher baud rates fails on m8 gps - break; + // autoBaudRateIndex is not sorted by baud rate + continue; } // 2. Set serial port to baud rate and send an $UBX command to switch the baud rate specified by portConfig [baudrateIndex] serialSetBaudRate(gpsState.gpsPort, baudRates[gpsToSerialBaudRate[gpsState.autoBaudrateIndex]]); From 78a25eff70e52b83ad281db07ea82052b38371e4 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sun, 6 Aug 2023 14:27:28 +0200 Subject: [PATCH 5/8] update docs --- docs/Settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Settings.md b/docs/Settings.md index f65f2e40e21..048e8de9d25 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -1372,7 +1372,7 @@ Automatic configuration of GPS baudrate(The specified baudrate in configured in --- -### gps_auto_baud_max +### gps_auto_baud_max_supported Max baudrate supported by GPS unit. This is used during autobaud. M8 supports up to 460400, M10 supports up to 921600 and 230400 is the value used before INAV 7.0 From 0f4a35d25e4028cc919a17828bd5fb7f46291c5b Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sun, 6 Aug 2023 15:41:23 +0200 Subject: [PATCH 6/8] bump pg_register version --- src/main/io/gps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/io/gps.c b/src/main/io/gps.c index 03f8ca829d3..2c66b98c0dd 100755 --- a/src/main/io/gps.c +++ b/src/main/io/gps.c @@ -113,7 +113,7 @@ static gpsProviderDescriptor_t gpsProviders[GPS_PROVIDER_COUNT] = { }; -PG_REGISTER_WITH_RESET_TEMPLATE(gpsConfig_t, gpsConfig, PG_GPS_CONFIG, 3); +PG_REGISTER_WITH_RESET_TEMPLATE(gpsConfig_t, gpsConfig, PG_GPS_CONFIG, 4); PG_RESET_TEMPLATE(gpsConfig_t, gpsConfig, .provider = SETTING_GPS_PROVIDER_DEFAULT, From dfad61b4a8680ae606a47b6defd778adeea2a5f3 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sun, 6 Aug 2023 15:54:17 +0200 Subject: [PATCH 7/8] Make sure autoBaudMax default is set correctly --- src/main/io/gps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/io/gps.c b/src/main/io/gps.c index 2c66b98c0dd..4d7380e84df 100755 --- a/src/main/io/gps.c +++ b/src/main/io/gps.c @@ -125,7 +125,8 @@ PG_RESET_TEMPLATE(gpsConfig_t, gpsConfig, .ubloxUseGalileo = SETTING_GPS_UBLOX_USE_GALILEO_DEFAULT, .ubloxUseBeidou = SETTING_GPS_UBLOX_USE_BEIDOU_DEFAULT, .ubloxUseGlonass = SETTING_GPS_UBLOX_USE_GLONASS_DEFAULT, - .ubloxNavHz = SETTING_GPS_UBLOX_NAV_HZ_DEFAULT + .ubloxNavHz = SETTING_GPS_UBLOX_NAV_HZ_DEFAULT, + .autoBaudMax = SETTING_GPS_AUTO_BAUD_MAX_SUPPORTED_DEFAULT ); int gpsBaudRateToInt(gpsBaudRate_e baudrate) From 8afc50562f650817a460fa933c678f81424032e2 Mon Sep 17 00:00:00 2001 From: druckgott Date: Sun, 6 Aug 2023 17:21:37 +0200 Subject: [PATCH 8/8] Update target.h, Fix Sensor VL53L1X, Speedybee Target V3 Add I2C1 Adress to the RANGEFINDER, VL53L1X --- src/main/target/SPEEDYBEEF7V3/target.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/target/SPEEDYBEEF7V3/target.h b/src/main/target/SPEEDYBEEF7V3/target.h index f8705f97da7..7c1d565c377 100644 --- a/src/main/target/SPEEDYBEEF7V3/target.h +++ b/src/main/target/SPEEDYBEEF7V3/target.h @@ -149,6 +149,7 @@ // ********** Optiical Flow adn Lidar ************** #define USE_RANGEFINDER #define USE_RANGEFINDER_MSP +#define RANGEFINDER_I2C_BUS BUS_I2C1 #define USE_OPFLOW #define USE_OPFLOW_MSP