This repo contains different controller configs for use with the RetroPie. Just make an initial connection with your controller and copy these configs to "/opt/retropie/configs/all/retroarch-joypads" and restart. Everything should work smoothly.
Tested with firmware: v1.71 & v1.69
Both controller config files need to be copied into "/opt/retropie/configs/all/retroarch-joypads", because the config without spaces is for main RetroArch and the other is for when an emulator is running. You also need to include the mupen64plus.cfg file in "/opt/retropie/configs/n64/mupen64plus.cfg" and the mupen64plus.sh file in "/opt/retropie/emulators/mupen64plus/bin/" to make hotkeys work correctly in the n64 emulator.
Just copy over the config from this directory into "/opt/retropie/configs/all/retroarch-joypads/".