amiro-lld / source / MPU6050 / v1 / alld_MPU6050_v1.c @ 26dead12
History | View | Annotate | Download (4.338 KB)
1 |
/*
|
---|---|
2 |
* sd_hal_mpu6050.c
|
3 |
*
|
4 |
* Created on: Feb 19, 2016
|
5 |
* Author: Sina Darvishi
|
6 |
* Edited on: Jan 15, 2019
|
7 |
* Editor: Simon Welzel
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* |----------------------------------------------------------------------
|
12 |
* | Copyright (C) Sina Darvishi,2016
|
13 |
* |
|
14 |
* | This program is free software: you can redistribute it and/or modify
|
15 |
* | it under the terms of the GNU General Public License as published by
|
16 |
* | the Free Software Foundation, either version 3 of the License, or
|
17 |
* | any later version.
|
18 |
* |
|
19 |
* | This program is distributed in the hope that it will be useful,
|
20 |
* | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
* | GNU General Public License for more details.
|
23 |
* |
|
24 |
* | You should have received a copy of the GNU General Public License
|
25 |
* | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
26 |
* |----------------------------------------------------------------------
|
27 |
*/
|
28 |
|
29 |
#include <alld_MPU6050.h> |
30 |
|
31 |
#if (defined(AMIROLLD_CFG_MPU6050) && (AMIROLLD_CFG_MPU6050 == 1)) || defined(__DOXYGEN__) |
32 |
|
33 |
/******************************************************************************/
|
34 |
/* LOCAL DEFINITIONS */
|
35 |
/******************************************************************************/
|
36 |
|
37 |
/******************************************************************************/
|
38 |
/* EXPORTED VARIABLES */
|
39 |
/******************************************************************************/
|
40 |
|
41 |
/******************************************************************************/
|
42 |
/* LOCAL TYPES */
|
43 |
/******************************************************************************/
|
44 |
|
45 |
/******************************************************************************/
|
46 |
/* LOCAL VARIABLES */
|
47 |
/******************************************************************************/
|
48 |
|
49 |
/******************************************************************************/
|
50 |
/* LOCAL FUNCTIONS */
|
51 |
/******************************************************************************/
|
52 |
|
53 |
/******************************************************************************/
|
54 |
/* EXPORTED FUNCTIONS */
|
55 |
/******************************************************************************/
|
56 |
|
57 |
// from alld_ina219.c
|
58 |
/**
|
59 |
* @brief Read the value of one or more of the registers.
|
60 |
* @param[in] i2cd i2c driver
|
61 |
* @param[in] inad ina219 driver
|
62 |
* @param[in] addr register address
|
63 |
* @param[out] data register content
|
64 |
* @param[in] num number of subsequent registers to read
|
65 |
* @param[in] timeout timeout
|
66 |
* @return An indicator whether the call was successfull
|
67 |
*/
|
68 |
apalExitStatus_t mpu6050_lld_read_register(const MPU6050Driver* const mpu6050, const uint8_t addr, uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
69 |
{ |
70 |
apalDbgAssert(mpu6050 != 0);
|
71 |
apalDbgAssert(mpu6050->i2cd != 0);
|
72 |
apalDbgAssert(data != 0);
|
73 |
|
74 |
return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), &addr, 1, data, num, timeout); |
75 |
} |
76 |
|
77 |
/**
|
78 |
* @brief Write the value of one or more of the registers.
|
79 |
* @param[in] i2cd i2c driver
|
80 |
* @param[in] inad ina219 driver
|
81 |
* @param[in] addr register address
|
82 |
* @param[in] data data to write
|
83 |
* @param[in] num number of subsequent registers to read
|
84 |
* @param[in] timeout timeout
|
85 |
* @return An indicator whether the call was successfull
|
86 |
*/
|
87 |
apalExitStatus_t mpu6050_lld_write_register(const MPU6050Driver* const mpu6050, const uint8_t addr, const uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
88 |
{ |
89 |
apalDbgAssert(mpu6050 != 0);
|
90 |
apalDbgAssert(mpu6050->i2cd != 0);
|
91 |
apalDbgAssert(data != 0);
|
92 |
|
93 |
uint8_t buffer[1+num];
|
94 |
buffer[0] = addr;
|
95 |
for (uint8_t dataIdx = 0; dataIdx < num; dataIdx++) { |
96 |
buffer[dataIdx+1] = data[dataIdx];
|
97 |
} |
98 |
return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), buffer, 1+num, NULL, 0, timeout); |
99 |
} |
100 |
|
101 |
#endif /* defined(AMIROLLD_CFG_MPU6050) && (AMIROLLD_CFG_MPU6050 == 1) */ |
102 |
|