Added SPI3w support through DevSPI
Dependencies: ST_INTERFACES X_NUCLEO_COMMON_3W
Fork of LPS22HB by
LPS22HBSensor.h@0:3de9cb936fd1, 2017-09-04 (annotated)
- Committer:
- nikapov
- Date:
- Mon Sep 04 16:06:45 2017 +0000
- Revision:
- 0:3de9cb936fd1
- Child:
- 1:8813c9be1720
First version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikapov | 0:3de9cb936fd1 | 1 | /** |
nikapov | 0:3de9cb936fd1 | 2 | ****************************************************************************** |
nikapov | 0:3de9cb936fd1 | 3 | * @file LPS22HBSensor.h |
nikapov | 0:3de9cb936fd1 | 4 | * @author CLab |
nikapov | 0:3de9cb936fd1 | 5 | * @version V1.0.0 |
nikapov | 0:3de9cb936fd1 | 6 | * @date 5 August 2016 |
nikapov | 0:3de9cb936fd1 | 7 | * @brief Abstract Class of an LPS22HB Pressure sensor. |
nikapov | 0:3de9cb936fd1 | 8 | ****************************************************************************** |
nikapov | 0:3de9cb936fd1 | 9 | * @attention |
nikapov | 0:3de9cb936fd1 | 10 | * |
nikapov | 0:3de9cb936fd1 | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
nikapov | 0:3de9cb936fd1 | 12 | * |
nikapov | 0:3de9cb936fd1 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
nikapov | 0:3de9cb936fd1 | 14 | * are permitted provided that the following conditions are met: |
nikapov | 0:3de9cb936fd1 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
nikapov | 0:3de9cb936fd1 | 16 | * this list of conditions and the following disclaimer. |
nikapov | 0:3de9cb936fd1 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
nikapov | 0:3de9cb936fd1 | 18 | * this list of conditions and the following disclaimer in the documentation |
nikapov | 0:3de9cb936fd1 | 19 | * and/or other materials provided with the distribution. |
nikapov | 0:3de9cb936fd1 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
nikapov | 0:3de9cb936fd1 | 21 | * may be used to endorse or promote products derived from this software |
nikapov | 0:3de9cb936fd1 | 22 | * without specific prior written permission. |
nikapov | 0:3de9cb936fd1 | 23 | * |
nikapov | 0:3de9cb936fd1 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
nikapov | 0:3de9cb936fd1 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
nikapov | 0:3de9cb936fd1 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
nikapov | 0:3de9cb936fd1 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
nikapov | 0:3de9cb936fd1 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
nikapov | 0:3de9cb936fd1 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
nikapov | 0:3de9cb936fd1 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
nikapov | 0:3de9cb936fd1 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
nikapov | 0:3de9cb936fd1 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
nikapov | 0:3de9cb936fd1 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
nikapov | 0:3de9cb936fd1 | 34 | * |
nikapov | 0:3de9cb936fd1 | 35 | ****************************************************************************** |
nikapov | 0:3de9cb936fd1 | 36 | */ |
nikapov | 0:3de9cb936fd1 | 37 | |
nikapov | 0:3de9cb936fd1 | 38 | |
nikapov | 0:3de9cb936fd1 | 39 | /* Prevent recursive inclusion -----------------------------------------------*/ |
nikapov | 0:3de9cb936fd1 | 40 | |
nikapov | 0:3de9cb936fd1 | 41 | #ifndef __LPS22HBSensor_H__ |
nikapov | 0:3de9cb936fd1 | 42 | #define __LPS22HBSensor_H__ |
nikapov | 0:3de9cb936fd1 | 43 | |
nikapov | 0:3de9cb936fd1 | 44 | |
nikapov | 0:3de9cb936fd1 | 45 | /* Includes ------------------------------------------------------------------*/ |
nikapov | 0:3de9cb936fd1 | 46 | |
nikapov | 0:3de9cb936fd1 | 47 | #include "DevI2C.h" |
nikapov | 0:3de9cb936fd1 | 48 | #include "LPS22HB_driver.h" |
nikapov | 0:3de9cb936fd1 | 49 | #include "PressureSensor.h" |
nikapov | 0:3de9cb936fd1 | 50 | #include "TempSensor.h" |
nikapov | 0:3de9cb936fd1 | 51 | |
nikapov | 0:3de9cb936fd1 | 52 | /* Class Declaration ---------------------------------------------------------*/ |
nikapov | 0:3de9cb936fd1 | 53 | |
nikapov | 0:3de9cb936fd1 | 54 | /** |
nikapov | 0:3de9cb936fd1 | 55 | * Abstract class of an LPS22HB Pressure sensor. |
nikapov | 0:3de9cb936fd1 | 56 | */ |
nikapov | 0:3de9cb936fd1 | 57 | class LPS22HBSensor : public PressureSensor, public TempSensor |
nikapov | 0:3de9cb936fd1 | 58 | { |
nikapov | 0:3de9cb936fd1 | 59 | public: |
nikapov | 0:3de9cb936fd1 | 60 | LPS22HBSensor(DevI2C &i2c); |
nikapov | 0:3de9cb936fd1 | 61 | LPS22HBSensor(DevI2C &i2c, uint8_t address); |
nikapov | 0:3de9cb936fd1 | 62 | virtual int init(void *init); |
nikapov | 0:3de9cb936fd1 | 63 | virtual int read_id(uint8_t *id); |
nikapov | 0:3de9cb936fd1 | 64 | virtual int get_pressure(float *pfData); |
nikapov | 0:3de9cb936fd1 | 65 | virtual int get_temperature(float *pfData); |
nikapov | 0:3de9cb936fd1 | 66 | int enable(void); |
nikapov | 0:3de9cb936fd1 | 67 | int disable(void); |
nikapov | 0:3de9cb936fd1 | 68 | int reset(void); |
nikapov | 0:3de9cb936fd1 | 69 | int get_odr(float *odr); |
nikapov | 0:3de9cb936fd1 | 70 | int set_odr(float odr); |
nikapov | 0:3de9cb936fd1 | 71 | int read_reg(uint8_t reg, uint8_t *data); |
nikapov | 0:3de9cb936fd1 | 72 | int write_reg(uint8_t reg, uint8_t data); |
nikapov | 0:3de9cb936fd1 | 73 | |
nikapov | 0:3de9cb936fd1 | 74 | /** |
nikapov | 0:3de9cb936fd1 | 75 | * @brief Utility function to read data. |
nikapov | 0:3de9cb936fd1 | 76 | * @param pBuffer: pointer to data to be read. |
nikapov | 0:3de9cb936fd1 | 77 | * @param RegisterAddr: specifies internal address register to be read. |
nikapov | 0:3de9cb936fd1 | 78 | * @param NumByteToRead: number of bytes to be read. |
nikapov | 0:3de9cb936fd1 | 79 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:3de9cb936fd1 | 80 | */ |
nikapov | 0:3de9cb936fd1 | 81 | uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) |
nikapov | 0:3de9cb936fd1 | 82 | { |
nikapov | 0:3de9cb936fd1 | 83 | return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); |
nikapov | 0:3de9cb936fd1 | 84 | } |
nikapov | 0:3de9cb936fd1 | 85 | |
nikapov | 0:3de9cb936fd1 | 86 | /** |
nikapov | 0:3de9cb936fd1 | 87 | * @brief Utility function to write data. |
nikapov | 0:3de9cb936fd1 | 88 | * @param pBuffer: pointer to data to be written. |
nikapov | 0:3de9cb936fd1 | 89 | * @param RegisterAddr: specifies internal address register to be written. |
nikapov | 0:3de9cb936fd1 | 90 | * @param NumByteToWrite: number of bytes to write. |
nikapov | 0:3de9cb936fd1 | 91 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:3de9cb936fd1 | 92 | */ |
nikapov | 0:3de9cb936fd1 | 93 | uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
nikapov | 0:3de9cb936fd1 | 94 | { |
nikapov | 0:3de9cb936fd1 | 95 | return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); |
nikapov | 0:3de9cb936fd1 | 96 | } |
nikapov | 0:3de9cb936fd1 | 97 | |
nikapov | 0:3de9cb936fd1 | 98 | private: |
nikapov | 0:3de9cb936fd1 | 99 | int Set_ODR_When_Enabled(float odr); |
nikapov | 0:3de9cb936fd1 | 100 | int Set_ODR_When_Disabled(float odr); |
nikapov | 0:3de9cb936fd1 | 101 | |
nikapov | 0:3de9cb936fd1 | 102 | /* Helper classes. */ |
nikapov | 0:3de9cb936fd1 | 103 | DevI2C &_dev_i2c; |
nikapov | 0:3de9cb936fd1 | 104 | |
nikapov | 0:3de9cb936fd1 | 105 | /* Configuration */ |
nikapov | 0:3de9cb936fd1 | 106 | uint8_t _address; |
nikapov | 0:3de9cb936fd1 | 107 | |
nikapov | 0:3de9cb936fd1 | 108 | uint8_t _is_enabled; |
nikapov | 0:3de9cb936fd1 | 109 | float _last_odr; |
nikapov | 0:3de9cb936fd1 | 110 | }; |
nikapov | 0:3de9cb936fd1 | 111 | |
nikapov | 0:3de9cb936fd1 | 112 | #ifdef __cplusplus |
nikapov | 0:3de9cb936fd1 | 113 | extern "C" { |
nikapov | 0:3de9cb936fd1 | 114 | #endif |
nikapov | 0:3de9cb936fd1 | 115 | uint8_t LPS22HB_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
nikapov | 0:3de9cb936fd1 | 116 | uint8_t LPS22HB_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); |
nikapov | 0:3de9cb936fd1 | 117 | #ifdef __cplusplus |
nikapov | 0:3de9cb936fd1 | 118 | } |
nikapov | 0:3de9cb936fd1 | 119 | #endif |
nikapov | 0:3de9cb936fd1 | 120 | |
nikapov | 0:3de9cb936fd1 | 121 | #endif |