/* Concurrently transmits and receives one 1-Wire bit by sending and receiving one uart byte  */
static int serial_tx_rx(const struct device *dev, const uint8_t *tx_data, uint8_t *rx_data, size_t len, uint32_t timeout)
/* Concurrently transmits and receives one 1-Wire bit by sending and receiving one uart byte  */
static int serial_tx_rx(const struct device *dev, const uint8_t *tx_data, uint8_t *rx_data, size_t len, uint32_t timeout)
{
	const struct w1_serial_config *cfg = dev->config;
	k_timepoint_t end;
	uint8_t dummy;
	int ret = 0;
	__ASSERT_NO_MSG(tx_data != NULL);
	__ASSERT_NO_MSG(rx_data != NULL);
	for (int i = 0; i < len; ++i) {
		while (uart_poll_in(cfg->uart_dev, &dummy) == 0) {
		}
		uart_poll_out(cfg->uart_dev, tx_data[i]);
		end = sys_timepoint_calc(K_USEC(timeout));
		do {
			ret = uart_poll_in(cfg->uart_dev, &rx_data[i]);
		} while (ret != 0 && !sys_timepoint_expired(end));
	}
	return ret;
}