LibDriver SCD30
Loading...
Searching...
No Matches
driver_scd30_basic.c
Go to the documentation of this file.
1
36
37#include "driver_scd30_basic.h"
38
39static scd30_handle_t gs_handle;
40
50uint8_t scd30_basic_init(scd30_interface_t interface, uint16_t mbar)
51{
52 uint8_t res;
53 uint16_t second;
54 scd30_bool_t enable;
55
56 /* link functions */
69
70 /* set the interface */
71 res = scd30_set_interface(&gs_handle, interface);
72 if (res != 0)
73 {
74 scd30_interface_debug_print("scd30: set interface failed.\n");
75
76 return 1;
77 }
78
79 /* init the chip */
80 res = scd30_init(&gs_handle);
81 if (res != 0)
82 {
83 scd30_interface_debug_print("scd30: init failed.\n");
84
85 return 1;
86 }
87
88 /* get measurement interval */
89 res = scd30_get_measurement_interval(&gs_handle, &second);
90 if (res != 0)
91 {
92 scd30_interface_debug_print("scd30: get measurement interval failed.\n");
93 (void)scd30_deinit(&gs_handle);
94
95 return 1;
96 }
97
98 /* check config */
100 {
101 /* set default measurement interval */
103 if (res != 0)
104 {
105 scd30_interface_debug_print("scd30: set measurement interval failed.\n");
106 (void)scd30_deinit(&gs_handle);
107
108 return 1;
109 }
110 }
111
112 /* get automatic self calibration */
113 res = scd30_get_automatic_self_calibration(&gs_handle, &enable);
114 if (res != 0)
115 {
116 scd30_interface_debug_print("scd30: get automatic self calibration failed.\n");
117 (void)scd30_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* check config */
124 {
125 /* set default automatic self calibration */
127 if (res != 0)
128 {
129 scd30_interface_debug_print("scd30: set automatic self calibration failed.\n");
130 (void)scd30_deinit(&gs_handle);
131
132 return 1;
133 }
134 }
135
136 /* check mbar */
137 if (mbar != 0)
138 {
140 if (res != 0)
141 {
142 scd30_interface_debug_print("scd30: start measurement with pressure compensation failed.\n");
143 (void)scd30_deinit(&gs_handle);
144
145 return 1;
146 }
147 }
148 else
149 {
150 res = scd30_start_measurement(&gs_handle);
151 if (res != 0)
152 {
153 scd30_interface_debug_print("scd30: start measurement failed.\n");
154 (void)scd30_deinit(&gs_handle);
155
156 return 1;
157 }
158 }
159
160 return 0;
161}
162
171{
172 uint8_t res;
173
174 /* stop measurement */
175 res = scd30_stop_measurement(&gs_handle);
176 if (res != 0)
177 {
178 return 1;
179 }
180
181 /* deinit */
182 res = scd30_deinit(&gs_handle);
183 if (res != 0)
184 {
185 return 1;
186 }
187
188 return 0;
189}
190
200{
201 uint8_t res;
202
203 /* read data */
204 res = scd30_read(&gs_handle, data);
205 if (res != 0)
206 {
207 return 1;
208 }
209
210 return 0;
211}
212
220uint8_t scd30_basic_reset(void)
221{
222 if (scd30_soft_reset(&gs_handle) != 0)
223 {
224 return 1;
225 }
226
227 return 0;
228}
229
239uint8_t scd30_basic_get_version(uint8_t *major, uint8_t *minor)
240{
241 uint16_t version;
242
243 if (scd30_get_firmware_version(&gs_handle, &version) != 0)
244 {
245 return 1;
246 }
247 *major = (version >> 8) & 0xFF;
248 *minor = (version >> 0) & 0xFF;
249
250 return 0;
251}
driver scd30 basic header file
uint8_t scd30_init(scd30_handle_t *handle)
initialize the chip
uint8_t scd30_deinit(scd30_handle_t *handle)
close the chip
struct scd30_data_s scd30_data_t
scd30 data structure definition
uint8_t scd30_stop_measurement(scd30_handle_t *handle)
stop the measurement
uint8_t scd30_soft_reset(scd30_handle_t *handle)
soft reset
uint8_t scd30_read(scd30_handle_t *handle, scd30_data_t *data)
read the result
scd30_interface_t
scd30 interface enumeration definition
uint8_t scd30_get_firmware_version(scd30_handle_t *handle, uint16_t *version)
get firmware version
uint8_t scd30_get_automatic_self_calibration(scd30_handle_t *handle, scd30_bool_t *enable)
get automatic self calibration
uint8_t scd30_set_interface(scd30_handle_t *handle, scd30_interface_t interface)
set the chip interface
uint8_t scd30_set_automatic_self_calibration(scd30_handle_t *handle, scd30_bool_t enable)
set automatic self calibration
uint8_t scd30_start_measurement(scd30_handle_t *handle)
start the measurement
struct scd30_handle_s scd30_handle_t
scd30 handle structure definition
uint8_t scd30_set_measurement_interval(scd30_handle_t *handle, uint16_t second)
set the measurement interval
uint8_t scd30_get_measurement_interval(scd30_handle_t *handle, uint16_t *second)
get the measurement interval
uint8_t scd30_start_measurement_with_pressure_compensation(scd30_handle_t *handle, uint16_t mbar)
start the measurement with pressure compensation
scd30_bool_t
scd30 bool enumeration definition
uint8_t scd30_basic_init(scd30_interface_t interface, uint16_t mbar)
basic example init
uint8_t scd30_basic_get_version(uint8_t *major, uint8_t *minor)
basic example get the version
#define SCD30_BASIC_DEFAULT_MEASUREMENT_INTERVAL
scd30 basic example default definition
#define SCD30_BASIC_DEFAULT_AUTO_SELF_CALIBRATION
uint8_t scd30_basic_read(scd30_data_t *data)
basic example read
uint8_t scd30_basic_deinit(void)
basic example deinit
uint8_t scd30_basic_reset(void)
basic example reset
uint8_t scd30_interface_uart_init(void)
interface uart init
uint8_t scd30_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t scd30_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t scd30_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
void scd30_interface_debug_print(const char *const fmt,...)
interface print format data
uint16_t scd30_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t scd30_interface_iic_init(void)
interface iic bus init
void scd30_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t scd30_interface_uart_flush(void)
interface uart flush
uint8_t scd30_interface_iic_deinit(void)
interface iic bus deinit
uint8_t scd30_interface_uart_deinit(void)
interface uart deinit