dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_etasv3.c
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  */
29 
30 /* Project Includes */
31 #include "pios.h"
32 
33 #if defined(PIOS_INCLUDE_ETASV3)
34 
35 #include "pios_etasv3.h"
36 
37 static bool PIOS_ETASV3_Read(uint8_t * buffer, uint8_t len)
38 {
39  const struct pios_i2c_txn txn_list[] = {
40  {
41  .info = __func__,
42  .addr = ETASV3_I2C_ADDR,
43  .rw = PIOS_I2C_TXN_READ,
44  .len = len,
45  .buf = buffer,
46  }
47  };
48 
49  return PIOS_I2C_Transfer(PIOS_I2C_ETASV3_ADAPTER, txn_list, NELEMENTS(txn_list));
50 }
51 
52 int16_t PIOS_ETASV3_ReadAirspeed (void)
53 {
54  uint8_t airspeed_raw[2];
55 
56  if (PIOS_ETASV3_Read(airspeed_raw, sizeof(airspeed_raw)) != 0) {
57  /* Failed to read airspeed */
58  return -1;
59  }
60 
61  return (airspeed_raw[0] | (airspeed_raw[1]<<8));
62 }
63 
64 #endif /* PIOS_INCLUDE_ETASV3 */
Main PiOS header to include all the compiled in PiOS options.
#define NELEMENTS(x)
Definition: pios.h:192
int32_t PIOS_I2C_Transfer(pios_i2c_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns)
const char * info
Definition: pios_i2c.h:41
uint32_t len
Definition: pios_i2c.h:44
ETASV3 Airspeed Sensor Driver.
#define ETASV3_I2C_ADDR
Definition: pios_etasv3.h:30
int16_t PIOS_ETASV3_ReadAirspeed(void)