diff --git a/platforms/common/include/px4_platform_common/board_common.h b/platforms/common/include/px4_platform_common/board_common.h index f8c983b8d4..2c158c58f9 100644 --- a/platforms/common/include/px4_platform_common/board_common.h +++ b/platforms/common/include/px4_platform_common/board_common.h @@ -264,8 +264,10 @@ */ #if defined(CONFIG_BOARD_SERIAL_RC) # define RC_SERIAL CONFIG_BOARD_SERIAL_RC -#else +#elif defined(RC_SERIAL_PORT) # define RC_SERIAL RC_SERIAL_PORT +#else +# error Board needs to define either CONFIG_BOARD_SERIAL_RC or RC_SERIAL_PORT #endif /* @@ -511,6 +513,35 @@ static inline bool board_rc_swap_rxtx(const char *device) { return strcmp(device static inline bool board_rc_swap_rxtx(const char *device) { return false; } #endif +/************************************************************************************ + * Name: board_rc_conflicting + * + * Description: + * A board may define its serial RC to be the same as PX4IO_SERIAL_DEVICE, + * especially when using PX4IO. + * + * This is problematic when trying to open the serial device used for PX4IO + * for RC. + * + * Input Parameters: + * device: serial device, e.g. "/dev/ttyS0" + * + * Returned Value: + * true if the given serial device does conflict with the PX4IO. + * false if not. + * + ************************************************************************************/ + +#if defined(RC_SERIAL) && defined(PX4IO_SERIAL_DEVICE) +static inline bool board_rc_conflicting(const char *device) +{ + return strcmp(device, RC_SERIAL) == 0 && strcmp(RC_SERIAL, PX4IO_SERIAL_DEVICE) == 0 + && (access("/dev/px4io", R_OK) == 0); +} +#else +static inline bool board_rc_conflicting(const char *device) { return false; } +#endif + /************************************************************************************ * Name: board_rc_invert_input * diff --git a/src/drivers/rc/crsf_rc/CrsfRc.cpp b/src/drivers/rc/crsf_rc/CrsfRc.cpp index d7401f57ae..9db8911636 100644 --- a/src/drivers/rc/crsf_rc/CrsfRc.cpp +++ b/src/drivers/rc/crsf_rc/CrsfRc.cpp @@ -97,6 +97,11 @@ int CrsfRc::task_spawn(int argc, char *argv[]) return PX4_ERROR; } + if (board_rc_conflicting(device_name)) { + PX4_INFO("unable to start, conflict with PX4IO on %s", device_name); + return PX4_ERROR; + } + CrsfRc *instance = new CrsfRc(device_name); if (instance == nullptr) { diff --git a/src/drivers/rc/dsm_rc/DsmRc.cpp b/src/drivers/rc/dsm_rc/DsmRc.cpp index b12fbfedcc..c20538726e 100644 --- a/src/drivers/rc/dsm_rc/DsmRc.cpp +++ b/src/drivers/rc/dsm_rc/DsmRc.cpp @@ -93,6 +93,11 @@ int DsmRc::task_spawn(int argc, char *argv[]) return -1; } + if (board_rc_conflicting(device_name)) { + PX4_INFO("unable to start, conflict with PX4IO on %s", device_name); + return PX4_ERROR; + } + if (device_name && (access(device_name, R_OK | W_OK) == 0)) { DsmRc *instance = new DsmRc(device_name); diff --git a/src/drivers/rc/ghst_rc/GhstRc.cpp b/src/drivers/rc/ghst_rc/GhstRc.cpp index aa4525d64c..e113b149f6 100644 --- a/src/drivers/rc/ghst_rc/GhstRc.cpp +++ b/src/drivers/rc/ghst_rc/GhstRc.cpp @@ -88,6 +88,11 @@ int GhstRc::task_spawn(int argc, char *argv[]) return -1; } + if (board_rc_conflicting(device_name)) { + PX4_INFO("unable to start, conflict with PX4IO on %s", device_name); + return PX4_ERROR; + } + if (device_name && (access(device_name, R_OK | W_OK) == 0)) { GhstRc *instance = new GhstRc(device_name); diff --git a/src/drivers/rc/sbus_rc/SbusRc.cpp b/src/drivers/rc/sbus_rc/SbusRc.cpp index 2ebdcfa207..0ac96797e1 100644 --- a/src/drivers/rc/sbus_rc/SbusRc.cpp +++ b/src/drivers/rc/sbus_rc/SbusRc.cpp @@ -85,6 +85,11 @@ int SbusRc::task_spawn(int argc, char *argv[]) return -1; } + if (board_rc_conflicting(device_name)) { + PX4_INFO("unable to start, conflict with PX4IO on %s", device_name); + return PX4_ERROR; + } + if (device_name && (access(device_name, R_OK | W_OK) == 0)) { SbusRc *instance = new SbusRc(device_name); diff --git a/src/drivers/rc/sbus_rc/module.yaml b/src/drivers/rc/sbus_rc/module.yaml index bc8a0ee140..d7228d2e27 100644 --- a/src/drivers/rc/sbus_rc/module.yaml +++ b/src/drivers/rc/sbus_rc/module.yaml @@ -4,7 +4,7 @@ serial_config: port_config_param: name: RC_SBUS_PRT_CFG group: Serial - default: RC + #default: RC #depends_on_port: RC description_extended: | SBUS RC driver.