Merge pull request #317 from UncleRus/fix_ms5611
Code style fixes for MS5611
This commit is contained in:
commit
0b063730f3
2 changed files with 42 additions and 38 deletions
|
@ -23,9 +23,10 @@ void user_init(void)
|
|||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n\n", sdk_system_get_sdk_version());
|
||||
|
||||
ms561101ba03_config_data_t conf = {0,0,0,0,0,0};
|
||||
ms561101ba03_result_t result = {0,0};
|
||||
ms561101ba03_t device= {MS561101BA03_ADDR_CSB_LOW, MS561101BA03_OSR_4096, conf, result, 0};
|
||||
ms561101ba03_t device = {
|
||||
.addr = MS561101BA03_ADDR_CSB_LOW,
|
||||
.osr = MS561101BA03_OSR_4096,
|
||||
};
|
||||
|
||||
while (!ms561101ba03_init(&device))
|
||||
printf("Device not found\n");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Driver for barometic pressure sensor ms511-01BA03
|
||||
* Driver for barometic pressure sensor MS5611-01BA03
|
||||
*
|
||||
* Copyright (C) 2016 Bernhard Guillon <Bernhard.Guillon@web.de>
|
||||
*
|
||||
|
@ -16,6 +16,7 @@
|
|||
#define CONVERT_D1 0x40
|
||||
#define CONVERT_D2 0x50
|
||||
#define ADC_READ 0x00
|
||||
#define RESET 0x1E
|
||||
|
||||
/*
|
||||
* FIXME:
|
||||
|
@ -25,8 +26,6 @@
|
|||
*/
|
||||
#define CONVERSION_TIME 20 / portTICK_PERIOD_MS // milliseconds
|
||||
|
||||
static const uint8_t RESET = 0x1E;
|
||||
|
||||
static inline bool reset(uint8_t addr)
|
||||
{
|
||||
uint8_t buf[1] = { RESET };
|
||||
|
@ -103,28 +102,32 @@ static inline int32_t calc_temp(ms561101ba03_t *dev)
|
|||
{
|
||||
// Actual temerature (-40...85C with 0.01 resulution)
|
||||
// TEMP = 20C +dT * TEMPSENSE =2000 + dT * C6 / 2^23
|
||||
return (int32_t)((int64_t)2000 +(int64_t)dev->dT * (int64_t)dev->config_data.tempsens / (int64_t)8388608);
|
||||
return (int32_t)(2000 + (int64_t)dev->dT * dev->config_data.tempsens / 8388608);
|
||||
}
|
||||
|
||||
static inline int64_t calc_off(ms561101ba03_t *dev)
|
||||
{
|
||||
// Offset at actual temperature
|
||||
// OFF=OFF_t1 + TCO * dT = OFF_t1(C2) * 2^16 + (C4*dT)/2^7
|
||||
return (int64_t)((int64_t)dev->config_data.off * (int64_t)65536) + (((int64_t)dev->config_data.tco * (int64_t)dev->dT ) /(int64_t)128);
|
||||
return (int64_t)((int64_t)dev->config_data.off * (int64_t)65536)
|
||||
+ (((int64_t)dev->config_data.tco * (int64_t)dev->dT) / (int64_t)128);
|
||||
}
|
||||
|
||||
static inline int64_t calc_sens(ms561101ba03_t *dev)
|
||||
{
|
||||
// Senisitivity at actual temperature
|
||||
// SENS=SENS_t1 + TCS *dT = SENS_t1(C1) *2^15 + (TCS(C3) *dT)/2^8
|
||||
return (int64_t)(((int64_t)dev->config_data.sens) *(int64_t)32768) + (((int64_t)dev->config_data.tcs * (int64_t)dev->dT ) /(int64_t)256);
|
||||
return (int64_t)(((int64_t)dev->config_data.sens) * (int64_t)32768)
|
||||
+ (((int64_t)dev->config_data.tcs * (int64_t)dev->dT) / (int64_t)256);
|
||||
}
|
||||
|
||||
static inline int32_t calc_p(uint32_t digital_pressure, int64_t sens, int64_t off)
|
||||
{
|
||||
// Temperature compensated pressure (10...1200mbar with 0.01mbar resolution
|
||||
// P = digital pressure value * SENS - OFF = (D1 * SENS/2^21 -OFF)/2^15
|
||||
return (int32_t) (((int64_t)digital_pressure * (int64_t)((int64_t)sens / (int64_t)0x200000) - (int64_t)off) / (int64_t)32768);
|
||||
return (int32_t)(((int64_t)digital_pressure
|
||||
* (int64_t)((int64_t)sens / (int64_t)0x200000) - (int64_t)off)
|
||||
/ (int64_t)32768);
|
||||
}
|
||||
|
||||
static inline bool get_raw_temperature(ms561101ba03_t *dev, uint32_t *result)
|
||||
|
|
Loading…
Reference in a new issue