42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
68#define MPUIMU_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.fsy = MIKROBUS( mikrobus, MIKROBUS_RST ); \
76 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
83#define MPUIMU_MASTER_I2C 0
84#define MPUIMU_MASTER_SPI 1
91#define MPUIMU_RETVAL uint8_t
94#define MPUIMU_INIT_ERROR 0xFF
101#define MPUIMU_I2C_ADDR_0 0xD2
102#define MPUIMU_I2C_ADDR_1 0x69
109#define MPUIMU_REG_SELF_TEST_X 0x0D
110#define MPUIMU_REG_SELF_TEST_Y 0x0E
111#define MPUIMU_REG_SELF_TEST_Z 0x0F
112#define MPUIMU_REG_SELF_TEST_A 0x10
113#define MPUIMU_REG_SMPLRT_DIV 0x19
114#define MPUIMU_REG_MOT_THR 0x1F
115#define MPUIMU_REG_I2C_MST_CTRL 0x24
116#define MPUIMU_REG_I2C_SLV0_ADDR 0x25
117#define MPUIMU_REG_I2C_SLV0 0x26
118#define MPUIMU_REG_I2C_SLV0_CTRL 0x27
119#define MPUIMU_REG_I2C_SLV1_ADDR 0x28
120#define MPUIMU_REG_I2C_SLV1 0x29
121#define MPUIMU_REG_I2C_SLV1_CTRL 0x2A
122#define MPUIMU_REG_I2C_SLV2_ADDR 0x2B
123#define MPUIMU_REG_I2C_SLV2 0x2C
124#define MPUIMU_REG_I2C_SLV2_CTRL 0x2D
125#define MPUIMU_REG_I2C_SLV3_ADDR 0x2E
126#define MPUIMU_REG_I2C_SLV3 0x2F
127#define MPUIMU_REG_I2C_SLV3_CTRL 0x30
128#define MPUIMU_REG_I2C_SLV4_ADDR 0x31
129#define MPUIMU_REG_I2C_SLV4 0x32
130#define MPUIMU_REG_I2C_SLV4_DO 0x33
131#define MPUIMU_REG_I2C_SLV4_CTRL 0x34
132#define MPUIMU_REG_I2C_SLV4_DI 0x35
133#define MPUIMU_REG_I2C_MST_STATUS 0x36
134#define MPUIMU_REG_I2C_SLV0_DO 0x63
135#define MPUIMU_REG_I2C_SLV1_DO 0x64
136#define MPUIMU_REG_I2C_SLV2_DO 0x65
137#define MPUIMU_REG_I2C_SLV3_DO 0x66
138#define MPUIMU_REG_I2C_MST_DELAY_CT 0x67
139#define MPUIMU_REG_INT_PIN_CFG 0x37
140#define MPUIMU_REG_INT_ENABLE 0x38
141#define MPUIMU_REG_INT_STATUS 0x3A
142#define MPUIMU_REG_SIGNAL_PATH_RES 0x68
143#define MPUIMU_REG_MOT_DETECT_CTRL 0x69
144#define MPUIMU_REG_USER_CTRL 0x6A
145#define MPUIMU_REG_PWR_MGMT_1 0x6B
146#define MPUIMU_REG_PWR_MGMT_2 0x6C
147#define MPUIMU_REG_FIFO_EN 0x23
148#define MPUIMU_REG_FIFO_COUNTH 0x72
149#define MPUIMU_REG_FIFO_COUNTL 0x73
150#define MPUIMU_REG_FIFO_R_W 0x74
151#define MPUIMU_REG_WHO_AM_I 0x75
158#define MPUIMU_CFG_CONFIG 0x1A
159#define MPUIMU_CFG_RAW_ACCEL 0x3B
160#define MPUIMU_CFG_RAW_GYRO 0x43
161#define MPUIMU_CFG_STANDARD_GYRO 0x1B
162#define MPUIMU_CFG_STANDARD_ACCEL 0x1C
163#define MPUIMU_CFG_PWR 0x80
164#define MPUIMU_CFG_PWR_SET 0x00
165#define MPUIMU_CFG_FIFO_ENABLE 0x78
166#define MPUIMU_CFG_INT_ENABLE 0x10
173#define MPUIMU_EXT_SENS_DATA_00 0x49
174#define MPUIMU_EXT_SENS_DATA_01 0x4A
175#define MPUIMU_EXT_SENS_DATA_02 0x4B
176#define MPUIMU_EXT_SENS_DATA_03 0x4C
177#define MPUIMU_EXT_SENS_DATA_04 0x4D
178#define MPUIMU_EXT_SENS_DATA_05 0x4E
179#define MPUIMU_EXT_SENS_DATA_06 0x4F
180#define MPUIMU_EXT_SENS_DATA_07 0x50
181#define MPUIMU_EXT_SENS_DATA_08 0x51
182#define MPUIMU_EXT_SENS_DATA_11 0x54
183#define MPUIMU_EXT_SENS_DATA_09 0x52
184#define MPUIMU_EXT_SENS_DATA_10 0x53
185#define MPUIMU_EXT_SENS_DATA_12 0x55
186#define MPUIMU_EXT_SENS_DATA_13 0x56
187#define MPUIMU_EXT_SENS_DATA_14 0x57
188#define MPUIMU_EXT_SENS_DATA_15 0x58
189#define MPUIMU_EXT_SENS_DATA_16 0x59
190#define MPUIMU_EXT_SENS_DATA_17 0x5A
191#define MPUIMU_EXT_SENS_DATA_18 0x5B
192#define MPUIMU_EXT_SENS_DATA_19 0x5C
193#define MPUIMU_EXT_SENS_DATA_20 0x5D
194#define MPUIMU_EXT_SENS_DATA_21 0x5E
195#define MPUIMU_EXT_SENS_DATA_22 0x5F
196#define MPUIMU_EXT_SENS_DATA_23 0x60
206#define MPUIMU_GYRO_XOUT_H 0x43
207#define MPUIMU_GYRO_XOUT_L 0x44
208#define MPUIMU_GYRO_YOUT_H 0x45
209#define MPUIMU_GYRO_YOUT_L 0x46
210#define MPUIMU_GYRO_ZOUT_H 0x47
211#define MPUIMU_GYRO_ZOUT_L 0x48
215#define MPUIMU_ACCEL_XOUT_H 0x3B
216#define MPUIMU_ACCEL_XOUT_L 0x3C
217#define MPUIMU_ACCEL_YOUT_H 0x3D
218#define MPUIMU_ACCEL_YOUT_L 0x3E
219#define MPUIMU_ACCEL_ZOUT_H 0x3F
220#define MPUIMU_ACCEL_ZOUT_L 0x40
224#define MPUIMU_TEMP_OUT_H 0x41
225#define MPUIMU_TEMP_OUT_L 0x42
#define MPUIMU_RETVAL
Definition mpuimu.h:91
void mpuimu_read_gyro(mpuimu_t *ctx, mpuimu_gyro_data_t *gyro_data)
Read Axis function.
void mpuimu_default_cfg(mpuimu_t *ctx)
Click Default Configuration function.
float mpuimu_read_temperature(mpuimu_t *ctx)
Temperature read function.
void software_reset(mpuimu_t *ctx)
Software reset function.
void mpuimu_generic_write(mpuimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void mpuimu_generic_read(mpuimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void mpuimu_cfg_setup(mpuimu_cfg_t *cfg)
Config Object Initialization function.
MPUIMU_RETVAL mpuimu_init(mpuimu_t *ctx, mpuimu_cfg_t *cfg)
Initialization function.
int16_t mpuimu_get_axis(mpuimu_t *ctx, uint8_t adr_reg_high)
High register data function.
void mpuimu_read_accel(mpuimu_t *ctx, mpuimu_accel_data_t *accel_data)
Read Axis function.
void(* mpuimu_master_io_t)(struct mpuimu_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition mpuimu.h:244
uint8_t mpuimu_select_t
Communication type.
Definition mpuimu.h:239
struct mpuimu_s mpuimu_t
Click ctx object definition.
mpuimu_accel_data_t accel_data
Definition main.c:35
mpuimu_gyro_data_t gyro_data
Definition main.c:36
int16_t accel_x
Definition mpuimu.h:313
int16_t accel_y
Definition mpuimu.h:314
int16_t accel_z
Definition mpuimu.h:315
Click configuration structure definition.
Definition mpuimu.h:279
mpuimu_select_t sel
Definition mpuimu.h:303
uint32_t i2c_speed
Definition mpuimu.h:296
spi_master_chip_select_polarity_t cs_polarity
Definition mpuimu.h:301
pin_name_t sck
Definition mpuimu.h:286
spi_master_mode_t spi_mode
Definition mpuimu.h:300
pin_name_t mosi
Definition mpuimu.h:285
uint32_t spi_speed
Definition mpuimu.h:299
pin_name_t scl
Definition mpuimu.h:282
pin_name_t int_pin
Definition mpuimu.h:292
pin_name_t fsy
Definition mpuimu.h:291
pin_name_t miso
Definition mpuimu.h:284
pin_name_t sda
Definition mpuimu.h:283
pin_name_t cs
Definition mpuimu.h:287
uint8_t i2c_address
Definition mpuimu.h:297
Gyro data object definition.
Definition mpuimu.h:323
int16_t gyro_y
Definition mpuimu.h:325
int16_t gyro_x
Definition mpuimu.h:324
int16_t gyro_z
Definition mpuimu.h:326
Click ctx object definition.
Definition mpuimu.h:250
digital_out_t cs
Definition mpuimu.h:253
digital_out_t fsy
Definition mpuimu.h:254
spi_master_t spi
Definition mpuimu.h:263
mpuimu_master_io_t read_f
Definition mpuimu.h:270
mpuimu_select_t master_sel
Definition mpuimu.h:271
digital_in_t int_pin
Definition mpuimu.h:258
i2c_master_t i2c
Definition mpuimu.h:262
uint8_t slave_address
Definition mpuimu.h:267
mpuimu_master_io_t write_f
Definition mpuimu.h:269
pin_name_t chip_select
Definition mpuimu.h:268