Revision b6364b51

View differences:

include/MPU6050/v1/alld_MPU6050_v1.h
40 40
 */
41 41
#define MPU6050_LLD_I2C_MAXFREQUENCY    400000
42 42

  
43
#define SD_MPU6050_DataRate_8KHz        0   /**< Sample rate set to 8 kHz */
44
#define SD_MPU6050_DataRate_4KHz        1   /**< Sample rate set to 4 kHz */
45
#define SD_MPU6050_DataRate_2KHz        3   /**< Sample rate set to 2 kHz */
46
#define SD_MPU6050_DataRate_1KHz        7   /**< Sample rate set to 1 kHz */
47
#define SD_MPU6050_DataRate_500Hz       15  /**< Sample rate set to 500 Hz */
48
#define SD_MPU6050_DataRate_250Hz       31  /**< Sample rate set to 250 Hz */
49
#define SD_MPU6050_DataRate_125Hz       63  /**< Sample rate set to 125 Hz */
50
#define SD_MPU6050_DataRate_100Hz       79  /**< Sample rate set to 100 Hz */
43
/* Default I2C address */
44
#define MPU6050_LLD_I2C_ADDR_FIXED      0x68
45
#define MPU6050_LLD_I2C_ADDR_AD0        0x01
46

  
47
/* MPU6050 registers */
48
#define MPU6050_LLD_AUX_VDDIO   0x01
49
#define MPU6050_LLD_SMPLRT_DIV   0x19
50
#define MPU6050_LLD_CONFIG    0x1A
51
#define MPU6050_LLD_GYRO_CONFIG   0x1B
52
#define MPU6050_LLD_ACCEL_CONFIG  0x1C
53
#define MPU6050_LLD_MOTION_THRESH  0x1F
54
#define MPU6050_LLD_INT_PIN_CFG   0x37
55
#define MPU6050_LLD_INT_ENABLE   0x38
56
#define MPU6050_LLD_INT_STATUS   0x3A
57
#define MPU6050_LLD_ACCEL_XOUT_H  0x3B
58
#define MPU6050_LLD_ACCEL_XOUT_L  0x3C
59
#define MPU6050_LLD_ACCEL_YOUT_H  0x3D
60
#define MPU6050_LLD_ACCEL_YOUT_L  0x3E
61
#define MPU6050_LLD_ACCEL_ZOUT_H  0x3F
62
#define MPU6050_LLD_ACCEL_ZOUT_L  0x40
63
#define MPU6050_LLD_TEMP_OUT_H   0x41
64
#define MPU6050_LLD_TEMP_OUT_L   0x42
65
#define MPU6050_LLD_GYRO_XOUT_H   0x43
66
#define MPU6050_LLD_GYRO_XOUT_L   0x44
67
#define MPU6050_LLD_GYRO_YOUT_H   0x45
68
#define MPU6050_LLD_GYRO_YOUT_L   0x46
69
#define MPU6050_LLD_GYRO_ZOUT_H   0x47
70
#define MPU6050_LLD_GYRO_ZOUT_L   0x48
71
#define MPU6050_LLD_MOT_DETECT_STATUS 0x61
72
#define MPU6050_LLD_SIGNAL_PATH_RESET 0x68
73
#define MPU6050_LLD_MOT_DETECT_CTRL  0x69
74
#define MPU6050_LLD_USER_CTRL   0x6A
75
#define MPU6050_LLD_PWR_MGMT_1   0x6B
76
#define MPU6050_LLD_PWR_MGMT_2   0x6C
77
#define MPU6050_LLD_FIFO_COUNTH   0x72
78
#define MPU6050_LLD_FIFO_COUNTL   0x73
79
#define MPU6050_LLD_FIFO_R_W   0x74
80
#define MPU6050_LLD_WHO_AM_I   0x75
81

  
82
#define MPU6050_LLD_DataRate_8KHz        0   /**< Sample rate set to 8 kHz */
83
#define MPU6050_LLD_DataRate_4KHz        1   /**< Sample rate set to 4 kHz */
84
#define MPU6050_LLD_DataRate_2KHz        3   /**< Sample rate set to 2 kHz */
85
#define MPU6050_LLD_DataRate_1KHz        7   /**< Sample rate set to 1 kHz */
86
#define MPU6050_LLD_DataRate_500Hz       15  /**< Sample rate set to 500 Hz */
87
#define MPU6050_LLD_DataRate_250Hz       31  /**< Sample rate set to 250 Hz */
88
#define MPU6050_LLD_DataRate_125Hz       63  /**< Sample rate set to 125 Hz */
89
#define MPU6050_LLD_DataRate_100Hz       79  /**< Sample rate set to 100 Hz */
90

  
91
/* Who I am register value */
92
#define MPU6050_I_AM    MPU6050_LLD_I2C_ADDR_FIXED
93

  
94
/* Gyro sensitivities in degrees/s */
95
#define MPU6050_LLD_GYRO_SENS_250  ((float) 131)
96
#define MPU6050_LLD_GYRO_SENS_500  ((float) 65.5)
97
#define MPU6050_LLD_GYRO_SENS_1000  ((float) 32.8)
98
#define MPU6050_LLD_GYRO_SENS_2000  ((float) 16.4)
99

  
100
/* Acce sensitivities in g/s */
101
#define MPU6050_LLD_ACCE_SENS_2   ((float) 16384)
102
#define MPU6050_LLD_ACCE_SENS_4   ((float) 8192)
103
#define MPU6050_LLD_ACCE_SENS_8   ((float) 4096)
104
#define MPU6050_LLD_ACCE_SENS_16  ((float) 2048)
51 105

  
52 106
/******************************************************************************/
53 107
/* SETTINGS                                                                   */
......
62 116
/******************************************************************************/
63 117

  
64 118
/**
65
 * @brief I2C address masks. TODO: Set to MPU6050 adresses!
66
 */
67
enum {
68
  MPU6050_LLD_I2C_ADDR_FIXED   = 0x0040u,
69
  MPU6050_LLD_I2C_ADDR_A0      = 0x0001u,
70
  MPU6050_LLD_I2C_ADDR_A1      = 0x0004u,
71
};
72

  
73
/**
74
 * @brief Registers. TODO: Adjust to MPU6050 registers
75
 */
76
typedef enum {
77
  MPU6050_LLD_REGISTER_CONFIGURATION = 0x00,
78
  MPU6050_LLD_REGISTER_SHUNT_VOLTAGE = 0x01,
79
  MPU6050_LLD_REGISTER_BUS_VOLTAGE   = 0x02,
80
  MPU6050_LLD_REGISTER_POWER         = 0x03,
81
  MPU6050_LLD_REGISTER_CURRENT       = 0x04,
82
  MPU6050_LLD_REGISTER_CALIBRATION   = 0x05,
83
} mpu6050_lld_register_t;
84

  
85
/**
86 119
 * @brief  MPU6050 can have 2 different slave addresses, depends on it's input AD0 pin
87 120
 *         This feature allows you to use 2 different sensors with this library at the same time
88 121
 */
......
163 196
typedef struct {
164 197
  apalI2CDriver_t* i2cd;
165 198
  apalI2Caddr_t addr;   /**<The address of the module for I2C communication */
166
  uint16_t current_lsb_uA;
167
  mpu6050_lld_cfg_t *config;
168 199
} MPU6050Driver;
169 200

  
170 201
/******************************************************************************/
......
178 209
#ifdef __cplusplus
179 210
extern "C" {
180 211
#endif
181
  apalExitStatus_t mpu6050_lld_read_register(const MPU6050Driver* const mpu6050, const mpu6050_lld_register_t addr, uint16_t* const data, const uint8_t num, const apalTime_t timeout);
182
  apalExitStatus_t mpu6050_lld_write_register(const MPU6050Driver* const mpu6050, const mpu6050_lld_register_t addr, const uint16_t* const data, const uint8_t num, const apalTime_t timeout);
212
  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);
213
  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);
183 214
#ifdef __cplusplus
184 215
}
185 216
#endif
source/MPU6050/v1/alld_MPU6050_v1.c
34 34
/* LOCAL DEFINITIONS                                                          */
35 35
/******************************************************************************/
36 36

  
37
/* Default I2C address */
38
#define MPU6050_I2C_ADDR   0xD0
39

  
40
/* Who I am register value */
41
#define MPU6050_I_AM    0x68
42

  
43
/* MPU6050 registers */
44
#define MPU6050_AUX_VDDIO   0x01
45
#define MPU6050_SMPLRT_DIV   0x19
46
#define MPU6050_CONFIG    0x1A
47
#define MPU6050_GYRO_CONFIG   0x1B
48
#define MPU6050_ACCEL_CONFIG  0x1C
49
#define MPU6050_MOTION_THRESH  0x1F
50
#define MPU6050_INT_PIN_CFG   0x37
51
#define MPU6050_INT_ENABLE   0x38
52
#define MPU6050_INT_STATUS   0x3A
53
#define MPU6050_ACCEL_XOUT_H  0x3B
54
#define MPU6050_ACCEL_XOUT_L  0x3C
55
#define MPU6050_ACCEL_YOUT_H  0x3D
56
#define MPU6050_ACCEL_YOUT_L  0x3E
57
#define MPU6050_ACCEL_ZOUT_H  0x3F
58
#define MPU6050_ACCEL_ZOUT_L  0x40
59
#define MPU6050_TEMP_OUT_H   0x41
60
#define MPU6050_TEMP_OUT_L   0x42
61
#define MPU6050_GYRO_XOUT_H   0x43
62
#define MPU6050_GYRO_XOUT_L   0x44
63
#define MPU6050_GYRO_YOUT_H   0x45
64
#define MPU6050_GYRO_YOUT_L   0x46
65
#define MPU6050_GYRO_ZOUT_H   0x47
66
#define MPU6050_GYRO_ZOUT_L   0x48
67
#define MPU6050_MOT_DETECT_STATUS 0x61
68
#define MPU6050_SIGNAL_PATH_RESET 0x68
69
#define MPU6050_MOT_DETECT_CTRL  0x69
70
#define MPU6050_USER_CTRL   0x6A
71
#define MPU6050_PWR_MGMT_1   0x6B
72
#define MPU6050_PWR_MGMT_2   0x6C
73
#define MPU6050_FIFO_COUNTH   0x72
74
#define MPU6050_FIFO_COUNTL   0x73
75
#define MPU6050_FIFO_R_W   0x74
76
#define MPU6050_WHO_AM_I   0x75
77

  
78
/* Gyro sensitivities in degrees/s */
79
#define MPU6050_GYRO_SENS_250  ((float) 131)
80
#define MPU6050_GYRO_SENS_500  ((float) 65.5)
81
#define MPU6050_GYRO_SENS_1000  ((float) 32.8)
82
#define MPU6050_GYRO_SENS_2000  ((float) 16.4)
83

  
84
/* Acce sensitivities in g/s */
85
#define MPU6050_ACCE_SENS_2   ((float) 16384)
86
#define MPU6050_ACCE_SENS_4   ((float) 8192)
87
#define MPU6050_ACCE_SENS_8   ((float) 4096)
88
#define MPU6050_ACCE_SENS_16  ((float) 2048)
89

  
90 37
/******************************************************************************/
91 38
/* EXPORTED VARIABLES                                                         */
92 39
/******************************************************************************/
......
118 65
 * @param[in]   timeout     timeout
119 66
 * @return                  An indicator whether the call was successfull
120 67
 */
121
apalExitStatus_t mpu6050_lld_read_register(const MPU6050Driver* const mpu6050, const mpu6050_lld_register_t addr, uint16_t* const data, const uint8_t num, const apalTime_t timeout)
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)
122 69
{
123 70
  apalDbgAssert(mpu6050 != 0);
124 71
  apalDbgAssert(mpu6050->i2cd != 0);
125 72
  apalDbgAssert(data != 0);
126 73

  
127
  uint8_t buffer[num*2];
128
  apalExitStatus_t status = apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), (uint8_t*)&addr, 1, buffer, 2*num, timeout);
129
  for (uint8_t dataIdx = 0; dataIdx < num; dataIdx++) {
130
    data[dataIdx] = (buffer[2*dataIdx] << 8) | buffer[2*dataIdx+1];
131
  }
132
  return status;
74
  return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), &addr, 1, data, num, timeout);
133 75
}
134 76

  
135 77
/**
......
142 84
 * @param[in]   timeout     timeout
143 85
 * @return                  An indicator whether the call was successfull
144 86
 */
145
apalExitStatus_t mpu6050_lld_write_register(const MPU6050Driver* const mpu6050, const mpu6050_lld_register_t addr, const uint16_t* const data, const uint8_t num, const apalTime_t timeout)
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)
146 88
{
147 89
  apalDbgAssert(mpu6050 != 0);
148 90
  apalDbgAssert(mpu6050->i2cd != 0);
149 91
  apalDbgAssert(data != 0);
150 92

  
151
  uint8_t buffer[1+2*num];
93
  uint8_t buffer[1+num];
152 94
  buffer[0] = addr;
153 95
  for (uint8_t dataIdx = 0; dataIdx < num; dataIdx++) {
154
    buffer[dataIdx*2+1] = data[dataIdx] >> 8;
155
    buffer[dataIdx*2+2] = data[dataIdx] & (0x00FFu);
96
    buffer[dataIdx+1] = data[dataIdx];
156 97
  }
157
  return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), buffer, 1+2*num, NULL, 0, timeout);
98
  return apalI2CMasterTransmit(mpu6050->i2cd, (MPU6050_LLD_I2C_ADDR_FIXED | mpu6050->addr), buffer, 1+num, NULL, 0, timeout);
158 99
}
159 100

  
160 101
#endif /* defined(AMIROLLD_CFG_MPU6050) && (AMIROLLD_CFG_MPU6050 == 1) */

Also available in: Unified diff