@alphabetapie
Do you only ever have one type of controller plugged in, and only using retroarch cores?
If yes, then you could use the EmulationStation input configuration to set up the M30 to match Sega Genesis (or whatever), and then create a core remap file in the retroarch RGUI > Input settings to swap any buttons as needed in the other cores. You could use even use game remaps if you need to.
It is also possible, but more manual effort, to put different configurations in different directories, and then use the retroarch.cfg joypad_autoconfig_dir setting to point different cores (or even games) at different controller configurations.
joypad_autoconfig_dir = "/opt/retropie/configs/snes/joypads/"