summaryrefslogtreecommitdiff
path: root/include/accelerometer.h
blob: 0c8703f3aed56c35b696440743ecd6d55b72ff5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef __CROS_EC_ACCELEROMETER_H
#define __CROS_EC_ACCELEROMETER_H

/* Header file for accelerometer drivers. */

/* This array must be defined in board.c. */
extern const int accel_addr[];

/* This enum must be defined in board.h. */
enum accel_id;

/* Number of counts from accelerometer that represents 1G acceleration. */
#define ACCEL_G  1024

/**
 * Read all three accelerations of an accelerometer. Note that all three
 * accelerations come back in counts, where ACCEL_G can be used to convert
 * counts to engineering units.
 *
 * @param id Target accelerometer
 * @param x_acc Pointer to store X-axis acceleration (in counts).
 * @param y_acc Pointer to store Y-axis acceleration (in counts).
 * @param z_acc Pointer to store Z-axis acceleration (in counts).
 *
 * @return EC_SUCCESS if successful, non-zero if error.
 */
int accel_read(const enum accel_id id, int * const x_acc, int * const y_acc,
		int * const z_acc);

/**
 * Initialize accelerometers.
 *
 * @param id Target accelerometer
 *
 * @return EC_SUCCESS if successful, non-zero if error.
 */
int accel_init(const enum accel_id id);

/**
 * Setter and getter methods for the sensor range. The sensor range defines
 * the maximum value that can be returned from accel_read(). As the range
 * increases, the resolution gets worse.
 *
 * @param id Target accelerometer
 * @param range Range (Units are +/- G's for accel, +/- deg/s for gyro)
 * @param rnd Rounding flag. If true, it rounds up to nearest valid value.
 *                Otherwise, it rounds down.
 *
 * @return EC_SUCCESS if successful, non-zero if error.
 */
int accel_set_range(const enum accel_id id, const int range, const int rnd);
int accel_get_range(const enum accel_id id, int * const range);


/**
 * Setter and getter methods for the sensor resolution.
 *
 * @param id Target accelerometer
 * @param range Resolution (Units are number of bits)
 * param rnd Rounding flag. If true, it rounds up to nearest valid value.
 *                Otherwise, it rounds down.
 *
 * @return EC_SUCCESS if successful, non-zero if error.
 */
int accel_set_resolution(const enum accel_id id, const int res, const int rnd);
int accel_get_resolution(const enum accel_id id, int * const res);

/**
 * Setter and getter methods for the sensor output data range. As the ODR
 * increases, the LPF roll-off frequency also increases.
 *
 * @param id Target accelerometer
 * @param rate Output data rate (units are mHz)
 * @param rnd Rounding flag. If true, it rounds up to nearest valid value.
 *                Otherwise, it rounds down.
 *
 * @return EC_SUCCESS if successful, non-zero if error.
 */
int accel_set_datarate(const enum accel_id id, const int rate, const int rnd);
int accel_get_datarate(const enum accel_id id, int * const rate);

#endif /* __CROS_EC_ACCELEROMETER_H */