Skip to content

Commit

Permalink
rc_input: add RC_PORT_CONFIG param to configure RC port
Browse files Browse the repository at this point in the history
The parameter will only be available if the board defines an 'RC' serial
port in SERIAL_PORTS (in default.cmake).
  • Loading branch information
bkueng committed Jul 16, 2019
1 parent b7a0e1e commit 5fe4c61
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
13 changes: 8 additions & 5 deletions ROMFS/px4fmu_common/init.d/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion Tools/serial/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
"default_baudrate": 0,
},

# RC Port
"RC": {
"label": "Radio Controller",
"index": 300,
"default_baudrate": 0,
},

}

parser = argparse.ArgumentParser(description='Generate Serial params & startup script')
Expand Down Expand Up @@ -280,6 +287,15 @@ def parse_yaml_parameters_config(yaml_config):
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:
Expand All @@ -299,7 +315,8 @@ def parse_yaml_parameters_config(yaml_config):
'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:
Expand Down
2 changes: 2 additions & 0 deletions Tools/serial/serial_params.c.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/rc_input/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ px4_add_module(
SRCS
RCInput.cpp
crsf_telemetry.cpp
MODULE_CONFIG
module.yaml
DEPENDS
rc
)
12 changes: 12 additions & 0 deletions src/drivers/rc_input/module.yaml
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions validation/module_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5fe4c61

Please sign in to comment.