<?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>Object Oriented example for the Data Acquisition Board for Pi Pico</title><link>/products/raspberry-pi/raspberrypi_projects/b/blog/posts/object-oriented-example-for-the-data-acquisition-board-for-pi-pico</link><description>shabaz designed a Data Acquisition Board for Pi Pico . In this post, I&amp;#39;m building a C++ class for the ADC. And I turn my continuous sample exercise into an OO one. Goal: investigate if it&amp;#39;s up to handling 1 second...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Object Oriented example for the Data Acquisition Board for Pi Pico</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/object-oriented-example-for-the-data-acquisition-board-for-pi-pico</link><pubDate>Wed, 20 Dec 2023 11:24:45 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:579f804a-5548-48b3-836a-ff6fb6a709dc</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Follow-up:&amp;nbsp;&amp;nbsp;[mention:ff4ffc78cae84182b8cac557a297596f:f7d226abd59f475c9d224a79e3f0ec07]&amp;nbsp;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27356&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Object Oriented example for the Data Acquisition Board for Pi Pico</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/object-oriented-example-for-the-data-acquisition-board-for-pi-pico</link><pubDate>Mon, 18 Dec 2023 15:57:11 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:579f804a-5548-48b3-836a-ff6fb6a709dc</guid><dc:creator>shabaz</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hi Jan,&lt;/p&gt;
&lt;p&gt;This is a pretty detailed example of using STL and it&amp;#39;s all microcontroller-friendly. This is a superb article that I&amp;#39;m going to make use of, since I mostly stick with the few STL features I&amp;#39;m familiar with (e.g. vector, map, pair) and need to learn more of them. Also some very neat features used in the coding, e.g. enum class, I&amp;#39;ve not seen before.&lt;/p&gt;
&lt;p&gt;Although the code here is useful for those using the ADS111x series of chips, it&amp;#39;s a great resource for anyone to simply study the code and apply the techniques elsewhere.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27356&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Object Oriented example for the Data Acquisition Board for Pi Pico</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/object-oriented-example-for-the-data-acquisition-board-for-pi-pico</link><pubDate>Mon, 18 Dec 2023 15:34:39 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:579f804a-5548-48b3-836a-ff6fb6a709dc</guid><dc:creator>ggabe</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;What do you think of encapsulating the buffer into a new object? Along with the different ways of accessing/representing it.&amp;nbsp;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27356&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Object Oriented example for the Data Acquisition Board for Pi Pico</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/object-oriented-example-for-the-data-acquisition-board-for-pi-pico</link><pubDate>Mon, 18 Dec 2023 14:00:59 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:579f804a-5548-48b3-836a-ff6fb6a709dc</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;for type safe use of the enumerators with the Pico C api, I made these controlled type casters:&lt;/p&gt;
&lt;div&gt;
&lt;pre&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; // safe conversions, only available within the class implementation&lt;br /&gt;&lt;/span&gt;&lt;span&gt;    inline&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;operator()&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;addr&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)a;}&lt;br /&gt;&lt;/span&gt;&lt;span&gt;    inline&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;addr&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;operator()&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;assert&lt;/span&gt;&lt;span&gt;(a &amp;gt;= (*&lt;/span&gt;&lt;span&gt;this&lt;/span&gt;&lt;span&gt;)(&lt;/span&gt;&lt;span&gt;addr&lt;/span&gt;&lt;span&gt;::A_0) &amp;amp;&amp;amp; a &amp;lt; (*&lt;/span&gt;&lt;span&gt;this&lt;/span&gt;&lt;span&gt;)(&lt;/span&gt;&lt;span&gt;addr&lt;/span&gt;&lt;span&gt;::A_LAST));&lt;/span&gt;&lt;span&gt; // debug support&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; &amp;nbsp;(addr)a;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;inline&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;operator()&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;reg&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;r&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)r;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;inline&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;operator()&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;data_rate&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;dr&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)dr;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;inline&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;operator()&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;gain&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;g&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)g;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;inline&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;operator()&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;channel&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;c&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)c;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;inline&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;operator()&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;diff&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;d&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;)d;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;In code, this removes the explicit typedefs in the implementation. A few examples:&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;from:&lt;/div&gt;
&lt;pre&gt;adc_confreg[1] |= ((uint8_t)dr &amp;lt;&amp;lt; 5); // set the DR bits&lt;/pre&gt;
&lt;div&gt;to:&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;pre&gt;&lt;span&gt;adc_confreg&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;] |= ((*&lt;/span&gt;&lt;span&gt;this&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;dr&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; &amp;lt;&amp;lt; &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;span&gt; // set the DR bits&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;from:&lt;/div&gt;
&lt;pre&gt;i2c_write_blocking(i2c_port, (uint8_t)address, buf, 3, false);&lt;/pre&gt;
&lt;div&gt;to:&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;pre&gt;&lt;span&gt;i2c_write_blocking&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;i2c_port&lt;/span&gt;&lt;span&gt;, (*&lt;/span&gt;&lt;span&gt;this&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;address&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;3&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;false&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;It doesn&amp;#39;t cost more runtime or code space.&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;I explicitly declared them private. The developer isn&amp;#39;t supposed to convert the strongly typed constants. But it&amp;#39;s needed to translate into the lower leve Pico C SDK APIs.&lt;/div&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27356&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>