Skip to content

Commit

Permalink
AP_HAL: move serial re-mapping to UART array initialization
Browse files Browse the repository at this point in the history
Saves a bit of flash and execution time.
  • Loading branch information
tpwrules committed Nov 21, 2023
1 parent ca3c615 commit c0fdc6b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions libraries/AP_HAL/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ HAL::FunCallbacks::FunCallbacks(void (*setup_fun)(void), void (*loop_fun)(void))
// access serial ports using SERIALn numbering
AP_HAL::UARTDriver* AP_HAL::HAL::serial(uint8_t sernum) const
{
// this mapping captures the historical use of uartB as SERIAL3
const uint8_t mapping[] = { 0, 2, 3, 1, 4, 5, 6, 7, 8, 9 };
static_assert(sizeof(mapping) == ARRAY_SIZE(uart_array), "array size must match mapping");
if (sernum >= ARRAY_SIZE(uart_array)) {
return nullptr;
}
return uart_array[mapping[sernum]];
return uart_array[sernum];
}
4 changes: 2 additions & 2 deletions libraries/AP_HAL/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class AP_HAL::HAL {
:
uart_array{
_uartA,
_uartB,
_uartC,
_uartC, // ordering captures the historical use of uartB as SERIAL3
_uartD,
_uartB,
_uartE,
_uartF,
_uartG,
Expand Down

0 comments on commit c0fdc6b

Please sign in to comment.