a good startpoint is to read RaspberryPI_CodesysV3_FirstSteps_EN.pdf:
"c:\Users\<YourWindowsUserName>\CODESYS Control for Raspberry PI\18.104.22.168\Documentation\RaspberryPI_CodesysV3_FirstSteps_EN.pdf"
In Chapter 4 'Connecting additional devices via I²C and SPI' there is a Basic description how it works.
See after reading this the 'open' libraries and devices here:
"c:\Users\<YourWindowsUserName>\CODESYS Control for Raspberry PI\22.214.171.124\Libraries\"
open these libraries with CODESYS and check how they are implemented.
They use the I2C/SPI FB's from Raspberry Pi Periphials Library.
you need to implement a own device description for your device and install it then to the device repository
"c:\Users\<YourWindowsUserName>\CODESYS Control for Raspberry PI\126.96.36.199\Devices\"
The best practice how to work/debug/install... with libraries you'll find here:viewtopic.php?f=22&t=5641&p=10677#p10677