2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
5 * @addtogroup PIOS_BMA180 BMA180 Functions
6 * @brief Deals with the hardware interface to the BMA180 3-axis accelerometer
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
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
35 #include "fifo_buffer.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
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,
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,
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
{
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 */