-
Notifications
You must be signed in to change notification settings - Fork 0
/
ltc24xx.h
84 lines (71 loc) · 3.33 KB
/
ltc24xx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
* LTC24xx firmware
*
*******************************************************************************/
#ifndef _LTC24XX_H_INCLUDED
#define _LTC24XX_H_INCLUDED
#define LTC24XX_EN 0x20
#define LTC24XX_PRE 0x80
#define LTC24xx_SGL 0x10
#define LTC24xx_SIGN 0x08
#define LTC24xx_CH_0 0x00
#define LTC24xx_CH_1 0x01
#define LTC24xx_EN2 0x80
#define LTC24xx_IM 0x40
#define LTC24xx_FA 0x20
#define LTC24xx_FB 0x10
#define LTC24xx_SPD 0x08
#define LTC24xx_GS2 0x04
#define LTC24xx_GS1 0x02
#define LTC24xx_GS0 0x01
#define LTC24xx_GAIN1 (0)
#define LTC24xx_GAIN4 (LTC24xx_GS0)
#define LTC24xx_GAIN8 (LTC24xx_GS1)
#define LTC24xx_GAIN16 (LTC24xx_GS1|LTC24xx_GS0)
#define LTC24xx_GAIN32 (LTC24xx_GS2)
#define LTC24xx_GAIN64 (LTC24xx_GS2|LTC24xx_GS0)
#define LTC24xx_GAIN128 (LTC24xx_GS2|LTC24xx_GS1)
#define LTC24xx_GAIN264 (LTC24xx_GS2|LTC24xx_GS1|LTC24xx_GS0)
//address for all LTC24XX ADC's
#define LTC24XX_GLOBAL_ADDR 0x77
/*******************************************************************************
* setup_adc
* This is the two bytes that get written to LTC24XX that set the input channel,
* gain, speed, and rejection ratio or uses the temperature input
*******************************************************************************/
int setup_adc(short addr, short channel, short enable_2, short gain, short speed, short rejection, short temp_in);
/*******************************************************************************
* adc2long
* convert returned data from 16bit LTC24xx ADC into a signed long integer
*******************************************************************************/
long adc_to_long(unsigned char *dat);
/*******************************************************************************
* read_adc
* Reads the magnetometer of a given its address
* returns the long integer that is assembled from the registers
* or it will return -70000 for a NACK or -80000 for other I2C errors
*******************************************************************************/
long read_adc(short addr);
/*******************************************************************************
* set_channel
* chose between channel 0 (0+,1-) and channel 1 (2+,3-)
*******************************************************************************/
int set_channel(short addr,short channel);
/*******************************************************************************
* set_gain
* chose between channel 0 (0+,1-) and channel 1 (2+,3-)
* to set the gain
*******************************************************************************/
int set_gain(short addr,short channel,short gain);
/*******************************************************************************
* set_all_gain
* chose between channel 0 (0+,1-) and channel 1 (2+,3-)
* and set the gain on all LTC24XX devices
*******************************************************************************/
int set_all_gain(short channel,short gain);
/******************************************************************************
* test_ltc24xx
* Function that verifies the firmware code is functioning as expected
******************************************************************************/
int test_ltc24xx(char **argv, unsigned short argc);
#endif