Skip to content

Commit

Permalink
fix build platformio with arduino
Browse files Browse the repository at this point in the history
update

update docs, add examples

update docs

up

update build flags to fit esp-idf

add msc-fat example

move esp-idf examples to separate repo

Temporary remove guards to compile with arduino and esp-idf,
add sd card for sdspi and sd_mmc with example

Add sd card class with example,
sd class is working with both interfaces (spi and mmc)

Initial hid code

Initial hid code

fixed something

Fix examples

Some fixes

Some fixes

Refactor MSC

Refactor MSC

Refactor MSC

Add keyboard

Fix examples

Fix examples

Some fixes

Some fixes

Refactor MSC

Refactor MSC

Refactor MSC

Add keyboard

Fix examples

Create README.md

Add keyboard
  • Loading branch information
chegewara committed Nov 20, 2022
1 parent 67fca3b commit 4b4232c
Show file tree
Hide file tree
Showing 68 changed files with 2,714 additions and 568 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*/documentation/**

*/__pycache__/**

library.json

**/build/**
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "examples/esp-idf/hello-world-msc-fat/components/esp32-usb-v2"]
path = examples/esp-idf/hello-world-msc-fat/components/esp32-usb-v2
url = https://github.com/chegewara/esp32-usb-v2.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FILE(GLOB_RECURSE app_sources src/*.*)

idf_component_register(SRCS ${app_sources}
PRIV_REQUIRES tinyusb driver fatfs
INCLUDE_DIRS "./src/include"
INCLUDE_DIRS "./src"
)
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Description

This is very early version and still WiP, so API may and probably will change. All implemented devices are provided with simple examples for arduino.
Library is compatible with arduino, platformio, esp-idf and there will be also repository with examples for esp-idf.

I want to replace old callbacks build on `class callback` to use `std::function`, which also let us to use lambdas. In the future i maybe add C style callbacks too.
I wanted to make this library as much flexible as possible, so all tinyusb callbacks are weak and its possible to override any in user code (advanced users only).


Library allows to build USB class devices and to make it usable with minimal effort:
- [x] CDC, communication device class,
- [x] MSC, mass storage class,
- [x] HID, human interface device class: keyboard, mouse, generic IN/OUT, option to combine few reports
- [ ] MIDI, musical instrument digital interface class,
- [ ] DFU, device firmware update class,- its still not ready
- [x] WebUSB, its using vendor class to show webusb usage.

# How to
Library allows to set all values in standard USB device like:
- manufacturer
- product name
- serial number
- revision
- VID and PID

```
ANYusb device; // any USB class like HID, MSC, CDC
device.mfgStringId(addString(""));
device.productStringId(addString(""));
device.serialStringId(addString(""));
device.setVidPid(vid, pid);
device.setVersion(revisionBCD, usbBCD);
```

# Todo
There is still a lot to do, so any suggestions are welcome.

# Documentation
I would like to finish this project with fancy documentation, but this is time consuming and i have full time job and few more projects which i would like to continue, so any help is appreciated

https://tinyusb.esp32.eu.org/

# Contributions
Issues and PRs are welcome.

# Hardware
To use native USB we need to connect pins 19 and 20 to usb cable or with similar connectors:
![](https://ae01.alicdn.com/kf/HTB1MFvqNgHqK1RjSZJnq6zNLpXaR/10-sztuk-Mini-Micro-USB-do-DIP-2-54mm-Adapter-z-cze-modu-u-Panel-kobiet.jpg)
![](https://ae01.alicdn.com/kf/HTB1cfmCgcnI8KJjSspeq6AwIpXa6/AMS1117-3-3V-AMS1117-3-3V-Mini-USB-5V-3-3V-DC-Perfect-Power-Supply-Module.jpg)
68 changes: 68 additions & 0 deletions docs/Doxyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This is Doxygen configuration file
#
# Doxygen provides over 260 configuration statements
# To make this file easier to follow,
# it contains only statements that are non-default
#
# NOTE:
# It is recommended not to change defaults unless specifically required
# Test any changes how they affect generated documentation
# Make sure that correct warnings are generated to flag issues with documented code
#
# For the complete list of configuration statements see:
# http://doxygen.nl/manual/config.html


PROJECT_NAME = "Esp-docs simple example"

## The 'INPUT' statement below is used as input by script 'gen-df-input.py'
## to automatically generate API reference list files header_file.inc
## These files are placed in '_inc' directory
## and used to include in API reference documentation

INPUT = \
$(PROJECT_PATH)/src/private/descriptor.hpp \
$(PROJECT_PATH)/src/private/endpoint.hpp \
$(PROJECT_PATH)/src/private/interface.hpp \
$(PROJECT_PATH)/src/private/usb_device.hpp \
$(PROJECT_PATH)/src/flashdisk.hpp \
$(PROJECT_PATH)/src/ramdisk.hpp \
$(PROJECT_PATH)/src/sdcard.hpp \
$(PROJECT_PATH)/src/usb_cdc.hpp \
$(PROJECT_PATH)/src/usb_dfu.hpp \
$(PROJECT_PATH)/src/usb_hid.hpp \
$(PROJECT_PATH)/src/usb_mouse.hpp \
$(PROJECT_PATH)/src/usb_msc.hpp \
$(PROJECT_PATH)/src/usb_webusb.hpp \


## Get warnings for functions that have no documentation for their parameters or return value
##
WARN_NO_PARAMDOC = YES

## Enable preprocessing and remove __attribute__(...) expressions from the INPUT files
##
ENABLE_PREPROCESSING = NO
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
PREDEFINED = \
$(ENV_DOXYGEN_DEFINES)

## Do not complain about not having dot
##
HAVE_DOT = NO

## Generate XML that is required for Breathe
##
GENERATE_XML = YES
XML_OUTPUT = xml

GENERATE_HTML = NO
HAVE_DOT = NO
GENERATE_LATEX = NO
GENERATE_MAN = YES
GENERATE_RTF = NO

## Skip distracting progress messages
##
QUIET = YES
Empty file added docs/_static/README.md
Empty file.
5 changes: 5 additions & 0 deletions docs/build_latest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -u

build-docs -t esp32s3 -l en -pp .. -b documentation

26 changes: 26 additions & 0 deletions docs/conf_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from esp_docs.conf_docs import * # noqa: F403,F401

extensions += ['sphinx_copybutton',
'sphinxcontrib.wavedrom',
'esp_docs.esp_extensions.dummy_build_system',
'esp_docs.esp_extensions.run_doxygen',
]
# link roles config
github_repo = 'chegewara/esp32-usb-v2'

# # context used by sphinx_idf_theme
html_context['github_user'] = 'chegewara'
html_context['github_repo'] = 'esp32-usb-v2'

html_static_path = ['../_static']

# # Extra options required by sphinx_idf_theme
# project_slug = 'caplamp'
# project_slug = 'esp-idf'
# versions_url = './_static/doc_versions.js'

idf_targets = ['esp32s2', 'esp32s3']
languages = ['en']
linkcheck_anchors = False
todo_include_todos = True

24 changes: 24 additions & 0 deletions docs/en/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
#
# English Language RTD & Sphinx config file
#
# Uses ../conf_common.py for most non-language-specific settings.

# Importing conf_common adds all the non-language-specific
# parts to this conf module

try:
from conf_common import * # noqa: F403,F401
except ImportError:
import os
import sys
sys.path.insert(0, os.path.abspath('../'))
from conf_common import * # noqa: F403,F401

# General information about the project.
project = u'Esp32tinyusb'
copyright = u'2020-2022, chegewara'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
language = 'en'
7 changes: 7 additions & 0 deletions docs/en/device/classes/cdc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USB CDC
=======


:example:`/arduino/cdc/`

.. include-build-file:: inc/usb_cdc.inc
8 changes: 8 additions & 0 deletions docs/en/device/classes/dfu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
USB DFU
=======



:example:`/arduino/dfu/`

.. include-build-file:: inc/usb_dfu.inc
7 changes: 7 additions & 0 deletions docs/en/device/classes/flashdisk.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USB flashdisk
=============


:example:`/arduino/msc/flashdisk`

.. include-build-file:: inc/flashdisk.inc
17 changes: 17 additions & 0 deletions docs/en/device/classes/hid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
USB HID
=======


Examples
^^^^^^^^

:example:`keyboard </arduino/hid/keyboard>`

:example:`mouse </arduino/hid/mouse>`

:example:`composite </arduino/hid/composite>`

:example:`keyboard + mouse </arduino/hid/dual>`


.. include-build-file:: inc/usb_hid.inc
13 changes: 13 additions & 0 deletions docs/en/device/classes/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
USB classes
===========



.. toctree::
:maxdepth: 1

CDC <cdc>
DFU <dfu>
MSC <msc>
HID <hid>
WebUSB <webusb>
14 changes: 14 additions & 0 deletions docs/en/device/classes/msc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
USB MSC
=======




.. toctree::
:maxdepth: 1

Flashdisk <flashdisk>
Ramdisk <ramdisk>
Sd card <sdcard>

.. include-build-file:: inc/usb_msc.inc
7 changes: 7 additions & 0 deletions docs/en/device/classes/ramdisk.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USB ramdisk
===========


:example:`/arduino/msc/ramdisk`

.. include-build-file:: inc/ramdisk.inc
7 changes: 7 additions & 0 deletions docs/en/device/classes/sdcard.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USB sd card disk
================


:example:`/arduino/msc/sdcard`

.. include-build-file:: inc/sdcard.inc
7 changes: 7 additions & 0 deletions docs/en/device/classes/webusb.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USB WebUSB
==========


:example:`/arduino/web`

.. include-build-file:: inc/usb_webusb.inc
17 changes: 17 additions & 0 deletions docs/en/device/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
USB device
==========



.. toctree::
:maxdepth: 1

Devices <classes/index>

.. toctree::
:hidden:

.. include-build-file:: inc/descriptor.inc
.. include-build-file:: inc/endpoint.inc
.. include-build-file:: inc/interface.inc
.. include-build-file:: inc/usb_device.inc
6 changes: 6 additions & 0 deletions docs/en/host/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
USB host
========




13 changes: 13 additions & 0 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
USB library
==================
This is project i decided to start some time ago to learn USB peripheral on esp32-S2. First library is working, but its not the best, so i decided to rewrite it completely to make it compatible with arduino and esp-idf this time.

Although it is new library it is still reusing part of old code and has similar API, so it should be fairly easy to migrate code to new library for users. Both libraries, old and new one, should work with S2 and S3, but old library wont be supported when this one is finished.



.. toctree::
:hidden:

USB device <device/index>
USB host <host/index>
17 changes: 17 additions & 0 deletions docs/upload_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

FOLDER='./documentation/en/esp32s3/html'

ftp_site=192.168.0.5
username=$1
passwd=$2
remote=/usb-lib
cd ${FOLDER}
pwd

ncftp -u $username -p $passwd ftp://$ftp_site <<EOF
cd $remote
mput -r *
close
quit
34 changes: 34 additions & 0 deletions examples/arduino/cdc/cdc.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "Arduino.h"
#include "usb_cdc.hpp"

using namespace esptinyusb;

USBcdc cdc;

void setup()
{
Serial.begin(115200);

if (!cdc.begin())
printf("failed to begin cdc\n");

cdc.onData([](){
printf("new data\n");
});

}

void loop()
{
while(Serial.available())
{ // If anything comes in Serial (USB),
cdc.write(Serial.read());
}

while(cdc.available())
{ // If anything comes in Serial1 (pins 0 & 1)
Serial.write(cdc.read()); // read it and send it out Serial (USB)
}

delay(10);
}
Empty file added examples/arduino/dfu/dfu.ino
Empty file.
Loading

0 comments on commit 4b4232c

Please sign in to comment.