no-OS
Loading...
Searching...
No Matches
lm75.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef __LM75_H__
34#define __LM75_H__
35#include "no_os_util.h"
36#include "no_os_i2c.h"
37
38#define LM75_DEVICE_SIGNATURE 0x7f4c4d75
39#define LM75_HW_ADDR 0b1001000
40#define LM75_FRAME_SIZE 3
41
42#define LM75_ADDR_MASK 0xFFFF
43#define LM75_SENSOR_DATA_MASK 0xFF80
44
45#define LM75_MIN_TEMP -55
46#define LM75_MAX_TEMP 125
47
48#define LM75_MIN_TEMP_MILLICEL (LM75_MIN_TEMP * 1000)
49#define LM75_MAX_TEMP_MILLICEL (LM75_MAX_TEMP * 1000)
50
57
62
68
73
80
82 uint8_t fault_count;
83 /* os_polarity here is for comparator mode which is
84 * what the driver will initialize the LM75 by default. */
87};
88
89struct lm75_dev {
90 uint32_t signature;
92};
93
94#define LM75_CONFIG_SHUTDOWN NO_OS_BIT(0)
95#define LM75_CONFIG_INT_EN NO_OS_BIT(1)
96#define LM75_CONFIG_OS_POLARITY NO_OS_BIT(2)
97#define LM75_CONFIG_FAULT_QUEUE NO_OS_GENMASK(4, 3)
98
99#define LM75_HYST_POR_VALUE 0x4b00
100#define LM75_OS_POR_VALUE 0x5000
101
102#define LM75_TEMP_MASK NO_OS_GENMASK(15, 7)
103
104static inline bool lm75_is_lm75(struct lm75_dev *dev)
105{
106 if (!dev)
107 return false;
108 return dev->signature == LM75_DEVICE_SIGNATURE;
109}
110
111int lm75_init(struct lm75_dev **devpp,
112 struct lm75_init_param *ip);
113int lm75_remove(struct lm75_dev *dev);
114
115int lm75_read_temperature(struct lm75_dev *dev,
116 enum lm75_temperature_type whence,
117 uint16_t *val);
118int lm75_write_temperature(struct lm75_dev *dev,
119 enum lm75_temperature_type whence,
120 uint16_t val);
121
122int lm75_raw_to_millicelsius(const uint16_t raw_temp);
123uint16_t lm75_millicelsius_to_raw(const int millicelsius);
124int lm75_is_shutdown(struct lm75_dev *dev, bool *flag);
125int lm75_shutdown(struct lm75_dev *dev, bool flag);
126
127int lm75_read_mode(struct lm75_dev *dev, enum lm75_mode *mode);
128int lm75_write_mode(struct lm75_dev *dev, enum lm75_mode mode);
129
130int lm75_read_os_polarity(struct lm75_dev *dev, enum lm75_os_polarity *pol);
131int lm75_write_os_polarity(struct lm75_dev *dev, enum lm75_os_polarity pol);
132
133int lm75_read_fault_queue(struct lm75_dev *dev, enum lm75_fault_queue *fq);
134int lm75_write_fault_queue(struct lm75_dev *dev, enum lm75_fault_queue fq);
135
136#endif /* __LM75_H__ */
int lm75_shutdown(struct lm75_dev *dev, bool flag)
Put the LM75 into normal or shutdown operation.
Definition lm75.c:626
int lm75_write_temperature(struct lm75_dev *dev, enum lm75_temperature_type whence, uint16_t val)
Write temperature data.
Definition lm75.c:467
int lm75_write_fault_queue(struct lm75_dev *dev, enum lm75_fault_queue fq)
Write fault count.
Definition lm75.c:700
#define LM75_DEVICE_SIGNATURE
Definition lm75.h:38
int lm75_init(struct lm75_dev **devpp, struct lm75_init_param *ip)
Initialize LM75 device driver.
Definition lm75.c:333
int lm75_read_fault_queue(struct lm75_dev *dev, enum lm75_fault_queue *fq)
Read fault count.
Definition lm75.c:687
int lm75_remove(struct lm75_dev *dev)
Uninitialize LM75 device driver.
Definition lm75.c:396
int lm75_write_os_polarity(struct lm75_dev *dev, enum lm75_os_polarity pol)
Write the polarity of the over temperature line.
Definition lm75.c:674
int lm75_read_mode(struct lm75_dev *dev, enum lm75_mode *mode)
Read the event mode of LM75, whether interrupt based or comparator.
Definition lm75.c:637
int lm75_read_os_polarity(struct lm75_dev *dev, enum lm75_os_polarity *pol)
Read the over temperature line polarity setting.
Definition lm75.c:661
lm75_mode
Definition lm75.h:69
@ lm75_interrupt_mode
Definition lm75.h:71
@ lm75_comparator_mode
Definition lm75.h:70
int lm75_write_mode(struct lm75_dev *dev, enum lm75_mode mode)
Change the event mode of LM75, whether interrupt based or comparator.
Definition lm75.c:648
int lm75_raw_to_millicelsius(const uint16_t raw_temp)
Convert a raw sensor data to milliCelsius value.
Definition lm75.c:497
lm75_temperature_type
Definition lm75.h:63
@ lm75_over_temperature
Definition lm75.h:66
@ lm75_hysteresis_temperature
Definition lm75.h:65
@ lm75_die_temperature
Definition lm75.h:64
int lm75_is_shutdown(struct lm75_dev *dev, bool *flag)
Read if LM75 is in shutdown or normal operation.
Definition lm75.c:598
lm75_register
Definition lm75.h:51
@ lm75_temperature_reg
Definition lm75.h:52
@ lm75_hyst_reg
Definition lm75.h:54
@ lm75_os_reg
Definition lm75.h:55
@ lm75_configuration_reg
Definition lm75.h:53
uint16_t lm75_millicelsius_to_raw(const int millicelsius)
Convert a milliCelsius value to raw sensor data that can be written to an LM75 device.
Definition lm75.c:518
int lm75_read_temperature(struct lm75_dev *dev, enum lm75_temperature_type whence, uint16_t *val)
Read temperature data.
Definition lm75.c:423
lm75_os_polarity
Definition lm75.h:58
@ lm75_os_active_low
Definition lm75.h:59
@ lm75_os_active_high
Definition lm75.h:60
lm75_fault_queue
Definition lm75.h:74
@ lm75_6_fault
Definition lm75.h:78
@ lm75_4_fault
Definition lm75.h:77
@ lm75_2_fault
Definition lm75.h:76
@ lm75_1_fault
Definition lm75.h:75
Header file of I2C Interface.
Header file of utility functions.
Definition lm75.h:89
struct no_os_i2c_desc * i2c
Definition lm75.h:91
uint32_t signature
Definition lm75.h:90
Definition lm75.h:81
enum lm75_os_polarity os_polarity
Definition lm75.h:85
uint8_t fault_count
Definition lm75.h:82
struct no_os_i2c_init_param * i2c_ip
Definition lm75.h:86
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52