The expansion pins correspond to different I/O pins (I believe they have the same pin layer as an arduino mega).
Here is the board layout [
files.panucatt.com]
So under exp1 D25 = digital pin #25, under exp2 A5 = analog pin 5. This in mind if you know how to control pins on an arduino then you can do the same here.
As for g-code/firmware update you may not need to do anything special, and g-code M42 should work for what you need to do. M42 works like this
M42 P S for example I use the D04 pin located in the "low power switch" section of the X3 to turn on and off my driver cooling fan.
To turn on - M42 P04 S255
To turn off - M42 P04 S0
Since this is a pwm pin if I wanted to run the fans at part speed - M42 P04 S150
Hope this helps