| |
| |
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| |
| |
| |
| <title>Sensor API — Apache Mynewt latest documentation</title> |
| |
| |
| |
| |
| <link rel="shortcut icon" href="../../../_static/mynewt-logo-only-newt32x32.png"/> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" /> |
| |
| |
| <link rel="stylesheet" href="../../../_static/css/sphinx_theme.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/bootstrap-3.0.3.min.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/v2.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/restructuredtext.css" type="text/css" /> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../../_static/css/overrides.css" type="text/css" /> |
| <link rel="index" title="Index" |
| href="../../../genindex.html"/> |
| <link rel="search" title="Search" href="../../../search.html"/> |
| <link rel="top" title="Apache Mynewt latest documentation" href="../../../index.html"/> |
| |
| |
| <script src="../../../_static/js/modernizr.min.js"></script> |
| |
| |
| <script> |
| (function(i, s, o, g, r, a, m) { |
| i["GoogleAnalyticsObject"] = r; |
| (i[r] = |
| i[r] || |
| function() { |
| (i[r].q = i[r].q || []).push(arguments); |
| }), |
| (i[r].l = 1 * new Date()); |
| (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); |
| a.async = 1; |
| a.src = g; |
| m.parentNode.insertBefore(a, m); |
| })(window, document, "script", "//www.google-analytics.com/analytics.js", "ga"); |
| |
| ga("create", "UA-72162311-1", "auto"); |
| ga("send", "pageview"); |
| </script> |
| |
| |
| </head> |
| |
| <body class="not-front page-documentation" role="document" > |
| <div id="wrapper"> |
| <div class="container"> |
| <div id="banner" class="row v2-main-banner"> |
| <a class="logo-cell" href="/"> |
| <img class="logo" src="../../../_static/img/logo.png"> |
| </a> |
| <div class="tagline-cell"> |
| <h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4> |
| </div> |
| <div class="news-cell"> |
| <div class="well"> |
| <h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.12.0, Apache NimBLE 1.7.0 </a> released April 4, 2024) |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <header> |
| <nav id="navbar" class="navbar navbar-inverse" role="navigation"> |
| <div class="container"> |
| <!-- Collapsed navigation --> |
| <div class="navbar-header"> |
| <!-- Expander button --> |
| <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| |
| </div> |
| |
| <!-- Expanded navigation --> |
| <div class="navbar-collapse collapse"> |
| <!-- Main navigation --> |
| <ul class="nav navbar-nav navbar-right"> |
| <li> |
| <a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a> |
| </li> |
| <li class="important"> |
| <a href="/quick-start/">Quick Start</a> |
| </li> |
| <li> |
| <a href="/about/">About</a> |
| </li> |
| <li> |
| <a href="/talks/">Talks</a> |
| </li> |
| <li class="active"> |
| <a href="/documentation/">Documentation</a> |
| </li> |
| <li> |
| <a href="/download/">Download</a> |
| </li> |
| <li> |
| <a href="/community/">Community</a> |
| </li> |
| <li> |
| <a href="/events/">Events</a> |
| </li> |
| </ul> |
| |
| <!-- Search, Navigation and Repo links --> |
| <ul class="nav navbar-nav navbar-right"> |
| |
| </ul> |
| </div> |
| </div> |
| </nav> |
| </header> |
| <!-- STARTS MAIN CONTENT --> |
| <div id="main-content"> |
| |
| |
| |
| |
| |
| |
| <div id="breadcrumb"> |
| <div class="container"> |
| <a href="/documentation/">Docs</a> / |
| |
| Sensor API |
| |
| <div class="sourcelink"> |
| <a href="https://github.com/apache/mynewt-core/edit/master/docs/os/modules/sensor_framework/sensor_api.rst" class="icon icon-github" |
| rel="nofollow"> Edit on GitHub</a> |
| </div> |
| </div> |
| </div> |
| <!-- STARTS CONTAINER --> |
| <div class="container"> |
| <!-- STARTS .content --> |
| <div id="content" class="row"> |
| |
| <!-- STARTS .container-sidebar --> |
| <div class="container-sidebar col-xs-12 col-sm-3"> |
| <div id="docSidebar" class="sticky-container"> |
| <div role="search" class="sphinx-search"> |
| <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search documentation" class="search-documentation" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| <!-- Note: only works when deployed --> |
| <select class="form-control" onchange="if (this.value) window.location.href=this.value"> |
| <option value="/latest" selected> |
| Version: latest |
| </option> |
| <option value="/v1_12_0" > |
| Version: 1.12.0 |
| </option> |
| <option value="/v1_11_0" > |
| Version: 1.11.0 |
| </option> |
| <option value="/v1_10_0" > |
| Version: 1.10.0 |
| </option> |
| <option value="/v1_9_0" > |
| Version: 1.9.0 |
| </option> |
| <option value="/v1_8_0" > |
| Version: 1.8.0 |
| </option> |
| <option value="/v1_7_0" > |
| Version: 1.7.0 |
| </option> |
| <option value="/v1_6_0" > |
| Version: 1.6.0 |
| </option> |
| <option value="/v1_5_0" > |
| Version: 1.5.0 |
| </option> |
| <option value="/v1_4_0" selected="selected" > |
| Version: 1.4.0 |
| </option> |
| <option value="/v1_3_0/os/introduction" > |
| Version: 1.3.0 |
| </option> |
| <option value="/v1_2_0/os/introduction" > |
| Version: 1.2.0 |
| </option> |
| <option value="/v1_1_0/os/introduction" > |
| Version: 1.1.0 |
| </option> |
| <option value="/v1_0_0/os/introduction" > |
| Version: 1.0.0 |
| </option> |
| <option value="/v0_9_0/os/introduction" > |
| Version: 0.9.0 |
| </option> |
| </select> |
| <div class="region region-sidebar"> |
| <div class="docs-menu"> |
| |
| |
| |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../../../index.html">Introduction</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../get_started/index.html">Setup & Get Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../concepts.html">Concepts</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../tutorials/tutorials.html">Tutorials</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../external_links.html">Third-party Resources</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../os_user_guide.html">OS User Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../network/index.html">BLE User Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../newt/index.html">Newt Tool Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../newtmgr/index.html">Newt Manager Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../mynewt_faq/index.html">Mynewt FAQ</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../misc/index.html">Appendix</a></li> |
| </ul> |
| |
| |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS STICKY CONTAINER --> |
| </div> |
| <!-- ENDS .container-sidebar --> |
| |
| <div class="col-xs-12 col-sm-9"> |
| |
| <div class="alert alert-warning"> |
| <p> |
| Version 1.4.0 is not the most recent version of the |
| Apache Mynewt documentation. Click <a href="/latest">here</a> to |
| read the latest version. |
| </p> |
| </div> |
| |
| |
| |
| <div class=""> |
| <div class="rst-content"> |
| <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| <div itemprop="articleBody"> |
| |
| <div class="section" id="sensor-api"> |
| <h1>Sensor API<a class="headerlink" href="#sensor-api" title="Permalink to this headline">¶</a></h1> |
| <p>The sensor API implements the sensor abstraction and the functions:</p> |
| <ul class="simple"> |
| <li><p>For a sensor device driver package to initialize a sensor object with |
| the device specific information.</p></li> |
| <li><p>For an application to read sensor data from a sensor and to configure |
| a sensor for polling.</p></li> |
| </ul> |
| <p>A sensor is represented by the <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">sensor</span></code> object.</p> |
| <div class="section" id="sensor-api-functions-used-by-a-sensor-device-driver-package"> |
| <h2>Sensor API Functions Used by a Sensor Device Driver Package<a class="headerlink" href="#sensor-api-functions-used-by-a-sensor-device-driver-package" title="Permalink to this headline">¶</a></h2> |
| <p>A sensor device driver package must use the sensor API to initialize |
| device specific information for a sensor object and to change sensor |
| configuration types.</p> |
| <div class="section" id="initializing-a-sensor-object"> |
| <h3>Initializing a Sensor Object<a class="headerlink" href="#initializing-a-sensor-object" title="Permalink to this headline">¶</a></h3> |
| <p>When the BSP or the sensor creator package creates an OS device for a |
| sensor named <code class="docutils literal notranslate"><span class="pre">SENSORNAME</span></code>, it specifies the <code class="docutils literal notranslate"><span class="pre"><sensorname>_init()</span></code> |
| callback function, that the device driver exports, for the |
| <code class="docutils literal notranslate"><span class="pre">os_dev_create()</span></code> function to call to initialize the device. The |
| <code class="docutils literal notranslate"><span class="pre"><sensorname>_init()</span></code> function must use the following sensor API |
| functions to set the driver and interface information in the sensor |
| object:</p> |
| <ul class="simple"> |
| <li><p>The <code class="docutils literal notranslate"><span class="pre">sensor_init()</span></code> function to initialize the <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">sensor</span></code> |
| object for the device.</p></li> |
| <li><p>The <code class="docutils literal notranslate"><span class="pre">sensor_set_driver()</span></code> function to set the types that the sensor |
| device supports and the sensor driver functions to read the sensor |
| data from the device and to retrieve the value type for a given |
| sensor type.</p></li> |
| <li><p>The <code class="docutils literal notranslate"><span class="pre">sensor_set_interface()</span></code> function to set the interface to use |
| to communicate with the sensor device.</p></li> |
| </ul> |
| <p><strong>Notes</strong>:</p> |
| <ul class="simple"> |
| <li><p>See the <a class="reference external" href="/os/modules/sensor_framework/sensor_driver.html">Sensor Device |
| Driver</a> page for |
| the functions and data structures that a sensor driver package |
| exports.</p></li> |
| <li><p>The <code class="docutils literal notranslate"><span class="pre"><sensorname>_init()</span></code> function must also call the |
| <code class="docutils literal notranslate"><span class="pre">sensor_mgr_register()</span></code> function to register the sensor with the |
| sensor manager. See the <a class="reference external" href="/os/modules/sensor_framework/sensor_manager_api.html">Sensor Manager |
| API</a> for |
| details.</p></li> |
| </ul> |
| </div> |
| <div class="section" id="setting-the-configured-sensor-types"> |
| <h3>Setting the Configured Sensor Types<a class="headerlink" href="#setting-the-configured-sensor-types" title="Permalink to this headline">¶</a></h3> |
| <p>The BSP, or the sensor creator package, also calls the |
| <code class="docutils literal notranslate"><span class="pre"><sensorname>_config()</span></code> function to configure the sensor device with |
| default values. The <code class="docutils literal notranslate"><span class="pre"><sensorname>_config()</span></code> function is exported by |
| the sensor device driver and must call the sensor API |
| <code class="docutils literal notranslate"><span class="pre">sensor_set_type_mask()</span></code> function to set the configured sensor types |
| in the sensor object. The configured sensor types are a subset of the |
| sensor types that the device supports. The sensor framework must know |
| the sensor types that a sensor device is configured for because it only |
| reads sensor data for the configured sensor types.</p> |
| <p><strong>Note:</strong> An application may also call the <code class="docutils literal notranslate"><span class="pre"><sensorname>_config()</span></code> |
| function to configure the sensor device.</p> |
| </div> |
| </div> |
| <div class="section" id="sensor-api-functions-used-by-an-application"> |
| <h2>Sensor API Functions Used By an Application<a class="headerlink" href="#sensor-api-functions-used-by-an-application" title="Permalink to this headline">¶</a></h2> |
| <p>The sensor API provides the functions for an application to read sensor |
| data from a sensor and to configure a sensor for polling.</p> |
| <div class="section" id="reading-sensor-data"> |
| <h3>Reading Sensor Data<a class="headerlink" href="#reading-sensor-data" title="Permalink to this headline">¶</a></h3> |
| <p>An application calls the <code class="docutils literal notranslate"><span class="pre">sensor_read()</span></code> function to read sensor data |
| from a sensor device. You specify a bit mask of the configured sensor |
| types to read from a sensor device and a callback function to call when |
| the sensor data is read. The callback is called for each specified |
| configured type and the data read for that sensor type is passed to the |
| callback.</p> |
| </div> |
| <div class="section" id="setting-a-poll-rate-for-a-sensor"> |
| <h3>Setting a Poll Rate for A Sensor<a class="headerlink" href="#setting-a-poll-rate-for-a-sensor" title="Permalink to this headline">¶</a></h3> |
| <p>The sensor manager implements a poller that reads sensor data from a |
| sensor at specified poll intervals. An application must call the |
| <code class="docutils literal notranslate"><span class="pre">sensor_set_poll_rate_ms()</span></code> function to set the poll rate for a sensor |
| in order for poller to poll the sensor.</p> |
| <p><strong>Note:</strong> An application needs to register a <a class="reference external" href="/os/modules/sensor_framework/sensor_listener_api.html">sensor |
| listener</a> to |
| receive the sensor data that the sensor manager poller reads from a |
| sensor.</p> |
| </div> |
| </div> |
| <div class="section" id="data-structures"> |
| <h2>Data Structures<a class="headerlink" href="#data-structures" title="Permalink to this headline">¶</a></h2> |
| <p>We list the main data structures that the sensor API uses and mention |
| things to note. For more details, see the |
| <a class="reference external" href="https://github.com/apache/mynewt-core/blob/master/hw/sensor/include/sensor/sensor.h">sensor.h</a> |
| include file.</p> |
| <div class="section" id="sensor-object"> |
| <h3>Sensor Object<a class="headerlink" href="#sensor-object" title="Permalink to this headline">¶</a></h3> |
| <p>The <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">sensor</span></code> data structure represents the sensor device. The |
| sensor API, the <a class="reference external" href="/os/modules/sensor_framework/sensor_mgr_api.html">sensor manager |
| API</a>, and the <a class="reference external" href="/os/modules/sensor_framework/sensor_listener_api.html">sensor |
| listener API</a> |
| all operate on the <code class="docutils literal notranslate"><span class="pre">sensor</span></code> object abstraction. A sensor is maintained |
| in the sensor manager global sensors list.</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">sensor</span><span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="cm">/* The OS device this sensor inherits from, this is typically a sensor</span> |
| <span class="cm"> * specific driver.</span> |
| <span class="cm"> */</span> |
| <span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_dev</span><span class="w"> </span><span class="o">*</span><span class="n">s_dev</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* The lock for this sensor object */</span> |
| <span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_mutex</span><span class="w"> </span><span class="n">s_lock</span><span class="p">;</span> |
| |
| |
| <span class="w"> </span><span class="cm">/* A bit mask describing the types of sensor objects available from this</span> |
| <span class="cm"> * sensor. If the bit corresponding to the sensor_type_t is set, then this</span> |
| <span class="cm"> * sensor supports that variable.</span> |
| <span class="cm"> */</span> |
| <span class="w"> </span><span class="n">sensor_type_t</span><span class="w"> </span><span class="n">s_types</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor mask of the configured sensor type s*/</span> |
| <span class="w"> </span><span class="n">sensor_type_t</span><span class="w"> </span><span class="n">s_mask</span><span class="p">;</span> |
| <span class="w"> </span><span class="cm">/**</span> |
| <span class="cm"> * Poll rate in MS for this sensor.</span> |
| <span class="cm"> */</span> |
| <span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">s_poll_rate</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* The next time at which we want to poll data from this sensor */</span> |
| <span class="w"> </span><span class="n">os_time_t</span><span class="w"> </span><span class="n">s_next_run</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor driver specific functions, created by the device registering the</span> |
| <span class="cm"> * sensor.</span> |
| <span class="cm"> */</span> |
| <span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">sensor_driver</span><span class="w"> </span><span class="o">*</span><span class="n">s_funcs</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor last reading timestamp */</span> |
| <span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">sensor_timestamp</span><span class="w"> </span><span class="n">s_sts</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor interface structure */</span> |
| <span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">sensor_itf</span><span class="w"> </span><span class="n">s_itf</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* A list of listeners that are registered to receive data off of this</span> |
| <span class="cm"> * sensor</span> |
| <span class="cm"> */</span> |
| <span class="w"> </span><span class="n">SLIST_HEAD</span><span class="p">(,</span><span class="w"> </span><span class="n">sensor_listener</span><span class="p">)</span><span class="w"> </span><span class="n">s_listener_list</span><span class="p">;</span> |
| <span class="w"> </span><span class="cm">/* The next sensor in the global sensor list. */</span> |
| <span class="w"> </span><span class="n">SLIST_ENTRY</span><span class="p">(</span><span class="n">sensor</span><span class="p">)</span><span class="w"> </span><span class="n">s_next</span><span class="p">;</span> |
| <span class="p">};</span> |
| </pre></div> |
| </div> |
| <p><strong>Note:</strong> There are two fields, <code class="docutils literal notranslate"><span class="pre">s_types</span></code> and <code class="docutils literal notranslate"><span class="pre">s_mask</span></code>, of type |
| <code class="docutils literal notranslate"><span class="pre">sensor_type_t</span></code>. The <code class="docutils literal notranslate"><span class="pre">s_types</span></code> field is a bit mask that specifies |
| the sensor types that the sensor device supports. The <code class="docutils literal notranslate"><span class="pre">s_mask</span></code> field |
| is a bit mask that specifies the sensor types that the sensor device is |
| configured for. Only sensor data for a configured sensor type can be |
| read.</p> |
| </div> |
| <div class="section" id="sensor-types"> |
| <h3>Sensor Types<a class="headerlink" href="#sensor-types" title="Permalink to this headline">¶</a></h3> |
| <p>The <code class="docutils literal notranslate"><span class="pre">sensor_type_t</span></code> type is an enumeration of a bit mask of sensor |
| types, with each bit representing one sensor type. Here is an excerpt of |
| the enumeration values. See the |
| <a class="reference external" href="https://github.com/apache/mynewt-core/blob/master/hw/sensor/include/sensor/sensor.h">sensor.h</a> |
| for details:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">typedef</span><span class="w"> </span><span class="k">enum</span><span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="cm">/* No sensor type, used for queries */</span> |
| <span class="w"> </span><span class="n">SENSOR_TYPE_NONE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span> |
| <span class="w"> </span><span class="cm">/* Accelerometer functionality supported */</span> |
| <span class="w"> </span><span class="n">SENSOR_TYPE_ACCELEROMETER</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="mi">0</span><span class="p">),</span> |
| <span class="w"> </span><span class="cm">/* Magnetic field supported */</span> |
| <span class="w"> </span><span class="n">SENSOR_TYPE_MAGNETIC_FIELD</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="mi">1</span><span class="p">),</span> |
| <span class="w"> </span><span class="cm">/* Gyroscope supported */</span> |
| <span class="w"> </span><span class="n">SENSOR_TYPE_GYROSCOPE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="mi">2</span><span class="p">),</span> |
| <span class="w"> </span><span class="cm">/* Light supported */</span> |
| <span class="w"> </span><span class="n">SENSOR_TYPE_LIGHT</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="mi">3</span><span class="p">),</span> |
| <span class="w"> </span><span class="cm">/* Temperature supported */</span> |
| <span class="w"> </span><span class="n">SENSOR_TYPE_TEMPERATURE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="mi">4</span><span class="p">),</span> |
| |
| <span class="w"> </span><span class="p">....</span> |
| |
| <span class="w"> </span><span class="n">SENSOR_TYPE_USER_DEFINED_6</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="mi">31</span><span class="p">),</span> |
| <span class="w"> </span><span class="cm">/* A selector, describes all sensors */</span> |
| <span class="w"> </span><span class="n">SENSOR_TYPE_ALL</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mh">0xFFFFFFFF</span> |
| |
| <span class="p">}</span><span class="w"> </span><span class="n">sensor_type_t</span><span class="p">;</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="sensor-interface"> |
| <h3>Sensor Interface<a class="headerlink" href="#sensor-interface" title="Permalink to this headline">¶</a></h3> |
| <p>The <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">sensor_itf</span></code> data structure represents the interface the |
| sensor device driver uses to communicate with the sensor device.</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">sensor_itf</span><span class="w"> </span><span class="p">{</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor interface type */</span> |
| <span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">si_type</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor interface number */</span> |
| <span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">si_num</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor CS pin */</span> |
| <span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">si_cs_pin</span><span class="p">;</span> |
| |
| <span class="w"> </span><span class="cm">/* Sensor address */</span> |
| <span class="w"> </span><span class="kt">uint16_t</span><span class="w"> </span><span class="n">si_addr</span><span class="p">;</span> |
| <span class="p">};</span> |
| </pre></div> |
| </div> |
| <p>The <code class="docutils literal notranslate"><span class="pre">si_cs_pin</span></code> specifies the chip select pin and is optional. The |
| <code class="docutils literal notranslate"><span class="pre">si_type</span></code> field must be of the following types:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#define SENSOR_ITF_SPI (0)</span> |
| <span class="cp">#define SENSOR_ITF_I2C (1)</span> |
| <span class="cp">#define SENSOR_ITF_UART (2)</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="sensor-value-type"> |
| <h3>Sensor Value Type<a class="headerlink" href="#sensor-value-type" title="Permalink to this headline">¶</a></h3> |
| <p>The <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">sensor_cfg</span></code> data structure represents the configuration |
| sensor type:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/**</span> |
| <span class="cm"> * Configuration structure, describing a specific sensor type off of</span> |
| <span class="cm"> * an existing sensor.</span> |
| <span class="cm"> */</span> |
| <span class="k">struct</span><span class="w"> </span><span class="nc">sensor_cfg</span><span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="cm">/* The value type for this sensor (e.g. SENSOR_VALUE_TYPE_INT32).</span> |
| <span class="cm"> * Used to describe the result format for the value corresponding</span> |
| <span class="cm"> * to a specific sensor type.</span> |
| <span class="cm"> */</span> |
| <span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">sc_valtype</span><span class="p">;</span> |
| <span class="w"> </span><span class="cm">/* Reserved for future usage */</span> |
| <span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">_reserved</span><span class="p">[</span><span class="mi">3</span><span class="p">];</span> |
| <span class="p">};</span> |
| </pre></div> |
| </div> |
| <p>Only the <code class="docutils literal notranslate"><span class="pre">sc_valtype</span></code> field is currently used and specifies the data |
| value type of the sensor data. The valid value types are:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/**</span> |
| <span class="cm"> * Opaque 32-bit value, must understand underlying sensor type</span> |
| <span class="cm"> * format in order to interpret.</span> |
| <span class="cm"> */</span> |
| <span class="cp">#define SENSOR_VALUE_TYPE_OPAQUE (0)</span> |
| <span class="cm">/**</span> |
| <span class="cm"> * 32-bit signed integer</span> |
| <span class="cm"> */</span> |
| <span class="cp">#define SENSOR_VALUE_TYPE_INT32 (1)</span> |
| <span class="cm">/**</span> |
| <span class="cm"> * 32-bit floating point</span> |
| <span class="cm"> */</span> |
| <span class="cp">#define SENSOR_VALUE_TYPE_FLOAT (2)</span> |
| <span class="cm">/**</span> |
| <span class="cm"> * 32-bit integer triplet.</span> |
| <span class="cm"> */</span> |
| <span class="cp">#define SENSOR_VALUE_TYPE_INT32_TRIPLET (3)</span> |
| <span class="cm">/**</span> |
| <span class="cm"> * 32-bit floating point number triplet.</span> |
| <span class="cm"> */</span> |
| <span class="cp">#define SENSOR_VALUE_TYPE_FLOAT_TRIPLET (4)</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="sensor-driver-functions"> |
| <h3>Sensor Driver Functions<a class="headerlink" href="#sensor-driver-functions" title="Permalink to this headline">¶</a></h3> |
| <p>The <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">sensor_device</span></code> data structure represents the device driver |
| functions. The sensor device driver must implement the functions and set |
| up the function pointers.</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct sensor_driver { |
| sensor_read_func_t sd_read; |
| sensor_get_config_func_t sd_get_config; |
| }; |
| </pre></div> |
| </div> |
| </div> |
| </div> |
| <div class="section" id="list-of-functions"> |
| <h2>List of Functions:<a class="headerlink" href="#list-of-functions" title="Permalink to this headline">¶</a></h2> |
| <p>These are the functions defined by the sensor API. Please see the |
| <a class="reference external" href="https://github.com/apache/mynewt-core/blob/master/hw/sensor/include/sensor/sensor.h">sensor.h</a> |
| include file for details.</p> |
| <table class="docutils align-default"> |
| <colgroup> |
| <col style="width: 43%" /> |
| <col style="width: 57%" /> |
| </colgroup> |
| <thead> |
| <tr class="row-odd"><th class="head"><p>Function</p></th> |
| <th class="head"><p>Description</p></th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="row-even"><td><p>sensor_in |
| it</p></td> |
| <td><p>Initializes a |
| sensor. A |
| sensor device |
| driver uses |
| this function.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>sensor_se |
| t_driver</p></td> |
| <td><p>Sets the |
| sensor types |
| that the |
| sensor device |
| supports, and |
| the driver |
| functions to |
| read data and |
| to get value |
| type for a |
| sensor type. A |
| sensor device |
| driver uses |
| this function.</p></td> |
| </tr> |
| <tr class="row-even"><td><p>sensor_se |
| t_interfa |
| ce</p></td> |
| <td><p>Sets the |
| sensor |
| interface to |
| use to |
| communicate |
| with the |
| sensor device. |
| A sensor |
| device driver |
| uses this |
| function.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>sensor_se |
| t_type_m |
| ask</p></td> |
| <td><p>Specifies the |
| sensor types |
| that a sensor |
| device is |
| configured |
| for. A sensor |
| device driver |
| uses this |
| function.</p></td> |
| </tr> |
| <tr class="row-even"><td><p>sensor_re |
| ad</p></td> |
| <td><p>Reads sensor |
| data for the |
| specified |
| sensor types. |
| An application |
| uses this |
| function.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>sensor_se |
| t_poll_r |
| ate_ms</p></td> |
| <td><p>Sets poll rate |
| for the sensor |
| manager to |
| poll the |
| sensor device. |
| An application |
| uses this |
| function.</p></td> |
| </tr> |
| <tr class="row-even"><td><p>sensor_lo |
| ck</p></td> |
| <td><p>Locks the |
| sensor object |
| for exclusive |
| access.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>sensor_un |
| lock</p></td> |
| <td><p>Unlocks the |
| sensor object.</p></td> |
| </tr> |
| <tr class="row-even"><td><p>SENSOR_GE |
| T_DEV</p></td> |
| <td><p>Macro that the |
| sensor device |
| driver uses to |
| retrieve the |
| os_dev from |
| the sensor |
| object.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p>SENSOR_GE |
| T_ITF</p></td> |
| <td><p>Macro that the |
| sensor device |
| driver uses to |
| retrieve the |
| sensor_itf |
| from the |
| sensor object.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| |
| |
| </div> |
| </div> |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS CONTENT SECTION --> |
| </div> |
| <!-- ENDS .content --> |
| </div> |
| </div> |
| <footer> |
| <div class="container"> |
| <div class="row"> |
| <div class="col-xs-12"> |
| |
| <p class="copyright">Apache Mynewt is available under Apache License, version 2.0.</p> |
| |
| </div> |
| <div class="col-xs-12"> |
| <div class="logos"> |
| <img src="../../../_static/img/asf_logo_wide_small.png" alt="Apache" title="Apache"> |
| <small class="footnote"> |
| Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt project logo are either |
| registered trademarks or trademarks of the Apache Software Foundation in the United States and other countries. |
| </small> |
| <a href=""> |
| <img src="../../../_static/img/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" /> |
| </a> |
| </div> |
| </div> |
| </div> |
| </div> |
| </footer> |
| </div> |
| <!-- ENDS #wrapper --> |
| |
| |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT:'../../../', |
| VERSION:'latest', |
| COLLAPSE_INDEX:false, |
| FILE_SUFFIX:'.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '.txt', |
| LINK_SUFFIX: '.html' |
| }; |
| </script> |
| <script type="text/javascript" src="../../../_static/jquery.js"></script> |
| <script type="text/javascript" src="../../../_static/underscore.js"></script> |
| <script type="text/javascript" src="../../../_static/doctools.js"></script> |
| <script type="text/javascript" src="../../../_static/js/bootstrap-3.0.3.min.js"></script> |
| <script type="text/javascript" src="../../../_static/js/affix.js"></script> |
| <script type="text/javascript" src="../../../_static/js/main.js"></script> |
| |
| |
| |
| </body> |
| </html> |