<?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>Port an MBED design to non-MBED - Phase 5: OO Callbacks Simplified</title><link>/technologies/embedded/b/blog/posts/port-an-mbed-design-to-non-mbed---phase-5-oo-callbacks-simplified</link><description>I&amp;#39;m playing with object oriented firmware for embedded controllers.In this blog I review object oriented callbacks. How to invoke the correct function of the correct object. I&amp;#39;ve been using the C / C++ mix for a decent time now, with good result...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Port an MBED design to non-MBED - Phase 5: OO Callbacks Simplified</title><link>https://community.element14.com/technologies/embedded/b/blog/posts/port-an-mbed-design-to-non-mbed---phase-5-oo-callbacks-simplified</link><pubDate>Tue, 03 Nov 2020 20:19:08 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:0a08d8fc-58d4-439a-b320-4a3ad08212c8</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I was going to write a follow up blog. But I can conclude this in the comments too. It&amp;#39;s a 3 star post anyways so not going to burn more energy.&lt;/p&gt;&lt;p&gt;There are 2 use cases.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;The calling object knows it&amp;#39;s going to be called by an interrupt or timer, and will deal with the context.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;In that case, we use a low level api. We pass the object pointer and a static function reference:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The &amp;quot;class to be called has to have a special static member that&amp;#39;s &amp;quot;in the know&amp;quot;&lt;/p&gt;&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3ef06e6b-9b7d-4651-b12d-db8be7f5e991:type=c_cpp&amp;amp;text=protected%3A%0A++static+void+_timeouthandler%28uint32_t+id%29%3B%0A++Callback%3Cvoid%28%29%3E+_function%3B]&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The implementation of the handler has to know how to translate that again into an object instance, and call the member:&lt;/p&gt;&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3ef06e6b-9b7d-4651-b12d-db8be7f5e991:type=c_cpp&amp;amp;text=void+Timeout%3A%3A_timeouthandler%28uint32_t+id%29+%7B%0A++Timeout+*handler+%3D+%28Timeout*%29id%3B%0A++Callback%3Cvoid%28%29%3E+local+%3D+handler-%3E_function%3B%0A++handler-%3Edetach%28%29%3B%0A++local.call%28%29%3B%0A%7D]&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;When using the full object oriented way&lt;/strong&gt;, where the compiler can do some work for us:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3ef06e6b-9b7d-4651-b12d-db8be7f5e991:type=c_cpp&amp;amp;text=++%2F%2F+Initialize+Radio+driver%0A++RadioEvents.TxDone+%3D+OnTxDone%3B%0A%2F%2F+...%0A++++dio0.rise%28+callback%28+this%2C+static_cast%3C+TriggerMB1xAS+%3E+%28+irqHandlers%5B0%5D+%29+%29+%29%3B]&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The object and method that are called don&amp;#39;t have to know that there&amp;#39;s a timer or interrupt involved. A normal class member will do.&lt;/p&gt;&lt;p&gt;The difference is there for those that appreciate it. No explicit rendering an object to a void pointer.&amp;nbsp; Strong typing all the way (with the developer protection by compiler instead of debugger that comes with that) without runtime overhead.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=10194&amp;AppID=7&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Port an MBED design to non-MBED - Phase 5: OO Callbacks Simplified</title><link>https://community.element14.com/technologies/embedded/b/blog/posts/port-an-mbed-design-to-non-mbed---phase-5-oo-callbacks-simplified</link><pubDate>Tue, 03 Nov 2020 18:50:12 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:0a08d8fc-58d4-439a-b320-4a3ad08212c8</guid><dc:creator>DAB</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Nice update Jan.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;DAB&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=10194&amp;AppID=7&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>