<?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>OO Library to handle Pico PIO relative interrupts: usage and example</title><link>/products/raspberry-pi/b/blog/posts/oo-library-to-handle-pico-pio-relative-interrupts</link><description>I made an Object Oriented library that supports handling PIO interrupts with C++ objects.Goal: let a PIO state machine call the very C++ object that can manage (or watch) that particular event.





For who is this library?
It&amp;#39;s m...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: OO Library to handle Pico PIO relative interrupts: usage and example</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/oo-library-to-handle-pico-pio-relative-interrupts</link><pubDate>Wed, 17 Dec 2025 21:21:09 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:0da272cb-ebad-486b-9805-aeff96f7425d</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I like to be confident of my designs - but I&amp;#39;ve been around [emoticon:c4563cd7d5574777a71c318021cbbcc8].&lt;/p&gt;
&lt;p&gt;Dealing with real time&amp;nbsp;and frequent interrupts can be challenging.&lt;br /&gt;I&amp;#39;m using an&amp;nbsp;OO design here -&amp;nbsp;an approach that&amp;#39;s often flagged as risky for embedded designs.&lt;/p&gt;
&lt;p&gt;I trust the code, but prefer to back that up with real world data.&lt;br /&gt;I tested this design on a RP2040, and an RP2350 (in ARM and RISC mode), for a month.&lt;/p&gt;
&lt;p&gt;With all PIO state machines used (8 on a RP2040, 12 on a Pico2), there was not a single interrupt missed, and no memory leakage.&lt;br /&gt;I also tested this with fewer than max PIO state machines deployed. The code has&amp;nbsp;behaved stable all the time.&lt;/p&gt;
&lt;p&gt;It shows that C++26 and GCC are stable. But it also shows that the Pico controllers - and the Raspberry Pico SDK, are sound.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=29161&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: OO Library to handle Pico PIO relative interrupts: usage and example</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/oo-library-to-handle-pico-pio-relative-interrupts</link><pubDate>Fri, 07 Nov 2025 16:50:06 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:0da272cb-ebad-486b-9805-aeff96f7425d</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;In the example that I attached to the post, I program each PIO, and initiate each state machine individually:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:df5cc185-7d76-43b4-beeb-0a4ab61e700a:type=c_cpp&amp;text=%20%20%20%20%2F%2F%20program%20each%20PIO%2C%20and%20initialise%20each%20sm%0A%20%20%20%20uint%20offset%20%20%3D%200U%3B%0A%0A%20%20%20%20offset%20%3D%20pio_add_program%28pio0%2C%20%26run_program%29%3B%0A%20%20%20%20run_program_init%28pio0%2C%200%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio0%2C%201%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio0%2C%202%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio0%2C%203%2C%20offset%29%3B%0A%20%20%20%20offset%20%3D%20pio_add_program%28pio1%2C%20%26run_program%29%3B%0A%20%20%20%20run_program_init%28pio1%2C%200%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio1%2C%201%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio1%2C%202%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio1%2C%203%2C%20offset%29%3B%0A%23if%20%28NUM_PIOS%20%3E%202%29%20%2F%2F%20pico%202%0A%20%20%20%20offset%20%3D%20pio_add_program%28pio2%2C%20%26run_program%29%3B%0A%20%20%20%20run_program_init%28pio2%2C%200%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio2%2C%201%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio2%2C%202%2C%20offset%29%3B%0A%20%20%20%20run_program_init%28pio2%2C%203%2C%20offset%29%3B%0A%23endif%20%20%20%20]&lt;/p&gt;
&lt;p&gt;When you use the c++ standard library, you could do this&amp;nbsp;differently.&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:6acc9203-6fb8-4012-a934-8dc06e21420f:type=csharp&amp;text=%20%20%20%20%2F%2F%20program%20each%20PIO%2C%20and%20initialise%20each%20sm%0D%0A%20%20%20%20for%20%28uint%20u%20%3D%200u%3B%20u%20%3C%20NUM_PIOS%3B%20u%2B%2B%29%20%7B%0D%0A%20%20%20%20%20%20%20%20uint%20offset%20%20%3D%20pio_add_program%28PIO_INSTANCE%28u%29%2C%20%26run_program%29%3B%20%0D%0A%20%20%20%20%20%20%20%20for%28auto%20%26h%20%3A%20handlers%20%7C%20std%3A%3Aviews%3A%3Afilter%28%5Bu%5D%28const%20auto%26%20h%29%7B%20return%20h.pio%20%3D%3D%20PIO_INSTANCE%28u%29%3B%7D%29%29%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20run_program_init%28h.pio%2C%20h.sm%2C%20offset%29%3B%0D%0A%20%20%20%20%20%20%20%20%7D%20%20%0D%0A%20%20%20%20%7D]&lt;/p&gt;
&lt;p&gt;This uses a range filter. It &amp;#39;ll only return handler objects assigned to&amp;nbsp;a particular PIO.&lt;/p&gt;
&lt;p&gt;For each PIO, it&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;programs that PIO&lt;/li&gt;
&lt;li&gt;checks the handler container if there are any state machines for that PIO&lt;/li&gt;
&lt;li&gt;if yes, initialises those state machines&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is all embedded friendly. Each option has its pros and cons. But no excessive resource usage - this is all cheap on the cycles.&lt;/p&gt;
&lt;p&gt;opinion?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;img src="https://community.element14.com/aggbug?PostID=29161&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: OO Library to handle Pico PIO relative interrupts: usage and example</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/oo-library-to-handle-pico-pio-relative-interrupts</link><pubDate>Thu, 28 Aug 2025 20:43:22 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:0da272cb-ebad-486b-9805-aeff96f7425d</guid><dc:creator>DAB</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Great post Jan.&lt;/p&gt;
&lt;p&gt;I am curious, do you have an implementation that actually uses seven stepper motors?&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=29161&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: OO Library to handle Pico PIO relative interrupts: usage and example</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/oo-library-to-handle-pico-pio-relative-interrupts</link><pubDate>Wed, 27 Aug 2025 21:11:59 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:0da272cb-ebad-486b-9805-aeff96f7425d</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&amp;nbsp;[mention:f92905a7470f4b3e9f2dbfcd6cdd918f:f7d226abd59f475c9d224a79e3f0ec07]&amp;nbsp;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=29161&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>