Skip to content

Commit ae2dec2

Browse files
authored
Serial refactoring and idf 4.4.7 for ESP32 (#1048)
* Split esp32 code from esp8266 for Serial * split receive serial message and processing serial message in esp32 in different task * Make the esp32 code backward compatible with Arduino esp32 2.0.17 / IDF 4.4.7
1 parent bd5f96d commit ae2dec2

File tree

11 files changed

+538
-177
lines changed

11 files changed

+538
-177
lines changed

esp3d/configuration.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,6 @@
611611
*/
612612
#define ESP_SAVE_SETTINGS SETTINGS_IN_EEPROM
613613

614-
/* Add serial task
615-
* ESP32 need to add a task to handle serial communication
616-
*/
617-
#define SERIAL_INDEPENDANT_TASK
618-
619614
/************************************
620615
*
621616
* Development setting

esp3d/src/core/esp3d_hal.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@
3434
#endif // __has_include ("rtc_wdt.h")
3535
#endif // CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
3636
#include <WiFi.h>
37+
#if ESP_ARDUINO_VERSION_MAJOR == 3
3738
#include <esp_adc/adc_continuous.h>
3839
#include <esp_adc/adc_oneshot.h>
40+
#endif // ESP_ARDUINO_VERSION_MAJOR == 3
41+
#if ESP_ARDUINO_VERSION_MAJOR == 2
42+
#include <driver/adc.h>
43+
#endif // ESP_ARDUINO_VERSION_MAJOR == 2
3944
#include <esp_task_wdt.h>
4045

4146
#if !CONFIG_IDF_TARGET_ESP32C6

esp3d/src/include/esp3d_sanity.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121
#pragma once
2222

23+
/**************************
24+
* Arduino core version
25+
* ***********************/
26+
#if ESP_ARDUINO_VERSION_MAJOR == 1
27+
#error "ESP3D does not support Arduino Core 1.x.x"
28+
#endif
29+
2330
/**************************
2431
* Settings
2532
* ***********************/

esp3d/src/modules/mDNS/mDNS.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ const char* mDNS_Service::answerIP(uint16_t index) {
252252
return "";
253253
}
254254
#if defined(ARDUINO_ARCH_ESP32)
255+
#if ESP_ARDUINO_VERSION_MAJOR == 3
255256
tmp = MDNS.address(index).toString();
257+
#endif // ESP_ARDUINO_VERSION_MAJOR == 3
258+
#if ESP_ARDUINO_VERSION_MAJOR == 2
259+
tmp = MDNS.IP(index).toString();
260+
#endif // ESP_ARDUINO_VERSION_MAJOR == 2
256261

257262
#endif // ARDUINO_ARCH_ESP32
258263
#if defined(ARDUINO_ARCH_ESP8266)

esp3d/src/modules/serial/serial_service.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "../../core/esp3d_client_types.h"
2525
#include "../../core/esp3d_message.h"
2626

27+
#if defined(ARDUINO_ARCH_ESP32)
28+
#include "../../core/esp3d_messageFifo.h"
29+
#endif // ARDUINO_ARCH_ESP32
30+
2731
#define ESP3D_SERIAL_BUFFER_SIZE 1024
2832

2933
extern const uint32_t SupportedBaudList[];
@@ -36,11 +40,10 @@ class ESP3DSerialService final {
3640
void setParameters();
3741
bool begin(uint8_t serialIndex);
3842
bool end();
39-
void updateBaudRate(long br);
43+
void updateBaudRate(uint32_t br);
4044
void handle();
41-
void process();
4245
bool reset();
43-
long baudRate();
46+
uint32_t baudRate();
4447
uint8_t serialIndex() { return _serialIndex; }
4548
const uint32_t *get_baudratelist(uint8_t *count);
4649
void flush();
@@ -52,8 +55,13 @@ class ESP3DSerialService final {
5255
void initAuthentication();
5356
void setAuthentication(ESP3DAuthenticationLevel auth) { _auth = auth; }
5457
ESP3DAuthenticationLevel getAuthentication();
55-
58+
#if defined(ARDUINO_ARCH_ESP32)
59+
void receiveCb();
60+
static void receiveSerialCb();
61+
static void receiveBridgeSeialCb();
62+
#endif // ARDUINO_ARCH_ESP32
5663
private:
64+
uint32_t _baudRate;
5765
ESP3DAuthenticationLevel _auth;
5866
uint8_t _serialIndex;
5967
ESP3DClientType _origin;
@@ -65,6 +73,10 @@ class ESP3DSerialService final {
6573
uint32_t _lastflush;
6674
uint8_t _buffer[ESP3D_SERIAL_BUFFER_SIZE + 1]; // keep space of 0x0 terminal
6775
size_t _buffer_size;
76+
#if defined(ARDUINO_ARCH_ESP32)
77+
SemaphoreHandle_t _mutex;
78+
ESP3DMessageFIFO _messagesInFIFO;
79+
#endif // ARDUINO_ARCH_ESP32
6880
void push2buffer(uint8_t *sbuf, size_t len);
6981
void flushbuffer();
7082
};

0 commit comments

Comments
 (0)