blob: 0f1b80c129dcb42c631c084fe1612a2383be0488 [file] [log] [blame]
<!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">
<!-- This is broken by doc revisioning.
-->
<link rel="shortcut icon" href="../../../../img/favicon.ico">
<title>Sensor API - Apache Mynewt</title>
<link href="../../../../css/bootstrap-3.0.3.min.css" rel="stylesheet">
<link rel="stylesheet" href="../../../../css/highlight.css">
<link href="../../../../css/base.css" rel="stylesheet">
<link href="../../../../css/custom.css" rel="stylesheet">
<link href="../../../../css/v2.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<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="Sensor API">
<div class="container">
<div class="row v2-main-banner">
<a class="logo-cell" href="/">
<img class="logo" src="/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.11.0, Apache NimBLE 1.6.0 </a> released (September 7, 2023)
</div>
</div>
</div>
</div>
<nav id="navbar" class="navbar navbar-inverse affix-top" data-spy="affix" data-offset-top="150" 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
class=""
>
<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
class=""
>
<a href="/about/">About</a>
</li>
<li
class=""
>
<a href="/talks/">Talks</a>
</li>
<li
class="active"
>
<a href="/documentation/">Documentation</a>
</li>
<li
class=""
>
<a href="/download/">Download</a>
</li>
<li
class=""
>
<a href="/community/">Community</a>
</li>
<li
class=""
>
<a href="/events/">Events</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-3 v2-sidebar sidebar-container"><div id="docSidebar" class="hidden-print" role="complementary">
<div class="top">
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search documentation" />
</div>
</form>
</div>
</div>
<ul class="toc-nav">
<li class="doc-version"><select class="form-control" onchange="if (this.value) window.location.href=this.value">
<option value="/latest">
Version: master
</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/" >
Version: 1.4.0
</option>
<option value="/v1_3_0/os/introduction" selected="selected" >
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></li>
<li ><a href="../../../introduction/">Mynewt Documentation</a>
<ul>
<li ><a href="../../../get_started/get_started/">Basic Setup</a>
</li>
<li >
<a href="../../../get_started/vocabulary/">Concepts</a>
</li>
<li ><a href="../../../tutorials/tutorials/">Tutorials</a>
</li>
<li ><a href="../../../os_user_guide/">OS User Guide</a>
<ul>
<li ><a href="../../../core_os/mynewt_os/">OS Core</a>
</li>
<li ><a href="../../../core_os/porting/port_os/">Porting to your Platform</a>
</li>
<li ><a href="../../console/console/">Console</a>
</li>
<li ><a href="../../shell/shell/">Shell</a>
</li>
<li ><a href="../../split/split/">Split Images</a>
</li>
<li ><a href="../../bootloader/bootloader/">Bootloader</a>
</li>
<li><a href="
../../fs/fs/fs/
">File System</a>
</li>
<li ><a href="../../hal/hal/">Hardware Abstraction Layer</a>
</li>
<li ><a href="../sensor_framework_overview/">Sensor Framework</a>
<ul>
<li><a href="
./
">API</a>
<ul>
<li class="active">
<a href="./">Sensor API</a>
</li>
<li >
<a href="../sensor_mgr_api/">Sensor Manager API</a>
</li>
<li >
<a href="../sensor_listener_api/">Sensor Listener API</a>
</li>
<li >
<a href="../sensor_oic/">OIC Sensor API</a>
</li>
</ul>
</li>
<li >
<a href="../sensor_shell/">Sensor Shell</a>
</li>
<li >
<a href="../sensor_driver/">Sensor Device Driver</a>
</li>
<li >
<a href="../sensor_create/">Creating and Configuring Sensor Devices</a>
</li>
</ul>
</li>
<li ><a href="../../drivers/driver/">Drivers</a>
</li>
<li ><a href="../../testutil/testutil/">Test Utilities</a>
</li>
<li ><a href="../../devmgmt/newtmgr/">Device Management with Newt Manager</a>
</li>
<li ><a href="../../imgmgr/imgmgr/">Image Manager</a>
</li>
<li >
<a href="../../baselibc/">Baselibc library</a>
</li>
<li ><a href="../../json/json/">JSON</a>
</li>
<li ><a href="../../fcb/fcb/">Flash Circular Buffer</a>
</li>
<li ><a href="../../stats/stats/">Stats</a>
</li>
<li ><a href="../../logs/logs/">Logs</a>
</li>
<li ><a href="../../sysinitconfig/sysinitconfig/">System Configuration And Initialization</a>
</li>
</ul>
</li>
<li><a href="
../../../../network/ble/ble_intro/
">BLE User Guide</a>
</li>
<li ><a href="../../../../newt/newt_intro/">Newt Tool Guide</a>
</li>
<li ><a href="../../../../newtmgr/overview/">Newt Manager Guide</a>
</li>
<li >
<a href="../../../../known_issues/">Known Issues</a>
</li>
</ul>
</li>
<li><a href="
../../../../newt/install/prev_releases/
">Appendix</a>
</li>
</ul>
</div></div>
<div class="col-md-9" role="main">
<div class="doc-header">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="/documentation/">Docs</a></li>
<li>&raquo; API</li>
<li>&raquo; <a href="os/modules/sensor_framework/sensor_framework_overview/">Sensor Framework</a></li>
<li>&raquo; <a href="os/os_user_guide/">OS User Guide</a></li>
<li>&raquo; <a href="os/introduction/">Mynewt Documentation</a></li>
<li>&raquo; Sensor API</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/apache/mynewt-site/blob/master/docs/os/modules/sensor_framework/sensor_api.md"
class="icon icon-github"> Edit on GitHub</a>
</li>
</ul>
</div>
</div>
<div class="alert alert-warning">
<p>
Version 1.3.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>
<h2 id="sensor-api">Sensor API</h2>
<p>The sensor API implements the sensor abstraction and the functions:</p>
<ul>
<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>struct sensor</code> object.</p>
<h3 id="sensor-api-functions-used-by-a-sensor-device-driver-package">Sensor API Functions Used by a Sensor Device Driver Package</h3>
<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>
<h4 id="initializing-a-sensor-object">Initializing a Sensor Object</h4>
<p>When the BSP or the sensor creator package creates an OS device for a sensor named <code>SENSORNAME</code>, it specifies the <code>&lt;sensorname&gt;_init()</code> callback function, that the device driver exports, for the <code>os_dev_create()</code> function to call to initialize the device. The <code>&lt;sensorname&gt;_init()</code> function must use the following sensor API functions to set the driver and interface information in the sensor object: </p>
<ul>
<li>
<p>The <code>sensor_init()</code> function to initialize the <code>struct sensor</code> object for the device.</p>
</li>
<li>
<p>The <code>sensor_set_driver()</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>sensor_set_interface()</code> function to set the interface to use to communicate with the sensor device.</p>
</li>
</ul>
<p><strong>Notes</strong>: </p>
<ul>
<li>
<p>See the <a href="/os/modules/sensor_framework/sensor_driver.md">Sensor Device Driver</a> page for the functions and data structures that a sensor driver package exports.</p>
</li>
<li>
<p>The <code>&lt;sensorname&gt;_init()</code> function must also call the <code>sensor_mgr_register()</code> function to register the sensor with the sensor manager. See the <a href="/os/modules/sensor_framework/sensor_manager_api.md">Sensor Manager API</a> for details.</p>
</li>
</ul>
<p><br></p>
<h4 id="setting-the-configured-sensor-types">Setting the Configured Sensor Types</h4>
<p>The BSP, or the sensor creator package, also calls the <code>&lt;sensorname&gt;_config()</code> function to configure the sensor device with default values. The <code>&lt;sensorname&gt;_config()</code> function is exported by the sensor device driver and must call the sensor API <code>sensor_set_type_mask()</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>&lt;sensorname&gt;_config()</code> function to configure the sensor device. </p>
<h3 id="sensor-api-functions-used-by-an-application">Sensor API Functions Used By an Application</h3>
<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>
<h4 id="reading-sensor-data">Reading Sensor Data</h4>
<p>An application calls the <code>sensor_read()</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>
<h4 id="setting-a-poll-rate-for-a-sensor">Setting a Poll Rate for A Sensor</h4>
<p>The sensor manager implements a poller that reads sensor data from a sensor at specified poll intervals. An application must call the <code>sensor_set_poll_rate_ms()</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 href="/os/modules/sensor_framework/sensor_listener_api.md">sensor listener</a> to receive the sensor data that the sensor manager poller reads from a sensor.</p>
<h3 id="data-structures">Data Structures</h3>
<p>We list the main data structures that the sensor API uses and mention things to note. For more details, see the <a href="https://github.com/apache/mynewt-core/blob/master/hw/sensor/include/sensor/sensor.h">sensor.h</a> include file.
<br></p>
<h4 id="sensor-object">Sensor Object</h4>
<p>The <code>struct sensor</code> data structure represents the sensor device. The sensor API, the <a href="/os/modules/sensor_framework/sensor_mgr_api.md">sensor manager API</a>, and the <a href="/os/modules/sensor_framework/sensor_listener_api.md">sensor listener API</a> all operate on the <code>sensor</code> object abstraction. A sensor is maintained in the sensor manager global sensors list.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code><span style="color: #A90D91">struct</span> <span style="color: #3F6E75">sensor</span> {
<span style="color: #177500">/* The OS device this sensor inherits from, this is typically a sensor</span>
<span style="color: #177500"> * specific driver.</span>
<span style="color: #177500"> */</span>
<span style="color: #A90D91">struct</span> <span style="color: #3F6E75">os_dev</span> <span style="color: #000000">*s_dev</span>;
<span style="color: #177500">/* The lock for this sensor object */</span>
<span style="color: #A90D91">struct</span> <span style="color: #3F6E75">os_mutex</span> <span style="color: #000000">s_lock</span>;
<span style="color: #177500">/* A bit mask describing the types of sensor objects available from this</span>
<span style="color: #177500"> * sensor. If the bit corresponding to the sensor_type_t is set, then this</span>
<span style="color: #177500"> * sensor supports that variable.</span>
<span style="color: #177500"> */</span>
<span style="color: #000000">sensor_type_t</span> <span style="color: #000000">s_types</span>;
<span style="color: #177500">/* Sensor mask of the configured sensor type s*/</span>
<span style="color: #000000">sensor_type_t</span> <span style="color: #000000">s_mask</span>;
<span style="color: #177500">/**</span>
<span style="color: #177500"> * Poll rate in MS for this sensor.</span>
<span style="color: #177500"> */</span>
<span style="color: #A90D91">uint32_t</span> <span style="color: #000000">s_poll_rate</span>;
<span style="color: #177500">/* The next time at which we want to poll data from this sensor */</span>
<span style="color: #000000">os_time_t</span> <span style="color: #000000">s_next_run</span>;
<span style="color: #177500">/* Sensor driver specific functions, created by the device registering the</span>
<span style="color: #177500"> * sensor.</span>
<span style="color: #177500"> */</span>
<span style="color: #A90D91">struct</span> <span style="color: #3F6E75">sensor_driver</span> <span style="color: #000000">*s_funcs</span>;
<span style="color: #177500">/* Sensor last reading timestamp */</span>
<span style="color: #A90D91">struct</span> <span style="color: #3F6E75">sensor_timestamp</span> <span style="color: #000000">s_sts</span>;
<span style="color: #177500">/* Sensor interface structure */</span>
<span style="color: #A90D91">struct</span> <span style="color: #3F6E75">sensor_itf</span> <span style="color: #000000">s_itf</span>;
<span style="color: #177500">/* A list of listeners that are registered to receive data off of this</span>
<span style="color: #177500"> * sensor</span>
<span style="color: #177500"> */</span>
<span style="color: #000000">SLIST_HEAD</span>(, <span style="color: #000000">sensor_listener</span>) <span style="color: #000000">s_listener_list</span>;
<span style="color: #177500">/* The next sensor in the global sensor list. */</span>
<span style="color: #000000">SLIST_ENTRY</span>(<span style="color: #000000">sensor</span>) <span style="color: #000000">s_next</span>;
};
</code></pre></div>
<p><br></p>
<p><strong>Note:</strong> There are two fields, <code>s_types</code> and <code>s_mask</code>, of type <code>sensor_type_t</code>. The <code>s_types</code> field is a bit mask that specifies the sensor types that the sensor device supports. The <code>s_mask</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>
<p><br></p>
<h4 id="sensor-types">Sensor Types</h4>
<p>The <code>sensor_type_t</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 href="https://github.com/apache/mynewt-core/blob/master/hw/sensor/include/sensor/sensor.h">sensor.h</a> for details:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code><span style="color: #A90D91">typedef</span> <span style="color: #A90D91">enum</span> {
<span style="color: #177500">/* No sensor type, used for queries */</span>
<span style="color: #000000">SENSOR_TYPE_NONE</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>,
<span style="color: #177500">/* Accelerometer functionality supported */</span>
<span style="color: #000000">SENSOR_TYPE_ACCELEROMETER</span> <span style="color: #000000">=</span> (<span style="color: #1C01CE">1</span> <span style="color: #000000">&lt;&lt;</span> <span style="color: #1C01CE">0</span>),
<span style="color: #177500">/* Magnetic field supported */</span>
<span style="color: #000000">SENSOR_TYPE_MAGNETIC_FIELD</span> <span style="color: #000000">=</span> (<span style="color: #1C01CE">1</span> <span style="color: #000000">&lt;&lt;</span> <span style="color: #1C01CE">1</span>),
<span style="color: #177500">/* Gyroscope supported */</span>
<span style="color: #000000">SENSOR_TYPE_GYROSCOPE</span> <span style="color: #000000">=</span> (<span style="color: #1C01CE">1</span> <span style="color: #000000">&lt;&lt;</span> <span style="color: #1C01CE">2</span>),
<span style="color: #177500">/* Light supported */</span>
<span style="color: #000000">SENSOR_TYPE_LIGHT</span> <span style="color: #000000">=</span> (<span style="color: #1C01CE">1</span> <span style="color: #000000">&lt;&lt;</span> <span style="color: #1C01CE">3</span>),
<span style="color: #177500">/* Temperature supported */</span>
<span style="color: #000000">SENSOR_TYPE_TEMPERATURE</span> <span style="color: #000000">=</span> (<span style="color: #1C01CE">1</span> <span style="color: #000000">&lt;&lt;</span> <span style="color: #1C01CE">4</span>),
....
<span style="color: #000000">SENSOR_TYPE_USER_DEFINED_6</span> <span style="color: #000000">=</span> (<span style="color: #1C01CE">1</span> <span style="color: #000000">&lt;&lt;</span> <span style="color: #1C01CE">31</span>),
<span style="color: #177500">/* A selector, describes all sensors */</span>
<span style="color: #000000">SENSOR_TYPE_ALL</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0xFFFFFFFF</span>
} <span style="color: #000000">sensor_type_t</span>;
</code></pre></div>
<p><br></p>
<h4 id="sensor-interface">Sensor Interface</h4>
<p>The <code>struct sensor_itf</code> data structure represents the interface the sensor device driver uses to communicate with the sensor device. </p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code><span style="color: #A90D91">struct</span> <span style="color: #3F6E75">sensor_itf</span> {
<span style="color: #177500">/* Sensor interface type */</span>
<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">si_type</span>;
<span style="color: #177500">/* Sensor interface number */</span>
<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">si_num</span>;
<span style="color: #177500">/* Sensor CS pin */</span>
<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">si_cs_pin</span>;
<span style="color: #177500">/* Sensor address */</span>
<span style="color: #A90D91">uint16_t</span> <span style="color: #000000">si_addr</span>;
};
</code></pre></div>
<p>The <code>si_cs_pin</code> specifies the chip select pin and is optional. The <code>si_type</code> field must be of the following types:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code><span style="color: #633820">#define SENSOR_ITF_SPI (0)</span>
<span style="color: #633820">#define SENSOR_ITF_I2C (1)</span>
<span style="color: #633820">#define SENSOR_ITF_UART (2) </span>
</code></pre></div>
<p><br></p>
<h4 id="sensor-value-type">Sensor Value Type</h4>
<p>The <code>struct sensor_cfg</code> data structure represents the configuration sensor type:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code><span style="color: #177500">/**</span>
<span style="color: #177500"> * Configuration structure, describing a specific sensor type off of</span>
<span style="color: #177500"> * an existing sensor.</span>
<span style="color: #177500"> */</span>
<span style="color: #A90D91">struct</span> <span style="color: #3F6E75">sensor_cfg</span> {
<span style="color: #177500">/* The value type for this sensor (e.g. SENSOR_VALUE_TYPE_INT32).</span>
<span style="color: #177500"> * Used to describe the result format for the value corresponding</span>
<span style="color: #177500"> * to a specific sensor type.</span>
<span style="color: #177500"> */</span>
<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">sc_valtype</span>;
<span style="color: #177500">/* Reserved for future usage */</span>
<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">_reserved</span>[<span style="color: #1C01CE">3</span>];
};
</code></pre></div>
<p><br>
Only the <code>sc_valtype</code> field is currently used and specifies the data value type of the sensor data. The valid value types are:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code><span style="color: #177500">/**</span>
<span style="color: #177500"> * Opaque 32-bit value, must understand underlying sensor type</span>
<span style="color: #177500"> * format in order to interpret.</span>
<span style="color: #177500"> */</span>
<span style="color: #633820">#define SENSOR_VALUE_TYPE_OPAQUE (0)</span>
<span style="color: #177500">/**</span>
<span style="color: #177500"> * 32-bit signed integer</span>
<span style="color: #177500"> */</span>
<span style="color: #633820">#define SENSOR_VALUE_TYPE_INT32 (1)</span>
<span style="color: #177500">/**</span>
<span style="color: #177500"> * 32-bit floating point</span>
<span style="color: #177500"> */</span>
<span style="color: #633820">#define SENSOR_VALUE_TYPE_FLOAT (2)</span>
<span style="color: #177500">/**</span>
<span style="color: #177500"> * 32-bit integer triplet.</span>
<span style="color: #177500"> */</span>
<span style="color: #633820">#define SENSOR_VALUE_TYPE_INT32_TRIPLET (3)</span>
<span style="color: #177500">/**</span>
<span style="color: #177500"> * 32-bit floating point number triplet.</span>
<span style="color: #177500"> */</span>
<span style="color: #633820">#define SENSOR_VALUE_TYPE_FLOAT_TRIPLET (4)</span>
</code></pre></div>
<p><br></p>
<h4 id="sensor-driver-functions">Sensor Driver Functions</h4>
<p>The <code>struct sensor_device</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="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>struct sensor_driver {
sensor_read_func_t sd_read;
sensor_get_config_func_t sd_get_config;
};
</code></pre></div>
<p><br></p>
<p><br></p>
<h3 id="list-of-functions">List of Functions:</h3>
<p>These are the functions defined by the sensor API. Please see the <a href="https://github.com/apache/mynewt-core/blob/master/hw/sensor/include/sensor/sensor.h">sensor.h</a> include file for details.</p>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>sensor_init</td>
<td>Initializes a sensor. A sensor device driver uses this function.</td>
</tr>
<tr>
<td>sensor_set_driver</td>
<td>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.</td>
</tr>
<tr>
<td>sensor_set_interface</td>
<td>Sets the sensor interface to use to communicate with the sensor device. A sensor device driver uses this function.</td>
</tr>
<tr>
<td>sensor_set_type_mask</td>
<td>Specifies the sensor types that a sensor device is configured for. A sensor device driver uses this function.</td>
</tr>
<tr>
<td>sensor_read</td>
<td>Reads sensor data for the specified sensor types. An application uses this function.</td>
</tr>
<tr>
<td>sensor_set_poll_rate_ms</td>
<td>Sets poll rate for the sensor manager to poll the sensor device. An application uses this function.</td>
</tr>
<tr>
<td>sensor_lock</td>
<td>Locks the sensor object for exclusive access.</td>
</tr>
<tr>
<td>sensor_unlock</td>
<td>Unlocks the sensor object.</td>
</tr>
<tr>
<td>SENSOR_GET_DEV</td>
<td>Macro that the sensor device driver uses to retrieve the os_dev from the sensor object.</td>
</tr>
<tr>
<td>SENSOR_GET_ITF</td>
<td>Macro that the sensor device driver uses to retrieve the sensor_itf from the sensor object.</td>
</tr>
</tbody>
</table>
<div class="row">
<ul class="nav nav-pills" style="margin-bottom: 10px">
<li>
</li>
<li class="pull-right">
</li>
</ul>
</div>
<footer 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">
<a href="https://www.apache.org/">
<img src="/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
</a>
<p>
Copyright © 2015-2021 The Apache Software Foundation.<br>
<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>
</p>
<a href="">
<img src="https://www.countit.com/images/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" />
</a>
</div>
</div>
<a href="https://www.apache.org/licenses/">
<button class="button-footer-asf">
License
</button>
</a>
<a href="https://www.apache.org/foundation/sponsorship.html">
<button class="button-footer-asf">
Sponsorship
</button>
</a>
<a href="https://www.apache.org/foundation/thanks.html">
<button class="button-footer-asf">
Thanks
</button>
</a>
<a href="https://www.apache.org/security/">
<button class="button-footer-asf">
Security
</button>
</a>
<a href="https://apache.org/events/current-event">
<button class="button-footer-asf">
ASF Events
</button>
</a>
</footer>
</div>
</div>
</div>
<script src="../../../../js/jquery-1.10.2.min.js"></script>
<script src="../../../../js/bootstrap-3.0.3.min.js"></script>
<script src="../../../../js/highlight.pack.js"></script>
<script src="../../../../js/base.js"></script>
<script src="../../../../js/custom.js"></script>
<script src="search/main.js"></script>
</body>
</html>