Atmel Software Framework

sfh7770.h File Reference

Osram SFH7770 light & proximity sensor driver.

This file contains functions for initializing and reading data from a Osram SFH7770 light & proximity sensor.

Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.

#include <asf.h>

Macros

#define SFH7770_DATA_RESOLUTION   (16)
 
#define SFH7770_TWI_ADDR   (0x38)
 
#define SFH7770_ALS_CONTROL   (0x80) /* ambient light sensor control */
 SFH7770 Register Addresses. More...
 
#define SFH7770_PS_CONTROL   (0x81) /* proximity sensor control */
 
#define SFH7770_I_LED_1_2   (0x82) /* emitter current - LED1 & 2 */
 
#define SFH7770_I_LED_3   (0x83) /* emitter control reg 2 */
 
#define SFH7770_ALS_PS_TRIG   (0x84) /* measurement start (trigger mode) */
 
#define SFH7770_PS_INTERVAL   (0x85) /* proximity measurement interval */
 
#define SFH7770_ALS_INTERVAL   (0x86) /* light measurement interval */
 
#define SFH7770_PART_ID   (0x8A) /* part id & revision */
 
#define SFH7770_MAN_ID   (0x8B) /* manufacturer id */
 
#define SFH7770_ALS_DATA_LSB   (0x8C) /* light meas data (low 8 bits) */
 
#define SFH7770_ALS_DATA_MSB   (0x8D) /* light meas data (high 8 bits) */
 
#define SFH7770_ALS_PS_STATUS   (0x8E) /* light/prox measurement status */
 
#define SFH7770_PS_DATA_LED1   (0x8F) /* proximity meas data (LED1) */
 
#define SFH7770_PS_DATA_LED2   (0x90) /* proximity meas data (LED2) */
 
#define SFH7770_PS_DATA_LED3   (0x91) /* proximity meas data (LED3) */
 
#define SFH7770_INT_SET   (0x92) /* interrupt status/control */
 
#define SFH7770_PS_THR_LED1   (0x93) /* proximity threshold (LED1) */
 
#define SFH7770_PS_THR_LED2   (0x94) /* proximity threshold (LED2) */
 
#define SFH7770_PS_THR_LED3   (0x95) /* proximity threshold (LED3) */
 
#define SFH7770_ALS_UP_THR_LSB   (0x96) /* upper light threshold (lsb) */
 
#define SFH7770_ALS_UP_THR_MSB   (0x97) /* upper light threshold (msb) */
 
#define SFH7770_ALS_LO_THR_LSB   (0x98) /* lower light threshold (lsb) */
 
#define SFH7770_ALS_LO_THR_MSB   (0x99) /* lower light threshold (msb) */
 
#define ALS_MODE_MASK   (0x03) /* light sensor mode mask */
 SFH7770 Register Bit Definitions. More...
 
#define ALS_MODE_STANDBY   (0x00) /* standby mode (default) */
 
#define ALS_MODE_TRIGGERED   (0x02) /* triggered mode */
 
#define ALS_MODE_FREE_RUNNING   (0x03) /* free-running mode */
 
#define ALS_CONTROL_SW_RESET   (0x04) /* software reset */
 
#define PS_MODE_MASK   (0x03) /* proximity sensor mode mask */
 
#define PS_MODE_STANDBY   (0x00) /* standby mode (default) */
 
#define PS_MODE_TRIGGERED   (0x02) /* triggered mode */
 
#define PS_MODE_FREE_RUNNING   (0x03) /* free-running mode */
 
#define I_LED_5MA   (0x00) /* LED current = 5mA */
 
#define I_LED_10MA   (0x01) /* LED current = 10mA */
 
#define I_LED_20MA   (0x02) /* LED current = 20mA */
 
#define I_LED_50MA   (0x03) /* LED current = 50mA (default) */
 
#define I_LED_100MA   (0x04) /* LED current = 100mA */
 
#define I_LED_150MA   (0x05) /* LED current = 150mA */
 
#define I_LED_200MA   (0x06) /* LED current = 200mA */
 
#define I_LED2_SHIFT   (3) /* bit shift for LED2 field */
 
#define I_LED1_MASK   (0x07) /* LED1 pulse current mask */
 
#define I_LED1_5MA   (I_LED_5MA)
 
#define I_LED1_10MA   (I_LED_10MA)
 
#define I_LED1_20MA   (I_LED_20MA)
 
#define I_LED1_50MA   (I_LED_50MA)
 
#define I_LED1_100MA   (I_LED_100MA)
 
#define I_LED1_150MA   (I_LED_150MA)
 
#define I_LED1_200MA   (I_LED_200MA)
 
#define I_LED2_MASK   (0x38) /* LED2 pulse current mask */
 
#define I_LED2_5MA   (I_LED_5MA << I_LED2_SHIFT)
 
#define I_LED2_10MA   (I_LED_10MA << I_LED2_SHIFT)
 
#define I_LED2_20MA   (I_LED_20MA << I_LED2_SHIFT)
 
#define I_LED2_50MA   (I_LED_50MA << I_LED2_SHIFT)
 
#define I_LED2_100MA   (I_LED_100MA << I_LED2_SHIFT)
 
#define I_LED2_150MA   (I_LED_150MA << I_LED2_SHIFT)
 
#define I_LED2_200MA   (I_LED_200MA << I_LED2_SHIFT)
 
#define LED_ACTIVE_MASK   (0xC0) /* active LED mask */
 
#define LED_ACTIVE_1   (0x00) /* LED1 active */
 
#define LED_ACTIVE_1_2   (0x40) /* LED1 & LED2 active */
 
#define LED_ACTIVE_1_3   (0x80) /* LED1 & LED3 active */
 
#define LED_ACTIVE_ALL   (0xC0) /* all LEDs active */
 
#define I_LED3_MASK   (0x07) /* LED3 pulse current mask */
 
#define I_LED3_5MA   (I_LED_5MA)
 
#define I_LED3_10MA   (I_LED_10MA)
 
#define I_LED3_20MA   (I_LED_20MA)
 
#define I_LED3_50MA   (I_LED_50MA)
 
#define I_LED3_100MA   (I_LED_100MA)
 
#define I_LED3_150MA   (I_LED_150MA)
 
#define I_LED3_200MA   (I_LED_200MA)
 
#define PS_INTERVAL_10MS   (0x00) /* 10 msec */
 
#define PS_INTERVAL_20MS   (0x01) /* 20 msec */
 
#define PS_INTERVAL_30MS   (0x02) /* 30 msec */
 
#define PS_INTERVAL_50MS   (0x03) /* 50 msec */
 
#define PS_INTERVAL_70MS   (0x04) /* 70 msec */
 
#define PS_INTERVAL_100MS   (0x05) /* 100 msec (default) */
 
#define PS_INTERVAL_200MS   (0x06) /* 200 msec */
 
#define PS_INTERVAL_500MS   (0x07) /* 500 msec */
 
#define PS_INTERVAL_1000MS   (0x08) /* 1000 msec */
 
#define PS_INTERVAL_2000MS   (0x09) /* 2000 msec */
 
#define ALS_INTERVAL_100MS   (0x00) /* 100 msec */
 
#define ALS_INTERVAL_200MS   (0x01) /* 200 msec */
 
#define ALS_INTERVAL_500MS   (0x02) /* 500 msec (default) */
 
#define ALS_INTERVAL_1000MS   (0x03) /* 1000 msec */
 
#define ALS_INTERVAL_2000MS   (0x04) /* 2000 msec */
 
#define PART_REV_MASK   (0x0F) /* SFH7770 chip revision bit mask */
 
#define PART_ID_MASK   (0xF0) /* SFH7770 chip id bit mask */
 
#define PART_ID_SHIFT
 
#define SFH7770_PART_ID_VAL   (0x90) /* expected chip id field value */
 
#define SFH7770_PART_REV_VAL
 
#define SFH7770_MAN_ID_VAL   (0x03) /* expected manufacturer id value */
 
#define PS_LED1_DATA   (0x01) /* PS LED1 sensor data available */
 
#define PS_LED1_THRESH
 
#define PS_LED2_DATA   (0x04) /* PS LED2 sensor data available */
 
#define PS_LED2_THRESH
 
#define PS_LED3_DATA   (0x10) /* PS LED3 sensor data available */
 
#define PS_LED3_THRESH
 
#define ALS_DATA   (0x40) /* ALS sensor data available */
 
#define ALS_THRESH   (0x80) /* ALS sensor value above threshold */
 
#define INT_MODE_MASK   (0x03) /* interrupt mode enable (2 bits) */
 
#define INT_MODE_PS   (0x01) /* enable interrupt from prox sensor */
 
#define INT_MODE_ALS   (0x02) /* enable interrupt from ALS */
 
#define INT_OUT_POL
 
#define INT_OUT_MODE
 
#define INT_SOURCE_MASK   (0x60) /* interrupt source (2 bits) */
 
#define INT_SOURCE_ALS   (0x00) /* source = ALS */
 
#define INT_SOURCE_LED1   (0x20) /* source = PS, LED 1 */
 
#define INT_SOURCE_LED2   (0x40) /* source = PS, LED 2 */
 
#define INT_SOURCE_LED3   (0x60) /* source = PS, LED 3 */
 

Functions

bool sfh7770_init (sensor_t *, int)
 Osram SFH7770 light & proximity sensor driver initialization. More...
 

#define ALS_CONTROL_SW_RESET   (0x04) /* software reset */

Referenced by sfh7770_init().

#define ALS_DATA   (0x40) /* ALS sensor data available */
#define ALS_INTERVAL_1000MS   (0x03) /* 1000 msec */
#define ALS_INTERVAL_100MS   (0x00) /* 100 msec */
#define ALS_INTERVAL_2000MS   (0x04) /* 2000 msec */
#define ALS_INTERVAL_200MS   (0x01) /* 200 msec */
#define ALS_INTERVAL_500MS   (0x02) /* 500 msec (default) */

Referenced by sfh7770_init().

#define ALS_MODE_FREE_RUNNING   (0x03) /* free-running mode */

Referenced by sfh7770_init(), and sfh7770_set_state().

#define ALS_MODE_MASK   (0x03) /* light sensor mode mask */

SFH7770 Register Bit Definitions.

#define ALS_MODE_STANDBY   (0x00) /* standby mode (default) */
#define ALS_MODE_TRIGGERED   (0x02) /* triggered mode */
#define ALS_THRESH   (0x80) /* ALS sensor value above threshold */
#define I_LED1_100MA   (I_LED_100MA)
#define I_LED1_10MA   (I_LED_10MA)
#define I_LED1_150MA   (I_LED_150MA)
#define I_LED1_200MA   (I_LED_200MA)
#define I_LED1_20MA   (I_LED_20MA)
#define I_LED1_50MA   (I_LED_50MA)
#define I_LED1_5MA   (I_LED_5MA)
#define I_LED1_MASK   (0x07) /* LED1 pulse current mask */

Referenced by sfh7770_set_current().

#define I_LED2_100MA   (I_LED_100MA << I_LED2_SHIFT)
#define I_LED2_10MA   (I_LED_10MA << I_LED2_SHIFT)
#define I_LED2_150MA   (I_LED_150MA << I_LED2_SHIFT)
#define I_LED2_200MA   (I_LED_200MA << I_LED2_SHIFT)
#define I_LED2_20MA   (I_LED_20MA << I_LED2_SHIFT)
#define I_LED2_50MA   (I_LED_50MA << I_LED2_SHIFT)
#define I_LED2_5MA   (I_LED_5MA << I_LED2_SHIFT)
#define I_LED2_MASK   (0x38) /* LED2 pulse current mask */

Referenced by sfh7770_set_current().

#define I_LED2_SHIFT   (3) /* bit shift for LED2 field */
#define I_LED3_100MA   (I_LED_100MA)
#define I_LED3_10MA   (I_LED_10MA)
#define I_LED3_150MA   (I_LED_150MA)
#define I_LED3_200MA   (I_LED_200MA)
#define I_LED3_20MA   (I_LED_20MA)
#define I_LED3_50MA   (I_LED_50MA)
#define I_LED3_5MA   (I_LED_5MA)
#define I_LED3_MASK   (0x07) /* LED3 pulse current mask */
#define I_LED_100MA   (0x04) /* LED current = 100mA */
#define I_LED_10MA   (0x01) /* LED current = 10mA */
#define I_LED_150MA   (0x05) /* LED current = 150mA */
#define I_LED_200MA   (0x06) /* LED current = 200mA */
#define I_LED_20MA   (0x02) /* LED current = 20mA */
#define I_LED_50MA   (0x03) /* LED current = 50mA (default) */

Referenced by sfh7770_init().

#define I_LED_5MA   (0x00) /* LED current = 5mA */
#define INT_MODE_ALS   (0x02) /* enable interrupt from ALS */

Referenced by sfh7770_event().

#define INT_MODE_MASK   (0x03) /* interrupt mode enable (2 bits) */
#define INT_MODE_PS   (0x01) /* enable interrupt from prox sensor */

Referenced by sfh7770_event().

#define INT_OUT_MODE
Value:
(0x08) /* int output mode (0=latched, 1=not
* latchd) */
#define INT_OUT_POL
Value:
(0x04) /* int output polarity (0=active lo,
* 1=high) */
#define INT_SOURCE_ALS   (0x00) /* source = ALS */

Referenced by sfh7770_isr().

#define INT_SOURCE_LED1   (0x20) /* source = PS, LED 1 */

Referenced by sfh7770_isr().

#define INT_SOURCE_LED2   (0x40) /* source = PS, LED 2 */

Referenced by sfh7770_isr().

#define INT_SOURCE_LED3   (0x60) /* source = PS, LED 3 */

Referenced by sfh7770_isr().

#define INT_SOURCE_MASK   (0x60) /* interrupt source (2 bits) */

Referenced by sfh7770_isr().

#define LED_ACTIVE_1   (0x00) /* LED1 active */
#define LED_ACTIVE_1_2   (0x40) /* LED1 & LED2 active */
#define LED_ACTIVE_1_3   (0x80) /* LED1 & LED3 active */
#define LED_ACTIVE_ALL   (0xC0) /* all LEDs active */

Referenced by sfh7770_init().

#define LED_ACTIVE_MASK   (0xC0) /* active LED mask */
#define PART_ID_MASK   (0xF0) /* SFH7770 chip id bit mask */
#define PART_ID_SHIFT
Value:
(0x04) /* bit shift for part ID (upper 4
* bits) */
#define PART_REV_MASK   (0x0F) /* SFH7770 chip revision bit mask */
#define PS_INTERVAL_1000MS   (0x08) /* 1000 msec */
#define PS_INTERVAL_100MS   (0x05) /* 100 msec (default) */

Referenced by sfh7770_init().

#define PS_INTERVAL_10MS   (0x00) /* 10 msec */
#define PS_INTERVAL_2000MS   (0x09) /* 2000 msec */
#define PS_INTERVAL_200MS   (0x06) /* 200 msec */
#define PS_INTERVAL_20MS   (0x01) /* 20 msec */
#define PS_INTERVAL_30MS   (0x02) /* 30 msec */
#define PS_INTERVAL_500MS   (0x07) /* 500 msec */
#define PS_INTERVAL_50MS   (0x03) /* 50 msec */
#define PS_INTERVAL_70MS   (0x04) /* 70 msec */
#define PS_LED1_DATA   (0x01) /* PS LED1 sensor data available */
#define PS_LED1_THRESH
Value:
(0x02) /* PS LED1 sensor value above
* threshold */

Referenced by sfh7770_get_proximity(), and sfh7770_isr().

#define PS_LED2_DATA   (0x04) /* PS LED2 sensor data available */
#define PS_LED2_THRESH
Value:
(0x08) /* PS LED2 sensor value above
* threshold */

Referenced by sfh7770_get_proximity(), and sfh7770_isr().

#define PS_LED3_DATA   (0x10) /* PS LED3 sensor data available */
#define PS_LED3_THRESH
Value:
(0x20) /* PS LED3 sensor value above
* threshold */

Referenced by sfh7770_get_proximity(), and sfh7770_isr().

#define PS_MODE_FREE_RUNNING   (0x03) /* free-running mode */

Referenced by sfh7770_init(), and sfh7770_set_state().

#define PS_MODE_MASK   (0x03) /* proximity sensor mode mask */
#define PS_MODE_STANDBY   (0x00) /* standby mode (default) */

Referenced by sfh7770_set_state().

#define PS_MODE_TRIGGERED   (0x02) /* triggered mode */
#define SFH7770_ALS_CONTROL   (0x80) /* ambient light sensor control */

SFH7770 Register Addresses.

Referenced by sfh7770_init(), and sfh7770_set_state().

#define SFH7770_ALS_DATA_LSB   (0x8C) /* light meas data (low 8 bits) */

Referenced by sfh7770_get_light(), and sfh7770_init().

#define SFH7770_ALS_DATA_MSB   (0x8D) /* light meas data (high 8 bits) */
#define SFH7770_ALS_INTERVAL   (0x86) /* light measurement interval */

Referenced by sfh7770_init(), and sfh7770_set_rate().

#define SFH7770_ALS_LO_THR_LSB   (0x98) /* lower light threshold (lsb) */

Referenced by sfh7770_set_threshold().

#define SFH7770_ALS_LO_THR_MSB   (0x99) /* lower light threshold (msb) */
#define SFH7770_ALS_PS_STATUS   (0x8E) /* light/prox measurement status */

Referenced by sfh7770_get_proximity().

#define SFH7770_ALS_PS_TRIG   (0x84) /* measurement start (trigger mode) */
#define SFH7770_ALS_UP_THR_LSB   (0x96) /* upper light threshold (lsb) */

Referenced by sfh7770_set_threshold().

#define SFH7770_ALS_UP_THR_MSB   (0x97) /* upper light threshold (msb) */
#define SFH7770_DATA_RESOLUTION   (16)

Referenced by sfh7770_init().

#define SFH7770_I_LED_1_2   (0x82) /* emitter current - LED1 & 2 */
#define SFH7770_I_LED_3   (0x83) /* emitter control reg 2 */
#define SFH7770_INT_SET   (0x92) /* interrupt status/control */

Referenced by sfh7770_event(), and sfh7770_init().

#define SFH7770_MAN_ID   (0x8B) /* manufacturer id */
#define SFH7770_MAN_ID_VAL   (0x03) /* expected manufacturer id value */
#define SFH7770_PART_ID   (0x8A) /* part id & revision */

Referenced by sfh7770_device_id(), and sfh7770_init().

#define SFH7770_PART_ID_VAL   (0x90) /* expected chip id field value */

Referenced by sfh7770_init().

#define SFH7770_PART_REV_VAL
Value:
(0x04) /* expected chip revision field
* value */

Referenced by sfh7770_init().

#define SFH7770_PS_CONTROL   (0x81) /* proximity sensor control */

Referenced by sfh7770_init(), and sfh7770_set_state().

#define SFH7770_PS_DATA_LED1   (0x8F) /* proximity meas data (LED1) */

Referenced by sfh7770_calibrate().

#define SFH7770_PS_DATA_LED2   (0x90) /* proximity meas data (LED2) */

Referenced by sfh7770_calibrate().

#define SFH7770_PS_DATA_LED3   (0x91) /* proximity meas data (LED3) */

Referenced by sfh7770_calibrate().

#define SFH7770_PS_INTERVAL   (0x85) /* proximity measurement interval */

Referenced by sfh7770_init(), and sfh7770_set_rate().

#define SFH7770_PS_THR_LED1   (0x93) /* proximity threshold (LED1) */
#define SFH7770_PS_THR_LED2   (0x94) /* proximity threshold (LED2) */
#define SFH7770_PS_THR_LED3   (0x95) /* proximity threshold (LED3) */
#define SFH7770_TWI_ADDR   (0x38)