Lines Matching +full:data +full:- +full:timeout
4 * SPDX-License-Identifier: Apache-2.0
9 /* sensor pms7003.c - Driver for plantower PMS7003 sensor
27 /* wait serial output with 1000ms timeout */
41 * @brief wait for an array data from uart device with a timeout
44 * @param data the data array to be matched
45 * @param len the data array len
46 * @param timeout the timeout in milliseconds
47 * @return 0 if success; -ETIME if timeout
49 static int uart_wait_for(const struct device *dev, uint8_t *data, int len, in uart_wait_for() argument
50 int timeout) in uart_wait_for() argument
53 int64_t timeout_time = k_uptime_get() + timeout; in uart_wait_for()
59 return -ETIME; in uart_wait_for()
63 if (c == data[matched_size]) { in uart_wait_for()
69 } else if (c == data[0]) { in uart_wait_for()
82 * @param data the data buffer
83 * @param len the data len
84 * @param timeout the timeout in milliseconds
85 * @return 0 if success; -ETIME if timeout
87 static int uart_read_bytes(const struct device *dev, uint8_t *data, int len, in uart_read_bytes() argument
88 int timeout) in uart_read_bytes() argument
91 int64_t timeout_time = k_uptime_get() + timeout; in uart_read_bytes()
97 return -ETIME; in uart_read_bytes()
101 data[read_size++] = c; in uart_read_bytes()
113 struct pms7003_data *drv_data = dev->data; in pms7003_sample_fetch()
114 const struct pms7003_config *cfg = dev->config; in pms7003_sample_fetch()
124 if (uart_wait_for(cfg->uart_dev, pms7003_start_bytes, in pms7003_sample_fetch()
127 LOG_WRN("waiting for start bytes is timeout"); in pms7003_sample_fetch()
128 return -ETIME; in pms7003_sample_fetch()
131 if (uart_read_bytes(cfg->uart_dev, pms7003_receive_buffer, 30, in pms7003_sample_fetch()
133 return -ETIME; in pms7003_sample_fetch()
136 drv_data->pm_1_0 = in pms7003_sample_fetch()
138 drv_data->pm_2_5 = in pms7003_sample_fetch()
140 drv_data->pm_10 = in pms7003_sample_fetch()
143 LOG_DBG("pm1.0 = %d", drv_data->pm_1_0); in pms7003_sample_fetch()
144 LOG_DBG("pm2.5 = %d", drv_data->pm_2_5); in pms7003_sample_fetch()
145 LOG_DBG("pm10 = %d", drv_data->pm_10); in pms7003_sample_fetch()
153 struct pms7003_data *drv_data = dev->data; in pms7003_channel_get()
156 val->val1 = drv_data->pm_1_0; in pms7003_channel_get()
157 val->val2 = 0; in pms7003_channel_get()
159 val->val1 = drv_data->pm_2_5; in pms7003_channel_get()
160 val->val2 = 0; in pms7003_channel_get()
162 val->val1 = drv_data->pm_10; in pms7003_channel_get()
163 val->val2 = 0; in pms7003_channel_get()
165 return -ENOTSUP; in pms7003_channel_get()
177 const struct pms7003_config *cfg = dev->config; in pms7003_init()
179 if (!device_is_ready(cfg->uart_dev)) { in pms7003_init()
181 return -ENODEV; in pms7003_init()