OB1203 basic mbed driver
Revision 25:ca9caacd0f9f, committed 2020-07-23
- Comitter:
- laserdad
- Date:
- Thu Jul 23 20:19:25 2020 +0000
- Parent:
- 19:a27b98998edf
- Commit message:
- removed manual trim and overwrite digital trim
Changed in this revision
OB1203.cpp | Show annotated file Show diff for this revision Revisions of this file |
OB1203.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r a27b98998edf -r ca9caacd0f9f OB1203.cpp --- a/OB1203.cpp Fri Oct 12 20:19:38 2018 +0000 +++ b/OB1203.cpp Thu Jul 23 20:19:25 2020 +0000 @@ -162,10 +162,17 @@ void OB1203::setPPGcurrent() { char writeData[4]; - writeData[0] = (char) (ir_current & 0x00FF); - writeData[1] = (char) ((ir_current & 0xFF00)>>8); - writeData[2] = (char) (r_current & 0x00FF); - writeData[3] = (char) ((r_current & 0xFF00)>>8); + if(led_flip == LED_FLIP_OFF) { + writeData[0] = (char) (ir_current & 0x00FF); + writeData[1] = (char) ((ir_current & 0xFF00)>>8); + writeData[2] = (char) (r_current & 0x00FF); + writeData[3] = (char) ((r_current & 0xFF00)>>8); + } else { + writeData[2] = (char) (ir_current & 0x00FF); + writeData[3] = (char) ((ir_current & 0xFF00)>>8); + writeData[0] = (char) (r_current & 0x00FF); + writeData[1] = (char) ((r_current & 0xFF00)>>8); + } writeBlock(OB1203_ADDR,REG_PPG_IRLED_CURR,writeData,4); } @@ -207,6 +214,14 @@ writeBlock(OB1203_ADDR, REG_LED_TRIM,writeData,1); } +void OB1203::setDigTrim() +{ + char writeData[2]; + writeData[0] = led1_trim; + writeData[1] = led2_trim; + writeBlock(OB1203_ADDR, REG_DIG_LED1_TRIM,writeData,2); +} + void OB1203::setDigitalCan() { char writeData[2]; @@ -278,7 +293,7 @@ ls_en = LS_OFF; ppg_ps_en = 1; ppg_ps_mode = PS_MODE; - setLEDTrim(); + //setLEDTrim(); setMainConfig(); } @@ -304,7 +319,7 @@ ls_en = LS_ON; ppg_ps_en = PPG_PS_ON; ppg_ps_mode = PS_MODE; - setLEDTrim(); + //setLEDTrim(); setMainConfig(); } @@ -324,8 +339,9 @@ setPPGavg_and_rate(); setFifoConfig(); ppg_ps_mode = HR_MODE; - setBioTrim(); - setLEDTrim(); + //setBioTrim(); + //setLEDTrim(); + setDigTrim(); setMainConfig(); } @@ -344,8 +360,9 @@ setPPGavg_and_rate(); setFifoConfig(); ppg_ps_mode = SPO2_MODE; - setLEDTrim(); - setBioTrim(); + //setLEDTrim(); + setDigTrim(); + //setBioTrim(); setMainConfig(); } @@ -431,14 +448,22 @@ } -uint8_t OB1203::getNumFifoSamplesAvailable() +void OB1203::getNumFifoSamplesAvailable(char *fifo_info, char *sample_info) { + /*sample_info [3] = {numSamplesHR, numSamplesSpO2, overflow*/ + + getFifoInfo(fifo_info); + uint8_t writePointer = fifo_info[0]; + uint8_t readPointer = fifo_info [1]; uint8_t numSamples = writePointer; if (writePointer<readPointer) { - numSamples += 31-readPointer; + numSamples += 32; } - return numSamples; + numSamples -= readPointer; + sample_info[0] = numSamples; //num HR samples + sample_info[1] = (numSamples>>1); //num SpO2 samples + sample_info[2] = fifo_info[2]; } @@ -470,7 +495,14 @@ const uint32_t tol2 = TOL2; const uint16_t in_range_persist = IN_RANGE_PERSIST; static uint16_t in_range[2] = {0,0}; - const uint16_t maxCurrent[2] = {IR_MAX_CURRENT , R_MAX_CURRENT}; + uint16_t maxCurrent[2]; + if(led_flip == LED_FLIP_OFF) { + maxCurrent[0] = IR_MAX_CURRENT; + maxCurrent[1] = R_MAX_CURRENT; + } else { + maxCurrent[0] = R_MAX_CURRENT; + maxCurrent[1] = IR_MAX_CURRENT; + } const uint16_t step = STEP; const uint32_t targetCounts[2] = {IR_TARGET_COUNTS, R_TARGET_COUNTS}; //ch = 0 for IR, 1 for R (channel)
diff -r a27b98998edf -r ca9caacd0f9f OB1203.h --- a/OB1203.h Fri Oct 12 20:19:38 2018 +0000 +++ b/OB1203.h Thu Jul 23 20:19:25 2020 +0000 @@ -52,7 +52,8 @@ #define REG_OSC_TRIM 0x3E #define REG_LED_TRIM 0x3F #define REG_BIO_TRIM 0x40 - +#define REG_DIG_LED1_TRIM 0x42 +#define REG_DIG_LED2_TRIM 0x43 //Define settings //STATUS_0 @@ -164,8 +165,8 @@ #define PPG_AVG(x) (x & 0x07)<<4 //PPG_PWIDTH_RATE #define PPG_PWIDTH(x) (x & 0x07)<<4 -#define PPG_FREQ_60HZ 0 -#define PPG_FREQ_50HZ 1<<3 +#define PPG_FREQ_PREPRODUCTION 0 +#define PPG_FREQ_PRODUCTION 1 #define PPG_RATE(x) (x & 0x07) //FIFO_CFG #define FIFO_ROLL_ON 1<<4 @@ -220,8 +221,8 @@ uint16_t ps_thres_hi; uint16_t ps_thres_lo; uint16_t ps_current; - uint16_t ir_current; - uint16_t r_current; + volatile uint16_t ir_current; + volatile uint16_t r_current; char ppg_ps_gain; char ppg_pow_save; char led_flip; @@ -249,6 +250,8 @@ char diff; char alc; char sig_out; + char led1_trim; + char led2_trim; OB1203 (I2C *); @@ -291,11 +294,11 @@ void init_hr(); void init_spo2(); void getFifoInfo(char *fifo_info); - uint8_t getNumFifoSamplesAvailable(); + void getNumFifoSamplesAvailable(char *fifo_info, char *sample_info); void getFifoSamples(uint8_t, char *); void parseFifoSamples(char, char *, uint32_t *); char get_part_ID(char *); - + void setDigTrim(void); //agc functions void do_agc(uint32_t,bool);