Difference between revisions of "Example io demo UPDATE 2019"

From wiki.emacinc.com
Jump to: navigation, search
 
(91 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
|description=This is a guide to the <code>io_demo</code> C example project included in the EMAC OE SDK.
 
|description=This is a guide to the <code>io_demo</code> C example project included in the EMAC OE SDK.
 
}}
 
}}
This demo covers basic gpio usage for the IPAC single board computer, and 150 and 200 series carrier boards. This demo first cover gpio manipulation through the Linux terminal and then demonstrates gpio usage in a C program using an io example program.
+
This demo covers basic GPIO usage for the IPAC single board computer, and 150 and 200 series carrier boards. This demo first cover GPIO manipulation through the Linux terminal and then demonstrates gpio usage in a C program using an io example program.
  
 +
GPIO control is accomplished through use of the libgpiod driver, as a result only the libgpiod library will be covered in this tutorial. For manipulation of non-GPIO peripherals use sysfs.
  
== Setup ==
+
 
 +
===Hardware Requirements===
 +
To use the '''io demo''' program you will need the following target hardware.
 +
 
 +
* An EMAC 150 series carrier board with a compatible SoM <br />
 +
'''OR''' <br />
 +
* An EMAC 200 series carrier board with a compatible SoM <br />
 +
'''OR'''
 +
* An IPAC single board computer <br />
 +
'''AND'''
 +
* additional components to establish to serial and Ethernet connections for your target hardware <br />
 +
 
 +
===Software Requirments===
 +
 
 +
These tools should already be installed if you installed the EMAC SDK using the automatic installer.
 +
* [[Getting_Started_with_the_EMAC_OE_SDK | EMAC OE 5.X SDK]]
 +
* EMAC Qt Creator
 +
* GNU <code>make</code>
 +
* CMake
 +
 
 +
=== Setup ===
 +
If you haven't already, please review the EMAC_OE_SDK [[Getting_Started_with_the_EMAC_OE_SDK| "getting started" page]]. EMAC_OE_SDK will need to be installed and serial and network connections will need to be established between the developer machine and the target device.See the [[Serial Connections]] or [[Network Connections]] page for more information on how to connect to the target EMAC product using a serial port or Ethernet connection.
 +
 
 +
== GPIO manipulation  through Linux Terminal ==
 +
GPIOs can be manipulated directly through the target devices serial terminal. The Libgpiod libary is used for this purpose. Linux terminal commands are defined in the libgpiod github readme (https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree) and are listed here for convenience:
 +
 
 +
"There are currently six command-line tools available: <br />
  
 +
'''gpiodetect''' - list all gpiochips present on the system, their names, labels and number of GPIO lines
  
 +
'''gpioinfo'''  - list all lines of specified gpiochips, their names, consumers, direction, active state and additional flags
  
== Usage and Behavior ==
+
'''gpioget'''    - read values of specified GPIO lines
  
===Hardware Requirements===
+
'''gpioset'''    - set values of specified GPIO lines, potentially keep the lines exported and wait until timeout, user input or signal
 +
 
 +
'''gpiofind'''  - find the gpiochip name and line offset given the line name
 +
 
 +
'''gpiomon'''    - wait for events on GPIO lines, specify which events to watch,how many events to process before exiting or if the events should be reported to the console"
 +
 
 +
In libgpiod ports and pins correspond to gpiochips and lines respectively. GPIO chip numbers are assigned by the kernel, and are hardware depended.
 +
== GPIO manipulation in C ==
 +
A more common manipulation of GPIOs is through a C program. The following example will demonstrated GPIO manipulation using the Libgpiod libary.
 +
 
 +
'''Program Setup''' <br \>
 +
 
 +
''On the target device'':
 +
<cl>
 +
1. Login, the default username and password is give below:
 +
<syntaxhighlight lang="text">
 +
username: root
 +
password: emac_inc
 +
</syntaxhighlight>
 +
* Change the file to read write by entering '''oemntrw''' into the device terminal.
 +
{{cli | oemntrw | hostname=somimx6ul}}
 +
 
 +
{{note|This will only change the root filesystem to read-write for the current boot.  When the system is rebooted, the root filesystem will once again be mounted read-only.}}
 +
* Obtain the device IP-address by entering '''ifconfig''' into the terminal. This is needed for device configuration in Qt Creator below.<br \>
 +
<syntaxhighlight lang=console highlight=3>
 +
root@emac-oe:~# ifconfig
 +
eth0      Link encap:Ethernet  HWaddr 00:50:C2:E6:60:F4
 +
          inet addr:10.0.2.100  Bcast:10.0.255.255  Mask:255.255.0.0
 +
          inet6 addr: fe80::5054:ff:feb1:f83e/64 Scope:Link
 +
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 +
          RX packets:1825 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:553 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:1000
 +
          RX bytes:139124 (135.8 KiB)  TX bytes:50603 (49.4 KiB)
 +
          Interrupt:25 Base address:0xc000
 +
 
 +
lo        Link encap:Local Loopback
 +
          inet addr:127.0.0.1  Mask:255.0.0.0
 +
          inet6 addr: ::1/128 Scope:Host
 +
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
 +
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:0
 +
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
 +
</syntaxhighlight>
 +
</cl>
 +
<br />
 +
'''On development machine''': <br />
 +
<ol>
 +
<li>Open Qt Creator</li>          <br />
 +
</ol>
 +
'''''Option 1:'''''
 +
 
 +
<ol start = 2>
 +
<li>Create a qmake project</li>
 +
*select '''+ New Project''' on the 'Welcome' window, the New Project window will appear.
 +
*Under Projects select '''Non-Qt Project''', Under the middle window select '''Plain C Application''', Click '''Choose...''', The Location window will appear.
 +
*Name your project '''LibGPIOd_example''', and choose a Create-in location, Click '''Next >''' to advance to the Build System window.
 +
*On the Build System Window choose the '''qmake''' option, Click '''Next >''' to advance to the Kits window.
 +
*On the Kits window check only '''ARM Qt5''', '''Click Next >'''  to advance to the Summary window
 +
*The options on the Summary window will default to '''<None>'', Click '''Finish'''. Your Project will now be generated.
 +
<li>Modify the qmake the build file ('''project_name.pro''').</li>
 +
*Copy and paste the following into your .pro file.
 +
<syntaxhighlight lang="text">
 +
TEMPLATE = app
 +
CONFIG += console
 +
CONFIG -= app_bundle
 +
CONFIG -= qt
 +
LIBS +=  -lgpiod
 +
SOURCES += main.c \
 +
    EMAC_Libgpiod.c
 +
target.path=/home/developer
 +
INSTALLS += target
 +
HEADERS += \
 +
    EMAC_Libgpiod.h
 +
 
 +
</syntaxhighlight>
 +
<li>Add the EMAC_Libgpiod.h file</li>
 +
*With you project selected, click '''File->New File or Project''', the New File or Project window will appear.
 +
*Under Files and Classes select General, and in the middle column select '''Empty file''', Click '''Choose...''', The Location window will appear
 +
*Name the file '''EMAC_Libgpiod.h''' and choose your project location as the path, Click '''Next>''' to advance to the Summary window
 +
*Click '''Finish''', the file will now open.
 +
*Copy and paste the provided .h file, [http://git.emacinc.com/OE/qt-creator-example-projects/raw/master/libgpiod_io_example/EMAC_Libgpiod.h EMAC_Libgpiod.h] into
 +
*Save the file, by click '''File->Save All''', the file will now be added to your project under '''Libgpiod_example->Headers'''
 +
<li>Add the EMAC_Libgpiod.c file</li>
 +
*repeat same steps as for the .h file, but replace the file name enter '''EMAC_Libgpiod.c''' and Copy and paste the provided [http://git.emacinc.com/OE/qt-creator-example-projects/raw/master/libgpiod_io_example/EMAC_Libgpiod.c EMAC_Libgpiod.c file]
 +
*select '''File->Save All'''
 +
</ol>
 +
'''Option 2:'''
 +
<ol start = 2>
 +
<li>Create a cmake project</li>
 +
*select '''+ New Project''' on the 'Welcome' window, the New Project window will appear.
 +
*Under Projects select '''EMAC Project''', Under the middle window select '''EMAC C Project (CMake Build)''', Click '''Choose...''', The Location window will appear.
 +
*Name your project '''LibGPIOd_example''', and choose a Create-in location, Click '''Next >''' to advance to the Summary window.
 +
*The options on the Summary window will default to '''<None>'', Click '''Finish'''. Your Project will now be generated.
 +
*Click on the '''Projects''' tab, select only the '''Arm''' option and click '''Configure Project'''. A CMakeLists.txt file will now be generated under the project.
 +
<li>Add the EMAC_Libgpiod.h file</li>
 +
*Under the project folder right click on '''CMakeLists.txt''' and select '''Show Containing Folder''' to open the project directory.
 +
*Save this [http://git.emacinc.com/OE/qt-creator-example-projects/blob/master/libgpiod_io_example/EMAC_Libgpiod.h EMAC_Libgpiod.h file] to the project directory. Do this in git by right clicking on '''Raw''', selecting '''Save link as...''' and choosing the project directory.
 +
<li>Add the [http://git.emacinc.com/OE/qt-creator-example-projects/blob/master/libgpiod_io_example/EMAC_Libgpiod.c EMAC_Libgpiod.c file] in the same way.</li> 
 +
<li>Right click on the project folder and select '''Run CMake''' to add the files to the project.</li>
 +
</ol>
 +
<br />
 +
 
 +
'''End of Options, Continuing:'''<br />
 +
<ol start = 6>
 +
<li>Open main.c under '''LibGPIOd_example->Sources''' and copy and paste the provided [http://git.emacinc.com/OE/qt-creator-example-projects/raw/master/libgpiod_io_example/main.c main.c].</li>
 +
*Note, the program must be configured to run for your target device. In the main.c file select your target device by un-commenting the #define preprocessor directive corresponding to the device '''you're using'''. All other devices should be commented out. For this example we're using a 150ES carrier board so we'll select the '''CARRIER_BOARD_150'''.
 +
 
 +
<syntaxhighlight lang="c">
 +
//In main.c
 +
 
 +
#define CARRIER_BOARD_150
 +
//#define CARRIER_BOARD_200
 +
//#define IPAC               
 +
 
 +
</syntaxhighlight>
 +
 
 +
Similarly, 1 of 4 example programs can be selected to run, example 4 is selected by default, we'll continue with this option.
 +
<syntaxhighlight lang="c">
 +
//In main.c
 +
 
 +
//#define EXAMPLE_1
 +
//#define EXAMPLE_2
 +
//#define EXAMPLE_3
 +
#define EXAMPLE_4
 +
</syntaxhighlight>
 +
 
 +
*select '''File->Save All''', All necessary files have now been added to the project
 +
<li>Configure build options</li>
 +
*Go to '''Tools->Options...''' to open the options window
 +
*Select Devices in the left hand column to open the Devices tab
 +
*From the '''Devices''' tab select '''Devices''' sub-tab and Click '''Add...''' in the right hand column
 +
*Select Generic Linux Device, then click '''Start Wizard'''.
  
To use the '''io demo''' program you will need the following hardware.
+
[[File:Generic_linux.png|600px|left|thumb|Figure 6: Qt Creator Wizard Selection]]
 +
<br clear=all>
  
* An EMAC [http://www.emacinc.com/som/som150es.htm SOM-150ES] carrier board with a compatible SoM <br />
+
*Type in a name, the IP address, the user name, and the password for the device. Use the credentials below to sign in.
OR <br />
 
*An EMC 200 carrier board with a compatible SoM <br />
 
OR
 
* an IPAC <br />
 
OR
 
  
====Carrier Board====
+
{| class="wikitable"
 +
!colspan="2"|Table 4: Default Login Credentials
 +
|-
 +
! Username !! Password
 +
|-
 +
| root || emac_inc
 +
|}
  
[[File:know_your_som_150.jpg|frame|left|SOM-150ES carrier board with GPIO, LEDs and analog IO indicated.]]
+
[[File:Libgpiod_device_config_12.PNG]]
 
<br clear=all>
 
<br clear=all>
  
This is a detail of the '''HDR1 PLD & BUFFERED GPIO''' header. Pin 49 is Vcc. The bottom pins: 2, 4, 6...46, 48, 50; are all ground. Port A is pins 1, 3, 5, 7, 9, 11, 13, 15. Port B is pins 17, 19, 21, 23, 25, 27, 29, 31. Port C is pins 33, 35, 37, 39, 41, 43, 45, 47.  
+
*Click '''Next'''.
  
[[File:gpio_header_detail.png]]
+
*Click '''Finish'''.
  
The output shows the stray charge on the inputs being read by the analog-to-digital converter on pins 11, 12, 13, 14. Press '''a''' a few times to watch the values change.  
+
*A connection will be established with the target device.
  
This is the HDR8 ANALOG IO header.
+
[[File:Device_test.png|600px|left|thumb|Figure 8: Qt Creator Device Test]]
  
[[File:analog_io_header_detail.jpg]]
 
  
Let's do a couple of experiments on our analog in pins.
+
<br clear=all>
  
Connect pin 20 to pin 11 and hit '''a'''. Note that the first value is higher than the others. It should read approximately '''3FF'''. This means that the first analog-in pin has 2.5V on it.
+
*Click '''Close'''.
  
Connect pin 1 to pin 11. Hit '''a'''. Note that the first value is lower than the others. It's the vicinity of 0. That means that the first analog-in pin is pulled down to ground.
+
*Click '''Apply'''.
  
===Count Demo Usage===
+
*Click '''OK'''.
  
From the demo menu press '''c'''.
+
<li>Now, on the left side of Qt Creator, you will see the project icon, which looks like a monitor. Click this and select '''Release''' or '''Debug''' under build.</li>
  
The system counts from 0 to 255 in binary. It takes about 15 seconds to complete.<br />
+
{{note|If multiple build options were selected three sub-menus will appear ('''Kit, Build''' and '''Run'''). Click this and make sure '''Arm Qt5''' is selected under '''Kit''', '''Release''' is selected under '''Build''', and the project is set to be run on the remote device under '''Run'''.
The steps of this process are reflected in the GPIO PortC header pins (see [[Example_io_demo#Carrier_Board | Carrier Board]], above). As each bit in our 8-bit register is set to 1, the corresponding pin in the PortC header momentarily registers 5 volts (easily detected with a multimeter or oscilloscope).
+
}}
 +
 
 +
 
 +
[[File:Libgpiod_14.PNG|600px|left|thumb]]
 +
<br clear=all>
  
More visibly, the counting process is also reflected in the strip of 8 LEDs on the board LD1-LD8. (see [[Example_io_demo#Carrier_Board | Carrier Board]], above). A lit LED indicates a 1 in our 8-bit register and an unlit LED indicates a 0. When the counting process is finished, all 8 LEDs are lit (255).
+
<li>Now, simply press the green play button. The program should run on the target device and yield an output.</li>
  
===Input to Output Demo Usage===
+
</ol>
 +
== Examples ==
 +
As previously stated the main.c program must be configured to run for your target device. In the main.c file select your target device by un-commenting the '''#define''' preprocessor directive corresponding to the device you're using. All other devices should be commented out.
  
In this usage example the carrier board talks to itself. We send an 8-bit data stream directly from Port B to Port C via a short piece of cable. See [[Example_io_demo#Carrier_Board | Carrier Board]], above, for details.
 
  
This is the ribbon cable for the input-to-output demo. Note that we connect PortC:pin0 to PortB:pin0; PortC:pin1 to PortB:pin1; etc.<br />
+
<syntaxhighlight lang="c">
[[File:iodemo_homemaderibboncable.jpg|500px|border|]]
+
//In main.c
  
Here's the cable plugged into the GPIO header. You see that PortC:pin0 outputs to PortB:pin0; PortC:pin1 outputs to PortB:pin1; etc.
+
#define CARRIER_BOARD_150
[[File:iodemo_homemaderibboncable_closeup.jpg|500px|border|]]
+
//#define CARRIER_BOARD_200
 +
//#define IPAC               
  
The data stream for each pin is 1, 0, 1, 0, 1, 0... That is to say: all pins are set to 1, then they are all set to 0, then to 1 again, etc. We observe our data stream in the strip of 8 LEDs on the carrier board. They blink in unison.
+
</syntaxhighlight>
  
'''Note''' The blinking may get a little out of sync after a few seconds. This is normal.
+
Similarly, 1 of 4 example programs can be selected to run, un-comment 1 of the "example" '''#define''' preprocessor directives and leave the rest commented out. Changes these options will require rebuilding of the program (Simply press the green play button again, this should automatically rebuild and launch the project on the target device.)
 +
<syntaxhighlight lang="c">
 +
//In main.c
  
===Usage Example. Ring Demo===
+
//#define EXAMPLE_1
 +
//#define EXAMPLE_2
 +
//#define EXAMPLE_3
 +
#define EXAMPLE_4
 +
</syntaxhighlight>
  
From the demo menu press '''r'''.
 
  
The system sets a bit on Port C to 1, then sets it to 0, then sets the bit after that to 1, then sets that pin to 0, and so on, sequentially. This shows a ring counter on the LED strip (see [[Example_io_demo#Carrier_Board | Carrier Board]], above).
+
All examples use the Libgpiod libary ('''#include <gpiod.h>'''), with example 4 using custom built functions provided in '''EMAC_Libgpiod.h'''. <br />
  
The steps of this process are reflected in the GPIO PortC header pins. As each bit in the 8-bit register is set to 1, the corresponding pin in the PortC header momentarily registers 5 volts (easily detected with a multimeter or oscilloscope).
+
'''EXAMPLE_1''' demonstrates basic IO configuration using Libgpiod's contextless functions <br />
 +
'''EXAMPLE_2''' demonstrates basic IO configuration without contextless functions <br />
 +
'''EXAMPLE_3''' LED demo using only Libgpiod<br />
 +
'''EXAMPLE_4''' LED demo using custom built Libgpiod-based helper functions <br />

Latest revision as of 15:28, 19 July 2019

TODO: {{#todo:SEOKWREV (01.03.14-16:47->JG+);(01.03.14-17:35->MD+);(04.07.14-09:45->BS+);(04.09.14-16:15->BS+)|Jgreene|oe 4,oe 5,jg,md,SEOKWREV,ky,bs}}

This demo covers basic GPIO usage for the IPAC single board computer, and 150 and 200 series carrier boards. This demo first cover GPIO manipulation through the Linux terminal and then demonstrates gpio usage in a C program using an io example program.

GPIO control is accomplished through use of the libgpiod driver, as a result only the libgpiod library will be covered in this tutorial. For manipulation of non-GPIO peripherals use sysfs.


Hardware Requirements

To use the io demo program you will need the following target hardware.

  • An EMAC 150 series carrier board with a compatible SoM

OR

  • An EMAC 200 series carrier board with a compatible SoM

OR

  • An IPAC single board computer

AND

  • additional components to establish to serial and Ethernet connections for your target hardware

Software Requirments

These tools should already be installed if you installed the EMAC SDK using the automatic installer.

Setup

If you haven't already, please review the EMAC_OE_SDK "getting started" page. EMAC_OE_SDK will need to be installed and serial and network connections will need to be established between the developer machine and the target device.See the Serial Connections or Network Connections page for more information on how to connect to the target EMAC product using a serial port or Ethernet connection.

GPIO manipulation through Linux Terminal

GPIOs can be manipulated directly through the target devices serial terminal. The Libgpiod libary is used for this purpose. Linux terminal commands are defined in the libgpiod github readme (https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree) and are listed here for convenience:

"There are currently six command-line tools available:

gpiodetect - list all gpiochips present on the system, their names, labels and number of GPIO lines

gpioinfo - list all lines of specified gpiochips, their names, consumers, direction, active state and additional flags

gpioget - read values of specified GPIO lines

gpioset - set values of specified GPIO lines, potentially keep the lines exported and wait until timeout, user input or signal

gpiofind - find the gpiochip name and line offset given the line name

gpiomon - wait for events on GPIO lines, specify which events to watch,how many events to process before exiting or if the events should be reported to the console"

In libgpiod ports and pins correspond to gpiochips and lines respectively. GPIO chip numbers are assigned by the kernel, and are hardware depended.

GPIO manipulation in C

A more common manipulation of GPIOs is through a C program. The following example will demonstrated GPIO manipulation using the Libgpiod libary.

Program Setup

On the target device:

  1. Login, the default username and password is give below:

    username: root
    password: emac_inc
    
  2. Change the file to read write by entering oemntrw into the device terminal.

    root@somimx6ul:~# oemntrw



    NOTE
    This will only change the root filesystem to read-write for the current boot. When the system is rebooted, the root filesystem will once again be mounted read-only.
  3. Obtain the device IP-address by entering ifconfig into the terminal. This is needed for device configuration in Qt Creator below.

    root@emac-oe:~# ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:50:C2:E6:60:F4
              inet addr:10.0.2.100  Bcast:10.0.255.255  Mask:255.255.0.0
              inet6 addr: fe80::5054:ff:feb1:f83e/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:1825 errors:0 dropped:0 overruns:0 frame:0
              TX packets:553 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:139124 (135.8 KiB)  TX bytes:50603 (49.4 KiB)
              Interrupt:25 Base address:0xc000
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    


On development machine:

  1. Open Qt Creator

Option 1:

  1. Create a qmake project
    • select + New Project on the 'Welcome' window, the New Project window will appear.
    • Under Projects select Non-Qt Project, Under the middle window select Plain C Application, Click Choose..., The Location window will appear.
    • Name your project LibGPIOd_example, and choose a Create-in location, Click Next > to advance to the Build System window.
    • On the Build System Window choose the qmake option, Click Next > to advance to the Kits window.
    • On the Kits window check only ARM Qt5, Click Next > to advance to the Summary window
    • The options on the Summary window will default to <None>, Click Finish'. Your Project will now be generated.
  2. Modify the qmake the build file (project_name.pro).
    • Copy and paste the following into your .pro file.
    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt
    LIBS +=  -lgpiod
    SOURCES += main.c \
        EMAC_Libgpiod.c
    target.path=/home/developer
    INSTALLS += target
    HEADERS += \
        EMAC_Libgpiod.h
    
  3. Add the EMAC_Libgpiod.h file
    • With you project selected, click File->New File or Project, the New File or Project window will appear.
    • Under Files and Classes select General, and in the middle column select Empty file, Click Choose..., The Location window will appear
    • Name the file EMAC_Libgpiod.h and choose your project location as the path, Click Next> to advance to the Summary window
    • Click Finish, the file will now open.
    • Copy and paste the provided .h file, EMAC_Libgpiod.h into
    • Save the file, by click File->Save All, the file will now be added to your project under Libgpiod_example->Headers
  4. Add the EMAC_Libgpiod.c file
    • repeat same steps as for the .h file, but replace the file name enter EMAC_Libgpiod.c and Copy and paste the provided EMAC_Libgpiod.c file
    • select File->Save All

Option 2:

  1. Create a cmake project
    • select + New Project on the 'Welcome' window, the New Project window will appear.
    • Under Projects select EMAC Project, Under the middle window select EMAC C Project (CMake Build), Click Choose..., The Location window will appear.
    • Name your project LibGPIOd_example, and choose a Create-in location, Click Next > to advance to the Summary window.
    • The options on the Summary window will default to <None>, Click Finish'. Your Project will now be generated.
    • Click on the Projects tab, select only the Arm option and click Configure Project. A CMakeLists.txt file will now be generated under the project.
  2. Add the EMAC_Libgpiod.h file
    • Under the project folder right click on CMakeLists.txt and select Show Containing Folder to open the project directory.
    • Save this EMAC_Libgpiod.h file to the project directory. Do this in git by right clicking on Raw, selecting Save link as... and choosing the project directory.
  3. Add the EMAC_Libgpiod.c file in the same way.
  4. Right click on the project folder and select Run CMake to add the files to the project.


End of Options, Continuing:

  1. Open main.c under LibGPIOd_example->Sources and copy and paste the provided main.c.
    • Note, the program must be configured to run for your target device. In the main.c file select your target device by un-commenting the #define preprocessor directive corresponding to the device you're using. All other devices should be commented out. For this example we're using a 150ES carrier board so we'll select the CARRIER_BOARD_150.
    //In main.c
    
    #define CARRIER_BOARD_150 
    //#define CARRIER_BOARD_200
    //#define IPAC
    

    Similarly, 1 of 4 example programs can be selected to run, example 4 is selected by default, we'll continue with this option.

    //In main.c
    
    //#define EXAMPLE_1
    //#define EXAMPLE_2
    //#define EXAMPLE_3
    #define EXAMPLE_4
    
    • select File->Save All, All necessary files have now been added to the project
  2. Configure build options
    • Go to Tools->Options... to open the options window
    • Select Devices in the left hand column to open the Devices tab
    • From the Devices tab select Devices sub-tab and Click Add... in the right hand column
    • Select Generic Linux Device, then click Start Wizard.
    Figure 6: Qt Creator Wizard Selection


    • Type in a name, the IP address, the user name, and the password for the device. Use the credentials below to sign in.
    Table 4: Default Login Credentials
    Username Password
    root emac_inc

    Libgpiod device config 12.PNG

    • Click Next.
    • Click Finish.
    • A connection will be established with the target device.
    Figure 8: Qt Creator Device Test



    • Click Close.
    • Click Apply.
    • Click OK.
  3. Now, on the left side of Qt Creator, you will see the project icon, which looks like a monitor. Click this and select Release or Debug under build.


  4. NOTE
    If multiple build options were selected three sub-menus will appear (Kit, Build and Run). Click this and make sure Arm Qt5 is selected under Kit, Release is selected under Build, and the project is set to be run on the remote device under Run.


    Libgpiod 14.PNG


  5. Now, simply press the green play button. The program should run on the target device and yield an output.

Examples

As previously stated the main.c program must be configured to run for your target device. In the main.c file select your target device by un-commenting the #define preprocessor directive corresponding to the device you're using. All other devices should be commented out.


//In main.c

#define CARRIER_BOARD_150 
//#define CARRIER_BOARD_200
//#define IPAC

Similarly, 1 of 4 example programs can be selected to run, un-comment 1 of the "example" #define preprocessor directives and leave the rest commented out. Changes these options will require rebuilding of the program (Simply press the green play button again, this should automatically rebuild and launch the project on the target device.)

//In main.c

//#define EXAMPLE_1
//#define EXAMPLE_2
//#define EXAMPLE_3
#define EXAMPLE_4


All examples use the Libgpiod libary (#include <gpiod.h>), with example 4 using custom built functions provided in EMAC_Libgpiod.h.

EXAMPLE_1 demonstrates basic IO configuration using Libgpiod's contextless functions
EXAMPLE_2 demonstrates basic IO configuration without contextless functions
EXAMPLE_3 LED demo using only Libgpiod
EXAMPLE_4 LED demo using custom built Libgpiod-based helper functions