i2c: all function calls are consistent. fixed some MISRA errors.
This commit is contained in:
parent
657ee06eed
commit
958b2e8e00
7 changed files with 71 additions and 68 deletions
49
bmp.c
49
bmp.c
|
|
@ -2,11 +2,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
#include "./bmp.h"
|
||||
|
||||
static const uint8_t BMP_RESET[2] = {0x7E, 0xB6};
|
||||
static const uint8_t BMP_CAL_DATA[21];
|
||||
static const uint8_t BMP_SETUP[6] = {0x1C, 0x0B, 0x1D, 0x08, 0x1F, 0x0A};
|
||||
static const uint8_t BMP_START[2] = {0x1B, 0x33};
|
||||
|
||||
float bmp_cal_data_fp[15];
|
||||
|
||||
int getBMPData(i2c_inst_t *i2c, float *temperature, float *pressure) {
|
||||
|
|
@ -75,44 +70,50 @@ int getBMPCalData(i2c_inst_t *i2c, bmp_cal_data_t *calData) {
|
|||
calData->NVM_PAR_T1 = (uint16_t)((rawValues[1] << 8) | rawValues[0]);
|
||||
calData->NVM_PAR_T2 = (uint16_t)((rawValues[3] << 8) | rawValues[2]);
|
||||
calData->NVM_PAR_T3 = (int8_t)(rawValues[4]);
|
||||
calData->NVM_PAR_P1 = (int16_t)((rawValues[6] << 8) | rawValues[5]);
|
||||
calData->NVM_PAR_P2 = (int16_t)((rawValues[8] << 8) | rawValues[7]);
|
||||
calData->NVM_PAR_P1 = ((int16_t)(rawValues[6] << 8) | (int16_t)rawValues[5]);
|
||||
calData->NVM_PAR_P2 = ((int16_t)(rawValues[8] << 8) | (int16_t)rawValues[7]);
|
||||
calData->NVM_PAR_P3 = (int8_t)(rawValues[9]);
|
||||
calData->NVM_PAR_P4 = (int8_t)(rawValues[10]);
|
||||
calData->NVM_PAR_P5 = (uint16_t)((rawValues[12] << 8) | rawValues[11]);
|
||||
calData->NVM_PAR_P6 = (uint16_t)((rawValues[14] << 8) | rawValues[13]);
|
||||
calData->NVM_PAR_P7 = (int8_t)(rawValues[15]);
|
||||
calData->NVM_PAR_P8 = (int8_t)(rawValues[16]);
|
||||
calData->NVM_PAR_P9 = (int16_t)((rawValues[18] << 8) | rawValues[17]);
|
||||
calData->NVM_PAR_P9 =
|
||||
((int16_t)(rawValues[18] << 8) | (int16_t)rawValues[17]);
|
||||
calData->NVM_PAR_P10 = (int8_t)(rawValues[19]);
|
||||
calData->NVM_PAR_P11 = (int8_t)(rawValues[20]);
|
||||
|
||||
// convert cal values to floating point, adjusted values
|
||||
bmp_cal_data_fp[PAR_T1] = (float)calData->NVM_PAR_T1 / pow(2, -8);
|
||||
bmp_cal_data_fp[PAR_T2] = (float)calData->NVM_PAR_T2 / pow(2, 30);
|
||||
bmp_cal_data_fp[PAR_T3] = (float)calData->NVM_PAR_T3 / pow(2, 48);
|
||||
bmp_cal_data_fp[PAR_T1] = (float)calData->NVM_PAR_T1 * 256.0f;
|
||||
bmp_cal_data_fp[PAR_T2] = (float)calData->NVM_PAR_T2 / 1073741824.0f;
|
||||
bmp_cal_data_fp[PAR_T3] = (float)calData->NVM_PAR_T3 / 281474976710656.0f;
|
||||
bmp_cal_data_fp[PAR_P1] =
|
||||
((float)calData->NVM_PAR_P1 - pow(2, 14)) / pow(2, 20);
|
||||
((float)calData->NVM_PAR_P1 - 16384.0f) / 1048576.0f;
|
||||
bmp_cal_data_fp[PAR_P2] =
|
||||
((float)calData->NVM_PAR_P2 - pow(2, 14)) / pow(2, 29);
|
||||
bmp_cal_data_fp[PAR_P3] = (float)calData->NVM_PAR_P3 / pow(2, 32);
|
||||
bmp_cal_data_fp[PAR_P4] = (float)calData->NVM_PAR_P4 / pow(2, 37);
|
||||
bmp_cal_data_fp[PAR_P5] = (float)calData->NVM_PAR_P5 / pow(2, -3);
|
||||
bmp_cal_data_fp[PAR_P6] = (float)calData->NVM_PAR_P6 / pow(2, 6);
|
||||
bmp_cal_data_fp[PAR_P7] = (float)calData->NVM_PAR_P7 / pow(2, 8);
|
||||
bmp_cal_data_fp[PAR_P8] = (float)calData->NVM_PAR_P8 / pow(2, 15);
|
||||
bmp_cal_data_fp[PAR_P9] = (float)calData->NVM_PAR_P9 / pow(2, 48);
|
||||
bmp_cal_data_fp[PAR_P10] = (float)calData->NVM_PAR_P10 / pow(2, 48);
|
||||
bmp_cal_data_fp[PAR_P11] = (float)calData->NVM_PAR_P11 / pow(2, 65);
|
||||
((float)calData->NVM_PAR_P2 - 16384.0f) / 536870912.0f;
|
||||
bmp_cal_data_fp[PAR_P3] = (float)calData->NVM_PAR_P3 / 4294967296.0f;
|
||||
bmp_cal_data_fp[PAR_P4] = (float)calData->NVM_PAR_P4 / 137438953472.0f;
|
||||
bmp_cal_data_fp[PAR_P5] = (float)calData->NVM_PAR_P5 * 8.0f;
|
||||
bmp_cal_data_fp[PAR_P6] = (float)calData->NVM_PAR_P6 / 64.0f;
|
||||
bmp_cal_data_fp[PAR_P7] = (float)calData->NVM_PAR_P7 / 256.0f;
|
||||
bmp_cal_data_fp[PAR_P8] = (float)calData->NVM_PAR_P8 / 32768.0f;
|
||||
bmp_cal_data_fp[PAR_P9] = (float)calData->NVM_PAR_P9 / 281474976710656.0f;
|
||||
bmp_cal_data_fp[PAR_P10] = (float)calData->NVM_PAR_P10 / 281474976710656.0f;
|
||||
bmp_cal_data_fp[PAR_P11] =
|
||||
(float)calData->NVM_PAR_P11 / 36893488147419103232.0f;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int initBMP(i2c_inst_t *i2c) {
|
||||
bmp_cal_data_t bmpRawCalValues, *bmpRawCalValues_t = &bmpRawCalValues;
|
||||
static const uint8_t BMP_RESET[2] = {0x7E, 0xB6};
|
||||
static const uint8_t BMP_SETUP[6] = {0x1C, 0x0B, 0x1D, 0x08, 0x1F, 0x0A};
|
||||
static const uint8_t BMP_START[2] = {0x1B, 0x33};
|
||||
|
||||
bmp_cal_data_t bmpRawCalValues;
|
||||
i2c_write_blocking(i2c, BMP_ADDR, BMP_RESET, 2, false); // send reset
|
||||
sleep_ms(2); // wait for reset to complete
|
||||
getBMPCalData(i2c, bmpRawCalValues_t);
|
||||
getBMPCalData(i2c, &bmpRawCalValues);
|
||||
i2c_write_blocking(i2c, BMP_ADDR, BMP_SETUP, 6,
|
||||
false); // set up sampling parameters
|
||||
i2c_write_blocking(i2c, BMP_ADDR, BMP_START, 2,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue