Skip to content
Snippets Groups Projects
Commit 1bb1cef3 authored by k2-alfadhala's avatar k2-alfadhala
Browse files

usb functions

parent 7dbb00b3
No related branches found
No related tags found
No related merge requests found
#include "usb_serial.h"
void usb_init(void) {
tusb_init(); // Setup USB
}
int usb_write(const uint8_t *buf, int len) {
if (!tud_cdc_connected()) return -1;
int sent_total = 0;
while (len > 0) {
int sent = tud_cdc_write(buf, len);
if (sent < 0) return sent;
tud_cdc_write_flush();
buf += sent;
len -= sent;
sent_total += sent;
}
return sent_total;
}
int usb_read(uint8_t *buf, int len) {
if (tud_cdc_available()) {
return tud_cdc_read(buf, len);
}
return 0;
}
void usb_cleanup(void) {
}
bool usb_connected(void) {
return tud_cdc_connected();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment