itg320x.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #endif
46 
47 #include <stdbool.h>
48 #include <stdint.h>
49 
50 #include "periph/gpio.h"
51 #include "periph/i2c.h"
52 
57 #define ITG320X_I2C_ADDRESS_1 (0x68)
58 #define ITG320X_I2C_ADDRESS_2 (0x69)
62 #define ITG320X_ID (0x68)
63 
67 typedef enum {
68  ITG320X_OK = 0,
74 
84 typedef enum {
93 
97 typedef enum {
99  ITG320X_INT_LOW = 0x80,
101 
105 typedef enum {
107  ITG320X_INT_OPEN_DRAIN = 0x40
109 
113 typedef enum {
121 
125 typedef struct {
126  int16_t x;
127  int16_t y;
128  int16_t z;
130 
138 typedef struct {
139  int16_t x;
140  int16_t y;
141  int16_t z;
143 
147 typedef struct {
149  uint8_t addr;
151  uint8_t isr_div;
161 #if MODULE_ITG320X_INT || DOXYGEN
162  gpio_t int_pin;
168 #endif /* MODULE_ITG320X_INT || DOXYGEN */
170 
174 typedef struct {
176 } itg320x_t;
177 
178 #if MODULE_ITG320X_INT || DOXYGEN
188 typedef void (*itg320x_drdy_int_cb_t)(void *);
189 
190 #endif /* MODULE_ITG320X_INT || DOXYGEN */
191 
205 int itg320x_init(itg320x_t *dev, const itg320x_params_t *params);
206 
207 #if MODULE_ITG320X_INT || DOXYGEN
224 int itg320x_init_int(const itg320x_t *dev, itg320x_drdy_int_cb_t cb, void *arg);
225 
226 #endif /* MODULE_ITG320X_INT || DOXYGEN */
227 
241 
256 int itg320x_read(const itg320x_t *dev, itg320x_data_t *data);
257 
269 
280 int itg320x_read_temp(const itg320x_t *dev, int16_t* temp);
281 
295 
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 
Low-level GPIO peripheral driver interface definitions.
int itg320x_read(const itg320x_t *dev, itg320x_data_t *data)
Read one sample of angular rates in tenths of a degree per second.
itg320x_lpf_bw_t
Low pass filter bandwidth.
Definition: itg320x.h:84
int itg320x_init_int(const itg320x_t *dev, itg320x_drdy_int_cb_t cb, void *arg)
Initialize and activate the DRDY interrupt of ITG320X sensor device.
int itg320x_power_up(itg320x_t *dev)
Power up the sensor.
int itg320x_read_temp(const itg320x_t *dev, int16_t *temp)
Read temperature in tenths of a degree Celsius.
itg320x_clk_sel_t
Clock source selection (ITG320X_REG_PWR_MGM<2:0>)
Definition: itg320x.h:113
int itg320x_read_raw(const itg320x_t *dev, itg320x_raw_data_t *raw)
Read one sample of raw sensor data as 16 bit two's complements.
void(* itg320x_drdy_int_cb_t)(void *)
ITG320X data ready interrupt (DRDY) callback function type.
Definition: itg320x.h:188
int itg320x_init(itg320x_t *dev, const itg320x_params_t *params)
Initialize the ITG320X sensor device.
itg320x_int_drive_t
Drive type for INT output pin (ITG320X_REG_INT_CFG<6>)
Definition: itg320x.h:105
int itg320x_data_ready(const itg320x_t *dev)
Data-ready status function.
itg320x_error_codes_t
Named return values.
Definition: itg320x.h:67
itg320x_int_level_t
Logic level for INT output pin (ITG320X_REG_INT_CFG<7>)
Definition: itg320x.h:97
int itg320x_power_down(itg320x_t *dev)
Power down the sensor.
@ ITG320X_LPF_BW_20
20 Hz, ISR = 1 kHz
Definition: itg320x.h:89
@ ITG320X_LPF_BW_98
98 Hz, ISR = 1 kHz
Definition: itg320x.h:87
@ ITG320X_LPF_BW_10
10 Hz, ISR = 1 kHz
Definition: itg320x.h:90
@ ITG320X_LPF_BW_42
42 Hz, ISR = 1 kHz
Definition: itg320x.h:88
@ ITG320X_LPF_BW_5
5 Hz, ISR = 1 kHz (default)
Definition: itg320x.h:91
@ ITG320X_LPF_BW_256
256 Hz, ISR = 8 kHz
Definition: itg320x.h:85
@ ITG320X_LPF_BW_188
188 Hz, ISR = 1 kHz
Definition: itg320x.h:86
@ ITG320X_CLK_PLL_19M
PLL with external 19.2 MHz reference.
Definition: itg320x.h:119
@ ITG320X_CLK_PLL_Y_GYRO
PLL with X Gyro reference.
Definition: itg320x.h:116
@ ITG320X_CLK_INTERNAL
Internal oscillator.
Definition: itg320x.h:114
@ ITG320X_CLK_PLL_Z_GYRO
PLL with X Gyro reference.
Definition: itg320x.h:117
@ ITG320X_CLK_PLL_X_GYRO
PLL with X Gyro reference (default)
Definition: itg320x.h:115
@ ITG320X_CLK_PLL_32K
PLL with external 32.768 kHz reference.
Definition: itg320x.h:118
@ ITG320X_INT_PUSH_PULL
INT output is of type push/pull (default)
Definition: itg320x.h:106
@ ITG320X_INT_OPEN_DRAIN
INT output is of type open drain.
Definition: itg320x.h:107
@ ITG320X_ERROR_I2C
I2C communication error.
Definition: itg320x.h:69
@ ITG320X_OK
success
Definition: itg320x.h:68
@ ITG320X_ERROR_RAW_DATA
reading raw data failed
Definition: itg320x.h:72
@ ITG320X_ERROR_NO_DATA
no data are available
Definition: itg320x.h:71
@ ITG320X_ERROR_WRONG_ID
wrong id read
Definition: itg320x.h:70
@ ITG320X_INT_LOW
INT output is active low.
Definition: itg320x.h:99
@ ITG320X_INT_HIGH
INT output is active high (default)
Definition: itg320x.h:98
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:144
Low-level I2C peripheral driver interface definition.
Angular rate values in tenths of a degree per second.
Definition: itg320x.h:125
int16_t z
angular rate y-axis (yaw)
Definition: itg320x.h:128
int16_t x
angular rate x-axis (roll)
Definition: itg320x.h:126
int16_t y
angular rate y-axis (pitch)
Definition: itg320x.h:127
ITG320X device initialization parameters.
Definition: itg320x.h:147
itg320x_int_level_t int_level
Logic level for INT output pin (default ITG320X_INT_LOW)
Definition: itg320x.h:164
uint8_t addr
I2C slave address (default ITG320X_I2C_ADDRESS_1)
Definition: itg320x.h:149
uint8_t isr_div
Internal sample rate divider ISR_DIV (default 99) ODR = ISR / (ISR_DIV + 1) where internal sample rat...
Definition: itg320x.h:151
gpio_t int_pin
DRDY interrupt pin: GPIO_UNDEF if not used.
Definition: itg320x.h:162
i2c_t dev
I2C device (default I2C_DEV(0))
Definition: itg320x.h:148
itg320x_int_drive_t int_drive
Drive type for INT output pin (default ITG320X_INT_PUSH_PULL.
Definition: itg320x.h:166
itg320x_clk_sel_t clk_sel
Clock source selection (default ITG320X_CLK_PLL_X_GYRO)
Definition: itg320x.h:158
itg320x_lpf_bw_t lpf_bw
Low pass filter bandwidth (default ITG320X_LPF_BW_5, ISR 1 kHz)
Definition: itg320x.h:156
Raw data set as two complements.
Definition: itg320x.h:138
int16_t x
angular rate x-axis as 16 bit two's complements (roll)
Definition: itg320x.h:139
int16_t y
angular rate y-axis as 16 bit two's complements (pitch)
Definition: itg320x.h:140
int16_t z
angular rate z-axis as 16 bit two's complements (yaw)
Definition: itg320x.h:141
ITG320X sensor device data structure type.
Definition: itg320x.h:174
itg320x_params_t params
device initialization parameters
Definition: itg320x.h:175