10 #include "lib/sensors.h"
11 #include "dev/tmp102-sensor.h"
26 static void set_configuration(uint8_t rate,
bool precision) {
27 uint8_t tx_buf[] = {TMP102_REGISTER_CONFIGURATION,
29 (precision ? TMP102_CONF_EXTENDED_MODE : 0) | ((rate << 6) & TMP102_CONF_CONVERSION_RATE)
32 i2c_transmitinit(TMP102_ADDR, 3, tx_buf);
36 static int value(
int type) {
37 uint8_t reg = TMP102_REGISTER_TEMPERATURE;
39 int16_t temperature = 0;
42 i2c_transmitinit(TMP102_ADDR, 1, ®);
43 while (!i2c_transferred());
46 i2c_receiveinit(TMP102_ADDR, 2, temp);
47 while (!i2c_transferred());
50 temperature = ((temp[0] <<8) | (temp[1])) >> 4;
55 temperature = (100*temperature)/16;
60 static int status(
int type) {
70 static int configure(
int type,
int c) {
75 set_configuration(1,
false);
86 SENSORS_SENSOR(tmp102_sensor,
"Temperature", value, configure, status);