From 885bd922cfd02810a9ebe1d8a0e255226a472852 Mon Sep 17 00:00:00 2001 From: "Mr. Green's Workshop" <76992231+MrGreensWorkshop@users.noreply.github.com> Date: Fri, 20 Jan 2023 07:49:00 +0900 Subject: [PATCH] Ability to set USB device as self powered device (#1105) --- src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h | 5 +++++ src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h index 565b6c3..8548169 100644 --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h @@ -102,6 +102,11 @@ #define PICO_STDIO_USB_CONNECTION_WITHOUT_DTR 0 #endif +// PICO_CONFIG: PICO_STDIO_USB_DEVICE_SELF_POWERED, Set USB device as self powered device, type=bool, default=0, group=pico_stdio_usb +#ifndef PICO_STDIO_USB_DEVICE_SELF_POWERED +#define PICO_STDIO_USB_DEVICE_SELF_POWERED 0 +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c index e1babf8..c3ce49b 100644 --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c @@ -54,7 +54,13 @@ #else #define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_RPI_RESET_DESC_LEN) #endif +#if !PICO_STDIO_USB_DEVICE_SELF_POWERED +#define USBD_CONFIGURATION_DESCRIPTOR_ATTRIBUTE (0) #define USBD_MAX_POWER_MA (250) +#else +#define USBD_CONFIGURATION_DESCRIPTOR_ATTRIBUTE TUSB_DESC_CONFIG_ATT_SELF_POWERED +#define USBD_MAX_POWER_MA (1) +#endif #define USBD_ITF_CDC (0) // needs 2 interfaces #if !PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE @@ -102,7 +108,7 @@ static const tusb_desc_device_t usbd_desc_device = { static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = { TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_MAX, USBD_STR_0, USBD_DESC_LEN, - 0, USBD_MAX_POWER_MA), + USBD_CONFIGURATION_DESCRIPTOR_ATTRIBUTE, USBD_MAX_POWER_MA), TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),