LibDriver MAX30205
Loading...
Searching...
No Matches
driver_max30205_interrupt.c
Go to the documentation of this file.
1
37
39
40static max30205_handle_t gs_handle;
41
53uint8_t max30205_interrupt_init(max30205_address_t addr_pin, max30205_interrupt_mode_t mode, float low, float high)
54{
55 uint8_t res;
56 int16_t low_threshold;
57 int16_t high_threshold;
58
59 /* link interface function */
67
68 /* set max30205 iic address */
69 res = max30205_set_addr_pin(&gs_handle, addr_pin);
70 if (res != 0)
71 {
72 max30205_interface_debug_print("max30205: set addr pin failed.\n");
73
74 return 1;
75 }
76
77 /* max30205 init */
78 res = max30205_init(&gs_handle);
79 if (res != 0)
80 {
81 max30205_interface_debug_print("max30205: init failed.\n");
82
83 return 1;
84 }
85
86 /* set data format */
88 if (res != 0)
89 {
90 max30205_interface_debug_print("max30205: set data format failed.\n");
91 (void)max30205_deinit(&gs_handle);
92
93 return 1;
94 }
95
96 /* set interrupt mode */
97 res = max30205_set_interrupt_mode(&gs_handle, mode);
98 if (res != 0)
99 {
100 max30205_interface_debug_print("max30205: set interrupt mode failed.\n");
101 (void)max30205_deinit(&gs_handle);
102
103 return 1;
104 }
105
106 /* set fault queue */
108 if (res != 0)
109 {
110 max30205_interface_debug_print("max30205: set fault queue failed.\n");
111 (void)max30205_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* set pin polarity */
118 if (res != 0)
119 {
120 max30205_interface_debug_print("max30205: set pin polarity failed.\n");
121 (void)max30205_deinit(&gs_handle);
122
123 return 1;
124 }
125
126 /* set bus timeout */
128 if (res != 0)
129 {
130 max30205_interface_debug_print("max30205: set bus timeout failed.\n");
131 (void)max30205_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* convert low threshold */
137 res= max30205_convert_to_register(&gs_handle, low, (int16_t *)&low_threshold);
138 if (res != 0)
139 {
140 max30205_interface_debug_print("max30205: convert to register failed.\n");
141 (void)max30205_deinit(&gs_handle);
142
143 return 1;
144 }
145
146 /* set interrupt low threshold */
147 res = max30205_set_interrupt_low_threshold(&gs_handle, low_threshold);
148 if (res != 0)
149 {
150 max30205_interface_debug_print("max30205: set low threshold failed.\n");
151 (void)max30205_deinit(&gs_handle);
152
153 return 1;
154 }
155
156 /* convert high threshold */
157 res = max30205_convert_to_register(&gs_handle, high, (int16_t *)&high_threshold);
158 if (res != 0)
159 {
160 max30205_interface_debug_print("max30205: convert to register failed.\n");
161 (void)max30205_deinit(&gs_handle);
162
163 return 1;
164 }
165
166 /* set interrupt high threshold */
167 res = max30205_set_interrupt_high_threshold(&gs_handle, high_threshold);
168 if (res != 0)
169 {
170 max30205_interface_debug_print("max30205: set high threshold failed.\n");
171 (void)max30205_deinit(&gs_handle);
172
173 return 1;
174 }
175
176 /* start continuous read */
177 res = max30205_start_continuous_read(&gs_handle);
178 if (res != 0)
179 {
180 max30205_interface_debug_print("max30205: start continuous read failed.\n");
181 (void)max30205_deinit(&gs_handle);
182
183 return 1;
184 }
185
186 return 0;
187}
188
197uint8_t max30205_interrupt_read(float *s)
198{
199 int16_t raw;
200
201 /* read data */
202 if (max30205_continuous_read(&gs_handle, (int16_t *)&raw, s) != 0)
203 {
204 return 1;
205 }
206 else
207 {
208 return 0;
209 }
210}
211
220{
221 uint8_t res;
222
223 /* stop continuous read */
224 res = max30205_stop_continuous_read(&gs_handle);
225 if (res != 0)
226 {
227 return 1;
228 }
229
230 /* close max30205 */
231 if (max30205_deinit(&gs_handle) != 0)
232 {
233 return 1;
234 }
235
236 return 0;
237}
driver max30205 interrupt header file
struct max30205_handle_s max30205_handle_t
max30205 handle structure definition
uint8_t max30205_set_data_format(max30205_handle_t *handle, max30205_data_format_t format)
set the chip data format
uint8_t max30205_start_continuous_read(max30205_handle_t *handle)
start reading data
uint8_t max30205_set_addr_pin(max30205_handle_t *handle, max30205_address_t addr_pin)
set the iic address pin
max30205_address_t
max30205 address enumeration definition
uint8_t max30205_deinit(max30205_handle_t *handle)
close the chip
uint8_t max30205_set_bus_timeout(max30205_handle_t *handle, max30205_bus_timeout_t bus_timeout)
set the iic bus timeout
uint8_t max30205_continuous_read(max30205_handle_t *handle, int16_t *raw, float *s)
read data continuously
uint8_t max30205_init(max30205_handle_t *handle)
initialize the chip
uint8_t max30205_stop_continuous_read(max30205_handle_t *handle)
stop reading data
uint8_t max30205_interrupt_init(max30205_address_t addr_pin, max30205_interrupt_mode_t mode, float low, float high)
interrupt example init
uint8_t max30205_interrupt_deinit(void)
interrupt example deinit
#define MAX30205_INTERRUPT_DEFAULT_PIN_POLARITY
uint8_t max30205_interrupt_read(float *s)
interrupt example read
#define MAX30205_INTERRUPT_DEFAULT_BUS_TIMEOUT
#define MAX30205_INTERRUPT_DEFAULT_DATA_FORMAT
max30205 interrupt example default definition
#define MAX30205_INTERRUPT_DEFAULT_FAULT_QUEUE
void max30205_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max30205_interface_iic_deinit(void)
interface iic bus deinit
uint8_t max30205_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t max30205_interface_iic_init(void)
interface iic bus init
uint8_t max30205_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void max30205_interface_debug_print(const char *const fmt,...)
interface print format data
max30205_interrupt_mode_t
max30205 interrupt mode enumeration definition
uint8_t max30205_set_fault_queue(max30205_handle_t *handle, max30205_fault_queue_t fault_queue)
set the chip fault queue
uint8_t max30205_set_interrupt_mode(max30205_handle_t *handle, max30205_interrupt_mode_t mode)
set the chip interrupt mode
uint8_t max30205_set_interrupt_low_threshold(max30205_handle_t *handle, int16_t threshold)
set the chip interrupt low threshold
uint8_t max30205_set_pin_polarity(max30205_handle_t *handle, max30205_pin_polarity_t polarity)
set the interrupt pin polarity
uint8_t max30205_convert_to_register(max30205_handle_t *handle, float s, int16_t *reg)
convert a temperature value to a register raw data
uint8_t max30205_set_interrupt_high_threshold(max30205_handle_t *handle, int16_t threshold)
set the chip interrupt high threshold