Skip to content

Commit d679b9b

Browse files
authored
Merge branch 'master' into usbhid_semaphore
2 parents 9c66cb5 + 85aecec commit d679b9b

File tree

26 files changed

+1496
-72
lines changed

26 files changed

+1496
-72
lines changed

boards.txt

+683
Large diffs are not rendered by default.

cores/esp32/Esp.cpp

+39-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
}
3131
#include <MD5Builder.h>
3232

33+
#include "soc/spi_reg.h"
3334
#include "esp_system.h"
3435
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
3536
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
@@ -55,6 +56,14 @@ extern "C" {
5556
#define ESP_FLASH_IMAGE_BASE 0x1000
5657
#endif
5758

59+
// REG_SPI_BASE is not defined for S3/C3 ??
60+
61+
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
62+
#ifndef REG_SPI_BASE
63+
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
64+
#endif // REG_SPI_BASE
65+
#endif // TARGET
66+
5867
/**
5968
* User-defined Literals
6069
* usage:
@@ -192,7 +201,7 @@ static uint32_t sketchSize(sketchSize_t response) {
192201
return data.image_len;
193202
}
194203
}
195-
204+
196205
uint32_t EspClass::getSketchSize () {
197206
return sketchSize(SKETCH_SIZE_TOTAL);
198207
}
@@ -305,13 +314,17 @@ const char * EspClass::getSdkVersion(void)
305314
return esp_get_idf_version();
306315
}
307316

317+
uint32_t ESP_getFlashChipId(void)
318+
{
319+
uint32_t id = g_rom_flashchip.device_id;
320+
id = ((id & 0xff) << 16) | ((id >> 16) & 0xff) | (id & 0xff00);
321+
return id;
322+
}
323+
308324
uint32_t EspClass::getFlashChipSize(void)
309325
{
310-
esp_image_header_t fhdr;
311-
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
312-
return 0;
313-
}
314-
return magicFlashChipSize(fhdr.spi_size);
326+
uint32_t id = (ESP_getFlashChipId() >> 16) & 0xFF;
327+
return 2 << (id - 1);
315328
}
316329

317330
uint32_t EspClass::getFlashChipSpeed(void)
@@ -325,11 +338,26 @@ uint32_t EspClass::getFlashChipSpeed(void)
325338

326339
FlashMode_t EspClass::getFlashChipMode(void)
327340
{
328-
esp_image_header_t fhdr;
329-
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
330-
return FM_UNKNOWN;
331-
}
332-
return magicFlashChipMode(fhdr.spi_mode);
341+
#if CONFIG_IDF_TARGET_ESP32S2
342+
uint32_t spi_ctrl = REG_READ(PERIPHS_SPI_FLASH_CTRL);
343+
#else
344+
uint32_t spi_ctrl = REG_READ(SPI_CTRL_REG(0));
345+
#endif
346+
/* Not all of the following constants are already defined in older versions of spi_reg.h, so do it manually for now*/
347+
if (spi_ctrl & BIT(24)) { //SPI_FREAD_QIO
348+
return (FM_QIO);
349+
} else if (spi_ctrl & BIT(20)) { //SPI_FREAD_QUAD
350+
return (FM_QOUT);
351+
} else if (spi_ctrl & BIT(23)) { //SPI_FREAD_DIO
352+
return (FM_DIO);
353+
} else if (spi_ctrl & BIT(14)) { // SPI_FREAD_DUAL
354+
return (FM_DOUT);
355+
} else if (spi_ctrl & BIT(13)) { //SPI_FASTRD_MODE
356+
return (FM_FAST_READ);
357+
} else {
358+
return (FM_SLOW_READ);
359+
}
360+
return (FM_DOUT);
333361
}
334362

335363
uint32_t EspClass::magicFlashChipSize(uint8_t byte)

docs/source/boards/boards.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Development Boards
88
You will need a development board or a custom board with the ESP32 (see Supported SoC's) to start playing.
99
There is a bunch of different types and models widely available on the Internet. You need to choose one that covers all your requirements.
1010

11-
To help you on this selection, we point out some facts about choosing the proper boardsto help you to save money and time.
11+
To help you on this selection, we point out some facts about choosing the proper boards to help you to save money and time.
1212

1313
**One ESP32 to rule them all!**
1414

@@ -112,4 +112,4 @@ Resources
112112

113113
.. |board_lolin_d32_pro| raw:: html
114114

115-
<a href="https://www.wemos.cc/en/latest/d32/d32_pro.html" target="_blank">LOLIN D32 Pro</a>
115+
<a href="https://www.wemos.cc/en/latest/d32/d32_pro.html" target="_blank">LOLIN D32 Pro</a>

docs/source/faq.rst

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ To use the arduino-esp32 core with a modified sdkconfig option, you need to use
1111

1212
Note that modifying ``sdkconfig`` or ``sdkconfig.h`` files found in the arduino-esp32 project tree **does not** result in changes to these options. This is because ESP-IDF libraries are included into the arduino-esp32 project tree as pre-built libraries.
1313

14+
How to compile libs with different debug level?
15+
-----------------------------------------------
16+
17+
The short answer is ``esp32-arduino-lib-builder/configs/defconfig.common:44``. A guide explaining the process can be found here <guides/core_debug>

docs/source/guides/core_debug.rst

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
##################################
2+
Compile Arduino libs with ESP_LOGx
3+
##################################
4+
5+
There are 2 primary approaches and both of them involve editing file ``configs/defconfig.common``.
6+
Edit the file directly and then build.
7+
Later you can ``git restore configs/defconfig.common`` to go back.
8+
Copy the file ``cp configs/defconfig.common configs/defconfig.debug`` and edit the debug version.
9+
10+
``vim configs/defconfig.common`` or ``vim configs/defconfig.debug``
11+
12+
Edit **line 44** containing by default ``CONFIG_LOG_DEFAULT_LEVEL_ERROR=y`` to one of the following lines depending on your desired log level:
13+
14+
.. code-block:: bash
15+
16+
CONFIG_LOG_DEFAULT_LEVEL_NONE=y # No output
17+
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y # Errors - default
18+
CONFIG_LOG_DEFAULT_LEVEL_WARN=y # Warnings
19+
CONFIG_LOG_DEFAULT_LEVEL_INFO=y # Info
20+
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # Debug
21+
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y # Verbose
22+
23+
Then simply build the libs for all SoCs or one specific SoC. Note that building for all SoCs takes a lot of time, so if you are working only with specific SoC(s), build only for those.
24+
25+
.. note::
26+
If you have copied the ``defconfig`` file and the debug settings are in file ``configs/defconfig.debug`` add flag ``debug`` to compilation command.
27+
Example : ``./build.sh debug``
28+
29+
- **Option 1**: Build for all SoCs: ``./build.sh``
30+
- **Option 2**: Build for one SoC: ``./build.sh -t <soc>``. The exact text to choose the SoC:
31+
32+
- ``esp32``
33+
- ``esp32s2``
34+
- ``esp32c3``
35+
- ``esp32s3``
36+
- Example: ``./build.sh -t esp32``
37+
- A wrong format or non-existing SoC will result in the error sed: can't read sdkconfig: No such file or directory
38+
- **Option 3**: Build for multiple SoCs (not all) - simply write them down separated with space: ``./build.sh -t <soc1> <soc2> <soc3>``
39+
40+
- Example: ``./build.sh -t esp32 esp32-c3``
41+

libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/.skip.esp32c3

Whitespace-only changes.

libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/.skip.esp32s2

Whitespace-only changes.

libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/.skip.esp32s3

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
This example smothly blinks GPIO_2 using different frequencies changed after Deep Sleep Time
3+
The PWM and control of blink frequency is done by ULP exclusively
4+
This is an example about how to program the ULP using Arduino
5+
It also demonstrates use of RTM MEMORY to persist data and states
6+
*/
7+
8+
#include <Arduino.h>
9+
#include "esp32/ulp.h"
10+
#include "driver/rtc_io.h"
11+
12+
// RTC Memory used for ULP internal variable and Sketch interfacing
13+
#define RTC_dutyMeter 0
14+
#define RTC_dir 4
15+
#define RTC_fadeDelay 12
16+
// *fadeCycleDelay is used to pass values to ULP and change its behaviour
17+
uint32_t *fadeCycleDelay = &RTC_SLOW_MEM[RTC_fadeDelay];
18+
#define ULP_START_OFFSET 32
19+
20+
// For ESP32 Arduino, it is usually at offeset 512, defined in sdkconfig
21+
RTC_DATA_ATTR uint32_t ULP_Started = 0; // 0 or 1
22+
23+
//Time-to-Sleep
24+
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
25+
#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in microseconds); multiplied by above conversion to achieve seconds*/
26+
27+
28+
void ulp_setup() {
29+
if (ULP_Started) {
30+
return;
31+
}
32+
*fadeCycleDelay = 5; // 5..200 works fine for a full Fade In + Out cycle
33+
ULP_Started = 1;
34+
35+
// GPIO2 initialization (set to output and initial value is 0)
36+
const gpio_num_t MeterPWMPin = GPIO_NUM_2;
37+
rtc_gpio_init(MeterPWMPin);
38+
rtc_gpio_set_direction(MeterPWMPin, RTC_GPIO_MODE_OUTPUT_ONLY);
39+
rtc_gpio_set_level(MeterPWMPin, 0);
40+
41+
// if LED is connected to GPIO2 (specify by +RTC_GPIO_OUT_DATA_S : ESP32 is 14, S2/S3 is 10)
42+
const uint32_t MeterPWMBit = rtc_io_number_get(MeterPWMPin) + RTC_GPIO_OUT_DATA_S;
43+
44+
enum labels {
45+
INIFINITE_LOOP,
46+
RUN_PWM,
47+
NEXT_PWM_CYCLE,
48+
PWM_ON,
49+
PWM_OFF,
50+
END_PWM_CYCLE,
51+
POSITIVE_DIR,
52+
DEC_DUTY,
53+
INC_DUTY,
54+
};
55+
56+
// Define ULP program
57+
const ulp_insn_t ulp_prog[] = {
58+
// Initial Value setup
59+
I_MOVI(R0, 0), // R0 = 0
60+
I_ST(R0, R0, RTC_dutyMeter), // RTC_SLOW_MEM[RTC_dutyMeter] = 0
61+
I_MOVI(R1, 1), // R1 = 1
62+
I_ST(R1, R0, RTC_dir), // RTC_SLOW_MEM[RTC_dir] = 1
63+
64+
M_LABEL(INIFINITE_LOOP), // while(1) {
65+
66+
// run certain PWM Duty for about (RTC_fadeDelay x 100) microseconds
67+
I_MOVI(R3, 0), // R3 = 0
68+
I_LD(R3, R3, RTC_fadeDelay), // R3 = RTC_SLOW_MEM[RTC_fadeDelay]
69+
M_LABEL(RUN_PWM), // do { // repeat RTC_fadeDelay times:
70+
71+
// execute about 10KHz PWM on GPIO2 using as duty cycle = RTC_SLOW_MEM[RTC_dutyMeter]
72+
I_MOVI(R0, 0), // R0 = 0
73+
I_LD(R0, R0, RTC_dutyMeter), // R0 = RTC_SLOW_MEM[RTC_dutyMeter]
74+
M_BL(NEXT_PWM_CYCLE, 1), // if (R0 > 0) turn on LED
75+
I_WR_REG(RTC_GPIO_OUT_W1TS_REG, MeterPWMBit, MeterPWMBit, 1), // W1TS set bit to clear GPIO - GPIO2 on
76+
M_LABEL(PWM_ON), // while (R0 > 0) // repeat RTC_dutyMeter times:
77+
M_BL(NEXT_PWM_CYCLE, 1), // {
78+
//I_DELAY(8), // // 8 is about 1 microsecond based on 8MHz
79+
I_SUBI(R0, R0, 1), // R0 = R0 - 1
80+
M_BX(PWM_ON), // }
81+
M_LABEL(NEXT_PWM_CYCLE), // // toggle GPIO_2
82+
I_MOVI(R0, 0), // R0 = 0
83+
I_LD(R0, R0, RTC_dutyMeter), // R0 = RTC_SLOW_MEM[RTC_dutyMeter]
84+
I_MOVI(R1, 100), // R1 = 100
85+
I_SUBR(R0, R1, R0), // R0 = 100 - dutyMeter
86+
M_BL(END_PWM_CYCLE, 1), // if (R0 > 0) turn off LED
87+
I_WR_REG(RTC_GPIO_OUT_W1TC_REG, MeterPWMBit, MeterPWMBit, 1), // W1TC set bit to clear GPIO - GPIO2 off
88+
M_LABEL(PWM_OFF), // while (R0 > 0) // repeat (100 - RTC_dutyMeter) times:
89+
M_BL(END_PWM_CYCLE, 1), // {
90+
//I_DELAY(8), // // 8 is about 1us: ULP fetch+execution time
91+
I_SUBI(R0, R0, 1), // R0 = R0 - 1
92+
M_BX(PWM_OFF), // }
93+
M_LABEL(END_PWM_CYCLE), //
94+
95+
I_SUBI(R3, R3, 1), // R3 = R3 - 1 // RTC_fadeDelay
96+
I_MOVR(R0, R3), // R0 = R3 // only R0 can be used to compare and branch
97+
M_BGE(RUN_PWM, 1), // } while (R3 > 0) // ESP32 repeatinf RTC_fadeDelay times
98+
99+
// increase/decrease DutyMeter to apply Fade In/Out loop
100+
I_MOVI(R1, 0), // R1 = 0
101+
I_LD(R1, R1, RTC_dutyMeter), // R1 = RTC_SLOW_MEM[RTC_dutyMeter]
102+
I_MOVI(R0, 0), // R0 = 0
103+
I_LD(R0, R0, RTC_dir), // R0 = RTC_SLOW_MEM[RTC_dir]
104+
105+
M_BGE(POSITIVE_DIR, 1), // if(dir == 0) { // decrease duty by 2
106+
// Dir is 0, means decrease Duty by 2
107+
I_MOVR(R0, R1), // R0 = Duty
108+
M_BGE(DEC_DUTY, 1), // if (duty == 0) { // change direction and increase duty
109+
I_MOVI(R3, 0), // R3 = 0
110+
I_MOVI(R2, 1), // R2 = 1
111+
I_ST(R2, R3, RTC_dir), // RTC_SLOW_MEM[RTC_dir] = 1 // increasing direction
112+
M_BX(INC_DUTY), // goto "increase Duty"
113+
M_LABEL(DEC_DUTY), // } "decrease Duty":
114+
I_SUBI(R0, R0, 2), // Duty -= 2
115+
I_MOVI(R2, 0), // R2 = 0
116+
I_ST(R0, R2, RTC_dutyMeter), // RTC_SLOW_MEM[RTC_dutyMeter] += 2
117+
M_BX(INIFINITE_LOOP), // }
118+
119+
M_LABEL(POSITIVE_DIR), // else { // dir == 1 // increase duty by 2
120+
// Dir is 1, means increase Duty by 2
121+
I_MOVR(R0, R1), // R0 = Duty
122+
M_BL(INC_DUTY, 100), // if (duty == 100) { // change direction and decrease duty
123+
I_MOVI(R2, 0), // R2 = 0
124+
I_ST(R2, R2, RTC_dir), // RTC_SLOW_MEM[RTC_dir] = 0 // decreasing direction
125+
M_BX(DEC_DUTY), // goto "decrease Duty"
126+
M_LABEL(INC_DUTY), // } "increase Duty":
127+
I_ADDI(R0, R0, 2), // Duty += 2
128+
I_MOVI(R2, 0), // R2 = 0
129+
I_ST(R0, R2, RTC_dutyMeter), // RTC_SLOW_MEM[RTC_dutyMeter] -= 2
130+
// } // if (dir == 0)
131+
M_BX(INIFINITE_LOOP), // } // while(1)
132+
};
133+
// Run ULP program
134+
size_t size = sizeof(ulp_prog) / sizeof(ulp_insn_t);
135+
ulp_process_macros_and_load(ULP_START_OFFSET, ulp_prog, &size);
136+
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
137+
ulp_run(ULP_START_OFFSET);
138+
}
139+
140+
141+
void setup() {
142+
Serial.begin(115200);
143+
while (!Serial) {} // wait for Serial to start
144+
145+
ulp_setup(); // it really only runs on the first ESP32 boot
146+
Serial.printf("\nStarted smooth blink with delay %d\n", *fadeCycleDelay);
147+
148+
// *fadeCycleDelay resides in RTC_SLOW_MEM and persists along deep sleep waking up
149+
// it is used as a delay time parameter for smooth blinking, in the ULP processing code
150+
if (*fadeCycleDelay < 195) {
151+
*fadeCycleDelay += 10;
152+
} else {
153+
*fadeCycleDelay = 5; // 5..200 works fine for a full Fade In + Out cycle
154+
}
155+
Serial.println("Entering in Deep Sleep");
156+
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR /*/ 4*/); // time set with variable above
157+
esp_deep_sleep_start();
158+
// From this point on, no code is executed in DEEP SLEEP mode
159+
}
160+
161+
162+
void loop() {
163+
// It never reaches this code because it enters in Deep Sleep mode at the end of setup()
164+
}
165+

libraries/ESP32/examples/ESPNow/Basic/Master/Master.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <esp_now.h>
3333
#include <WiFi.h>
34+
#include <esp_wifi.h> // only for esp_wifi_set_channel()
3435

3536
// Global copy of slave
3637
esp_now_peer_info_t slave;
@@ -55,7 +56,7 @@ void InitESPNow() {
5556

5657
// Scan for slaves in AP mode
5758
void ScanForSlave() {
58-
int8_t scanResults = WiFi.scanNetworks();
59+
int16_t scanResults = WiFi.scanNetworks(false, false, false, 300, CHANNEL); // Scan only on one channel
5960
// reset on each scan
6061
bool slaveFound = 0;
6162
memset(&slave, 0, sizeof(slave));
@@ -222,9 +223,11 @@ void setup() {
222223
Serial.begin(115200);
223224
//Set device in STA mode to begin with
224225
WiFi.mode(WIFI_STA);
226+
esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
225227
Serial.println("ESPNow/Basic/Master Example");
226228
// This is the mac address of the Master in Station Mode
227229
Serial.print("STA MAC: "); Serial.println(WiFi.macAddress());
230+
Serial.print("STA CHANNEL "); Serial.println(WiFi.channel());
228231
// Init ESPNow with a fallback logic
229232
InitESPNow();
230233
// Once ESPNow is successfully Init, we will register for Send CB to

libraries/ESP32/examples/ESPNow/Basic/Slave/Slave.ino

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void configDeviceAP() {
5757
Serial.println("AP Config failed.");
5858
} else {
5959
Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID));
60+
Serial.print("AP CHANNEL "); Serial.println(WiFi.channel());
6061
}
6162
}
6263

libraries/RainMaker/src/RMaker.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Node RMakerClass::initNode(const char *name, const char *type)
5050

5151
esp_err_t RMakerClass::start()
5252
{
53-
err = esp_rmaker_start();
53+
err = esp_rmaker_start();
5454
if(err != ESP_OK){
5555
log_e("ESP RainMaker core task failed");
5656
}
@@ -106,6 +106,7 @@ esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert)
106106
{
107107
esp_rmaker_ota_config_t ota_config;
108108
ota_config.server_cert = cert;
109+
ota_config.ota_cb = NULL;
109110
err = esp_rmaker_ota_enable(&ota_config, type);
110111
if(err != ESP_OK) {
111112
log_e("OTA enable failed");

libraries/USB/src/USBHID.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,21 @@ bool USBHID::ready(void){
310310
return tud_hid_n_ready(0);
311311
}
312312

313-
void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len){
313+
// TinyUSB is in the process of changing the type of the last argument to
314+
// tud_hid_report_complete_cb(), so extract the type from the version of TinyUSB that we're
315+
// compiled with.
316+
template <class F> struct ArgType;
317+
318+
template <class R, class T1, class T2, class T3>
319+
struct ArgType<R(*)(T1, T2, T3)> {
320+
typedef T1 type1;
321+
typedef T2 type2;
322+
typedef T3 type3;
323+
};
324+
325+
typedef ArgType<decltype(&tud_hid_report_complete_cb)>::type3 tud_hid_report_complete_cb_len_t;
326+
327+
void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, tud_hid_report_complete_cb_len_t len){
314328
if (tinyusb_hid_device_input_sem) {
315329
xSemaphoreGive(tinyusb_hid_device_input_sem);
316330
}

0 commit comments

Comments
 (0)