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 23:31:17 -04:00
committed by Daniel Agar
parent 8ebde51648
commit d6bb5b3b9e
13 changed files with 60 additions and 2 deletions
+21
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)
@@ -117,10 +117,12 @@ public:
void *custom_data{nullptr}; ///< driver-specific custom argument
// driver defaults, if not specified via CLI
int default_spi_frequency{20 * 1000 * 1000}; ///< default spi bus frequency [Hz]
int default_i2c_frequency{400 * 1000}; ///< default i2c bus frequency [Hz]
int default_spi_frequency{-1}; ///< default spi bus frequency (driver needs to set this) [Hz]
int default_i2c_frequency{-1}; ///< default i2c bus frequency (driver needs to set this) [Hz]
private:
bool validateConfiguration();
char _options[32] {};
int _optind{1};
const char *_optarg{nullptr};