<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C++ gpio library for Raspberry Pi - Pt 2: Plug In drivers for direct register GPIO, or file system based GPIO</title><link>/products/raspberry-pi/b/blog/posts/c-gpio-library-for-raspberry-pi---pt-2-plug-in-drivers-for-direct-register-gpio-or-file-system-based-gpio</link><description>An exercise to build a C++ library for the GPIO pins. The programmer can decide what underlying mechanism is used to talk to the pins. In this second post, 3 mechanism are supported:

register access via memmap
the sysfs inter...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: C++ gpio library for Raspberry Pi - Pt 2: Plug In drivers for direct register GPIO, or file system based GPIO</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/c-gpio-library-for-raspberry-pi---pt-2-plug-in-drivers-for-direct-register-gpio-or-file-system-based-gpio</link><pubDate>Sat, 06 Jan 2024 20:16:08 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:719db582-3857-4e7d-93b4-1c6932327480</guid><dc:creator>DAB</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Great update Jan.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27412&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: C++ gpio library for Raspberry Pi - Pt 2: Plug In drivers for direct register GPIO, or file system based GPIO</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/c-gpio-library-for-raspberry-pi---pt-2-plug-in-drivers-for-direct-register-gpio-or-file-system-based-gpio</link><pubDate>Sat, 06 Jan 2024 18:34:57 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:719db582-3857-4e7d-93b4-1c6932327480</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;This little test program lets you set or read a pin:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:56d2c67d-37d8-49f8-b8c8-3206ccf1ccac:type=c_cpp&amp;text=%2F%2F%20uncomment%20the%20gpio%20handler%20that%20you%20want%20to%20use%0D%0A%2F%2F%23define%20DPGIO_SYSFS_FILEHANDLER%0D%0A%23define%20DPGIO_SYSFS_STREAM%0D%0A%2F%2F%23define%20DPGIO_MEMMAP%0D%0A%0D%0A%23include%20%22pin.h%22%0D%0A%0D%0A%23if%20defined%20DPGIO_SYSFS_FILEHANDLER%0D%0A%23include%20%3Csysfsdevice_filehandler.h%3E%0D%0Atypedef%20dgpio%3A%3Apin%3Cdgpio%3A%3Asysfsdevice_filehandler%3E%20pin%3B%0D%0A%23elif%20defined%20DPGIO_SYSFS_STREAM%0D%0A%23include%20%22sysfsdevice_stream.h%22%0D%0Atypedef%20dgpio%3A%3Apin%3Cdgpio%3A%3Asysfsdevice_stream%3E%20pin%3B%0D%0A%23elif%20defined%20DPGIO_MEMMAP%0D%0A%23include%20%22memmapdevice.h%22%0D%0Atypedef%20dgpio%3A%3Apin%3Cdgpio%3A%3Amemmapdevice%3E%20pin%3B%0D%0A%23endif%0D%0A%0D%0A%23include%20%3Cstdlib.h%3E%20%20%20%20%20%2F%2A%20atoi%20%2A%2F%0D%0Aint%20main%28int%20argc%2C%20char%20%2Aconst%20%2Aargv%29%20%7B%0D%0A%20%20%20%20if%20%28argc%20%3C%202%29%20%7B%0D%0A%09%09return%20-1%3B%0D%0A%20%20%20%20%7D%0D%0A%0D%0A%20%20%20%20int%20retval%20%3D%200%3B%0D%0A%0D%0A%20%20%20%20unsigned%20int%20gpio%20%3D%20atoi%28argv%5B1%5D%29%3B%0D%0A%20%20%20%20pin%3A%3Adir%20dir%20%3D%20pin%3A%3Adir%3A%3Ain%3B%0D%0A%20%20%20%20pin%3A%3Astatus%20status%20%3D%20pin%3A%3Astatus%3A%3Aoff%3B%0D%0A%0D%0A%20%20%20%20if%20%28argc%20%3D%3D%203%29%20%7B%20%2F%2F%20out%0D%0A%20%20%20%20%09dir%20%3D%20pin%3A%3Adir%3A%3Aout%3B%0D%0A%20%20%20%20%09if%20%28atoi%28argv%5B2%5D%29%20%3D%3D%201%29%20%7B%0D%0A%20%20%20%20%09%09status%20%3D%20pin%3A%3Astatus%3A%3Aon%3B%0D%0A%20%20%20%20%09%7D%0D%0A%20%20%20%20%7D%0D%0A%0D%0A%09pin%20p%20%3D%20pin%28gpio%29%3B%0D%0A%09p.init%28dir%29%3B%0D%0A%0D%0A%09if%20%28dir%20%3D%3D%20pin%3A%3Adir%3A%3Ain%29%20%7B%0D%0A%09%09pin%3A%3Astatus%20s%20%3D%20p.get%28%29%3B%0D%0A%09%09retval%20%3D%20s%20%3D%3D%20pin%3A%3Astatus%3A%3Aon%20%3F%201%20%3A%200%3B%0D%0A%09%7D%20else%20%7B%0D%0A%09%09p.set%28status%29%3B%0D%0A%09%7D%0D%0A%0D%0A%09p.deinit%28%29%3B%0D%0A%09return%20retval%3B%0D%0A%7D%0D%0A%0D%0A]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;to read a pin:&lt;/p&gt;
&lt;pre&gt;./device_gpio 21&lt;/pre&gt;
&lt;p&gt;the return value holds the state, and can be retrieved:&lt;/p&gt;
&lt;pre&gt;echo $?&lt;/pre&gt;
&lt;p&gt;to set a pin high:&lt;/p&gt;
&lt;pre&gt;./device_gpio 21 1&lt;/pre&gt;
&lt;p&gt;to set a pin low:&lt;/p&gt;
&lt;pre&gt;./device_gpio 21&amp;nbsp;0&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Test with a real GPIO pin please&amp;nbsp;[emoticon:44a8a53ad3364ea78a16c5a3229f75bb]&amp;nbsp;- the program will happily set any&amp;nbsp;Broadcom BCMxxx CPU pin below 30, or change its function to GPIO.&lt;/p&gt;
&lt;p&gt;No root needed, but you have to be in the gpio group.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27412&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: C++ gpio library for Raspberry Pi - Pt 2: Plug In drivers for direct register GPIO, or file system based GPIO</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/c-gpio-library-for-raspberry-pi---pt-2-plug-in-drivers-for-direct-register-gpio-or-file-system-based-gpio</link><pubDate>Fri, 05 Jan 2024 14:31:52 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:719db582-3857-4e7d-93b4-1c6932327480</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;fun fact: you can use one driver for pin A, and another for pin B. The only thing you have to do is make the two typedefs unique. Example:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:9ed23e88-45d5-4268-b0b8-5065d3475fb7:type=c_cpp&amp;text=%23include%20%22pin.h%22%0A%0A%23include%20%22sysfsdevice_stream.h%22%0Atypedef%20dgpio%3A%3Apin%3Cdgpio%3A%3Asysfsdevice_stream%3E%20fs_pin%3B%0A%0A%23include%20%22memmapdevice.h%22%0Atypedef%20dgpio%3A%3Apin%3Cdgpio%3A%3Amemmapdevice%3E%20reg_pin%3B%0A%0A%2F%2F%20...%0A%0A%09fs_pin%20p21%20%3D%20fs_pin%2821%29%3B%0A%09reg_pin%20p23%20%3D%20reg_pin%2823%29%3B%0A%0A%2F%2F%20...]&lt;/p&gt;
&lt;p&gt;Is that useful? Who knows&amp;nbsp;[emoticon:c4563cd7d5574777a71c318021cbbcc8]&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27412&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: C++ gpio library for Raspberry Pi - Pt 2: Plug In drivers for direct register GPIO, or file system based GPIO</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/c-gpio-library-for-raspberry-pi---pt-2-plug-in-drivers-for-direct-register-gpio-or-file-system-based-gpio</link><pubDate>Fri, 05 Jan 2024 12:25:54 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:719db582-3857-4e7d-93b4-1c6932327480</guid><dc:creator>BigG</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Not sure if helpful, but I know Adafruit&amp;#39;s Circuit Python library for the Raspberry Pi uses libgpiod. &lt;a id="" href="https://github.com/adafruit/Adafruit_Blinka" rel="noopener noreferrer nofollow" target="_blank" data-e14adj="t"&gt;https://github.com/adafruit/Adafruit_Blinka&lt;/a&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27412&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>