dszds

Committer:
zinnetyazicii53
Date:
Sun Jul 28 08:14:38 2019 +0000
Revision:
0:83277b73a1f8
commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zinnetyazicii53 0:83277b73a1f8 1 /*
zinnetyazicii53 0:83277b73a1f8 2 #define MAX30102_ADDRESS 0x57 //7-bit I2C Address
zinnetyazicii53 0:83277b73a1f8 3 //Note that MAX30102 has the same I2C address and Part ID
zinnetyazicii53 0:83277b73a1f8 4
zinnetyazicii53 0:83277b73a1f8 5 #define I2C_SPEED_STANDARD 100000
zinnetyazicii53 0:83277b73a1f8 6 #define I2C_SPEED_FAST 400000
zinnetyazicii53 0:83277b73a1f8 7
zinnetyazicii53 0:83277b73a1f8 8
zinnetyazicii53 0:83277b73a1f8 9 //Define the size of the I2C buffer based on the platform the user has
zinnetyazicii53 0:83277b73a1f8 10 #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
zinnetyazicii53 0:83277b73a1f8 11
zinnetyazicii53 0:83277b73a1f8 12 //I2C_BUFFER_LENGTH is defined in Wire.H
zinnetyazicii53 0:83277b73a1f8 13 #define I2C_BUFFER_LENGTH BUFFER_LENGTH
zinnetyazicii53 0:83277b73a1f8 14
zinnetyazicii53 0:83277b73a1f8 15 #elif defined(__SAMD21G18A__)
zinnetyazicii53 0:83277b73a1f8 16
zinnetyazicii53 0:83277b73a1f8 17 //SAMD21 uses RingBuffer.h
zinnetyazicii53 0:83277b73a1f8 18 #define I2C_BUFFER_LENGTH SERIAL_BUFFER_SIZE
zinnetyazicii53 0:83277b73a1f8 19
zinnetyazicii53 0:83277b73a1f8 20 #else
zinnetyazicii53 0:83277b73a1f8 21
zinnetyazicii53 0:83277b73a1f8 22 //The catch-all default is 32
zinnetyazicii53 0:83277b73a1f8 23 #define I2C_BUFFER_LENGTH 32
zinnetyazicii53 0:83277b73a1f8 24
zinnetyazicii53 0:83277b73a1f8 25 #endif
zinnetyazicii53 0:83277b73a1f8 26
zinnetyazicii53 0:83277b73a1f8 27 class MAX30102 {
zinnetyazicii53 0:83277b73a1f8 28 public:
zinnetyazicii53 0:83277b73a1f8 29 MAX30102(void);
zinnetyazicii53 0:83277b73a1f8 30
zinnetyazicii53 0:83277b73a1f8 31 // bool begin(TwoWire &wirePort = Wire, uint32_t i2cSpeed = I2C_SPEED_STANDARD, uint8_t i2caddr = MAX30102_ADDRESS);
zinnetyazicii53 0:83277b73a1f8 32
zinnetyazicii53 0:83277b73a1f8 33 uint32_t getRed(void); //Returns immediate red value
zinnetyazicii53 0:83277b73a1f8 34 uint32_t getIR(void); //Returns immediate IR value
zinnetyazicii53 0:83277b73a1f8 35 uint32_t getGreen(void); //Returns immediate green value
zinnetyazicii53 0:83277b73a1f8 36 bool safeCheck(uint8_t maxTimeToCheck); //Given a max amount of time, check for new data
zinnetyazicii53 0:83277b73a1f8 37
zinnetyazicii53 0:83277b73a1f8 38 // Configuration
zinnetyazicii53 0:83277b73a1f8 39 void softReset();
zinnetyazicii53 0:83277b73a1f8 40 void shutDown();
zinnetyazicii53 0:83277b73a1f8 41 void wakeUp();
zinnetyazicii53 0:83277b73a1f8 42
zinnetyazicii53 0:83277b73a1f8 43 void setLEDMode(uint8_t mode);
zinnetyazicii53 0:83277b73a1f8 44
zinnetyazicii53 0:83277b73a1f8 45 void setADCRange(uint8_t adcRange);
zinnetyazicii53 0:83277b73a1f8 46 void setSampleRate(uint8_t sampleRate);
zinnetyazicii53 0:83277b73a1f8 47 void setPulseWidth(uint8_t pulseWidth);
zinnetyazicii53 0:83277b73a1f8 48
zinnetyazicii53 0:83277b73a1f8 49 void setPulseAmplitudeRed(uint8_t value);
zinnetyazicii53 0:83277b73a1f8 50 void setPulseAmplitudeIR(uint8_t value);
zinnetyazicii53 0:83277b73a1f8 51 void setPulseAmplitudeGreen(uint8_t value);
zinnetyazicii53 0:83277b73a1f8 52 void setPulseAmplitudeProximity(uint8_t value);
zinnetyazicii53 0:83277b73a1f8 53
zinnetyazicii53 0:83277b73a1f8 54 void setProximityThreshold(uint8_t threshMSB);
zinnetyazicii53 0:83277b73a1f8 55
zinnetyazicii53 0:83277b73a1f8 56 //Multi-led configuration mode (page 22)
zinnetyazicii53 0:83277b73a1f8 57 void enableSlot(uint8_t slotNumber, uint8_t device); //Given slot number, assign a device to slot
zinnetyazicii53 0:83277b73a1f8 58 void disableSlots(void);
zinnetyazicii53 0:83277b73a1f8 59
zinnetyazicii53 0:83277b73a1f8 60 // Data Collection
zinnetyazicii53 0:83277b73a1f8 61
zinnetyazicii53 0:83277b73a1f8 62 //Interrupts (page 13, 14)
zinnetyazicii53 0:83277b73a1f8 63 uint8_t getINT1(void); //Returns the main interrupt group
zinnetyazicii53 0:83277b73a1f8 64 uint8_t getINT2(void); //Returns the temp ready interrupt
zinnetyazicii53 0:83277b73a1f8 65 void enableAFULL(void); //Enable/disable individual interrupts
zinnetyazicii53 0:83277b73a1f8 66 void disableAFULL(void);
zinnetyazicii53 0:83277b73a1f8 67 void enableDATARDY(void);
zinnetyazicii53 0:83277b73a1f8 68 void disableDATARDY(void);
zinnetyazicii53 0:83277b73a1f8 69 void enableALCOVF(void);
zinnetyazicii53 0:83277b73a1f8 70 void disableALCOVF(void);
zinnetyazicii53 0:83277b73a1f8 71 void enablePROXINT(void);
zinnetyazicii53 0:83277b73a1f8 72 void disablePROXINT(void);
zinnetyazicii53 0:83277b73a1f8 73 void enableDIETEMPRDY(void);
zinnetyazicii53 0:83277b73a1f8 74 void disableDIETEMPRDY(void);
zinnetyazicii53 0:83277b73a1f8 75
zinnetyazicii53 0:83277b73a1f8 76 //FIFO Configuration (page 18)
zinnetyazicii53 0:83277b73a1f8 77 void setFIFOAverage(uint8_t samples);
zinnetyazicii53 0:83277b73a1f8 78 void enableFIFORollover();
zinnetyazicii53 0:83277b73a1f8 79 void disableFIFORollover();
zinnetyazicii53 0:83277b73a1f8 80 void setFIFOAlmostFull(uint8_t samples);
zinnetyazicii53 0:83277b73a1f8 81
zinnetyazicii53 0:83277b73a1f8 82 //FIFO Reading
zinnetyazicii53 0:83277b73a1f8 83 uint16_t check(void); //Checks for new data and fills FIFO
zinnetyazicii53 0:83277b73a1f8 84 uint8_t available(void); //Tells caller how many new samples are available (head - tail)
zinnetyazicii53 0:83277b73a1f8 85 void nextSample(void); //Advances the tail of the sense array
zinnetyazicii53 0:83277b73a1f8 86 uint32_t getFIFORed(void); //Returns the FIFO sample pointed to by tail
zinnetyazicii53 0:83277b73a1f8 87 uint32_t getFIFOIR(void); //Returns the FIFO sample pointed to by tail
zinnetyazicii53 0:83277b73a1f8 88 uint32_t getFIFOGreen(void); //Returns the FIFO sample pointed to by tail
zinnetyazicii53 0:83277b73a1f8 89
zinnetyazicii53 0:83277b73a1f8 90 uint8_t getWritePointer(void);
zinnetyazicii53 0:83277b73a1f8 91 uint8_t getReadPointer(void);
zinnetyazicii53 0:83277b73a1f8 92 void clearFIFO(void); //Sets the read/write pointers to zero
zinnetyazicii53 0:83277b73a1f8 93
zinnetyazicii53 0:83277b73a1f8 94 //Proximity Mode Interrupt Threshold
zinnetyazicii53 0:83277b73a1f8 95 void setPROXINTTHRESH(uint8_t val);
zinnetyazicii53 0:83277b73a1f8 96
zinnetyazicii53 0:83277b73a1f8 97 // Die Temperature
zinnetyazicii53 0:83277b73a1f8 98 float readTemperature();
zinnetyazicii53 0:83277b73a1f8 99 float readTemperatureF();
zinnetyazicii53 0:83277b73a1f8 100
zinnetyazicii53 0:83277b73a1f8 101 // Detecting ID/Revision
zinnetyazicii53 0:83277b73a1f8 102 uint8_t getRevisionID();
zinnetyazicii53 0:83277b73a1f8 103 uint8_t readPartID();
zinnetyazicii53 0:83277b73a1f8 104
zinnetyazicii53 0:83277b73a1f8 105 // Setup the IC with user selectable settings
zinnetyazicii53 0:83277b73a1f8 106 void setup(byte powerLevel = 0x1F, byte sampleAverage = 4, byte ledMode = 3, int sampleRate = 400, int pulseWidth = 411, int adcRange = 4096);
zinnetyazicii53 0:83277b73a1f8 107
zinnetyazicii53 0:83277b73a1f8 108 // Low-level I2C communication
zinnetyazicii53 0:83277b73a1f8 109 uint8_t readRegister8(uint8_t address, uint8_t reg);
zinnetyazicii53 0:83277b73a1f8 110 void writeRegister8(uint8_t address, uint8_t reg, uint8_t value);
zinnetyazicii53 0:83277b73a1f8 111
zinnetyazicii53 0:83277b73a1f8 112 private:
zinnetyazicii53 0:83277b73a1f8 113 TwoWire *_i2cPort; //The generic connection to user's chosen I2C hardware
zinnetyazicii53 0:83277b73a1f8 114 uint8_t _i2caddr;
zinnetyazicii53 0:83277b73a1f8 115
zinnetyazicii53 0:83277b73a1f8 116 //activeLEDs is the number of channels turned on, and can be 1 to 3. 2 is common for Red+IR.
zinnetyazicii53 0:83277b73a1f8 117 byte activeLEDs; //Gets set during setup. Allows check() to calculate how many bytes to read from FIFO
zinnetyazicii53 0:83277b73a1f8 118
zinnetyazicii53 0:83277b73a1f8 119 uint8_t revisionID;
zinnetyazicii53 0:83277b73a1f8 120
zinnetyazicii53 0:83277b73a1f8 121 void readRevisionID();
zinnetyazicii53 0:83277b73a1f8 122
zinnetyazicii53 0:83277b73a1f8 123 void bitMask(uint8_t reg, uint8_t mask, uint8_t thing);
zinnetyazicii53 0:83277b73a1f8 124
zinnetyazicii53 0:83277b73a1f8 125 #define STORAGE_SIZE 4 //Each long is 4 bytes so limit this to fit on your micro
zinnetyazicii53 0:83277b73a1f8 126 typedef struct Record
zinnetyazicii53 0:83277b73a1f8 127 {
zinnetyazicii53 0:83277b73a1f8 128 uint32_t red[STORAGE_SIZE];
zinnetyazicii53 0:83277b73a1f8 129 uint32_t IR[STORAGE_SIZE];
zinnetyazicii53 0:83277b73a1f8 130 uint32_t green[STORAGE_SIZE];
zinnetyazicii53 0:83277b73a1f8 131 byte head;
zinnetyazicii53 0:83277b73a1f8 132 byte tail;
zinnetyazicii53 0:83277b73a1f8 133 } sense_struct; //This is our circular buffer of readings from the sensor
zinnetyazicii53 0:83277b73a1f8 134
zinnetyazicii53 0:83277b73a1f8 135 sense_struct sense;
zinnetyazicii53 0:83277b73a1f8 136
zinnetyazicii53 0:83277b73a1f8 137 };
zinnetyazicii53 0:83277b73a1f8 138 */