mp_hal_gpio_set_af will search for a given function and unit and set the alternate function to the alternate function index found.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such as stdio and delay/ticks, which ports should provide definitions for. A port will also provide mphalport.h with further HAL declarations.