LibDriver MAX30205
Loading...
Searching...
No Matches
driver_max30205_shot.c
Go to the documentation of this file.
1
37
39
40static max30205_handle_t gs_handle;
41
51{
52 uint8_t res;
53 int16_t low_threshold;
54 int16_t high_threshold;
55
56 /* link interface function */
64
65 /* set max30205 iic address */
66 res = max30205_set_addr_pin(&gs_handle, addr_pin);
67 if (res != 0)
68 {
69 max30205_interface_debug_print("max30205: set addr pin failed.\n");
70
71 return 1;
72 }
73
74 /* max30205 init */
75 res = max30205_init(&gs_handle);
76 if (res != 0)
77 {
78 max30205_interface_debug_print("max30205: init failed.\n");
79
80 return 1;
81 }
82
83 /* set data format */
85 if (res != 0)
86 {
87 max30205_interface_debug_print("max30205: set data format failed.\n");
88 (void)max30205_deinit(&gs_handle);
89
90 return 1;
91 }
92
93 /* set interrupt mode */
95 if (res != 0)
96 {
97 max30205_interface_debug_print("max30205: set interrupt mode failed.\n");
98 (void)max30205_deinit(&gs_handle);
99
100 return 1;
101 }
102
103 /* set fault queue */
105 if (res != 0)
106 {
107 max30205_interface_debug_print("max30205: set fault queue failed.\n");
108 (void)max30205_deinit(&gs_handle);
109
110 return 1;
111 }
112
113 /* set pin polarity */
115 if (res != 0)
116 {
117 max30205_interface_debug_print("max30205: set pin polarity failed.\n");
118 (void)max30205_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 /* set bus timeout */
125 if (res != 0)
126 {
127 max30205_interface_debug_print("max30205: set bus timeout failed.\n");
128 (void)max30205_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* convert to register */
134 res= max30205_convert_to_register(&gs_handle, MAX30205_SHOT_DEFAULT_INTERRUPT_LOW_THRESHOLD, (int16_t *)&low_threshold);
135 if (res != 0)
136 {
137 max30205_interface_debug_print("max30205: convert to register failed.\n");
138 (void)max30205_deinit(&gs_handle);
139
140 return 1;
141 }
142
143 /* set interrupt low threshold */
144 res = max30205_set_interrupt_low_threshold(&gs_handle, low_threshold);
145 if (res != 0)
146 {
147 max30205_interface_debug_print("max30205: set low threshold failed.\n");
148 (void)max30205_deinit(&gs_handle);
149
150 return 1;
151 }
152
153 /* convert to register */
154 res = max30205_convert_to_register(&gs_handle, MAX30205_SHOT_DEFAULT_INTERRUPT_HIGH_THRESHOLD, (int16_t *)&high_threshold);
155 if (res != 0)
156 {
157 max30205_interface_debug_print("max30205: convert to register failed.\n");
158 (void)max30205_deinit(&gs_handle);
159
160 return 1;
161 }
162
163 /* set interrupt high threshold */
164 res = max30205_set_interrupt_high_threshold(&gs_handle, high_threshold);
165 if (res != 0)
166 {
167 max30205_interface_debug_print("max30205: set high threshold failed.\n");
168 (void)max30205_deinit(&gs_handle);
169
170 return 1;
171 }
172
173 return 0;
174}
175
184uint8_t max30205_shot_read(float *s)
185{
186 int16_t raw;
187
188 /* single read */
189 if (max30205_single_read(&gs_handle, (int16_t *)&raw, s) != 0)
190 {
191 return 1;
192 }
193 else
194 {
195 return 0;
196 }
197}
198
207{
208 /* close max30205 */
209 if (max30205_deinit(&gs_handle) != 0)
210 {
211 return 1;
212 }
213 else
214 {
215 return 0;
216 }
217}
driver max30205 shot 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_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_single_read(max30205_handle_t *handle, int16_t *raw, float *s)
read data once
uint8_t max30205_init(max30205_handle_t *handle)
initialize the chip
#define MAX30205_SHOT_DEFAULT_INTERRUPT_HIGH_THRESHOLD
#define MAX30205_SHOT_DEFAULT_DATA_FORMAT
max30205 shot example default definition
#define MAX30205_SHOT_DEFAULT_FAULT_QUEUE
#define MAX30205_SHOT_DEFAULT_PIN_POLARITY
uint8_t max30205_shot_init(max30205_address_t addr_pin)
shot example init
uint8_t max30205_shot_deinit(void)
shot example deinit
#define MAX30205_SHOT_DEFAULT_INTERRUPT_LOW_THRESHOLD
#define MAX30205_SHOT_DEFAULT_BUS_TIMEOUT
#define MAX30205_SHOT_DEFAULT_INTERRUPT_MODE
uint8_t max30205_shot_read(float *s)
shot example read
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
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