removed X-NUCLEO-COMMON and ST-INTERFACES

Dependents:   unh-hackathon-example unh-hackathon-example-raw

Fork of X_NUCLEO_IKS01A1 by ST

Committer:
Wolfgang Betz
Date:
Fri Mar 24 10:57:29 2017 +0100
Revision:
92:d1c67d482bad
Parent:
88:7b8d3316d753
Align to latest `ST_INTERFACES`

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 4:566f2c41dc1d 1 /**
Wolfgang Betz 4:566f2c41dc1d 2 ******************************************************************************
Wolfgang Betz 4:566f2c41dc1d 3 * @file hts221_class.h
Wolfgang Betz 4:566f2c41dc1d 4 * @author AST / EST
Wolfgang Betz 4:566f2c41dc1d 5 * @version V0.0.1
Wolfgang Betz 4:566f2c41dc1d 6 * @date 14-April-2015
Wolfgang Betz 4:566f2c41dc1d 7 * @brief Header file for component HTS221
Wolfgang Betz 4:566f2c41dc1d 8 ******************************************************************************
Wolfgang Betz 4:566f2c41dc1d 9 * @attention
Wolfgang Betz 4:566f2c41dc1d 10 *
Wolfgang Betz 4:566f2c41dc1d 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Wolfgang Betz 4:566f2c41dc1d 12 *
Wolfgang Betz 4:566f2c41dc1d 13 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 4:566f2c41dc1d 14 * are permitted provided that the following conditions are met:
Wolfgang Betz 4:566f2c41dc1d 15 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 4:566f2c41dc1d 16 * this list of conditions and the following disclaimer.
Wolfgang Betz 4:566f2c41dc1d 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 4:566f2c41dc1d 18 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 4:566f2c41dc1d 19 * and/or other materials provided with the distribution.
Wolfgang Betz 4:566f2c41dc1d 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 4:566f2c41dc1d 21 * may be used to endorse or promote products derived from this software
Wolfgang Betz 4:566f2c41dc1d 22 * without specific prior written permission.
Wolfgang Betz 4:566f2c41dc1d 23 *
Wolfgang Betz 4:566f2c41dc1d 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 4:566f2c41dc1d 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 4:566f2c41dc1d 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 4:566f2c41dc1d 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 4:566f2c41dc1d 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 4:566f2c41dc1d 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 4:566f2c41dc1d 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 4:566f2c41dc1d 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 4:566f2c41dc1d 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 4:566f2c41dc1d 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 4:566f2c41dc1d 34 *
Wolfgang Betz 4:566f2c41dc1d 35 ******************************************************************************
Wolfgang Betz 4:566f2c41dc1d 36 */
Wolfgang Betz 4:566f2c41dc1d 37
Wolfgang Betz 4:566f2c41dc1d 38 #ifndef __HTS221_CLASS_H
Wolfgang Betz 4:566f2c41dc1d 39 #define __HTS221_CLASS_H
Wolfgang Betz 4:566f2c41dc1d 40
Wolfgang Betz 4:566f2c41dc1d 41 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 4:566f2c41dc1d 42 #include "mbed.h"
Wolfgang Betz 4:566f2c41dc1d 43 #include "DevI2C.h"
Wolfgang Betz 57:04563dd74269 44 #include "hts221.h"
Davidroid 88:7b8d3316d753 45 #include "HumiditySensor.h"
Davidroid 88:7b8d3316d753 46 #include "TempSensor.h"
Wolfgang Betz 4:566f2c41dc1d 47
Wolfgang Betz 4:566f2c41dc1d 48 /* Classes -------------------------------------------------------------------*/
Wolfgang Betz 4:566f2c41dc1d 49 /** Class representing a HTS221 sensor component
Wolfgang Betz 4:566f2c41dc1d 50 */
Wolfgang Betz 20:c20c8bd5be6b 51 class HTS221 : public HumiditySensor, public TempSensor {
Wolfgang Betz 4:566f2c41dc1d 52 public:
Wolfgang Betz 4:566f2c41dc1d 53 /** Constructor
Wolfgang Betz 54:2a676c734b30 54 * @param[in] i2c device I2C to be used for communication
Wolfgang Betz 4:566f2c41dc1d 55 */
Wolfgang Betz 92:d1c67d482bad 56 HTS221(DevI2C &i2c) : HumiditySensor(), TempSensor(), dev_i2c(i2c) {
Wolfgang Betz 4:566f2c41dc1d 57 T0_degC = T1_degC = H0_rh = H1_rh = 0.0;
Wolfgang Betz 4:566f2c41dc1d 58 T0_out = T1_out = H0_T0_out = H1_T0_out = 0;
Wolfgang Betz 4:566f2c41dc1d 59 }
Wolfgang Betz 4:566f2c41dc1d 60
Wolfgang Betz 44:d757094f6229 61 /** Destructor
Wolfgang Betz 44:d757094f6229 62 */
Wolfgang Betz 92:d1c67d482bad 63 virtual ~HTS221() {}
Wolfgang Betz 44:d757094f6229 64
Wolfgang Betz 4:566f2c41dc1d 65 /*** Interface Methods ***/
Wolfgang Betz 92:d1c67d482bad 66 virtual int init(void *init_struct) {
Wolfgang Betz 18:1cb4ae9d83e7 67 return HTS221_Init((HUM_TEMP_InitTypeDef*)init_struct);
Wolfgang Betz 4:566f2c41dc1d 68 }
Wolfgang Betz 4:566f2c41dc1d 69
Wolfgang Betz 50:f507d4465c31 70 /**
Wolfgang Betz 50:f507d4465c31 71 * @brief Enter sensor shutdown mode
Wolfgang Betz 50:f507d4465c31 72 * @return 0 in case of success, an error code otherwise
Wolfgang Betz 50:f507d4465c31 73 */
Wolfgang Betz 20:c20c8bd5be6b 74 virtual int PowerOff(void) {
Wolfgang Betz 4:566f2c41dc1d 75 return HTS221_Power_OFF();
Wolfgang Betz 4:566f2c41dc1d 76 }
Wolfgang Betz 4:566f2c41dc1d 77
Wolfgang Betz 92:d1c67d482bad 78 virtual int read_id(uint8_t *ht_id) {
Wolfgang Betz 4:566f2c41dc1d 79 return HTS221_ReadID(ht_id);
Wolfgang Betz 4:566f2c41dc1d 80 }
Wolfgang Betz 4:566f2c41dc1d 81
Wolfgang Betz 50:f507d4465c31 82 /**
Wolfgang Betz 50:f507d4465c31 83 * @brief Reset sensor
Wolfgang Betz 50:f507d4465c31 84 * @return 0 in case of success, an error code otherwise
Wolfgang Betz 50:f507d4465c31 85 */
Wolfgang Betz 18:1cb4ae9d83e7 86 virtual int Reset(void) {
Wolfgang Betz 4:566f2c41dc1d 87 return HTS221_RebootCmd();
Wolfgang Betz 4:566f2c41dc1d 88 }
Wolfgang Betz 4:566f2c41dc1d 89
Wolfgang Betz 92:d1c67d482bad 90 virtual int get_humidity(float *pfData) {
Wolfgang Betz 4:566f2c41dc1d 91 return HTS221_GetHumidity(pfData);
Wolfgang Betz 4:566f2c41dc1d 92 }
Wolfgang Betz 4:566f2c41dc1d 93
Wolfgang Betz 92:d1c67d482bad 94 virtual int get_temperature(float *pfData) {
Wolfgang Betz 4:566f2c41dc1d 95 return HTS221_GetTemperature(pfData);
Wolfgang Betz 4:566f2c41dc1d 96 }
Wolfgang Betz 4:566f2c41dc1d 97
Wolfgang Betz 4:566f2c41dc1d 98 protected:
Wolfgang Betz 4:566f2c41dc1d 99 /*** Methods ***/
Wolfgang Betz 4:566f2c41dc1d 100 HUM_TEMP_StatusTypeDef HTS221_Init(HUM_TEMP_InitTypeDef *HTS221_Init);
Wolfgang Betz 4:566f2c41dc1d 101 HUM_TEMP_StatusTypeDef HTS221_Power_OFF(void);
Wolfgang Betz 4:566f2c41dc1d 102 HUM_TEMP_StatusTypeDef HTS221_ReadID(uint8_t *ht_id);
Wolfgang Betz 4:566f2c41dc1d 103 HUM_TEMP_StatusTypeDef HTS221_RebootCmd(void);
Wolfgang Betz 4:566f2c41dc1d 104 HUM_TEMP_StatusTypeDef HTS221_GetHumidity(float* pfData);
Wolfgang Betz 4:566f2c41dc1d 105 HUM_TEMP_StatusTypeDef HTS221_GetTemperature(float* pfData);
Wolfgang Betz 6:8d2abd695c52 106
Wolfgang Betz 4:566f2c41dc1d 107 HUM_TEMP_StatusTypeDef HTS221_Power_On(void);
Wolfgang Betz 4:566f2c41dc1d 108 HUM_TEMP_StatusTypeDef HTS221_Calibration(void);
Wolfgang Betz 4:566f2c41dc1d 109
Wolfgang Betz 4:566f2c41dc1d 110 /**
Wolfgang Betz 4:566f2c41dc1d 111 * @brief Configures HTS221 interrupt lines for NUCLEO boards
Wolfgang Betz 4:566f2c41dc1d 112 */
Wolfgang Betz 4:566f2c41dc1d 113 void HTS221_IO_ITConfig(void)
Wolfgang Betz 4:566f2c41dc1d 114 {
Wolfgang Betz 4:566f2c41dc1d 115 /* To be implemented */
Wolfgang Betz 4:566f2c41dc1d 116 }
Wolfgang Betz 4:566f2c41dc1d 117
Wolfgang Betz 4:566f2c41dc1d 118 /**
Wolfgang Betz 4:566f2c41dc1d 119 * @brief Configures HTS221 I2C interface
Wolfgang Betz 57:04563dd74269 120 * @return HUM_TEMP_OK in case of success, an error code otherwise
Wolfgang Betz 4:566f2c41dc1d 121 */
Wolfgang Betz 4:566f2c41dc1d 122 HUM_TEMP_StatusTypeDef HTS221_IO_Init(void)
Wolfgang Betz 4:566f2c41dc1d 123 {
Wolfgang Betz 4:566f2c41dc1d 124 return HUM_TEMP_OK; /* done in constructor */
Wolfgang Betz 4:566f2c41dc1d 125 }
Wolfgang Betz 4:566f2c41dc1d 126
Wolfgang Betz 4:566f2c41dc1d 127 /**
Wolfgang Betz 57:04563dd74269 128 * @brief Utility function to read data from HTS221
Wolfgang Betz 57:04563dd74269 129 * @param[out] pBuffer pointer to the byte-array to read data in to
Wolfgang Betz 57:04563dd74269 130 * @param[in] RegisterAddr specifies internal address register to read from.
Wolfgang Betz 57:04563dd74269 131 * @param[in] NumByteToRead number of bytes to be read.
Wolfgang Betz 57:04563dd74269 132 * @retval HUM_TEMP_OK if ok,
Wolfgang Betz 57:04563dd74269 133 * @retval HUM_TEMP_ERROR if an I2C error has occured
Wolfgang Betz 4:566f2c41dc1d 134 */
Wolfgang Betz 4:566f2c41dc1d 135 HUM_TEMP_StatusTypeDef HTS221_IO_Read(uint8_t* pBuffer,
Wolfgang Betz 4:566f2c41dc1d 136 uint8_t RegisterAddr, uint16_t NumByteToRead)
Wolfgang Betz 4:566f2c41dc1d 137 {
Wolfgang Betz 4:566f2c41dc1d 138 int ret = dev_i2c.i2c_read(pBuffer,
Wolfgang Betz 4:566f2c41dc1d 139 HTS221_ADDRESS,
Wolfgang Betz 4:566f2c41dc1d 140 RegisterAddr,
Wolfgang Betz 4:566f2c41dc1d 141 NumByteToRead);
Wolfgang Betz 4:566f2c41dc1d 142 if(ret != 0) {
Wolfgang Betz 4:566f2c41dc1d 143 return HUM_TEMP_ERROR;
Wolfgang Betz 4:566f2c41dc1d 144 }
Wolfgang Betz 4:566f2c41dc1d 145 return HUM_TEMP_OK;
Wolfgang Betz 4:566f2c41dc1d 146 }
Wolfgang Betz 4:566f2c41dc1d 147
Wolfgang Betz 4:566f2c41dc1d 148 /**
Wolfgang Betz 57:04563dd74269 149 * @brief Utility function to write data to HTS221
Wolfgang Betz 57:04563dd74269 150 * @param[in] pBuffer pointer to the byte-array data to send
Wolfgang Betz 57:04563dd74269 151 * @param[in] RegisterAddr specifies internal address register to read from.
Wolfgang Betz 57:04563dd74269 152 * @param[in] NumByteToWrite number of bytes to write.
Wolfgang Betz 57:04563dd74269 153 * @retval HUM_TEMP_OK if ok,
Wolfgang Betz 57:04563dd74269 154 * @retval HUM_TEMP_ERROR if an I2C error has occured
Wolfgang Betz 4:566f2c41dc1d 155 */
Wolfgang Betz 4:566f2c41dc1d 156 HUM_TEMP_StatusTypeDef HTS221_IO_Write(uint8_t* pBuffer,
Wolfgang Betz 4:566f2c41dc1d 157 uint8_t RegisterAddr, uint16_t NumByteToWrite)
Wolfgang Betz 4:566f2c41dc1d 158 {
Wolfgang Betz 4:566f2c41dc1d 159 int ret = dev_i2c.i2c_write(pBuffer,
Wolfgang Betz 4:566f2c41dc1d 160 HTS221_ADDRESS,
Wolfgang Betz 4:566f2c41dc1d 161 RegisterAddr,
Wolfgang Betz 4:566f2c41dc1d 162 NumByteToWrite);
Wolfgang Betz 4:566f2c41dc1d 163 if(ret != 0) {
Wolfgang Betz 4:566f2c41dc1d 164 return HUM_TEMP_ERROR;
Wolfgang Betz 4:566f2c41dc1d 165 }
Wolfgang Betz 4:566f2c41dc1d 166 return HUM_TEMP_OK;
Wolfgang Betz 4:566f2c41dc1d 167 }
Wolfgang Betz 4:566f2c41dc1d 168
Wolfgang Betz 4:566f2c41dc1d 169 /*** Instance Variables ***/
Wolfgang Betz 4:566f2c41dc1d 170 /* IO Device */
Wolfgang Betz 4:566f2c41dc1d 171 DevI2C &dev_i2c;
Wolfgang Betz 4:566f2c41dc1d 172
Wolfgang Betz 4:566f2c41dc1d 173 /* Temperature in degree for calibration */
Wolfgang Betz 4:566f2c41dc1d 174 float T0_degC, T1_degC;
Wolfgang Betz 4:566f2c41dc1d 175
Wolfgang Betz 4:566f2c41dc1d 176 /* Output temperature value for calibration */
Wolfgang Betz 4:566f2c41dc1d 177 int16_t T0_out, T1_out;
Wolfgang Betz 4:566f2c41dc1d 178
Wolfgang Betz 4:566f2c41dc1d 179 /* Humidity for calibration */
Wolfgang Betz 4:566f2c41dc1d 180 float H0_rh, H1_rh;
Wolfgang Betz 4:566f2c41dc1d 181
Wolfgang Betz 4:566f2c41dc1d 182 /* Output Humidity value for calibration */
Wolfgang Betz 4:566f2c41dc1d 183 int16_t H0_T0_out, H1_T0_out;
Wolfgang Betz 4:566f2c41dc1d 184 };
Wolfgang Betz 4:566f2c41dc1d 185
Wolfgang Betz 4:566f2c41dc1d 186 #endif // __HTS221_CLASS_H