Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Oct 25, 2022
1 parent 9fbf9bf commit a304897
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 1 deletion.
5 changes: 5 additions & 0 deletions makefiles/stdio.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ STDIO_MODULES = \
stdio_semihosting \
stdio_uart \
stdio_telnet \
stdio_tinyusb \
#

ifneq (,$(filter newlib picolibc,$(USEMODULE)))
Expand Down Expand Up @@ -69,6 +70,10 @@ ifneq (,$(filter stdio_telnet,$(USEMODULE)))
USEMODULE += telnet
endif

ifneq (,$(filter stdio_tinyusb,$(USEMODULE)))
USEPKG += tinyusb
endif

# enable stdout buffering for modules that benefit from sending out buffers in larger chunks
ifneq (,$(filter picolibc,$(USEMODULE)))
ifneq (,$(filter stdio_cdc_acm stdio_ethos slipdev_stdio stdio_semihosting,$(USEMODULE)))
Expand Down
3 changes: 3 additions & 0 deletions pkg/tinyusb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ tinyusb_contrib:
tinyusb_hw:
$(QQ)"$(MAKE)" -C $(RIOTPKG)/$(PKG_NAME)/hw

tinyusb_stdio:
$(QQ)"$(MAKE)" -C $(RIOTPKG)/$(PKG_NAME)/stdio

tinyusb_class_audio:
$(QQ)"$(MAKE)" -C $(PSRC)/class/audio -f $(RIOTBASE)/Makefile.base MODULE=$@

Expand Down
6 changes: 6 additions & 0 deletions pkg/tinyusb/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ USEMODULE += tinyusb_hw

DEFAULT_MODULE += auto_init_tinyusb

ifneq (,$(filter stdio_tinyusb,$(USEMODULE)))
USEMODULE += tinyusb_class_cdc
USEMODULE += tinyusb_device
USEMODULE += tinyusb_stdio
endif

ifeq (,$(filter tinyusb_class_%,$(USEMODULE)))
$(error At least one tinyusb_class_* module has to be enabled)
endif
Expand Down
2 changes: 2 additions & 0 deletions pkg/tinyusb/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PSEUDOMODULES += stdio_tinyusb

INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/contrib
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/contrib/include
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/hw/include
Expand Down
1 change: 1 addition & 0 deletions pkg/tinyusb/contrib/include/tusb_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "tinyusb_config.h"
1 change: 1 addition & 0 deletions pkg/tinyusb/contrib/include/tusb_os_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)

return mutex_lock_cancelable(&_mc) == 0;
#else
(void)msec;
assert(msec == OSAL_TIMEOUT_WAIT_FOREVER);
mutex_lock(mutex_hdl);
return true;
Expand Down
2 changes: 1 addition & 1 deletion pkg/tinyusb/contrib/tinyusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int tinyusb_setup(void)
if ((res = thread_create(_tinyusb_thread_stack,
sizeof(_tinyusb_thread_stack),
TINYUSB_PRIORITY,
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
/* THREAD_CREATE_WOUT_YIELD | */ THREAD_CREATE_STACKTEST,
_tinyusb_thread_impl, NULL, "tinyusb")) < 0) {
DEBUG("tinyUSB thread couldn't be created, reason %d\n", res);
return res;
Expand Down
3 changes: 3 additions & 0 deletions pkg/tinyusb/stdio/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = tinyusb_stdio

include $(RIOTBASE)/Makefile.base
89 changes: 89 additions & 0 deletions pkg/tinyusb/stdio/tinyusb_stdio.c
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
}
Loading

0 comments on commit a304897

Please sign in to comment.