123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- #ifndef HTS221_INTERNAL_H
- #define HTS221_INTERNAL_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define HTS221_REG_WHO_AM_I 0x0F
- #define HTS221_REG_AV_CONF 0x10
- #define HTS221_REG_CTRL_REG1 0x20
- #define HTS221_REG_CTRL_REG2 0x21
- #define HTS221_REG_CTRL_REG3 0x22
- #define HTS221_REG_STATUS_REG 0x27
- #define HTS221_REG_HUM_OUT_L 0x28
- #define HTS221_REG_HUM_OUT_H 0x29
- #define HTS221_REG_TEMP_OUT_L 0x2A
- #define HTS221_REG_TEMP_OUT_H 0x2B
- #define HTS221_REG_CALIBRATION 0x30
- #define HTS221_REG_CALIBRATION_NUM 16
- #define HTS221_REG_CTRL_NUM 3
- #define HTS221_INCR_REG_MASK 0x80
- #define HTS221_DEF_AV_CONF 0x1B
- #define HTS221_AV_CONF_VALID_MASK 0xC0
- #define HTS221_AVGT_POS 3
- #define HTS221_AVGT_MASK (7 << HTS221_AVGT_POS)
- #define HTS221_AVGH_POS 0
- #define HTS221_AVGH_MASK (7 << HTS221_AVGH_POS)
- #define HTS221_CTRL1_VALID_MASK 0x78
- #define HTS221_PD_POS 7
- #define HTS221_PD_MASK (1 << HTS221_PD_POS)
- #define HTS221_BDU_POS 2
- #define HTS221_BDU_MASK (1 << HTS221_BDU_POS)
- #define HTS221_ODR_POS 0
- #define HTS221_ODR_MASK (3 << HTS221_ODR_POS)
- #define HTS221_CTRL2_VALID_MASK 0x7C
- #define HTS221_BOOT_POS 7
- #define HTS221_BOOT_MASK (1 << HTS221_BOOT_POS)
- #define HTS221_HEATER_POS 1
- #define HTS221_HEATER_MASK (1 << HTS221_HEATER_POS)
- #define HTS221_ONE_SHOT_POS 0
- #define HTS221_ONE_SHOT_MASK (1 << HTS221_ONE_SHOT_POS)
- #define HTS221_CTRL3_VALID_MASK 0x3B
- #define HTS221_DRDY_H_L_POS 7
- #define HTS221_DRDY_H_L_MASK (1 << HTS221_DRDY_H_L_POS)
- #define HTS221_PP_OD_POS 6
- #define HTS221_PP_OD_MASK (1 << HTS221_PP_OD_POS)
- #define HTS221_DRDY_EN_POS 2
- #define HTS221_DRDY_EN_MASK (1 << HTS221_DRDY_EN_POS)
- #define HTS221_H_DA_POS 1
- #define HTS221_H_DA_MASK (1 << HTS221_H_DA_POS)
- #define HTS221_T_DA_POS 0
- #define HTS221_T_DA_MASK (1 << HTS221_T_DA_POS)
- typedef struct
- {
- uint8_t H0_rH_x2;
- uint8_t H1_rH_x2;
- uint16_t T0_degC_x8;
- uint16_t T1_degC_x8;
- int16_t H0_T0_OUT;
- int16_t H1_T0_OUT;
- int16_t T0_OUT;
- int16_t T1_OUT;
- uint16_t padding;
- } hts221_calib_t;
- typedef struct
- {
- nrf_twi_sensor_t * const p_sensor_data;
- uint8_t const sensor_addr;
- hts221_calib_t calib_info;
- uint8_t ctrl_reg1;
- uint8_t ctrl_reg2;
- } hts221_instance_t;
- #define HTS221_INTERNAL_INSTANCE_DEF(_hts221_inst_name, _p_twi_sensor, _sensor_address) \
- static hts221_instance_t _hts221_inst_name = \
- { \
- .p_sensor_data = _p_twi_sensor, \
- .sensor_addr = _sensor_address, \
- }
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE ret_code_t hts221_who_am_i_read(hts221_instance_t * p_instance,
- nrf_twi_sensor_reg_cb_t user_cb,
- uint8_t * reg_val)
- {
- ASSERT(p_instance != NULL);
- return nrf_twi_sensor_reg_read(p_instance->p_sensor_data,
- p_instance->sensor_addr,
- HTS221_REG_WHO_AM_I,
- user_cb,
- reg_val,
- 1);
- }
- __STATIC_INLINE ret_code_t hts221_status_read(hts221_instance_t * p_instance,
- nrf_twi_sensor_reg_cb_t user_cb,
- uint8_t * reg_val)
- {
- ASSERT(p_instance != NULL);
- return nrf_twi_sensor_reg_read(p_instance->p_sensor_data,
- p_instance->sensor_addr,
- HTS221_REG_STATUS_REG,
- user_cb,
- reg_val,
- 1);
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|