/** * \file * * * \brief LM75 sensor temperature family. * * \author Daniele Basile * */ #include "lm75.h" #include "hw/hw_lm75.h" #include "cfg/cfg_lm75.h" #include #include // Define logging setting (for cfg/log.h module). #define LOG_LEVEL LM75_LOG_LEVEL #define LOG_FORMAT LM75_LOG_FORMAT #include #include #include // 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 #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(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)); 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; }