Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C89avr #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions bme280.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,12 @@ int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len,
{
int8_t rslt;
uint8_t temp_buff[20]; /* Typically not to write more than 10 registers */
uint16_t temp_len;
uint8_t reg_addr_cnt;

if (len > 10)
len = 10;

uint16_t temp_len;
uint8_t reg_addr_cnt;

/* Check for null pointer in the device structure*/
rslt = null_ptr_check(dev);
/* Check for arguments validity */
Expand Down Expand Up @@ -1035,7 +1034,7 @@ static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data
/* To avoid divide by zero exception */
if (var1 != 0) {
var4 = 1048576 - uncomp_data->pressure;
var4 = (((var4 * 2147483648) - var2) * 3125) / var1;
var4 = (((var4 * 2147483648LL) - var2) * 3125) / var1;
var1 = (((int64_t)calib_data->dig_P9) * (var4 / 8192) * (var4 / 8192)) / 33554432;
var2 = (((int64_t)calib_data->dig_P8) * var4) / 524288;
var4 = ((var4 + var1 + var2) / 256) + (((int64_t)calib_data->dig_P7) * 16);
Expand Down Expand Up @@ -1120,13 +1119,13 @@ static uint32_t compensate_humidity(const struct bme280_uncomp_data *uncomp_data
var2 = (int32_t)(uncomp_data->humidity * 16384);
var3 = (int32_t)(((int32_t)calib_data->dig_H4) * 1048576);
var4 = ((int32_t)calib_data->dig_H5) * var1;
var5 = (((var2 - var3) - var4) + (int32_t)16384) / 32768;
var5 = (((var2 - var3) - var4) + (int32_t)16384) / 32768L;
var2 = (var1 * ((int32_t)calib_data->dig_H6)) / 1024;
var3 = (var1 * ((int32_t)calib_data->dig_H3)) / 2048;
var4 = ((var2 * (var3 + (int32_t)32768)) / 1024) + (int32_t)2097152;
var4 = ((var2 * (var3 + (int32_t)32768L)) / 1024L) + (int32_t)2097152;
var2 = ((var4 * ((int32_t)calib_data->dig_H2)) + 8192) / 16384;
var3 = var5 * var2;
var4 = ((var3 / 32768) * (var3 / 32768)) / 128;
var4 = ((var3 / 32768L) * (var3 / 32768L)) / 128;
var5 = var3 - ((var4 * ((int32_t)calib_data->dig_H1)) / 16);
var5 = (var5 < 0 ? 0 : var5);
var5 = (var5 > 419430400 ? 419430400 : var5);
Expand Down