Finished project.

Dependencies:   X_NUCLEO_COMMON

Fork of ReferredCoursework2016 by Stage-1 Students SoCEM

Committer:
Wolfgang Betz
Date:
Mon Jun 08 18:04:19 2015 +0200
Revision:
50:f507d4465c31
Parent:
44:d757094f6229
Child:
54:2a676c734b30
Cleanup interfaces from not yet comfirmed methods

Potential generic methods to be put into interface classes from which to
derive other interfaces from are (among others):
- virtual int PowerOff(void) { /* not yet implemented */ return 0; }
- virtual int Reset(void) { /* not yet implemented */ return 0; }

- virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
- virtual void EnableIT(uint8_t) { /* not yet implemented */ }
- virtual void DisableIT(uint8_t) { /* not yet implemented */ }
- virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
- virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
- virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }

Who changed what in which revision?

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