<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>device driver API</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84708/device-driver-api</link><description>i just have a quick basic question about the device driver API, why does the samples/drivers/i2c_fujitsu_fram application not use a device tree node for the i2c peripheral? (with the &amp;lt;reg&amp;gt; address set to the i2c chip address and so on) i&amp;#39;ve seen explanations</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Feb 2022 10:31:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84708/device-driver-api" /><item><title>RE: device driver API</title><link>https://devzone.nordicsemi.com/thread/352839?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 10:31:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9dc86da-3b19-4245-ba4d-2c1e734af5d2</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;The sample you are referring to is using Zephyr&amp;#39;s Devicetree API to access the I2C peripheral, which is the recommended method for accessing peripherals in Zephyr.&lt;/p&gt;
&lt;p&gt;In the application the device is defined like this:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;I2C_DEV&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;DT_LABEL&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;DT_ALIAS&lt;/span&gt;&lt;span&gt;(i2c_0))&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;~~~~&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;device&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;i2c_dev&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;i2c_dev&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;device_get_binding&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;I2C_DEV&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;This code finds hardware specifications in the board specific devicetree file, and saves them in a device struct which is then used to access the device in the application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Putting the hardware specifications in a devicetree file makes your code more portable, because you can compile your application for a different board just by changing the devicetree overlay, while using the same application code.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;You ca read more about Zephyr&amp;#39;s devicetree here:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;a href="https://docs.zephyrproject.org/latest/guides/dts/intro.html"&gt;https://docs.zephyrproject.org/latest/guides/dts/intro.html&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;a href="http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/reference/devicetree/api.html"&gt;http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/reference/devicetree/api.html&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Hope this helps, best regards,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Einar&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>