Which SPI and I2C interface libraries for C/C++ Visual Studio Code Torizon on Bullseye?

Hi there,

I am a relative newcomer looking to port a debian bullseye beaglebone software stack to a Verdin IMX8MM running Torizon 5 (Bullseye). The software stack interfaces with SPI and I2C using librobotcontrol (Robot Control Library: SPI) on beaglebone, and I need to replace these libraries on my port on Torizon.

Looking around for libraries to enable control SPI and I2C via the spidev and i2c handles provided by the kernel, it appears that libsoc (GitHub - jackmitch/libsoc: libsoc: C library for interfacing with common SoC peripherals through generic kernel interfaces) may be commonly used - however it does not have a prebuilt binary and runtime available for bullseye, and therefore is not able to be found when added to the “devpackages” and “extrapackages” in VS Code. In a normal environment, I would compile libsoc from source, but I am unclear how to do this in the VS Code extension.

In conclusion I have two questions:

  1. Is there a common library that Torizon devs use for accessing spidev and i2c from user space that acts like libsoc or librobotcontrol?
  2. When a prebuilt binary package is not available, is there a way to build libraries from source in the Visual Studio Code extension for C/C++ applications?

Thank you,

DVLevine

Greetings @DVLevine,

Exact libraries can depend heavily on use-case and language/framework. But for basic C/C++ usage here’s what I would suggest. For SPI/spidev, you should be able to use via the utilities in the Linux kernel for spidev. Here’s an example of spidev usage from the Linux kernel source itself: https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c

If you want something more higher level for spidev usage, ultimately I can’t recommend anything specific because it depends.

As for I2C, there should be a package i2c-tools available in Debian: Debian -- Details of source package i2c-tools in bullseye

Installing this will also pull in userspace libraries for interacting with I2c.

When a prebuilt binary package is not available, is there a way to build libraries from source in the Visual Studio Code extension for C/C++ applications?

This is possible though it will require a bit of work/customization on your end to set it up properly. For this task I would reference our article here: IDE Extension | Toradex Developer Center

In the above example we’re building a C/C++ project and we need to build and include an external library (libspectrum). I would recommend to use this example as reference for compiling and adding external libraries.

Best Regards,
Jeremias
Best