From 4088c2581f38333a306d3cd55aa66b617a51eb93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 26 Aug 2020 08:46:35 +0200 Subject: [PATCH] i2c_spi_buses: add '-q' for quiet startup flag (#14969) * [WIP] i2c_spi_buses: add '-q' for quiet startup flag And enable for optional board sensors. * ROMFS: rc.sensors try starting all optional I2C sensors quietly Co-authored-by: Daniel Agar --- ROMFS/cannode/init.d/rcS | 4 +-- ROMFS/px4fmu_common/init.d/rc.sensors | 28 +++++++++---------- ROMFS/px4fmu_common/init.d/rcS | 4 +-- Tools/px4moduledoc/srcparser.py | 1 + boards/px4/fmu-v5/init/rc.board_sensors | 2 +- platforms/common/i2c_spi_buses.cpp | 9 ++++++ .../px4_platform_common/i2c_spi_buses.h | 1 + platforms/common/module.cpp | 1 + 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/ROMFS/cannode/init.d/rcS b/ROMFS/cannode/init.d/rcS index ab65892970..9c929c23d5 100644 --- a/ROMFS/cannode/init.d/rcS +++ b/ROMFS/cannode/init.d/rcS @@ -68,8 +68,8 @@ unset BOARD_RC_DEFAULTS # # Start system state indicator. # -rgbled start -X -rgbled_ncp5623c start -X +rgbled start -X -q +rgbled_ncp5623c start -X -q rgbled_pwm start if param greater LIGHT_EN_BLINKM 0 diff --git a/ROMFS/px4fmu_common/init.d/rc.sensors b/ROMFS/px4fmu_common/init.d/rc.sensors index b2b7e93975..77a0e1b990 100644 --- a/ROMFS/px4fmu_common/init.d/rc.sensors +++ b/ROMFS/px4fmu_common/init.d/rc.sensors @@ -99,22 +99,22 @@ fi if param compare SENS_EXT_I2C_PRB 1 then # compasses - ak09916 -X -R 6 start # external AK09916 (Here2) is rotated 270 degrees yaw - hmc5883 -T -X start - ist8308 -X start - ist8310 -X start - lis2mdl -X start - lis3mdl -X start - qmc5883 -X start - rm3100 -X start + ak09916 -X -R 6 -q start # external AK09916 (Here2) is rotated 270 degrees yaw + hmc5883 -T -X -q start + ist8308 -X -q start + ist8310 -X -q start + lis2mdl -X -q start + lis3mdl -X -q start + qmc5883 -X -q start + rm3100 -X -q start # differential pressure sensors if [ ${VEHICLE_TYPE} = fw -o ${VEHICLE_TYPE} = vtol ] then if param compare CBRK_AIRSPD_CHK 0 then - sdp3x_airspeed start -X - sdp3x_airspeed start -X -a 0x22 + sdp3x_airspeed start -X -q + sdp3x_airspeed start -X -a 0x22 -q # Pixhawk 2.1 has a MS5611 on I2C which gets wrongly # detected as MS5525 because the chip manufacturer was so @@ -122,14 +122,14 @@ then # register. if [ $BOARD_FMUV3 = 21 ] then - ms5525_airspeed start -X -b 2 + ms5525_airspeed start -X -b 2 -q else - ms5525_airspeed start -X + ms5525_airspeed start -X -q fi - ms4525_airspeed start -X + ms4525_airspeed start -X -q - ets_airspeed start -X + ets_airspeed start -X -q fi fi fi diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS index 327d6cae88..f6f43b8c03 100644 --- a/ROMFS/px4fmu_common/init.d/rcS +++ b/ROMFS/px4fmu_common/init.d/rcS @@ -225,8 +225,8 @@ else # # Start system state indicator. # - rgbled start -X - rgbled_ncp5623c start -X + rgbled start -X -q + rgbled_ncp5623c start -X -q if param greater LIGHT_EN_BLINKM 0 then diff --git a/Tools/px4moduledoc/srcparser.py b/Tools/px4moduledoc/srcparser.py index 00b2e6ab04..af9c6b46cd 100644 --- a/Tools/px4moduledoc/srcparser.py +++ b/Tools/px4moduledoc/srcparser.py @@ -142,6 +142,7 @@ class ModuleDocumentation(object): self._handle_usage_param_int(['\'m\'', '-1', '0', '3', "\"SPI mode\"", 'true']) self._handle_usage_param_int(['\'f\'', '-1', '0', '1000000', "\"bus frequency in kHz\"", 'true']) + self._handle_usage_param_flag(['\'q\'', "\"quiet startup (no message if no device found)\"", 'true']) self._paring_implicit_options = False def _handle_usage_params_i2c_address(self, args): diff --git a/boards/px4/fmu-v5/init/rc.board_sensors b/boards/px4/fmu-v5/init/rc.board_sensors index 03663d7ae7..a40cf1b11f 100644 --- a/boards/px4/fmu-v5/init/rc.board_sensors +++ b/boards/px4/fmu-v5/init/rc.board_sensors @@ -6,7 +6,7 @@ adc start # Internal SPI bus ICM-20602 -icm20602 -s -R 2 start +icm20602 -s -R 2 -q start # Internal SPI bus ICM-20689 icm20689 -s -R 2 start diff --git a/platforms/common/i2c_spi_buses.cpp b/platforms/common/i2c_spi_buses.cpp index 93ed8473b0..338fdebeca 100644 --- a/platforms/common/i2c_spi_buses.cpp +++ b/platforms/common/i2c_spi_buses.cpp @@ -86,6 +86,7 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options) *(p++) = 'b'; *(p++) = ':'; // bus *(p++) = 'f'; *(p++) = ':'; // frequency + *(p++) = 'q'; // quiet flag // copy all options const char *option = options; @@ -158,6 +159,10 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options) spi_mode = (spi_mode_e)atoi(_optarg); break; + case 'q': + quiet_start = true; + break; + default: if (ch == '?') { // abort further parsing on unknown arguments @@ -528,6 +533,10 @@ int I2CSPIDriverBase::module_start(const BusCLIArguments &cli, BusInstanceIterat } } + if (!started && !cli.quiet_start) { + PX4_WARN("%s: no instance started (no device on bus?)", px4_get_taskname()); + } + return started ? 0 : -1; } diff --git a/platforms/common/include/px4_platform_common/i2c_spi_buses.h b/platforms/common/include/px4_platform_common/i2c_spi_buses.h index 2af0c32464..d492e0b0a9 100644 --- a/platforms/common/include/px4_platform_common/i2c_spi_buses.h +++ b/platforms/common/include/px4_platform_common/i2c_spi_buses.h @@ -109,6 +109,7 @@ public: int bus_frequency{0}; spi_mode_e spi_mode{SPIDEV_MODE3}; uint8_t i2c_address{0}; ///< optional I2C address: a driver can set this to allow configuring the I2C address + bool quiet_start{false}; ///< do not print a message when startup fails uint8_t orientation{0}; ///< distance_sensor_s::ROTATION_* diff --git a/platforms/common/module.cpp b/platforms/common/module.cpp index 49b3ee64cf..b02263693f 100644 --- a/platforms/common/module.cpp +++ b/platforms/common/module.cpp @@ -111,6 +111,7 @@ void PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(bool i2c_support, bool spi_support } PRINT_MODULE_USAGE_PARAM_INT('f', -1, 0, 100000, "bus frequency in kHz", true); + PRINT_MODULE_USAGE_PARAM_FLAG('q', "quiet startup (no message if no device found)", true); } void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address)