Skip to content

Commit

Permalink
Merge branch 'main' into rp2350-riscv
Browse files Browse the repository at this point in the history
  • Loading branch information
tact1m4n3 authored Jan 9, 2025
2 parents 011a394 + 85fa438 commit ca3aa82
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/usb_cdc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,25 @@ pub fn main() !void {

var usb_tx_buff: [1024]u8 = undefined;

// Transfer data to host
// NOTE: After each USB chunk transfer, we have to call the USB task so that bus TX events can be handled
pub fn usb_cdc_write(comptime fmt: []const u8, args: anytype) void {
const text = std.fmt.bufPrint(&usb_tx_buff, fmt, args) catch &.{};

var write_buff = text;
while (write_buff.len > 0) {
write_buff = driver_cdc.write(write_buff);
usb_dev.task(false) catch unreachable;
}
// Short messages are not sent right away; instead, they accumulate in a buffer, so we have to force a flush to send them
_ = driver_cdc.write_flush();
usb_dev.task(false) catch unreachable;
}

var usb_rx_buff: [1024]u8 = undefined;

// TODO - right now there are 2 issues with reading data from serial:
// 1. It not always work, so sometime data is not received. This is probably related to how we reset usb buffer flags.
// 2. Even when usb host sends small chunk of data cdc read returns full packet length. This require further investigation.
// Receive data from host
// NOTE: Read code was not tested extensively. In case of issues, try to call USB task before every read operation
pub fn usb_cdc_read() []const u8 {
var total_read: usize = 0;
var read_buff: []u8 = usb_rx_buff[0..];
Expand Down

0 comments on commit ca3aa82

Please sign in to comment.