KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ahrs.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : ahrs.h
11  * Created : 14 jun. 2013
12  * Author : Antonio Orzelli
13  */
14 
15 
16 #ifndef AHRS_H_
17 #define AHRS_H_
18 
19 #include "types.h"
20 #include "util/float.h"
21 
22 /**
23  * @file
24  *
25  * @ingroup i2cdrivers
26  *
27  * This driver is to read and configure the AHRS I2C sensor.
28  *
29  * Usage:
30  *
31  * @code
32  * AHRS_Data_Struct data;
33  *
34  * if (ahrsRead(I2C2, AHRS_I2C_ADDR, AHRS_DATA_ID, (uint8_t *)&data, sizeof(data))) {
35  * printf("\n\nYaw: %x %x %x %x \n", data.Yaw[0], data.Yaw[1], data.Yaw[2], data.Yaw[3]);
36  * printf("\n\nPitch: %x %x %x %x \n", data.Pitch[0], data.Pitch[1], data.Pitch[2], data.Pitch[3]);
37  * printf...
38  * }else{
39  * //print the error
40  * printf("Error reading AHRS:\n");
41  * if (errHas()){
42  * errPrint(true);
43  * }
44  * }
45  *
46  * @endcode
47  *
48  */
49 
50 #include "drv/wb/i2c.h"
51 #include "errorcode.h"
52 
53 #define E_AHRS_REGSDIFFER ( E_AHRS + 1 ) ///!< Invalid readout value.
54 #define E_AHRS_REGSDIFFER_DESCR "Returned register differs"
55 
56 #define AHRS_VALID_CNT_NUM 5000 ///< Number of measure to do before receiving accurate results
57 
58 
59 #define AHRS_REG_DATA 0x00
60 #define AHRS_REG_KALMAN_ENABLED 0x32
61 #define AHRS_REG_VERSION 0x33
62 
63 
64 
65 /**
66  * Switch on the AHRS.
67  */
68 void ahrsOn();
69 
70 /**
71  * Switch off the AHRS.
72  */
73 void ahrsOff();
74 
75 /**
76  * Writes an AHRS register
77  *
78  * @param dev I2C device
79  * @param addr The I2C address
80  * @param reg_addr The AHRS register address
81  * @param newvalue The value to set
82  * @param readback Pointer to float to place the resulting value in. Pointer may be NULL.
83  *
84  * @retval true Success
85  * @retval false Failure, see err module for error.
86  */
87 bool ahrsWriteReg(I2C_Device * dev, uint8_t addr, uint8_t reg_addr, f32_t newvalue, f32_t * readback);
88 
89 
90 /**
91  * Reads an AHRS register
92  *
93  * @param dev I2C device
94  * @param addr The I2C address
95  * @param reg_addr The AHRS register address
96  * @param value Pointer to float to place the register value in.
97  *
98  * @retval true Success
99  * @retval false Failure, see err module for error.
100  */
101 bool ahrsReadReg(I2C_Device * dev, uint8_t addr, uint8_t reg_addr, f32_t * value);
102 
103 
104 /**
105  * Reads the AHRS version
106  *
107  * @param dev I2C device
108  * @param addr The I2C address
109  * @paran version 8 bit integer to fill. First digit is the major version, second digit the minor
110  *
111  * @retval true Success
112  * @retval false Failure, see err module for error.
113  */
114 bool ahrsGetVersion(I2C_Device * dev, uint8_t addr, uint8_t * version);
115 
116 /**
117  * Reads all data from the AHRS.
118  *
119  * @param dev I2C device
120  * @param addr The I2C address
121  * @param data Pointer to the AHR Data structure to fill.
122  *
123  * @retval true Success
124  * @retval false Failure, see err module for error.
125  */
126 bool ahrsRead(I2C_Device * dev, uint8_t addr, CompassData * data);
127 
128 #endif /* AHRS_H_ */
void ahrsOff()
Switch off the AHRS.
Definition: ahrs.c:46
void ahrsOn()
Switch on the AHRS.
Definition: ahrs.c:41
bool ahrsGetVersion(I2C_Device *dev, uint8_t addr, uint8_t *version)
Reads the AHRS version.
Definition: ahrs.c:86
Structure defines OpenCores I2C Device.
Definition: dev_i2c.h:55
Special library for primitive IEEE 754 floating point handling without dragging all float support alo...
Structure defines data from a compass/tilt/gyro sensor.
Definition: types.h:22
bool ahrsWriteReg(I2C_Device *dev, uint8_t addr, uint8_t reg_addr, f32_t newvalue, f32_t *readback)
Writes an AHRS register.
Definition: ahrs.c:53
bool ahrsRead(I2C_Device *dev, uint8_t addr, CompassData *data)
Reads all data from the AHRS.
Definition: ahrs.c:99
uint32_t f32_t
32 bit representation for float.
Definition: float.h:30
This module is responsible for distributing error codes.
bool ahrsReadReg(I2C_Device *dev, uint8_t addr, uint8_t reg_addr, f32_t *value)
Reads an AHRS register.
Definition: ahrs.c:68
OpenCores I2C device driver.