1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

USBUS cdc acm: Add STDIO wrapper for CDC ACM

This commit is contained in:
Koen Zandberg 2019-02-28 21:40:35 +01:00
parent 852b7c8d0a
commit 59743aed13
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
5 changed files with 97 additions and 6 deletions

View File

@ -401,7 +401,7 @@ ifneq (,$(filter newlib,$(USEMODULE)))
ifeq (,$(filter newlib_syscalls_%,$(USEMODULE)))
USEMODULE += newlib_syscalls_default
endif
ifeq (,$(filter stdio_rtt,$(USEMODULE)))
ifeq (,$(filter stdio_rtt stdio_cdc_acm,$(USEMODULE)))
USEMODULE += stdio_uart
endif
endif
@ -414,6 +414,11 @@ ifneq (,$(filter posix_sockets,$(USEMODULE)))
USEMODULE += xtimer
endif
ifneq (,$(filter stdio_cdc_acm,$(USEMODULE)))
USEMODULE += usbus_cdc_acm
USEMODULE += isrpipe
endif
ifneq (,$(filter stdio_rtt,$(USEMODULE)))
USEMODULE += xtimer
endif
@ -874,17 +879,17 @@ ifneq (,$(filter tlsf-malloc,$(USEMODULE)))
USEPKG += tlsf
endif
ifneq (,$(filter usbus_cdc_acm,$(USEMODULE)))
USEMODULE += tsrb
USEMODULE += usbus
endif
ifneq (,$(filter usbus,$(USEMODULE)))
FEATURES_REQUIRED += periph_usbdev
USEMODULE += core_thread_flags
USEMODULE += event
endif
ifneq (,$(filter usbus_cdc_acm,$(USEMODULE)))
USEMODULE += tsrb
USEMODULE += usbus
endif
ifneq (,$(filter usbus_cdc_ecm,$(USEMODULE)))
USEMODULE += iolist
USEMODULE += fmt

View File

@ -80,6 +80,7 @@ PSEUDOMODULES += sock_tcp
PSEUDOMODULES += sock_udp
PSEUDOMODULES += stdin
PSEUDOMODULES += stdio_ethos
PSEUDOMODULES += stdio_cdc_acm
PSEUDOMODULES += stdio_uart_rx
PSEUDOMODULES += sock_dtls

View File

@ -28,6 +28,9 @@
#include "usb/usbus/cdc/ecm.h"
usbus_cdcecm_device_t cdcecm;
#endif
#ifdef MODULE_USBUS_CDC_ACM
#include "usb/usbus/cdc/acm.h"
#endif
static char _stack[USBUS_STACKSIZE];
static usbus_t usbus;
@ -42,6 +45,11 @@ void auto_init_usb(void)
usbus_init(&usbus, usbdev);
/* USBUS function handlers initialization */
#ifdef MODULE_STDIO_CDC_ACM
void usb_cdc_acm_stdio_init(usbus_t *usbus);
usb_cdc_acm_stdio_init(&usbus);
#endif
#ifdef MODULE_USBUS_CDC_ECM
usbus_cdcecm_init(&usbus, &cdcecm);
#endif

View File

@ -1,4 +1,7 @@
MODULE = usbus_cdc_acm
SRC = cdc_acm.c
ifneq (,$(filter stdio_cdc_acm,$(USEMODULE)))
SRC += cdc_acm_stdio.c
endif
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2018 Koen Zandberg
*
* 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 sys
* @{
*
* @file
* @brief CDC ACM stdio implementation for USBUS CDC ACM
*
* This file implements a USB CDC ACM callback and read/write functions.
*
*
* @}
*/
#include <stdio.h>
#include "isrpipe.h"
#include "usb/usbus.h"
#include "usb/usbus/cdc/acm.h"
#if MODULE_VFS
#include "vfs.h"
#endif
static usbus_cdcacm_device_t cdcacm;
static uint8_t _cdc_tx_buf_mem[USBUS_CDC_ACM_STDIO_BUF_SIZE];
static uint8_t _cdc_rx_buf_mem[USBUS_CDC_ACM_STDIO_BUF_SIZE];
static isrpipe_t _cdc_stdio_isrpipe = ISRPIPE_INIT(_cdc_rx_buf_mem);
void stdio_init(void)
{
/* Initialize this side of the CDC ACM pipe */
#if MODULE_VFS
vfs_bind_stdio();
#endif
}
ssize_t stdio_read(void* buffer, size_t len)
{
(void)buffer;
(void)len;
return isrpipe_read(&_cdc_stdio_isrpipe, buffer, len);
}
ssize_t stdio_write(const void* buffer, size_t len)
{
usbus_cdc_acm_submit(&cdcacm, buffer, len);
usbus_cdc_acm_flush(&cdcacm);
/* Use tsrb and flush */
return len;
}
static void _cdc_acm_rx_pipe(usbus_cdcacm_device_t *cdcacm,
uint8_t *data, size_t len)
{
(void)cdcacm;
for (size_t i = 0; i < len; i++) {
isrpipe_write_one(&_cdc_stdio_isrpipe, data[i]);
}
}
void usb_cdc_acm_stdio_init(usbus_t *usbus)
{
usbus_cdc_acm_init(usbus, &cdcacm, _cdc_acm_rx_pipe, NULL,
_cdc_tx_buf_mem, sizeof(_cdc_tx_buf_mem));
}