From 764fc7ef5e43b63a95420ab6162981eaa67be23f Mon Sep 17 00:00:00 2001 From: liucheng5 Date: Thu, 6 Jan 2022 14:47:53 +0800 Subject: [PATCH] fix: sensor: ppg of dual- and quad-channel sensor types Some PPG devices have 4 ADCs to output quad-channel PPG values while some of them only have 2 ADCs to output dual-channel PPG. To deal the case above, the type PPGD(PPG of Dual-channel) takes the place of former type PPG, which also have 2-channel PPG outputs. Type PPGQ (PPG of Quad-channel) is new for 4-ADC-PPG. Both types have contained new data "gain" to indicate ADC gains of each PPG channel, for the reason that the gains may vary during automatical optical adjustments. Signed-off-by: liucheng5 --- drivers/sensors/sensor.c | 3 +- include/nuttx/sensors/sensor.h | 50 ++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index cb3031bf3d..651f669251 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -126,7 +126,8 @@ static const struct sensor_info g_sensor_info[] = {sizeof(struct sensor_event_hrate), "hrate"}, {sizeof(struct sensor_event_hbeat), "hbeat"}, {sizeof(struct sensor_event_ecg), "ecg"}, - {sizeof(struct sensor_event_ppg), "ppg"}, + {sizeof(struct sensor_event_ppgd), "ppgd"}, + {sizeof(struct sensor_event_ppgq), "ppgq"}, {sizeof(struct sensor_event_impd), "impd"}, {sizeof(struct sensor_event_ots), "ots"}, {sizeof(struct sensor_event_gps_satellite), "gps_satellite"}, diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h index 54a55895ff..a526761d0c 100644 --- a/include/nuttx/sensors/sensor.h +++ b/include/nuttx/sensors/sensor.h @@ -226,17 +226,27 @@ #define SENSOR_TYPE_ECG 25 -/* PPG (Photoplethysmography) - * A sensor of this type returns the PPG measurements in counts. The PPG - * measurements come from photodiode and following current amplifiers, where - * the photodiode switches reflected light intensity to current. Here the PPG - * value means the ADC counts, since the LED lightness, the photodiode model, - * the reflect-ratio, and the integration time of ADC varies with different - * measurements, while the useful information of PPG is the not the magnitude - * but the shape of the waveform. +/* PPG Dual (2-channel photoplethysmography) + * A sensor of this type returns the 2 channels PPG measurements in ADC + * counts and their corresponding LED current and ADC gains. The PPG + * measurements come from photodiodes and following current amplifiers and + * ADCs, where a photodiode switches reflected light intensity to current. + * The LED current decides the lightness of LED, which is the input of PPG + * measurements. The ADC gains are multipled on the output and affect SNR. */ -#define SENSOR_TYPE_PPG 26 +#define SENSOR_TYPE_PPGD 26 + +/* PPG Quad (4-channel photoplethysmography) + * A sensor of this type returns the 4 channels PPG measurements in ADC + * counts and their corresponding LED current and ADC gains. The PPG + * measurements come from photodiodes and following current amplifiers and + * ADCs, where a photodiode switches reflected light intensity to current. + * The LED current decides the lightness of LED, which is the input of PPG + * measurements. The ADC gains are multipled on the output and affect SNR. + */ + +#define SENSOR_TYPE_PPGQ 27 /* Imdepance * A sensor of this type returns the impedance measurements. An impedance @@ -244,7 +254,7 @@ * imaginary part(reactance). Both of them are in uint Ohm(Ω). */ -#define SENSOR_TYPE_IMPEDANCE 27 +#define SENSOR_TYPE_IMPEDANCE 28 /* OTS (Optical tracking sensor) * A sensor of this type returns the OTS measurements in counts. It @@ -253,17 +263,17 @@ * design flexibility into a compact device. */ -#define SENSOR_TYPE_OTS 28 +#define SENSOR_TYPE_OTS 29 /* Sensor of gps satellite * A sensor of this type returns the gps satellite information. */ -#define SENSOR_TYPE_GPS_SATELLITE 29 +#define SENSOR_TYPE_GPS_SATELLITE 30 /* The total number of sensor */ -#define SENSOR_TYPE_COUNT 30 +#define SENSOR_TYPE_COUNT 31 /**************************************************************************** * Inline Functions @@ -480,10 +490,20 @@ struct sensor_event_ecg /* Type: ECG */ float ecg; /* Unit is μV */ }; -struct sensor_event_ppg /* Type: PPG */ +struct sensor_event_ppgd /* Type: PPGD */ { uint64_t timestamp; /* Unit is microseconds */ - uint32_t ppg; /* Unit is ADC counts */ + uint32_t ppg[2]; /* PPG from 2 channels. Units are ADC counts. */ + uint32_t current; /* LED current. Unit is uA. */ + uint16_t gain[2]; /* ADC gains of channels. Units are V/V or V/A. */ +}; + +struct sensor_event_ppgq /* Type: PPDQ */ +{ + uint64_t timestamp; /* Unit is microseconds */ + uint32_t ppg[4]; /* PPG from 4 channels. Units are ADC counts. */ + uint32_t current; /* LED current. Unit is uA. */ + uint16_t gain[4]; /* ADC gains of channels. Units are V/V or V/A. */ }; struct sensor_event_impd /* Type: Impedance */