From 5fe4c61b42b7d9e1ba4ce20f6cd6337c1c73a259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 5 Jul 2019 14:13:58 +0200 Subject: [PATCH] rc_input: add RC_PORT_CONFIG param to configure RC port The parameter will only be available if the board defines an 'RC' serial port in SERIAL_PORTS (in default.cmake). --- ROMFS/px4fmu_common/init.d/rcS | 13 ++++++++----- Tools/serial/generate_config.py | 19 ++++++++++++++++++- Tools/serial/serial_params.c.jinja | 2 ++ src/drivers/rc_input/CMakeLists.txt | 2 ++ src/drivers/rc_input/module.yaml | 12 ++++++++++++ validation/module_schema.yaml | 9 +++++++++ 6 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 src/drivers/rc_input/module.yaml diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS index 393a17a939..c2dcb072e5 100644 --- a/ROMFS/px4fmu_common/init.d/rcS +++ b/ROMFS/px4fmu_common/init.d/rcS @@ -52,6 +52,7 @@ set PWM_MAX p:PWM_MAX set PWM_MIN p:PWM_MIN set PWM_OUT none set PWM_RATE p:PWM_RATE +set RC_INPUT_ARGS "" set SDCARD_MIXERS_PATH /fs/microsd/etc/mixers set USE_IO no set VEHICLE_TYPE none @@ -318,11 +319,6 @@ else tune_control play -t 2 fi - if [ $IO_PRESENT = no -o $USE_IO = no ] - then - rc_input start - fi - # # Sensors System (start before Commander so Preflight checks are properly run). # Commander needs to be this early for in-air-restarts. @@ -418,6 +414,12 @@ else # sh /etc/init.d/rc.serial + if [ $IO_PRESENT = no -o $USE_IO = no ] + then + # Must be started after the serial config is read + rc_input start $RC_INPUT_ARGS + fi + # # Configure vehicle type specific parameters. # Note: rc.vehicle_setup is the entry point for rc.interface, @@ -546,6 +548,7 @@ unset PWM_MAX unset PWM_MIN unset PWM_OUT unset PWM_RATE +unset RC_INPUT_ARGS unset SDCARD_MIXERS_PATH unset USE_IO unset VEHICLE_TYPE diff --git a/Tools/serial/generate_config.py b/Tools/serial/generate_config.py index 031e9af681..2b47d8247b 100755 --- a/Tools/serial/generate_config.py +++ b/Tools/serial/generate_config.py @@ -108,6 +108,13 @@ serial_ports = { "default_baudrate": 0, }, + # RC Port + "RC": { + "label": "Radio Controller", + "index": 300, + "default_baudrate": 0, + }, + } parser = argparse.ArgumentParser(description='Generate Serial params & startup script') @@ -280,6 +287,15 @@ for serial_command in serial_commands: for i in range(num_instances): port_config = serial_command['port_config_param'] port_param_name = port_config['name'].replace('${i}', str(i)) + + # check if a port dependency is specified + if 'depends_on_port' in port_config: + depends_on_port = port_config['depends_on_port'] + if not any(p['tag'] == depends_on_port for p in serial_devices): + if verbose: + print("Skipping {:} (missing dependent port)".format(port_param_name)) + continue + default_port = 0 # disabled if 'default' in port_config: if type(port_config['default']) == list: @@ -299,7 +315,8 @@ for serial_command in serial_commands: 'multi_instance': num_instances > 1, 'port_param_name': port_param_name, 'default_port': default_port, - 'param_group': port_config['group'] + 'param_group': port_config['group'], + 'description_extended': port_config.get('description_extended', '') }) if verbose: diff --git a/Tools/serial/serial_params.c.jinja b/Tools/serial/serial_params.c.jinja index 157e7bf665..013dc91338 100644 --- a/Tools/serial/serial_params.c.jinja +++ b/Tools/serial/serial_params.c.jinja @@ -52,6 +52,8 @@ PARAM_DEFINE_INT32(SER_{{ serial_device.tag }}_BAUD, {{ serial_device.default_ba * * Configure on which serial port to run {{ command.label }}. * + * {{ command.description_extended | replace("\n", " ") }} + * * @value 0 Disabled {% for serial_device in serial_devices -%} * @value {{ serial_device.index }} {{ serial_device.label }} diff --git a/src/drivers/rc_input/CMakeLists.txt b/src/drivers/rc_input/CMakeLists.txt index 45552a58c7..87d4173814 100644 --- a/src/drivers/rc_input/CMakeLists.txt +++ b/src/drivers/rc_input/CMakeLists.txt @@ -38,6 +38,8 @@ px4_add_module( SRCS RCInput.cpp crsf_telemetry.cpp + MODULE_CONFIG + module.yaml DEPENDS rc ) diff --git a/src/drivers/rc_input/module.yaml b/src/drivers/rc_input/module.yaml new file mode 100644 index 0000000000..ae3c04ad42 --- /dev/null +++ b/src/drivers/rc_input/module.yaml @@ -0,0 +1,12 @@ +module_name: RC Input Driver +serial_config: + - command: set RC_INPUT_ARGS "-d ${SERIAL_DEV}" + port_config_param: + name: RC_PORT_CONFIG + group: Serial + default: RC + depends_on_port: RC + description_extended: | + Setting this to 'Disabled' will use a board-specific default port + for RC input. + diff --git a/validation/module_schema.yaml b/validation/module_schema.yaml index 67b246e70d..8c31fa2c83 100644 --- a/validation/module_schema.yaml +++ b/validation/module_schema.yaml @@ -54,6 +54,15 @@ serial_config: minlength: 1 schema: type: string + depends_on_port: + # Optional serial tag dependency (e.g. GPS1). If a board + # does not specify this serial port, the parameter will + # not be included in the build (i.e. it's not + # configurable) + type: string + description_extended: + # Optional extended description + type: string label: # Optional command label (e.g. used in the autostart script). # If omitted, module_name is used.