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;
117 #if HTS221_SHARED_I2C 119 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
124 HTS221_AD_CALIB_0, calib, 16);
126 #if HTS221_SHARED_I2C 132 H0_T0_OUT = calib[6];
133 H0_T0_OUT += calib[7] << 8;
134 H1_T0_OUT = calib[10];
135 H1_T0_OUT += calib[11] << 8;
137 T0_degC_x8 = calib[2];
140 msb = (calib[5] & HTS221_SEL(0x03, 0));
141 if (msb & HTS221_SEL(0x01, 1)) {
142 msb |= HTS221_SEL(0x3F, 2);
144 T0_degC_x8 += msb << 8;
146 T1_degC_x8 = calib[3];
148 msb = ((calib[5] & HTS221_SEL(0x03, 2)) >> 2);
149 if (msb & HTS221_SEL(0x01, 1)) {
150 msb |= HTS221_SEL(0x3F, 2);
152 T1_degC_x8 += msb << 8;
155 T0_OUT += calib[13] << 8;
157 T1_OUT += calib[15] << 8;
159 devp->hygrofactorysensitivity = ((float)H1_rH_x2 - (
float)H0_rH_x2) /
160 (((
float)H1_T0_OUT - (float)H0_T0_OUT) * 2.0f);
163 devp->hygrofactorybias = (devp->hygrofactorysensitivity * (float)H0_T0_OUT) -
164 ((float)H0_rH_x2 / 2.0f);
166 devp->thermofactorysensitivity = ((float)T1_degC_x8 - (
float)T0_degC_x8) /
167 (((
float)T1_OUT - (float)T0_OUT) * 8.0f);
169 devp->thermofactorybias = (devp->thermofactorysensitivity * (float)T0_OUT) -
170 ((float)T0_degC_x8 / 8.0f);
216 "hygro_read_raw(), invalid state");
219 "hygro_read_raw(), channel not ready");
221 #if HTS221_SHARED_I2C 224 devp->config->i2ccfg);
230 #if HTS221_SHARED_I2C 235 tmp = buff[0] + (buff[1] << 8);
236 *axes = (int32_t)tmp;
269 "hygro_read_cooked(), invalid state");
273 *axes = (raw * devp->hygrosensitivity) - devp->hygrobias;
303 "hygro_set_bias(), invalid state");
305 devp->hygrobias = *bp;
329 "hygro_reset_bias(), invalid state");
331 devp->hygrobias = devp->hygrofactorybias;
357 "hygro_set_sensitivity(), invalid state");
359 devp->hygrosensitivity = *sp;
382 "hygro_reset_sensitivity(), invalid state");
384 devp->hygrosensitivity = devp->hygrofactorysensitivity;
429 "thermo_read_raw(), invalid state");
432 "thermo_read_raw(), channel not ready");
434 #if HTS221_SHARED_I2C 437 devp->config->i2ccfg);
443 #if HTS221_SHARED_I2C 448 tmp = buff[0] + (buff[1] << 8);
449 *axes = (int32_t)tmp;
482 "thermo_read_cooked(), invalid state");
486 *axis = (raw * devp->thermosensitivity) - devp->thermobias;
513 "thermo_set_bias(), invalid state");
515 devp->thermobias = *bp;
540 "thermo_reset_bias(), invalid state");
542 devp->thermobias = devp->thermofactorybias;
569 "thermo_set_sensitivity(), invalid state");
571 devp->thermosensitivity = *sp;
595 "thermo_reset_sensitivity(), invalid state");
597 devp->thermosensitivity = devp->thermofactorysensitivity;
602 static const struct HTS221VMT vmt_device = {
633 devp->
vmt = &vmt_device;
642 devp->hygrobias = 0.0f;
643 devp->thermobias = 0.0f;
661 "hts221Start(), invalid state");
663 devp->config = config;
665 #if HTS221_SHARED_I2C 669 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
672 #if HTS221_SHARED_I2C 676 if(devp->config->hygrosensitivity == NULL) {
677 devp->hygrosensitivity = devp->hygrofactorysensitivity;
681 devp->hygrosensitivity = *(devp->config->hygrosensitivity);
684 if(devp->config->hygrobias == NULL) {
685 devp->hygrobias = devp->hygrofactorybias;
689 devp->hygrobias = *(devp->config->hygrobias);
692 if(devp->config->thermosensitivity == NULL) {
693 devp->thermosensitivity = devp->thermofactorysensitivity;
697 devp->thermosensitivity = *(devp->config->thermosensitivity);
700 if(devp->config->thermobias == NULL) {
701 devp->thermobias = devp->thermofactorybias;
705 devp->thermobias = *(devp->config->thermobias);
710 cr[0] = HTS221_AD_CTRL_REG1;
711 cr[1] = devp->config->outputdatarate | HTS221_CTRL_REG1_PD;
712 #if HTS221_USE_ADVANCED || defined(__DOXYGEN__) 713 cr[1] |= devp->config->blockdataupdate;
716 #if HTS221_SHARED_I2C 718 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
723 #if HTS221_SHARED_I2C 730 cr[0] = HTS221_AD_AV_CONF;
732 #if HTS221_USE_ADVANCED || defined(__DOXYGEN__) 733 cr[1] = devp->config->hygroresolution | devp->config->thermoresolution;
736 #if HTS221_SHARED_I2C 738 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
743 #if HTS221_SHARED_I2C 767 "hts221Stop(), invalid state");
771 #if HTS221_SHARED_I2C 773 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
776 cr[0] = HTS221_AD_CTRL_REG1;
781 #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.