LibDriver LM75B
Loading...
Searching...
No Matches
driver_lm75b_interrupt.c
Go to the documentation of this file.
1
37
39
40static lm75b_handle_t gs_handle;
41
54 float low_threshold, float high_threshold)
55{
56 uint8_t res;
57 uint16_t reg;
58
59 /* link interface function */
67
68 /* set addr pin */
69 res = lm75b_set_addr_pin(&gs_handle, addr);
70 if (res != 0)
71 {
72 lm75b_interface_debug_print("lm75b: set addr pin failed.\n");
73
74 return 1;
75 }
76
77 /* lm75b init */
78 res = lm75b_init(&gs_handle);
79 if (res != 0)
80 {
81 lm75b_interface_debug_print("lm75b: init failed.\n");
82
83 return 1;
84 }
85
86 /* set interrupt mode */
87 res = lm75b_set_interrupt_mode(&gs_handle, mode);
88 if (res != 0)
89 {
90 lm75b_interface_debug_print("lm75b: set interrupt mode failed.\n");
91 (void)lm75b_deinit(&gs_handle);
92
93 return 1;
94 }
95
96 /* set fault queue 1 */
98 if (res != 0)
99 {
100 lm75b_interface_debug_print("lm75b: set fault queue failed.\n");
101 (void)lm75b_deinit(&gs_handle);
102
103 return 1;
104 }
105
106 /* set os polarity low */
108 if (res != 0)
109 {
110 lm75b_interface_debug_print("lm75b: set os polarity failed.\n");
111 (void)lm75b_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* over temperature threshold convert to register */
117 res = lm75b_over_temperature_threshold_convert_to_register(&gs_handle, high_threshold, (uint16_t *)&reg);
118 if (res != 0)
119 {
120 lm75b_interface_debug_print("lm75b: over temperature threshold convert to register failed.\n");
121 (void)lm75b_deinit(&gs_handle);
122
123 return 1;
124 }
125
126 /* set over temperature threshold */
127 res = lm75b_set_over_temperature_threshold(&gs_handle, reg);
128 if (res != 0)
129 {
130 lm75b_interface_debug_print("lm75b: set over temperature threshold failed.\n");
131 (void)lm75b_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* hysteresis convert to register */
137 res = lm75b_hysteresis_convert_to_register(&gs_handle, low_threshold, (uint16_t *)&reg);
138 if (res != 0)
139 {
140 lm75b_interface_debug_print("lm75b: hysteresis convert to register failed.\n");
141 (void)lm75b_deinit(&gs_handle);
142
143 return 1;
144 }
145
146 /* set hysteresis */
147 res = lm75b_set_hysteresis(&gs_handle, reg);
148 if (res != 0)
149 {
150 lm75b_interface_debug_print("lm75b: set hysteresis failed.\n");
151 (void)lm75b_deinit(&gs_handle);
152
153 return 1;
154 }
155
156 /* set normal mode */
157 res = lm75b_set_mode(&gs_handle, LM75B_MODE_NORMAL);
158 if (res != 0)
159 {
160 lm75b_interface_debug_print("lm75b: set mode failed.\n");
161 (void)lm75b_deinit(&gs_handle);
162
163 return 1;
164 }
165
166 return 0;
167}
168
177uint8_t lm75b_interrupt_read(float *s)
178{
179 uint16_t raw;
180
181 /* read adc data */
182 if (lm75b_read(&gs_handle, (uint16_t *)&raw, (float *)s) != 0)
183 {
184 return 1;
185 }
186 else
187 {
188 return 0;
189 }
190}
191
200{
201 uint8_t res;
202
203 /* set mode */
204 res = lm75b_set_mode(&gs_handle, LM75B_MODE_SHUTDOWN);
205 if (res != 0)
206 {
207 return 1;
208 }
209
210 /* close lm75b */
211 if (lm75b_deinit(&gs_handle) != 0)
212 {
213 return 1;
214 }
215 else
216 {
217 return 0;
218 }
219}
driver lm75b interrupt header file
struct lm75b_handle_s lm75b_handle_t
lm75b handle structure definition
uint8_t lm75b_set_mode(lm75b_handle_t *handle, lm75b_mode_t mode)
set the chip mode
lm75b_address_t
lm75b address enumeration definition
uint8_t lm75b_read(lm75b_handle_t *handle, uint16_t *raw, float *s)
read data from the chip
uint8_t lm75b_set_addr_pin(lm75b_handle_t *handle, lm75b_address_t addr_pin)
set the iic address pin
uint8_t lm75b_init(lm75b_handle_t *handle)
initialize the chip
uint8_t lm75b_deinit(lm75b_handle_t *handle)
close the chip
lm75b_os_operation_mode_t
lm75b os operation enumeration definition
@ LM75B_MODE_NORMAL
@ LM75B_MODE_SHUTDOWN
@ LM75B_FAULT_QUEUE_1
@ LM75B_OS_POLARITY_LOW
uint8_t lm75b_interrupt_deinit(void)
interrupt example deinit
uint8_t lm75b_interrupt_init(lm75b_address_t addr, lm75b_os_operation_mode_t mode, float low_threshold, float high_threshold)
interrupt example init
uint8_t lm75b_interrupt_read(float *s)
interrupt example read
uint8_t lm75b_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t lm75b_interface_iic_init(void)
interface iic bus init
void lm75b_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t lm75b_interface_iic_deinit(void)
interface iic bus deinit
uint8_t lm75b_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void lm75b_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t lm75b_hysteresis_convert_to_register(lm75b_handle_t *handle, float c, uint16_t *reg)
convert the hysteresis value to the register data
uint8_t lm75b_set_hysteresis(lm75b_handle_t *handle, uint16_t hysteresis)
set the hysteresis value
uint8_t lm75b_set_os_polarity(lm75b_handle_t *handle, lm75b_os_polarity_t polarity)
set the chip os polarity
uint8_t lm75b_set_interrupt_mode(lm75b_handle_t *handle, lm75b_os_operation_mode_t mode)
set the chip interrupt mode
uint8_t lm75b_set_fault_queue(lm75b_handle_t *handle, lm75b_fault_queue_t fault_queue)
set the chip fault queue
uint8_t lm75b_set_over_temperature_threshold(lm75b_handle_t *handle, uint16_t threshold)
set the over temperature threshold
uint8_t lm75b_over_temperature_threshold_convert_to_register(lm75b_handle_t *handle, float c, uint16_t *reg)
convert the over temperature threshold to the register data