I'm using m74hc08b1 AND gates to take the 3.3v as one input, 5v as the other input, and output 5v. I do have LinuxCNC running on the Pi, I can't find the exact instructions I used right now but check out here:
https://gnipsel.com/linuxcnc/uspace/rpi4-rt.html