/* ANY-LICENSE V1.0 ---------------- You can use these files under any license approved by the Open Source Initiative, preferrably one of the popular licenses, as long as the license you choose is compatible to the dependencies of these files. See http://www.opensource.org/licenses/ for a list of approved licenses. Author: Martin Furter Project: Tins AVR Lib Repository: http://repos.borg.ch/projects/tins_avr_lib/trunk Copyright: 2016 */ #include #include #include uint8_t lm75_read_temp( uint8_t addr, int16_t* v ) { uint8_t data[2]; addr = LM75_BASE_ADDRESS | (addr & 7); data[0] = LM75_REG_TEMPERATURE; if( !i2c_write( addr, 1, data ) ) { return false; } if( !i2c_read( addr, 2, data, true ) ) { return false; } *v = (data[0] << 8) | data[1]; return true; } uint8_t lm75_read_temp_quick( uint8_t addr, int16_t* v ) { uint8_t data[2]; addr = LM75_BASE_ADDRESS | (addr & 7); if( !i2c_read( addr, 2, data, true ) ) { return false; } return true; } uint8_t lm75_set_config( uint8_t addr, uint8_t cfg ) { uint8_t data[2]; addr = LM75_BASE_ADDRESS | (addr & 7); data[0] = LM75_REG_CONFIGURATION; data[1] = cfg & 0x1F; return i2c_write( addr, 2, data ); #if 0 uint8_t data[2]; addr = LM75_BASE_ADDRESS | (addr & 7); data[0] = LM75_REG_CONFIGURATION; if( !i2c_write( addr, 1, data ) ) { return false; } data[0] = cfg & 0x1F; return i2c_write( addr, 2, data ); #endif } uint8_t lm75_set_t_hyst( uint8_t addr, int16_t v ) { uint8_t data[3]; addr = LM75_BASE_ADDRESS | (addr & 7); data[0] = LM75_REG_T_HYSTERESIS; data[1] = v >> 8; data[2] = v; return i2c_write( addr, 3, data ); #if 0 uint8_t data[2]; addr = LM75_BASE_ADDRESS | (addr & 7); data[0] = LM75_REG_T_HYSTERESIS; if( !i2c_write( addr, 1, data ) ) { return false; } data[0] = v >> 8; data[1] = v; return i2c_write( addr, 2, data ); #endif } uint8_t lm75_set_t_os( uint8_t addr, int16_t v ) { uint8_t data[3]; addr = LM75_BASE_ADDRESS | (addr & 7); data[0] = LM75_REG_T_OS; data[1] = v >> 8; data[2] = v; return i2c_write( addr, 3, data ); #if 0 uint8_t data[2]; addr = LM75_BASE_ADDRESS | (addr & 7); data[0] = LM75_REG_T_OS; if( !i2c_write( addr, 1, data ) ) { return false; } data[0] = v >> 8; data[1] = v; return i2c_write( addr, 2, data ); #endif }