Contiki-NG
grove-gyro.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, Zolertia <http://www.zolertia.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32/*---------------------------------------------------------------------------*/
33/**
34 * \addtogroup zoul-sensors
35 * @{
36 *
37 * \defgroup zoul-grove-gyro-sensor Grove 3-axis gyroscope based on ITG-3200
38 * @{
39 *
40 * \file
41 * Grove 3-axis gyroscope header file
42 * \author
43 * Antonio Lignan <alinan@zolertia.com>
44 */
45/*---------------------------------------------------------------------------*/
46#include "lib/sensors.h"
47/* -------------------------------------------------------------------------- */
48#ifndef GROVE_GYRO_H_
49#define GROVE_GYRO_H_
50/* -------------------------------------------------------------------------- */
51/**
52 * \name Callback function to handle the interrupt
53 * @{
54 */
55#define GROVE_GYRO_REGISTER_INT(ptr) grove_gyro_int_callback = ptr;
56extern void (*grove_gyro_int_callback)(uint8_t value);
57/** @} */
58/* -------------------------------------------------------------------------- */
59/**
60 * \name Gyroscope data values structure
61 * @{
62 */
63typedef struct {
64 uint16_t x;
65 uint16_t y;
66 uint16_t z;
67 uint16_t x_offset;
68 uint16_t y_offset;
69 uint16_t z_offset;
70 int16_t temp;
71} grove_gyro_values_t;
72
73extern grove_gyro_values_t gyro_values;
74/** @} */
75/* -------------------------------------------------------------------------- */
76/**
77 * \name Grove 3-axis gyroscope address and registers
78 * @{
79 */
80#define GROVE_GYRO_ADDR 0x68
81
82#define GROVE_GYRO_WHO_AM_I 0x00
83#define GROVE_GYRO_SMPLRT_DIV 0x15
84#define GROVE_GYRO_DLPF_FS 0x16
85#define GROVE_GYRO_INT_CFG 0x17
86#define GROVE_GYRO_INT_STATUS 0x1A
87#define GROVE_GYRO_TEMP_OUT_H 0x1B
88#define GROVE_GYRO_TEMP_OUT_L 0x1C
89#define GROVE_GYRO_XOUT_H 0x1D
90#define GROVE_GYRO_XOUT_L 0x1E
91#define GROVE_GYRO_YOUT_H 0x1F
92#define GROVE_GYRO_YOUT_L 0x20
93#define GROVE_GYRO_ZOUT_H 0x21
94#define GROVE_GYRO_ZOUT_L 0x22
95#define GROVE_GYRO_PWR_MGMT 0x3E
96/** @} */
97/*--------------------------------------------------------------------------*/
98/**
99 * \name Grove 3-axis gyroscope bitmasks and config
100 * @{
101 */
102#define GROVE_GYRO_DLPF_FS_SEL 0x18
103#define GROVE_GYRO_DLPF_FS_CGF_8KHZ_LP256HZ 0x00
104#define GROVE_GYRO_DLPF_FS_CGF_1KHZ_LP188HZ 0x01
105#define GROVE_GYRO_DLPF_FS_CGF_1KHZ_LP98HZ 0x02
106#define GROVE_GYRO_DLPF_FS_CGF_1KHZ_LP42HZ 0x03
107#define GROVE_GYRO_DLPF_FS_CGF_1KHZ_LP20HZ 0x04
108#define GROVE_GYRO_DLPF_FS_CGF_1KHZ_LP10HZ 0x05
109#define GROVE_GYRO_DLPF_FS_CGF_1KHZ_LP5HZ 0x06
110
111#define GROVE_GYRO_INT_CFG_RAW_READY_EN 0x01
112#define GROVE_GYRO_INT_CFG_READY_EN 0x04
113#define GROVE_GYRO_INT_CFG_LATCH_CLR_ANY 0x10
114#define GROVE_GYRO_INT_CFG_LATCH_EN 0x20
115#define GROVE_GYRO_INT_CFG_PIN_OPEN 0x40
116#define GROVE_GYRO_INT_CFG_PIN_ACTL 0x80
117#define GROVE_GYRO_INT_CFG_DISABLE 0x00
118
119#define GROVE_GYRO_INT_STATUS_DATA_RDY_MASK 0x01
120#define GROVE_GYRO_INT_STATUS_PLL_RDY_MASK 0x04
121
122#define GROVE_GYRO_PWR_MGMT_CLK_SEL_INTOSC 0x00
123#define GROVE_GYRO_PWR_MGMT_CLK_SEL_PLL_X 0x01
124#define GROVE_GYRO_PWR_MGMT_CLK_SEL_PLL_Y 0x02
125#define GROVE_GYRO_PWR_MGMT_CLK_SEL_PLL_Z 0x03
126#define GROVE_GYRO_PWR_MGMT_CLK_SEL_EXT_32K 0x04
127#define GROVE_GYRO_PWR_MGMT_CLK_SEL_EXT_19K 0x05
128#define GROVE_GYRO_PWR_MGMT_STBY_ZG 0x08
129#define GROVE_GYRO_PWR_MGMT_STBY_YG 0x10
130#define GROVE_GYRO_PWR_MGMT_STBY_XG 0x20
131#define GROVE_GYRO_PWR_MGMT_SLEEP 0x40
132#define GROVE_GYRO_PWR_MGMT_RESET 0x80
133
134#ifdef GROVE_GYRO_CONF_OSC
135#define GROVE_GYRO_DEFAULT_OSC GROVE_GYRO_CONF_OSC
136#else
137#define GROVE_GYRO_DEFAULT_OSC GROVE_GYRO_PWR_MGMT_CLK_SEL_INTOSC
138#endif
139
140#define GROVE_GYRO_PWR_MGMT_CLK_SEL_MASK 0x07
141#define GROVE_GYRO_MAX_DATA 0x06
142/** @} */
143/* -------------------------------------------------------------------------- */
144/**
145 * \name Grove 3-axis gyroscope operation values
146 * @{
147 */
148/* Configure request type */
149#define GROVE_GYRO_ACTIVE SENSORS_ACTIVE
150#define GROVE_GYRO_DATA_INTERRUPT 0x01
151#define GROVE_GYRO_SAMPLE_RATE 0x02
152#define GROVE_GYRO_SAMPLE_RATE_DIVIDER 0x03
153#define GROVE_GYRO_POWER_ON 0x04
154#define GROVE_GYRO_POWER_OFF 0x05
155#define GROVE_GYRO_CALIBRATE_ZERO 0x06
156
157/* Sensor value request type, match to the stand-by mask to check if enabled */
158#define GROVE_GYRO_X GROVE_GYRO_PWR_MGMT_STBY_XG
159#define GROVE_GYRO_Y GROVE_GYRO_PWR_MGMT_STBY_YG
160#define GROVE_GYRO_Z GROVE_GYRO_PWR_MGMT_STBY_ZG
161#define GROVE_GYRO_SENSOR GROVE_GYRO_PWR_MGMT_SLEEP
162#define GROVE_GYRO_XYZ (GROVE_GYRO_X + GROVE_GYRO_Y + \
163 GROVE_GYRO_Z)
164#define GROVE_GYRO_ALL (GROVE_GYRO_XYZ + GROVE_GYRO_SENSOR)
165#define GROVE_GYRO_TEMP 0x06
166
167/* Return types */
168#define GROVE_GYRO_ERROR (-1)
169#define GROVE_GYRO_SUCCESS 0x00
170
171/* Calibration constants */
172#define GROVE_GYRO_CALIB_SAMPLES 200
173#define GROVE_GYRO_CALIB_TIME_US 5000
174/** @} */
175/* -------------------------------------------------------------------------- */
176#define GROVE_GYRO_STRING "Grove 3-axis gyroscope Sensor"
177/* -------------------------------------------------------------------------- */
178extern const struct sensors_sensor grove_gyro;
179/* -------------------------------------------------------------------------- */
180#endif /* ifndef GROVE_GYRO_H_ */
181/**
182 * @}
183 * @}
184 */