|
fsp_err_t | RM_OB1203_Open (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_cfg_t const *const p_cfg) |
| Opens and configures the OB1203 Middle module. Implements rm_ob1203_api_t::open. More...
|
|
fsp_err_t | RM_OB1203_Close (rm_ob1203_ctrl_t *const p_api_ctrl) |
| Disables specified OB1203 control block. Implements rm_ob1203_api_t::close. More...
|
|
fsp_err_t | RM_OB1203_MeasurementStart (rm_ob1203_ctrl_t *const p_api_ctrl) |
| Start measurement. Implements rm_ob1203_api_t::measurementStart. More...
|
|
fsp_err_t | RM_OB1203_MeasurementStop (rm_ob1203_ctrl_t *const p_api_ctrl) |
| Stop measurement. If device interrupt is enabled, interrupt bits are cleared after measurement stop. If PPG mode, FIFO information is also reset after measurement stop. In RTOS and Light/Proximity/Light Proximity mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. In RTOS and PPG mode, if device interrupt is enabled, blocks 6 bytes on the I2C bus. If device interrupt is disabled, blocks 4 bytes on the I2C bus. Implements rm_ob1203_api_t::measurementStop. More...
|
|
fsp_err_t | RM_OB1203_LightRead (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_raw_data_t *const p_raw_data, rm_ob1203_light_data_type_t type) |
| Reads Light ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. In RTOS and Light mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. Implements rm_ob1203_api_t::lightRead. More...
|
|
fsp_err_t | RM_OB1203_LightDataCalculate (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_raw_data_t *const p_raw_data, rm_ob1203_light_data_t *const p_ob1203_data) |
| Calculate light data from raw data. Implements rm_ob1203_api_t::lightDataCalculate. More...
|
|
fsp_err_t | RM_OB1203_ProxRead (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_raw_data_t *const p_raw_data) |
| Reads Proximity ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. In RTOS and Proximity mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. Implements rm_ob1203_api_t::proxRead. More...
|
|
fsp_err_t | RM_OB1203_ProxDataCalculate (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_raw_data_t *const p_raw_data, rm_ob1203_prox_data_t *const p_ob1203_data) |
| Calculate proximity data from raw data. Implements rm_ob1203_api_t::proxDataCalculate. More...
|
|
fsp_err_t | RM_OB1203_PpgRead (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_raw_data_t *const p_raw_data, uint8_t const number_of_samples) |
| Reads PPG ADC data from OB1203 device. One sample requires three bytes. 0 cannot set to the number of samples. Implements rm_ob1203_api_t::ppgRead. More...
|
|
fsp_err_t | RM_OB1203_PpgDataCalculate (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_raw_data_t *const p_raw_data, rm_ob1203_ppg_data_t *const p_ob1203_data) |
| Calculate PPG data from raw data. Implements rm_ob1203_api_t::ppgDataCalculate. More...
|
|
fsp_err_t | RM_OB1203_GainSet (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_gain_t const gain) |
| Set gain. This function should be called after calling RM_OB1203_MeasurementStop(). In RTOS and Light Proximity mode, blocks 2 bytes on the I2C bus. Implements rm_ob1203_api_t::gainSet. More...
|
|
fsp_err_t | RM_OB1203_LedCurrentSet (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_led_current_t const led_current) |
| Set currents. This function should be called after calling RM_OB1203_MeasurementStop(). Implements rm_ob1203_api_t::ledCurrentSet. More...
|
|
fsp_err_t | RM_OB1203_DeviceInterruptCfgSet (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_device_interrupt_cfg_t const interrupt_cfg) |
| Set device interrupt configurations. This function should be called after calling RM_OB1203_MeasurementStop(). Implements rm_ob1203_api_t::deviceInterruptCfgSet. More...
|
|
fsp_err_t | RM_OB1203_FifoInfoGet (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_fifo_info_t *const p_fifo_info) |
| Get FIFO information from OB1203 device. Implements rm_ob1203_api_t::fifoInfoGet. More...
|
|
fsp_err_t | RM_OB1203_DeviceStatusGet (rm_ob1203_ctrl_t *const p_api_ctrl, rm_ob1203_device_status_t *const p_status) |
| Get device status from OB1203 device. Clear all interrupt bits. Implements rm_ob1203_api_t::deviceStatusGet. More...
|
|
Middleware to implement the OB1203 sensor interface. This module implements the OB1203 Middleware Interface.
Overview
OB1203 is EOL.
This module provides APIs for configuring and controlling the OB1203 sensor operation modes. Supported OB1203 sensor operation modes are below.
- Light mode
- Proximity mode
- Light Proximity mode
- PPG mode
Features
The OB1203 sensor interface implementation has the following key features:
- Initialize the sensor for measurement
- Start and stop a measurement at any time
- Get the ADC data from the sensor
- Calculate the Light/Proximity/PPG values.
- Software reset
Configuration
Build Time Configurations for rm_ob1203
The following build time configurations are defined in fsp_cfg/rm_ob1203_cfg.h:
Configuration | Options | Default | Description |
Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Configurations for Sensor > OB1203 Light/Proximity/PPG Sensor (rm_ob1203) [Deprecated]
This module can be added to the Stacks tab via New Stack > Sensor > OB1203 Light/Proximity/PPG Sensor (rm_ob1203) [Deprecated].
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_ob1203_sensor0 | Module name. |
Semaphore Timeout (RTOS only) | Value must be a non-negative integer | 0xFFFFFFFF | Set timeout for blocking in using RTOS. |
Comms I2C Callback | Name must be a valid C symbol | ob1203_comms_i2c_callback | A user COMMS I2C callback function can be provided. |
IRQ Callback | Name must be a valid C symbol | ob1203_irq_callback | A user IRQ callback function can be provided. |
Configurations for Sensor > OB1203 Light mode (rm_ob1203)
Configuration | Options | Default | Description |
Operation Mode |
| LS mode | Set operation mode. |
Interrupt Type |
| Threshold | Set interrupt type. |
Interrupt Source |
-
Clear channel
-
Green channel
-
Red channel (CS mode only)
-
Blue channel (CS mode only)
| Clear channel | Set interrupt source. |
The Number of Similar Consecutive Interrupt Events | Value must be a non-negative integer | 0x02 | The number of similar consecutive Light mode interrupt events that must occur before the interrupt is asserted (4bits). Min = 0x0 and Max = 0xF |
Sleep after Interrupt |
| Disabled | Set sleep after interrupt. |
Gain |
| 3 | Set gain for detection range. |
Resolution and Measurement Period | Refer to the RA Configuration tool for available options. | Resolution:18bit. Measurement Period:100ms | Set resolution and measurement period. |
Upper Threshold | Value must be a non-negative integer | 0x00CCC | Set upper threshold value (20bits). Min = 0x00000 and Max = 0xFFFFF. |
Lower Threshold | Value must be a non-negative integer | 0x00000 | Set lower threshold value (20bits). Min = 0x00000 and Max = 0xFFFFF. |
Variance Threshold |
-
+/- 8 counts
-
+/- 16 counts
-
+/- 32 counts
-
+/- 64 counts
-
+/- 128 counts
-
+/- 256 counts
-
+/- 512 counts
-
+/- 1024 counts
| +/- 128 counts | Set variance threshold. New data varies by selected counts compared to previous result. |
Configurations for Sensor > OB1203 Proximity mode (rm_ob1203)
Configuration | Options | Default | Description |
Interrupt Type |
| Normal | Set interrupt type. |
The Number of Similar Consecutive Interrupt Events | Value must be a non-negative integer | 0x02 | The number of similar consecutive Proximity mode interrupt events that must occur before the interrupt is asserted (4bits). Min = 0x0 and Max = 0xF |
Sleep after Interrupt |
| Disabled | Set sleep after interrupt. |
Gain |
| 1 | Set gain of ADC output and noise. |
LED Current | Value must be a non-negative integer | 0x100 | Set Current for LED (10bits). Min = 0x000 and Max = 0x3FF |
LED Order |
-
IR LED first, Red LED second
-
Red LED first, IR LED second
| IR LED first, Red LED second | Set LED order. |
LED Analog Cancellation |
-
Enabled (50% offset of the full-scale value)
-
Disabled
| Disabled | Set analog cancellation level. |
LED Digital Cancellation | Value must be a non-negative integer | 0x100 | Set digital cancellation level (16bits). Min = 0x0000 and Max = 0xFFFF |
Number of LED pulses |
-
1 pulse
-
2 pulses
-
4 pulses
-
8 pulses
-
16 pulses
-
32 pulses
| 8 pulses | Set number of LED pulses. |
Pulse Width and Measurement Period | Refer to the RA Configuration tool for available options. | Pulse width:42us. Measurement Period:100ms | Set pulse width and measurement period. |
Moving Average |
| Disabled | Set moving average. |
Hysteresis | Value must be a non-negative integer | 0x00 | Set hysteresis level (7bits). Min = 0x00 and Max = 0x7F. |
Upper Threshold | Value must be a non-negative integer | 0x0600 | Set upper threshold value (16bits). Min = 0x0000 and Max = 0xFFFF. |
Lower Threshold | Value must be a non-negative integer | 0x0000 | Set lower threshold value (16bits). Min = 0x0000 and Max = 0xFFFF. |
Configurations for Sensor > OB1203 PPG mode (rm_ob1203)
Configuration | Options | Default | Description |
Operation Mode |
| PPG2 mode | Set operation mode. |
Interrupt Type |
| Data | Set interrupt type. |
Gain |
| 1 | Set gain of ADC output and noise. |
IR LED Current | Value must be a non-negative integer | 0x366 | Set Current for IR LED (10bits). Min = 0x000 and Max = 0x3FF |
Red LED Current | Value must be a non-negative integer | 0x1B3 | Set Current for Red LED (9bits). Min = 0x000 and Max = 0x1FF |
Power Save Mode |
| Disabled | Set power save mode. |
LED Order |
-
IR LED first, Red LED second
-
Red LED first, IR LED second
| IR LED first, Red LED second | Set LED order. |
IR LED Analog Cancellation |
-
Enabled (50% offset of the full-scale value)
-
Disabled
| Disabled | Set analog cancellation level. |
Red LED Analog Cancellation |
-
Enabled (50% offset of the full-scale value)
-
Disabled
| Disabled | Set analog cancellation level. |
Number of Averaged PPG Samples |
-
1 (No averaging)
-
2 consecutives samples are averaged
-
4 consecutives samples are averaged
-
8 consecutives samples are averaged
-
16 consecutives samples are averaged
-
32 consecutives samples are averaged
| 8 consecutives samples are averaged | Set number of averaged for PPG samples. |
Pulse Width and Measurement Period | Refer to the RA Configuration tool for available options. | Pulse width:130us. Measurement Period:1.25ms | Set pulse width and measurement period. |
FIFO Rollover |
| Enabled | Set FIFO rollover. |
FIFO Almost Full Value | Value must be a non-negative integer | 0x0C | Set the number of empty FIFO words when the FIFO almost full interrupt is issued (4bits). Min = 0x0 and Max = 0xF. In PPG2 Mode, only even values must be used. |
Configurations for Sensor > OB1203 Light Proximity mode (rm_ob1203)
Configuration | Options | Default | Description |
General |
Device Interrupt |
-
Light mode
-
Proximity mode
| Light mode | Select an operation mode using device interrupt. |
Light mode |
Operation Mode |
| LS mode | Set operation mode. |
Interrupt Type |
| Threshold | Set interrupt type. |
Interrupt Source |
-
Clear channel
-
Green channel
-
Red channel (CS mode only)
-
Blue channel (CS mode only)
| Clear channel | Set interrupt source. |
The Number of Similar Consecutive Interrupt Events | Value must be a non-negative integer | 0x02 | The number of similar consecutive Light mode interrupt events that must occur before the interrupt is asserted (4bits). Min = 0x0 and Max = 0xF |
Sleep after Interrupt |
| Disabled | Set sleep after interrupt. |
Gain |
| 3 | Set gain for detection range. |
Resolution and Measurement Period | Refer to the RA Configuration tool for available options. | Resolution:18bit. Measurement Period:100ms | Set resolution and measurement period. |
Upper Threshold | Value must be a non-negative integer | 0x00CCC | Set upper threshold value (20bits). Min = 0x00000 and Max = 0xFFFFF. |
Lower Threshold | Value must be a non-negative integer | 0x00000 | Set lower threshold value (20bits). Min = 0x00000 and Max = 0xFFFFF. |
Variance Threshold |
-
+/- 8 counts
-
+/- 16 counts
-
+/- 32 counts
-
+/- 64 counts
-
+/- 128 counts
-
+/- 256 counts
-
+/- 512 counts
-
+/- 1024 counts
| +/- 128 counts | Set variance threshold. New data varies by selected counts compared to previous result. |
Proximity mode |
Interrupt Type |
| Normal | Set interrupt type. |
The Number of Similar Consecutive Interrupt Events | Value must be a non-negative integer | 0x02 | The number of similar consecutive Proximity mode interrupt events that must occur before the interrupt is asserted (4bits). Min = 0x0 and Max = 0xF |
Sleep after Interrupt |
| Disabled | Set sleep after interrupt. |
Gain |
| 1 | Set gain of ADC output and noise. |
LED Current | Value must be a non-negative integer | 0x100 | Set Current for LED (10bits). Min = 0x000 and Max = 0x3FF |
LED Order |
-
IR LED first, Red LED second
-
Red LED first, IR LED second
| IR LED first, Red LED second | Set LED order. |
LED Analog Cancellation |
-
Enabled (50% offset of the full-scale value)
-
Disabled
| Disabled | Set analog cancellation level. |
LED Digital Cancellation | Value must be a non-negative integer | 0x100 | Set digital cancellation level (16bits). Min = 0x0000 and Max = 0xFFFF |
Number of LED pulses |
-
1 pulse
-
2 pulses
-
4 pulses
-
8 pulses
-
16 pulses
-
32 pulses
| 8 pulses | Set number of LED pulses. |
Pulse Width and Measurement Period | Refer to the RA Configuration tool for available options. | Pulse width:42us. Measurement Period:100ms | Set pulse width and measurement period. |
Moving Average |
| Disabled | Set moving average. |
Hysteresis | Value must be a non-negative integer | 0x00 | Set hysteresis level (7bits). Min = 0x00 and Max = 0x7F. |
Upper Threshold | Value must be a non-negative integer | 0x0600 | Set upper threshold value (16bits). Min = 0x0000 and Max = 0xFFFF. |
Lower Threshold | Value must be a non-negative integer | 0x0000 | Set lower threshold value (16bits). Min = 0x0000 and Max = 0xFFFF. |
Pin Configuration
This module uses I2C Master, SCI I2C and IRQ drivers. Therefore, this module uses SDA and SCL pins of I2C Master and SCI I2C and an IRQ pin.
Usage Notes
OB1203 datasheet is here.
The OB1203 has four operation modes.
Light mode
Light mode has two operation modes.
Operation mode | Red | Green | Blue | Clear | Comp *1 |
LS mode | | ✓ | | ✓ | ✓ |
CS mode | ✓ | ✓ | ✓ | ✓ | ✓ |
*1 : Temperature compensation data
Light mode features are below.
- High lux accuracy over different light sources
- Absolute sensitivity: 0.06 lux to > 150000 lux
- Output resolution: 13 to 20 bits
- Three LS/CS gain modes: x1 to x6
- Highly linear output, 50Hz/60Hz light and fluorescent light flicker immunity
- Four parallel channels (red, green, blue, clear)
- Accurate Correlated Color Temperature (CCT)
- Accurate CIE 1931 XYZ (RGB) color measurement
- Very stable spectral response over angle of light incidence
Proximity mode
Proximity mode features are below.
- Integrated and trimmed LED source, driver, and photodetector
- Programmable pulsed LED up to 250mA output current
- High resolution (12 to 16 bits)
- Object movement detection (in/out)
- Ambient light suppression > 100klx sun light
- Crosstalk cancelation (analog and digital)
PPG mode
PPG mode has two operation modes.
Operation mode | Discription |
PPG1 mode | Only one LED is used. This mode allows determination of parameters related to heart rate with an appropriate algorithm |
PPG2 mode | Two LED are used. Second LED is used as a transmitter. This mode supports further analysis, such as SpO2 and respiration rate determination. |
PPG mode features are below.
- SpO2 measurement behind visibly dark, IR transmissive ink
- Industry’s smallest optical biosensor module
- Fully integrated and trimmed module, including two LEDs, 250mA maximum drive current, and photodetectors
- Output resolution PPG: 16 to 18 bits
- Data stored in 18-bit wide, 32-sample FIFO memory
- Integrated averaging function for higher signal-to-noise ratio(SNR) and data rate reduction
- Programmable measurement rate: up to 3200 samples per second
- High SNR
Light Proximity mode
Light mode and Proximity mode can be used in parallel.
Bus Initialization
The OB1203 interface expects a bus instance to be opened before opening any OB1203 device. The interface will handle switching between devices on the bus but will not open or close the bus instance. The user should open the bus with the appropriate I2C Master Interface open call.
If an RTOS is used, blocking and bus lock for I2C bus are available.
- If blocking of an I2C bus is required, it is necessary to create a semaphore for blocking.
- If bus lock is required, it is necessary to create a mutex for bus lock. Bus lock is only available when a semaphore for blocking is used.
Initialization
Initialize with RM_OB1203_Open().
From measurement start to data acquisition
After normal completion, start the measurement with RM_OB1203_MeasurementStart().
Light mode
If IRQ is enabled
- Wait until RM_OB1203_EVENT_THRESHOLD_CROSSED is received via IRQ callback.
- Call RM_OB1203_LightRead(). This function will read the ADC data and clear the interrupt bits.
- Wait until RM_OB1203_EVENT_SUCCESS is received.
- Call RM_OB1203_LightDataCalculate(). This function will calculate light data from the ADC data.
If IRQ is disabled
- Wait for measurement period configured.
- Call RM_OB1203_LightRead(). This function will read the ADC data.
- Wait until RM_OB1203_EVENT_SUCCESS is received.
- Call RM_OB1203_LightDataCalculate(). This function will calculate light data from the ADC data.
Proximity mode
If IRQ is enabled
- Wait until RM_OB1203_EVENT_THRESHOLD_CROSSED or RM_OB1203_EVENT_OBJECT_NEAR is received via IRQ callback.
- Call RM_OB1203_ProxRead(). This function will read the ADC data and clear the interrupt bits.
- Wait until RM_OB1203_EVENT_SUCCESS is received.
- Call RM_OB1203_ProxDataCalculate(). This function will calculate proximity data from the ADC data.
If IRQ is disabled
- Wait for measurement period configured.
- Call RM_OB1203_ProxRead(). This function will read the ADC data.
- Wait until RM_OB1203_EVENT_SUCCESS is received.
- Call RM_OB1203_ProxDataCalculate(). This function will calculate proximity data from the ADC data.
PPG mode
If IRQ is enabled
- Wait until RM_OB1203_EVENT_MEASUREMENT_COMPLETE is received via IRQ callback.
- Call RM_OB1203_PpgRead(). This function will read the ADC data and clear the interrupt bits. In PPG2 mode, the number of read FIFO samples must be even value because two samples is one pair.
- Wait until RM_OB1203_EVENT_SUCCESS is received.
- Call RM_OB1203_PpgDataCalculate(). This function will calculate PPG data from the ADC data.
If IRQ is disabled
- Wait for measurement period configured.
- Call RM_OB1203_PpgRead(). This function will read the ADC data. In PPG2 mode, the number of read FIFO samples must be even value because two samples is one pair.
- Wait until RM_OB1203_EVENT_SUCCESS is received.
- Call RM_OB1203_PpgDataCalculate(). This function will calculate PPG data from the ADC data.
Light Proximity mode
Combination of the above Light mode and Proximity mode.
Getting device status
Call RM_OB1203_DeviceStatusGet(). This function will get device status over I2C.
- If power_on_reset_occur is true, the part has had a power-up event, either because the part was turned on or because there was a power-supply voltage disturbance.
- If light_interrupt_occur is true, Light mode interrupt condition has occurred.
- If light_measurement_complete is true, Light mode measurement is complete.
- If ts_measurement_complete is true, TS measurement is complete.
- If fifo_afull_interrupt_occur is true, FIFO almost full interrupt condition has occurred.
- If ppg_measurement_complete is true, PPG mode measurement is complete.
- If object_near is true, an object is near.
- If prox_interrupt_occur is true, Proximity mode interrupt condition has occurred.
- If prox_measurement_complete is true, Proximity mode measurement is complete.
Clearing interrupt bits
If interrupt bits are needed to clear without calling RM_OB1203_LightRead(), RM_OB1203_ProxRead(), RM_OB1203_PpgRead() and RM_OB1203_MeasurementStop(), please call RM_OB1203_DeviceStatusGet(). Interrupt bits are reset by STATUS_0 and STATUS_1 registers read.
Sleep after interrupt
Sleep after interrupt is valid in Light mode and Proximity mode. If a sleep after interrupt bit are set, a measurement will be stopped after an interrupt occurs. After STATUS_0 and STATUS_1 registers are read, a measurement will be started. please call RM_OB1203_DeviceStatusGet().
PPG FIFO
PPG FIFO data is stored in 18-bit wide, 32-sample FIFO memory.
The FIFO almost full interrupt is triggered when a certain number of free FIFO registers are remaining.
If FIFO informations (write index, read index, overflow counter, unread_samples) are got, Call RM_OB1203_FifoInfoGet().
- write_index is the FIFO index where the next sample of PPG data will be written in the FIFO.
- read_index is the index of the next sample to be read from the FIFO_DATA register.
- overflow_counter is the number of old samples (up to 15) which are overwritten by new data. If the FIFO Rollover is enabled, the FIFO overflow counter counts.
- unread_samples is the number of unread FIFO samples, which can be calculated by write index and read index.
Reconfiguration
The interface supports the following APIs for reconfiguration.
Relationship between APIs and registers
The relationship between APIs and registers accessed by the API is below.
API | Registers |
RM_OB1203_MeasurementStart() | MAIN_CTRL_0 and MAIN_CTRL_1 |
RM_OB1203_MeasurementStop() | MAIN_CTRL_0, MAIN_CTRL_1 , STATUS_0, STATUS_1, FIFO_WR_PTR, FIFO_RD_PTR and FIFO_OVF_CNT |
RM_OB1203_LightRead() | LS_CLEAR_DATA, LS_GREEN_DATA, LS_BULE_DATA, LS_RED_DATA, COMP_DATA, STATUS_0 and STATUS_1 |
RM_OB1203_ProxRead() | PS_DATA, STATUS_0 and STATUS_1 |
RM_OB1203_PpgRead() | FIFO_DATA |
RM_OB1203_DeviceStatusGet() | STATUS_0 and STATUS_1 |
RM_OB1203_GainSet() | LS_GAIN and PPG_PS_GAIN |
RM_OB1203_LedCurrentSet() | PS_LED_CURR, PPG_IRLED_CURR and PPG_RLED_CURR |
RM_OB1203_DeviceInterruptCfgSet() | INT_CFG_0, INT_CFG_1 and INT_PST |
RM_OB1203_FifoInfoGet() | FIFO_WR_PTR, FIFO_RD_PTR and FIFO_OVF_CNT |
Notifications
The application note [R01AN6311] using this module has an algorithm for biometric data calculation. The algorithm has the constraint of sampling rate (default: 100 samples per second). Please refer to the application note [R36AN0001EU] and OB1203 sensor page (https://www.renesas.com/jp/en/products/sensor-products/biosensors/ob1203-heart-rate-blood-oxygen-concentration-pulse-oximetry-proximity-light-and-color-sensor)
R01AN6311 : https://www.renesas.com/document/apn/ob1203-sample-application-sample-code
R36AN0001EU : https://www.renesas.com/document/apn/ob1203-pulse-oximeter-algorithm-spo2-heart-rate-and-respiration-rate
If multiple operation modes is used with a single OB1203 sensor device, rm_ob1203 modules need to be used while switching between operation modes because modules cannot work in parallel. Threfore, a current rm_ob1203 module must be closed with RM_OB1203_Close() before another rm_ob1203 module is opened with RM_OB1203_Open().
Examples
Basic Example
These are basic examples of minimal use of OB1203 sensor implementation in an application.
Light mode
void rm_ob1203_light_mode_basic_example (void)
{
#if 0 == RM_OB1203_EXAMPLE_IRQ_ENABLE
#endif
rm_comms_i2c_bus_extended_cfg_t * p_extend =
(rm_comms_i2c_bus_extended_cfg_t *) g_ob1203_cfg.p_comms_instance->p_cfg->p_extend;
p_driver_instance->
p_api->
open(p_driver_instance->p_ctrl, p_driver_instance->p_cfg);
#if BSP_CFG_RTOS
if (NULL != p_extend->p_blocking_semaphore)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_semaphore_create(p_extend->p_blocking_semaphore->p_semaphore_handle,
p_extend->p_blocking_semaphore->p_semaphore_name,
(ULONG) 0);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_blocking_semaphore->p_semaphore_handle) =
xSemaphoreCreateCountingStatic((UBaseType_t) 1,
(UBaseType_t) 0,
p_extend->p_blocking_semaphore->p_semaphore_memory);
#endif
}
if (NULL != p_extend->p_bus_recursive_mutex)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_mutex_create(p_extend->p_bus_recursive_mutex->p_mutex_handle,
p_extend->p_bus_recursive_mutex->p_mutex_name,
TX_INHERIT);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_bus_recursive_mutex->p_mutex_handle) =
xSemaphoreCreateRecursiveMutexStatic(p_extend->p_bus_recursive_mutex->p_mutex_memory);
#endif
}
#endif
handle_error(err);
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
while (true)
{
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
while (0 == g_irq_flag)
{
}
g_irq_flag = 0;
#else
do
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
} while (false == device_status.light_measurement_complete);
#endif
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
}
}
Proximity mode
void rm_ob1203_prox_mode_basic_example (void)
{
#if 0 == RM_OB1203_EXAMPLE_IRQ_ENABLE
#endif
rm_comms_i2c_bus_extended_cfg_t * p_extend =
(rm_comms_i2c_bus_extended_cfg_t *) g_ob1203_cfg.p_comms_instance->p_cfg->p_extend;
p_driver_instance->
p_api->
open(p_driver_instance->p_ctrl, p_driver_instance->p_cfg);
#if BSP_CFG_RTOS
if (NULL != p_extend->p_blocking_semaphore)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_semaphore_create(p_extend->p_blocking_semaphore->p_semaphore_handle,
p_extend->p_blocking_semaphore->p_semaphore_name,
(ULONG) 0);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_blocking_semaphore->p_semaphore_handle) =
xSemaphoreCreateCountingStatic((UBaseType_t) 1,
(UBaseType_t) 0,
p_extend->p_blocking_semaphore->p_semaphore_memory);
#endif
}
if (NULL != p_extend->p_bus_recursive_mutex)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_mutex_create(p_extend->p_bus_recursive_mutex->p_mutex_handle,
p_extend->p_bus_recursive_mutex->p_mutex_name,
TX_INHERIT);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_bus_recursive_mutex->p_mutex_handle) =
xSemaphoreCreateRecursiveMutexStatic(p_extend->p_bus_recursive_mutex->p_mutex_memory);
#endif
}
#endif
handle_error(err);
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
while (true)
{
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
while (0 == g_irq_flag)
{
}
g_irq_flag = 0;
#else
do
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
} while (false == device_status.prox_measurement_complete);
#endif
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
}
}
Light Proximity mode
void rm_ob1203_light_prox_mode_basic_example (void)
{
#if 0 == RM_OB1203_EXAMPLE_IRQ_ENABLE
#endif
rm_comms_i2c_bus_extended_cfg_t * p_extend =
(rm_comms_i2c_bus_extended_cfg_t *) g_ob1203_cfg.p_comms_instance->p_cfg->p_extend;
p_driver_instance->
p_api->
open(p_driver_instance->p_ctrl, p_driver_instance->p_cfg);
#if BSP_CFG_RTOS
if (NULL != p_extend->p_blocking_semaphore)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_semaphore_create(p_extend->p_blocking_semaphore->p_semaphore_handle,
p_extend->p_blocking_semaphore->p_semaphore_name,
(ULONG) 0);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_blocking_semaphore->p_semaphore_handle) =
xSemaphoreCreateCountingStatic((UBaseType_t) 1,
(UBaseType_t) 0,
p_extend->p_blocking_semaphore->p_semaphore_memory);
#endif
}
if (NULL != p_extend->p_bus_recursive_mutex)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_mutex_create(p_extend->p_bus_recursive_mutex->p_mutex_handle,
p_extend->p_bus_recursive_mutex->p_mutex_name,
TX_INHERIT);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_bus_recursive_mutex->p_mutex_handle) =
xSemaphoreCreateRecursiveMutexStatic(p_extend->p_bus_recursive_mutex->p_mutex_memory);
#endif
}
#endif
handle_error(err);
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
while (true)
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
while (0 == g_irq_flag)
{
}
g_irq_flag = 0;
#else
do
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
} while (false == device_status.prox_measurement_complete);
#endif
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
}
}
PPG mode
void rm_ob1203_ppg_mode_basic_example (void)
{
#if 0 == RM_OB1203_EXAMPLE_IRQ_ENABLE
#endif
rm_comms_i2c_bus_extended_cfg_t * p_extend =
(rm_comms_i2c_bus_extended_cfg_t *) g_ob1203_cfg.p_comms_instance->p_cfg->p_extend;
p_driver_instance->
p_api->
open(p_driver_instance->p_ctrl, p_driver_instance->p_cfg);
#if BSP_CFG_RTOS
if (NULL != p_extend->p_blocking_semaphore)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_semaphore_create(p_extend->p_blocking_semaphore->p_semaphore_handle,
p_extend->p_blocking_semaphore->p_semaphore_name,
(ULONG) 0);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_blocking_semaphore->p_semaphore_handle) =
xSemaphoreCreateCountingStatic((UBaseType_t) 1,
(UBaseType_t) 0,
p_extend->p_blocking_semaphore->p_semaphore_memory);
#endif
}
if (NULL != p_extend->p_bus_recursive_mutex)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_mutex_create(p_extend->p_bus_recursive_mutex->p_mutex_handle,
p_extend->p_bus_recursive_mutex->p_mutex_name,
TX_INHERIT);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_bus_recursive_mutex->p_mutex_handle) =
xSemaphoreCreateRecursiveMutexStatic(p_extend->p_bus_recursive_mutex->p_mutex_memory);
#endif
}
#endif
handle_error(err);
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
while (true)
{
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
while (0 == g_irq_flag)
{
}
g_irq_flag = 0;
#else
do
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
} while (false == device_status.ppg_measurement_complete);
#endif
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
}
}
Light mode reconfiguration at runtime
void rm_ob1203_light_reconfiguration_basic_example (void)
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
{
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
{
.persist = 0x02,
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#endif
while (0 == g_i2c_flag)
{
}
}
Proximity mode reconfiguration at runtime
void rm_ob1203_prox_reconfiguration_basic_example (void)
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
{
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
{
.
ir_led = RM_OB1203_EXAMPLE_IR_CURRENT_0X366,
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
{
.persist = 0x02,
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#endif
while (0 == g_i2c_flag)
{
}
}
Light Proximity mode reconfiguration at runtime
void rm_ob1203_light_prox_reconfiguration_basic_example (void)
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
{
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
{
.
ir_led = RM_OB1203_EXAMPLE_IR_CURRENT_0X366,
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
{
.persist = 0x02,
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#endif
while (0 == g_i2c_flag)
{
}
}
PPG mode reconfiguration at runtime
void rm_ob1203_ppg_reconfiguration_basic_example (void)
{
g_i2c_flag = 0;
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
{
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
{
.
ir_led = RM_OB1203_EXAMPLE_IR_CURRENT_0X366,
.red_led = RM_OB1203_EXAMPLE_RED_CURRENT_0X1B3,
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#if RM_OB1203_EXAMPLE_IRQ_ENABLE
{
};
while (0 == g_i2c_flag)
{
}
g_i2c_flag = 0;
#endif
while (0 == g_i2c_flag)
{
}
}
◆ rm_ob1203_init_process_params_t
struct rm_ob1203_init_process_params_t |
OB1203 initialization process block
Data Fields |
volatile bool |
communication_finished |
Communication flag for blocking. |
volatile rm_ob1203_event_t |
event |
Callback event. |
◆ rm_ob1203_mode_extended_cfg_t
struct rm_ob1203_mode_extended_cfg_t |
OB1203 mode extended configuration
◆ rm_ob1203_instance_ctrl_t
struct rm_ob1203_instance_ctrl_t |
◆ RM_OB1203_Open()
Opens and configures the OB1203 Middle module. Implements rm_ob1203_api_t::open.
Example:
- Return values
-
FSP_SUCCESS | OB1203 successfully configured. |
FSP_ERR_ASSERTION | Null pointer, or one or more configuration options is invalid. |
FSP_ERR_ALREADY_OPEN | Module is already open. This module can only be opened once. |
FSP_ERR_TIMEOUT | Communication is timeout. |
FSP_ERR_ABORTED | Communication is aborted. |
◆ RM_OB1203_Close()
Disables specified OB1203 control block. Implements rm_ob1203_api_t::close.
- Return values
-
FSP_SUCCESS | Successfully closed. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not open. |
◆ RM_OB1203_MeasurementStart()
Start measurement. Implements rm_ob1203_api_t::measurementStart.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_MeasurementStop()
Stop measurement. If device interrupt is enabled, interrupt bits are cleared after measurement stop. If PPG mode, FIFO information is also reset after measurement stop. In RTOS and Light/Proximity/Light Proximity mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. In RTOS and PPG mode, if device interrupt is enabled, blocks 6 bytes on the I2C bus. If device interrupt is disabled, blocks 4 bytes on the I2C bus. Implements rm_ob1203_api_t::measurementStop.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_LightRead()
Reads Light ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. In RTOS and Light mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. Implements rm_ob1203_api_t::lightRead.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_LightDataCalculate()
Calculate light data from raw data. Implements rm_ob1203_api_t::lightDataCalculate.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_ProxRead()
Reads Proximity ADC data from OB1203 device. If device interrupt is enabled, interrupt bits are cleared after data read. In RTOS and Proximity mode, if device interrupt is enabled, blocks 2 bytes on the I2C bus. Implements rm_ob1203_api_t::proxRead.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_ProxDataCalculate()
Calculate proximity data from raw data. Implements rm_ob1203_api_t::proxDataCalculate.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_PpgRead()
Reads PPG ADC data from OB1203 device. One sample requires three bytes. 0 cannot set to the number of samples. Implements rm_ob1203_api_t::ppgRead.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_PpgDataCalculate()
Calculate PPG data from raw data. Implements rm_ob1203_api_t::ppgDataCalculate.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_GainSet()
Set gain. This function should be called after calling RM_OB1203_MeasurementStop(). In RTOS and Light Proximity mode, blocks 2 bytes on the I2C bus. Implements rm_ob1203_api_t::gainSet.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_LedCurrentSet()
Set currents. This function should be called after calling RM_OB1203_MeasurementStop(). Implements rm_ob1203_api_t::ledCurrentSet.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_DeviceInterruptCfgSet()
◆ RM_OB1203_FifoInfoGet()
Get FIFO information from OB1203 device. Implements rm_ob1203_api_t::fifoInfoGet.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
◆ RM_OB1203_DeviceStatusGet()
Get device status from OB1203 device. Clear all interrupt bits. Implements rm_ob1203_api_t::deviceStatusGet.
- Return values
-
FSP_SUCCESS | Successfully results are read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not opened configured. |
FSP_ERR_TIMEOUT | Communication is timeout. |
FSP_ERR_ABORTED | Communication is aborted. |