Atmel Software Framework

sfh5712.c File Reference

Osram SFH5712 light sensor driver.

This file contains functions for initializing and reading data from a Osram SFH5712 light sensor.

Copyright (c) 2012 Atmel Corporation. All rights reserved.

#include "sfh5712.h"

Functions

static bool sfh5712_device_id (sensor_hal_t *hal, sensor_data_t *data)
 Read SFH5712 device ID and revision numbers. More...
 
static bool sfh5712_get_light (sensor_hal_t *hal, sensor_data_t *data)
 Read SFH5712 light level data. More...
 
bool sfh5712_init (sensor_t *sensor, int resvd)
 Osram SFH5712 light sensor driver initialization. More...
 
static bool sfh5712_ioctl (sensor_t *sensor, sensor_command_t cmd, void *arg)
 SFH5712 ioctl control entry point. More...
 
static bool sfh5712_read (sensor_t *sensor, sensor_read_t type, sensor_data_t *data)
 Read sensor data. More...
 
static bool sfh5712_set_state (sensor_hal_t *hal, sensor_state_t state)
 Set the SFH5712 execution mode. More...
 

static bool sfh5712_device_id ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read SFH5712 device ID and revision numbers.

This function reads the sensor hardware identification registers and returns these values in the specified data structure.

Parameters
halAddress of an initialized sensor hardware descriptor.
dataAddress of sensor_data_t structure to return values.
Returns
bool true if the call succeeds, else false is returned.

References sensor_data_t::device, PART_ID_MASK, PART_ID_SHIFT, PART_REV_MASK, sensor_bus_get, and SFH5712_PART_ID.

Referenced by sfh5712_read().

static bool sfh5712_get_light ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read SFH5712 light level data.

This function reads the ambient light level data from the sensor and places it in the user-provided sensor_data_t structure.

Parameters
sensorAddress of an initialized sensor device descriptor.
dataThe address of a vector storing sensor measurement data.
Returns
bool true if the call succeeds, else false is returned.

References count, sensor_data_t::light, sensor_bus_read, and SFH5712_ALS_DATA_LSB.

Referenced by sfh5712_read().

bool sfh5712_init ( sensor_t sensor,
int  resvd 
)

Osram SFH5712 light sensor driver initialization.

This is the main initialization function for the SFH5712 device.

Parameters
sensorAddress of a sensor device descriptor.
resvdReserved value.
Returns
bool true if the call succeeds, else false is returned.

References ALS_MODE_ACTIVE, sensor_desc::drv, sensor_device_t::func, sensor_desc::hal, sensor_funcs_t::read, sensor_hal::resolution, sensor_bus_get, sensor_bus_put, SENSOR_SCALE_one, SENSOR_UNITS_lux, SENSOR_VENDOR_OSRAM, SFH5712_ALS_CONTROL, SFH5712_DATA_RESOLUTION, sfh5712_ioctl(), SFH5712_PART_ID, SFH5712_PART_ID_VAL, SFH5712_PART_REV_VAL, sfh5712_read(), and status.

static bool sfh5712_ioctl ( sensor_t sensor,
sensor_command_t  cmd,
void *  arg 
)
static

SFH5712 ioctl control entry point.

Parameters
halAddress of an initialized sensor hardware descriptor.
cmdCommand to execute
argArgument for command (varies)
Returns
bool true if the call succeeds, else false is returned.

References sensor_desc::err, sensor_desc::hal, SENSOR_ERR_UNSUPPORTED, SENSOR_SET_STATE, sfh5712_set_state(), and status.

Referenced by sfh5712_init().

static bool sfh5712_read ( sensor_t sensor,
sensor_read_t  type,
sensor_data_t data 
)
static

Read sensor data.

This routine calls the appropriate internal data function to obtain the specified type of data from the sensor device.

Parameters
sensorAddress of an initialized sensor device descriptor.
typeType of sensor data to read.
dataThe address where data values are returned.
Returns
bool true if the call succeeds, else false is returned.

References sensor_desc::err, sensor_desc::hal, SENSOR_ERR_FUNCTION, SENSOR_READ_ID, SENSOR_READ_LIGHT, sfh5712_device_id(), and sfh5712_get_light().

Referenced by sfh5712_init().

static bool sfh5712_set_state ( sensor_hal_t hal,
sensor_state_t  state 
)
static

Set the SFH5712 execution mode.

This routine sets a specified SFH5712 execution state to one of the following:

SENSOR_STATE_SLEEP: Setting the sleep mode puts the sensor in standby mode, in which no measurements are made.

SENSOR_STATE_NORMAL: Setting the sleep mode puts sensor in continuous measurement mode.

Parameters
halAddress of an initialized sensor hardware descriptor.
stateA specified sensor operational state.
Returns
bool true if the call succeeds, else false is returned.

References ALS_MODE_ACTIVE, ALS_MODE_STANDBY, sensor_bus_put, SENSOR_STATE_NORMAL, SENSOR_STATE_SLEEP, and SFH5712_ALS_CONTROL.

Referenced by sfh5712_ioctl().