37#define HTS221_SEL(mask, offset) (int16_t)(mask << offset)
39#define HTS221_FLAG_HYGRO_BIAS 0x01
40#define HTS221_FLAG_HYGRO_SENS 0x02
41#define HTS221_FLAG_THERMO_BIAS 0x04
42#define HTS221_FLAG_THERMO_SENS 0x08
56#if (HTS221_USE_I2C) || defined(__DOXYGEN__)
114 uint8_t calib[16], H0_rH_x2, H1_rH_x2, msb;
115 int16_t H0_T0_OUT, H1_T0_OUT, T0_degC_x8, T1_degC_x8, T0_OUT, T1_OUT;
123 H0_T0_OUT = calib[6];
124 H0_T0_OUT += calib[7] << 8;
125 H1_T0_OUT = calib[10];
126 H1_T0_OUT += calib[11] << 8;
128 T0_degC_x8 = calib[2];
135 T0_degC_x8 += msb << 8;
137 T1_degC_x8 = calib[3];
139 msb = ((calib[5] &
HTS221_SEL(0x03, 2)) >> 2);
143 T1_degC_x8 += msb << 8;
146 T0_OUT += calib[13] << 8;
148 T1_OUT += calib[15] << 8;
150 devp->hygrofactorysensitivity = ((float)H1_rH_x2 - (float)H0_rH_x2) /
151 (((
float)H1_T0_OUT - (
float)H0_T0_OUT) * 2.0f);
154 devp->hygrofactorybias = (devp->hygrofactorysensitivity * (float)H0_T0_OUT) -
155 ((
float)H0_rH_x2 / 2.0f);
157 devp->thermofactorysensitivity = ((float)T1_degC_x8 - (float)T0_degC_x8) /
158 (((
float)T1_OUT - (
float)T0_OUT) * 8.0f);
160 devp->thermofactorybias = (devp->thermofactorysensitivity * (float)T0_OUT) -
161 ((
float)T0_degC_x8 / 8.0f);
207 "hygro_read_raw(), invalid state");
210 "hygro_read_raw(), channel not ready");
215 devp->config->i2ccfg);
226 tmp = buff[0] + (buff[1] << 8);
227 *axes = (int32_t)tmp;
260 "hygro_read_cooked(), invalid state");
264 *axes = (raw * devp->hygrosensitivity) - devp->hygrobias;
294 "hygro_set_bias(), invalid state");
296 devp->hygrobias = *bp;
320 "hygro_reset_bias(), invalid state");
322 devp->hygrobias = devp->hygrofactorybias;
348 "hygro_set_sensitivity(), invalid state");
350 devp->hygrosensitivity = *sp;
373 "hygro_reset_sensitivity(), invalid state");
375 devp->hygrosensitivity = devp->hygrofactorysensitivity;
420 "thermo_read_raw(), invalid state");
423 "thermo_read_raw(), channel not ready");
428 devp->config->i2ccfg);
439 tmp = buff[0] + (buff[1] << 8);
440 *axes = (int32_t)tmp;
473 "thermo_read_cooked(), invalid state");
477 *axis = (raw * devp->thermosensitivity) - devp->thermobias;
504 "thermo_set_bias(), invalid state");
506 devp->thermobias = *bp;
531 "thermo_reset_bias(), invalid state");
533 devp->thermobias = devp->thermofactorybias;
560 "thermo_set_sensitivity(), invalid state");
562 devp->thermosensitivity = *sp;
586 "thermo_reset_sensitivity(), invalid state");
588 devp->thermosensitivity = devp->thermofactorysensitivity;
633 devp->hygrobias = 0.0f;
634 devp->thermobias = 0.0f;
652 "hts221Start(), invalid state");
654 devp->config = config;
661 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
670 if(devp->config->hygrosensitivity == NULL) {
671 devp->hygrosensitivity = devp->hygrofactorysensitivity;
675 devp->hygrosensitivity = *(devp->config->hygrosensitivity);
678 if(devp->config->hygrobias == NULL) {
679 devp->hygrobias = devp->hygrofactorybias;
683 devp->hygrobias = *(devp->config->hygrobias);
686 if(devp->config->thermosensitivity == NULL) {
687 devp->thermosensitivity = devp->thermofactorysensitivity;
691 devp->thermosensitivity = *(devp->config->thermosensitivity);
694 if(devp->config->thermobias == NULL) {
695 devp->thermobias = devp->thermofactorybias;
699 devp->thermobias = *(devp->config->thermobias);
706#if HTS221_USE_ADVANCED || defined(__DOXYGEN__)
707 cr[1] |= devp->config->blockdataupdate;
712 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
726#if HTS221_USE_ADVANCED || defined(__DOXYGEN__)
727 cr[1] = devp->config->hygroresolution | devp->config->thermoresolution;
732 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
761 "hts221Stop(), invalid state");
767 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
static const struct ADXL317VMT vmt_device
static msg_t thermo_set_bias(void *ip, float *bp)
Set the thermometer bias.
static msg_t thermo_read_raw(void *ip, int32_t axes[])
Read thermometer raw data.
static size_t thermo_get_axes_number(void *ip)
Get the thermometer number of axes.
static msg_t thermo_read_cooked(void *ip, float axes[])
Read thermometer cooked data.
static msg_t thermo_reset_bias(void *ip)
Reset the thermometer bias.
#define objGetInstance(type, ip)
Returns the instance pointer starting from an interface pointer.
static msg_t thermo_reset_sensitivity(void *ip)
Reset sensitivity values for the BaseThermometer.
#define HTS221_AD_CTRL_REG1
static msg_t hygro_set_bias(void *ip, float *bp)
Set bias values for the BaseHygrometer.
static msg_t thermo_set_sensitivity(void *ip, float *sp)
Set sensitivity values for the BaseThermometer.
void hts221Stop(HTS221Driver *devp)
Deactivates the HTS221 Complex Driver peripheral.
static msg_t hygro_reset_bias(void *ip)
Reset bias values for the BaseHygrometer.
#define HTS221_CTRL_REG1_PD
static msg_t thermo_set_bias(void *ip, float *bp)
Set bias values for the BaseThermometer.
static msg_t hygro_reset_sensitivity(void *ip)
Reset sensitivity values for the BaseHygrometer.
void hts221ObjectInit(HTS221Driver *devp)
Initializes an instance.
static msg_t thermo_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseThermometer.
static const struct BaseHygrometerVMT vmt_hygrometer
static msg_t hygro_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseHygrometer.
#define HTS221_AD_CALIB_0
static msg_t hts221I2CReadRegister(I2CDriver *i2cp, uint8_t reg, uint8_t *rxbuf, size_t n)
Reads registers value using I2C.
#define HTS221_THERMO_NUMBER_OF_AXES
HTS221 thermometer subsystem characteristics.
static msg_t hts221Calibrate(HTS221Driver *devp)
Computes biases and sensitivities starting from data stored in calibration registers.
static size_t hygro_get_axes_number(void *ip)
Return the number of axes of the BaseHygrometer.
#define HTS221_HYGRO_NUMBER_OF_AXES
HTS221 hygrometer subsystem characteristics.
#define HTS221_SEL(mask, offset)
#define HTS221_AD_HUMIDITY_OUT_L
static const struct BaseThermometerVMT vmt_thermometer
static size_t thermo_get_axes_number(void *ip)
Return the number of axes of the BaseThermometer.
void hts221Start(HTS221Driver *devp, const HTS221Config *config)
Configures and activates HTS221 Complex Driver peripheral.
#define HTS221_AD_TEMP_OUT_L
static msg_t thermo_read_cooked(void *ip, float *axis)
Retrieves cooked data from the BaseThermometer.
#define HTS221_AD_AV_CONF
static msg_t hts221I2CWriteRegister(I2CDriver *i2cp, uint8_t *txbuf, size_t n)
Writes a value into a register using I2C.
static msg_t hygro_set_sensitivity(void *ip, float *sp)
Set sensitivity values for the BaseHygrometer.
static msg_t thermo_reset_bias(void *ip)
Reset bias values for the BaseThermometer.
static msg_t hygro_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseHygrometer.
msg_t i2cStart(I2CDriver *i2cp, const I2CConfig *config)
Configures and activates the I2C peripheral.
msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, i2caddr_t addr, const uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, sysinterval_t timeout)
Sends data via the I2C bus.
void i2cReleaseBus(I2CDriver *i2cp)
Releases exclusive access to the I2C bus.
void i2cStop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
void i2cAcquireBus(I2CDriver *i2cp)
Gains exclusive access to the I2C bus.
struct hal_i2c_driver I2CDriver
Type of a structure representing an I2C driver.
#define osalDbgAssert(c, remark)
Condition assertion.
#define osalDbgCheck(c)
Function parameters check.
#define osalThreadSleepMilliseconds(msecs)
Delays the invoking thread for the specified number of milliseconds.
#define MSG_OK
Normal wakeup message.
#define TIME_INFINITE
Infinite interval specification for all functions with a timeout specification.
HTS221 MEMS interface module header.
const struct BaseHygrometerVMT * vmt
Virtual Methods Table.
BaseHygrometer virtual methods table.
const struct BaseThermometerVMT * vmt
Virtual Methods Table.
BaseThermometer virtual methods table.
HTS221 configuration structure.
HTS221 2-axis hygrometer/thermometer class.
BaseThermometer thermo_if
Base thermometer interface.
BaseHygrometer hygro_if
Base hygrometer interface.
const struct HTS221VMT * vmt
Virtual Methods Table.
HTS221 virtual methods table.