First version of new i2c bitbang API.
[bertos.git] / bertos / drv / lm75.c
index 2828f3e18f3573dfd29f554803b620c3be7d98b5..5d24e0ae520224b348727e016982d0d1b7a2e64d 100644 (file)
@@ -43,6 +43,7 @@
 #include "cfg/cfg_lm75.h"
 
 #include <cfg/debug.h>
+#include <cfg/module.h>
 
 // Define logging setting (for cfg/log.h module).
 #define LOG_LEVEL   LM75_LOG_LEVEL
 #include <cfg/log.h>
 
 #include <drv/i2c.h>
+#include <drv/ntc.h> // Macro and data type to manage celsius degree
 
 #define SELECT_ADDRESS(addr)   LM75_ADDRESS_BYTE | (addr << 1)
 
-deci_celsius_t lm75_read(addr_t sens_addr)
+deg_t lm75_read(uint8_t sens_addr)
 {
        uint8_t data[2];
        int16_t degree;
        int16_t deci_degree;
 
-       i2c_start_w(SELECT_ADDRESS(sens_addr));
-       i2c_put(LM75_PAD_BYTE);
-       i2c_start_r(SELECT_ADDRESS(sens_addr));
-       i2c_recv(data, sizeof(data));
+       if( !(i2c_start_w(SELECT_ADDRESS(sens_addr))
+               && i2c_put(LM75_PAD_BYTE)
+               && i2c_start_r(SELECT_ADDRESS(sens_addr))) )
+       {
+               i2c_stop();
+               return EOF;
+       }
+
+       if ( !i2c_recv(data, sizeof(data)) )
+       {
+               i2c_stop();
+               return EOF;
+       }
+       i2c_stop();
 
        degree = (int16_t)data[0];
        deci_degree = (int16_t)(((data[1] >> 7) & 1 ) * 5);