1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <common.h>
19#include <i2c.h>
20#include <dtt.h>
21
22#define ADT7460_ADDRESS 0x2c
23#define ADT7460_INVALID 128
24#define ADT7460_CONFIG 0x40
25#define ADT7460_REM1_TEMP 0x25
26#define ADT7460_LOCAL_TEMP 0x26
27#define ADT7460_REM2_TEMP 0x27
28
29int dtt_read(int sensor, int reg)
30{
31 u8 dir = reg;
32 u8 data;
33
34 if (i2c_read(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
35 return -1;
36 if (data == ADT7460_INVALID)
37 return -1;
38
39 return data;
40}
41
42int dtt_write(int sensor, int reg, int val)
43{
44 u8 dir = reg;
45 u8 data = val;
46
47 if (i2c_write(ADT7460_ADDRESS, dir, 1, &data, 1) == -1)
48 return -1;
49
50 return 0;
51}
52
53int dtt_init(void)
54{
55 printf("ADT7460 at I2C address 0x%2x\n", ADT7460_ADDRESS);
56
57 if (dtt_write(0, ADT7460_CONFIG, 1) == -1) {
58 puts("Error initialiting ADT7460\n");
59 return -1;
60 }
61
62 return 0;
63}
64
65int dtt_get_temp(int sensor)
66{
67 int aux;
68 u8 table[] =
69 { ADT7460_REM1_TEMP, ADT7460_LOCAL_TEMP, ADT7460_REM2_TEMP };
70
71 if (sensor > 2) {
72 puts("DTT sensor does not exist\n");
73 return -1;
74 }
75
76 aux = dtt_read(0, table[sensor]);
77 if (aux == -1) {
78 puts("DTT temperature read failed\n");
79 return -1;
80 }
81
82 return aux;
83}
84