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__) 73 txbuf |= HTS221_SUB_MS;
94 (*txbuf) |= HTS221_SUB_MS;
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;
119 HTS221_AD_CALIB_0, calib, 16);
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];
131 msb = (calib[5] & HTS221_SEL(0x03, 0));
132 if (msb & HTS221_SEL(0x01, 1)) {
133 msb |= HTS221_SEL(0x3F, 2);
135 T0_degC_x8 += msb << 8;
137 T1_degC_x8 = calib[3];
139 msb = ((calib[5] & HTS221_SEL(0x03, 2)) >> 2);
140 if (msb & HTS221_SEL(0x01, 1)) {
141 msb |= HTS221_SEL(0x3F, 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");
212 #if HTS221_SHARED_I2C 215 devp->config->i2ccfg);
221 #if HTS221_SHARED_I2C 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");
425 #if HTS221_SHARED_I2C 428 devp->config->i2ccfg);
434 #if HTS221_SHARED_I2C 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;
593 static const struct HTS221VMT vmt_device = {
624 devp->
vmt = &vmt_device;
633 devp->hygrobias = 0.0f;
634 devp->thermobias = 0.0f;
652 "hts221Start(), invalid state");
654 devp->config = config;
656 #if HTS221_SHARED_I2C 661 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
665 #if HTS221_SHARED_I2C 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);
704 cr[0] = HTS221_AD_CTRL_REG1;
705 cr[1] = devp->config->outputdatarate | HTS221_CTRL_REG1_PD;
706 #if HTS221_USE_ADVANCED || defined(__DOXYGEN__) 707 cr[1] |= devp->config->blockdataupdate;
710 #if HTS221_SHARED_I2C 712 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
717 #if HTS221_SHARED_I2C 724 cr[0] = HTS221_AD_AV_CONF;
726 #if HTS221_USE_ADVANCED || defined(__DOXYGEN__) 727 cr[1] = devp->config->hygroresolution | devp->config->thermoresolution;
730 #if HTS221_SHARED_I2C 732 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
737 #if HTS221_SHARED_I2C 761 "hts221Stop(), invalid state");
765 #if HTS221_SHARED_I2C 767 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
770 cr[0] = HTS221_AD_CTRL_REG1;
775 #if HTS221_SHARED_I2C static msg_t thermo_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseThermometer.
static msg_t thermo_set_sensitivity(void *ip, float *sp)
Set sensitivity values for the BaseThermometer.
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.
static msg_t thermo_read_cooked(void *ip, float *axis)
Retrieves cooked data from the BaseThermometer.
void i2cStart(I2CDriver *i2cp, const I2CConfig *config)
Configures and activates the I2C peripheral.
static msg_t hygro_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseHygrometer.
const struct HTS221VMT * vmt
Virtual Methods Table.
void i2cAcquireBus(I2CDriver *i2cp)
Gains exclusive access to the I2C bus.
static msg_t thermo_reset_bias(void *ip)
Reset bias values for the BaseThermometer.
BaseHygrometer hygro_if
Base hygrometer interface.
void i2cReleaseBus(I2CDriver *i2cp)
Releases exclusive access to the I2C bus.
static msg_t hygro_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseHygrometer.
BaseThermometer virtual methods table.
void hts221ObjectInit(HTS221Driver *devp)
Initializes an instance.
HTS221 2-axis hygrometer/thermometer class.
static msg_t thermo_reset_sensitivity(void *ip)
Reset sensitivity values for the BaseThermometer.
static msg_t hygro_set_bias(void *ip, float *bp)
Set bias values for the BaseHygrometer.
BaseThermometer thermo_if
Base thermometer interface.
#define objGetInstance(type, ip)
Returns the instance pointer starting from an interface pointer.
#define HTS221_HYGRO_NUMBER_OF_AXES
HTS221 hygrometer subsystem characteristics.
static msg_t hts221Calibrate(HTS221Driver *devp)
Computes biases and sensitivities starting from data stored in calibration registers.
HTS221 virtual methods table.
#define osalThreadSleepMilliseconds(msecs)
Delays the invoking thread for the specified number of milliseconds.
static msg_t thermo_set_bias(void *ip, float *bp)
Set bias values for the BaseThermometer.
static msg_t hygro_set_sensitivity(void *ip, float *sp)
Set sensitivity values for the BaseHygrometer.
void i2cStop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
Structure representing an I2C driver.
static msg_t hygro_reset_bias(void *ip)
Reset bias values for the BaseHygrometer.
#define TIME_INFINITE
Infinite interval specification for all functions with a timeout specification.
#define osalDbgCheck(c)
Function parameters check.
static msg_t hygro_reset_sensitivity(void *ip)
Reset sensitivity values for the BaseHygrometer.
HTS221 MEMS interface module header.
#define MSG_OK
Normal wakeup message.
static size_t hygro_get_axes_number(void *ip)
Return the number of axes of the BaseHygrometer.
static size_t thermo_get_axes_number(void *ip)
Return the number of axes of the BaseThermometer.
void hts221Stop(HTS221Driver *devp)
Deactivates the HTS221 Complex Driver peripheral.
static msg_t hts221I2CReadRegister(I2CDriver *i2cp, uint8_t reg, uint8_t *rxbuf, size_t n)
Reads registers value using I2C.
static msg_t hts221I2CWriteRegister(I2CDriver *i2cp, uint8_t *txbuf, size_t n)
Writes a value into a register using I2C.
#define osalDbgAssert(c, remark)
Condition assertion.
void hts221Start(HTS221Driver *devp, const HTS221Config *config)
Configures and activates HTS221 Complex Driver peripheral.
#define HTS221_THERMO_NUMBER_OF_AXES
HTS221 thermometer subsystem characteristics.
const struct BaseHygrometerVMT * vmt
Virtual Methods Table.
BaseHygrometer virtual methods table.
const struct BaseThermometerVMT * vmt
Virtual Methods Table.
HTS221 configuration structure.