KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
max123x.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2012-2014 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : max123x.h
11  * Created : 28 jul. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #ifndef MAX123X_H_
16 #define MAX123X_H_
17 
18 /**
19  * @file
20  *
21  * @ingroup i2cdrivers
22  *
23  * MAX123x multichannel ADC driver.
24  */
25 
26 #include <stdbool.h>
27 
28 #include "util/macro.h"
29 
30 #include "drv/wb/i2c.h"
31 
32 #define MAX123X_MAX_VALUE 0x0FFF //! Max value of the ADC
33 
34 #define MAX123X_REF_VDD_AIN 0x0 //! Reference is Vdd (default), AIN3/11 is input
35 #define MAX123X_REF_EXT_RIN 0x2 //! Reference is the external reference on AIN3/11
36 #define MAX123X_REF_INT_AIN 0x4 //! Internal ref., AIN3/11 is input channel
37 #define MAX123X_REF_INT_AIN_REF 0x5 //! Internal ref. + int. ref. state
38 #define MAX123X_REF_INT_ROUT 0x6 //! Internal ref., AIN3/11 is reference output
39 #define MAX123X_REF_INT_ROUT_REF 0x7 //! Internal ref. + state, AIN3/11 is ref. output
40 
41 #define MAX1236_MAX_CHAN 3 //! Max channel MAX1236
42 #define MAX1237_MAX_CHAN 3 //! Max channel MAX1237
43 #define MAX1238_MAX_CHAN 11 //! Max channel MAX1238
44 #define MAX1239_MAX_CHAN 11 //! Max channel MAX1239
45 #define MAX1236_MAX_CHAN_REF 2 //! Max channel MAX1236 with external reference
46 #define MAX1237_MAX_CHAN_REF 2 //! Max channel MAX1237 with external reference
47 #define MAX1238_MAX_CHAN_REF 10 //! Max channel MAX1238 with external reference
48 #define MAX1239_MAX_CHAN_REF 10 //! Max channel MAX1239 with external reference
49 
50 
51 /**
52  * Writes the setup register of the MAX123x.
53  *
54  * @param dev The I2C device
55  * @param addr The I2C component address
56  * @param ref Reference voltage setup
57  * @param extclk Use external clock
58  * @param bipolar Bipolar mode (+/- 1/2 Vref, else its 0-Vref.)
59  *
60  * @retval true Success
61  * @retval false Failure, check error module for error.
62  */
63 bool max123xSetup(I2C_Device * dev, i2cAddr addr, int ref, bool extclk, bool bipolar);
64 
65 /**
66  * Scan from analog input up to a given channel. Results will be stored in 'results' array.
67  *
68  * @param dev The I2C device.
69  * @param addr The I2C component register
70  * @param upToCh The last channel to convert (e.g. 3 will scan channel 0 to 3).
71  * @param results Results array, must be enough to include no. of channels.
72  *
73  * @retval true Success
74  * @retval false Failure, check error module for error.
75  */
76 bool max123xScanUpTo(I2C_Device * dev, i2cAddr addr, int upToCh, uint16_t * results);
77 
78 /**
79  * Performs a single conversion of a specific channel.
80  *
81  * @param dev The I2C device.
82  * @param addr The I2C component register
83  * @param ch The channel to convert
84  * @param result Pointer filled with the conversion value.
85  *
86  * @retval true Success
87  * @retval false Failure, check error module for error.
88  */
89 bool max123xConvert(I2C_Device * dev, i2cAddr addr, int ch, uint16_t * result);
90 
91 #endif /* MAX123X_H_ */
Structure defines OpenCores I2C Device.
Definition: dev_i2c.h:55
bool max123xConvert(I2C_Device *dev, i2cAddr addr, int ch, uint16_t *result)
Performs a single conversion of a specific channel.
Definition: max123x.c:56
uint8_t i2cAddr
I2C address type.
Definition: i2c.h:93
bool max123xSetup(I2C_Device *dev, i2cAddr addr, int ref, bool extclk, bool bipolar)
Writes the setup register of the MAX123x.
Definition: max123x.c:38
bool max123xScanUpTo(I2C_Device *dev, i2cAddr addr, int upToCh, uint16_t *results)
Scan from analog input up to a given channel.
Definition: max123x.c:68
Provides common macros.
OpenCores I2C device driver.