amiro-lld / drivers / MPU6050 / v1 / alld_MPU6050.c @ 14c96f7f
History | View | Annotate | Download (3.988 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2020 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
#include <alld_MPU6050.h> |
20 |
|
21 |
#include <string.h> |
22 |
|
23 |
/******************************************************************************/
|
24 |
/* LOCAL DEFINITIONS */
|
25 |
/******************************************************************************/
|
26 |
|
27 |
/******************************************************************************/
|
28 |
/* EXPORTED VARIABLES */
|
29 |
/******************************************************************************/
|
30 |
|
31 |
/******************************************************************************/
|
32 |
/* LOCAL TYPES */
|
33 |
/******************************************************************************/
|
34 |
|
35 |
/******************************************************************************/
|
36 |
/* LOCAL VARIABLES */
|
37 |
/******************************************************************************/
|
38 |
|
39 |
/******************************************************************************/
|
40 |
/* LOCAL FUNCTIONS */
|
41 |
/******************************************************************************/
|
42 |
|
43 |
/******************************************************************************/
|
44 |
/* EXPORTED FUNCTIONS */
|
45 |
/******************************************************************************/
|
46 |
|
47 |
/**
|
48 |
* @brief Read the value of one or more of the registers.
|
49 |
* @param[in] i2cd i2c driver
|
50 |
* @param[in] inad ina219 driver
|
51 |
* @param[in] addr register address
|
52 |
* @param[out] data register content
|
53 |
* @param[in] num number of subsequent registers to read
|
54 |
* @param[in] timeout timeout
|
55 |
* @return An indicator whether the call was successfull
|
56 |
*/
|
57 |
apalExitStatus_t mpu6050_lld_read_register(const MPU6050Driver* const mpu6050, const mpu6050_lld_register_t addr, uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
58 |
{ |
59 |
apalDbgAssert(mpu6050 != NULL);
|
60 |
apalDbgAssert(mpu6050->i2cd != NULL);
|
61 |
apalDbgAssert(data != NULL || num == 0); |
62 |
|
63 |
return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), (uint8_t*)&addr, 1, data, num, timeout); |
64 |
} |
65 |
|
66 |
/**
|
67 |
* @brief Write the value of one or more of the registers.
|
68 |
* @param[in] i2cd i2c driver
|
69 |
* @param[in] inad ina219 driver
|
70 |
* @param[in] addr register address
|
71 |
* @param[in] data data to write
|
72 |
* @param[in] num number of subsequent registers to read
|
73 |
* @param[in] timeout timeout
|
74 |
* @return An indicator whether the call was successfull
|
75 |
*/
|
76 |
apalExitStatus_t mpu6050_lld_write_register(const MPU6050Driver* const mpu6050, const mpu6050_lld_register_t addr, const uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
77 |
{ |
78 |
apalDbgAssert(mpu6050 != NULL);
|
79 |
apalDbgAssert(mpu6050->i2cd != NULL);
|
80 |
apalDbgAssert(data != NULL || num == 0); |
81 |
|
82 |
uint8_t buffer[1+num];
|
83 |
buffer[0] = addr;
|
84 |
memcpy(&buffer[1], data, num);
|
85 |
return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), buffer, 1+num, NULL, 0, timeout); |
86 |
} |