Loading...
Searching...
No Matches

Device driver for InvenSense ITG320X 3-axis gyroscope. More...

Detailed Description

Device driver for InvenSense ITG320X 3-axis gyroscope.

The driver can be used with InvenSense ITG3200, ITG3205, and MPU3050. The latter one can be used only with reduced feature set.

The driver implements polling mode as well as interrupt mode. Thus, the application may use two different approaches to retrieve new data, either

To use the latter approach, module itg320x_int has to be enabled and the GPIO to which the sensor's INT output pin is connected has to be configured.

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.

Files

file  itg320x.h
 Device driver for InvenSense ITG320X 3-axis gyroscope.
 
file  itg320x_params.h
 Default configuration for InvenSense ITG320X 3-axis gyroscope.
 
file  itg320x_regs.h
 Register definitions for InvenSense ITG320X 3-axis gyroscope.
 

Data Structures

struct  itg320x_data_t
 Angular rate values in tenths of a degree per second. More...
 
struct  itg320x_raw_data_t
 Raw data set as two complements. More...
 
struct  itg320x_params_t
 ITG320X device initialization parameters. More...
 
struct  itg320x_t
 ITG320X sensor device data structure type. More...
 

Macros

#define ITG320X_ID   (0x68)
 ITG320X chip id defined in Who Am I.
 

Typedefs

typedef void(* itg320x_drdy_int_cb_t) (void *)
 ITG320X data ready interrupt (DRDY) callback function type.
 

Enumerations

enum  itg320x_error_codes_t {
  ITG320X_OK = 0 , ITG320X_ERROR_I2C = -1 , ITG320X_ERROR_WRONG_ID = -2 , ITG320X_ERROR_NO_DATA = -3 ,
  ITG320X_ERROR_RAW_DATA = -4
}
 Named return values. More...
 
enum  itg320x_lpf_bw_t {
  ITG320X_LPF_BW_256 = 0 , ITG320X_LPF_BW_188 , ITG320X_LPF_BW_98 , ITG320X_LPF_BW_42 ,
  ITG320X_LPF_BW_20 , ITG320X_LPF_BW_10 , ITG320X_LPF_BW_5
}
 Low pass filter bandwidth. More...
 
enum  itg320x_int_level_t { ITG320X_INT_HIGH = 0x00 , ITG320X_INT_LOW = 0x80 }
 Logic level for INT output pin (ITG320X_REG_INT_CFG<7>) More...
 
enum  itg320x_int_drive_t { ITG320X_INT_PUSH_PULL = 0x00 , ITG320X_INT_OPEN_DRAIN = 0x40 }
 Drive type for INT output pin (ITG320X_REG_INT_CFG<6>) More...
 
enum  itg320x_clk_sel_t {
  ITG320X_CLK_INTERNAL = 0 , ITG320X_CLK_PLL_X_GYRO , ITG320X_CLK_PLL_Y_GYRO , ITG320X_CLK_PLL_Z_GYRO ,
  ITG320X_CLK_PLL_32K , ITG320X_CLK_PLL_19M
}
 Clock source selection (ITG320X_REG_PWR_MGM<2:0>) More...
 

Functions

int itg320x_init (itg320x_t *dev, const itg320x_params_t *params)
 Initialize the ITG320X sensor device.
 
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_data_ready (const itg320x_t *dev)
 Data-ready status function.
 
int itg320x_read (const itg320x_t *dev, itg320x_data_t *data)
 Read one sample of angular rates in tenths of a degree per second.
 
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.
 
int itg320x_read_temp (const itg320x_t *dev, int16_t *temp)
 Read temperature in tenths of a degree Celsius.
 
int itg320x_power_down (itg320x_t *dev)
 Power down the sensor.
 
int itg320x_power_up (itg320x_t *dev)
 Power up the sensor.
 

I2C addresses

#define ITG320X_I2C_ADDRESS_1   (0x68)
 AD0 pin low.
 
#define ITG320X_I2C_ADDRESS_2   (0x69)
 AD0 pin high.
 

Macro Definition Documentation

◆ ITG320X_I2C_ADDRESS_1

#define ITG320X_I2C_ADDRESS_1   (0x68)

AD0 pin low.

Definition at line 58 of file itg320x.h.

◆ ITG320X_I2C_ADDRESS_2

#define ITG320X_I2C_ADDRESS_2   (0x69)

AD0 pin high.

Definition at line 59 of file itg320x.h.

◆ ITG320X_ID

#define ITG320X_ID   (0x68)

ITG320X chip id defined in Who Am I.

Definition at line 63 of file itg320x.h.

Typedef Documentation

◆ itg320x_drdy_int_cb_t

typedef void(* itg320x_drdy_int_cb_t) (void *)

ITG320X data ready interrupt (DRDY) callback function type.

Function prototype for the function which is called on DRDY interrupt if the interrupt is activated by itg320x_init_int

Note
The cb function is called in interrupt context. The application should do nothing time consuming and not directly access sensor data.

Definition at line 189 of file itg320x.h.

Enumeration Type Documentation

◆ itg320x_clk_sel_t

Clock source selection (ITG320X_REG_PWR_MGM<2:0>)

Enumerator
ITG320X_CLK_INTERNAL 

Internal oscillator.

ITG320X_CLK_PLL_X_GYRO 

PLL with X Gyro reference (default)

ITG320X_CLK_PLL_Y_GYRO 

PLL with X Gyro reference.

ITG320X_CLK_PLL_Z_GYRO 

PLL with X Gyro reference.

ITG320X_CLK_PLL_32K 

PLL with external 32.768 kHz reference.

ITG320X_CLK_PLL_19M 

PLL with external 19.2 MHz reference.

Definition at line 114 of file itg320x.h.

◆ itg320x_error_codes_t

Named return values.

Enumerator
ITG320X_OK 

success

ITG320X_ERROR_I2C 

I2C communication error.

ITG320X_ERROR_WRONG_ID 

wrong id read

ITG320X_ERROR_NO_DATA 

no data are available

ITG320X_ERROR_RAW_DATA 

reading raw data failed

Definition at line 68 of file itg320x.h.

◆ itg320x_int_drive_t

Drive type for INT output pin (ITG320X_REG_INT_CFG<6>)

Enumerator
ITG320X_INT_PUSH_PULL 

INT output is of type push/pull (default)

ITG320X_INT_OPEN_DRAIN 

INT output is of type open drain.

Definition at line 106 of file itg320x.h.

◆ itg320x_int_level_t

Logic level for INT output pin (ITG320X_REG_INT_CFG<7>)

Enumerator
ITG320X_INT_HIGH 

INT output is active high (default)

ITG320X_INT_LOW 

INT output is active low.

Definition at line 98 of file itg320x.h.

◆ itg320x_lpf_bw_t

Low pass filter bandwidth.

Note
Low pass filter bandwidth determines the internal sample rate (ISR). The internal sample rate (ISR) together with sample rate divider (ISR_DIV) determines the output data rate ODR = ISR / (ISR_DIV + 1) where internal sample rate (ISR) is 8 kHz for ITG320X_LPF_BW_256, or 1 kHz otherwise.
Enumerator
ITG320X_LPF_BW_256 

256 Hz, ISR = 8 kHz

ITG320X_LPF_BW_188 

188 Hz, ISR = 1 kHz

ITG320X_LPF_BW_98 

98 Hz, ISR = 1 kHz

ITG320X_LPF_BW_42 

42 Hz, ISR = 1 kHz

ITG320X_LPF_BW_20 

20 Hz, ISR = 1 kHz

ITG320X_LPF_BW_10 

10 Hz, ISR = 1 kHz

ITG320X_LPF_BW_5 

5 Hz, ISR = 1 kHz (default)

Definition at line 85 of file itg320x.h.

Function Documentation

◆ itg320x_data_ready()

int itg320x_data_ready ( const itg320x_t dev)

Data-ready status function.

The function checks the status register and returns

Parameters
[in]devdevice descriptor of ITG320X sensor
Return values
ITG320X_OKnew data available
ITG320X_ERROR_NO_DATAno new data available
ITG320X_ERROR_*negative error code, see itg320x_error_codes_t

◆ itg320x_init()

int itg320x_init ( itg320x_t dev,
const itg320x_params_t params 
)

Initialize the ITG320X sensor device.

This function resets the sensor and initializes the sensor according to given initialization parameters. All registers are reset to default values.

Parameters
[in]devdevice descriptor of ITG320X sensor to be initialized
[in]paramsITG320X initialization parameters
Return values
ITG320X_OKon success
ITG320X_ERROR_*a negative error code on error, see itg320x_error_codes_t

◆ 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.

This function activates the DRDY interrupt and initializes the pin defined as the interrupt pin in the initialization parameters of the device. The cb parameter specifies the function, along with an optional argument arg, which is called when a DRDY interrupt is triggered.

Warning
The given callback function cb is executed in interrupt context. Make sure not to call any driver API function in that context.
Note
This function is only available when module itg320x_int is enabled.
Parameters
[in]devdevice descriptor of ITG320X sensor
[in]cbfunction called when DRDY interrupt is triggered
[in]argargument for the callback function

◆ itg320x_power_down()

int itg320x_power_down ( itg320x_t dev)

Power down the sensor.

Changes the sensor operation mode to sleep mode in which almost all including the gyros are switched off.

Parameters
[in]devDevice descriptor of ITG320X device to read from
Return values
ITG320X_OKon success
ITG320X_ERROR_*a negative error code on error, see itg320x_error_codes_t

◆ itg320x_power_up()

int itg320x_power_up ( itg320x_t dev)

Power up the sensor.

Swichtes the sensor back into active operation mode. It takes up to 20 ms since the gyros have to be switched on again.

Parameters
[in]devDevice descriptor of ITG320X device to read from
Return values
ITG320X_OKon success
ITG320X_ERROR_*a negative error code on error, see itg320x_error_codes_t

◆ 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.

Raw magnetometer data are read from the sensor and normalized with respect to full scale +-2000 dps. Angular rate values are given in tenths of a degrees per second:

Parameters
[in]devdevice descriptor of ITG320X sensor
[out]dataresult vector in tenths of a degrees per second
Return values
ITG320X_OKon success
ITG320X_ERROR_*a negative error code on error, see itg320x_error_codes_t

◆ 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.

Parameters
[in]devdevice descriptor of ITG320X sensor
[out]rawraw data vector
Return values
ITG320X_OKon success
ITG320X_ERROR_*a negative error code on error, see itg320x_error_codes_t

◆ itg320x_read_temp()

int itg320x_read_temp ( const itg320x_t dev,
int16_t *  temp 
)

Read temperature in tenths of a degree Celsius.

Parameters
[in]devdevice descriptor of ITG320X sensor
[out]temptemperature tenths of a degree Celsius
Return values
ITG320X_OKon success
ITG320X_ERROR_*a negative error code on error, see itg320x_error_codes_t