PX4 Firmware
PX4 Autopilot Software http://px4.io
ms5611.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2013 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file ms5611.h
36  *
37  * Shared defines for the ms5611 driver.
38  */
39 
40 #pragma once
41 
42 #include <string.h>
43 
44 #include <drivers/device/i2c.h>
45 #include <drivers/device/device.h>
47 #include <drivers/device/spi.h>
48 #include <drivers/drv_baro.h>
49 #include <lib/cdev/CDev.hpp>
50 #include <lib/perf/perf_counter.h>
51 #include <px4_platform_common/getopt.h>
52 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
53 #include <systemlib/err.h>
54 #include <uORB/uORB.h>
55 
56 #include "board_config.h"
57 
58 #define ADDR_RESET_CMD 0x1E /* write to this address to reset chip */
59 #define ADDR_PROM_SETUP 0xA0 /* address of 8x 2 bytes factory and calibration data */
60 
61 /* interface ioctls */
62 #define IOCTL_RESET 2
63 #define IOCTL_MEASURE 3
64 
65 namespace ms5611
66 {
67 
68 /**
69  * Calibration PROM as reported by the device.
70  */
71 #pragma pack(push,1)
72 struct prom_s {
73  uint16_t factory_setup;
74  uint16_t c1_pressure_sens;
80  uint16_t serial_and_crc;
81 };
82 
83 /**
84  * Grody hack for crc4()
85  */
86 union prom_u {
87  uint16_t c[8];
89 };
90 #pragma pack(pop)
91 
92 extern bool crc4(uint16_t *n_prom);
93 
94 } /* namespace */
95 
96 /* interface factories */
97 extern device::Device *MS5611_spi_interface(ms5611::prom_u &prom_buf, uint8_t busnum);
98 extern device::Device *MS5611_i2c_interface(ms5611::prom_u &prom_buf, uint8_t busnum);
99 extern device::Device *MS5611_sim_interface(ms5611::prom_u &prom_buf, uint8_t busnum);
100 typedef device::Device *(*MS5611_constructor)(ms5611::prom_u &prom_buf, uint8_t busnum);
uint16_t serial_and_crc
Definition: ms5611.h:80
uint16_t c1_pressure_sens
Definition: ms5611.h:74
bool crc4(uint16_t *n_prom)
MS5611 crc4 cribbed from the datasheet.
Definition: ms5611.cpp:608
API for the uORB lightweight object broker.
Calibration PROM as reported by the device.
Definition: ms5611.h:72
uint16_t c4_temp_coeff_pres_offset
Definition: ms5611.h:77
device::Device * MS5611_i2c_interface(ms5611::prom_u &prom_buf, uint8_t busnum)
Definition: ms5611_i2c.cpp:90
uint16_t c5_reference_temp
Definition: ms5611.h:78
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
uint16_t factory_setup
Definition: ms5611.h:73
uint16_t c2_pressure_offset
Definition: ms5611.h:75
uint16_t c6_temp_coeff_temp
Definition: ms5611.h:79
device::Device * MS5611_sim_interface(ms5611::prom_u &prom_buf, uint8_t busnum)
Grody hack for crc4()
Definition: ms5611.h:86
Local functions in support of the shell command.
Definition: ms5611.cpp:601
device::Device * MS5611_spi_interface(ms5611::prom_u &prom_buf, uint8_t busnum)
Fundamental base class for all physical drivers (I2C, SPI).
Definition: Device.hpp:65
uint16_t c3_temp_coeff_pres_sens
Definition: ms5611.h:76
Barometric pressure sensor driver interface.
prom_s s
Definition: ms5611.h:88
Performance measuring tools.
Base class for devices connected via I2C.