2022-10-26 16:32:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 ML!PA Consulting GmbH
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup pkg_tinyusb
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief CDC ACM stdio implementation for tinyUSB CDC ACM
|
|
|
|
*
|
|
|
|
* This file implements a USB CDC ACM callback and read/write functions.
|
|
|
|
*
|
|
|
|
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2022-12-03 12:05:26 +01:00
|
|
|
#define USB_H_USER_IS_RIOT_INTERNAL
|
|
|
|
|
2022-10-26 16:32:58 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2023-06-14 19:05:34 +02:00
|
|
|
#include "stdio_base.h"
|
2022-10-26 16:32:58 +02:00
|
|
|
|
|
|
|
#include "tusb.h"
|
|
|
|
#include "tinyusb.h"
|
|
|
|
|
2023-06-14 19:05:34 +02:00
|
|
|
static ssize_t _write(const void* buffer, size_t len)
|
2022-10-26 16:32:58 +02:00
|
|
|
{
|
|
|
|
const char *start = buffer;
|
|
|
|
|
|
|
|
while (tud_cdc_connected() && len) {
|
|
|
|
size_t n = tud_cdc_write(buffer, len);
|
|
|
|
buffer = (char *)buffer + n;
|
|
|
|
len -= n;
|
|
|
|
};
|
|
|
|
|
|
|
|
tud_cdc_write_flush();
|
|
|
|
|
|
|
|
return (char *)buffer - start;
|
|
|
|
}
|
|
|
|
|
2024-02-08 17:06:28 +01:00
|
|
|
#ifdef MODULE_STDIN
|
2022-10-26 16:32:58 +02:00
|
|
|
void tud_cdc_rx_cb(uint8_t itf)
|
|
|
|
{
|
|
|
|
(void)itf;
|
|
|
|
|
2023-06-14 19:05:34 +02:00
|
|
|
uint8_t buffer[64];
|
|
|
|
unsigned res = tud_cdc_read(buffer, sizeof(buffer));
|
|
|
|
isrpipe_write(&stdin_isrpipe, buffer, res);
|
2022-10-26 16:32:58 +02:00
|
|
|
}
|
2024-02-08 17:06:28 +01:00
|
|
|
#endif
|
2023-06-14 19:05:34 +02:00
|
|
|
|
|
|
|
STDIO_PROVIDER(STDIO_TINYUSB_CDC_ACM, NULL, NULL, _write)
|