9 static U8 lm75Address = LM75_ADDRESS;
10 static U8 lm75LastRegister = LM75_REGISTER_TEMPERATURE;
11 static U8 lm75Mode = 0;
16 static int lm75Read8 (U8 reg, int *value)
18 lm75LastRegister = reg;
21 if (i2cWriteBuffer (lm75Address, (U8 *) ®, sizeof (U8)))
24 return i2cReadBuffer (lm75Address, (U8 *) value, sizeof (U8));
27 static int lm75Write8 (U8 reg, int value)
31 buffer [0] = lm75LastRegister = reg;
34 return i2cWriteBuffer (lm75Address, buffer, sizeof (buffer));
38 // DANGER, WILL ROBINSON! 'value' is the desired temperature * 2, where
39 // the low bit indicates 0.5C or not. So for -50C degrees, we see -100.
40 // For -50.5C, we see -101.
42 static int lm75Read16 (U8 reg, int *value)
46 buffer [0] = lm75LastRegister = reg;
50 if (i2cWriteReadBuffer (lm75Address, buffer, sizeof (U8), sizeof (buffer)))
55 if (i2cWriteBuffer (lm75Address, (U8 *) ®, sizeof (U8)))
58 if (i2cReadBuffer (lm75Address, buffer, sizeof (buffer)))
63 // Sign extend negative numbers
65 *value = ((buffer [0] << 8) | buffer [1]) >> 7;
67 if (buffer [0] & 0x80)
73 static int lm75Write16 (U8 reg, int value)
79 buffer [0] = lm75LastRegister = reg;
80 buffer [1] = value >> 8;
83 return i2cWriteBuffer (lm75Address, buffer, sizeof (buffer));
87 // Don't call lm75Init() before tasker is started. The I2C routines use the
88 // newlib/syscalls.c _times function, which calls xTaskGetTickCount(), which
89 // hasn't been initialized yet.
93 return lm75ConfigWrite (0);
96 void lm75SetMode (int mode)
101 void lm75SetAddress (U8 address)
103 lm75Address = address;
106 int lm75ReRead (int *value)
110 if (lm75LastRegister == LM75_REGISTER_CONFIGURATION)
111 return i2cReadBuffer (lm75Address, (U8 *) value, sizeof (U8));
116 if (i2cReadBuffer (lm75Address, buffer, sizeof (buffer)))
119 *value = ((buffer [0] << 8) | buffer [1]) >> 7;
125 int lm75TemperatureRead (int *temp)
127 return lm75Read16 (LM75_REGISTER_TEMPERATURE, temp);
130 int lm75ConfigRead (int *configValue)
132 return lm75Read8 (LM75_REGISTER_CONFIGURATION, configValue);
135 int lm75ConfigWrite (int configValue)
137 return lm75Write8 (LM75_REGISTER_CONFIGURATION, configValue);
140 int lm75THYSTRead (int *thystValue)
142 return lm75Read16 (LM75_REGISTER_THYST, thystValue);
145 int lm75THYSTWrite (int thystValue)
147 return lm75Write16 (LM75_REGISTER_THYST, thystValue);
150 int lm75TOSTRead (int *thystValue)
152 return lm75Read16 (LM75_REGISTER_TOS, thystValue);
155 int lm75TOSWrite (int thystValue)
157 return lm75Write16 (LM75_REGISTER_TOS, thystValue);