Atmel Software Framework

sensor.c File Reference

Atmel Software Framework Common Sensor API.

The sensor device service provides high-level interfaces and binary driver libraries for sensor devices on systems built around UC3, XMEGA, and SAM microcontrollers.

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

#include "sensor.h"

Macros

#define SENSOR_DRV_CALL(sns, fn,...)
 Driver Call Wrapper. More...
 

Functions

void default_event_handler (volatile sensor_event_data_t *data, volatile void *arg)
 Default sensor event callback handler. More...
 
static bool sensor_band_index (const sensor_caps_t *caps, int16_t band, int *index)
 Get a bandwidth table index associated with a bandwidth value. More...
 
static bool sensor_range_index (const sensor_caps_t *caps, int16_t range, int *index)
 Get a range table index associated with a range value. More...
 
static bool sensor_driver_unimpl (sensor_t *sensor)
 Unimplemented driver function handler. More...
 
bool sensor_attach (sensor_t *sensor, sensor_type_t type, int num, void *aux)
 Attach a specified sensor descriptor to a sensor device. More...
 
bool sensor_device_enum (sensor_type_t type, sensor_enum_callback func, void *arg)
 Enumerate sensor devices. More...
 
bool sensor_device_id (sensor_t *sensor, uint32_t *id, uint8_t *ver)
 Get sensor hardware device ID. More...
 
bool sensor_read (sensor_t *sensor, sensor_read_t type, sensor_data_t *data)
 Read sensor data. More...
 
bool sensor_enum_bandwidth (sensor_t *sensor, const sensor_band_t **table, size_t *count)
 Enumerate sensor bandwidth settings. More...
 
bool sensor_enum_range (sensor_t *sensor, const sensor_range_t **table, size_t *count)
 Enumerate sensor range settings. More...
 
bool sensor_add_event (sensor_t *sensor, sensor_event_t sensor_event, sensor_event_callback handler, volatile void *arg, bool enable)
 Install a sensor event handler. More...
 
bool sensor_calibrate (sensor_t *sensor, sensor_calibration_t caltype, int code, void *caldata)
 Calibrate a sensor device. More...
 
bool sensor_sleep (sensor_t *sensor, int arg)
 Set a sensor device to low-power or standby mode. More...
 
bool sensor_reset (sensor_t *sensor, int arg)
 Initiate a sensor device software reset. More...
 
bool sensor_set_state (sensor_t *sensor, sensor_state_t mode)
 Set a sensor mode. More...
 
bool sensor_get_state (sensor_t *sensor, sensor_state_t *mode)
 Get a sensor mode. More...
 
bool sensor_set_threshold (sensor_t *sensor, sensor_threshold_t type, int16_t value)
 Set a sensor operational threshold. More...
 
bool sensor_get_threshold (sensor_t *sensor, sensor_threshold_t type, int16_t *value)
 Get a sensor operational threshold. More...
 
bool sensor_ioctl (sensor_t *sensor, sensor_command_t cmd, void *arg)
 Execute a sensor device control function. More...
 
bool sensor_set_tap (sensor_t *sensor, sensor_tap_params_t *params)
 Set tap event parameters. More...
 
bool sensor_selftest (sensor_t *sensor, int *test_code, void *arg)
 Activate a sensor self-test function. More...
 
const char * sensor_api_version (void)
 Atmel Software Framework Common Sensor API version. More...
 

#define SENSOR_DRV_CALL (   sns,
  fn,
  ... 
)
Value:
(((sns)->drv->func.fn) \
? (((sns)->drv->func.fn)(sns, __VA_ARGS__)) : sensor_driver_unimpl(sns))
static bool sensor_driver_unimpl(sensor_t *sensor)
Unimplemented driver function handler.
Definition: sensor.c:150

Driver Call Wrapper.

Referenced by sensor_add_event(), sensor_calibrate(), sensor_get_threshold(), sensor_ioctl(), sensor_read(), sensor_selftest(), sensor_set_state(), sensor_set_tap(), and sensor_set_threshold().

static bool sensor_band_index ( const sensor_caps_t caps,
int16_t  band,
int *  index 
)
inlinestatic

Get a bandwidth table index associated with a bandwidth value.

This utility routine, provided for internal API and driver functions, fetches the driver bandwidth table index associated with a specified bandwidth value. The table index returned in index is undefined in the event of a false return value.

Parameters
capsSpecifies an initialized driver capabilities descriptor.
bandA bandwidth value (Hz).
indexThe driver range table index is returned to this location.
Returns
bool true if the call succeeds, else false is returned.

References sensor_caps_t::band_count, sensor_caps_t::band_table, and sensor_map_t::bandwidth_Hz.

Referenced by sensor_ioctl().

static bool sensor_range_index ( const sensor_caps_t caps,
int16_t  range,
int *  index 
)
inlinestatic

Get a range table index associated with a range value.

This utility routine, provided for internal API and driver functions, fetches the driver range table index associated with a device-specific range value. The table index returned in index is undefined in the event of a false return value.

Parameters
capsSpecifies an initialized driver capabilities descriptor.
rangeA device-specific operational range value.
indexThe driver range table index is returned to this location.
Returns
bool true if the call succeeds, else false is returned.

References sensor_caps_t::range_count, sensor_caps_t::range_table, and sensor_map_t::range_units.

Referenced by sensor_ioctl().