Building libdaq example applications / libraries;a=tree;h=refs/heads/master;hb=refs/heads/master

The libdaq folder contains a bunch of different libraries for controlling different devices from userspace. Some of these have a "main()" to allow testing the library, and we can build them using the following

source /opt/criticallink/mitysom-335x_2020-08-20/environment-setup-cortexa8t2hf-neon-criticallink-linux-gnueabi
git clone
cd libdaq
./configure --host=arm-criticallink-linux-gnueabi --enable-factoryconfig=no
make -j$(nproc)

The most useful example binaries are likely going to be "gpio", "gpiosingle" and "pwm"

 $ ls -l gpio pwm
-rwxr-xr-x 1 jcormier engineer 119868 Mar 24 10:28 gpio
-rwxr-xr-x 1 jcormier engineer 119868 Mar 24 10:28 gpiosingle
-rwxr-xr-x 1 jcormier engineer  51164 Mar 24 10:28 pwm

Building and using gpiosingle with QT and QtCreator

  • Create a test project for this demo. File -> New File or Project
    • Application -> Qt Widgets Application
    • Name: TestMe
    • Accept defaults. Make sure to pick a valid Kit
  • Checkout libdaq inside project folder
    Documents/TestMe$ git clone
    Cloning into 'libdaq'...
    remote: Counting objects: 969, done.
    remote: Compressing objects: 100% (346/346), done.
    remote: Total 969 (delta 689), reused 872 (delta 616)
    Receiving objects: 100% (969/969), 549.12 KiB | 8.32 MiB/s, done.
    Resolving deltas: 100% (689/689), done.
  • Open project in QtCreator
  • Right-click in the project area and click "Add existing files". Then select "gpiosingle.cpp" and "gpiosingle.h"
  • Build the project
    Note: If you get various #include file not found warnings, make sure you are compiling for Linux or with the arm cross-compile toolchain. The libdaq libraries are not designed to build for Windows.
  • Open mainwindow.h
    • Add @#include "libdaq/gpiosingle.h"
    • Under private and the mainwindow ui, add
          Ui::MainWindow *ui;
          MityDSP::tcGpioSingle redLed;
  • Open mainwindow.cpp
  • Above the class, add:
    #define GPIO_TO_PIN(bank, gpio) ((bank)*32 + (gpio))

    Note: This changes depending on the processor, the above is correct for the AM335x. The L138 however would be 16 instead of 32...
    • In the constructor, initialize the gpio to the correct gpio number, and ensure the direction is set
      Note: gpio1_12 was picked at random, the devkit doesn't have any gpios attached to LEDs. This is just an example
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
          , gpioRedLed(GPIO_TO_NUM(1,12)) // gpio1_12
          gpioRedLed.setDirection(1, 0); // Set gpio as output low
  • Add a ToggleLED button to the mainwindow form and create a clicked handler
  • Setup click handler to get current gpio value and flip it so we toggle the LED on then off each time the button is pushed
    void MainWindow::on_pbToggleLed_clicked()
        int ret;
        unsigned int value;
        ret = gpioRedLed.GetValue(value);
        if (ret < 0) {
            qDebug() << "Error: Failed to get gpio value";
        ret = gpioRedLed.SetValue(!value);
        if (ret < 0) {
            qDebug() << "Error: Failed to set gpio value";

Attached modified mainwindow files: mainwindow.h mainwindow.ui mainwindow.cpp

Go to top
Add picture from clipboard (Maximum size: 600 MB)