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