#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)
+#define LM75_ADDRESS_BYTE 0x91
+#define LM75_PAD_BYTE 0x0
-deci_celsius_t lm75_read(addr_t sens_addr)
+
+#if !CONFIG_I2C_DISABLE_OLD_API
+
+deg_t lm75_read_1(uint8_t sens_addr)
+{
+ return lm75_read_2(&local_i2c_old_api, sens_addr);
+}
+#endif /* !CONFIG_I2C_DISABLE_OLD_API */
+
+
+/*
+ * New API
+ */
+deg_t lm75_read_2(I2c *i2c, 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));
+ i2c_start_w(i2c, SELECT_ADDRESS(sens_addr), 1, I2C_NOSTOP);
+ i2c_putc(i2c, LM75_PAD_BYTE);
+ i2c_start_r(i2c, SELECT_ADDRESS(sens_addr), sizeof(data), I2C_STOP);
+ i2c_read(i2c, data, sizeof(data));
- degree = (uint16_t)data[0];
- deci_degree = (uint16_t)(((data[1] >> 7) & 1 ) * 5);
+ if (i2c_error(i2c))
+ return EOF;
+
+ degree = (int16_t)data[0];
+ deci_degree = (int16_t)(((data[1] >> 7) & 1 ) * 5);
LOG_INFO("[%d.%d C]\n", degree, deci_degree);
return degree * 10 + deci_degree;
}
-
-void lm75_init(void)
-{
- i2c_init();
- LOG_INFO("Init I2C module.\n");
-
- LM75_HW_INIT();
-}
-
-