Skip to content

Commit ae96410

Browse files
authored
Merge pull request #11 from espressif/master
17042021
2 parents 137302e + cfa3aa6 commit ae96410

File tree

10 files changed

+1995
-153
lines changed

10 files changed

+1995
-153
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if [ $? -ne 0 ]; then exit 1; fi
2020
source ./tools/install-esp-idf.sh
2121
if [ $? -ne 0 ]; then exit 1; fi
2222

23-
TARGETS="esp32s2 esp32"
23+
TARGETS="esp32c3 esp32s2 esp32"
2424

2525
echo $(git -C $AR_COMPS/arduino describe --all --long) > version.txt
2626

components/arduino_tinyusb/src/dcd_esp32s2.c

Lines changed: 127 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
#include "tusb_option.h"
30+
#include "common/tusb_fifo.h"
3031

3132
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 && TUSB_OPT_DEVICE_ENABLED
3233

@@ -59,6 +60,7 @@
5960

6061
typedef struct {
6162
uint8_t *buffer;
63+
// tu_fifo_t * ff; // TODO support dcd_edpt_xfer_fifo API
6264
uint16_t total_len;
6365
uint16_t queued_len;
6466
uint16_t max_size;
@@ -371,6 +373,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
371373

372374
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
373375
xfer->buffer = buffer;
376+
// xfer->ff = NULL; // TODO support dcd_edpt_xfer_fifo API
374377
xfer->total_len = total_bytes;
375378
xfer->queued_len = 0;
376379
xfer->short_packet = false;
@@ -406,6 +409,56 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
406409
return true;
407410
}
408411

412+
#if 0 // TODO support dcd_edpt_xfer_fifo API
413+
bool dcd_edpt_xfer_fifo (uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes)
414+
{
415+
(void)rhport;
416+
417+
// USB buffers always work in bytes so to avoid unnecessary divisions we demand item_size = 1
418+
TU_ASSERT(ff->item_size == 1);
419+
420+
uint8_t const epnum = tu_edpt_number(ep_addr);
421+
uint8_t const dir = tu_edpt_dir(ep_addr);
422+
423+
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
424+
xfer->buffer = NULL;
425+
xfer->ff = ff;
426+
xfer->total_len = total_bytes;
427+
xfer->queued_len = 0;
428+
xfer->short_packet = false;
429+
430+
uint16_t num_packets = (total_bytes / xfer->max_size);
431+
uint8_t short_packet_size = total_bytes % xfer->max_size;
432+
433+
// Zero-size packet is special case.
434+
if (short_packet_size > 0 || (total_bytes == 0)) {
435+
num_packets++;
436+
}
437+
438+
ESP_LOGV(TAG, "Transfer <-> EP%i, %s, pkgs: %i, bytes: %i",
439+
epnum, ((dir == TUSB_DIR_IN) ? "USB0.HOST (in)" : "HOST->DEV (out)"),
440+
num_packets, total_bytes);
441+
442+
// IN and OUT endpoint xfers are interrupt-driven, we just schedule them
443+
// here.
444+
if (dir == TUSB_DIR_IN) {
445+
// A full IN transfer (multiple packets, possibly) triggers XFRC.
446+
USB0.in_ep_reg[epnum].dieptsiz = (num_packets << USB_D_PKTCNT0_S) | total_bytes;
447+
USB0.in_ep_reg[epnum].diepctl |= USB_D_EPENA1_M | USB_D_CNAK1_M; // Enable | CNAK
448+
449+
// Enable fifo empty interrupt only if there are something to put in the fifo.
450+
if(total_bytes != 0) {
451+
USB0.dtknqr4_fifoemptymsk |= (1 << epnum);
452+
}
453+
} else {
454+
// Each complete packet for OUT xfers triggers XFRC.
455+
USB0.out_ep_reg[epnum].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
456+
USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
457+
}
458+
return true;
459+
}
460+
#endif
461+
409462
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
410463
{
411464
(void)rhport;
@@ -514,35 +567,46 @@ static void receive_packet(xfer_ctl_t *xfer, /* usb_out_endpoint_t * out_ep, */
514567
to_recv_size = (xfer_size > xfer->max_size) ? xfer->max_size : xfer_size;
515568
}
516569

517-
uint8_t to_recv_rem = to_recv_size % 4;
518-
uint16_t to_recv_size_aligned = to_recv_size - to_recv_rem;
519-
520-
// Do not assume xfer buffer is aligned.
521-
uint8_t *base = (xfer->buffer + xfer->queued_len);
522-
523-
// This for loop always runs at least once- skip if less than 4 bytes
524-
// to collect.
525-
if (to_recv_size >= 4) {
526-
for (uint16_t i = 0; i < to_recv_size_aligned; i += 4) {
527-
uint32_t tmp = (*rx_fifo);
528-
base[i] = tmp & 0x000000FF;
529-
base[i + 1] = (tmp & 0x0000FF00) >> 8;
530-
base[i + 2] = (tmp & 0x00FF0000) >> 16;
531-
base[i + 3] = (tmp & 0xFF000000) >> 24;
532-
}
570+
// Common buffer read
571+
#if 0 // TODO support dcd_edpt_xfer_fifo API
572+
if (xfer->ff)
573+
{
574+
// Ring buffer
575+
tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void *) rx_fifo, to_recv_size);
533576
}
577+
else
578+
#endif
579+
{
580+
uint8_t to_recv_rem = to_recv_size % 4;
581+
uint16_t to_recv_size_aligned = to_recv_size - to_recv_rem;
582+
583+
// Do not assume xfer buffer is aligned.
584+
uint8_t *base = (xfer->buffer + xfer->queued_len);
585+
586+
// This for loop always runs at least once- skip if less than 4 bytes
587+
// to collect.
588+
if (to_recv_size >= 4) {
589+
for (uint16_t i = 0; i < to_recv_size_aligned; i += 4) {
590+
uint32_t tmp = (*rx_fifo);
591+
base[i] = tmp & 0x000000FF;
592+
base[i + 1] = (tmp & 0x0000FF00) >> 8;
593+
base[i + 2] = (tmp & 0x00FF0000) >> 16;
594+
base[i + 3] = (tmp & 0xFF000000) >> 24;
595+
}
596+
}
534597

535-
// Do not read invalid bytes from RX FIFO.
536-
if (to_recv_rem != 0) {
537-
uint32_t tmp = (*rx_fifo);
538-
uint8_t *last_32b_bound = base + to_recv_size_aligned;
598+
// Do not read invalid bytes from RX FIFO.
599+
if (to_recv_rem != 0) {
600+
uint32_t tmp = (*rx_fifo);
601+
uint8_t *last_32b_bound = base + to_recv_size_aligned;
539602

540-
last_32b_bound[0] = tmp & 0x000000FF;
541-
if (to_recv_rem > 1) {
542-
last_32b_bound[1] = (tmp & 0x0000FF00) >> 8;
543-
}
544-
if (to_recv_rem > 2) {
545-
last_32b_bound[2] = (tmp & 0x00FF0000) >> 16;
603+
last_32b_bound[0] = tmp & 0x000000FF;
604+
if (to_recv_rem > 1) {
605+
last_32b_bound[1] = (tmp & 0x0000FF00) >> 8;
606+
}
607+
if (to_recv_rem > 2) {
608+
last_32b_bound[2] = (tmp & 0x00FF0000) >> 16;
609+
}
546610
}
547611
}
548612

@@ -562,37 +626,47 @@ static void transmit_packet(xfer_ctl_t *xfer, volatile usb_in_endpoint_t *in_ep,
562626
xfer->queued_len = xfer->total_len - remaining;
563627

564628
uint16_t to_xfer_size = (remaining > xfer->max_size) ? xfer->max_size : remaining;
565-
uint8_t to_xfer_rem = to_xfer_size % 4;
566-
uint16_t to_xfer_size_aligned = to_xfer_size - to_xfer_rem;
567-
568-
// Buffer might not be aligned to 32b, so we need to force alignment
569-
// by copying to a temp var.
570-
uint8_t *base = (xfer->buffer + xfer->queued_len);
571-
572-
// This for loop always runs at least once- skip if less than 4 bytes
573-
// to send off.
574-
if (to_xfer_size >= 4) {
575-
for (uint16_t i = 0; i < to_xfer_size_aligned; i += 4) {
576-
uint32_t tmp = base[i] | (base[i + 1] << 8) |
577-
(base[i + 2] << 16) | (base[i + 3] << 24);
578-
(*tx_fifo) = tmp;
579-
}
629+
630+
#if 0 // TODO support dcd_edpt_xfer_fifo API
631+
if (xfer->ff)
632+
{
633+
tu_fifo_read_n_const_addr_full_words(xfer->ff, (void *) tx_fifo, to_xfer_size);
580634
}
635+
else
636+
#endif
637+
{
638+
uint8_t to_xfer_rem = to_xfer_size % 4;
639+
uint16_t to_xfer_size_aligned = to_xfer_size - to_xfer_rem;
640+
641+
// Buffer might not be aligned to 32b, so we need to force alignment
642+
// by copying to a temp var.
643+
uint8_t *base = (xfer->buffer + xfer->queued_len);
644+
645+
// This for loop always runs at least once- skip if less than 4 bytes
646+
// to send off.
647+
if (to_xfer_size >= 4) {
648+
for (uint16_t i = 0; i < to_xfer_size_aligned; i += 4) {
649+
uint32_t tmp = base[i] | (base[i + 1] << 8) |
650+
(base[i + 2] << 16) | (base[i + 3] << 24);
651+
(*tx_fifo) = tmp;
652+
}
653+
}
581654

582-
// Do not read beyond end of buffer if not divisible by 4.
583-
if (to_xfer_rem != 0) {
584-
uint32_t tmp = 0;
585-
uint8_t *last_32b_bound = base + to_xfer_size_aligned;
655+
// Do not read beyond end of buffer if not divisible by 4.
656+
if (to_xfer_rem != 0) {
657+
uint32_t tmp = 0;
658+
uint8_t *last_32b_bound = base + to_xfer_size_aligned;
586659

587-
tmp |= last_32b_bound[0];
588-
if (to_xfer_rem > 1) {
589-
tmp |= (last_32b_bound[1] << 8);
590-
}
591-
if (to_xfer_rem > 2) {
592-
tmp |= (last_32b_bound[2] << 16);
593-
}
660+
tmp |= last_32b_bound[0];
661+
if (to_xfer_rem > 1) {
662+
tmp |= (last_32b_bound[1] << 8);
663+
}
664+
if (to_xfer_rem > 2) {
665+
tmp |= (last_32b_bound[2] << 16);
666+
}
594667

595-
(*tx_fifo) = tmp;
668+
(*tx_fifo) = tmp;
669+
}
596670
}
597671
}
598672

components/fb_gfx/fb_gfx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ uint8_t fb_gfx_putc(fb_data_t *fb, int32_t x, int32_t y, uint32_t color, unsigne
108108
return xa;
109109
}
110110

111-
uint32_t fb_gfx_print(fb_data_t *fb, int x, int y, uint32_t color, const char * str)
111+
uint32_t fb_gfx_print(fb_data_t *fb, int32_t x, int32_t y, uint32_t color, const char * str)
112112
{
113113
uint32_t l = 0;
114114
int xc = x, yc = y, lc = fb->width - gfxFont->glyph[0].xAdvance;

sdkconfig.esp32

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,6 @@ CONFIG_SPIRAM_SPIWP_SD3_PIN=7
553553

554554
# CONFIG_ESP32_TRAX is not set
555555
CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0
556-
# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set
557-
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y
558-
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4
559556
CONFIG_ESP32_ULP_COPROC_ENABLED=y
560557
CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=512
561558
CONFIG_ESP32_DEBUG_OCDAWARE=y
@@ -569,7 +566,6 @@ CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y
569566
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_6 is not set
570567
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set
571568
CONFIG_ESP32_BROWNOUT_DET_LVL=0
572-
CONFIG_ESP32_REDUCE_PHY_TX_POWER=y
573569
CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
574570
# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
575571
# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
@@ -678,7 +674,15 @@ CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y
678674
CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
679675
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y
680676
CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y
677+
# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set
678+
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y
679+
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4
681680
# end of MAC Config
681+
682+
#
683+
# Sleep Config
684+
#
685+
# end of Sleep Config
682686
# end of Hardware Settings
683687

684688
#
@@ -785,6 +789,7 @@ CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
785789
# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set
786790
CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20
787791
CONFIG_ESP32_PHY_MAX_TX_POWER=20
792+
CONFIG_ESP32_REDUCE_PHY_TX_POWER=y
788793
# end of PHY
789794

790795
#
@@ -1035,6 +1040,7 @@ CONFIG_LWIP_PPP_PAP_SUPPORT=y
10351040
CONFIG_LWIP_PPP_CHAP_SUPPORT=y
10361041
CONFIG_LWIP_PPP_MSCHAP_SUPPORT=y
10371042
CONFIG_LWIP_PPP_MPPE_SUPPORT=y
1043+
# CONFIG_LWIP_ENABLE_LCP_ECHO is not set
10381044
# CONFIG_LWIP_PPP_DEBUG_ON is not set
10391045
# CONFIG_LWIP_SLIP_SUPPORT is not set
10401046

@@ -1058,13 +1064,6 @@ CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1
10581064
CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000
10591065
# end of SNTP
10601066

1061-
#
1062-
# LCP
1063-
#
1064-
CONFIG_LCP_ECHOINTERVAL=0
1065-
CONFIG_LCP_MAXECHOFAILS=3
1066-
# end of LCP
1067-
10681067
CONFIG_LWIP_ESP_LWIP_ASSERT=y
10691068

10701069
#
@@ -1081,22 +1080,7 @@ CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE=y
10811080
# CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_CUSTOM is not set
10821081
# end of Hooks
10831082

1084-
#
1085-
# Debug
1086-
#
1087-
# CONFIG_LWIP_NETIF_DEBUG is not set
1088-
# CONFIG_LWIP_PBUF_DEBUG is not set
1089-
# CONFIG_LWIP_ETHARP_DEBUG is not set
1090-
# CONFIG_LWIP_API_LIB_DEBUG is not set
1091-
# CONFIG_LWIP_SOCKETS_DEBUG is not set
1092-
# CONFIG_LWIP_IP_DEBUG is not set
1093-
# CONFIG_LWIP_ICMP_DEBUG is not set
1094-
# CONFIG_LWIP_DHCP_STATE_DEBUG is not set
1095-
# CONFIG_LWIP_DHCP_DEBUG is not set
1096-
# CONFIG_LWIP_IP6_DEBUG is not set
1097-
# CONFIG_LWIP_ICMP6_DEBUG is not set
1098-
# CONFIG_LWIP_TCP_DEBUG is not set
1099-
# end of Debug
1083+
# CONFIG_LWIP_DEBUG is not set
11001084
# end of LWIP
11011085

11021086
#
@@ -1229,6 +1213,7 @@ CONFIG_MDNS_TASK_AFFINITY_CPU0=y
12291213
# CONFIG_MDNS_TASK_AFFINITY_CPU1 is not set
12301214
CONFIG_MDNS_TASK_AFFINITY=0x0
12311215
CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000
1216+
# CONFIG_MDNS_STRICT_MODE is not set
12321217
CONFIG_MDNS_TIMER_PERIOD_MS=100
12331218
# end of mDNS
12341219

@@ -1273,6 +1258,12 @@ CONFIG_OPENSSL_ASSERT_DO_NOTHING=y
12731258
# CONFIG_OPENSSL_ASSERT_EXIT is not set
12741259
# end of OpenSSL
12751260

1261+
#
1262+
# OpenThread
1263+
#
1264+
# CONFIG_OPENTHREAD_ENABLED is not set
1265+
# end of OpenThread
1266+
12761267
#
12771268
# PThreads
12781269
#
@@ -1609,9 +1600,6 @@ CONFIG_ADC2_DISABLE_DAC=y
16091600
CONFIG_SPIRAM_SUPPORT=y
16101601
# CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST is not set
16111602
CONFIG_TRACEMEM_RESERVE_DRAM=0x0
1612-
# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
1613-
CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
1614-
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
16151603
CONFIG_ULP_COPROC_ENABLED=y
16161604
CONFIG_ULP_COPROC_RESERVE_MEM=512
16171605
CONFIG_BROWNOUT_DET=y
@@ -1624,7 +1612,6 @@ CONFIG_BROWNOUT_DET_LVL_SEL_0=y
16241612
# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set
16251613
# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set
16261614
CONFIG_BROWNOUT_DET_LVL=0
1627-
CONFIG_REDUCE_PHY_TX_POWER=y
16281615
CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
16291616
# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set
16301617
# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC is not set
@@ -1634,6 +1621,9 @@ CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
16341621
# CONFIG_EVENT_LOOP_PROFILING is not set
16351622
CONFIG_POST_EVENTS_FROM_ISR=y
16361623
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
1624+
# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
1625+
CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
1626+
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
16371627
# CONFIG_ESP32S2_PANIC_PRINT_HALT is not set
16381628
CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y
16391629
# CONFIG_ESP32S2_PANIC_SILENT_REBOOT is not set
@@ -1658,6 +1648,7 @@ CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
16581648
CONFIG_IPC_TASK_STACK_SIZE=1024
16591649
CONFIG_TIMER_TASK_STACK_SIZE=4096
16601650
CONFIG_SW_COEXIST_ENABLE=y
1651+
CONFIG_REDUCE_PHY_TX_POWER=y
16611652
# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
16621653
# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
16631654
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y

0 commit comments

Comments
 (0)