AP_HAL_Linux: eliminate internal legacy UART ordering/references

Leave the legacy command line arguments to avoid breaking users.
This commit is contained in:
Thomas Watson 2023-12-10 21:32:18 -06:00 committed by Andrew Tridgell
parent 6b79349947
commit f34034584f
1 changed files with 41 additions and 40 deletions

View File

@ -64,16 +64,17 @@ static UtilRPI utilInstance;
static Util utilInstance; static Util utilInstance;
#endif #endif
// 9 serial ports on Linux // 10 serial ports on Linux
static UARTDriver uartADriver(true); static UARTDriver serial0Driver(true);
static UARTDriver uartCDriver(false); static UARTDriver serial1Driver(false);
static UARTDriver uartDDriver(false); static UARTDriver serial2Driver(false);
static UARTDriver uartEDriver(false); // serial3Driver declared below depending on board type
static UARTDriver uartFDriver(false); static UARTDriver serial4Driver(false);
static UARTDriver uartGDriver(false); static UARTDriver serial5Driver(false);
static UARTDriver uartHDriver(false); static UARTDriver serial6Driver(false);
static UARTDriver uartIDriver(false); static UARTDriver serial7Driver(false);
static UARTDriver uartJDriver(false); static UARTDriver serial8Driver(false);
static UARTDriver serial9Driver(false);
static I2CDeviceManager i2c_mgr_instance; static I2CDeviceManager i2c_mgr_instance;
static SPIDeviceManager spi_mgr_instance; static SPIDeviceManager spi_mgr_instance;
@ -81,9 +82,9 @@ static SPIDeviceManager spi_mgr_instance;
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \ #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH
static SPIUARTDriver uartBDriver; static SPIUARTDriver serial3Driver;
#else #else
static UARTDriver uartBDriver(false); static UARTDriver serial3Driver(false);
#endif #endif
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \ #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
@ -247,22 +248,22 @@ static CANIface* canDrivers[HAL_NUM_CAN_IFACES];
HAL_Linux::HAL_Linux() : HAL_Linux::HAL_Linux() :
AP_HAL::HAL( AP_HAL::HAL(
&uartADriver, &serial0Driver,
&uartCDriver, // ordering captures the historical use of uartB as SERIAL3 &serial1Driver,
&uartDDriver, &serial2Driver,
&uartBDriver, &serial3Driver,
&uartEDriver, &serial4Driver,
&uartFDriver, &serial5Driver,
&uartGDriver, &serial6Driver,
&uartHDriver, &serial7Driver,
&uartIDriver, &serial8Driver,
&uartJDriver, &serial9Driver,
&i2c_mgr_instance, &i2c_mgr_instance,
&spi_mgr_instance, &spi_mgr_instance,
&wspi_mgr_instance, &wspi_mgr_instance,
&analogIn, &analogIn,
&storageDriver, &storageDriver,
&uartADriver, &serial0Driver,
&gpioDriver, &gpioDriver,
&rcinDriver, &rcinDriver,
&rcoutDriver, &rcoutDriver,
@ -281,16 +282,16 @@ HAL_Linux::HAL_Linux() :
void _usage(void) void _usage(void)
{ {
printf("Usage: --serial0 serial0Path --serial1 serial2Path \n"); printf("Usage: --serial0 serial0Path --serial1 serial1Path \n");
printf("Examples:\n"); printf("Examples:\n");
printf("\tserial (0 through 9 available):\n"); printf("\tserial (0 through 9 available):\n");
printf("\t --serial0 /dev/ttyO4\n"); printf("\t --serial0 /dev/ttyO4\n");
printf("\t --serial3 /dev/ttyS1\n"); printf("\t --serial3 /dev/ttyS1\n");
printf("\tlegacy UART options still work, their mappings are:\n"); printf("\tlegacy UART options still work, their mappings are:\n");
printf("\t -A/--uartA is SERIAL0\n"); printf("\t -A/--uartA is SERIAL0\n");
printf("\t -B/--uartB is SERIAL3\n");
printf("\t -C/--uartC is SERIAL1\n"); printf("\t -C/--uartC is SERIAL1\n");
printf("\t -D/--uartD is SERIAL2\n"); printf("\t -D/--uartD is SERIAL2\n");
printf("\t -B/--uartB is SERIAL3\n");
printf("\t -E/--uartE is SERIAL4\n"); printf("\t -E/--uartE is SERIAL4\n");
printf("\t -F/--uartF is SERIAL5\n"); printf("\t -F/--uartF is SERIAL5\n");
printf("\t -G/--uartG is SERIAL6\n"); printf("\t -G/--uartG is SERIAL6\n");
@ -334,12 +335,12 @@ void HAL_Linux::run(int argc, char* const argv[], Callbacks* callbacks) const
const struct GetOptLong::option options[] = { const struct GetOptLong::option options[] = {
{"uartA", true, 0, 'A'}, {"uartA", true, 0, 'A'},
{"serial0", true, 0, 'A'}, {"serial0", true, 0, 'A'},
{"uartB", true, 0, 'B'}, {"uartC", true, 0, 'C'}, // ordering captures the historical use of uartB as SERIAL3
{"serial3", true, 0, 'B'},
{"uartC", true, 0, 'C'},
{"serial1", true, 0, 'C'}, {"serial1", true, 0, 'C'},
{"uartD", true, 0, 'D'}, {"uartD", true, 0, 'D'},
{"serial2", true, 0, 'D'}, {"serial2", true, 0, 'D'},
{"uartB", true, 0, 'B'},
{"serial3", true, 0, 'B'},
{"uartE", true, 0, 'E'}, {"uartE", true, 0, 'E'},
{"serial4", true, 0, 'E'}, {"serial4", true, 0, 'E'},
{"uartF", true, 0, 'F'}, {"uartF", true, 0, 'F'},
@ -371,34 +372,34 @@ void HAL_Linux::run(int argc, char* const argv[], Callbacks* callbacks) const
while ((opt = gopt.getoption()) != -1) { while ((opt = gopt.getoption()) != -1) {
switch (opt) { switch (opt) {
case 'A': case 'A':
uartADriver.set_device_path(gopt.optarg); serial0Driver.set_device_path(gopt.optarg);
break;
case 'B':
uartBDriver.set_device_path(gopt.optarg);
break; break;
case 'C': case 'C':
uartCDriver.set_device_path(gopt.optarg); serial1Driver.set_device_path(gopt.optarg);
break; break;
case 'D': case 'D':
uartDDriver.set_device_path(gopt.optarg); serial2Driver.set_device_path(gopt.optarg);
break;
case 'B':
serial3Driver.set_device_path(gopt.optarg);
break; break;
case 'E': case 'E':
uartEDriver.set_device_path(gopt.optarg); serial4Driver.set_device_path(gopt.optarg);
break; break;
case 'F': case 'F':
uartFDriver.set_device_path(gopt.optarg); serial5Driver.set_device_path(gopt.optarg);
break; break;
case 'G': case 'G':
uartGDriver.set_device_path(gopt.optarg); serial6Driver.set_device_path(gopt.optarg);
break; break;
case 'H': case 'H':
uartHDriver.set_device_path(gopt.optarg); serial7Driver.set_device_path(gopt.optarg);
break; break;
case 'I': case 'I':
uartIDriver.set_device_path(gopt.optarg); serial8Driver.set_device_path(gopt.optarg);
break; break;
case 'J': case 'J':
uartJDriver.set_device_path(gopt.optarg); serial9Driver.set_device_path(gopt.optarg);
break; break;
case 'l': case 'l':
utilInstance.set_custom_log_directory(gopt.optarg); utilInstance.set_custom_log_directory(gopt.optarg);