diff --git a/Tools/px4moduledoc/srcparser.py b/Tools/px4moduledoc/srcparser.py index 2e8ccc1894..cd4b029f95 100644 --- a/Tools/px4moduledoc/srcparser.py +++ b/Tools/px4moduledoc/srcparser.py @@ -33,9 +33,12 @@ class ModuleDocumentation(object): self._scope = scope self._options = '' # all option chars + self._explicit_options = '' # all option chars (explicit in the module) self._all_values = [] # list of all values self._all_commands = [] + self._paring_implicit_options = False + for func_name, args in function_calls: attribute_name = '_handle_'+func_name.lower() try: @@ -99,7 +102,7 @@ class ModuleDocumentation(object): def _handle_usage_param_int(self, args): assert(len(args) == 6) # option_char, default_val, min_val, max_val, description, is_optional option_char = self._get_option_char(args[0]) - default_val = int(args[1]) + default_val = int(args[1], 0) description = self._get_string(args[4]) if self._is_bool_true(args[5]): self._usage_string += " [-%s ] %s\n" % (option_char, description) @@ -120,6 +123,33 @@ class ModuleDocumentation(object): else: self._usage_string += " -%s %s\n" % (option_char, description) + def _handle_usage_params_i2c_spi_driver(self, args): + assert(len(args) == 2) # i2c_support, spi_support + self._paring_implicit_options = True + if self._is_bool_true(args[0]): + self._handle_usage_param_flag(['\'I\'', "\"Internal I2C bus(es)\"", 'true']) + self._handle_usage_param_flag(['\'X\'', "\"External I2C bus(es\")", 'true']) + if self._is_bool_true(args[1]): + self._handle_usage_param_flag(['\'s\'', "\"Internal SPI bus(es)\"", 'true']) + self._handle_usage_param_flag(['\'S\'', "\"External SPI bus(es)\"", 'true']) + + self._handle_usage_param_int(['\'b\'', '-1', '0', '16', + "\"bus (board-specific internal (default=all) or n-th external (default=1))\"", 'true']) + + if self._is_bool_true(args[1]): + self._handle_usage_param_int(['\'c\'', '1', '1', '10', + "\"chip-select index (for external SPI)\"", 'true']) + 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._paring_implicit_options = False + + def _handle_usage_params_i2c_address(self, args): + assert(len(args) == 1) # i2c_address + self._paring_implicit_options = True + self._handle_usage_param_int(['\'a\'', args[0], '0', '0xff', "\"I2C address\"", 'true']) + self._paring_implicit_options = False + def _handle_usage_param_flag(self, args): assert(len(args) == 3) # option_char, description, is_optional option_char = self._get_option_char(args[0]) @@ -187,6 +217,8 @@ class ModuleDocumentation(object): assert(len(argument) == 3) # must have the form: 'p' (assume there's no escaping) option_char = argument[1] self._options += option_char + if not self._paring_implicit_options: + self._explicit_options += option_char return option_char @@ -234,9 +266,10 @@ class ModuleDocumentation(object): def options(self): """ - get all the -p options as string of chars + get all the -p options as string of chars, that are explicitly set in + the module """ - return self._options + return self._explicit_options def all_values(self): """ @@ -257,7 +290,7 @@ class SourceParser(object): """ # Regex to extract module doc function calls, starting with PRINT_MODULE_ - re_doc_definition = re.compile(r'PRINT_MODULE_([A-Z_]*)\s*\(') + re_doc_definition = re.compile(r'PRINT_MODULE_([A-Z0-9_]*)\s*\(') def __init__(self): self._modules = {} # all found modules: key is the module name diff --git a/platforms/common/include/px4_platform_common/module.h b/platforms/common/include/px4_platform_common/module.h index 2b55c29f31..229debb78b 100644 --- a/platforms/common/include/px4_platform_common/module.h +++ b/platforms/common/include/px4_platform_common/module.h @@ -499,6 +499,17 @@ __EXPORT void PRINT_MODULE_USAGE_COMMAND_DESCR(const char *name, const char *des PRINT_MODULE_USAGE_COMMAND("stop"); \ PRINT_MODULE_USAGE_COMMAND_DESCR("status", "print status info"); +/** + * Print default params for I2C or SPI drivers + * @param i2c_support true if the driver supports I2C + * @param spi_support true if the driver supports SPI + */ +__EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(bool i2c_support, bool spi_support); + +/** + * Configurable I2C address (via -a
) + */ +__EXPORT void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address); /** @note Each of the PRINT_MODULE_USAGE_PARAM_* methods apply to the previous PRINT_MODULE_USAGE_COMMAND_DESCR(). */ diff --git a/platforms/common/module.cpp b/platforms/common/module.cpp index af6e3e65d6..49b3ee64cf 100644 --- a/platforms/common/module.cpp +++ b/platforms/common/module.cpp @@ -89,6 +89,35 @@ void PRINT_MODULE_USAGE_PARAM_COMMENT(const char *comment) PX4_INFO_RAW("\n %s\n", comment); } +void PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(bool i2c_support, bool spi_support) +{ + // Note: this must be kept in sync with Tools/px4moduledoc/srcparser.py + if (i2c_support) { + PRINT_MODULE_USAGE_PARAM_FLAG('I', "Internal I2C bus(es)", true); + PRINT_MODULE_USAGE_PARAM_FLAG('X', "External I2C bus(es)", true); + } + + if (spi_support) { + PRINT_MODULE_USAGE_PARAM_FLAG('s', "Internal SPI bus(es)", true); + PRINT_MODULE_USAGE_PARAM_FLAG('S', "External SPI bus", true); + } + + PRINT_MODULE_USAGE_PARAM_INT('b', -1, 0, 16, "bus (board-specific internal (default=all) or n-th external (default=1))", + true); + + if (spi_support) { + PRINT_MODULE_USAGE_PARAM_INT('c', 1, 1, 10, "chip-select index (for external SPI)", true); + PRINT_MODULE_USAGE_PARAM_INT('m', -1, 0, 3, "SPI mode", true); + } + + PRINT_MODULE_USAGE_PARAM_INT('f', -1, 0, 100000, "bus frequency in kHz", true); +} + +void PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(uint8_t default_address) +{ + PRINT_MODULE_USAGE_PARAM_INT('a', default_address, 0, 0xff, "I2C address", true); +} + void PRINT_MODULE_USAGE_PARAM_INT(char option_char, int default_val, int min_val, int max_val, const char *description, bool is_optional) {