Finished project.

Dependencies:   X_NUCLEO_COMMON

Fork of ReferredCoursework2016 by Stage-1 Students SoCEM

Committer:
Wolfgang Betz
Date:
Mon Jun 08 13:57:32 2015 +0200
Revision:
43:2544d064d528
Parent:
24:92cc9c6e4b2b
Child:
44:d757094f6229
Move abstract classes to new & dedicated 'Interfaces' directory

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 6:8d2abd695c52 60 /*** Interface Methods ***/
Wolfgang Betz 18:1cb4ae9d83e7 61 virtual int Init(void *init_struct) {
Wolfgang Betz 18:1cb4ae9d83e7 62 return LPS25H_Init((PRESSURE_InitTypeDef*)init_struct);
Wolfgang Betz 6:8d2abd695c52 63 }
Wolfgang Betz 6:8d2abd695c52 64
Wolfgang Betz 18:1cb4ae9d83e7 65 virtual int PowerOff(void) {
Wolfgang Betz 6:8d2abd695c52 66 return LPS25H_PowerOff();
Wolfgang Betz 6:8d2abd695c52 67 }
Wolfgang Betz 6:8d2abd695c52 68
Wolfgang Betz 18:1cb4ae9d83e7 69 virtual int ReadID(uint8_t *p_id) {
Wolfgang Betz 6:8d2abd695c52 70 return LPS25H_ReadID(p_id);
Wolfgang Betz 6:8d2abd695c52 71 }
Wolfgang Betz 6:8d2abd695c52 72
Wolfgang Betz 18:1cb4ae9d83e7 73 virtual int Reset(void) {
Wolfgang Betz 6:8d2abd695c52 74 return LPS25H_RebootCmd();
Wolfgang Betz 6:8d2abd695c52 75 }
Wolfgang Betz 6:8d2abd695c52 76
Wolfgang Betz 6:8d2abd695c52 77 virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
Wolfgang Betz 6:8d2abd695c52 78 virtual void EnableIT(uint8_t) { /* not yet implemented */ }
Wolfgang Betz 6:8d2abd695c52 79 virtual void DisableIT(uint8_t) { /* not yet implemented */ }
Wolfgang Betz 6:8d2abd695c52 80 virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
Wolfgang Betz 6:8d2abd695c52 81 virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
Wolfgang Betz 6:8d2abd695c52 82
Wolfgang Betz 18:1cb4ae9d83e7 83 virtual int GetPressure(float *pfData) {
Wolfgang Betz 6:8d2abd695c52 84 return LPS25H_GetPressure(pfData);
Wolfgang Betz 6:8d2abd695c52 85 }
Wolfgang Betz 6:8d2abd695c52 86
Wolfgang Betz 18:1cb4ae9d83e7 87 virtual int GetTemperature(float *pfData) {
Wolfgang Betz 6:8d2abd695c52 88 return LPS25H_GetTemperature(pfData);
Wolfgang Betz 6:8d2abd695c52 89 }
Wolfgang Betz 6:8d2abd695c52 90
Wolfgang Betz 20:c20c8bd5be6b 91 virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }
Wolfgang Betz 20:c20c8bd5be6b 92
Wolfgang Betz 20:c20c8bd5be6b 93 void SlaveAddrRemap(uint8_t SA0_Bit_Status) {
Wolfgang Betz 6:8d2abd695c52 94 LPS25H_SlaveAddrRemap(SA0_Bit_Status);
Wolfgang Betz 6:8d2abd695c52 95 }
Wolfgang Betz 6:8d2abd695c52 96
Wolfgang Betz 6:8d2abd695c52 97 protected:
Wolfgang Betz 6:8d2abd695c52 98 /*** Methods ***/
Wolfgang Betz 6:8d2abd695c52 99 PRESSURE_StatusTypeDef LPS25H_Init(PRESSURE_InitTypeDef *LPS25H_Init);
Wolfgang Betz 6:8d2abd695c52 100 PRESSURE_StatusTypeDef LPS25H_ReadID(uint8_t *p_id);
Wolfgang Betz 6:8d2abd695c52 101 PRESSURE_StatusTypeDef LPS25H_RebootCmd(void);
Wolfgang Betz 6:8d2abd695c52 102 PRESSURE_StatusTypeDef LPS25H_GetPressure(float* pfData);
Wolfgang Betz 6:8d2abd695c52 103 PRESSURE_StatusTypeDef LPS25H_GetTemperature(float* pfData);
Wolfgang Betz 6:8d2abd695c52 104 PRESSURE_StatusTypeDef LPS25H_PowerOff(void);
Wolfgang Betz 6:8d2abd695c52 105 void LPS25H_SlaveAddrRemap(uint8_t SA0_Bit_Status);
Wolfgang Betz 6:8d2abd695c52 106
Wolfgang Betz 6:8d2abd695c52 107 PRESSURE_StatusTypeDef LPS25H_PowerOn(void);
Wolfgang Betz 24:92cc9c6e4b2b 108 PRESSURE_StatusTypeDef LPS25H_I2C_ReadRawPressure(int32_t *raw_press);
Wolfgang Betz 6:8d2abd695c52 109 PRESSURE_StatusTypeDef LPS25H_I2C_ReadRawTemperature(int16_t *raw_data);
Wolfgang Betz 6:8d2abd695c52 110
Wolfgang Betz 6:8d2abd695c52 111 /**
Wolfgang Betz 6:8d2abd695c52 112 * @brief Configures LPS25H interrupt lines for NUCLEO boards
Wolfgang Betz 6:8d2abd695c52 113 * @param None
Wolfgang Betz 6:8d2abd695c52 114 * @retval None
Wolfgang Betz 6:8d2abd695c52 115 */
Wolfgang Betz 6:8d2abd695c52 116 void LPS25H_IO_ITConfig(void)
Wolfgang Betz 6:8d2abd695c52 117 {
Wolfgang Betz 6:8d2abd695c52 118 /* To be implemented */
Wolfgang Betz 6:8d2abd695c52 119 }
Wolfgang Betz 6:8d2abd695c52 120
Wolfgang Betz 6:8d2abd695c52 121 /**
Wolfgang Betz 6:8d2abd695c52 122 * @brief Configures LPS25H I2C interface
Wolfgang Betz 6:8d2abd695c52 123 * @param None
Wolfgang Betz 6:8d2abd695c52 124 * @retval PRESSURE_OK in case of success, an error code otherwise
Wolfgang Betz 6:8d2abd695c52 125 */
Wolfgang Betz 6:8d2abd695c52 126 PRESSURE_StatusTypeDef LPS25H_IO_Init(void)
Wolfgang Betz 6:8d2abd695c52 127 {
Wolfgang Betz 6:8d2abd695c52 128 return PRESSURE_OK; /* done in constructor */
Wolfgang Betz 6:8d2abd695c52 129 }
Wolfgang Betz 6:8d2abd695c52 130
Wolfgang Betz 6:8d2abd695c52 131 /**
Wolfgang Betz 6:8d2abd695c52 132 * @brief utility function to read data from STC3115
Wolfgang Betz 6:8d2abd695c52 133 * @param pBuffer: pointer to data to be read.
Wolfgang Betz 6:8d2abd695c52 134 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 6:8d2abd695c52 135 * @param NumByteToRead: number of bytes to be read.
Wolfgang Betz 6:8d2abd695c52 136 * @retval PRESSURE_OK if ok, PRESSURE_ERROR if an I2C error has occured
Wolfgang Betz 6:8d2abd695c52 137 */
Wolfgang Betz 6:8d2abd695c52 138 PRESSURE_StatusTypeDef LPS25H_IO_Read(uint8_t* pBuffer,
Wolfgang Betz 6:8d2abd695c52 139 uint8_t RegisterAddr, uint16_t NumByteToRead)
Wolfgang Betz 6:8d2abd695c52 140 {
Wolfgang Betz 6:8d2abd695c52 141 int ret = dev_i2c.i2c_read(pBuffer,
Wolfgang Betz 6:8d2abd695c52 142 LPS25H_SlaveAddress,
Wolfgang Betz 6:8d2abd695c52 143 RegisterAddr,
Wolfgang Betz 6:8d2abd695c52 144 NumByteToRead);
Wolfgang Betz 6:8d2abd695c52 145 if(ret != 0) {
Wolfgang Betz 6:8d2abd695c52 146 return PRESSURE_ERROR;
Wolfgang Betz 6:8d2abd695c52 147 }
Wolfgang Betz 6:8d2abd695c52 148 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 149 }
Wolfgang Betz 6:8d2abd695c52 150
Wolfgang Betz 6:8d2abd695c52 151 /**
Wolfgang Betz 6:8d2abd695c52 152 * @brief utility function to write data to STC3115
Wolfgang Betz 6:8d2abd695c52 153 * @param pBuffer: pointer to buffer to be filled.
Wolfgang Betz 6:8d2abd695c52 154 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 6:8d2abd695c52 155 * @param NumByteToWrite: number of bytes to write.
Wolfgang Betz 6:8d2abd695c52 156 * @retval 0 if ok, -1 if an I2C error has occured
Wolfgang Betz 6:8d2abd695c52 157 */
Wolfgang Betz 6:8d2abd695c52 158 PRESSURE_StatusTypeDef LPS25H_IO_Write(uint8_t* pBuffer,
Wolfgang Betz 6:8d2abd695c52 159 uint8_t RegisterAddr, uint16_t NumByteToWrite)
Wolfgang Betz 6:8d2abd695c52 160 {
Wolfgang Betz 6:8d2abd695c52 161 int ret = dev_i2c.i2c_write(pBuffer,
Wolfgang Betz 6:8d2abd695c52 162 LPS25H_SlaveAddress,
Wolfgang Betz 6:8d2abd695c52 163 RegisterAddr,
Wolfgang Betz 6:8d2abd695c52 164 NumByteToWrite);
Wolfgang Betz 6:8d2abd695c52 165 if(ret != 0) {
Wolfgang Betz 6:8d2abd695c52 166 return PRESSURE_ERROR;
Wolfgang Betz 6:8d2abd695c52 167 }
Wolfgang Betz 6:8d2abd695c52 168 return PRESSURE_OK;
Wolfgang Betz 6:8d2abd695c52 169 }
Wolfgang Betz 6:8d2abd695c52 170
Wolfgang Betz 6:8d2abd695c52 171 /*** Instance Variables ***/
Wolfgang Betz 6:8d2abd695c52 172 /* IO Device */
Wolfgang Betz 6:8d2abd695c52 173 DevI2C &dev_i2c;
Wolfgang Betz 6:8d2abd695c52 174
Wolfgang Betz 6:8d2abd695c52 175 uint8_t LPS25H_SlaveAddress;
Wolfgang Betz 6:8d2abd695c52 176 };
Wolfgang Betz 6:8d2abd695c52 177
Wolfgang Betz 6:8d2abd695c52 178 #endif // __LPS25H_CLASS_H