temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IKobayashi 0:c88c3b616c00 1 /*
IKobayashi 0:c88c3b616c00 2 Copyright (c) 2012, Senio Networks, Inc.
IKobayashi 0:c88c3b616c00 3
IKobayashi 0:c88c3b616c00 4 Permission is hereby granted, free of charge, to any person obtaining a copy
IKobayashi 0:c88c3b616c00 5 of this software and associated documentation files (the "Software"), to deal
IKobayashi 0:c88c3b616c00 6 in the Software without restriction, including without limitation the rights
IKobayashi 0:c88c3b616c00 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
IKobayashi 0:c88c3b616c00 8 copies of the Software, and to permit persons to whom the Software is
IKobayashi 0:c88c3b616c00 9 furnished to do so, subject to the following conditions:
IKobayashi 0:c88c3b616c00 10
IKobayashi 0:c88c3b616c00 11 The above copyright notice and this permission notice shall be included in
IKobayashi 0:c88c3b616c00 12 all copies or substantial portions of the Software.
IKobayashi 0:c88c3b616c00 13
IKobayashi 0:c88c3b616c00 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IKobayashi 0:c88c3b616c00 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
IKobayashi 0:c88c3b616c00 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
IKobayashi 0:c88c3b616c00 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
IKobayashi 0:c88c3b616c00 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
IKobayashi 0:c88c3b616c00 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
IKobayashi 0:c88c3b616c00 20 THE SOFTWARE.
IKobayashi 0:c88c3b616c00 21 */
IKobayashi 0:c88c3b616c00 22
IKobayashi 0:c88c3b616c00 23 #ifndef MS5607_I2C_H
IKobayashi 0:c88c3b616c00 24 #define MS5607_I2C_H
IKobayashi 0:c88c3b616c00 25
IKobayashi 0:c88c3b616c00 26 #include "MS5607Base.h"
IKobayashi 0:c88c3b616c00 27
IKobayashi 0:c88c3b616c00 28 class MS5607I2C : public MS5607Base {
IKobayashi 0:c88c3b616c00 29 public:
IKobayashi 0:c88c3b616c00 30 MS5607I2C(PinName sda, PinName scl, int csb = 0) : i2c(sda, scl), i2cAddr(csb ? 0xEC : 0xEE) {
IKobayashi 0:c88c3b616c00 31 init();
IKobayashi 0:c88c3b616c00 32 }
IKobayashi 0:c88c3b616c00 33
IKobayashi 0:c88c3b616c00 34 private:
IKobayashi 0:c88c3b616c00 35 I2C i2c;
IKobayashi 0:c88c3b616c00 36 int i2cAddr;
IKobayashi 0:c88c3b616c00 37
IKobayashi 0:c88c3b616c00 38 virtual void writeCommand(int command, int ms = 0) {
IKobayashi 0:c88c3b616c00 39 char buf[1] = {command};
IKobayashi 0:c88c3b616c00 40 i2c.write(i2cAddr, buf, 1);
IKobayashi 0:c88c3b616c00 41 if (ms) wait_ms(ms);
IKobayashi 0:c88c3b616c00 42 }
IKobayashi 0:c88c3b616c00 43
IKobayashi 0:c88c3b616c00 44 virtual int readPROM(int address) {
IKobayashi 0:c88c3b616c00 45 char buf[2] = {PROM_READ | (address << 1), 0};
IKobayashi 0:c88c3b616c00 46
IKobayashi 0:c88c3b616c00 47 if (i2c.write(i2cAddr, buf, 1) == 0 &&
IKobayashi 0:c88c3b616c00 48 i2c.read(i2cAddr, buf, 2) == 0)
IKobayashi 0:c88c3b616c00 49 return buf[0] << 8 | buf[1];
IKobayashi 0:c88c3b616c00 50
IKobayashi 0:c88c3b616c00 51 return -1;
IKobayashi 0:c88c3b616c00 52 }
IKobayashi 0:c88c3b616c00 53
IKobayashi 0:c88c3b616c00 54 virtual int readADC(int command) {
IKobayashi 0:c88c3b616c00 55 char cmd[] = {ADC_CONV | command};
IKobayashi 0:c88c3b616c00 56
IKobayashi 0:c88c3b616c00 57 if (i2c.write(i2cAddr, cmd, sizeof(cmd)) == 0) {
IKobayashi 0:c88c3b616c00 58 static int duration[] = {500, 1100, 2100, 4100, 8220};
IKobayashi 0:c88c3b616c00 59 wait_us(duration[(command & 0x0F) >> 1]);
IKobayashi 0:c88c3b616c00 60 cmd[0] = ADC_READ;
IKobayashi 0:c88c3b616c00 61 char buf[3];
IKobayashi 0:c88c3b616c00 62 if (i2c.write(i2cAddr, cmd, sizeof(cmd)) == 0 &&
IKobayashi 0:c88c3b616c00 63 i2c.read(i2cAddr, buf, sizeof(buf)) == 0)
IKobayashi 0:c88c3b616c00 64 return buf[0] << 16 | buf[1] << 8 | buf[2];
IKobayashi 0:c88c3b616c00 65 }
IKobayashi 0:c88c3b616c00 66
IKobayashi 0:c88c3b616c00 67 return -1;
IKobayashi 0:c88c3b616c00 68 }
IKobayashi 0:c88c3b616c00 69 };
IKobayashi 0:c88c3b616c00 70
IKobayashi 0:c88c3b616c00 71 #endif