Skip to content

Commit

Permalink
Added USB Library
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed May 30, 2024
1 parent c1f1b5c commit 5397b63
Show file tree
Hide file tree
Showing 27 changed files with 8,561 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/ESP32_USB_STREAM/.github/workflows/arduino_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Arduino Lint Action

on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
30 changes: 30 additions & 0 deletions lib/ESP32_USB_STREAM/.github/workflows/check_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check Versions

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
check_versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get latest release info of repository
id: last_release
uses: InsonusK/[email protected]
with:
myToken: ${{ github.token }}
exclude_types: "draft|prerelease"
view_top: 1
- name: Print result
run: |
echo "id: ${{ steps.last_release.outputs.id }}"
echo "name: ${{ steps.last_release.outputs.name }}"
echo "tag_name: ${{ steps.last_release.outputs.tag_name }}"
echo "created_at: ${{ steps.last_release.outputs.created_at }}"
echo "draft: ${{ steps.last_release.outputs.draft }}"
echo "prerelease: ${{ steps.last_release.outputs.prerelease }}"
echo "url: ${{ steps.last_release.outputs.url }}"
- name: Check & Compare versions
run: bash ./.github/scripts/check_versions.sh ${{ steps.last_release.outputs.tag_name }}

14 changes: 14 additions & 0 deletions lib/ESP32_USB_STREAM/.github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
71 changes: 71 additions & 0 deletions lib/ESP32_USB_STREAM/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.config
*.o
*.pyc
*.orig

# gtags
GTAGS
GRTAGS
GPATH

# emacs
.dir-locals.el

# emacs temp file suffixes
*~
.#*
\#*#

# eclipse setting
.settings

# MacOS directory files
.DS_Store

# Unit Test CMake compile log folder
log_ut_cmake

TEST_LOGS

# gcov coverage reports
*.gcda
*.gcno
coverage.info
coverage_report/

test_multi_heap_host

# VS Code Settings
.vscode/

# VIM files
*.swp
*.swo

# Clion IDE CMake build & config
.idea/
cmake-build-*/

# Results for the checking of the Python coding style and static analysis
.mypy_cache
flake8_output.txt

# esp-idf default build directory name
build
build_esp*/
build_linux*/
size_info.txt
sdkconfig
sdkconfig.old

# lock files for examples and components
dependencies.lock

# managed_components for examples
managed_components

# pytest log
pytest_embedded_log/
pytest_log/
.pytest_cache/
XUNIT_RESULT.xml
26 changes: 26 additions & 0 deletions lib/ESP32_USB_STREAM/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
exclude: 'src/original'
repos:
- repo: https://github.com/igrr/astyle_py.git
rev: master
hooks:
- id: astyle_py
args: ['--style=otbs', '--attach-namespaces', '--attach-classes', '--indent=spaces=4', '--convert-tabs', '--align-pointer=name', '--align-reference=name', '--keep-one-line-statements', '--pad-header', '--pad-oper']

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
types_or: [c, c++]
- id: end-of-file-fixer
types_or: [c, c++]
- id: check-merge-conflict
- id: mixed-line-ending
types_or: [c, c++]
args: ['--fix=lf']
description: Forces to replace line ending by the UNIX 'lf' character

- repo: https://github.com/espressif/check-copyright/
rev: v1.0.3
hooks:
- id: check-copyright
args: ['--config', 'check_copyright_config.yaml']
11 changes: 11 additions & 0 deletions lib/ESP32_USB_STREAM/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ChangeLog

## v0.0.1 - [2023-11-10]

### Enhancements:

* Only support for ESP32-S2 and ESP32-S3 SoCs.
* Support video stream through UVC Stream interface.
* Support microphone stream and speaker stream through the UAC Stream interface
* Support volume, mute and other features control through the UAC Control interface
* Support stream separately suspend and resume
69 changes: 69 additions & 0 deletions lib/ESP32_USB_STREAM/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[![Arduino Lint](https://github.com/esp-arduino-libs/ESP32_USB_Stream/actions/workflows/arduino_lint.yml/badge.svg)](https://github.com/esp-arduino-libs/ESP32_USB_Stream/actions/workflows/arduino_lint.yml) [![pre-commit](https://github.com/esp-arduino-libs/ESP32_USB_Stream/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/esp-arduino-libs/ESP32_USB_Stream/actions/workflows/pre-commit.yml)

# ESP32_USB_STREAM

ESP32_USB_STREAM is an Arduino library designed to support USB UVC + UAC host driver for ESP32-S2/ESP32-S3. It supports read/write/control multimedia streaming from usb device. For example, at most one UVC + one Microphone + one Speaker streaming can be supported at the same time.

ESP32_USB_STREAM encapsulates the component from the [Espressif Components Registry](https://components.espressif.com/). It is developed based on [arduino-esp32](https://github.com/espressif/arduino-esp32) and can be easily downloaded and integrated into the Arduino IDE.

## Features

* Only support for ESP32-S2 and ESP32-S3 SoCs.
* Support video stream through UVC Stream interface.
* Support microphone stream and speaker stream through the UAC Stream interface
* Support volume, mute and other features control through the UAC Control interface
* Support stream separately suspend and resume

## Supported Drivers

| **Driver** | **Version** |
| ------------------------------------------------------------------ | ----------- |
| [usb_stream](https://components.espressif.com/components/espressif/usb_stream) |1.2.0|

## How to Use

For information on how to use the library in the Arduino IDE, please refer to the documentation for [Arduino IDE v1.x.x](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries) or [Arduino IDE v2.x.x](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-installing-a-library).

## Dependencies Version

| **Name** | **Version** |
| -------------------------------------------------------------------------- | ----------- |
| [arduino-esp32](https://github.com/espressif/arduino-esp32) | >= v2.0.14 |

### Examples

* [Getting started with a UVC](examples/GettingStartUVC/): Demonstrates how to use usb video streaming.
* [Getting started with a UAC](examples/GettingStartUAC/): Demonstrates how to use usb audio streaming.

### Detailed Usage

```cpp
#include "USB_STREAM.h"

// Instantiate a Ustream object
USB_STREAM *usb = new USB_STREAM();

// allocate memory
uint8_t *_xferBufferA = (uint8_t *)malloc(55 * 1024);
assert(_xferBufferA != NULL);
uint8_t *_xferBufferB = (uint8_t *)malloc(55 * 1024);
assert(_xferBufferB != NULL);
uint8_t *_frameBuffer = (uint8_t *)malloc(55 * 1024);
assert(_frameBuffer != NULL);

// Config the parameter
usb->uvcConfiguration(FRAME_RESOLUTION_ANY, FRAME_RESOLUTION_ANY, FRAME_INTERVAL_FPS_15, 55 * 1024, _xferBufferA, _xferBufferB, 55 * 1024, _frameBuffer);


//Register the camera frame callback function
usb->uvcCamRegisterFrameCb(&cameraFramecb, NULL);

usb->start();

/*Dont forget to free the allocated memory*/
// free(_xferBufferA);
// free(_xferBufferB);
// free(_frameBuffer);

```
Note: For additional details and information about the **usb_stream** functionality, please refer to the documentation provided by [ESP-IOT Solutions](https://github.com/espressif/esp-iot-solution/tree/master/components/usb/usb_stream).
41 changes: 41 additions & 0 deletions lib/ESP32_USB_STREAM/check_copyright_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
DEFAULT:
perform_check: yes # should the check be performed?
# Sections setting this to 'no' don't need to include any other options as they are ignored
# When a file is using a section with the option set to 'no', no checks are performed.

# what licenses (or license expressions) are allowed for files in this section
# when setting this option in a section, you need to list all the allowed licenses
allowed_licenses:
- Apache-2.0
license_for_new_files: Apache-2.0 # license to be used when inserting a new copyright notice
new_notice_c: | # notice for new C, CPP, H, HPP and LD files
/*
* SPDX-FileCopyrightText: {years} Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: {license}
*/
new_notice_python: | # notice for new python files
# SPDX-FileCopyrightText: {years} Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: {license}
# comment lines matching:
# SPDX-FileCopyrightText: year[-year] Espressif Systems
# or
# SPDX-FileContributor: year[-year] Espressif Systems
# are replaced with this template prefixed with the correct comment notation (# or // or *) and SPDX- notation
espressif_copyright: '{years} Espressif Systems (Shanghai) CO LTD'

# You can create your own rules for files or group of files
examples_and_unit_tests:
include:
- 'test_apps/'
allowed_licenses:
- Apache-2.0
- Unlicense
- CC0-1.0
license_for_new_files: CC0-1.0

ignore: # You can also select ignoring files here
perform_check: no # Don't check files from that block
include:
- 'examples/'
45 changes: 45 additions & 0 deletions lib/ESP32_USB_STREAM/examples/GettingStartUAC/GettingStartUAC.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <Arduino.h>
#include "USB_STREAM.h"

/* Define the Mic frame callback function implementation */
static void onMicFrameCallback(mic_frame_t *frame, void *ptr)
{
// We should using higher baudrate here, to reduce the blocking time here
Serial.printf("mic callback! bit_resolution = %u, samples_frequence = %"PRIu32", data_bytes = %"PRIu32"\n", frame->bit_resolution, frame->samples_frequence, frame->data_bytes);
}

void setup()
{
Serial.begin(115200);
// Instantiate a Ustream object
USB_STREAM *usb = new USB_STREAM();

// Config the parameter
usb->uacConfiguration(UAC_CH_ANY, UAC_BITS_ANY, UAC_FREQUENCY_ANY, 6400, UAC_CH_ANY, UAC_BITS_ANY, UAC_FREQUENCY_ANY, 6400);

//Register the camera frame callback function
usb->uacMicRegisterCb(&onMicFrameCallback, NULL);

usb->start();

usb->connectWait(1000);
delay(5000);

usb->uacMicMute((void *)0);
delay(5000);

usb->uacMicVolume((void *)60);

usb->uacMicSuspend(NULL);
delay(5000);

usb->uacMicResume(NULL);

}

// The loop function runs repeatedly
void loop()
{
// Delay the task for 100ms
vTaskDelay(5000);
}
50 changes: 50 additions & 0 deletions lib/ESP32_USB_STREAM/examples/GettingStartUVC/GettingStartUVC.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <Arduino.h>
#include "USB_STREAM.h"

/* Define the camera frame callback function implementation */
static void onCameraFrameCallback(uvc_frame *frame, void *user_ptr)
{
Serial.printf("uvc callback! frame_format = %d, seq = %" PRIu32 ", width = %" PRIu32", height = %" PRIu32 ", length = %u, ptr = %d\n",
frame->frame_format, frame->sequence, frame->width, frame->height, frame->data_bytes, (int)user_ptr);
}

void setup()
{
Serial.begin(115200);
// Instantiate an object
USB_STREAM *usb = new USB_STREAM();

// allocate memory
uint8_t *_xferBufferA = (uint8_t *)malloc(55 * 1024);
assert(_xferBufferA != NULL);
uint8_t *_xferBufferB = (uint8_t *)malloc(55 * 1024);
assert(_xferBufferB != NULL);
uint8_t *_frameBuffer = (uint8_t *)malloc(55 * 1024);
assert(_frameBuffer != NULL);

// Config the parameter
usb->uvcConfiguration(FRAME_RESOLUTION_ANY, FRAME_RESOLUTION_ANY, FRAME_INTERVAL_FPS_15, 55 * 1024, _xferBufferA, _xferBufferB, 55 * 1024, _frameBuffer);

//Register the camera frame callback function
usb->uvcCamRegisterCb(&onCameraFrameCallback, NULL);

usb->start();

usb->connectWait(1000);
delay(5000);

usb->uvcCamSuspend(NULL);
delay(5000);

usb->uvcCamResume(NULL);

/*Dont forget to free the allocated memory*/
// free(_xferBufferA);
// free(_xferBufferB);
// free(_frameBuffer);
}

void loop()
{
vTaskDelay(100);
}
10 changes: 10 additions & 0 deletions lib/ESP32_USB_STREAM/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=ESP32_USB_STREAM
version=0.0.1
author=espressif
maintainer=alibukharai
sentence=ESP32_USB_STREAM is a specialized library created to facilitate the implementation of USB stream functionality on ESP SoCs.
paragraph=This means that it provides a convenient and efficient way to transmit audio and video data through USB connections, making it an invaluable tool for a wide range of applications such as audio and video streaming, data transfer, and more. Currently, it is only competible with ESP32-S2 and ESP32-S3.
category=Other
architectures=esp32
url=https://github.com/esp-arduino-libs/ESP32_USB_Stream
includes=USB_STREAM.h
Loading

0 comments on commit 5397b63

Please sign in to comment.