Move C++ tree into firmware/

This commit is contained in:
Ian Gulliver
2026-04-05 21:33:19 +09:00
parent 4989cfd8cb
commit 30a697066c
22 changed files with 3 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
#pragma once
#include <cstdint>
#include <span>
#include <vector>
#include "tusb.h"
#include "ring_buffer.h"
struct usb_cdc {
ring_buffer<512> tx;
void send(std::span<const uint8_t> data) {
tx.push(data);
drain();
}
void send(const std::vector<uint8_t>& data) {
send(std::span<const uint8_t>{data});
}
void drain() {
while (!tx.empty()) {
uint32_t avail = tud_cdc_write_available();
if (avail == 0) break;
auto chunk = tx.read_contiguous();
if (chunk.size() > avail) chunk = chunk.first(avail);
tud_cdc_write(chunk.data(), chunk.size());
tx.consume(chunk.size());
}
tud_cdc_write_flush();
}
};