lab 7

Fork of MPL3115A2 by MSS

Committer:
Rhyme
Date:
Sun Dec 13 08:57:16 2015 +0000
Revision:
0:752c9dbed2fa
Child:
1:6fdcf150410e
commit before publishing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:752c9dbed2fa 1 /*
Rhyme 0:752c9dbed2fa 2 * File description here
Rhyme 0:752c9dbed2fa 3 */
Rhyme 0:752c9dbed2fa 4 #include "MPL3115A2.h"
Rhyme 0:752c9dbed2fa 5
Rhyme 0:752c9dbed2fa 6 /* some definitions here */
Rhyme 0:752c9dbed2fa 7 #define MPL_STATUS 0x00
Rhyme 0:752c9dbed2fa 8 #define MPL_OUT_P_MSB 0x01
Rhyme 0:752c9dbed2fa 9 #define MPL_OUT_P_CSB 0x02
Rhyme 0:752c9dbed2fa 10 #define MPL_OUT_P_LSB 0x03
Rhyme 0:752c9dbed2fa 11 #define MPL_OUT_T_MSB 0x04
Rhyme 0:752c9dbed2fa 12 #define MPL_OUT_T_LSB 0x05
Rhyme 0:752c9dbed2fa 13 #define MPL_DR_STATUS 0x06
Rhyme 0:752c9dbed2fa 14 #define MPL_OUT_P_DELTA_MSB 0x07
Rhyme 0:752c9dbed2fa 15 #define MPL_OUT_P_DELTA_CSB 0x08
Rhyme 0:752c9dbed2fa 16 #define MPL_OUT_P_DELTA_LSB 0x09
Rhyme 0:752c9dbed2fa 17 #define MPL_OUT_T_DELTA_MSB 0x0A
Rhyme 0:752c9dbed2fa 18 #define MPL_OUT_T_DELTA_LSB 0x0B
Rhyme 0:752c9dbed2fa 19 #define MPL_WHO_AM_I 0x0C
Rhyme 0:752c9dbed2fa 20 #define MPL_F_STATUS 0x0D
Rhyme 0:752c9dbed2fa 21 #define MPL_F_DATA 0x0E
Rhyme 0:752c9dbed2fa 22 #define MPL_F_SETUP 0x0F
Rhyme 0:752c9dbed2fa 23 #define MPL_TIME_DLY 0x10
Rhyme 0:752c9dbed2fa 24 #define MPL_SYSMOD 0x11
Rhyme 0:752c9dbed2fa 25 #define MPL_INT_SOURCE 0x12
Rhyme 0:752c9dbed2fa 26 #define MPL_PT_DATA_CFG 0x13
Rhyme 0:752c9dbed2fa 27 #define MPL_BAR_IN_MSB 0x14
Rhyme 0:752c9dbed2fa 28 #define MPL_BAR_IN_LSB 0x15
Rhyme 0:752c9dbed2fa 29 #define MPL_P_TGT_MSB 0x16
Rhyme 0:752c9dbed2fa 30 #define MPL_P_TGT_LSB 0x17
Rhyme 0:752c9dbed2fa 31 #define MPL_T_TGT 0x18
Rhyme 0:752c9dbed2fa 32 #define MPL_P_WND_MSB 0x19
Rhyme 0:752c9dbed2fa 33 #define MPL_P_WND_LSB 0x1A
Rhyme 0:752c9dbed2fa 34 #define MPL_T_WND 0x1B
Rhyme 0:752c9dbed2fa 35 #define MPL_P_MIN_MSB 0x1C
Rhyme 0:752c9dbed2fa 36 #define MPL_P_MIN_CSB 0x1D
Rhyme 0:752c9dbed2fa 37 #define MPL_P_MIN_LSB 0x1E
Rhyme 0:752c9dbed2fa 38 #define MPL_T_MIN_MSB 0x1F
Rhyme 0:752c9dbed2fa 39 #define MPL_T_MIN_LSB 0x20
Rhyme 0:752c9dbed2fa 40 #define MPL_P_MAX_MSB 0x21
Rhyme 0:752c9dbed2fa 41 #define MPL_P_MAX_CSB 0x22
Rhyme 0:752c9dbed2fa 42 #define MPL_P_MAX_LSB 0x23
Rhyme 0:752c9dbed2fa 43 #define MPL_T_MAX_MSB 0x24
Rhyme 0:752c9dbed2fa 44 #define MPL_T_MAX_LSB 0x25
Rhyme 0:752c9dbed2fa 45 #define MPL_CTRL_REG1 0x26
Rhyme 0:752c9dbed2fa 46 #define MPL_CTRL_REG2 0x27
Rhyme 0:752c9dbed2fa 47 #define MPL_CTRL_REG3 0x28
Rhyme 0:752c9dbed2fa 48 #define MPL_CTRL_REG4 0x29
Rhyme 0:752c9dbed2fa 49 #define MPL_CTRL_REG5 0x2A
Rhyme 0:752c9dbed2fa 50 #define MPL_OFF_P 0x2B
Rhyme 0:752c9dbed2fa 51 #define MPL_OFF_T 0x2C
Rhyme 0:752c9dbed2fa 52 #define MPL_OFF_H 0x2D
Rhyme 0:752c9dbed2fa 53 /*
Rhyme 0:752c9dbed2fa 54 * If F_MODE = 0, FIFO is disabled
Rhyme 0:752c9dbed2fa 55 *
Rhyme 0:752c9dbed2fa 56 * 0x00/0x06 Sensor Status Register (DR_STATUS)
Rhyme 0:752c9dbed2fa 57 * 0x01 Pressure Data Out MSB (OUT_P_MSB)
Rhyme 0:752c9dbed2fa 58 * 0x02 Pressure Data Out CSB (OUT_P_CSB)
Rhyme 0:752c9dbed2fa 59 * 0x03 Pressure Data Out LSB (OUT_P_LSB)
Rhyme 0:752c9dbed2fa 60 * 0x04 Temperature Data Out MSB (OUT_T_MSB)
Rhyme 0:752c9dbed2fa 61 * 0x05 Temperature Data out LSB (OUT_T_LSB)
Rhyme 0:752c9dbed2fa 62 *
Rhyme 0:752c9dbed2fa 63 * If F_Mode > 0, FIFO is circular buffer or full stop mode
Rhyme 0:752c9dbed2fa 64 *
Rhyme 0:752c9dbed2fa 65 * 0x00/0x0D Sensor Status Register (F_STATUS)
Rhyme 0:752c9dbed2fa 66 * 0x01 FIFO 8-bit Data Access (F_DATA)
Rhyme 0:752c9dbed2fa 67 * 0x02 Read to Reserved Area returns 00
Rhyme 0:752c9dbed2fa 68 * 0x03 Read to Reserved Area returns 00
Rhyme 0:752c9dbed2fa 69 * 0x04 Read to Reserved Area returns 00
Rhyme 0:752c9dbed2fa 70 * 0x05 Read to Reserved Area returns 00
Rhyme 0:752c9dbed2fa 71 *
Rhyme 0:752c9dbed2fa 72 * F_MODE = 00, FIFO is disabled
Rhyme 0:752c9dbed2fa 73 * F_MODE = 01, FIFO is circulated buffer
Rhyme 0:752c9dbed2fa 74 * F_MODE = 10, FIFO is full stop mode
Rhyme 0:752c9dbed2fa 75 */
Rhyme 0:752c9dbed2fa 76
Rhyme 0:752c9dbed2fa 77
Rhyme 0:752c9dbed2fa 78 MPL3115A2::MPL3115A2(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr<<1) {
Rhyme 0:752c9dbed2fa 79 // activate the peripheral
Rhyme 0:752c9dbed2fa 80 }
Rhyme 0:752c9dbed2fa 81
Rhyme 0:752c9dbed2fa 82 MPL3115A2::~MPL3115A2() { }
Rhyme 0:752c9dbed2fa 83
Rhyme 0:752c9dbed2fa 84 void MPL3115A2::readRegs(int addr, uint8_t * data, int len) {
Rhyme 0:752c9dbed2fa 85 char t[1] = {addr} ;
Rhyme 0:752c9dbed2fa 86 m_i2c.write(m_addr, t, 1, true) ;
Rhyme 0:752c9dbed2fa 87 m_i2c.read(m_addr, (char*)data, len) ;
Rhyme 0:752c9dbed2fa 88 }
Rhyme 0:752c9dbed2fa 89
Rhyme 0:752c9dbed2fa 90 void MPL3115A2::writeRegs(uint8_t * data, int len) {
Rhyme 0:752c9dbed2fa 91 m_i2c.write(m_addr, (char *)data, len) ;
Rhyme 0:752c9dbed2fa 92 }
Rhyme 0:752c9dbed2fa 93
Rhyme 0:752c9dbed2fa 94 uint8_t MPL3115A2::getStatus(void) {
Rhyme 0:752c9dbed2fa 95 uint8_t data[1] ;
Rhyme 0:752c9dbed2fa 96 readRegs(MPL_DR_STATUS, data, 1) ;
Rhyme 0:752c9dbed2fa 97 return( data[0] ) ;
Rhyme 0:752c9dbed2fa 98 }
Rhyme 0:752c9dbed2fa 99
Rhyme 0:752c9dbed2fa 100 /*
Rhyme 0:752c9dbed2fa 101 * getAltitude returns the altitude in meters times 65536
Rhyme 0:752c9dbed2fa 102 */
Rhyme 0:752c9dbed2fa 103 uint32_t MPL3115A2::getAltitude(void)
Rhyme 0:752c9dbed2fa 104 {
Rhyme 0:752c9dbed2fa 105 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 106 uint32_t data ;
Rhyme 0:752c9dbed2fa 107
Rhyme 0:752c9dbed2fa 108 readRegs(MPL_OUT_P_MSB, tmp, 3) ;
Rhyme 0:752c9dbed2fa 109 data = (tmp[0]<<24)|(tmp[1]<<16)|(tmp[2]<<8) ;
Rhyme 0:752c9dbed2fa 110 return( data ) ;
Rhyme 0:752c9dbed2fa 111 }
Rhyme 0:752c9dbed2fa 112
Rhyme 0:752c9dbed2fa 113 /*
Rhyme 0:752c9dbed2fa 114 * getPressure returns the pressure in Pascals times 64
Rhyme 0:752c9dbed2fa 115 */
Rhyme 0:752c9dbed2fa 116 uint32_t MPL3115A2::getPressure(void)
Rhyme 0:752c9dbed2fa 117 {
Rhyme 0:752c9dbed2fa 118 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 119 uint32_t data ;
Rhyme 0:752c9dbed2fa 120
Rhyme 0:752c9dbed2fa 121 readRegs(MPL_OUT_P_MSB, tmp, 3) ;
Rhyme 0:752c9dbed2fa 122 data = (tmp[0]<<16)|(tmp[1]<<8)|(tmp[2]) ;
Rhyme 0:752c9dbed2fa 123 return( data ) ;
Rhyme 0:752c9dbed2fa 124 }
Rhyme 0:752c9dbed2fa 125
Rhyme 0:752c9dbed2fa 126 /*
Rhyme 0:752c9dbed2fa 127 * getTemperature returns the temperature in c-degree times 256
Rhyme 0:752c9dbed2fa 128 */
Rhyme 0:752c9dbed2fa 129 uint16_t MPL3115A2::getTemperature(void)
Rhyme 0:752c9dbed2fa 130 {
Rhyme 0:752c9dbed2fa 131 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 132 uint16_t data ;
Rhyme 0:752c9dbed2fa 133
Rhyme 0:752c9dbed2fa 134 readRegs(MPL_OUT_T_MSB, tmp, 2) ;
Rhyme 0:752c9dbed2fa 135 data = (tmp[0]<<8)|(tmp[1]) ;
Rhyme 0:752c9dbed2fa 136 return( data ) ;
Rhyme 0:752c9dbed2fa 137 }
Rhyme 0:752c9dbed2fa 138
Rhyme 0:752c9dbed2fa 139 /*
Rhyme 0:752c9dbed2fa 140 * getAltDelta returns delta of alt in meters times 65536
Rhyme 0:752c9dbed2fa 141 */
Rhyme 0:752c9dbed2fa 142 int32_t MPL3115A2::getAltDelta(void)
Rhyme 0:752c9dbed2fa 143 {
Rhyme 0:752c9dbed2fa 144 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 145 int32_t data ;
Rhyme 0:752c9dbed2fa 146
Rhyme 0:752c9dbed2fa 147 readRegs(MPL_OUT_P_DELTA_MSB, tmp, 3) ;
Rhyme 0:752c9dbed2fa 148 data = (tmp[0]<<24)|(tmp[1]<<16)|((tmp[2]&0xF0)<<8) ;
Rhyme 0:752c9dbed2fa 149 return( data ) ;
Rhyme 0:752c9dbed2fa 150 }
Rhyme 0:752c9dbed2fa 151
Rhyme 0:752c9dbed2fa 152 /*
Rhyme 0:752c9dbed2fa 153 * getPrsDelta returns delta of pressure in Pascal times 16
Rhyme 0:752c9dbed2fa 154 */
Rhyme 0:752c9dbed2fa 155 int32_t MPL3115A2::getPrsDelta(void)
Rhyme 0:752c9dbed2fa 156 {
Rhyme 0:752c9dbed2fa 157 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 158 int32_t data ;
Rhyme 0:752c9dbed2fa 159
Rhyme 0:752c9dbed2fa 160 readRegs(MPL_OUT_P_DELTA_MSB, tmp, 3) ;
Rhyme 0:752c9dbed2fa 161 data = (tmp[0]<<24)|(tmp[1]<<16)|((tmp[2]&0xF0)<<8) ;
Rhyme 0:752c9dbed2fa 162 return( data ) ;
Rhyme 0:752c9dbed2fa 163 }
Rhyme 0:752c9dbed2fa 164
Rhyme 0:752c9dbed2fa 165 /*
Rhyme 0:752c9dbed2fa 166 * getTempDelta returns delta of temperature in c-degree times 16
Rhyme 0:752c9dbed2fa 167 */
Rhyme 0:752c9dbed2fa 168 int16_t MPL3115A2::getTempDelta(void)
Rhyme 0:752c9dbed2fa 169 {
Rhyme 0:752c9dbed2fa 170 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 171 int16_t data ;
Rhyme 0:752c9dbed2fa 172
Rhyme 0:752c9dbed2fa 173 readRegs(MPL_OUT_T_DELTA_MSB, tmp, 2) ;
Rhyme 0:752c9dbed2fa 174 data = (tmp[0]<<8) | (tmp[1]&0xF0) ;
Rhyme 0:752c9dbed2fa 175 return( data ) ;
Rhyme 0:752c9dbed2fa 176 }
Rhyme 0:752c9dbed2fa 177
Rhyme 0:752c9dbed2fa 178 uint8_t MPL3115A2::getID(void)
Rhyme 0:752c9dbed2fa 179 {
Rhyme 0:752c9dbed2fa 180 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 181 readRegs(MPL_WHO_AM_I, tmp, 1) ;
Rhyme 0:752c9dbed2fa 182 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 183 }
Rhyme 0:752c9dbed2fa 184
Rhyme 0:752c9dbed2fa 185 uint8_t MPL3115A2::getFstatus(void)
Rhyme 0:752c9dbed2fa 186 {
Rhyme 0:752c9dbed2fa 187 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 188 readRegs(MPL_F_STATUS, tmp, 1) ;
Rhyme 0:752c9dbed2fa 189 return(tmp[0]) ;
Rhyme 0:752c9dbed2fa 190 }
Rhyme 0:752c9dbed2fa 191
Rhyme 0:752c9dbed2fa 192 uint8_t MPL3115A2::getFdata(void)
Rhyme 0:752c9dbed2fa 193 {
Rhyme 0:752c9dbed2fa 194 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 195 readRegs(MPL_F_DATA, tmp, 1) ;
Rhyme 0:752c9dbed2fa 196 return(tmp[0]) ;
Rhyme 0:752c9dbed2fa 197 }
Rhyme 0:752c9dbed2fa 198
Rhyme 0:752c9dbed2fa 199 uint8_t MPL3115A2::getFsetup(void)
Rhyme 0:752c9dbed2fa 200 {
Rhyme 0:752c9dbed2fa 201 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 202 readRegs(MPL_F_SETUP, tmp, 1) ;
Rhyme 0:752c9dbed2fa 203 return(tmp[0]) ;
Rhyme 0:752c9dbed2fa 204 }
Rhyme 0:752c9dbed2fa 205
Rhyme 0:752c9dbed2fa 206 void MPL3115A2::setFsetup(uint8_t data)
Rhyme 0:752c9dbed2fa 207 {
Rhyme 0:752c9dbed2fa 208 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 209 tmp[0] = MPL_F_SETUP ;
Rhyme 0:752c9dbed2fa 210 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 211 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 212 }
Rhyme 0:752c9dbed2fa 213
Rhyme 0:752c9dbed2fa 214 uint8_t MPL3115A2::getTimeDelay(void)
Rhyme 0:752c9dbed2fa 215 {
Rhyme 0:752c9dbed2fa 216 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 217 readRegs(MPL_TIME_DLY, tmp, 1) ;
Rhyme 0:752c9dbed2fa 218 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 219 }
Rhyme 0:752c9dbed2fa 220
Rhyme 0:752c9dbed2fa 221 uint8_t MPL3115A2::getSysMod(void)
Rhyme 0:752c9dbed2fa 222 {
Rhyme 0:752c9dbed2fa 223 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 224 readRegs(MPL_SYSMOD, tmp, 1) ;
Rhyme 0:752c9dbed2fa 225 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 226 }
Rhyme 0:752c9dbed2fa 227
Rhyme 0:752c9dbed2fa 228 uint8_t MPL3115A2::getIntSource(void)
Rhyme 0:752c9dbed2fa 229 {
Rhyme 0:752c9dbed2fa 230 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 231 readRegs(MPL_INT_SOURCE, tmp, 1) ;
Rhyme 0:752c9dbed2fa 232 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 233 }
Rhyme 0:752c9dbed2fa 234
Rhyme 0:752c9dbed2fa 235 uint8_t MPL3115A2::getPtDataConfig(void)
Rhyme 0:752c9dbed2fa 236 {
Rhyme 0:752c9dbed2fa 237 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 238 readRegs(MPL_PT_DATA_CFG, tmp, 1) ;
Rhyme 0:752c9dbed2fa 239 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 240 }
Rhyme 0:752c9dbed2fa 241
Rhyme 0:752c9dbed2fa 242 void MPL3115A2::setPtDataConfig(uint8_t data)
Rhyme 0:752c9dbed2fa 243 {
Rhyme 0:752c9dbed2fa 244 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 245 tmp[0] = MPL_PT_DATA_CFG ;
Rhyme 0:752c9dbed2fa 246 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 247 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 248 }
Rhyme 0:752c9dbed2fa 249
Rhyme 0:752c9dbed2fa 250 uint16_t MPL3115A2::getBarIn(void)
Rhyme 0:752c9dbed2fa 251 {
Rhyme 0:752c9dbed2fa 252 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 253 readRegs(MPL_BAR_IN_MSB, tmp, 2) ;
Rhyme 0:752c9dbed2fa 254 return( (uint16_t)tmp[0] ) ;
Rhyme 0:752c9dbed2fa 255 }
Rhyme 0:752c9dbed2fa 256
Rhyme 0:752c9dbed2fa 257 void MPL3115A2::setBarIn(uint16_t data)
Rhyme 0:752c9dbed2fa 258 {
Rhyme 0:752c9dbed2fa 259 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 260 tmp[0] = MPL_BAR_IN_MSB ;
Rhyme 0:752c9dbed2fa 261 tmp[1] = (data >> 8)&0xFF ;
Rhyme 0:752c9dbed2fa 262 tmp[2] = data & 0xFF ;
Rhyme 0:752c9dbed2fa 263 writeRegs(tmp, 3) ;
Rhyme 0:752c9dbed2fa 264 }
Rhyme 0:752c9dbed2fa 265
Rhyme 0:752c9dbed2fa 266 int16_t MPL3115A2::getP_TGT(void)
Rhyme 0:752c9dbed2fa 267 {
Rhyme 0:752c9dbed2fa 268 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 269 int16_t data ;
Rhyme 0:752c9dbed2fa 270 readRegs(MPL_P_TGT_MSB, tmp, 2) ;
Rhyme 0:752c9dbed2fa 271 data = (tmp[0] << 8) | tmp[1] ;
Rhyme 0:752c9dbed2fa 272 return( data ) ;
Rhyme 0:752c9dbed2fa 273 }
Rhyme 0:752c9dbed2fa 274
Rhyme 0:752c9dbed2fa 275 void MPL3115A2::setP_TGT(int16_t data)
Rhyme 0:752c9dbed2fa 276 {
Rhyme 0:752c9dbed2fa 277 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 278 tmp[0] = MPL_P_TGT_MSB ;
Rhyme 0:752c9dbed2fa 279 tmp[1] = (data >> 8) & 0xFF ;
Rhyme 0:752c9dbed2fa 280 tmp[2] = data & 0xFF ;
Rhyme 0:752c9dbed2fa 281 writeRegs(tmp, 3) ;
Rhyme 0:752c9dbed2fa 282 }
Rhyme 0:752c9dbed2fa 283
Rhyme 0:752c9dbed2fa 284 int8_t MPL3115A2::getT_TGT(void)
Rhyme 0:752c9dbed2fa 285 {
Rhyme 0:752c9dbed2fa 286 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 287 readRegs(MPL_T_TGT, tmp, 1) ;
Rhyme 0:752c9dbed2fa 288 return( (int8_t)tmp[0] ) ;
Rhyme 0:752c9dbed2fa 289 }
Rhyme 0:752c9dbed2fa 290
Rhyme 0:752c9dbed2fa 291 void MPL3115A2::setT_TGT(int8_t data)
Rhyme 0:752c9dbed2fa 292 {
Rhyme 0:752c9dbed2fa 293 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 294 tmp[0] = MPL_PT_DATA_CFG ;
Rhyme 0:752c9dbed2fa 295 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 296 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 297 }
Rhyme 0:752c9dbed2fa 298
Rhyme 0:752c9dbed2fa 299 uint16_t MPL3115A2::getP_WND(void)
Rhyme 0:752c9dbed2fa 300 {
Rhyme 0:752c9dbed2fa 301 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 302 uint16_t data ;
Rhyme 0:752c9dbed2fa 303 readRegs(MPL_P_WND_MSB, tmp, 2) ;
Rhyme 0:752c9dbed2fa 304 data = (tmp[0]<<8) | tmp[1] ;
Rhyme 0:752c9dbed2fa 305 return(data) ;
Rhyme 0:752c9dbed2fa 306 }
Rhyme 0:752c9dbed2fa 307
Rhyme 0:752c9dbed2fa 308 void MPL3115A2::setP_WND(uint16_t data)
Rhyme 0:752c9dbed2fa 309 {
Rhyme 0:752c9dbed2fa 310 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 311 tmp[0] = MPL_P_WND_MSB ;
Rhyme 0:752c9dbed2fa 312 tmp[1] = (data >> 8)&0xFF ;
Rhyme 0:752c9dbed2fa 313 tmp[2] = data & 0xFF ;
Rhyme 0:752c9dbed2fa 314 writeRegs(tmp, 3) ;
Rhyme 0:752c9dbed2fa 315 }
Rhyme 0:752c9dbed2fa 316
Rhyme 0:752c9dbed2fa 317 uint8_t MPL3115A2::getT_WND(void)
Rhyme 0:752c9dbed2fa 318 {
Rhyme 0:752c9dbed2fa 319 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 320 readRegs(MPL_T_WND, tmp, 1) ;
Rhyme 0:752c9dbed2fa 321 return(tmp[0]) ;
Rhyme 0:752c9dbed2fa 322 }
Rhyme 0:752c9dbed2fa 323
Rhyme 0:752c9dbed2fa 324 void MPL3115A2::setT_WND(uint8_t data)
Rhyme 0:752c9dbed2fa 325 {
Rhyme 0:752c9dbed2fa 326 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 327 tmp[0] = MPL_T_WND ;
Rhyme 0:752c9dbed2fa 328 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 329 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 330 }
Rhyme 0:752c9dbed2fa 331
Rhyme 0:752c9dbed2fa 332 int32_t MPL3115A2::getP_MIN(void)
Rhyme 0:752c9dbed2fa 333 {
Rhyme 0:752c9dbed2fa 334 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 335 int32_t data ;
Rhyme 0:752c9dbed2fa 336 readRegs(MPL_P_MIN_MSB, tmp, 3) ;
Rhyme 0:752c9dbed2fa 337 data = (tmp[0]<<24)|(tmp[1]<<16)|((tmp[2]&0xF0)<<8) ;
Rhyme 0:752c9dbed2fa 338 return( data ) ;
Rhyme 0:752c9dbed2fa 339 }
Rhyme 0:752c9dbed2fa 340
Rhyme 0:752c9dbed2fa 341 void MPL3115A2::setT_MIN(int32_t data)
Rhyme 0:752c9dbed2fa 342 {
Rhyme 0:752c9dbed2fa 343 uint8_t tmp[4] ;
Rhyme 0:752c9dbed2fa 344 tmp[0] = MPL_P_MIN_MSB ;
Rhyme 0:752c9dbed2fa 345 tmp[1] = (data >> 24) & 0xFF ;
Rhyme 0:752c9dbed2fa 346 tmp[2] = (data >> 16) & 0xFF ;
Rhyme 0:752c9dbed2fa 347 tmp[3] = (data >> 8) & 0xF0 ;
Rhyme 0:752c9dbed2fa 348 writeRegs(tmp, 4) ;
Rhyme 0:752c9dbed2fa 349 }
Rhyme 0:752c9dbed2fa 350
Rhyme 0:752c9dbed2fa 351 int32_t MPL3115A2::getP_MAX(void)
Rhyme 0:752c9dbed2fa 352 {
Rhyme 0:752c9dbed2fa 353 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 354 int32_t data ;
Rhyme 0:752c9dbed2fa 355 readRegs(MPL_P_MAX_MSB, tmp, 3) ;
Rhyme 0:752c9dbed2fa 356 data = (tmp[0]<<24)|(tmp[1]<<16)|((tmp[2]&0xF0)<<8) ;
Rhyme 0:752c9dbed2fa 357 return( data ) ;
Rhyme 0:752c9dbed2fa 358 }
Rhyme 0:752c9dbed2fa 359
Rhyme 0:752c9dbed2fa 360 void MPL3115A2::setP_MAX(int32_t data)
Rhyme 0:752c9dbed2fa 361 {
Rhyme 0:752c9dbed2fa 362 uint8_t tmp[4] ;
Rhyme 0:752c9dbed2fa 363 tmp[0] = MPL_P_MAX_MSB ;
Rhyme 0:752c9dbed2fa 364 tmp[1] = (data >> 24) & 0xFF ;
Rhyme 0:752c9dbed2fa 365 tmp[2] = (data >> 16) & 0xFF ;
Rhyme 0:752c9dbed2fa 366 tmp[3] = (data >> 8) & 0xF0 ;
Rhyme 0:752c9dbed2fa 367 writeRegs(tmp, 4) ;
Rhyme 0:752c9dbed2fa 368 }
Rhyme 0:752c9dbed2fa 369
Rhyme 0:752c9dbed2fa 370 int16_t MPL3115A2::getT_MIN(void)
Rhyme 0:752c9dbed2fa 371 {
Rhyme 0:752c9dbed2fa 372 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 373 uint16_t data ;
Rhyme 0:752c9dbed2fa 374 readRegs(MPL_T_MIN_MSB, tmp, 2) ;
Rhyme 0:752c9dbed2fa 375 data = (tmp[0]<<8) | tmp[1] ;
Rhyme 0:752c9dbed2fa 376 return(data) ;
Rhyme 0:752c9dbed2fa 377 }
Rhyme 0:752c9dbed2fa 378
Rhyme 0:752c9dbed2fa 379 void MPL3115A2::setT_MIN(int16_t data)
Rhyme 0:752c9dbed2fa 380 {
Rhyme 0:752c9dbed2fa 381 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 382 tmp[0] = MPL_T_MIN_MSB ;
Rhyme 0:752c9dbed2fa 383 tmp[1] = (data >> 8) & 0xFF ;
Rhyme 0:752c9dbed2fa 384 tmp[2] = data & 0xFF ;
Rhyme 0:752c9dbed2fa 385 writeRegs(tmp, 3) ;
Rhyme 0:752c9dbed2fa 386 }
Rhyme 0:752c9dbed2fa 387
Rhyme 0:752c9dbed2fa 388 int16_t MPL3115A2::getT_MAX(void)
Rhyme 0:752c9dbed2fa 389 {
Rhyme 0:752c9dbed2fa 390 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 391 uint16_t data ;
Rhyme 0:752c9dbed2fa 392 readRegs(MPL_T_MAX_MSB, tmp, 2) ;
Rhyme 0:752c9dbed2fa 393 data = (tmp[0]<<8) | tmp[1] ;
Rhyme 0:752c9dbed2fa 394 return( data ) ;
Rhyme 0:752c9dbed2fa 395 }
Rhyme 0:752c9dbed2fa 396
Rhyme 0:752c9dbed2fa 397 void MPL3115A2::setT_MAX(int16_t data)
Rhyme 0:752c9dbed2fa 398 {
Rhyme 0:752c9dbed2fa 399 uint8_t tmp[3] ;
Rhyme 0:752c9dbed2fa 400 tmp[0] = MPL_T_MAX_MSB ;
Rhyme 0:752c9dbed2fa 401 tmp[1] = (data >> 8) & 0xFF ;
Rhyme 0:752c9dbed2fa 402 tmp[2] = data & 0xFF ;
Rhyme 0:752c9dbed2fa 403 writeRegs(tmp, 3) ;
Rhyme 0:752c9dbed2fa 404 }
Rhyme 0:752c9dbed2fa 405
Rhyme 0:752c9dbed2fa 406 uint8_t MPL3115A2::getCTRL_REG1(void)
Rhyme 0:752c9dbed2fa 407 {
Rhyme 0:752c9dbed2fa 408 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 409 readRegs(MPL_CTRL_REG1, tmp, 1) ;
Rhyme 0:752c9dbed2fa 410 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 411 }
Rhyme 0:752c9dbed2fa 412
Rhyme 0:752c9dbed2fa 413 void MPL3115A2::setCTRL_REG1(uint8_t data)
Rhyme 0:752c9dbed2fa 414 {
Rhyme 0:752c9dbed2fa 415 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 416 tmp[0] = MPL_CTRL_REG1 ;
Rhyme 0:752c9dbed2fa 417 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 418 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 419 }
Rhyme 0:752c9dbed2fa 420
Rhyme 0:752c9dbed2fa 421 uint8_t MPL3115A2::getCTRL_REG2(void)
Rhyme 0:752c9dbed2fa 422 {
Rhyme 0:752c9dbed2fa 423 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 424 readRegs(MPL_CTRL_REG2, tmp, 1) ;
Rhyme 0:752c9dbed2fa 425 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 426 }
Rhyme 0:752c9dbed2fa 427
Rhyme 0:752c9dbed2fa 428 void MPL3115A2::setCTRL_REG2(uint8_t data)
Rhyme 0:752c9dbed2fa 429 {
Rhyme 0:752c9dbed2fa 430 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 431 tmp[0] = MPL_CTRL_REG2 ;
Rhyme 0:752c9dbed2fa 432 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 433 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 434 }
Rhyme 0:752c9dbed2fa 435
Rhyme 0:752c9dbed2fa 436 uint8_t MPL3115A2::getCTRL_REG3(void)
Rhyme 0:752c9dbed2fa 437 {
Rhyme 0:752c9dbed2fa 438 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 439 readRegs(MPL_CTRL_REG3, tmp, 1) ;
Rhyme 0:752c9dbed2fa 440 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 441 }
Rhyme 0:752c9dbed2fa 442
Rhyme 0:752c9dbed2fa 443 void MPL3115A2::setCTRL_REG3(uint8_t data)
Rhyme 0:752c9dbed2fa 444 {
Rhyme 0:752c9dbed2fa 445 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 446 tmp[0] = MPL_CTRL_REG3 ;
Rhyme 0:752c9dbed2fa 447 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 448 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 449 }
Rhyme 0:752c9dbed2fa 450
Rhyme 0:752c9dbed2fa 451 uint8_t MPL3115A2::getCTRL_REG4(void)
Rhyme 0:752c9dbed2fa 452 {
Rhyme 0:752c9dbed2fa 453 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 454 readRegs(MPL_CTRL_REG4, tmp, 1) ;
Rhyme 0:752c9dbed2fa 455 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 456 }
Rhyme 0:752c9dbed2fa 457
Rhyme 0:752c9dbed2fa 458 void MPL3115A2::setCTRL_REG4(uint8_t data)
Rhyme 0:752c9dbed2fa 459 {
Rhyme 0:752c9dbed2fa 460 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 461 tmp[0] = MPL_CTRL_REG4 ;
Rhyme 0:752c9dbed2fa 462 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 463 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 464 }
Rhyme 0:752c9dbed2fa 465
Rhyme 0:752c9dbed2fa 466 uint8_t MPL3115A2::getCTRL_REG5(void)
Rhyme 0:752c9dbed2fa 467 {
Rhyme 0:752c9dbed2fa 468 uint8_t tmp[1] ;
Rhyme 0:752c9dbed2fa 469 readRegs(MPL_CTRL_REG5, tmp, 1) ;
Rhyme 0:752c9dbed2fa 470 return( tmp[0] ) ;
Rhyme 0:752c9dbed2fa 471 }
Rhyme 0:752c9dbed2fa 472
Rhyme 0:752c9dbed2fa 473 void MPL3115A2::setCTRL_REG5(uint8_t data)
Rhyme 0:752c9dbed2fa 474 {
Rhyme 0:752c9dbed2fa 475 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 476 tmp[0] = MPL_CTRL_REG5 ;
Rhyme 0:752c9dbed2fa 477 tmp[1] = data ;
Rhyme 0:752c9dbed2fa 478 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 479 }
Rhyme 0:752c9dbed2fa 480
Rhyme 0:752c9dbed2fa 481 uint16_t MPL3115A2::OneShot(void)
Rhyme 0:752c9dbed2fa 482 {
Rhyme 0:752c9dbed2fa 483 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 484 uint16_t sample_time = 6 ;
Rhyme 0:752c9dbed2fa 485 tmp[0] = MPL_CTRL_REG1 ;
Rhyme 0:752c9dbed2fa 486 readRegs(tmp[0], &tmp[1], 1) ;
Rhyme 0:752c9dbed2fa 487 tmp[1] |= 0x02 ;
Rhyme 0:752c9dbed2fa 488 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 489 switch((tmp[1]>>3)&0x07) {
Rhyme 0:752c9dbed2fa 490 case 0: sample_time = 6 ; break ;
Rhyme 0:752c9dbed2fa 491 case 1: sample_time = 10 ; break ;
Rhyme 0:752c9dbed2fa 492 case 2: sample_time = 18 ; break ;
Rhyme 0:752c9dbed2fa 493 case 3: sample_time = 34 ; break ;
Rhyme 0:752c9dbed2fa 494 case 4: sample_time = 66 ; break ;
Rhyme 0:752c9dbed2fa 495 case 5: sample_time = 130 ; break ;
Rhyme 0:752c9dbed2fa 496 case 6: sample_time = 258 ; break ;
Rhyme 0:752c9dbed2fa 497 case 7: sample_time = 512 ; break ;
Rhyme 0:752c9dbed2fa 498 default: sample_time = 6 ; break ;
Rhyme 0:752c9dbed2fa 499 }
Rhyme 0:752c9dbed2fa 500 return( sample_time ) ;
Rhyme 0:752c9dbed2fa 501 }
Rhyme 0:752c9dbed2fa 502
Rhyme 0:752c9dbed2fa 503 void MPL3115A2::standby(void)
Rhyme 0:752c9dbed2fa 504 {
Rhyme 0:752c9dbed2fa 505 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 506 tmp[0] = MPL_CTRL_REG1 ;
Rhyme 0:752c9dbed2fa 507 readRegs(tmp[0], &tmp[1], 1) ;
Rhyme 0:752c9dbed2fa 508 tmp[1] &= 0xFE ;
Rhyme 0:752c9dbed2fa 509 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 510 }
Rhyme 0:752c9dbed2fa 511
Rhyme 0:752c9dbed2fa 512 void MPL3115A2::activate(void)
Rhyme 0:752c9dbed2fa 513 {
Rhyme 0:752c9dbed2fa 514 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 515 tmp[0] = MPL_CTRL_REG1 ;
Rhyme 0:752c9dbed2fa 516 readRegs(tmp[0], &tmp[1], 1) ;
Rhyme 0:752c9dbed2fa 517 tmp[1] |= 0x01 ;
Rhyme 0:752c9dbed2fa 518 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 519 }
Rhyme 0:752c9dbed2fa 520
Rhyme 0:752c9dbed2fa 521 void MPL3115A2::modeAlt(void)
Rhyme 0:752c9dbed2fa 522 {
Rhyme 0:752c9dbed2fa 523 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 524 tmp[0] = MPL_CTRL_REG1 ;
Rhyme 0:752c9dbed2fa 525 readRegs(tmp[0], &tmp[1], 1) ;
Rhyme 0:752c9dbed2fa 526 tmp[1] |= 0x80 ;
Rhyme 0:752c9dbed2fa 527 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 528 }
Rhyme 0:752c9dbed2fa 529
Rhyme 0:752c9dbed2fa 530 void MPL3115A2::modeBar(void)
Rhyme 0:752c9dbed2fa 531 {
Rhyme 0:752c9dbed2fa 532 uint8_t tmp[2] ;
Rhyme 0:752c9dbed2fa 533 tmp[0] = MPL_CTRL_REG1 ;
Rhyme 0:752c9dbed2fa 534 readRegs(tmp[0], &tmp[1], 1) ;
Rhyme 0:752c9dbed2fa 535 tmp[1] &= 0x7F ;
Rhyme 0:752c9dbed2fa 536 writeRegs(tmp, 2) ;
Rhyme 0:752c9dbed2fa 537 }