Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / MPU6050 / v1 / alld_MPU6050_v1.h @ 69a601a5

History | View | Annotate | Download (7.064 KB)

1 5d4d14a3 Thomas Schöpping
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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
/**
20
 * @file    alld_MPU6050_v1.h
21
 * @brief   Gyro & Accelerometer macros and structures.
22
 *
23
 * @addtogroup lld_mems
24
 * @{
25
 */
26
27
#ifndef AMIROLLD_MPU6050_V1_H
28
#define AMIROLLD_MPU6050_V1_H
29
30
#include <amiro-lld.h>
31
32
#if (defined(AMIROLLD_CFG_MPU6050) && (AMIROLLD_CFG_MPU6050 == 1)) || defined(__DOXYGEN__)
33
34
/******************************************************************************/
35
/* CONSTANTS                                                                  */
36
/******************************************************************************/
37
38
/**
39
 * @brief Maximum I2C frequency.
40
 */
41
#define MPU6050_LLD_I2C_MAXFREQUENCY    400000
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 */
51
52
/******************************************************************************/
53
/* SETTINGS                                                                   */
54
/******************************************************************************/
55
56
/******************************************************************************/
57
/* CHECKS                                                                     */
58
/******************************************************************************/
59
60
/******************************************************************************/
61
/* DATA STRUCTURES AND TYPES                                                  */
62
/******************************************************************************/
63
64
/**
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
 * @brief  MPU6050 can have 2 different slave addresses, depends on it's input AD0 pin
87
 *         This feature allows you to use 2 different sensors with this library at the same time
88
 */
89
typedef enum  {
90
        SD_MPU6050_Device_0 = 0x00, /*!< AD0 pin is set to low */
91
        SD_MPU6050_Device_1 = 0x02  /*!< AD0 pin is set to high */
92
} SD_MPU6050_Device;
93
94
/**
95
 * @brief  MPU6050 result enumeration
96
 */
97
typedef enum  {
98
        SD_MPU6050_Result_Ok = 0x00,          /*!< Everything OK */
99
        SD_MPU6050_Result_Error,              /*!< Unknown error */
100
        SD_MPU6050_Result_DeviceNotConnected, /*!< There is no device with valid slave address */
101
        SD_MPU6050_Result_DeviceInvalid       /*!< Connected device with address is not MPU6050 */
102
} SD_MPU6050_Result;
103
104
/**
105
 * @brief  Parameters for accelerometer range
106
 */
107
typedef enum  {
108
        SD_MPU6050_Accelerometer_2G = 0x00, /*!< Range is +- 2G */
109
        SD_MPU6050_Accelerometer_4G = 0x01, /*!< Range is +- 4G */
110
        SD_MPU6050_Accelerometer_8G = 0x02, /*!< Range is +- 8G */
111
        SD_MPU6050_Accelerometer_16G = 0x03 /*!< Range is +- 16G */
112
} SD_MPU6050_Accelerometer;
113
114
/**
115
 * @brief  Parameters for gyroscope range
116
 */
117
typedef enum {
118
        SD_MPU6050_Gyroscope_250s = 0x00,  /*!< Range is +- 250 degrees/s */
119
        SD_MPU6050_Gyroscope_500s = 0x01,  /*!< Range is +- 500 degrees/s */
120
        SD_MPU6050_Gyroscope_1000s = 0x02, /*!< Range is +- 1000 degrees/s */
121
        SD_MPU6050_Gyroscope_2000s = 0x03  /*!< Range is +- 2000 degrees/s */
122
} SD_MPU6050_Gyroscope;
123
124
125
/**
126
 * @brief  Interrupts union and structure
127
 */
128
typedef union {
129
        struct {
130
                uint8_t DataReady:1;       /*!< Data ready interrupt */
131
                uint8_t reserved2:2;       /*!< Reserved bits */
132
                uint8_t Master:1;          /*!< Master interrupt. Not enabled with library */
133
                uint8_t FifoOverflow:1;    /*!< FIFO overflow interrupt. Not enabled with library */
134
                uint8_t reserved1:1;       /*!< Reserved bit */
135
                uint8_t MotionDetection:1; /*!< Motion detected interrupt */
136
                uint8_t reserved0:1;       /*!< Reserved bit */
137
        } F;
138
        uint8_t Status;
139
} SD_MPU6050_Interrupt;
140
141
/**
142
 * @brief Config register.
143
 */
144
typedef union {
145
  uint16_t data;
146
  struct {
147
    /**
148
    ina219_lld_mode_t mode : 3;
149
    ina219_lld_adc_t sadc : 4;
150
    ina219_lld_adc_t badc : 4;
151
    ina219_lld_gain_t gain : 2;
152
    ina219_lld_brng_t brng : 1;
153
    */
154
    uint8_t zero : 1;
155
    uint8_t reset : 1;
156
  } options;
157
} mpu6050_lld_cfg_t;
158
159
160
/**
161
 * @brief The MPU6050 struct.
162
 */
163
typedef struct {
164
  apalI2CDriver_t* i2cd;
165
  apalI2Caddr_t addr;   /**<The address of the module for I2C communication */
166
  uint16_t current_lsb_uA;
167
  mpu6050_lld_cfg_t *config;
168
} MPU6050Driver;
169
170
/******************************************************************************/
171
/* MACROS                                                                     */
172
/******************************************************************************/
173
174
/******************************************************************************/
175
/* EXTERN DECLARATIONS                                                        */
176
/******************************************************************************/
177
178
#ifdef __cplusplus
179
extern "C" {
180
#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);
183
#ifdef __cplusplus
184
}
185
#endif
186
187
/******************************************************************************/
188
/* INLINE FUNCTIONS                                                           */
189
/******************************************************************************/
190
191
#endif /* defined(AMIROLLD_CFG_MPU6050) && (AMIROLLD_CFG_MPU6050 == 1) */
192
193
#endif /* AMIROLLD_MPU6050_V1_H */