mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
add examples
This commit is contained in:
parent
265d41b6a3
commit
4128624f93
112 changed files with 158017 additions and 0 deletions
|
@ -0,0 +1,77 @@
|
|||
/*******************************************************************************
|
||||
HRM.h - Definition header
|
||||
*******************************************************************************/
|
||||
#ifndef HRM_H
|
||||
#define HRM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//------------------------------------------------------
|
||||
#define HR_SAMPLE_RATE 25// Hz
|
||||
#define HR_INTEG_MIN HR_INTEG_40
|
||||
#define HR_INTEG_BASE HR_INTEG_250
|
||||
#define HR_INTEG_MAX HR_INTEG_250
|
||||
|
||||
#define HR_TH_HIGH 63000
|
||||
#define HR_TH_LOW 30000
|
||||
//------------------------------------------------------
|
||||
|
||||
// HRM I2C address & register sub-addresses
|
||||
#define HR_SLAVE_ADDRESS 0x82
|
||||
|
||||
#define HR_FILTER_1 0<<5
|
||||
#define HR_FILTER_2 1<<5
|
||||
#define HR_FILTER_4 2<<5
|
||||
#define HR_FILTER_8 3<<5
|
||||
#define HR_FILTER_16 4<<5
|
||||
#define HR_FILTER_32 5<<5
|
||||
#define HR_FILTER_64 6<<5
|
||||
#define HR_FILTER_128 7<<5
|
||||
|
||||
#define HR_MODE_HR 1<<4
|
||||
#define HR_MODE_HRS 9<<4
|
||||
|
||||
#define HR_GAIN_MID 1
|
||||
#define HR_GAIN_LOW 3
|
||||
|
||||
#define HR_INTEG_20 5
|
||||
#define HR_INTEG_25 6
|
||||
#define HR_INTEG_30 7
|
||||
#define HR_INTEG_40 8
|
||||
#define HR_INTEG_55 9
|
||||
#define HR_INTEG_70 10
|
||||
#define HR_INTEG_90 11
|
||||
#define HR_INTEG_110 12
|
||||
#define HR_INTEG_150 13
|
||||
#define HR_INTEG_200 14
|
||||
#define HR_INTEG_250 15
|
||||
#define HR_INTEG_350 16
|
||||
#define HR_INTEG_450 17
|
||||
#define HR_INTEG_550 18
|
||||
|
||||
#define HR_OSR_64 0<<2
|
||||
#define HR_OSR_256 1<<2
|
||||
#define HR_OSR_1024 2<<2
|
||||
#define HR_OSR_2048 3<<2
|
||||
|
||||
#define HR_RESETN_RESET 0<<2
|
||||
#define HR_RESETN_RUN 1<<2
|
||||
|
||||
#define HR_PDRIVE_70MA 0<<4
|
||||
#define HR_PDRIVE_35MA 1<<4
|
||||
#define HR_PDRIVE_200MA 2<<4
|
||||
#define HR_PDRIVE_100MA 3<<4
|
||||
|
||||
#define HR_INT_FRAME 1<<2
|
||||
#define HR_INT_DISABLED 2<<2
|
||||
|
||||
#define HR_IR_DISABLE 0<<7
|
||||
#define HR_IR_ENABLE 1<<7
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
// Declarations
|
||||
void init_hrm(void);
|
||||
uint16_t read_hrm(void);
|
||||
|
||||
#endif /* HRM_H */
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* heart_interface.h
|
||||
*
|
||||
* Created on: 2014/4/29
|
||||
* Author: 01004
|
||||
*/
|
||||
|
||||
#ifndef HEART_INTERFACE_H_
|
||||
#define HEART_INTERFACE_H_
|
||||
|
||||
#define MIN_HEART_RATE 48
|
||||
#define MAX_HEART_RATE 180
|
||||
|
||||
extern int g_heartrate;
|
||||
|
||||
typedef void (*hr_callback)(int);
|
||||
|
||||
/*
|
||||
* If there is no g-sensor, fill x, y, z in 0.
|
||||
*/
|
||||
void add_PPG_XYZ(int ppg, short xx, short yy, short zz);
|
||||
|
||||
/*
|
||||
* A callback to handle heartrate events.
|
||||
*/
|
||||
void register_callback(hr_callback callback);
|
||||
|
||||
/*
|
||||
* Ex: report_period = 25.
|
||||
* it means report a heart rate every 25 samples.
|
||||
*/
|
||||
void start(int report_period);
|
||||
|
||||
void reset(void);
|
||||
|
||||
void stop(void);
|
||||
|
||||
|
||||
#endif /* HEART_INTERFACE_H_ */
|
|
@ -0,0 +1,16 @@
|
|||
Example Description
|
||||
|
||||
this example is use to measure heart rate of human
|
||||
|
||||
Requirement Components:
|
||||
extend board
|
||||
|
||||
work with arduino extended board, which has heart rate sensor
|
||||
|
||||
during the measurement, user has to lie his pulp on the sensor and do not rock the sensor
|
||||
|
||||
the test code will return back the heart rate
|
||||
|
||||
Build code
|
||||
1. Please be sure to copy inc\heart_interface.h, inc\HRM_2197.h
|
||||
2. Include hr_library.a in IAR project. Add hr_library.a into folder "lib" in IAR project.
|
165
RTL00_SDKV35a/example_sources/i2c_epl2197_heartrate/src/main.c
Normal file
165
RTL00_SDKV35a/example_sources/i2c_epl2197_heartrate/src/main.c
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*******************************************************************************
|
||||
* HRM.c - Eminent Heart Rate Module (HRM) routines via I2C
|
||||
*******************************************************************************/
|
||||
#include "HRM_2197.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
//#include <windows.h>
|
||||
#include "heart_interface.h"
|
||||
#include "device.h"
|
||||
#include "PinNames.h"
|
||||
|
||||
#include "basic_types.h"
|
||||
#include "diag.h"
|
||||
#include "osdep_api.h"
|
||||
|
||||
#include "i2c_api.h"
|
||||
#include "pinmap.h"
|
||||
//#include "rtl_lib.h"
|
||||
#include "gpio_api.h" // mbed
|
||||
#include "main.h"
|
||||
|
||||
#define MBED_I2C_SLAVE_ADDR0 0x41
|
||||
#define HR_MODE 0x001b
|
||||
#define LED_ENABLE 0x3081
|
||||
#define FRAME_ENABLE 0x4804
|
||||
#define CHIP_RESET 0x4000
|
||||
#define CHIP_RUN 0x4004
|
||||
#define DATA_LOCK 0x4005
|
||||
#define DATA_UNLOCK 0x4004
|
||||
#define I2C_DATA_MAX_LENGTH 20
|
||||
#define CLOCK_SET 0x3800
|
||||
#define MBED_I2C_MTR_SDA PB_3
|
||||
#define MBED_I2C_MTR_SCL PB_2
|
||||
#define MBED_I2C_INTB PA_5
|
||||
#define MBED_I2C_BUS_CLK 100000 //hz
|
||||
|
||||
uint8_t i2cdata_write[I2C_DATA_MAX_LENGTH];
|
||||
uint8_t i2cdata_read[I2C_DATA_MAX_LENGTH];
|
||||
uint16_t cmd;
|
||||
|
||||
i2c_t i2cmaster;
|
||||
|
||||
uint8_t integ_time = HR_INTEG_MIN;
|
||||
int integ_time_array[] = { 4, 6, 8, 10, 15, 20, 25, 30, 40, 55, 70, 90, 110, 150, 200, 250, 350, 450, 550 };
|
||||
|
||||
|
||||
|
||||
|
||||
//Step1. define the callback to handle event of heart rate update
|
||||
/*******************************************************************************
|
||||
* report heart rate every 1 second
|
||||
*******************************************************************************/
|
||||
void on_heartrate_update(int heartrate) {
|
||||
printf("heart rate %d\n", heartrate);
|
||||
//fflush(stdout);
|
||||
}
|
||||
|
||||
char i2cdatasrc[3] = {0x68, 0x90, 0x98};
|
||||
|
||||
|
||||
static void ePL_WriteCommand(uint16_t cmd)
|
||||
{
|
||||
i2cdata_write[0] = (uint8_t)(cmd >>8);
|
||||
i2cdata_write[1] = (uint8_t)(cmd&0xFF);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &i2cdata_write[0], 2, 1);
|
||||
}
|
||||
|
||||
uint16_t read_hrm(void) {
|
||||
uint32_t raw, normalized_raw;
|
||||
int integ_time_changed = 0;
|
||||
ePL_WriteCommand(DATA_LOCK);
|
||||
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &i2cdatasrc[1], 1, 1);
|
||||
i2c_read(&i2cmaster, MBED_I2C_SLAVE_ADDR0, (char*)&i2cdata_read[1], 2, 1);
|
||||
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &i2cdatasrc[2], 1, 1);
|
||||
i2c_read(&i2cmaster, MBED_I2C_SLAVE_ADDR0, (char*)&i2cdata_read[2], 2, 1);
|
||||
|
||||
raw = i2cdata_read[1];
|
||||
raw |= (uint16_t) i2cdata_read[2] << 8;
|
||||
|
||||
|
||||
normalized_raw = raw >> 4;
|
||||
normalized_raw = normalized_raw * integ_time_array[HR_INTEG_BASE];
|
||||
normalized_raw = normalized_raw / integ_time_array[integ_time];
|
||||
|
||||
if (raw > HR_TH_HIGH && integ_time > HR_INTEG_MIN) {
|
||||
integ_time -= 1;
|
||||
integ_time_changed = 1;
|
||||
} else if (raw < HR_TH_LOW && integ_time < HR_INTEG_MAX) {
|
||||
integ_time += 1;
|
||||
integ_time_changed = 1;
|
||||
}
|
||||
|
||||
if (integ_time_changed == 1) {
|
||||
|
||||
ePL_WriteCommand(((0x01<<3)<<8) | ( HR_FILTER_4 | integ_time));
|
||||
ePL_WriteCommand(((0x08<<3)<<8) | ( HR_RESETN_RESET));
|
||||
}
|
||||
|
||||
ePL_WriteCommand(((0x08<<3)<<8) | ( HR_RESETN_RUN));
|
||||
|
||||
return normalized_raw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* main function to read data, input to library,
|
||||
* and calculate heart rate
|
||||
*******************************************************************************/
|
||||
void main(void) {
|
||||
int i, length;
|
||||
int *data;
|
||||
int should_stop = 0;
|
||||
uint16_t result;
|
||||
data = (int*) calloc(3000, sizeof(int));
|
||||
//load_ppg_signal(data, &length); //Load Test Data From File
|
||||
i2c_init(&i2cmaster, MBED_I2C_MTR_SDA ,MBED_I2C_MTR_SCL);
|
||||
i2c_frequency(&i2cmaster,MBED_I2C_BUS_CLK);
|
||||
//Step2. delegate the event of heart rate update
|
||||
register_callback(on_heartrate_update);
|
||||
|
||||
|
||||
|
||||
|
||||
//Step3. Set the data length of heart rate calculation= 2^9 = 512
|
||||
|
||||
ePL_WriteCommand(((0x00<<3)<<8) | ( HR_MODE_HRS | HR_OSR_1024 | HR_GAIN_MID));
|
||||
ePL_WriteCommand(((0x01<<3)<<8) | ( HR_FILTER_4 | integ_time));
|
||||
ePL_WriteCommand(((0x09<<3)<<8) | ( HR_PDRIVE_70MA));
|
||||
ePL_WriteCommand(((0x06<<3)<<8) | ( HR_IR_ENABLE | HR_INT_FRAME));
|
||||
ePL_WriteCommand(((0x08<<3)<<8) | ( HR_RESETN_RESET));
|
||||
while(1) {
|
||||
//Step4. Add ppg data continuously, and the Lib will return the Heart Rate 1 time/sec
|
||||
result = read_hrm();
|
||||
|
||||
if(result>100)
|
||||
add_PPG_XYZ(result, 0, 0, 0);
|
||||
|
||||
Mdelay(40); //Simulate the ppg input time interval = 40ms
|
||||
if(should_stop)
|
||||
break;
|
||||
}
|
||||
|
||||
//Step5. Stop
|
||||
stop();
|
||||
|
||||
free(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* initialize ic parameters
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* read rawdata
|
||||
*******************************************************************************/
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue