OP-1516 fixed boundf mistake
[librepilot.git] / flight / pios / inc / pios_bma180.h
blob01164658a4f16e47d58eea1377e98f0956e45756
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @addtogroup PIOS_BMA180 BMA180 Functions
6 * @brief Deals with the hardware interface to the BMA180 3-axis accelerometer
7 * @{
9 * @file pios_bma180.h
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
11 * @brief PiOS BMA180 digital accelerometer driver.
12 * - Driver for the BMA180 digital accelerometer on the SPI bus.
13 * @see The GNU Public License (GPL) Version 3
15 *****************************************************************************/
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifndef PIOS_BMA180_H
33 #define PIOS_BMA180_H
35 #include "fifo_buffer.h"
37 #include <pios.h>
39 /* BMA180 Addresses */
40 #define BMA_CHIPID_ADDR 0x00
41 #define BMA_VERSION_ADDR 0x00
42 #define BMA_X_LSB_ADDR 0x02
43 #define BMA_Y_LSB_ADDR 0x04
44 #define BMA_Z_LSB_ADDR 0x06
45 #define BMA_WE_ADDR 0x0D
46 #define BMA_RESET 0x10
47 #define BMA_BW_ADDR 0x20
48 #define BMA_RANGE_ADDR 0x35
49 #define BMA_OFFSET_LSB1 0x35
50 #define BMA_GAIN_Y 0x33
51 #define BMA_CTRREG3 0x21
52 #define BMA_CTRREG0 0x0D
54 #define BMA_RESET_CODE 0x6B
56 /* Accel range */
57 #define BMA_RANGE_MASK 0x0E
58 #define BMA_RANGE_SHIFT 1
59 enum bma180_range { BMA_RANGE_1G = 0x00,
60 BMA_RANGE_1_5G = 0x01,
61 BMA_RANGE_2G = 0x02,
62 BMA_RANGE_3G = 0x03,
63 BMA_RANGE_4G = 0x04,
64 BMA_RANGE_8G = 0x05,
65 BMA_RANGE_16G = 0x06 };
67 /* Measurement bandwidth */
68 #define BMA_BW_MASK 0xF0
69 #define BMA_BW_SHIFT 4
70 enum bma180_bandwidth { BMA_BW_10HZ = 0x00,
71 BMA_BW_20HZ = 0x01,
72 BMA_BW_40HZ = 0x02,
73 BMA_BW_75HZ = 0x03,
74 BMA_BW_150HZ = 0x04,
75 BMA_BW_300HZ = 0x05,
76 BMA_BW_600HZ = 0x06,
77 BMA_BW_1200HZ = 0x07,
78 BMA_BW_HP1HZ = 0x08, // High-pass, 1 Hz
79 BMA_BW_BP0_300HZ = 0x09 // Band-pass, 0.3Hz-300Hz
82 #define BMA_NEW_DAT_INT 0x02
84 struct pios_bma180_data {
85 int16_t x;
86 int16_t y;
87 int16_t z;
88 int8_t temperature;
92 struct pios_bma180_cfg {
93 const struct pios_exti_cfg *exti_cfg; /* Pointer to the EXTI configuration */
94 enum bma180_bandwidth bandwidth;
95 enum bma180_range range;
98 /* Public Functions */
99 extern int32_t PIOS_BMA180_Init(uint32_t spi_id, uint32_t slave_num, const struct pios_bma180_cfg *cfg);
100 extern void PIOS_BMA180_Attach(uint32_t spi_id);
101 extern float PIOS_BMA180_GetScale();
102 extern int32_t PIOS_BMA180_ReadFifo(struct pios_bma180_data *buffer);
103 extern int32_t PIOS_BMA180_ReadAccels(struct pios_bma180_data *data);
104 extern int32_t PIOS_BMA180_Test();
105 extern bool PIOS_BMA180_IRQHandler();
107 #endif /* PIOS_BMA180_H */
110 * @}
111 * @}