i2c spi buses: enforce drivers to set default SPI/I2C bus frequency

Not a lot of drivers use the global default, which is somewhat arbitrary.
This commit is contained in:
Beat Küng
2020-03-17 18:51:31 +01:00
committed by Daniel Agar
parent 8ebde51648
commit d6bb5b3b9e
13 changed files with 60 additions and 2 deletions

View File

@@ -62,6 +62,10 @@ const char *BusCLIArguments::parseDefaultArguments(int argc, char *argv[])
int BusCLIArguments::getopt(int argc, char *argv[], const char *options)
{
if (_options[0] == 0) { // need to initialize
if (!validateConfiguration()) {
return EOF;
}
char *p = (char *)&_options;
if (_i2c_support) {
@@ -182,6 +186,23 @@ int BusCLIArguments::getopt(int argc, char *argv[], const char *options)
return ch;
}
bool BusCLIArguments::validateConfiguration()
{
bool success = true;
if (_i2c_support && default_i2c_frequency == -1) {
PX4_ERR("Bug: driver %s does not set default_i2c_frequency", px4_get_taskname());
success = false;
}
if (_spi_support && default_spi_frequency == -1) {
PX4_ERR("Bug: driver %s does not set default_spi_frequency", px4_get_taskname());
success = false;
}
return success;
}
BusInstanceIterator::BusInstanceIterator(const char *module_name,
const BusCLIArguments &cli_arguments, uint16_t devid_driver_index)