Magnetic rotation sensor code, help??

For the encoder, the data sheet you link to is the AS5047D. In OP you mention AS5040. Which one is it, really?

Also that's just the chip, not the mechanical part of the encoder. There has to be more to it: the device that produces the ABI signal pulses as the wheel rotates (A and B for the location/direction, I a zero position so the encoder know where to start counting).