MAXREFDES#117

Dependencies:   mbed USBDevice

Files at this revision

API Documentation at this revision

Comitter:
the_nabil
Date:
Mon Jan 27 11:27:41 2020 +0000
Parent:
4:5273ab1085ab
Commit message:
MAXREFDES#117

Changed in this revision

MAX30102/MAX30102.cpp Show annotated file Show diff for this revision Revisions of this file
MAX30102/MAX30102.h Show annotated file Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/MAX30102/MAX30102.cpp	Thu May 19 22:04:06 2016 +0000
+++ b/MAX30102/MAX30102.cpp	Mon Jan 27 11:27:41 2020 +0000
@@ -1,3 +1,6 @@
+
+
+
 /** \file max30102.cpp ******************************************************
 *
 * Project: MAXREFDES117#
@@ -58,13 +61,13 @@
 */
 #include "mbed.h"
 #include "MAX30102.h"
-
+ 
 #ifdef TARGET_MAX32600MBED
 I2C i2c(I2C1_SDA, I2C1_SCL);
 #else
 I2C i2c(I2C_SDA, I2C_SCL);
 #endif
-
+ 
 bool maxim_max30102_write_reg(uint8_t uch_addr, uint8_t uch_data)
 /**
 * \brief        Write a value to a MAX30102 register
@@ -86,7 +89,7 @@
   else
     return false;
 }
-
+ 
 bool maxim_max30102_read_reg(uint8_t uch_addr, uint8_t *puch_data)
 /**
 * \brief        Read a MAX30102 register
@@ -111,7 +114,7 @@
   else
     return false;
 }
-
+ 
 bool maxim_max30102_init()
 /**
 * \brief        Initialize the MAX30102
@@ -148,7 +151,7 @@
     return false;
   return true;  
 }
-
+ 
 bool maxim_max30102_read_fifo(uint32_t *pun_red_led, uint32_t *pun_ir_led)
 /**
 * \brief        Read a set of samples from the MAX30102 FIFO register
@@ -201,7 +204,7 @@
   
   return true;
 }
-
+ 
 bool maxim_max30102_reset()
 /**
 * \brief        Reset the MAX30102
@@ -218,3 +221,46 @@
     else
         return true;    
 }
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+uint8_t MAX30102_begin(uint8_t reg)
+{
+    char data;
+    char temp[1] = {reg};
+    i2c.write(I2C_WRITE_ADDR, temp , 1);
+    temp[1] = 0x00;
+    i2c.write(I2C_WRITE_ADDR, temp, 1);
+    int a = i2c.read(I2C_WRITE_ADDR, &data, 1);
+    return data;
+
+}
+ 
+int MAX30102_writeRegValue(uint8_t reg,  char value)
+{
+    char cmdData[2] = { (char)reg, value };
+ 
+    if (i2c.write(I2C_WRITE_ADDR, cmdData, sizeof(cmdData)) != 0) {
+        return MAX30102_ERROR;
+    }
+ 
+    return MAX30102_NO_ERROR;
+}           
\ No newline at end of file
--- a/MAX30102/MAX30102.h	Thu May 19 22:04:06 2016 +0000
+++ b/MAX30102/MAX30102.h	Mon Jan 27 11:27:41 2020 +0000
@@ -88,10 +88,16 @@
 #define REG_REV_ID 0xFE
 #define REG_PART_ID 0xFF
 
+
+#define MAX30102_NO_ERROR   0
+#define MAX30102_ERROR      -1
+
+int MAX30102_writeRegValue(uint8_t reg,  char value); 
+uint8_t MAX30102_begin(uint8_t reg);
 bool maxim_max30102_init();
 bool maxim_max30102_read_fifo(uint32_t *pun_red_led, uint32_t *pun_ir_led);
 bool maxim_max30102_write_reg(uint8_t uch_addr, uint8_t uch_data);
-bool maxim_max30102_read_reg(uint8_t uch_addr, uint8_t *puch_data);
+bool maxim_max30102_read_reg(uint8_t uch_addr, uint8_t puch_data);
 bool maxim_max30102_reset(void);
 
 #endif /* MAX30102_H_ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Mon Jan 27 11:27:41 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/USBDevice/#53949e6131f6
--- a/main.cpp	Thu May 19 22:04:06 2016 +0000
+++ b/main.cpp	Mon Jan 27 11:27:41 2020 +0000
@@ -74,6 +74,7 @@
 #include "mbed.h"
 #include "algorithm.h"
 #include "MAX30102.h"
+#include "USBSerial.h"
 
 #define MAX_BRIGHTNESS 255
 
@@ -86,7 +87,9 @@
 int8_t  ch_hr_valid;    //indicator to show if the heart rate calculation is valid
 uint8_t uch_dummy;
 
-Serial pc(USBTX, USBRX);    //initializes the serial port
+USBSerial pc;   //initializes the serial port
+
+/*
 #ifdef TARGET_KL25Z 
 PwmOut led(PTB18);  //initializes the pwm output that connects to the on board LED
 DigitalIn INT(PTD1);  //pin PTD1 connects to the interrupt output pin of the MAX30102
@@ -98,8 +101,10 @@
 PwmOut led(LED_RED);    //initializes the pwm output that connects to the on board LED
 DigitalIn INT(P2_0);  //pin P20 connects to the interrupt output pin of the MAX30102
 #endif
+*/
 
 // the setup routine runs once when you press reset:
+// the setup routine runs once when you press reset:
 int main() { 
     uint32_t un_min, un_max, un_prev_data;  //variables to calculate the on-board LED brightness that reflects the heartbeats
     int i;
@@ -108,21 +113,21 @@
     
     maxim_max30102_reset(); //resets the MAX30102
     // initialize serial communication at 115200 bits per second:
-    pc.baud(115200);
-    pc.format(8,SerialBase::None,1);
+    //pc.baud(115200);
+    //pc.format(8,SerialBase::None,1);
     wait(1);
     
     //read and clear status register
-    maxim_max30102_read_reg(0,&uch_dummy);
+    //maxim_max30102_read_reg(0,&uch_dummy);
     
     //wait until the user presses a key
-    while(pc.readable()==0)
-    {
-        pc.printf("\x1B[2J");  //clear terminal program screen
-        pc.printf("Press any key to start conversion\n\r");
-        wait(1);
-    }
-    uch_dummy=getchar();
+    //while(pc.readable()==0)
+    //{
+        //pc.printf("\x1B[2J");  //clear terminal program screen
+       // pc.printf("Press any key to start conversion\n\r");
+       // wait(1);
+    //}
+    //uch_dummy=getchar();
     
     maxim_max30102_init();  //initializes the MAX30102
         
@@ -136,7 +141,7 @@
     //read the first 500 samples, and determine the signal range
     for(i=0;i<n_ir_buffer_length;i++)
     {
-        while(INT.read()==1);   //wait until the interrupt pin asserts
+        //while(INT.read()==1);   //wait until the interrupt pin asserts
         
         maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));  //read from MAX30102 FIFO
             
@@ -179,7 +184,7 @@
         for(i=400;i<500;i++)
         {
             un_prev_data=aun_red_buffer[i-1];
-            while(INT.read()==1);
+            //while(INT.read()==1);
             maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));
         
             if(aun_red_buffer[i]>un_prev_data)
@@ -212,8 +217,10 @@
             pc.printf("HRvalid=%i, ", ch_hr_valid);
             pc.printf("SpO2=%i, ", n_sp02);
             pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid);
+            wait(1);
         }
         maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); 
     }
 }
- 
\ No newline at end of file
+ 
+            
\ No newline at end of file
--- a/mbed.bld	Thu May 19 22:04:06 2016 +0000
+++ b/mbed.bld	Mon Jan 27 11:27:41 2020 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file