Merge pull request #13375 from leandrolanzieri/pr/kconfig_migrate/sys/usbus_cdc

usbus/cdc/acm: Expose configurations to Kconfig
This commit is contained in:
Koen Zandberg 2020-04-07 15:00:36 +02:00 committed by GitHub
commit c81c8ed104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 10 deletions

View File

@ -46,15 +46,28 @@ extern "C" {
* @brief Buffer size for STDIN and STDOUT data to and from USB when using
* the USBUS_CDC_ACM_STDIO module
*/
#ifndef USBUS_CDC_ACM_STDIO_BUF_SIZE
#define USBUS_CDC_ACM_STDIO_BUF_SIZE (128)
#ifdef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP
#define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (1<<CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP)
#endif
#ifndef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE
#define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (128)
#endif
/**
* @brief USB CDC ACM bulk endpoint size
*/
#ifndef USBUS_CDC_ACM_BULK_EP_SIZE
#define USBUS_CDC_ACM_BULK_EP_SIZE (64)
#if IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_8)
#define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (8)
#elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_16)
#define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (16)
#elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_32)
#define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (32)
#elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_64)
#define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (64)
#endif
#ifndef CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE
#define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (64)
#endif
/** @} */

View File

@ -42,4 +42,6 @@ config USBUS_EP0_SIZE_64
endchoice
rsource "cdc/Kconfig"
endif # KCONFIG_MODULE_USBUS

View File

@ -0,0 +1 @@
rsource "acm/Kconfig"

View File

@ -0,0 +1,46 @@
# Copyright (c) 2020 HAW Hamburg
#
# 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.
#
menuconfig KCONFIG_MODULE_USBUS_CDC_ACM
bool "Configure USBUS CDC ACM"
depends on MODULE_USBUS_CDC_ACM
help
Configure the USBUS CDC ACM module via Kconfig.
if KCONFIG_MODULE_USBUS_CDC_ACM
config USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP
int "Buffer size for STDIN and STDOUT data (as exponent of 2^n)"
default 7
range 0 31
depends on MODULE_STDIO_CDC_ACM
help
As buffer size ALWAYS needs to be power of two, this changes this option
represents the exponent of 2^n, which will be used as the size of the
buffer.
choice
bool "USB CDC ACM bulk endpoint size"
default USBUS_CDC_ACM_BULK_EP_SIZE_64
help
This configures the maximum amount of bytes (chars) sent per transfer
over the USB connection.
config USBUS_CDC_ACM_BULK_EP_SIZE_8
bool "8"
config USBUS_CDC_ACM_BULK_EP_SIZE_16
bool "16"
config USBUS_CDC_ACM_BULK_EP_SIZE_32
bool "32"
config USBUS_CDC_ACM_BULK_EP_SIZE_64
bool "64"
endchoice
endif # KCONFIG_MODULE_USBUS_CDC_ACM

View File

@ -232,14 +232,14 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler)
usbus_enable_endpoint(ep);
ep = usbus_add_endpoint(usbus, &cdcacm->iface_data,
USB_EP_TYPE_BULK, USB_EP_DIR_IN,
USBUS_CDC_ACM_BULK_EP_SIZE);
CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE);
ep->interval = 0; /* Interval is not used with bulk endpoints */
usbus_enable_endpoint(ep);
/* Store the endpoint reference to activate it
* when DTE present is signalled by the host */
ep = usbus_add_endpoint(usbus, &cdcacm->iface_data,
USB_EP_TYPE_BULK, USB_EP_DIR_OUT,
USBUS_CDC_ACM_BULK_EP_SIZE);
CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE);
ep->interval = 0; /* Interval is not used with bulk endpoints */
usbus_enable_endpoint(ep);
@ -319,12 +319,12 @@ static void _handle_in(usbus_cdcacm_device_t *cdcacm,
(cdcacm->state != USBUS_CDC_ACM_LINE_STATE_DTE)) {
return;
}
/* copy at most USBUS_CDC_ACM_BULK_EP_SIZE chars from input into ep->buf */
/* copy at most CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE chars from input into ep->buf */
unsigned old = irq_disable();
while (!tsrb_empty(&cdcacm->tsrb)) {
int c = tsrb_get_one(&cdcacm->tsrb);
ep->buf[cdcacm->occupied++] = (uint8_t)c;
if (cdcacm->occupied >= USBUS_CDC_ACM_BULK_EP_SIZE) {
if (cdcacm->occupied >= CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE) {
break;
}
}

View File

@ -38,8 +38,8 @@
#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 uint8_t _cdc_tx_buf_mem[CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE];
static uint8_t _cdc_rx_buf_mem[CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE];
static isrpipe_t _cdc_stdio_isrpipe = ISRPIPE_INIT(_cdc_rx_buf_mem);
void stdio_init(void)