PX4 Firmware
PX4 Autopilot Software http://px4.io
BMI055.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2018 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 #pragma once
35 
36 #include <drivers/device/spi.h>
37 #include <ecl/geo/geo.h>
38 #include <lib/perf/perf_counter.h>
39 #include <px4_platform_common/getopt.h>
40 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
41 
42 #define DIR_READ 0x80
43 #define DIR_WRITE 0x00
44 
45 //Soft-reset command Value
46 #define BMI055_SOFT_RESET 0xB6
47 
48 #define BMI055_BUS_SPEED 10*1000*1000
49 
50 #define BMI055_TIMER_REDUCTION 200
51 
52 class BMI055 : public device::SPI
53 {
54 
55 protected:
56 
57  uint8_t _whoami; /** whoami result */
58 
59  uint8_t _register_wait;
60  uint64_t _reset_wait;
61 
63 
64  uint8_t _checked_next;
65 
66  /**
67  * Read a register from the BMI055
68  *
69  * @param The register to read.
70  * @return The value that was read.
71  */
72  uint8_t read_reg(unsigned reg);
73  uint16_t read_reg16(unsigned reg);
74 
75  /**
76  * Write a register in the BMI055
77  *
78  * @param reg The register to write.
79  * @param value The new value to write.
80  */
81  void write_reg(unsigned reg, uint8_t value);
82 
83  /* do not allow to copy this class due to pointer data members */
84  BMI055(const BMI055 &);
85  BMI055 operator=(const BMI055 &);
86 
87 public:
88 
89  BMI055(const char *name, const char *devname, int bus, uint32_t device, enum spi_mode_e mode, uint32_t frequency,
90  enum Rotation rotation);
91 
92  virtual ~BMI055() = default;
93 
94 
95 };
spi_mode_e
Definition: SPI.hpp:46
Definition of geo / math functions to perform geodesic calculations.
uint64_t _reset_wait
Definition: BMI055.hpp:60
Namespace encapsulating all device framework classes, functions and data.
Definition: CDev.cpp:47
void write_reg(unsigned reg, uint8_t value)
Write a register in the BMI055.
BMI055(const BMI055 &)
uint8_t read_reg(unsigned reg)
Read a register from the BMI055.
virtual ~BMI055()=default
enum Rotation _rotation
Definition: BMI055.hpp:62
BMI055 operator=(const BMI055 &)
Rotation
Enum for board and external compass rotations.
Definition: rotation.h:51
uint16_t read_reg16(unsigned reg)
uint8_t _register_wait
whoami result
Definition: BMI055.hpp:59
uint8_t _whoami
Definition: BMI055.hpp:57
const char * name
Definition: tests_main.c:58
uint8_t _checked_next
Definition: BMI055.hpp:64
mode
Definition: vtol_type.h:76
Performance measuring tools.