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;
75 return i2cMasterTransmitTimeout(i2cp, HTS221_SAD, &txbuf, 1, rxbuf, n,
94 (*txbuf) |= HTS221_SUB_MS;
96 return i2cMasterTransmitTimeout(i2cp, HTS221_SAD, txbuf, n + 1, NULL, 0,
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);
201 osalDbgCheck((ip != NULL) && (axes != NULL));
207 "hygro_read_raw(), invalid state");
209 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
210 "hygro_read_raw(), channel not ready");
212 #if HTS221_SHARED_I2C 213 i2cAcquireBus(devp->config->i2cp);
214 i2cStart(devp->config->i2cp,
215 devp->config->i2ccfg);
221 #if HTS221_SHARED_I2C 222 i2cReleaseBus(devp->config->i2cp);
226 tmp = buff[0] + (buff[1] << 8);
227 *axes = (int32_t)tmp;
254 osalDbgCheck((ip != NULL) && (axes != NULL));
260 "hygro_read_cooked(), invalid state");
264 *axes = (raw * devp->hygrosensitivity) - devp->hygrobias;
288 osalDbgCheck((ip != NULL) && (bp != NULL));
294 "hygro_set_bias(), invalid state");
296 devp->hygrobias = *bp;
314 osalDbgCheck(ip != NULL);
320 "hygro_reset_bias(), invalid state");
322 devp->hygrobias = devp->hygrofactorybias;
342 osalDbgCheck((ip != NULL) && (sp != NULL));
348 "hygro_set_sensitivity(), invalid state");
350 devp->hygrosensitivity = *sp;
367 osalDbgCheck(ip != NULL);
373 "hygro_reset_sensitivity(), invalid state");
375 devp->hygrosensitivity = devp->hygrofactorysensitivity;
414 osalDbgCheck((ip != NULL) && (axes != NULL));
420 "thermo_read_raw(), invalid state");
422 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
423 "thermo_read_raw(), channel not ready");
425 #if HTS221_SHARED_I2C 426 i2cAcquireBus(devp->config->i2cp);
427 i2cStart(devp->config->i2cp,
428 devp->config->i2ccfg);
434 #if HTS221_SHARED_I2C 435 i2cReleaseBus(devp->config->i2cp);
439 tmp = buff[0] + (buff[1] << 8);
440 *axes = (int32_t)tmp;
467 osalDbgCheck((ip != NULL) && (axis != NULL));
473 "thermo_read_cooked(), invalid state");
477 *axis = (raw * devp->thermosensitivity) - devp->thermobias;
498 osalDbgCheck((ip != NULL) && (bp != NULL));
504 "thermo_set_bias(), invalid state");
506 devp->thermobias = *bp;
525 osalDbgCheck(ip != NULL);
531 "thermo_reset_bias(), invalid state");
533 devp->thermobias = devp->thermofactorybias;
554 osalDbgCheck((ip != NULL) && (sp != NULL));
560 "thermo_set_sensitivity(), invalid state");
562 devp->thermosensitivity = *sp;
580 osalDbgCheck(ip != NULL);
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;
649 osalDbgCheck((devp != NULL) && (config != NULL));
652 "hts221Start(), invalid state");
654 devp->config = config;
656 #if HTS221_SHARED_I2C 657 i2cAcquireBus(devp->config->i2cp);
661 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
665 #if HTS221_SHARED_I2C 666 i2cReleaseBus(devp->config->i2cp);
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 711 i2cAcquireBus(devp->config->i2cp);
712 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
717 #if HTS221_SHARED_I2C 718 i2cReleaseBus(devp->config->i2cp);
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 731 i2cAcquireBus(devp->config->i2cp);
732 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
737 #if HTS221_SHARED_I2C 738 i2cReleaseBus(devp->config->i2cp);
743 osalThreadSleepMilliseconds(5);
758 osalDbgCheck(devp != NULL);
761 "hts221Stop(), invalid state");
765 #if HTS221_SHARED_I2C 766 i2cAcquireBus(devp->config->i2cp);
767 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
770 cr[0] = HTS221_AD_CTRL_REG1;
774 i2cStop(devp->config->i2cp);
775 #if HTS221_SHARED_I2C 776 i2cReleaseBus(devp->config->i2cp);
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.
static msg_t thermo_read_cooked(void *ip, float *axis)
Retrieves cooked data from the BaseThermometer.
static msg_t hygro_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseHygrometer.
const struct HTS221VMT * vmt
Virtual Methods Table.
static msg_t thermo_reset_bias(void *ip)
Reset bias values for the BaseThermometer.
BaseHygrometer hygro_if
Base hygrometer interface.
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 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.
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.
static msg_t hygro_reset_bias(void *ip)
Reset bias values for the BaseHygrometer.
static msg_t hygro_reset_sensitivity(void *ip)
Reset sensitivity values for the BaseHygrometer.
HTS221 MEMS interface module header.
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.
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.