static void read_and_echo_data(int *bytes_read) { while (data_received == false) ; data_received = false; /* Read all data and echo it back. */ while ((*bytes_read = cdc_acm_fifo_read((uint8_t *)data_buf, sizeof(data_buf)))) { write_data(data_buf, *bytes_read); } }
static int read_data(uint8_t *buf, size_t *len, size_t max_len) { size_t part = 0; size_t total = 0; do { part = cdc_acm_fifo_read(buf + total, max_len - total); total += part; } while (part && (total < max_len)); *len = total; if (part) { return -EIO; } return 0; }