-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cherryusb): add cherryusb library #2212
Open
sakumisu
wants to merge
2
commits into
raspberrypi:develop
Choose a base branch
from
CherryUSB:master
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,243
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
if (DEFINED ENV{PICO_CHERRYUSB_PATH} AND (NOT PICO_CHERRYUSB_PATH)) | ||
set(PICO_CHERRYUSB_PATH $ENV{PICO_CHERRYUSB_PATH}) | ||
message("Using PICO_CHERRYUSB_PATH from environment ('${PICO_CHERRYUSB_PATH}')") | ||
endif () | ||
|
||
set(CHERRYUSB_TEST_PATH "port/rp2040") | ||
if (NOT PICO_CHERRYUSB_PATH) | ||
set(PICO_CHERRYUSB_PATH ${PROJECT_SOURCE_DIR}/lib/cherryusb) | ||
if (NOT EXISTS ${PICO_CHERRYUSB_PATH}/${CHERRYUSB_TEST_PATH}) | ||
message(WARNING "CherryUSB submodule has not been initialized; USB support will be unavailable | ||
hint: try 'git submodule update --init' from your SDK directory (${PICO_SDK_PATH}).") | ||
endif() | ||
elseif (NOT EXISTS ${PICO_CHERRYUSB_PATH}/${CHERRYUSB_TEST_PATH}) | ||
message(WARNING "PICO_CHERRYUSB_PATH specified but content not present.") | ||
endif() | ||
|
||
if (EXISTS ${PICO_CHERRYUSB_PATH}/${CHERRYUSB_TEST_PATH}) | ||
message("CherryUSB available at ${PICO_CHERRYUSB_PATH}; enabling build support for USB.") | ||
pico_register_common_scope_var(PICO_CHERRYUSB_PATH) | ||
|
||
set(CONFIG_CHERRYUSB_DEVICE 1) | ||
set(CONFIG_CHERRYUSB_DEVICE_CDC_ACM 1) | ||
set(CONFIG_CHERRYUSB_DEVICE_HID 1) | ||
set(CONFIG_CHERRYUSB_DEVICE_MSC 1) | ||
set(CONFIG_CHERRYUSB_DEVICE_AUDIO 1) | ||
set(CONFIG_CHERRYUSB_DEVICE_VIDEO 1) | ||
set(CONFIG_CHERRYUSB_DEVICE_DCD "rp2040") | ||
include(${PICO_CHERRYUSB_PATH}/cherryusb.cmake) | ||
pico_add_library(cherryusb_device NOFLAG) | ||
target_include_directories(cherryusb_device_headers SYSTEM INTERFACE ${cherryusb_incs}) | ||
target_sources(cherryusb_device INTERFACE ${cherryusb_srcs}) | ||
|
||
set(CONFIG_CHERRYUSB_HOST 1) | ||
set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1) | ||
set(CONFIG_CHERRYUSB_HOST_HID 1) | ||
set(CONFIG_CHERRYUSB_HOST_MSC 1) | ||
set(CONFIG_CHERRYUSB_OSAL "freertos") | ||
set(CONFIG_CHERRYUSB_HOST_HCD "rp2040") | ||
|
||
include(${PICO_CHERRYUSB_PATH}/cherryusb.cmake) | ||
pico_add_library(cherryusb_host NOFLAG) | ||
target_include_directories(cherryusb_host_headers SYSTEM INTERFACE ${cherryusb_incs}) | ||
target_sources(cherryusb_host INTERFACE ${cherryusb_srcs}) | ||
|
||
pico_promote_common_scope_vars() | ||
endif() |
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
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,25 @@ | ||
if (TARGET cherryusb_device) | ||
pico_add_library(pico_stdio_usb) | ||
|
||
target_include_directories(pico_stdio_usb_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) | ||
|
||
target_sources(pico_stdio_usb INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/stdio_usb.c | ||
) | ||
|
||
pico_mirrored_target_link_libraries(pico_stdio_usb INTERFACE | ||
pico_stdio | ||
pico_time | ||
pico_unique_id | ||
pico_usb_reset_interface | ||
) | ||
target_link_libraries(pico_stdio_usb INTERFACE | ||
cherryusb_device | ||
) | ||
# PICO_CMAKE_CONFIG: PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS, Maximum number of milliseconds to wait during initialization for a CDC connection from the host (negative means indefinite) during initialization, type=int, default=0, group=pico_stdio_usb | ||
if (PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS) | ||
target_compile_definitions(pico_stdio_usb INTERFACE | ||
PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=${PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS} | ||
) | ||
endif() | ||
endif() |
168 changes: 168 additions & 0 deletions
168
src/rp2_common/pico_stdio_cherryusb/include/pico/stdio_usb.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#ifndef _PICO_STDIO_USB_H | ||
#define _PICO_STDIO_USB_H | ||
|
||
#include "pico/stdio.h" | ||
|
||
/** \brief Support for stdin/stdout over USB serial (CDC) | ||
* \defgroup pico_stdio_usb pico_stdio_usb | ||
* \ingroup pico_stdio | ||
* | ||
* Linking this library or calling `pico_enable_stdio_usb(TARGET ENABLED)` in the CMake (which | ||
* achieves the same thing) will add USB CDC to the drivers used for standard input/output | ||
* | ||
* Note this library is a developer convenience. It is not applicable in all cases; for one it takes full control of the USB device precluding your | ||
* use of the USB in device or host mode. For this reason, this library will automatically disengage if you try to using it alongside \ref tinyusb_device or | ||
* \ref tinyusb_host. It also takes control of a lower level IRQ and sets up a periodic background task. | ||
* | ||
* This library also includes (by default) functionality to enable the RP-series microcontroller to be reset over the USB interface. | ||
*/ | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_DEFAULT_CRLF, Default state of CR/LF translation for USB output, type=bool, default=PICO_STDIO_DEFAULT_CRLF, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_DEFAULT_CRLF | ||
#define PICO_STDIO_USB_DEFAULT_CRLF PICO_STDIO_DEFAULT_CRLF | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_STDOUT_TIMEOUT_US, Number of microseconds to be blocked trying to write USB output before assuming the host has disappeared and discarding data, default=500000, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_STDOUT_TIMEOUT_US | ||
#define PICO_STDIO_USB_STDOUT_TIMEOUT_US 500000 | ||
#endif | ||
|
||
// todo perhaps unnecessarily frequent? | ||
// PICO_CONFIG: PICO_STDIO_USB_TASK_INTERVAL_US, Period of microseconds between calling tud_task in the background, default=1000, advanced=true, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_TASK_INTERVAL_US | ||
#define PICO_STDIO_USB_TASK_INTERVAL_US 1000 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_LOW_PRIORITY_IRQ, Explicit User IRQ number to claim for tud_task() background execution instead of letting the implementation pick a free one dynamically (deprecated), advanced=true, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_LOW_PRIORITY_IRQ | ||
// this variable is no longer set by default (one is claimed dynamically), but will be respected if specified | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE | ||
#if !defined(LIB_TINYUSB_HOST) && !defined(LIB_TINYUSB_DEVICE) | ||
#define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 1 | ||
#endif | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE | ||
#define PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE 1200 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS, Maximum number of milliseconds to wait during initialization for a CDC connection from the host (negative means indefinite) during initialization, default=0, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS | ||
#define PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS 0 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_POST_CONNECT_WAIT_DELAY_MS, Number of extra milliseconds to wait when using PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS after a host CDC connection is detected (some host terminals seem to sometimes lose transmissions sent right after connection), default=50, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_POST_CONNECT_WAIT_DELAY_MS | ||
#define PICO_STDIO_USB_POST_CONNECT_WAIT_DELAY_MS 50 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_DEINIT_DELAY_MS, Number of milliseconds to wait before deinitializing stdio_usb, default=110, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_DEINIT_DELAY_MS | ||
#define PICO_STDIO_USB_DEINIT_DELAY_MS 110 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=pico_stdio_usb | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW | ||
#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW 0 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED | ||
#define PICO_STDIO_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0 | ||
#endif | ||
|
||
// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE. | ||
// PICO_CONFIG: PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=3, default=0, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK | ||
#define PICO_STDIO_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE | ||
#if !defined(LIB_TINYUSB_HOST) && !defined(LIB_TINYUSB_DEVICE) | ||
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1 | ||
#endif | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL | ||
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT | ||
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR | ||
#define PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS | ||
#define PICO_STDIO_USB_RESET_RESET_TO_FLASH_DELAY_MS 100 | ||
#endif | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_CONNECTION_WITHOUT_DTR, Disable use of DTR for connection checking meaning connection is assumed to be valid, type=bool, default=0, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_CONNECTION_WITHOUT_DTR | ||
#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 | ||
|
||
// PICO_CONFIG: PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK, Enable USB STDIO support for stdio_set_chars_available_callback. Can be disabled to make use of USB CDC RX callback elsewhere, type=bool, default=1, group=pico_stdio_usb | ||
#ifndef PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK | ||
#define PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK 1 | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern stdio_driver_t stdio_usb; | ||
|
||
/*! \brief Explicitly initialize USB stdio and add it to the current set of stdin drivers | ||
* \ingroup pico_stdio_usb | ||
* | ||
* \ref PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS can be set to cause this method to wait for a CDC connection | ||
* from the host before returning, which is useful if you don't want any initial stdout output to be discarded | ||
* before the connection is established. | ||
* | ||
* \return true if the USB CDC was initialized, false if an error occurred | ||
*/ | ||
bool stdio_usb_init(void); | ||
|
||
/*! \brief Explicitly deinitialize USB stdio and remove it from the current set of stdin drivers | ||
* \ingroup pico_stdio_usb | ||
* | ||
* \return true if the USB CDC was deinitialized, false if an error occurred | ||
*/ | ||
bool stdio_usb_deinit(void); | ||
|
||
/*! \brief Check if there is an active stdio CDC connection to a host | ||
* \ingroup pico_stdio_usb | ||
* | ||
* \return true if stdio is connected over CDC | ||
*/ | ||
bool stdio_usb_connected(void); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
13 changes: 13 additions & 0 deletions
13
src/rp2_common/pico_stdio_cherryusb/include/pico/stdio_usb/reset_interface.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#ifndef _PICO_STDIO_USB_RESET_INTERFACE_H | ||
#define _PICO_STDIO_USB_RESET_INTERFACE_H | ||
|
||
// definitions have been moved here | ||
#include "pico/usb_reset_interface.h" | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
tools/extract_configs.py
script will get upset if the samePICO_CONFIG:
entry appears in multiple different files.