ICM20948 DMP代码详解(38)
接前一篇文章:ICM20948 DMP代码详解(37)
上一回继续解析inv_icm20948_set_slave_compass_id函数,解析了第3段代码,本回解析接下来的代码。为了便于理解和回顾,再次贴出该函数源码,在EMD-Core\sources\Invn\Devices\Drivers\ICM20948\Icm20948DataBaseDriver.c中,如下:
int inv_icm20948_set_slave_compass_id(struct inv_icm20948 *s, int id)
{
int result = 0;
(void)id;
//result = inv_icm20948_wakeup_mems(s);
//if (result)
// return result;
inv_icm20948_prevent_lpen_control(s);
activate_compass(s);
inv_icm20948_init_secondary(s);
// Set up the secondary I2C bus on 20630.
inv_icm20948_set_secondary(s);
//Setup Compass
result = inv_icm20948_setup_compass_akm(s);
//Setup Compass mounting matrix into DMP
result |= inv_icm20948_compass_dmp_cal(s, s->mounting_matrix, s->mounting_matrix_secondary_compass);
if (result)
desactivate_compass(s);
//result = inv_icm20948_sleep_mems(s);
inv_icm20948_allow_lpen_control(s);
return result;
}
4)inv_icm20948_set_secondary函数
代码片段如下:
// Set up the secondary I2C bus on 20630.
inv_icm20948_set_secondary(s);
inv_icm20948_set_secondary函数在EMD-Core\sources\Invn\Devices\Drivers\ICM20948\Icm20948DataBaseDriver.c,代码如下:
/**
* @brief Set up the secondary I2C bus on 20630.
* @param[in] MPU state varible
* @return 0 if successful.
*/
int inv_icm20948_set_secondary(struct inv_icm20948 *s)
{
int r = 0;
static uint8_t lIsInited = 0;
if(lIsInited == 0)
{
r = inv_icm20948_write_single_mems_reg(s, REG_I2C_MST_CTRL, BIT_I2C_MST_P_NSR);
r |= inv_icm20948_write_single_mems_reg(s, REG_I2C_MST_ODR_CONFIG, MIN_MST_ODR_CONFIG);
lIsInited = 1;
}
return r;
}
REG_I2C_MST_CTRL、BIT_I2C_MST_P_NSR、REG_I2C_MST_ODR_CONFIG宏在EMD-Core\sources\Invn\Devices\Drivers\ICM20948\Icm20948Defs.h中,定义如下:
/* bank 3 register map */
#define REG_I2C_MST_ODR_CONFIG (BANK_3 | 0x0)
#define REG_I2C_MST_CTRL (BANK_3 | 0x01)
#define BIT_I2C_MST_P_NSR 0x10
#define REG_I2C_MST_DELAY_CTRL (BANK_3 | 0x02)
MIN_MST_ODR_CONFIG宏在EMD-Core\sources\Invn\Devices\Drivers\ICM20948\Icm20948Defs.h中,定义如下:
#define MIN_MST_ODR_CONFIG 4
综上,以下代码片段的意思是:
r = inv_icm20948_write_single_mems_reg(s, REG_I2C_MST_CTRL, BIT_I2C_MST_P_NSR);
写I2C_MST_CTRL寄存器的值为0x10,即I2C_MST_CLK[3:0]设置为0b0000;
MULT_MST_EN位为0;I2C_MST_P_NSR位为1。
以下代码片段的意思是:
r |= inv_icm20948_write_single_mems_reg(s, REG_I2C_MST_ODR_CONFIG, MIN_MST_ODR_CONFIG);
写I2C_MST_ODR_CONFIG寄存器的值为4(0x04),即I2C_MST_ODR_CONFIG[3:0]设置为0b0000。
同时,设置lIsInited变量的值为1。
至此,inv_icm20948_set_secondary函数就解析完了。inv_icm20948_set_slave_compass_id函数后续内容的解析请看下回。