forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
384 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "tinyusb_config.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MODULE = tinyusb_stdio | ||
|
||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2022 Gunar Schorcht | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <sys/types.h> | ||
|
||
#include "log.h" | ||
#include "isrpipe.h" | ||
|
||
#if MODULE_VFS | ||
#include "vfs.h" | ||
#endif | ||
|
||
#ifdef MODULE_USB_BOARD_RESET | ||
#include "usb_board_reset_internal.h" | ||
#endif | ||
|
||
#include "tinyusb.h" | ||
#include "class/cdc/cdc_device.h" | ||
|
||
#define CONFIG_TINYUSB_STDIO_BUF_SIZE 32 | ||
|
||
static uint8_t _isrpipe_mem[CONFIG_TINYUSB_STDIO_BUF_SIZE]; | ||
static isrpipe_t _isrpipe = ISRPIPE_INIT(_isrpipe_mem); | ||
|
||
void stdio_init(void) | ||
{ | ||
/* Initialize this side of the CDC ACM pipe */ | ||
#if MODULE_VFS | ||
vfs_bind_stdio(); | ||
#endif | ||
} | ||
|
||
#if IS_USED(MODULE_STDIO_AVAILABLE) | ||
int stdio_available(void) | ||
{ | ||
return tsrb_avail(&_isrpipe.tsrb); | ||
} | ||
#endif | ||
|
||
ssize_t stdio_read(void* buffer, size_t len) | ||
{ | ||
(void)buffer; | ||
(void)len; | ||
return isrpipe_read(&_isrpipe, buffer, len); | ||
} | ||
|
||
ssize_t stdio_write(const void* buffer, size_t len) | ||
{ | ||
#if 0 | ||
const char *start = buffer; | ||
do { | ||
size_t n = usbus_tinyusb_acm_submit(&cdcacm, buffer, len); | ||
usbus_cdc_acm_flush(&cdcacm); | ||
/* Use tsrb and flush */ | ||
buffer = (char *)buffer + n; | ||
len -= n; | ||
} while (len); | ||
return (char *)buffer - start; | ||
#elif 0 | ||
return tud_cdc_n_write(0, buffer, len); | ||
#else | ||
size_t n = tud_cdc_n_write(0, buffer, len); | ||
tud_cdc_n_write_flush(0); | ||
return n; | ||
#endif | ||
} | ||
|
||
static uint8_t _rx_buffer[CONFIG_TINYUSB_STDIO_BUF_SIZE]; | ||
|
||
void tud_cdc_rx_cb(uint8_t itf) | ||
{ | ||
uint32_t len = tud_cdc_n_read(itf, _rx_buffer, CONFIG_TINYUSB_STDIO_BUF_SIZE); | ||
|
||
for (uint32_t i = 0; i < len; i++) { | ||
isrpipe_write_one(&_isrpipe, _rx_buffer[i]); | ||
} | ||
} | ||
|
||
void tinyusb_stdio_init(void) | ||
{ | ||
#ifdef MODULE_USB_BOARD_RESET | ||
#endif | ||
} |
Oops, something went wrong.