drivers: sensor: ccs811: cleanup of raw reading processing
Use CMSIS-standard bit mask and offset macros. Rename the field to more closely match the data sheet. Use slightly less magic numbers for the scale multipliers. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
parent
af0c69fb9f
commit
316c6e3aeb
2 changed files with 13 additions and 8 deletions
|
@ -154,7 +154,7 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
drv_data->voc = sys_be16_to_cpu(buf[1]);
|
drv_data->voc = sys_be16_to_cpu(buf[1]);
|
||||||
drv_data->status = status;
|
drv_data->status = status;
|
||||||
drv_data->error = error_from_status(status);
|
drv_data->error = error_from_status(status);
|
||||||
drv_data->resistance = sys_be16_to_cpu(buf[3]);
|
drv_data->raw = sys_be16_to_cpu(buf[3]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +180,8 @@ static int ccs811_channel_get(struct device *dev,
|
||||||
/*
|
/*
|
||||||
* Raw ADC readings are contained in least significant 10 bits
|
* Raw ADC readings are contained in least significant 10 bits
|
||||||
*/
|
*/
|
||||||
uval = (drv_data->resistance & CCS811_VOLTAGE_MASK)
|
uval = ((drv_data->raw & CCS811_RAW_VOLTAGE_MSK)
|
||||||
* CCS811_VOLTAGE_SCALE;
|
>> CCS811_RAW_VOLTAGE_POS) * CCS811_RAW_VOLTAGE_SCALE;
|
||||||
val->val1 = uval / 1000000U;
|
val->val1 = uval / 1000000U;
|
||||||
val->val2 = uval % 1000000;
|
val->val2 = uval % 1000000;
|
||||||
|
|
||||||
|
@ -191,7 +191,8 @@ static int ccs811_channel_get(struct device *dev,
|
||||||
* Current readings are contained in most
|
* Current readings are contained in most
|
||||||
* significant 6 bits in microAmps
|
* significant 6 bits in microAmps
|
||||||
*/
|
*/
|
||||||
uval = drv_data->resistance >> 10;
|
uval = ((drv_data->raw & CCS811_RAW_CURRENT_MSK)
|
||||||
|
>> CCS811_RAW_CURRENT_POS) * CCS811_RAW_CURRENT_SCALE;
|
||||||
val->val1 = uval / 1000000U;
|
val->val1 = uval / 1000000U;
|
||||||
val->val2 = uval % 1000000;
|
val->val2 = uval % 1000000;
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,13 @@
|
||||||
#define CCS811_MODE_DATARDY 0x08
|
#define CCS811_MODE_DATARDY 0x08
|
||||||
#define CCS811_MODE_THRESH 0x04
|
#define CCS811_MODE_THRESH 0x04
|
||||||
|
|
||||||
#define CCS811_VOLTAGE_SCALE 1613
|
#define CCS811_RAW_VOLTAGE_POS 0
|
||||||
|
#define CCS811_RAW_VOLTAGE_MSK (0x3FF << CCS811_RAW_VOLTAGE_POS)
|
||||||
#define CCS811_VOLTAGE_MASK 0x3FF
|
#define CCS811_RAW_VOLTAGE_SCALE (1650000U / (CCS811_RAW_VOLTAGE_MSK \
|
||||||
|
>> CCS811_RAW_VOLTAGE_POS))
|
||||||
|
#define CCS811_RAW_CURRENT_POS 10
|
||||||
|
#define CCS811_RAW_CURRENT_MSK (0x3F << CCS811_RAW_CURRENT_POS)
|
||||||
|
#define CCS811_RAW_CURRENT_SCALE 1
|
||||||
|
|
||||||
#define CCS811_CO2_MIN_PPM 400
|
#define CCS811_CO2_MIN_PPM 400
|
||||||
#define CCS811_CO2_MAX_PPM 32767
|
#define CCS811_CO2_MAX_PPM 32767
|
||||||
|
@ -82,7 +86,7 @@ struct ccs811_data {
|
||||||
#endif
|
#endif
|
||||||
u16_t co2;
|
u16_t co2;
|
||||||
u16_t voc;
|
u16_t voc;
|
||||||
u16_t resistance;
|
u16_t raw;
|
||||||
u8_t status;
|
u8_t status;
|
||||||
u8_t error;
|
u8_t error;
|
||||||
u8_t mode;
|
u8_t mode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue