Library for MAX30101, read/write functions for registers implemented.

Dependents:   test_MAX30101 testSensor

Revision:
0:4ad9373787e8
Child:
1:fc677d82d0f1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX30101.cpp	Tue Dec 29 06:25:58 2015 +0000
@@ -0,0 +1,69 @@
+/**
+ * MAX30101
+ * High-Sensitivity Pulse Oximeter and
+ * Heart-Rate Sensor for Wearable Health
+ */
+#include "mbed.h"
+#include "MAX30101.h"
+
+/* Status */
+#define REG_INT_MSB        0x00 /* Interrupt Status 1 */
+#define REG_INT_LSB        0x01 /* Interrupt Status 2 */
+#define REG_INT_ENB_MSB    0x02 /* Interrupt Enable 1 */
+#define REG_INT_ENB_LSB    0x03 /* Interrupt Enable 2 */
+/* FIFO */
+#define REG_FIFO_WR_PTR    0x04 /* FIFO Write Pointer */
+#define REG_OVF_COUNTER    0x05 /* Overflow Counter */
+#define REG_FIFO_RD_PTR    0x06 /* FIFO Read Pointer */
+#define REG_FIFO_DATA      0x07 /* FIFO Data Register */
+/* Configuration */
+#define REG_FIFO_CONFIG    0x08 /* FIFO Configuration */
+#define REG_MODE_CONFIG    0x09 /* Mode Configuration */
+#define REG_SPO2_CONFIG    0x0A /* SpO2 Configuration */
+/* reserved                0x0B */
+#define REG_LED1_PA        0x0C /* LED Pulse Amplitude 1 */
+#define REG_LED2_PA        0x0D /* LED Pulse Amplitude 2 */
+#define REG_LED3_PA        0x0E /* LED Pulse Amplitude 3 */
+/* reserved                0x0F */
+#define REG_PILOT_PA       0x10 /* Proximity LED Pulse Amplitude */
+#define REG_SLOT_MSB       0x11 /* Multi-LED Mode Control Registers 2, 1 */
+#define REG_SLOT_LSB       0x12 /* Multi-LED Mode Control Registers 4, 3 */
+/* DIE Temperature */
+#define REG_TEMP_INT       0x1F /* Die Temperature Integer */
+#define REG_TEMP_FRAC      0x20 /* Die Temperature Fraction */
+#define REG_TEMP_EN        0x21 /* Die Temperature Config */
+/* Proximity Function */
+#define REG_PROX_INT_THS   0x30 /* Proximity Interrupt Threshold */
+/* Part ID */
+#define REG_REV_ID         0xFE /* Revision ID */
+#define REG_PART_ID        0xFF /* Part ID: 0x15 */
+
+MAX30101::MAX30101(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr<<1) {
+    // activate the peripheral
+}
+
+MAX30101::~MAX30101() { }
+
+void MAX30101::readRegs(int addr, uint8_t * data, int len) {
+    char t[1] = {addr} ;
+    m_i2c.write(m_addr, t, 1, true) ;
+    m_i2c.read(m_addr, (char*)data, len) ;
+}
+
+void MAX30101::writeRegs(uint8_t * data, int len) {
+   m_i2c.write(m_addr, (char *)data, len) ;
+}
+
+uint8_t MAX30101::getID(void)
+{
+    uint8_t id ;
+    readRegs(REG_PART_ID, &id, 1) ;
+    return( id ) ;
+}
+
+uint8_t MAX30101::getRev(void)
+{
+    uint8_t rev ;
+    readRegs(REG_REV_ID, &rev, 1) ;
+    return( rev ) ;
+}
\ No newline at end of file