temp
Dependencies: mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem
MS5607/MS5607SPI.h@0:c88c3b616c00, 2020-03-16 (annotated)
- Committer:
- IKobayashi
- Date:
- Mon Mar 16 23:37:42 2020 +0900
- Revision:
- 0:c88c3b616c00
copy
Who changed what in which revision?
User | Revision | Line number | New 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_SPI_H |
IKobayashi | 0:c88c3b616c00 | 24 | #define MS5607_SPI_H |
IKobayashi | 0:c88c3b616c00 | 25 | |
IKobayashi | 0:c88c3b616c00 | 26 | #include "MS5607Base.h" |
IKobayashi | 0:c88c3b616c00 | 27 | |
IKobayashi | 0:c88c3b616c00 | 28 | class MS5607SPI : public MS5607Base { |
IKobayashi | 0:c88c3b616c00 | 29 | public: |
IKobayashi | 0:c88c3b616c00 | 30 | MS5607SPI(PinName mosi, PinName miso, PinName sclk, PinName csb) : spi(mosi, miso, sclk), csb(csb) { |
IKobayashi | 0:c88c3b616c00 | 31 | init(); |
IKobayashi | 0:c88c3b616c00 | 32 | } |
IKobayashi | 0:c88c3b616c00 | 33 | |
IKobayashi | 0:c88c3b616c00 | 34 | private: |
IKobayashi | 0:c88c3b616c00 | 35 | SPI spi; |
IKobayashi | 0:c88c3b616c00 | 36 | DigitalOut csb; |
IKobayashi | 0:c88c3b616c00 | 37 | |
IKobayashi | 0:c88c3b616c00 | 38 | virtual void writeCommand(int command, int ms = 0) { |
IKobayashi | 0:c88c3b616c00 | 39 | csb = 0; |
IKobayashi | 0:c88c3b616c00 | 40 | spi.write(command); |
IKobayashi | 0:c88c3b616c00 | 41 | if (ms) wait_ms(ms); |
IKobayashi | 0:c88c3b616c00 | 42 | csb = 1; |
IKobayashi | 0:c88c3b616c00 | 43 | } |
IKobayashi | 0:c88c3b616c00 | 44 | |
IKobayashi | 0:c88c3b616c00 | 45 | virtual int readPROM(int address) { |
IKobayashi | 0:c88c3b616c00 | 46 | csb = 0; |
IKobayashi | 0:c88c3b616c00 | 47 | spi.write(PROM_READ | address << 1); |
IKobayashi | 0:c88c3b616c00 | 48 | int hi = spi.write(0); |
IKobayashi | 0:c88c3b616c00 | 49 | int low = spi.write(0); |
IKobayashi | 0:c88c3b616c00 | 50 | csb = 1; |
IKobayashi | 0:c88c3b616c00 | 51 | return hi << 8 | low; |
IKobayashi | 0:c88c3b616c00 | 52 | } |
IKobayashi | 0:c88c3b616c00 | 53 | |
IKobayashi | 0:c88c3b616c00 | 54 | virtual int readADC(int command) { |
IKobayashi | 0:c88c3b616c00 | 55 | csb = 0; |
IKobayashi | 0:c88c3b616c00 | 56 | spi.write(ADC_CONV | command); |
IKobayashi | 0:c88c3b616c00 | 57 | static int duration[] = {500, 1100, 2100, 4100, 8220}; |
IKobayashi | 0:c88c3b616c00 | 58 | wait_us(duration[(command & 0x0F) >> 1]); |
IKobayashi | 0:c88c3b616c00 | 59 | csb = 1; |
IKobayashi | 0:c88c3b616c00 | 60 | csb = 0; |
IKobayashi | 0:c88c3b616c00 | 61 | spi.write(ADC_READ); |
IKobayashi | 0:c88c3b616c00 | 62 | int hi = spi.write(0); |
IKobayashi | 0:c88c3b616c00 | 63 | int mid = spi.write(0); |
IKobayashi | 0:c88c3b616c00 | 64 | int low = spi.write(0); |
IKobayashi | 0:c88c3b616c00 | 65 | csb = 1; |
IKobayashi | 0:c88c3b616c00 | 66 | return hi << 16 | mid << 8 | low; |
IKobayashi | 0:c88c3b616c00 | 67 | } |
IKobayashi | 0:c88c3b616c00 | 68 | }; |
IKobayashi | 0:c88c3b616c00 | 69 | |
IKobayashi | 0:c88c3b616c00 | 70 | #endif |