Skip to content

Commit

Permalink
Merge branch 'master' into feature/network_refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
me-no-dev committed Oct 18, 2023
2 parents e42b99a + 601efed commit 044da55
Show file tree
Hide file tree
Showing 58 changed files with 2,248 additions and 1,974 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
# The version names here correspond to the versions of espressif/idf Docker image.
# See https://hub.docker.com/r/espressif/idf/tags and
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ set(LIBRARY_SRCS
libraries/BluetoothSerial/src/BTScanResultsSet.cpp
libraries/DNSServer/src/DNSServer.cpp
libraries/EEPROM/src/EEPROM.cpp
libraries/ESP_I2S/src/ESP_I2S.cpp
libraries/ESP_SR/src/ESP_SR.cpp
libraries/ESP_SR/src/esp32-hal-sr.c
libraries/ESPmDNS/src/ESPmDNS.cpp
libraries/Ethernet/src/ETH.cpp
libraries/FFat/src/FFat.cpp
Expand All @@ -91,7 +94,6 @@ set(LIBRARY_SRCS
libraries/HTTPUpdate/src/HTTPUpdate.cpp
libraries/LittleFS/src/LittleFS.cpp
libraries/Insights/src/Insights.cpp
libraries/I2S/src/I2S.cpp
libraries/NetBIOS/src/NetBIOS.cpp
libraries/Networking/src/ESP_Network_Interface.cpp
libraries/Preferences/src/Preferences.cpp
Expand Down Expand Up @@ -180,6 +182,8 @@ set(includedirs
libraries/BluetoothSerial/src
libraries/DNSServer/src
libraries/EEPROM/src
libraries/ESP_I2S/src
libraries/ESP_SR/src
libraries/ESP32/src
libraries/ESPmDNS/src
libraries/Ethernet/src
Expand All @@ -189,7 +193,6 @@ set(includedirs
libraries/HTTPUpdate/src
libraries/LittleFS/src
libraries/Insights/src
libraries/I2S/src
libraries/NetBIOS/src
libraries/Networking/src
libraries/Preferences/src
Expand Down
12 changes: 5 additions & 7 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ _eventTask(NULL)

HardwareSerial::~HardwareSerial()
{
end();
end(true); // explicit Full UART termination
#if !CONFIG_DISABLE_HAL_LOCKS
if(_lock != NULL){
vSemaphoreDelete(_lock);
Expand Down Expand Up @@ -398,7 +398,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
if(_uart) {
// in this case it is a begin() over a previous begin() - maybe to change baud rate
// thus do not disable debug output
end(false);
end(false); // disables IDF UART driver and UART event Task + sets _uart to NULL
}

// IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified.
Expand All @@ -413,7 +413,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
yield();
}

end(false);
end(false); // disables IDF UART driver and UART event Task + sets _uart to NULL

if(detectedBaudRate) {
delay(100); // Give some time...
Expand Down Expand Up @@ -470,10 +470,8 @@ void HardwareSerial::end(bool fullyTerminate)
// do not invalidate callbacks, detach pins, invalidate DBG output
uart_driver_delete(_uart_nr);
}

uartEnd(_uart_nr);
_uart = 0;
_destroyEventTask();
_destroyEventTask(); // when IDF uart driver is deleted, _eventTask must finish too
_uart = NULL;
}

void HardwareSerial::setDebugOutput(bool en)
Expand Down
29 changes: 18 additions & 11 deletions cores/esp32/esp32-hal-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#include "driver/i2c.h"
#include "esp32-hal-periman.h"

#if SOC_I2C_SUPPORT_APB || SOC_I2C_SUPPORT_XTAL
#include "esp_private/esp_clk.h"
#endif
#if SOC_I2C_SUPPORT_RTC
#include "clk_ctrl_os.h"
#endif

typedef volatile struct {
bool initialized;
uint32_t frequency;
Expand Down Expand Up @@ -303,11 +310,6 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){
} else if(frequency > 1000000UL){
frequency = 1000000UL;
}
// Freq limitation when using different clock sources
#define I2C_CLK_LIMIT_REF_TICK (1 * 1000 * 1000 / 20) /*!< Limited by REF_TICK, no more than REF_TICK/20*/
#define I2C_CLK_LIMIT_APB (80 * 1000 * 1000 / 20) /*!< Limited by APB, no more than APB/20*/
#define I2C_CLK_LIMIT_RTC (20 * 1000 * 1000 / 20) /*!< Limited by RTC, no more than RTC/20*/
#define I2C_CLK_LIMIT_XTAL (40 * 1000 * 1000 / 20) /*!< Limited by RTC, no more than XTAL/20*/

typedef struct {
soc_module_clk_t clk; /*!< I2C source clock */
Expand All @@ -332,22 +334,22 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){
} i2c_sclk_t;

// i2c clock characteristic, The order is the same as i2c_sclk_t.
static i2c_clk_alloc_t i2c_clk_alloc[I2C_SCLK_MAX] = {
i2c_clk_alloc_t i2c_clk_alloc[I2C_SCLK_MAX] = {
{0, 0},
#if SOC_I2C_SUPPORT_APB
{SOC_MOD_CLK_APB, I2C_CLK_LIMIT_APB}, /*!< I2C APB clock characteristic*/
{SOC_MOD_CLK_APB, esp_clk_apb_freq()}, /*!< I2C APB clock characteristic*/
#endif
#if SOC_I2C_SUPPORT_XTAL
{SOC_MOD_CLK_XTAL, I2C_CLK_LIMIT_XTAL}, /*!< I2C XTAL characteristic*/
{SOC_MOD_CLK_XTAL, esp_clk_xtal_freq()}, /*!< I2C XTAL characteristic*/
#endif
#if SOC_I2C_SUPPORT_RTC
{SOC_MOD_CLK_RC_FAST, I2C_CLK_LIMIT_RTC}, /*!< I2C 20M RTC characteristic*/
{SOC_MOD_CLK_RC_FAST, periph_rtc_dig_clk8m_get_freq()}, /*!< I2C 20M RTC characteristic*/
#endif
#if SOC_I2C_SUPPORT_REF_TICK
{SOC_MOD_CLK_REF_TICK, I2C_CLK_LIMIT_REF_TICK},/*!< I2C REF_TICK characteristic*/
{SOC_MOD_CLK_REF_TICK, REF_CLK_FREQ},/*!< I2C REF_TICK characteristic*/
#endif
};

i2c_sclk_t src_clk = I2C_SCLK_DEFAULT;
ret = ESP_OK;
for (i2c_sclk_t clk = I2C_SCLK_DEFAULT + 1; clk < I2C_SCLK_MAX; clk++) {
Expand All @@ -367,6 +369,11 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){
} else {
i2c_hal_context_t hal;
hal.dev = I2C_LL_GET_HW(i2c_num);
#if SOC_I2C_SUPPORT_RTC
if(src_clk == I2C_SCLK_RTC){
periph_rtc_dig_clk8m_enable();
}
#endif
i2c_hal_set_bus_timing(&(hal), frequency, i2c_clk_alloc[src_clk].clk, i2c_clk_alloc[src_clk].clk_freq);
bus[i2c_num].frequency = frequency;
//Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2
Expand Down
27 changes: 10 additions & 17 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,32 +884,29 @@ void uartStartDetectBaudrate(uart_t *uart) {
return;
}

#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
// Baud rate detection only works for ESP32 and ESP32S2
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
uart_dev_t *hw = UART_LL_GET_HW(uart->num);
hw->auto_baud.glitch_filt = 0x08;
hw->auto_baud.en = 0;
hw->auto_baud.en = 1;
#else

// ESP32-C3 requires further testing
// Baud rate detection returns wrong values

log_e("ESP32-C3 baud rate detection is not supported.");
log_e("baud rate detection for this SoC is not supported.");
return;

// Code bellow for C3 kept for future recall
//hw->rx_filt.glitch_filt = 0x08;
//hw->rx_filt.glitch_filt_en = 1;
//hw->conf0.autobaud_en = 0;
//hw->conf0.autobaud_en = 1;
#elif CONFIG_IDF_TARGET_ESP32S3
log_e("ESP32-S3 baud rate detection is not supported.");
return;
#else
uart_dev_t *hw = UART_LL_GET_HW(uart->num);
hw->auto_baud.glitch_filt = 0x08;
hw->auto_baud.en = 0;
hw->auto_baud.en = 1;
#endif
}

unsigned long
uartDetectBaudrate(uart_t *uart)
unsigned long uartDetectBaudrate(uart_t *uart)
{
if(uart == NULL) {
return 0;
Expand Down Expand Up @@ -955,11 +952,7 @@ uartDetectBaudrate(uart_t *uart)

return default_rates[i];
#else
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
log_e("ESP32-C3 baud rate detection is not supported.");
#else
log_e("ESP32-S3 baud rate detection is not supported.");
#endif
log_e("baud rate detection this SoC is not supported.");
return 0;
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions docs/source/api/ble.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ To get started with BLE, you can try:
BLE Scan
********

.. literalinclude:: ../../../libraries/BLE/examples/BLE_scan/BLE_scan.ino
.. literalinclude:: ../../../libraries/BLE/examples/Scan/Scan.ino
:language: arduino

BLE UART
********

.. literalinclude:: ../../../libraries/BLE/examples/BLE_uart/BLE_uart.ino
.. literalinclude:: ../../../libraries/BLE/examples/UART/UART.ino
:language: arduino

Complete list of `BLE examples <https://github.com/espressif/arduino-esp32/tree/master/libraries/BLE/examples>`_.
6 changes: 5 additions & 1 deletion docs/source/api/ledc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ESP32-S2 8
ESP32-S3 8
ESP32-C3 6
ESP32-C6 6
ESP32-H2 6
========= =======================

Arduino-ESP32 LEDC API
Expand Down Expand Up @@ -125,10 +126,13 @@ This function is used to detach the pin from LEDC.

.. code-block:: arduino
void ledcDetach(uint8_t pin);
bool ledcDetach(uint8_t pin);
* ``pin`` select LEDC pin.

This function returns ``true`` if detaching was successful.
If ``false`` is returned, an error occurred and the pin was not detached.

ledcChangeFrequency
*******************

Expand Down
50 changes: 22 additions & 28 deletions docs/source/api/sigmadelta.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,61 @@ ESP32 SoC Number of SigmaDelta channels
========= =============================
ESP32 8
ESP32-S2 8
ESP32-C3 4
ESP32-S3 8
ESP32-C3 4
ESP32-C6 4
ESP32-H2 4
========= =============================

Arduino-ESP32 SigmaDelta API
----------------------------

sigmaDeltaSetup
***************
sigmaDeltaAttach
****************

This function is used to setup the SigmaDelta channel frequency and resolution.
This function is used to set up the SigmaDelta channel with the selected frequency and attach it to the selected pin.

.. code-block:: arduino
uint32_t sigmaDeltaSetup(uint8_t pin, uint8_t channel, uint32_t freq);
bool sigmaDeltaAttach(uint8_t pin, uint32_t freq);
* ``pin`` select GPIO pin.
* ``channel`` select SigmaDelta channel.
* ``freq`` select frequency.

* range is 1-14 bits (1-20 bits for ESP32).

This function will return ``frequency`` configured for the SigmaDelta channel.
If ``0`` is returned, error occurs and the SigmaDelta channel was not configured.
This function returns ``true`` if the configuration was successful.
If ``false`` is returned, an error occurred and the SigmaDelta channel was not configured.

sigmaDeltaWrite
***************

This function is used to set duty for the SigmaDelta channel.

.. code-block:: arduino
void sigmaDeltaWrite(uint8_t channel, uint8_t duty);
* ``channel`` select SigmaDelta channel.
* ``duty`` select duty to be set for selected channel.

sigmaDeltaRead
**************

This function is used to get configured duty for the SigmaDelta channel.
This function is used to set duty for the SigmaDelta pin.

.. code-block:: arduino
uint8_t sigmaDeltaRead(uint8_t channel)
bool sigmaDeltaWrite(uint8_t pin, uint8_t duty);
* ``channnel`` select SigmaDelta channel.
* ``pin`` selects the GPIO pin.
* ``duty`` selects the duty to be set for selected pin.

This function will return ``duty`` configured for the selected SigmaDelta channel.
This function returns ``true`` if setting the duty was successful.
If ``false`` is returned, error occurs and duty was not set.

sigmaDeltaDetachPin
*******************
sigmaDeltaDetach
****************

This function is used to detach pin from SigmaDelta.
This function is used to detach a pin from SigmaDelta and deinitialize the channel that was attached to the pin.

.. code-block:: arduino
void sigmaDeltaDetachPin(uint8_t pin);
bool sigmaDeltaDetach(uint8_t pin);
* ``pin`` select GPIO pin.

This function returns ``true`` if detaching was successful.
If ``false`` is returned, an error occurred and pin was not detached.

Example Applications
********************

Expand Down
4 changes: 3 additions & 1 deletion docs/source/api/timer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ ESP32 SoC Number of timers
========= ================
ESP32 4
ESP32-S2 4
ESP32-C3 2
ESP32-S3 4
ESP32-C3 2
ESP32-C6 2
ESP32-H2 2
========= ================

Arduino-ESP32 Timer API
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Here you will find all the relevant information about the project.
Guides <guides/guides>
Tutorials <tutorials/tutorials>
Advanced Utilities <advanced_utils>
Migration Guides <migration_guides/migration_guides>
FAQ <faq>
Troubleshooting <troubleshooting>
Contributing <contributing>
Expand Down
Loading

0 comments on commit 044da55

Please sign in to comment.