GPIO mapping for new board (NVIDIA Jetson Nano)

I am trying to run ArduPilot on NVIDIA Jetson Nano, so I need to create an implementation of AP_HAL::GPIO for Jetson. I rely on the JETGPIO library. The thing is the function gpioSetMode from this library expects parameter pin in the range 3-40, which identifies pin. As far as I understand - it is an index number of the pin. But the pin parameter from the AP_HAL::GPIO interface is some kind of board-agnostic value (not sure how exactly it works, but ArduPilot seems to provide values for it without knowing the exact board it runs on). So I need to map this ArduPilot board-agnostic value to the 3-40 index of Jetson pins.

How to do that? I would appreciate any insights on how to find all the possible “ArduPilot board-agnostic values” and on how to map them to Jetson pins

Here is my implementation of pinMode method for an instance:

void GPIO_Jetson::pinMode(uint8_t pin, uint8_t output)
{
    int result = gpioSetMode(<pin index in range 3-40 here>, JET_OUTPUT);
}

Jetson are Linux based just like RPI and BBB.
Look at the Linux Hal libraries for proper configuration of the GPIO

Here is the example for RPI, you would need to write the proper libraries for the Jetson:

I investigated how other Linux Hal libraries configure GPIO. But my question is how to map Ardupilot values of pin parameter to the values that JETGPIO library expects (index number in range from 3 to 40).

Here is the example from the file RCOutput.cpp of usage of the pinMode method of hal.gpio for you to clearly understand what I mean by “Ardupilot values of pin parameter”:

#if RCOU_DSHOT_TIMING_DEBUG
    hal.gpio->pinMode(54, 1);
    hal.gpio->pinMode(55, 1);
    hal.gpio->pinMode(56, 1);
    hal.gpio->pinMode(57, 1);
#endif

So the question is how should map these values (54, 55, 56…) to the pins of Jetson? And where to find all the possible values except for these 4 I provided in code sample

You must understand the difference betwen the different Hardware Abstaction Layers.
The example you give is for chibios that is a real time implementation for STM microcontrollers and has no direct correspondance to the Linux HAL.

I would suggest you study a little more the code and structure.
Wiki for dev is Welcome to the ArduPilot Development Site — Dev documentation