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 
40 #ifndef ITG320X_H
41 #define ITG320X_H
42 
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 #include <stdbool.h>
49 #include <stdint.h>
50 
51 #include "periph/gpio.h"
52 #include "periph/i2c.h"
53 
58 #define ITG320X_I2C_ADDRESS_1 (0x68)
59 #define ITG320X_I2C_ADDRESS_2 (0x69)
63 #define ITG320X_ID (0x68)
64 
68 typedef enum {
69  ITG320X_OK = 0,
75 
85 typedef enum {
94 
98 typedef enum {
102 
106 typedef enum {
110 
114 typedef enum {
122 
126 typedef struct {
127  int16_t x;
128  int16_t y;
129  int16_t z;
131 
139 typedef struct {
140  int16_t x;
141  int16_t y;
142  int16_t z;
144 
148 typedef struct {
150  uint8_t addr;
152  uint8_t isr_div;
162 #if MODULE_ITG320X_INT || DOXYGEN
163  gpio_t int_pin;
169 #endif /* MODULE_ITG320X_INT || DOXYGEN */
171 
175 typedef struct {
177 } itg320x_t;
178 
179 #if MODULE_ITG320X_INT || DOXYGEN
180 
189 typedef void (*itg320x_drdy_int_cb_t)(void *);
190 
191 #endif /* MODULE_ITG320X_INT || DOXYGEN */
192 
206 int itg320x_init(itg320x_t *dev, const itg320x_params_t *params);
207 
208 #if MODULE_ITG320X_INT || DOXYGEN
209 
225 int itg320x_init_int(const itg320x_t *dev, itg320x_drdy_int_cb_t cb, void *arg);
226 
227 #endif /* MODULE_ITG320X_INT || DOXYGEN */
228 
241 int itg320x_data_ready(const itg320x_t *dev);
242 
257 int itg320x_read(const itg320x_t *dev, itg320x_data_t *data);
258 
269 int itg320x_read_raw(const itg320x_t *dev, itg320x_raw_data_t *raw);
270 
281 int itg320x_read_temp(const itg320x_t *dev, int16_t* temp);
282 
295 int itg320x_power_down(itg320x_t *dev);
296 
309 int itg320x_power_up(itg320x_t *dev);
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 
315 #endif /* ITG320X_H */
316 
itg320x_init
int itg320x_init(itg320x_t *dev, const itg320x_params_t *params)
Initialize the ITG320X sensor device.
ITG320X_LPF_BW_42
@ ITG320X_LPF_BW_42
42 Hz, ISR = 1 kHz
Definition: itg320x.h:89
itg320x_clk_sel_t
itg320x_clk_sel_t
Clock source selection (ITG320X_REG_PWR_MGM<2:0>)
Definition: itg320x.h:114
ITG320X_LPF_BW_10
@ ITG320X_LPF_BW_10
10 Hz, ISR = 1 kHz
Definition: itg320x.h:91
itg320x_init_int
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.
itg320x_raw_data_t::y
int16_t y
angular rate y-axis as 16 bit two's complements (pitch)
Definition: itg320x.h:141
itg320x_data_t::y
int16_t y
angular rate y-axis (pitch)
Definition: itg320x.h:128
ITG320X_LPF_BW_20
@ ITG320X_LPF_BW_20
20 Hz, ISR = 1 kHz
Definition: itg320x.h:90
ITG320X_INT_HIGH
@ ITG320X_INT_HIGH
INT output is active high (default)
Definition: itg320x.h:99
ITG320X_ERROR_I2C
@ ITG320X_ERROR_I2C
I2C communication error.
Definition: itg320x.h:70
itg320x_drdy_int_cb_t
void(* itg320x_drdy_int_cb_t)(void *)
ITG320X data ready interrupt (DRDY) callback function type.
Definition: itg320x.h:189
itg320x_raw_data_t
Raw data set as two complements.
Definition: itg320x.h:139
ITG320X_ERROR_NO_DATA
@ ITG320X_ERROR_NO_DATA
no data are available
Definition: itg320x.h:72
itg320x_params_t::isr_div
uint8_t isr_div
Internal sample rate divider ISR_DIV (default 99) ODR = ISR / (ISR_DIV + 1) where internal sample rat...
Definition: itg320x.h:152
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
ITG320X_LPF_BW_98
@ ITG320X_LPF_BW_98
98 Hz, ISR = 1 kHz
Definition: itg320x.h:88
ITG320X_CLK_PLL_Z_GYRO
@ ITG320X_CLK_PLL_Z_GYRO
PLL with X Gyro reference.
Definition: itg320x.h:118
itg320x_params_t::int_pin
gpio_t int_pin
DRDY interrupt pin: GPIO_UNDEF if not used.
Definition: itg320x.h:163
ITG320X_LPF_BW_256
@ ITG320X_LPF_BW_256
256 Hz, ISR = 8 kHz
Definition: itg320x.h:86
ITG320X_CLK_PLL_32K
@ ITG320X_CLK_PLL_32K
PLL with external 32.768 kHz reference.
Definition: itg320x.h:119
ITG320X_ERROR_RAW_DATA
@ ITG320X_ERROR_RAW_DATA
reading raw data failed
Definition: itg320x.h:73
itg320x_params_t::lpf_bw
itg320x_lpf_bw_t lpf_bw
Low pass filter bandwidth (default ITG320X_LPF_BW_5, ISR 1 kHz)
Definition: itg320x.h:157
ITG320X_INT_OPEN_DRAIN
@ ITG320X_INT_OPEN_DRAIN
INT output is of type open drain.
Definition: itg320x.h:108
itg320x_params_t::dev
i2c_t dev
I2C device (default I2C_DEV(0))
Definition: itg320x.h:149
itg320x_data_ready
int itg320x_data_ready(const itg320x_t *dev)
Data-ready status function.
ITG320X_INT_LOW
@ ITG320X_INT_LOW
INT output is active low.
Definition: itg320x.h:100
itg320x_read_raw
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.
ITG320X_CLK_PLL_X_GYRO
@ ITG320X_CLK_PLL_X_GYRO
PLL with X Gyro reference (default)
Definition: itg320x.h:116
ITG320X_LPF_BW_5
@ ITG320X_LPF_BW_5
5 Hz, ISR = 1 kHz (default)
Definition: itg320x.h:92
ITG320X_OK
@ ITG320X_OK
success
Definition: itg320x.h:69
itg320x_int_drive_t
itg320x_int_drive_t
Drive type for INT output pin (ITG320X_REG_INT_CFG<6>)
Definition: itg320x.h:106
itg320x_raw_data_t::x
int16_t x
angular rate x-axis as 16 bit two's complements (roll)
Definition: itg320x.h:140
ITG320X_ERROR_WRONG_ID
@ ITG320X_ERROR_WRONG_ID
wrong id read
Definition: itg320x.h:71
itg320x_error_codes_t
itg320x_error_codes_t
Named return values.
Definition: itg320x.h:68
ITG320X_CLK_PLL_19M
@ ITG320X_CLK_PLL_19M
PLL with external 19.2 MHz reference.
Definition: itg320x.h:120
itg320x_params_t::addr
uint8_t addr
I2C slave address (default ITG320X_I2C_ADDRESS_1)
Definition: itg320x.h:150
itg320x_read_temp
int itg320x_read_temp(const itg320x_t *dev, int16_t *temp)
Read temperature in tenths of a degree Celsius.
ITG320X_CLK_INTERNAL
@ ITG320X_CLK_INTERNAL
Internal oscillator.
Definition: itg320x.h:115
itg320x_data_t
Angular rate values in tenths of a degree per second.
Definition: itg320x.h:126
ITG320X_LPF_BW_188
@ ITG320X_LPF_BW_188
188 Hz, ISR = 1 kHz
Definition: itg320x.h:87
ITG320X_CLK_PLL_Y_GYRO
@ ITG320X_CLK_PLL_Y_GYRO
PLL with X Gyro reference.
Definition: itg320x.h:117
itg320x_params_t::int_drive
itg320x_int_drive_t int_drive
Drive type for INT output pin (default ITG320X_INT_PUSH_PULL.
Definition: itg320x.h:167
itg320x_t::params
itg320x_params_t params
device initialization parameters
Definition: itg320x.h:176
itg320x_data_t::z
int16_t z
angular rate y-axis (yaw)
Definition: itg320x.h:129
itg320x_read
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_int_level_t
itg320x_int_level_t
Logic level for INT output pin (ITG320X_REG_INT_CFG<7>)
Definition: itg320x.h:98
gpio.h
Low-level GPIO peripheral driver interface definitions.
itg320x_raw_data_t::z
int16_t z
angular rate z-axis as 16 bit two's complements (yaw)
Definition: itg320x.h:142
itg320x_power_up
int itg320x_power_up(itg320x_t *dev)
Power up the sensor.
itg320x_data_t::x
int16_t x
angular rate x-axis (roll)
Definition: itg320x.h:127
itg320x_params_t::clk_sel
itg320x_clk_sel_t clk_sel
Clock source selection (default ITG320X_CLK_PLL_X_GYRO)
Definition: itg320x.h:159
itg320x_t
ITG320X sensor device data structure type.
Definition: itg320x.h:175
itg320x_lpf_bw_t
itg320x_lpf_bw_t
Low pass filter bandwidth.
Definition: itg320x.h:85
i2c.h
Low-level I2C peripheral driver interface definition.
itg320x_params_t::int_level
itg320x_int_level_t int_level
Logic level for INT output pin (default ITG320X_INT_LOW)
Definition: itg320x.h:165
itg320x_params_t
ITG320X device initialization parameters.
Definition: itg320x.h:148
itg320x_power_down
int itg320x_power_down(itg320x_t *dev)
Power down the sensor.
ITG320X_INT_PUSH_PULL
@ ITG320X_INT_PUSH_PULL
INT output is of type push/pull (default)
Definition: itg320x.h:107