In this article, we will show how you can manipulate GPIO using Torizon C/C++ Application development Visual Studio Plugin.
On Visual Studio 2019, create a new Torizon C/C++ Application. See the Visual Studio Extension For Torizon article for detailed instructions.
To add the libgpiod library to your project, right-click in your project on the Solution Explorer view and click on Properties.
In Configuration Properties, click on
Torizon C/C++ Application, right-click on the
Configuration item and then
RUN usermod -a -G gpio torizon command to "buildcommands" property. This provides the container user the necessary privileges to access gpio devices.
libgpiod-dev:arm64 libgpiod2:arm64 the "devpackages" property. If you plan to build a 32-bit application/container replace :arm64 with :armhf as suffix for the packages.
libgpiod2 gpiod to the "extrapackages" list. Please notice that in this case, you don’t need any suffix.
Also, add the corresponding gpiochip to the application. In this example, we will use
/dev/gpiochip0. Set this value to the "device" property. Also include other gpio devices you may want to access.
To use libgpiod in your C/C++ application, it is necessary to add the library to the Linker.
In Configuration Properties, click on "Linker" -> "Input" and add
gpiod to the "Library Dependencies" field.
After setting the project properties, we are ready to start working with code. The instructions below are a subset of the comprehensive article How to Use GPIO on TorizonCore:
To make an easier integration to the IDE: in the examples above, instead of passing the GPIO bank and line as arguments, we suggest that you declare them directly in the source-code:
int bank = <bank-number>; int line = <line-number>;