Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
Diff: Components/HTS221Sensor/HTS221_Driver.c
- Revision:
- 6:671fd10a51b7
- Parent:
- 0:cad5dab2b21d
--- a/Components/HTS221Sensor/HTS221_Driver.c Thu Dec 15 14:03:46 2016 +0000 +++ b/Components/HTS221Sensor/HTS221_Driver.c Tue Mar 14 13:41:32 2017 +0100 @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file HTS221_Driver.c + * @file HTS221_driver.c * @author HESA Application Team * @version V1.1 * @date 10-August-2016 @@ -36,7 +36,7 @@ */ /* Includes ------------------------------------------------------------------*/ -#include "HTS221_Driver.h" +#include "HTS221_driver.h" #ifdef __cplusplus extern "C" { @@ -60,8 +60,8 @@ * @{ */ -extern uint8_t HTS221_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); -extern uint8_t HTS221_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); +extern uint8_t HTS221_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); +extern uint8_t HTS221_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); /** * @} @@ -88,38 +88,38 @@ */ /******************************************************************************* -* Function Name : HTS221_ReadReg +* Function Name : HTS221_read_reg * Description : Generic Reading function. It must be fullfilled with either * : I2C or SPI reading functions * Input : Register Address * Output : Data Read * Return : None *******************************************************************************/ -HTS221_Error_et HTS221_ReadReg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ) +HTS221_Error_et HTS221_read_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ) { if ( NumByteToRead > 1 ) RegAddr |= 0x80; - if ( HTS221_IO_Read( handle, RegAddr, Data, NumByteToRead ) ) + if ( HTS221_io_read( handle, RegAddr, Data, NumByteToRead ) ) return HTS221_ERROR; else return HTS221_OK; } /******************************************************************************* -* Function Name : HTS221_WriteReg +* Function Name : HTS221_write_reg * Description : Generic Writing function. It must be fullfilled with either * : I2C or SPI writing function * Input : Register Address, Data to be written * Output : None * Return : None *******************************************************************************/ -HTS221_Error_et HTS221_WriteReg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ) +HTS221_Error_et HTS221_write_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ) { if ( NumByteToWrite > 1 ) RegAddr |= 0x80; - if ( HTS221_IO_Write( handle, RegAddr, Data, NumByteToWrite ) ) + if ( HTS221_io_write( handle, RegAddr, Data, NumByteToWrite ) ) return HTS221_ERROR; else return HTS221_OK; @@ -148,7 +148,7 @@ */ HTS221_Error_et HTS221_Get_DeviceID(void *handle, uint8_t* deviceid) { - if(HTS221_ReadReg(handle, HTS221_WHO_AM_I_REG, 1, deviceid)) + if(HTS221_read_reg(handle, HTS221_WHO_AM_I_REG, 1, deviceid)) return HTS221_ERROR; return HTS221_OK; @@ -175,17 +175,17 @@ HTS221_assert_param(IS_HTS221_OutputType(pxInit->irq_output_type)); HTS221_assert_param(IS_HTS221_State(pxInit->irq_enable)); - if(HTS221_ReadReg(handle, HTS221_AV_CONF_REG, 1, buffer)) + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) return HTS221_ERROR; buffer[0] &= ~(HTS221_AVGH_MASK | HTS221_AVGT_MASK); buffer[0] |= (uint8_t)pxInit->avg_h; buffer[0] |= (uint8_t)pxInit->avg_t; - if(HTS221_WriteReg(handle, HTS221_AV_CONF_REG, 1, buffer)) + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) return HTS221_ERROR; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 3, buffer)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 3, buffer)) return HTS221_ERROR; buffer[0] &= ~(HTS221_BDU_MASK | HTS221_ODR_MASK); @@ -200,7 +200,7 @@ buffer[2] |= (uint8_t)pxInit->irq_output_type; buffer[2] |= ((uint8_t)pxInit->irq_enable) << HTS221_DRDY_BIT; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG1, 3, buffer)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 3, buffer)) return HTS221_ERROR; return HTS221_OK; @@ -217,13 +217,13 @@ { uint8_t buffer[3]; - if(HTS221_ReadReg(handle, HTS221_AV_CONF_REG, 1, buffer)) + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) return HTS221_ERROR; pxInit->avg_h = (HTS221_Avgh_et)(buffer[0] & HTS221_AVGH_MASK); pxInit->avg_t = (HTS221_Avgt_et)(buffer[0] & HTS221_AVGT_MASK); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 3, buffer)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 3, buffer)) return HTS221_ERROR; pxInit->odr = (HTS221_Odr_et)(buffer[0] & HTS221_ODR_MASK); @@ -247,7 +247,7 @@ { uint8_t buffer[4]; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 2, buffer)) return HTS221_ERROR; /* HTS221 in power down */ @@ -256,11 +256,11 @@ /* Make HTS221 boot */ buffer[1] |= 0x01 << HTS221_BOOT_BIT; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG1, 2, buffer)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 2, buffer)) return HTS221_ERROR; /* Dump of data output */ - if(HTS221_ReadReg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) return HTS221_ERROR; return HTS221_OK; @@ -292,7 +292,7 @@ { uint8_t buffer[4]; - if(HTS221_ReadReg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) return HTS221_ERROR; *humidity = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]); @@ -314,20 +314,20 @@ uint8_t buffer[2]; float tmp_f; - if(HTS221_ReadReg(handle, HTS221_H0_RH_X2, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_H0_RH_X2, 2, buffer)) return HTS221_ERROR; H0_rh = buffer[0] >> 1; H1_rh = buffer[1] >> 1; - if(HTS221_ReadReg(handle, HTS221_H0_T0_OUT_L, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_H0_T0_OUT_L, 2, buffer)) return HTS221_ERROR; H0_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; - if(HTS221_ReadReg(handle, HTS221_H1_T0_OUT_L, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_H1_T0_OUT_L, 2, buffer)) return HTS221_ERROR; H1_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; - if(HTS221_ReadReg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) return HTS221_ERROR; H_T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; @@ -351,7 +351,7 @@ { uint8_t buffer[2]; - if(HTS221_ReadReg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) return HTS221_ERROR; *value = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]); @@ -372,9 +372,9 @@ uint8_t buffer[4], tmp; float tmp_f; - if(HTS221_ReadReg(handle, HTS221_T0_DEGC_X8, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_T0_DEGC_X8, 2, buffer)) return HTS221_ERROR; - if(HTS221_ReadReg(handle, HTS221_T0_T1_DEGC_H2, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_T0_T1_DEGC_H2, 1, &tmp)) return HTS221_ERROR; T0_degC_x8_u16 = (((uint16_t)(tmp & 0x03)) << 8) | ((uint16_t)buffer[0]); @@ -382,13 +382,13 @@ T0_degC = T0_degC_x8_u16 >> 3; T1_degC = T1_degC_x8_u16 >> 3; - if(HTS221_ReadReg(handle, HTS221_T0_OUT_L, 4, buffer)) + if(HTS221_read_reg(handle, HTS221_T0_OUT_L, 4, buffer)) return HTS221_ERROR; T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; T1_out = (((uint16_t)buffer[3]) << 8) | (uint16_t)buffer[2]; - if(HTS221_ReadReg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) return HTS221_ERROR; T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]; @@ -411,7 +411,7 @@ { uint8_t buffer[2]; - if(HTS221_ReadReg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) + if(HTS221_read_reg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) return HTS221_ERROR; *value = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]); @@ -431,7 +431,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_STATUS_REG, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_STATUS_REG, 1, &tmp)) return HTS221_ERROR; *humidity = (HTS221_BitStatus_et)((tmp & HTS221_HDA_MASK) >> HTS221_H_DA_BIT); @@ -450,12 +450,12 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; tmp |= HTS221_PD_MASK; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -470,12 +470,12 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_PD_MASK; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -493,7 +493,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_STATUS_REG, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_STATUS_REG, 1, &tmp)) return HTS221_ERROR; if((tmp & (uint8_t)(HTS221_HDA_MASK | HTS221_TDA_MASK)) == (uint8_t)(HTS221_HDA_MASK | HTS221_TDA_MASK)) @@ -519,14 +519,14 @@ HTS221_assert_param(IS_HTS221_AVGH(avgh)); HTS221_assert_param(IS_HTS221_AVGT(avgt)); - if(HTS221_ReadReg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) return HTS221_ERROR; tmp &= ~(HTS221_AVGH_MASK | HTS221_AVGT_MASK); tmp |= (uint8_t)avgh; tmp |= (uint8_t)avgt; - if(HTS221_WriteReg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -544,13 +544,13 @@ HTS221_assert_param(IS_HTS221_AVGH(avgh)); - if(HTS221_ReadReg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_AVGH_MASK; tmp |= (uint8_t)avgh; - if(HTS221_WriteReg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -568,13 +568,13 @@ HTS221_assert_param(IS_HTS221_AVGT(avgt)); - if(HTS221_ReadReg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_AVGT_MASK; tmp |= (uint8_t)avgt; - if(HTS221_WriteReg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -591,7 +591,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_AV_CONF_REG, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) return HTS221_ERROR; *avgh = (HTS221_Avgh_et)(tmp & HTS221_AVGH_MASK); @@ -614,13 +614,13 @@ HTS221_assert_param(IS_HTS221_State(status)); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_BDU_MASK; tmp |= ((uint8_t)status) << HTS221_BDU_BIT; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -636,7 +636,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; *status = (HTS221_State_et)((tmp & HTS221_BDU_MASK) >> HTS221_BDU_BIT); @@ -658,13 +658,13 @@ HTS221_assert_param(IS_HTS221_BitStatus(status)); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_PD_MASK; tmp |= ((uint8_t)status) << HTS221_PD_BIT; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -680,7 +680,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; *status = (HTS221_BitStatus_et)((tmp & HTS221_PD_MASK) >> HTS221_PD_BIT); @@ -701,13 +701,13 @@ HTS221_assert_param(IS_HTS221_ODR(odr)); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_ODR_MASK; tmp |= (uint8_t)odr; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -723,7 +723,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG1, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) return HTS221_ERROR; tmp &= HTS221_ODR_MASK; @@ -741,12 +741,12 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG2, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) return HTS221_ERROR; tmp |= HTS221_BOOT_MASK; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG2, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -765,13 +765,13 @@ HTS221_assert_param(IS_HTS221_State(status)); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG2, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_HEATHER_MASK; tmp |= ((uint8_t)status) << HTS221_HEATHER_BIT; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG2, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -787,7 +787,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG2, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) return HTS221_ERROR; *status = (HTS221_State_et)((tmp & HTS221_HEATHER_MASK) >> HTS221_HEATHER_BIT); @@ -805,12 +805,12 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG2, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) return HTS221_ERROR; tmp |= HTS221_ONE_SHOT_MASK; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG2, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -831,13 +831,13 @@ HTS221_assert_param(IS_HTS221_DrdyLevelType(value)); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_DRDY_H_L_MASK; tmp |= (uint8_t)value; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -853,7 +853,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; *value = (HTS221_DrdyLevel_et)(tmp & HTS221_DRDY_H_L_MASK); @@ -874,13 +874,13 @@ HTS221_assert_param(IS_HTS221_OutputType(value)); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_PP_OD_MASK; tmp |= (uint8_t)value; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -896,7 +896,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; *value = (HTS221_OutputType_et)(tmp & HTS221_PP_OD_MASK); @@ -917,13 +917,13 @@ HTS221_assert_param(IS_HTS221_State(status)); - if(HTS221_ReadReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; tmp &= ~HTS221_DRDY_MASK; tmp |= ((uint8_t)status) << HTS221_DRDY_BIT; - if(HTS221_WriteReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; return HTS221_OK; @@ -939,7 +939,7 @@ { uint8_t tmp; - if(HTS221_ReadReg(handle, HTS221_CTRL_REG3, 1, &tmp)) + if(HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) return HTS221_ERROR; *status = (HTS221_State_et)((tmp & HTS221_DRDY_MASK) >> HTS221_DRDY_BIT);