source: rtems/cpukit/dev/include/dev/i2c/ti-ads-16bit-adc.h @ 849500d

5
Last change on this file since 849500d was 849500d, checked in by Chris Johns <chrisj@…>, on 08/16/17 at 05:10:33

dev/i2c: Add I2C device support for FPGA Slave, LM25066A, TMP112, ADS1113, ADS1114 and ADS1115

Closes #3101.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (c) 2016-2017 Chris Johns <chrisj@rtems.org>
3 * All rights reserved.
4 *
5 * The license and distribution terms for this file may be
6 * found in the file LICENSE in this distribution or at
7 * http://www.rtems.org/license/LICENSE.
8 */
9
10/*
11 * TI ADS1113 and ADS1115.
12 *   http://www.ti.com/product/ads1113/description
13 */
14
15#ifndef TI_ADS1113_ADS1115_H
16#define TI_ADS1113_ADS1115_H
17
18#include <dev/i2c/i2c.h>
19
20/*
21 * Supported devices. Please others once tested.
22 */
23typedef enum {
24  TI_ADS1113,
25  TI_ADS1114,
26  TI_ADS1115
27} ti_ads_adc;
28
29/*
30 * Multiplexer interface. Avalable on ADS1115.
31 */
32typedef enum {
33  TI_ADS_MUX_ApA0_AnA1  = 0,    /* default */
34  TI_ADS_MUX_ApA0_AnA3  = 1,
35  TI_ADS_MUX_ApA1_AnA3  = 2,
36  TI_ADS_MUX_ApA2_AnA3  = 3,
37  TI_ADS_MUX_ApA0_AnGND = 4,
38  TI_ADS_MUX_ApA1_AnGND = 5,
39  TI_ADS_MUX_ApA2_AnGND = 6,
40  TI_ADS_MUX_ApA3_AnGND = 7
41} ti_ads_adc_mux;
42
43/*
44 * Programmable Gain Amplifier. Avalable on ADS1114 and ADS1115.
45 */
46typedef enum {
47  TI_ADS_PGA_FS_6_144V   = 0,
48  TI_ADS_PGA_FS_4_096V   = 1,
49  TI_ADS_PGA_FS_2_048V   = 2,    /* default */
50  TI_ADS_PGA_FS_1_024V   = 3,
51  TI_ADS_PGA_FS_0_512V   = 4,
52  TI_ADS_PGA_FS_0_256V   = 5,
53  TI_ADS_PGA_FS_0_256V_2 = 6,
54  TI_ADS_PGA_FS_0_256V_3 = 7,
55} ti_ads_adc_pga;
56
57/*
58 * Mode.
59 */
60typedef enum {
61  TI_ADS_MODE_CONTINUOUS  = 0,
62  TI_ADS_MODE_SINGLE_SHOT = 1,    /* default */
63} ti_ads_adc_mode;
64
65/*
66 * Data rate.
67 */
68typedef enum {
69  TI_ADS_DATARATE_8SPS   = 0,
70  TI_ADS_DATARATE_16SPS  = 1,
71  TI_ADS_DATARATE_32SPS  = 2,
72  TI_ADS_DATARATE_64SPS  = 3,
73  TI_ADS_DATARATE_128SPS = 4,    /* default */
74  TI_ADS_DATARATE_250SPS = 5,
75  TI_ADS_DATARATE_475SPS = 6,
76  TI_ADS_DATARATE_860SPS = 7,
77} ti_ads_adc_data_rate;
78
79/*
80 * Comparitor interface. Avalable on ADS1114 and ADS1115.
81 *
82 * Create a value to write.
83 */
84#define TI_ADS_COMP_MODE_HYSTERESIS  (0 << 4)    /* default */
85#define TI_ADS_COMP_MODE_WINDOW      (1 << 4)
86#define TI_ADS_COMP_POL_ACTIVE_LOW   (0 << 3)    /* default */
87#define TI_ADS_COMP_POL_ACTIVE_HIGH  (1 << 3)
88#define TI_ADS_COMP_LAT_NON_LATCHING (0 << 2)    /* default */
89#define TI_ADS_COMP_LAT_LATCHING     (1 << 2)
90#define TI_ADS_COMP_QUE_DISABLE_COMP (3 << 0)    /* default */
91#define TI_ADS_COMP_QUE_AFTER_4      (2 << 0)
92#define TI_ADS_COMP_QUE_AFTER_2      (1 << 0)
93#define TI_ADS_COMP_QUE_AFTER_1      (0 << 0)
94
95/*
96 * IO control interface.
97 *
98 * Note: if in Power-down single-shot mode (default) a conversion requires the
99 *       device to power up and perform a conversion and this can take
100 *       while. The TI_ADS_ADC_GET_CONV_WAIT call sets the micro-seconds to
101 *       wait between polls. The actual rate will depend on the system tick.
102 */
103#define TI_ADS_ADC_GET_CONVERSION  (I2C_DEV_IO_CONTROL + 0)
104#define TI_ADS_ADC_SET_MUX         (I2C_DEV_IO_CONTROL + 1)
105#define TI_ADS_ADC_SET_PGA         (I2C_DEV_IO_CONTROL + 2)
106#define TI_ADS_ADC_SET_MODE        (I2C_DEV_IO_CONTROL + 3)
107#define TI_ADS_ADC_SET_DATA_RATE   (I2C_DEV_IO_CONTROL + 4)
108#define TI_ADS_ADC_SET_COMP        (I2C_DEV_IO_CONTROL + 5)
109#define TI_ADS_ADC_SET_LO_THRESH   (I2C_DEV_IO_CONTROL + 6)
110#define TI_ADS_ADC_SET_HI_THRESH   (I2C_DEV_IO_CONTROL + 7)
111#define TI_ADS_ADC_SET_CONV_WAIT   (I2C_DEV_IO_CONTROL + 8)
112
113/*
114 * Register the device.
115 */
116int i2c_dev_register_ti_ads_adc(const char* bus_path,
117                                const char* dev_path,
118                                uint16_t    address,
119                                ti_ads_adc  device);
120
121/*
122 * Perform a conversion. If the mode is single shot a single shot conversion is
123 * started and the call waits for the conversion to complete.
124 */
125static inline int
126ti_ads_adc_convert(int fd, uint16_t* sample)
127{
128  return ioctl(fd, TI_ADS_ADC_GET_CONVERSION, sample);
129}
130
131/*
132 * Set the multipler.
133 */
134static inline int
135ti_ads_adc_set_mux(int fd, ti_ads_adc_mux mux)
136{
137  return ioctl(fd, TI_ADS_ADC_SET_MUX, (void *)(uintptr_t) mux);
138}
139
140/*
141 * Set the PGA.
142 */
143static inline int
144ti_ads_adc_set_pga(int fd, ti_ads_adc_pga pga)
145{
146  return ioctl(fd, TI_ADS_ADC_SET_PGA, (void *)(uintptr_t) pga);
147}
148
149/*
150 * Set the mode.
151 */
152static inline int
153ti_ads_adc_set_mode(int fd, ti_ads_adc_mode mode)
154{
155  return ioctl(fd, TI_ADS_ADC_SET_MODE, (void *)(uintptr_t) mode);
156}
157
158/*
159 * Set the data rate.
160 */
161static inline int
162ti_ads_adc_set_data_rate(int fd, ti_ads_adc_data_rate rate)
163{
164  return ioctl(fd, TI_ADS_ADC_SET_DATA_RATE, (void *)(uintptr_t) rate);
165}
166
167/*
168 * Configure the comparator.
169 */
170static inline int
171ti_ads_adc_set_comparator(int fd, uint16_t comp)
172{
173  return ioctl(fd, TI_ADS_ADC_SET_COMP, (void *)(uintptr_t) comp);
174}
175
176/*
177 * Set the lower threshold.
178 */
179static inline int
180ti_ads_adc_set_low_threshold(int fd, uint16_t level)
181{
182  return ioctl(fd, TI_ADS_ADC_SET_LO_THRESH, (void *)(uintptr_t) level);
183}
184
185/*
186 * Set the upper threshold.
187 */
188static inline int
189ti_ads_adc_set_high_threshold(int fd, uint16_t level)
190{
191  return ioctl(fd, TI_ADS_ADC_SET_HI_THRESH, (void *)(uintptr_t) level);
192}
193
194/*
195 * Set the conversion poll wait period.
196 */
197static inline int
198ti_ads_adc_set_conversion_poll_wait(int fd, uint32_t micro_seconds)
199{
200  return ioctl(fd, TI_ADS_ADC_SET_CONV_WAIT, (void *)(uintptr_t) micro_seconds);
201}
202
203#endif
Note: See TracBrowser for help on using the repository browser.