amiro-lld / drivers / MPU6050 / v1 / alld_MPU6050.c @ e637a510
History | View | Annotate | Download (4.174 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 |
/******************************************************************************/
|
| 32 |
/* LOCAL DEFINITIONS */
|
| 33 |
/******************************************************************************/
|
| 34 |
|
| 35 |
/******************************************************************************/
|
| 36 |
/* EXPORTED VARIABLES */
|
| 37 |
/******************************************************************************/
|
| 38 |
|
| 39 |
/******************************************************************************/
|
| 40 |
/* LOCAL TYPES */
|
| 41 |
/******************************************************************************/
|
| 42 |
|
| 43 |
/******************************************************************************/
|
| 44 |
/* LOCAL VARIABLES */
|
| 45 |
/******************************************************************************/
|
| 46 |
|
| 47 |
/******************************************************************************/
|
| 48 |
/* LOCAL FUNCTIONS */
|
| 49 |
/******************************************************************************/
|
| 50 |
|
| 51 |
/******************************************************************************/
|
| 52 |
/* EXPORTED FUNCTIONS */
|
| 53 |
/******************************************************************************/
|
| 54 |
|
| 55 |
// from alld_ina219.c
|
| 56 |
/**
|
| 57 |
* @brief Read the value of one or more of the registers.
|
| 58 |
* @param[in] i2cd i2c driver
|
| 59 |
* @param[in] inad ina219 driver
|
| 60 |
* @param[in] addr register address
|
| 61 |
* @param[out] data register content
|
| 62 |
* @param[in] num number of subsequent registers to read
|
| 63 |
* @param[in] timeout timeout
|
| 64 |
* @return An indicator whether the call was successfull
|
| 65 |
*/
|
| 66 |
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) |
| 67 |
{
|
| 68 |
apalDbgAssert(mpu6050 != 0);
|
| 69 |
apalDbgAssert(mpu6050->i2cd != 0);
|
| 70 |
apalDbgAssert(data != 0);
|
| 71 |
|
| 72 |
return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), &addr, 1, data, num, timeout); |
| 73 |
} |
| 74 |
|
| 75 |
/**
|
| 76 |
* @brief Write the value of one or more of the registers.
|
| 77 |
* @param[in] i2cd i2c driver
|
| 78 |
* @param[in] inad ina219 driver
|
| 79 |
* @param[in] addr register address
|
| 80 |
* @param[in] data data to write
|
| 81 |
* @param[in] num number of subsequent registers to read
|
| 82 |
* @param[in] timeout timeout
|
| 83 |
* @return An indicator whether the call was successfull
|
| 84 |
*/
|
| 85 |
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) |
| 86 |
{
|
| 87 |
apalDbgAssert(mpu6050 != 0);
|
| 88 |
apalDbgAssert(mpu6050->i2cd != 0);
|
| 89 |
apalDbgAssert(data != 0);
|
| 90 |
|
| 91 |
uint8_t buffer[1+num];
|
| 92 |
buffer[0] = addr;
|
| 93 |
for (uint8_t dataIdx = 0; dataIdx < num; dataIdx++) { |
| 94 |
buffer[dataIdx+1] = data[dataIdx];
|
| 95 |
} |
| 96 |
return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), buffer, 1+num, NULL, 0, timeout); |
| 97 |
} |