Revision ed9a1bf5 drivers/MPU6050/v1/alld_MPU6050.c

View differences:

drivers/MPU6050/v1/alld_MPU6050.c
1 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
 */
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.
9 4

  
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
 */
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
*/
28 18

  
29 19
#include <alld_MPU6050.h>
30 20

  
21
#include <string.h>
22

  
31 23
/******************************************************************************/
32 24
/* LOCAL DEFINITIONS                                                          */
33 25
/******************************************************************************/
......
52 44
/* EXPORTED FUNCTIONS                                                         */
53 45
/******************************************************************************/
54 46

  
55
// from alld_ina219.c
56 47
/**
57 48
 * @brief Read the value of one or more of the registers.
58 49
 * @param[in]   i2cd        i2c driver
......
63 54
 * @param[in]   timeout     timeout
64 55
 * @return                  An indicator whether the call was successfull
65 56
 */
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)
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)
67 58
{
68
  apalDbgAssert(mpu6050 != 0);
69
  apalDbgAssert(mpu6050->i2cd != 0);
70
  apalDbgAssert(data != 0);
59
  apalDbgAssert(mpu6050 != NULL);
60
  apalDbgAssert(mpu6050->i2cd != NULL);
61
  apalDbgAssert(data != NULL || num == 0);
71 62

  
72
  return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), &addr, 1, data, num, timeout);
63
  return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), (uint8_t*)&addr, 1, data, num, timeout);
73 64
}
74 65

  
75 66
/**
......
82 73
 * @param[in]   timeout     timeout
83 74
 * @return                  An indicator whether the call was successfull
84 75
 */
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)
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)
86 77
{
87
  apalDbgAssert(mpu6050 != 0);
88
  apalDbgAssert(mpu6050->i2cd != 0);
89
  apalDbgAssert(data != 0);
78
  apalDbgAssert(mpu6050 != NULL);
79
  apalDbgAssert(mpu6050->i2cd != NULL);
80
  apalDbgAssert(data != NULL || num == 0);
90 81

  
91 82
  uint8_t buffer[1+num];
92 83
  buffer[0] = addr;
93
  for (uint8_t dataIdx = 0; dataIdx < num; dataIdx++) {
94
    buffer[dataIdx+1] = data[dataIdx];
95
  }
84
  memcpy(&buffer[1], data, num);
96 85
  return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), buffer, 1+num, NULL, 0, timeout);
97 86
}

Also available in: Unified diff