Skip to content
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

Release/v4.4 [for tests] #130

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.5)

set(RMAKER_PATH ${CMAKE_SOURCE_DIR}/components/esp-rainmaker)
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components/esp-insights/components ${RMAKER_PATH}/components ${CMAKE_SOURCE_DIR}/components/esp-insights/components)
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components/esp-insights/components ${RMAKER_PATH}/components)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(arduino-lib-builder)
Expand Down
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ TARGET="all"
BUILD_TYPE="all"
SKIP_ENV=0
COPY_OUT=0
DEPLOY_OUT=0
if [ -z $DEPLOY_OUT ]; then
DEPLOY_OUT=0
fi

function print_help() {
echo "Usage: build.sh [-s] [-A <arduino_branch>] [-I <idf_branch>] [-i <idf_commit>] [-c <path>] [-t <target>] [-b <build|menuconfig|idf_libs|copy_bootloader|mem_variant>] [config ...]"
Expand Down
1 change: 1 addition & 0 deletions components/arduino_tinyusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if(CONFIG_TINYUSB_ENABLED)
"${COMPONENT_DIR}/tinyusb/src/class/msc/msc_device.c"
"${COMPONENT_DIR}/tinyusb/src/class/video/video_device.c"
"${COMPONENT_DIR}/tinyusb/src/class/dfu/dfu_rt_device.c"
"${COMPONENT_DIR}/tinyusb/src/class/dfu/dfu_device.c"
"${COMPONENT_DIR}/tinyusb/src/class/vendor/vendor_device.c"
"${COMPONENT_DIR}/tinyusb/src/common/tusb_fifo.c"
"${COMPONENT_DIR}/tinyusb/src/device/usbd_control.c"
Expand Down
25 changes: 25 additions & 0 deletions components/arduino_tinyusb/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,31 @@ menu "Arduino TinyUSB"

endmenu

menu "DFU driver"
depends on TINYUSB_ENABLED

config TINYUSB_DFU_ENABLED
bool "Enable USB DFU TinyUSB driver"
default y
help
Enable USB DFU TinyUSB driver.

config TINYUSB_DESC_DFU_STRING
string "DFU Device String"
default "Espressif DFU Device"
depends on TINYUSB_DFU_ENABLED
help
Specify name of the DFU device

config TINYUSB_DFU_BUFSIZE
int "DFU buffer size"
default 4096
depends on TINYUSB_DFU_ENABLED
help
DFU buffer size

endmenu

menu "VENDOR driver"
depends on TINYUSB_ENABLED

Expand Down
8 changes: 8 additions & 0 deletions components/arduino_tinyusb/include/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ extern "C" {
# define CONFIG_TINYUSB_DFU_RT_ENABLED 0
#endif

#ifndef CONFIG_TINYUSB_DFU_ENABLED
# define CONFIG_TINYUSB_DFU_ENABLED 0
#endif

#ifndef CONFIG_TINYUSB_VENDOR_ENABLED
# define CONFIG_TINYUSB_VENDOR_ENABLED 0
#endif
Expand Down Expand Up @@ -106,6 +110,7 @@ extern "C" {
#define CFG_TUD_VIDEO CONFIG_TINYUSB_VIDEO_ENABLED
#define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED
#define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_RT_ENABLED
#define CFG_TUD_DFU CONFIG_TINYUSB_DFU_ENABLED
#define CFG_TUD_VENDOR CONFIG_TINYUSB_VENDOR_ENABLED

// CDC FIFO size of TX and RX
Expand All @@ -126,6 +131,9 @@ extern "C" {
#define CFG_TUD_VIDEO_STREAMING CONFIG_TINYUSB_VIDEO_STREAMING_IFS
#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE CONFIG_TINYUSB_VIDEO_STREAMING_BUFSIZE

// DFU buffer size
#define CFG_TUD_DFU_XFER_BUFSIZE CONFIG_TINYUSB_DFU_BUFSIZE

// VENDOR FIFO size of TX and RX
#define CFG_TUD_VENDOR_RX_BUFSIZE CONFIG_TINYUSB_VENDOR_RX_BUFSIZE
#define CFG_TUD_VENDOR_TX_BUFSIZE CONFIG_TINYUSB_VENDOR_TX_BUFSIZE
Expand Down
54 changes: 48 additions & 6 deletions components/arduino_tinyusb/src/dcd_esp32sx.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,30 @@

#include "tusb_option.h"

#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && TUSB_OPT_DEVICE_ENABLED)
#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && CFG_TUD_ENABLED)

// Espressif
#include "driver/periph_ctrl.h"
#include "freertos/xtensa_api.h"
#include "esp_intr_alloc.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "soc/dport_reg.h"
#include "soc/gpio_sig_map.h"
#include "soc/usb_periph.h"
#include "soc/usb_reg.h"
#include "soc/usb_struct.h"
#include "soc/periph_defs.h" // for interrupt source
#include "soc/usb_wrap_struct.h"

#include "device/dcd.h"

#ifndef USB_OUT_EP_NUM
#define USB_OUT_EP_NUM ((int) (sizeof(USB0.out_ep_reg) / sizeof(USB0.out_ep_reg[0])))
#endif

#ifndef USB_IN_EP_NUM
#define USB_IN_EP_NUM ((int) (sizeof(USB0.in_ep_reg) / sizeof(USB0.in_ep_reg[0])))
#endif

// Max number of bi-directional endpoints including EP0
// Note: ESP32S2 specs say there are only up to 5 IN active endpoints include EP0
// We should probably prohibit enabling Endpoint IN > 4 (not done yet)
Expand All @@ -60,6 +70,7 @@ typedef struct {
uint16_t queued_len;
uint16_t max_size;
bool short_packet;
uint8_t interval;
} xfer_ctl_t;

static const char *TAG = "TUSB:DCD";
Expand Down Expand Up @@ -284,6 +295,14 @@ void dcd_disconnect(uint8_t rhport)
USB0.dctl |= USB_SFTDISCON_M;
}

void dcd_sof_enable(uint8_t rhport, bool en)
{
(void) rhport;
(void) en;

// TODO implement later
}

/*------------------------------------------------------------------*/
/* DCD Endpoint port
*------------------------------------------------------------------*/
Expand All @@ -303,6 +322,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)

xfer_ctl_t *xfer = XFER_CTL_BASE(epnum, dir);
xfer->max_size = tu_edpt_packet_size(desc_edpt);
xfer->interval = desc_edpt->bInterval;

if (dir == TUSB_DIR_OUT) {
out_ep[epnum].doepctl &= ~(USB_D_EPTYPE0_M | USB_D_MPS0_M);
Expand Down Expand Up @@ -423,6 +443,13 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
USB0.in_ep_reg[epnum].dieptsiz = (num_packets << USB_D_PKTCNT0_S) | total_bytes;
USB0.in_ep_reg[epnum].diepctl |= USB_D_EPENA1_M | USB_D_CNAK1_M; // Enable | CNAK

// For ISO endpoint with interval=1 set correct DATA0/DATA1 bit for next frame
if ((USB0.in_ep_reg[epnum].diepctl & USB_D_EPTYPE0_M) == (1 << USB_D_EPTYPE1_S) && xfer->interval == 1) {
// Take odd/even bit from frame counter.
uint32_t const odd_frame_now = (USB0.dsts & (1u << USB_SOFFN_S));
USB0.in_ep_reg[epnum].diepctl |= (odd_frame_now ? USB_DI_SETD0PID1 : USB_DI_SETD1PID1);
}

// Enable fifo empty interrupt only if there are something to put in the fifo.
if(total_bytes != 0) {
USB0.dtknqr4_fifoemptymsk |= (1 << epnum);
Expand All @@ -431,6 +458,13 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
// Each complete packet for OUT xfers triggers XFRC.
USB0.out_ep_reg[epnum].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;

// For ISO endpoint with interval=1 set correct DATA0/DATA1 bit for next frame
if ((USB0.out_ep_reg[epnum].doepctl & USB_D_EPTYPE0_M) == (1 << USB_D_EPTYPE1_S) && xfer->interval == 1) {
// Take odd/even bit from frame counter.
uint32_t const odd_frame_now = (USB0.dsts & (1u << USB_SOFFN_S));
USB0.out_ep_reg[epnum].doepctl |= (odd_frame_now ? USB_DO_SETD0PID1 : USB_DO_SETD1PID1);
}
}
return true;
}
Expand Down Expand Up @@ -459,7 +493,8 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
} else {
// Stop transmitting packets and NAK IN xfers.
in_ep[epnum].diepctl |= USB_DI_SNAK1_M;
while ((in_ep[epnum].diepint & USB_DI_SNAK1_M) == 0) ;
// while ((in_ep[epnum].diepint & USB_DI_SNAK1_M) == 0) ;
while ((in_ep[epnum].diepint & USB_D_INEPNAKEFF1_M) == 0) ;

// Disable the endpoint. Note that both SNAK and STALL are set here.
in_ep[epnum].diepctl |= (USB_DI_SNAK1_M | USB_D_STALL1_M | USB_D_EPDIS1_M);
Expand All @@ -469,9 +504,16 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)

// Flush the FIFO, and wait until we have confirmed it cleared.
uint8_t const fifo_num = ((in_ep[epnum].diepctl >> USB_D_TXFNUM1_S) & USB_D_TXFNUM1_V);
USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
USB0.grstctl |= USB_TXFFLSH_M;
// USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
// USB0.grstctl |= USB_TXFFLSH_M;
// while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
uint32_t rstctl_last = USB0.grstctl;
uint32_t rstctl = USB_TXFFLSH_M;
rstctl |= (fifo_num << USB_TXFNUM_S);
USB0.grstctl = rstctl;
while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
USB0.grstctl = rstctl_last;
// TODO: Clear grstctl::fifo_num after fifo flsh
} else {
// Only disable currently enabled non-control endpoint
if ((epnum == 0) || !(out_ep[epnum].doepctl & USB_EPENA0_M)) {
Expand Down
Loading