mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[ESPEasySerial] Split files into wrappers and drivers
This commit is contained in:
@@ -1,36 +1,18 @@
|
||||
#include "ESPEasySerialConfig.h"
|
||||
|
||||
/*
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
SoftwareSerialConfig SerialConfig_to_SoftwareSerialConfig(SerialConfig config)
|
||||
|
||||
#if USES_I2C_SC16IS752
|
||||
|
||||
bool ESPEasySerialConfig::getI2C_SC16IS752_Parameters(
|
||||
ESPEasySC16IS752_Serial::I2C_address & addr,
|
||||
ESPEasySC16IS752_Serial::SC16IS752_channel& ch) const
|
||||
{
|
||||
switch (config) {
|
||||
case SERIAL_5N1: return SWSERIAL_5N1;
|
||||
case SERIAL_6N1: return SWSERIAL_6N1;
|
||||
case SERIAL_7N1: return SWSERIAL_7N1;
|
||||
case SERIAL_8N1: return SWSERIAL_8N1;
|
||||
case SERIAL_5N2: return SWSERIAL_5N2;
|
||||
case SERIAL_6N2: return SWSERIAL_6N2;
|
||||
case SERIAL_7N2: return SWSERIAL_7N2;
|
||||
case SERIAL_8N2: return SWSERIAL_8N2;
|
||||
case SERIAL_5E1: return SWSERIAL_5E1;
|
||||
case SERIAL_6E1: return SWSERIAL_6E1;
|
||||
case SERIAL_7E1: return SWSERIAL_7E1;
|
||||
case SERIAL_8E1: return SWSERIAL_8E1;
|
||||
case SERIAL_5E2: return SWSERIAL_5E2;
|
||||
case SERIAL_6E2: return SWSERIAL_6E2;
|
||||
case SERIAL_7E2: return SWSERIAL_7E2;
|
||||
case SERIAL_8E2: return SWSERIAL_8E2;
|
||||
case SERIAL_5O1: return SWSERIAL_5O1;
|
||||
case SERIAL_6O1: return SWSERIAL_6O1;
|
||||
case SERIAL_7O1: return SWSERIAL_7O1;
|
||||
case SERIAL_8O1: return SWSERIAL_8O1;
|
||||
case SERIAL_5O2: return SWSERIAL_5O2;
|
||||
case SERIAL_6O2: return SWSERIAL_6O2;
|
||||
case SERIAL_7O2: return SWSERIAL_7O2;
|
||||
case SERIAL_8O2: return SWSERIAL_8O2;
|
||||
if ((receivePin >= 0x48) && (receivePin <= 0x57) && ((transmitPin >= 0) && (transmitPin < 2))) {
|
||||
addr = static_cast<ESPEasySC16IS752_Serial::I2C_address>(receivePin);
|
||||
ch = static_cast<ESPEasySC16IS752_Serial::SC16IS752_channel>(transmitPin);
|
||||
return true;
|
||||
}
|
||||
return SWSERIAL_8N1;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif // if USES_I2C_SC16IS752
|
||||
|
||||
@@ -1,13 +1,48 @@
|
||||
#ifndef ESPEASYSERIAL_ESPEASYSERIALCONFIG_H
|
||||
#define ESPEASYSERIAL_ESPEASYSERIALCONFIG_H
|
||||
/*
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "ESPEasySerial_common_defines.h"
|
||||
|
||||
#include "ESPEasySerialPort.h"
|
||||
|
||||
#if USES_I2C_SC16IS752
|
||||
# include "drivers/ESPEasySC16IS752_Serial.h"
|
||||
#endif // if USES_I2C_SC16IS752
|
||||
|
||||
#include <HardwareSerial.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerialConfig SerialConfig_to_SoftwareSerialConfig(SerialConfig config);
|
||||
struct ESPEasySerialConfig {
|
||||
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
ESPEasySerialConfig() = default;
|
||||
|
||||
#if USES_I2C_SC16IS752
|
||||
|
||||
bool getI2C_SC16IS752_Parameters(ESPEasySC16IS752_Serial::I2C_address & addr,
|
||||
ESPEasySC16IS752_Serial::SC16IS752_channel& ch) const;
|
||||
|
||||
|
||||
#endif // if USES_I2C_SC16IS752
|
||||
|
||||
|
||||
ESPEasySerialPort port = ESPEasySerialPort::not_set;
|
||||
unsigned long baud = 115200;
|
||||
int receivePin = -1;
|
||||
int transmitPin = -1;
|
||||
bool inverse_logic = false;
|
||||
unsigned int buffSize = 64;
|
||||
bool forceSWserial = false;
|
||||
unsigned long timeout_ms = 20000UL;
|
||||
|
||||
#ifdef ESP32
|
||||
uint32_t config = SERIAL_8N1;
|
||||
#endif // ifdef ESP32
|
||||
|
||||
#ifdef ESP8266
|
||||
SerialConfig config = SERIAL_8N1;
|
||||
SerialMode mode = SERIAL_FULL;
|
||||
#endif // ifdef ESP8266
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYSERIAL_ESPEASYSERIALCONFIG_H
|
||||
|
||||
@@ -4,28 +4,27 @@ const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort serType)
|
||||
{
|
||||
switch (serType) {
|
||||
case ESPEasySerialPort::not_set: break;
|
||||
#if USES_I2C_SC16IS752
|
||||
case ESPEasySerialPort::sc16is752: return F("I2C Serial");
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
case ESPEasySerialPort::serial0_swap: return F("HW Serial0 swap");
|
||||
#endif
|
||||
case ESPEasySerialPort::serial0: return F("HW Serial0");
|
||||
case ESPEasySerialPort::serial1: return F("HW Serial1");
|
||||
#if HAS_SERIAL2
|
||||
case ESPEasySerialPort::serial2: return F("HW Serial2");
|
||||
#endif
|
||||
#if USES_SW_SERIAL
|
||||
case ESPEasySerialPort::software: return F("SoftwareSerial");
|
||||
#if defined(ESP32) && defined(USE_USB_CDC_CONSOLE)
|
||||
# if USES_HWCDC
|
||||
#endif
|
||||
#if USES_HWCDC
|
||||
case ESPEasySerialPort::usb_hw_cdc: return F("USB HWCDC");
|
||||
# else // if USES_HWCDC
|
||||
case ESPEasySerialPort::usb_hw_cdc:
|
||||
break;
|
||||
# endif // if USES_HWCDC
|
||||
# if USES_USBCDC
|
||||
#endif
|
||||
#if USES_USBCDC
|
||||
case ESPEasySerialPort::usb_cdc_0: return F("USB CDC0");
|
||||
case ESPEasySerialPort::usb_cdc_1: return F("USB CDC1");
|
||||
# else // if USES_USBCDC
|
||||
case ESPEasySerialPort::usb_cdc_0:
|
||||
case ESPEasySerialPort::usb_cdc_1:
|
||||
break;
|
||||
# endif // if USES_USBCDC
|
||||
#endif // if defined(ESP32) && defined(USE_USB_CDC_CONSOLE)
|
||||
#endif
|
||||
case ESPEasySerialPort::MAX_SERIAL_TYPE: break;
|
||||
|
||||
// Do not include "default:" to let the compiler check if we miss some case
|
||||
@@ -36,10 +35,14 @@ const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort serType)
|
||||
bool isHWserial(ESPEasySerialPort serType)
|
||||
{
|
||||
switch (serType) {
|
||||
#ifdef ESP8266
|
||||
case ESPEasySerialPort::serial0_swap:
|
||||
#endif
|
||||
case ESPEasySerialPort::serial0:
|
||||
case ESPEasySerialPort::serial1:
|
||||
#if HAS_SERIAL2
|
||||
case ESPEasySerialPort::serial2:
|
||||
#endif
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -1,62 +1,40 @@
|
||||
#ifndef ESPEASY_SERIAL_ESPEASYSERIALPORT_H
|
||||
#define ESPEASY_SERIAL_ESPEASYSERIALPORT_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
// FIXME TD-er: Share this code to define USES_xxCDC
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
/*
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface
|
||||
CONFIG_IDF_TARGET_ESP32S2 || // support USB via USBCDC
|
||||
CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC
|
||||
*/
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
# define USES_HWCDC 1
|
||||
# else // No ARDUINO_USB_MODE
|
||||
# define USES_USBCDC 1
|
||||
# endif // ARDUINO_USB_MODE
|
||||
# endif // ifdef USE_USB_CDC_CONSOLE
|
||||
# endif // if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
#endif // ifdef ESP32
|
||||
|
||||
#ifndef USES_HWCDC
|
||||
# define USES_HWCDC 0
|
||||
#endif // ifndef USES_HWCDC
|
||||
|
||||
#ifndef USES_USBCDC
|
||||
# define USES_USBCDC 0
|
||||
#endif // ifndef USES_USBCDC
|
||||
|
||||
|
||||
#include "ESPEasySerial_common_defines.h"
|
||||
|
||||
|
||||
// Keep value assigned as it is used in scripts and stored in the Settings.TaskDevicePort
|
||||
enum class ESPEasySerialPort : uint8_t {
|
||||
not_set = 0,
|
||||
#if USES_I2C_SC16IS752
|
||||
sc16is752 = 1,
|
||||
serial0 = 2,
|
||||
serial0_swap = 3,
|
||||
serial1 = 4,
|
||||
serial2 = 5,
|
||||
software = 6,
|
||||
#if defined(ESP32) && defined(USE_USB_CDC_CONSOLE)
|
||||
usb_hw_cdc = 7,
|
||||
usb_cdc_0 = 8,
|
||||
usb_cdc_1 = 9,
|
||||
#endif
|
||||
serial0 = 2,
|
||||
#ifdef ESP8266
|
||||
serial0_swap = 3,
|
||||
#endif
|
||||
serial1 = 4,
|
||||
#if HAS_SERIAL2
|
||||
serial2 = 5,
|
||||
#endif
|
||||
#if USES_SW_SERIAL
|
||||
software = 6,
|
||||
#endif
|
||||
|
||||
#if USES_HWCDC
|
||||
usb_hw_cdc = 7,
|
||||
#endif
|
||||
#if USES_USBCDC
|
||||
usb_cdc_0 = 8,
|
||||
usb_cdc_1 = 9,
|
||||
#endif
|
||||
|
||||
MAX_SERIAL_TYPE
|
||||
};
|
||||
|
||||
const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort serType);
|
||||
|
||||
bool isHWserial(ESPEasySerialPort serType);
|
||||
bool isHWserial(ESPEasySerialPort serType);
|
||||
|
||||
#endif // ifndef ESPEASY_SERIAL_ESPEASYSERIALPORT_H
|
||||
|
||||
+10
-50
@@ -1,5 +1,9 @@
|
||||
#include "ESPEasySerialType.h"
|
||||
|
||||
#include "ESPEasySerial_common_defines.h"
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
#ifndef ESP32_SER0_TX
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
# define ESP32_SER0_TX 21
|
||||
@@ -46,35 +50,26 @@
|
||||
#endif
|
||||
#endif // ifndef ESP32_SER1_RX
|
||||
|
||||
#if HAS_SERIAL2
|
||||
#ifndef ESP32_SER2_TX
|
||||
# define ESP32_SER2_TX 17
|
||||
#endif // ifndef ESP32_SER2_TX
|
||||
#ifndef ESP32_SER2_RX
|
||||
# define ESP32_SER2_RX 16
|
||||
#endif // ifndef ESP32_SER2_RX
|
||||
|
||||
#endif
|
||||
|
||||
bool ESPeasySerialType::getSerialTypePins(ESPEasySerialPort serType, int& rxPin, int& txPin) {
|
||||
rxPin = -1;
|
||||
txPin = -1;
|
||||
|
||||
switch (serType) {
|
||||
#ifdef ESP32
|
||||
case ESPEasySerialPort::serial0: rxPin = ESP32_SER0_RX; txPin = ESP32_SER0_TX; return true;
|
||||
case ESPEasySerialPort::serial1: rxPin = ESP32_SER1_RX; txPin = ESP32_SER1_TX; return true;
|
||||
# if HAS_SERIAL2
|
||||
case ESPEasySerialPort::serial2: rxPin = ESP32_SER2_RX; txPin = ESP32_SER2_TX; return true;
|
||||
# endif
|
||||
#endif // ifdef ESP32
|
||||
#ifdef ESP8266
|
||||
case ESPEasySerialPort::serial0: rxPin = 3; txPin = 1; return true;
|
||||
case ESPEasySerialPort::serial0_swap: rxPin = 13; txPin = 15; return true;
|
||||
case ESPEasySerialPort::serial1: rxPin = -1; txPin = 2; return true;
|
||||
# ifndef DISABLE_SOFTWARE_SERIAL
|
||||
case ESPEasySerialPort::software: rxPin = 14; txPin = 12; return true;
|
||||
# endif // DISABLE_SOFTWARE_SERIAL
|
||||
#endif // ifdef ESP8266
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
case ESPEasySerialPort::sc16is752: return true;
|
||||
#endif // ifndef DISABLE_SC16IS752_Serial
|
||||
|
||||
@@ -84,7 +79,7 @@ bool ESPeasySerialType::getSerialTypePins(ESPEasySerialPort serType, int& rxPin,
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
ESPEasySerialPort ESPeasySerialType::getSerialType(ESPEasySerialPort typeHint, int receivePin, int transmitPin) {
|
||||
if (typeHint != ESPEasySerialPort::not_set) {
|
||||
return typeHint;
|
||||
@@ -105,48 +100,13 @@ ESPEasySerialPort ESPeasySerialType::getSerialType(ESPEasySerialPort typeHint, i
|
||||
return ESPEasySerialPort::serial2; // UART2
|
||||
}
|
||||
# endif
|
||||
|
||||
#if USES_I2C_SC16IS752
|
||||
if ((receivePin >= 0x48) && (receivePin <= 0x57)) {
|
||||
return ESPEasySerialPort::sc16is752; // I2C address range of SC16IS752
|
||||
}
|
||||
#endif
|
||||
|
||||
return ESPEasySerialPort::MAX_SERIAL_TYPE;
|
||||
}
|
||||
|
||||
#endif // ESP32
|
||||
|
||||
|
||||
#ifdef ESP8266
|
||||
ESPEasySerialPort ESPeasySerialType::getSerialType(ESPEasySerialPort typeHint, int receivePin, int transmitPin) {
|
||||
if (typeHint != ESPEasySerialPort::not_set) {
|
||||
return typeHint;
|
||||
}
|
||||
|
||||
if ((receivePin == 3) && (transmitPin == 1)) {
|
||||
return ESPEasySerialPort::serial0; // UART0
|
||||
}
|
||||
|
||||
// ESP8266
|
||||
if ((receivePin == 13) && (transmitPin == 15)) {
|
||||
return ESPEasySerialPort::serial0_swap; // UART0 remapped using Serial.swap()
|
||||
}
|
||||
|
||||
if ((receivePin == -1) && (transmitPin == 2)) {
|
||||
// Serial1 uses UART1, TX pin is GPIO2.
|
||||
// UART1 can not be used to receive data because normally
|
||||
// it's RX pin is occupied for flash chip connection.
|
||||
return ESPEasySerialPort::serial1;
|
||||
}
|
||||
|
||||
if ((receivePin >= 0x48) && (receivePin <= 0x57)) {
|
||||
return ESPEasySerialPort::sc16is752; // I2C address range of SC16IS752
|
||||
}
|
||||
|
||||
if ((receivePin == -1) && (transmitPin == -1)) {
|
||||
// No pins set, so no serial type
|
||||
return ESPEasySerialPort::MAX_SERIAL_TYPE;
|
||||
}
|
||||
return ESPEasySerialPort::software;
|
||||
}
|
||||
|
||||
#endif // ESP8266
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "ESPEasySerialType.h"
|
||||
|
||||
#include "ESPEasySerial_common_defines.h"
|
||||
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
|
||||
bool ESPeasySerialType::getSerialTypePins(ESPEasySerialPort serType, int& rxPin, int& txPin) {
|
||||
rxPin = -1;
|
||||
txPin = -1;
|
||||
|
||||
switch (serType) {
|
||||
case ESPEasySerialPort::serial0: rxPin = 3; txPin = 1; return true;
|
||||
case ESPEasySerialPort::serial0_swap: rxPin = 13; txPin = 15; return true;
|
||||
case ESPEasySerialPort::serial1: rxPin = -1; txPin = 2; return true;
|
||||
#if USES_SW_SERIAL
|
||||
case ESPEasySerialPort::software: rxPin = 14; txPin = 12; return true;
|
||||
#endif
|
||||
#if USES_I2C_SC16IS752
|
||||
case ESPEasySerialPort::sc16is752: return true;
|
||||
#endif // ifndef DISABLE_SC16IS752_Serial
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ESPEasySerialPort ESPeasySerialType::getSerialType(ESPEasySerialPort typeHint, int receivePin, int transmitPin) {
|
||||
if (typeHint != ESPEasySerialPort::not_set) {
|
||||
return typeHint;
|
||||
}
|
||||
|
||||
if ((receivePin == 3) && (transmitPin == 1)) {
|
||||
return ESPEasySerialPort::serial0; // UART0
|
||||
}
|
||||
|
||||
// ESP8266
|
||||
if ((receivePin == 13) && (transmitPin == 15)) {
|
||||
return ESPEasySerialPort::serial0_swap; // UART0 remapped using Serial.swap()
|
||||
}
|
||||
|
||||
if ((receivePin == -1) && (transmitPin == 2)) {
|
||||
// Serial1 uses UART1, TX pin is GPIO2.
|
||||
// UART1 can not be used to receive data because normally
|
||||
// it's RX pin is occupied for flash chip connection.
|
||||
return ESPEasySerialPort::serial1;
|
||||
}
|
||||
#if USES_I2C_SC16IS752
|
||||
if ((receivePin >= 0x48) && (receivePin <= 0x57)) {
|
||||
return ESPEasySerialPort::sc16is752; // I2C address range of SC16IS752
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((receivePin == -1) && (transmitPin == -1)) {
|
||||
// No pins set, so no serial type
|
||||
return ESPEasySerialPort::MAX_SERIAL_TYPE;
|
||||
}
|
||||
return ESPEasySerialPort::software;
|
||||
}
|
||||
|
||||
#endif // ESP8266
|
||||
@@ -79,13 +79,13 @@ void ESPeasySerial::resetConfig(
|
||||
bool inverse_logic,
|
||||
unsigned int buffSize)
|
||||
{
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
if (_i2cserial != nullptr) {
|
||||
_i2cserial->end();
|
||||
delete _i2cserial;
|
||||
}
|
||||
#endif
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
_i2cserial = nullptr;
|
||||
#endif
|
||||
_receivePin = receivePin;
|
||||
@@ -327,7 +327,7 @@ int ESPeasySerial::availableForWrite(void) {
|
||||
}
|
||||
|
||||
if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
// FIXME TD-er: Implement availableForWrite
|
||||
return 64; // _i2cserial->availableForWrite();
|
||||
#else
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <ESPeasySerial.h>
|
||||
|
||||
#if defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#if !USES_SW_SERIAL && defined(ESP8266)
|
||||
|
||||
// ****************************************
|
||||
// ESP8266 implementation wrapper
|
||||
@@ -271,4 +271,4 @@ bool ESPeasySerial::listen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // DISABLE_SOFTWARE_SERIAL
|
||||
#endif
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "ESPEasySerial_Port.h"
|
||||
|
||||
ESPEasySerial_Port::ESPEasySerial_Port() {}
|
||||
@@ -1,45 +0,0 @@
|
||||
#ifndef ESPEASYCORE_ESPEASY_USB_H
|
||||
#define ESPEASYCORE_ESPEASY_USB_H
|
||||
|
||||
// Do not include this file, but rather include "../Globals/ESPEasy_USB.h"
|
||||
// from a .cpp file.
|
||||
|
||||
|
||||
// FIXME TD-er: Share this code to define USES_xxCDC
|
||||
#ifdef ESP32
|
||||
|
||||
/*
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface
|
||||
CONFIG_IDF_TARGET_ESP32S2 || // support USB via USBCDC
|
||||
CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC
|
||||
*/
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
# include "HWCDC.h"
|
||||
# define USES_HWCDC 1
|
||||
extern HWCDC *_hwcdc_serial;
|
||||
# else // No ARDUINO_USB_MODE
|
||||
# include "USB.h"
|
||||
# include "USBCDC.h"
|
||||
# define USES_USBCDC 1
|
||||
extern USBCDC *_usbcdc_serial;
|
||||
# endif // ARDUINO_USB_MODE
|
||||
# endif // ifdef USE_USB_CDC_CONSOLE
|
||||
# endif // if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
#endif // ifdef ESP32
|
||||
|
||||
#ifndef USES_HWCDC
|
||||
# define USES_HWCDC 0
|
||||
#endif // ifndef USES_HWCDC
|
||||
|
||||
#ifndef USES_USBCDC
|
||||
# define USES_USBCDC 0
|
||||
#endif // ifndef USES_USBCDC
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYCORE_ESPEASY_USB_H
|
||||
@@ -1,72 +0,0 @@
|
||||
#ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
#define ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
|
||||
// FIXME TD-er: Share this code to define USES_xxCDC
|
||||
#ifdef ESP32
|
||||
# if CONFIG_IDF_TARGET_ESP32S2 // support USB via USBCDC
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if !ARDUINO_USB_MODE
|
||||
# define USES_USBCDC 1
|
||||
# endif // !ARDUINO_USB_MODE
|
||||
# endif // ifdef USE_USB_CDC_CONSOLE
|
||||
# endif // if CONFIG_IDF_TARGET_ESP32S2
|
||||
#endif // ifdef ESP32
|
||||
|
||||
#ifndef USES_USBCDC
|
||||
# define USES_USBCDC 0
|
||||
#endif // ifndef USES_USBCDC
|
||||
|
||||
|
||||
#if USES_USBCDC
|
||||
|
||||
// ESP32-S2 USB CDC interface
|
||||
# include "USB.h"
|
||||
# include "USBCDC.h"
|
||||
|
||||
# include <Arduino.h>
|
||||
# include "ESPEasySerial_Port.h"
|
||||
# include <inttypes.h>
|
||||
# include <Stream.h>
|
||||
|
||||
class ESPEasySerial_USBCDC_t : public ESPEasySerial_Port {
|
||||
public:
|
||||
|
||||
ESPEasySerial_USBCDC_t(ESPEasySerialPort port);
|
||||
|
||||
virtual ~ESPEasySerial_USBCDC_t();
|
||||
|
||||
void begin(unsigned long baud);
|
||||
|
||||
void end();
|
||||
int available(void);
|
||||
int availableForWrite(void);
|
||||
int peek(void);
|
||||
int read(void);
|
||||
size_t read(uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
void flush(void);
|
||||
void flush(bool txOnly);
|
||||
size_t write(uint8_t);
|
||||
size_t write(const uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
operator bool() const;
|
||||
|
||||
void setDebugOutput(bool);
|
||||
|
||||
size_t setRxBufferSize(size_t new_size);
|
||||
size_t setTxBufferSize(size_t new_size);
|
||||
|
||||
private:
|
||||
|
||||
USBCDC *_serial = nullptr;
|
||||
bool _mustDelete = false;
|
||||
};
|
||||
|
||||
|
||||
#endif // if USES_USBCDC
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
@@ -1,76 +0,0 @@
|
||||
#ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
#define ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
|
||||
|
||||
// FIXME TD-er: Share this code to define USES_xxCDC
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
/*
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface
|
||||
CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC
|
||||
*/
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
# define USES_HWCDC 1
|
||||
# endif // ARDUINO_USB_MODE
|
||||
# endif // ifdef USE_USB_CDC_CONSOLE
|
||||
# endif // if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
#endif // ifdef ESP32
|
||||
|
||||
#ifndef USES_HWCDC
|
||||
# define USES_HWCDC 0
|
||||
#endif // ifndef USES_HWCDC
|
||||
|
||||
#if USES_HWCDC
|
||||
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
# include "HWCDC.h"
|
||||
# include "ESPEasySerial_Port.h"
|
||||
|
||||
# include <Arduino.h>
|
||||
# include <inttypes.h>
|
||||
# include <Stream.h>
|
||||
|
||||
|
||||
class ESPEasySerial_USB_WHCDC_t : public ESPEasySerial_Port {
|
||||
public:
|
||||
|
||||
ESPEasySerial_USB_WHCDC_t();
|
||||
|
||||
virtual ~ESPEasySerial_USB_WHCDC_t() {}
|
||||
|
||||
void begin(unsigned long baud);
|
||||
|
||||
void end();
|
||||
int available(void);
|
||||
int availableForWrite(void);
|
||||
int peek(void);
|
||||
int read(void);
|
||||
size_t read(uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
void flush(void);
|
||||
void flush(bool txOnly);
|
||||
size_t write(uint8_t);
|
||||
size_t write(const uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
operator bool() const;
|
||||
|
||||
void setDebugOutput(bool);
|
||||
|
||||
size_t setRxBufferSize(size_t new_size);
|
||||
size_t setTxBufferSize(size_t new_size);
|
||||
};
|
||||
|
||||
|
||||
#endif // if USES_HWCDC
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <ESPeasySerial.h>
|
||||
|
||||
/*
|
||||
#include <deque>
|
||||
|
||||
std::deque<ESPeasySerial *> _ESPeasySerial_instances;
|
||||
*/
|
||||
#ifdef ESP8266
|
||||
#include "wrappers/ESPEasySerial_HardwareSerial.h"
|
||||
#include "wrappers/ESPEasySerial_I2C_SC16IS752.h"
|
||||
#include "wrappers/ESPEasySerial_SW_Serial.h"
|
||||
#include "wrappers/ESPEasySerial_USB_HWCDC.h"
|
||||
#include "wrappers/ESPEasySerial_USBCDC.h"
|
||||
|
||||
ESPeasySerial::ESPeasySerial(ESPEasySerialPort port,
|
||||
int receivePin,
|
||||
@@ -14,26 +14,20 @@ ESPeasySerial::ESPeasySerial(ESPEasySerialPort port,
|
||||
unsigned int buffSize,
|
||||
bool forceSWserial)
|
||||
:
|
||||
# ifndef DISABLE_SC16IS752_Serial
|
||||
_i2cserial(nullptr),
|
||||
# endif // ifndef DISABLE_SC16IS752_Serial
|
||||
# if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
_swserial(nullptr),
|
||||
# endif // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
_receivePin(receivePin),
|
||||
_transmitPin(transmitPin),
|
||||
_inverse_logic(inverse_logic),
|
||||
_buffSize(buffSize),
|
||||
#if defined(DISABLE_SOFTWARE_SERIAL)
|
||||
#if USES_SW_SERIAL
|
||||
_forceSWserial(false)
|
||||
#else
|
||||
_forceSWserial(forceSWserial)
|
||||
#endif
|
||||
{
|
||||
_serialtype = ESPeasySerialType::getSerialType(port, receivePin, transmitPin);
|
||||
#ifndef DISABLE_SOFTWARE_SERIAL
|
||||
#if USES_SW_SERIAL
|
||||
if (forceSWserial) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
if (_serialtype != ESPEasySerialPort::sc16is752) {
|
||||
_serialtype = ESPEasySerialPort::software;
|
||||
}
|
||||
@@ -44,99 +38,62 @@ ESPeasySerial::ESPeasySerial(ESPEasySerialPort port,
|
||||
#endif
|
||||
|
||||
switch (_serialtype) {
|
||||
#if USES_SW_SERIAL
|
||||
case ESPEasySerialPort::software:
|
||||
{
|
||||
#ifndef DISABLE_SOFTWARE_SERIAL
|
||||
_swserial = new ESPeasySoftwareSerial(receivePin, transmitPin, inverse_logic);
|
||||
#endif
|
||||
_serialPort = new ESPEasySerial_SW_Serial(receivePin, transmitPin, inverse_logic);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if USES_I2C_SC16IS752
|
||||
case ESPEasySerialPort::sc16is752:
|
||||
{
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
ESPEasySC16IS752_Serial::I2C_address addr = static_cast<ESPEasySC16IS752_Serial::I2C_address>(receivePin);
|
||||
ESPEasySC16IS752_Serial::SC16IS752_channel ch = static_cast<ESPEasySC16IS752_Serial::SC16IS752_channel>(transmitPin);
|
||||
|
||||
_i2cserial = new ESPEasySC16IS752_Serial(addr, ch);
|
||||
#endif
|
||||
_serialPort = new ESPEasySerial_I2C_SC16IS752(addr, ch);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if USES_HWCDC
|
||||
case ESPEasySerialPort::usb_hw_cdc:
|
||||
{
|
||||
_serialPort = new ESPEasySerial_USB_WHCDC_t();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if USES_USBCDC
|
||||
case ESPEasySerialPort::usb_cdc_0:
|
||||
case ESPEasySerialPort::usb_cdc_1:
|
||||
{
|
||||
_serialPort = new ESPEasySerial_USBCDC_t(_serialtype);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
|
||||
if (isValid()) {
|
||||
getHW()->pins(transmitPin, receivePin);
|
||||
if (isHWserial(_serialtype)) {
|
||||
_serialPort = new ESPEasySerial_HardwareSerial_t(_serialtype);
|
||||
if (_serialPort != nullptr) {
|
||||
_serialPort->resetConfig(_serialtype, receivePin, transmitPin, inverse_logic, buffSize);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isValid()) {
|
||||
begin(_baud, _config, _mode);
|
||||
if (_serialPort != nullptr) {
|
||||
_serialPort->begin(_baud);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ifdef ESP8266
|
||||
|
||||
#ifdef ESP32
|
||||
ESPeasySerial::ESPeasySerial(
|
||||
ESPEasySerialPort port,
|
||||
int receivePin,
|
||||
int transmitPin,
|
||||
bool inverse_logic,
|
||||
unsigned int buffSize)
|
||||
:
|
||||
# ifndef DISABLE_SC16IS752_Serial
|
||||
_i2cserial(nullptr),
|
||||
# endif // ifndef DISABLE_SC16IS752_Serial
|
||||
_receivePin(receivePin),
|
||||
_transmitPin(transmitPin),
|
||||
_inverse_logic(inverse_logic),
|
||||
_buffSize(buffSize)
|
||||
{
|
||||
switch (port) {
|
||||
case ESPEasySerialPort::serial0:
|
||||
case ESPEasySerialPort::serial1:
|
||||
# if HAS_SERIAL2
|
||||
case ESPEasySerialPort::serial2:
|
||||
# endif
|
||||
_serialtype = port;
|
||||
break;
|
||||
default:
|
||||
_serialtype = ESPeasySerialType::getSerialType(port, receivePin, transmitPin);
|
||||
}
|
||||
|
||||
# ifndef DISABLE_SC16IS752_Serial
|
||||
|
||||
switch (_serialtype) {
|
||||
case ESPEasySerialPort::sc16is752:
|
||||
{
|
||||
ESPEasySC16IS752_Serial::I2C_address addr = static_cast<ESPEasySC16IS752_Serial::I2C_address>(receivePin);
|
||||
ESPEasySC16IS752_Serial::SC16IS752_channel ch = static_cast<ESPEasySC16IS752_Serial::SC16IS752_channel>(transmitPin);
|
||||
_i2cserial = new ESPEasySC16IS752_Serial(addr, ch);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
# endif // ifndef DISABLE_SC16IS752_Serial
|
||||
|
||||
}
|
||||
|
||||
#endif // ifdef ESP32
|
||||
|
||||
ESPeasySerial::~ESPeasySerial() {
|
||||
flush();
|
||||
end();
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
|
||||
if (_swserial != nullptr) {
|
||||
delete _swserial;
|
||||
if (_serialPort != nullptr) {
|
||||
delete _serialPort;
|
||||
}
|
||||
#endif // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
|
||||
if (_i2cserial != nullptr) {
|
||||
delete _i2cserial;
|
||||
}
|
||||
#endif // ifndef DISABLE_SC16IS752_Serial
|
||||
}
|
||||
|
||||
String ESPeasySerial::getLogString() const {
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
#ifndef ESPEASYSERIAL_ESPEASYSERIAL_COMMON_DEFINES_H
|
||||
#define ESPEASYSERIAL_ESPEASYSERIAL_COMMON_DEFINES_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
#ifndef HAS_SERIAL2
|
||||
# ifdef ESP8266
|
||||
# define HAS_SERIAL2 0
|
||||
# elif defined(ESP32_CLASSIC) || defined(ESP32S2) || defined(ESP32S3) || defined(ESP32C3)
|
||||
# include <soc/soc_caps.h>
|
||||
# if SOC_UART_NUM > 2
|
||||
# define HAS_SERIAL2 1
|
||||
# else // if SOC_UART_NUM > 2
|
||||
# define HAS_SERIAL2 0
|
||||
# endif // if SOC_UART_NUM > 2
|
||||
# else // ifdef ESP8266
|
||||
static_assert(false, "Implement processor architecture");
|
||||
# endif // ifdef ESP8266
|
||||
#endif // ifndef HAS_SERIAL2
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
/*
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface
|
||||
CONFIG_IDF_TARGET_ESP32S2 || // support USB via USBCDC
|
||||
CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC
|
||||
*/
|
||||
# if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
// #if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE
|
||||
# ifdef USE_USB_CDC_CONSOLE
|
||||
# if ARDUINO_USB_MODE
|
||||
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
# define USES_HWCDC 1
|
||||
# else // No ARDUINO_USB_MODE
|
||||
# define USES_USBCDC 1
|
||||
# endif // ARDUINO_USB_MODE
|
||||
# endif // ifdef USE_USB_CDC_CONSOLE
|
||||
# endif // if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
#endif // ifdef ESP32
|
||||
|
||||
|
||||
|
||||
#ifndef ESP32
|
||||
# if defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
|
||||
# ifndef CORE_2_4_X
|
||||
# define CORE_2_4_X
|
||||
# endif // ifndef CORE_2_4_X
|
||||
# endif // if defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) ||
|
||||
// defined(ARDUINO_ESP8266_RELEASE_2_4_2)
|
||||
|
||||
# if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1)
|
||||
# ifndef CORE_PRE_2_4_2
|
||||
# define CORE_PRE_2_4_2
|
||||
# endif // ifndef CORE_PRE_2_4_2
|
||||
# endif // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) ||
|
||||
// defined(ARDUINO_ESP8266_RELEASE_2_4_1)
|
||||
|
||||
# if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(CORE_2_4_X)
|
||||
# ifndef CORE_PRE_2_5_0
|
||||
# define CORE_PRE_2_5_0
|
||||
# endif // ifndef CORE_PRE_2_5_0
|
||||
# else // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(CORE_2_4_X)
|
||||
# ifndef CORE_POST_2_5_0
|
||||
# define CORE_POST_2_5_0
|
||||
# endif // ifndef CORE_POST_2_5_0
|
||||
# endif // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(CORE_2_4_X)
|
||||
#endif // ESP32
|
||||
|
||||
|
||||
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ESP32)
|
||||
# ifndef DISABLE_SOFTWARE_SERIAL
|
||||
# define DISABLE_SOFTWARE_SERIAL
|
||||
# endif // ifndef DISABLE_SOFTWARE_SERIAL
|
||||
#endif // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ESP32)
|
||||
|
||||
#ifndef USES_HWCDC
|
||||
# define USES_HWCDC 0
|
||||
#endif // ifndef USES_HWCDC
|
||||
|
||||
#ifndef USES_USBCDC
|
||||
# define USES_USBCDC 0
|
||||
#endif // ifndef USES_USBCDC
|
||||
|
||||
|
||||
#ifndef USES_SW_SERIAL
|
||||
#ifndef DISABLE_SOFTWARE_SERIAL
|
||||
#define USES_SW_SERIAL 1
|
||||
#else
|
||||
#define USES_SW_SERIAL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef USES_I2C_SC16IS752
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#define USES_I2C_SC16IS752 1
|
||||
#else
|
||||
#define USES_I2C_SC16IS752 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -23,102 +23,15 @@
|
||||
#ifndef ESPeasySerial_h
|
||||
#define ESPeasySerial_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <HardwareSerial.h>
|
||||
#include <inttypes.h>
|
||||
#include <Stream.h>
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
# include <ESPEasySC16IS752_Serial.h>
|
||||
#endif // ifndef DISABLE_SC16IS752_Serial
|
||||
|
||||
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ESP32)
|
||||
# ifndef DISABLE_SOFTWARE_SERIAL
|
||||
# define DISABLE_SOFTWARE_SERIAL
|
||||
# endif // ifndef DISABLE_SOFTWARE_SERIAL
|
||||
#endif // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ESP32)
|
||||
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
# include <ESPEasySoftwareSerial.h>
|
||||
# include "ESPEasySerialConfig.h"
|
||||
#endif
|
||||
|
||||
#ifndef HAS_SERIAL2
|
||||
#ifdef ESP8266
|
||||
#define HAS_SERIAL2 0
|
||||
#elif defined(ESP32_CLASSIC) || defined(ESP32S2) || defined(ESP32S3) || defined(ESP32C3)
|
||||
#include <soc/soc_caps.h>
|
||||
#if SOC_UART_NUM > 2
|
||||
#define HAS_SERIAL2 1
|
||||
#else
|
||||
#define HAS_SERIAL2 0
|
||||
#endif
|
||||
# else
|
||||
static_assert(false, "Implement processor architecture");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
# ifndef DISABLE_SC16IS752_Serial
|
||||
# if HAS_SERIAL2
|
||||
# define NR_ESPEASY_SERIAL_TYPES 4 // Serial 0, 1, 2, sc16is752
|
||||
# else
|
||||
# define NR_ESPEASY_SERIAL_TYPES 3 // Serial 0, 1, sc16is752
|
||||
# endif
|
||||
# else // ifndef DISABLE_SC16IS752_Serial
|
||||
# if HAS_SERIAL2
|
||||
# define NR_ESPEASY_SERIAL_TYPES 3 // Serial 0, 1, 2
|
||||
# else
|
||||
# define NR_ESPEASY_SERIAL_TYPES 2 // Serial 0, 1
|
||||
# endif
|
||||
# endif // ifndef DISABLE_SC16IS752_Serial
|
||||
#endif // ifdef ESP32
|
||||
#ifdef ESP8266
|
||||
# if !defined(DISABLE_SOFTWARE_SERIAL)
|
||||
# ifndef DISABLE_SC16IS752_Serial
|
||||
# define NR_ESPEASY_SERIAL_TYPES 5 // Serial 0, 1, 0_swap, software, sc16is752
|
||||
# else // ifndef DISABLE_SC16IS752_Serial
|
||||
# define NR_ESPEASY_SERIAL_TYPES 4 // Serial 0, 1, 0_swap, software
|
||||
# endif // ifndef DISABLE_SC16IS752_Serial
|
||||
# else // if !defined(DISABLE_SOFTWARE_SERIAL)
|
||||
# ifndef DISABLE_SC16IS752_Serial
|
||||
# define NR_ESPEASY_SERIAL_TYPES 4 // Serial 0, 1, 0_swap, sc16is752
|
||||
# else // ifndef DISABLE_SC16IS752_Serial
|
||||
# define NR_ESPEASY_SERIAL_TYPES 3 // Serial 0, 1, 0_swap
|
||||
# endif // ifndef DISABLE_SC16IS752_Serial
|
||||
# endif // if !defined(DISABLE_SOFTWARE_SERIAL)
|
||||
#endif // ifdef ESP8266
|
||||
|
||||
#ifndef ESP32
|
||||
# if defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
|
||||
# ifndef CORE_2_4_X
|
||||
# define CORE_2_4_X
|
||||
# endif // ifndef CORE_2_4_X
|
||||
# endif // if defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) ||
|
||||
// defined(ARDUINO_ESP8266_RELEASE_2_4_2)
|
||||
|
||||
# if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1)
|
||||
# ifndef CORE_PRE_2_4_2
|
||||
# define CORE_PRE_2_4_2
|
||||
# endif // ifndef CORE_PRE_2_4_2
|
||||
# endif // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) ||
|
||||
// defined(ARDUINO_ESP8266_RELEASE_2_4_1)
|
||||
|
||||
# if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(CORE_2_4_X)
|
||||
# ifndef CORE_PRE_2_5_0
|
||||
# define CORE_PRE_2_5_0
|
||||
# endif // ifndef CORE_PRE_2_5_0
|
||||
# else // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(CORE_2_4_X)
|
||||
# ifndef CORE_POST_2_5_0
|
||||
# define CORE_POST_2_5_0
|
||||
# endif // ifndef CORE_POST_2_5_0
|
||||
# endif // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(CORE_2_4_X)
|
||||
#endif // ESP32
|
||||
|
||||
#include "ESPEasySerial_common_defines.h"
|
||||
|
||||
#include "ESPEasySerialPort.h"
|
||||
#include "ESPEasySerialType.h"
|
||||
|
||||
#include "wrappers/ESPEasySerial_Port_base.h"
|
||||
|
||||
|
||||
|
||||
class ESPeasySerial : public Stream {
|
||||
public:
|
||||
@@ -284,40 +197,13 @@ public:
|
||||
}
|
||||
private:
|
||||
|
||||
const HardwareSerial* getHW() const;
|
||||
HardwareSerial * getHW();
|
||||
const ESPEasySerial_Port_base* getHW() const;
|
||||
ESPEasySerial_Port_base * getHW();
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
#ifdef ESP8266
|
||||
bool doHWbegin(unsigned long baud,
|
||||
SerialConfig config,
|
||||
SerialMode mode);
|
||||
#endif // ifdef ESP8266
|
||||
ESPEasySerial_Port_base* _serialPort = nullptr;
|
||||
|
||||
bool isI2Cserial() const {
|
||||
return _serialtype == ESPEasySerialPort::sc16is752;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
ESPEasySC16IS752_Serial *_i2cserial = nullptr;
|
||||
#endif // ifndef DISABLE_SC16IS752_Serial
|
||||
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
bool isSWserial() const {
|
||||
return _serialtype == ESPEasySerialPort::software;
|
||||
}
|
||||
|
||||
ESPeasySoftwareSerial *_swserial = nullptr;
|
||||
#else // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
bool isSWserial() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#ifdef ESP8266
|
||||
static bool _serial0_swap_active;
|
||||
#endif // ESP8266
|
||||
|
||||
private:
|
||||
// Actual serial type
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
// ****************************************
|
||||
#ifdef ESP8266
|
||||
bool ESPeasySerial::_serial0_swap_active = false;
|
||||
#endif // ifdef ESP8266
|
||||
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#if USES_SW_SERIAL
|
||||
|
||||
void ESPeasySerial::resetConfig(ESPEasySerialPort port, int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize, bool forceSWserial)
|
||||
{
|
||||
@@ -20,13 +19,13 @@ void ESPeasySerial::resetConfig(ESPEasySerialPort port, int receivePin, int tran
|
||||
_swserial->end();
|
||||
delete _swserial;
|
||||
}
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
if (_i2cserial != nullptr) {
|
||||
_i2cserial->end();
|
||||
delete _i2cserial;
|
||||
}
|
||||
#endif
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
_i2cserial = nullptr;
|
||||
#endif
|
||||
_serialtype = ESPeasySerialType::getSerialType(port, receivePin, transmitPin);
|
||||
@@ -55,7 +54,7 @@ void ESPeasySerial::resetConfig(ESPEasySerialPort port, int receivePin, int tran
|
||||
}
|
||||
case ESPEasySerialPort::sc16is752:
|
||||
{
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
ESPEasySC16IS752_Serial::I2C_address addr = static_cast<ESPEasySC16IS752_Serial::I2C_address>(receivePin);
|
||||
ESPEasySC16IS752_Serial::SC16IS752_channel ch = static_cast<ESPEasySC16IS752_Serial::SC16IS752_channel>(transmitPin);
|
||||
|
||||
@@ -86,7 +85,7 @@ void ESPeasySerial::begin(unsigned long baud, SerialConfig config, SerialMode mo
|
||||
_swserial->begin(baud);
|
||||
}
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
if (_i2cserial != nullptr) {
|
||||
_i2cserial->begin(baud);
|
||||
}
|
||||
@@ -108,7 +107,7 @@ void ESPeasySerial::end() {
|
||||
# endif // ifndef ARDUINO_ESP8266_RELEASE_2_3_0
|
||||
return;
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
_i2cserial->end();
|
||||
#endif
|
||||
} else {
|
||||
@@ -147,7 +146,7 @@ bool ESPeasySerial::isValid() const {
|
||||
case ESPEasySerialPort::serial1: return true; // Must also check RX pin?
|
||||
case ESPEasySerialPort::software: return _swserial != nullptr;
|
||||
case ESPEasySerialPort::sc16is752:
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
return _i2cserial != nullptr;
|
||||
#else
|
||||
return false;
|
||||
@@ -165,7 +164,7 @@ int ESPeasySerial::peek(void) {
|
||||
if (isSWserial()) {
|
||||
return _swserial->peek();
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
return _i2cserial->peek();
|
||||
#else
|
||||
return -1;
|
||||
@@ -183,7 +182,7 @@ size_t ESPeasySerial::write(uint8_t val) {
|
||||
if (isSWserial()) {
|
||||
return _swserial->write(val);
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
return _i2cserial->write(val);
|
||||
#else
|
||||
return 0;
|
||||
@@ -210,7 +209,7 @@ size_t ESPeasySerial::write(const uint8_t *buffer, size_t size) {
|
||||
}
|
||||
return count;
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
return _i2cserial->write(buffer, size);
|
||||
#else
|
||||
return 0;
|
||||
@@ -233,7 +232,7 @@ int ESPeasySerial::read(void) {
|
||||
if (isSWserial()) {
|
||||
return _swserial->read();
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
return _i2cserial->read();
|
||||
#else
|
||||
return -1;
|
||||
@@ -261,7 +260,7 @@ size_t ESPeasySerial::readBytes(char *buffer, size_t size) {
|
||||
}
|
||||
return count;
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
return _i2cserial->readBytes(buffer, size);
|
||||
#else
|
||||
return 0;
|
||||
@@ -283,7 +282,7 @@ int ESPeasySerial::available(void) {
|
||||
if (isSWserial()) {
|
||||
return _swserial->available();
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
return _i2cserial->available();
|
||||
#else
|
||||
return 0;
|
||||
@@ -302,7 +301,7 @@ int ESPeasySerial::availableForWrite() {
|
||||
// FIXME TD-er: Implement availableForWrite
|
||||
return 1;
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
// FIXME TD-er: Implement availableForWrite
|
||||
return 4; //_i2cserial->availableForWrite();
|
||||
#else
|
||||
@@ -321,7 +320,7 @@ void ESPeasySerial::flush(void) {
|
||||
if (isSWserial()) {
|
||||
_swserial->flush();
|
||||
} else if (isI2Cserial()) {
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
_i2cserial->flush();
|
||||
#endif
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef ESPEASYCORE_ESPEASY_USB_H
|
||||
#define ESPEASYCORE_ESPEASY_USB_H
|
||||
|
||||
// Do not include this file, but rather include "../Globals/ESPEasy_USB.h"
|
||||
// from a .cpp file.
|
||||
|
||||
#include "../ESPEasySerial_common_defines.h"
|
||||
|
||||
#if USES_HWCDC
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
#include <HWCDC.h>
|
||||
extern HWCDC *_hwcdc_serial;
|
||||
#endif
|
||||
|
||||
#if USES_USBCDC
|
||||
#include <USB.h>
|
||||
#include <USBCDC.h>
|
||||
extern USBCDC *_usbcdc_serial;
|
||||
#endif
|
||||
|
||||
#endif // ifndef ESPEASYCORE_ESPEASY_USB_H
|
||||
+42
-57
@@ -3,21 +3,6 @@
|
||||
|
||||
#include "ESPEasySerialType.h"
|
||||
|
||||
#ifndef HAS_SERIAL2
|
||||
# ifdef ESP8266
|
||||
# define HAS_SERIAL2 0
|
||||
# elif defined(ESP32_CLASSIC) || defined(ESP32S2) || defined(ESP32S3) || defined(ESP32C3)
|
||||
# include <soc/soc_caps.h>
|
||||
# if SOC_UART_NUM > 2
|
||||
# define HAS_SERIAL2 1
|
||||
# else // if SOC_UART_NUM > 2
|
||||
# define HAS_SERIAL2 0
|
||||
# endif // if SOC_UART_NUM > 2
|
||||
# else // ifdef ESP8266
|
||||
static_assert(false, "Implement processor architecture");
|
||||
# endif // ifdef ESP8266
|
||||
#endif // ifndef HAS_SERIAL2
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
@@ -89,7 +74,7 @@ void setPinsCache(ESPEasySerialPort port,
|
||||
ESPEasySerial_HardwareSerial_t::ESPEasySerial_HardwareSerial_t(ESPEasySerialPort port)
|
||||
: _serial(nullptr)
|
||||
{
|
||||
_port = ESPEasySerialPort::not_set;
|
||||
_config.port = ESPEasySerialPort::not_set;
|
||||
}
|
||||
|
||||
void ESPEasySerial_HardwareSerial_t::resetConfig(
|
||||
@@ -99,10 +84,10 @@ void ESPEasySerial_HardwareSerial_t::resetConfig(
|
||||
bool inverse_logic,
|
||||
unsigned int buffSize)
|
||||
{
|
||||
_rxPin = receivePin;
|
||||
_txPin = transmitPin;
|
||||
_invert = inverse_logic;
|
||||
_buffSize = buffSize;
|
||||
_config.receivePin = receivePin;
|
||||
_config.transmitPin = transmitPin;
|
||||
_config.inverse_logic = inverse_logic;
|
||||
_config.buffSize = buffSize;
|
||||
|
||||
switch (port) {
|
||||
case ESPEasySerialPort::serial0:
|
||||
@@ -110,30 +95,30 @@ void ESPEasySerial_HardwareSerial_t::resetConfig(
|
||||
#if HAS_SERIAL2
|
||||
case ESPEasySerialPort::serial2:
|
||||
#endif // if HAS_SERIAL2
|
||||
_port = port;
|
||||
_config.port = port;
|
||||
break;
|
||||
default:
|
||||
_port = ESPeasySerialType::getSerialType(port, receivePin, transmitPin);
|
||||
_config.port = ESPeasySerialType::getSerialType(port, receivePin, transmitPin);
|
||||
}
|
||||
|
||||
if (_port == ESPEasySerialPort::serial0) {
|
||||
if (_config.port == ESPEasySerialPort::serial0) {
|
||||
#if defined(ESP32) && !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) && ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC
|
||||
_serial = &Serial0;
|
||||
#else // if defined(ESP32) && !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) && ARDUINO_USB_CDC_ON_BOOT
|
||||
_serial = &Serial;
|
||||
#endif // if defined(ESP32) && !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) && ARDUINO_USB_CDC_ON_BOOT
|
||||
#ifdef ESP8266
|
||||
} else if (_port == ESPEasySerialPort::serial0_swap) {
|
||||
} else if (_config.port == ESPEasySerialPort::serial0_swap) {
|
||||
_serial = &Serial;
|
||||
#endif // ifdef ESP8266
|
||||
} else if (_port == ESPEasySerialPort::serial1) {
|
||||
} else if (_config.port == ESPEasySerialPort::serial1) {
|
||||
_serial = &Serial1;
|
||||
#if HAS_SERIAL2
|
||||
} else if (_port == ESPEasySerialPort::serial2) {
|
||||
} else if (_config.port == ESPEasySerialPort::serial2) {
|
||||
_serial = &Serial2;
|
||||
#endif // if HAS_SERIAL2
|
||||
} else {
|
||||
_port = ESPEasySerialPort::not_set;
|
||||
_config.port = ESPEasySerialPort::not_set;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,8 +126,8 @@ void ESPEasySerial_HardwareSerial_t::resetConfig(
|
||||
void ESPEasySerial_HardwareSerial_t::setSerialConfig(SerialConfig config,
|
||||
SerialMode mode)
|
||||
{
|
||||
_config = config;
|
||||
_mode = mode;
|
||||
_config.config = config;
|
||||
_config.mode = mode;
|
||||
}
|
||||
|
||||
#endif // ifdef ESP8266
|
||||
@@ -151,7 +136,7 @@ void ESPEasySerial_HardwareSerial_t::setSerialConfig(SerialConfig config,
|
||||
void ESPEasySerial_HardwareSerial_t::setSerialConfig(uint32_t config)
|
||||
{
|
||||
// Make sure the extra bit is set for the config. The config differs between ESP32 and ESP82xx
|
||||
_config = config | 0x8000000;
|
||||
_config.config = config | 0x8000000;
|
||||
}
|
||||
|
||||
#endif // ifdef ESP32
|
||||
@@ -160,7 +145,7 @@ void ESPEasySerial_HardwareSerial_t::setSerialConfig(uint32_t config)
|
||||
void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
|
||||
{
|
||||
if (_serial == nullptr) {
|
||||
_baud = 0;
|
||||
_config.baud = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -169,23 +154,23 @@ void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
|
||||
* UART 1 allows only TX on 2 if UART 0 is not (2, 3)
|
||||
*/
|
||||
|
||||
if (_port == ESPEasySerialPort::serial0_swap) {
|
||||
_txPin = 15;
|
||||
_rxPin = 13;
|
||||
} else if (_port == ESPEasySerialPort::serial0) {
|
||||
_txPin = 1;
|
||||
_rxPin = 3;
|
||||
} else if (_port == ESPEasySerialPort::serial1) {
|
||||
_txPin = 2;
|
||||
_rxPin = -1;
|
||||
if (_config.port == ESPEasySerialPort::serial0_swap) {
|
||||
_config.transmitPin = 15;
|
||||
_config.receivePin = 13;
|
||||
} else if (_config.port == ESPEasySerialPort::serial0) {
|
||||
_config.transmitPin = 1;
|
||||
_config.receivePin = 3;
|
||||
} else if (_config.port == ESPEasySerialPort::serial1) {
|
||||
_config.transmitPin = 2;
|
||||
_config.receivePin = -1;
|
||||
} else {
|
||||
_txPin = -1;
|
||||
_rxPin = -1;
|
||||
_config.transmitPin = -1;
|
||||
_config.receivePin = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
_serial->begin(_baud, _config, _mode, _txPin, _invert);
|
||||
_serial->pins(_txPin, _rxPin);
|
||||
_serial->begin(_config.baud, _config, _mode, _config.transmitPin, _config.inverse_logic);
|
||||
_serial->pins(_config.transmitPin, _config.receivePin);
|
||||
}
|
||||
|
||||
#endif // ifdef ESP8266
|
||||
@@ -194,16 +179,16 @@ void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
|
||||
void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
|
||||
{
|
||||
if (_serial == nullptr) {
|
||||
_baud = 0;
|
||||
_config.baud = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Timeout added for 1.0.1
|
||||
// See: https://github.com/espressif/arduino-esp32/commit/233d31bed22211e8c85f82bcf2492977604bbc78
|
||||
// getHW()->begin(baud, config, _rxPin, _txPin, invert, timeout_ms);
|
||||
if (pinsChanged(_port, _rxPin, _txPin) || (_baud != baud)) {
|
||||
setPinsCache(_port, _rxPin, _txPin);
|
||||
_baud = baud;
|
||||
// getHW()->begin(baud, config, _config.receivePin, _config.transmitPin, invert, timeout_ms);
|
||||
if (pinsChanged(_config.port, _config.receivePin, _config.transmitPin) || (_config.baud != baud)) {
|
||||
setPinsCache(_config.port, _config.receivePin, _config.transmitPin);
|
||||
_config.baud = baud;
|
||||
|
||||
// Allow to flush data from the serial buffers
|
||||
// Otherwise the ESP may hang at boot.
|
||||
@@ -211,7 +196,7 @@ void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
|
||||
_serial->end();
|
||||
delay(10);
|
||||
|
||||
_serial->begin(baud, _config, _rxPin, _txPin, _invert);
|
||||
_serial->begin(baud, _config.config, _config.receivePin, _config.transmitPin, _config.inverse_logic);
|
||||
_serial->flush();
|
||||
}
|
||||
}
|
||||
@@ -264,10 +249,10 @@ size_t ESPEasySerial_HardwareSerial_t::read(uint8_t *buffer,
|
||||
if (_serial != nullptr) {
|
||||
#ifdef ESP32
|
||||
return _serial->read(buffer, size);
|
||||
#endif
|
||||
#endif // ifdef ESP32
|
||||
#ifdef ESP8266
|
||||
return _serial->read((char*)buffer, size);
|
||||
#endif
|
||||
return _serial->read((char *)buffer, size);
|
||||
#endif // ifdef ESP8266
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -284,10 +269,10 @@ void ESPEasySerial_HardwareSerial_t::flush(bool txOnly)
|
||||
if (_serial != nullptr) {
|
||||
#ifdef ESP32
|
||||
_serial->flush(txOnly);
|
||||
#endif
|
||||
#endif // ifdef ESP32
|
||||
#ifdef ESP8266
|
||||
_serial->flush();
|
||||
#endif
|
||||
#endif // ifdef ESP8266
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,10 +317,10 @@ size_t ESPEasySerial_HardwareSerial_t::setTxBufferSize(size_t new_size)
|
||||
if (_serial != nullptr) {
|
||||
#ifdef ESP32
|
||||
return _serial->setTxBufferSize(new_size);
|
||||
#endif
|
||||
#endif // ifdef ESP32
|
||||
#ifdef ESP8266
|
||||
return new_size;
|
||||
#endif
|
||||
#endif // ifdef ESP8266
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+4
-19
@@ -1,18 +1,17 @@
|
||||
#ifndef ESPEASYSERIAL_ESPEASYSERIAL_HARDWARESERIAL_H
|
||||
#define ESPEASYSERIAL_ESPEASYSERIAL_HARDWARESERIAL_H
|
||||
|
||||
#include "ESPEasySerial_Port.h"
|
||||
#include "../ESPEasySerial_common_defines.h"
|
||||
|
||||
#include "ESPEasySerial_Port_base.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
#include <Stream.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
#ifdef ESP32
|
||||
# include <esp32-hal-uart.h>
|
||||
#endif // ifdef ESP32
|
||||
|
||||
class ESPEasySerial_HardwareSerial_t : public ESPEasySerial_Port {
|
||||
class ESPEasySerial_HardwareSerial_t : public ESPEasySerial_Port_base {
|
||||
public:
|
||||
|
||||
ESPEasySerial_HardwareSerial_t(ESPEasySerialPort port);
|
||||
@@ -65,20 +64,6 @@ public:
|
||||
private:
|
||||
|
||||
HardwareSerial *_serial = nullptr;
|
||||
|
||||
#ifdef ESP32
|
||||
uint32_t _config = SERIAL_8N1;
|
||||
#endif // ifdef ESP32
|
||||
|
||||
#ifdef ESP8266
|
||||
SerialConfig _config = SERIAL_8N1;
|
||||
SerialMode _mode = SERIAL_FULL;
|
||||
#endif // ifdef ESP8266
|
||||
|
||||
uint32_t _buffSize = 128;
|
||||
int8_t _rxPin = -1;
|
||||
int8_t _txPin = -1;
|
||||
bool _invert = false;
|
||||
};
|
||||
|
||||
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
#include "ESPEasySerial_I2C_SC16IS752.h"
|
||||
|
||||
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
#if USES_I2C_SC16IS752
|
||||
|
||||
|
||||
ESPEasySerial_I2C_SC16IS752::ESPEasySerial_I2C_SC16IS752(ESPEasySC16IS752_Serial::I2C_address addr,
|
||||
ESPEasySC16IS752_Serial::SC16IS752_channel ch)
|
||||
{
|
||||
_port = ESPEasySerialPort::sc16is752;
|
||||
_i2cserial = new ESPEasySC16IS752_Serial(addr, ch);
|
||||
_config.port = ESPEasySerialPort::sc16is752;
|
||||
_i2cserial = new ESPEasySC16IS752_Serial(addr, ch);
|
||||
}
|
||||
|
||||
ESPEasySerial_I2C_SC16IS752::~ESPEasySerial_I2C_SC16IS752()
|
||||
@@ -44,7 +44,7 @@ int ESPEasySerial_I2C_SC16IS752::availableForWrite(void)
|
||||
{
|
||||
if (_i2cserial != nullptr) {
|
||||
// FIXME TD-er: Implement availableForWrite
|
||||
return 4; //_i2cserial->availableForWrite();
|
||||
return 4; // _i2cserial->availableForWrite();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+11
-12
@@ -1,18 +1,17 @@
|
||||
#ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
#define ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
|
||||
#ifndef DISABLE_SC16IS752_Serial
|
||||
# include <ESPEasySC16IS752_Serial.h>
|
||||
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_I2C_SC16IS752_H
|
||||
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_I2C_SC16IS752_H
|
||||
|
||||
|
||||
# include "ESPEasySerial_Port.h"
|
||||
#include "../ESPEasySerial_common_defines.h"
|
||||
|
||||
# include <Arduino.h>
|
||||
# include <inttypes.h>
|
||||
# include <Stream.h>
|
||||
#if USES_I2C_SC16IS752
|
||||
# include "../drivers/ESPEasySC16IS752_Serial.h"
|
||||
|
||||
|
||||
class ESPEasySerial_I2C_SC16IS752 : public ESPEasySerial_Port {
|
||||
# include "ESPEasySerial_Port_base.h"
|
||||
|
||||
|
||||
class ESPEasySerial_I2C_SC16IS752 : public ESPEasySerial_Port_base {
|
||||
public:
|
||||
|
||||
// ESPEasySC16IS752_Serial::I2C_address addr = static_cast<ESPEasySC16IS752_Serial::I2C_address>(receivePin);
|
||||
@@ -53,7 +52,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif // if USES_HWCDC
|
||||
#endif // if USES_I2C_SC16IS752
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_I2C_SC16IS752_H
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ESPEasySerial_Port_base.h"
|
||||
|
||||
ESPEasySerial_Port_base::ESPEasySerial_Port_base() {}
|
||||
+24
-12
@@ -1,17 +1,18 @@
|
||||
#ifndef ESPEASY_SERIAL_PORT_H
|
||||
#define ESPEASY_SERIAL_PORT_H
|
||||
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_PORT_BASE_H
|
||||
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_PORT_BASE_H
|
||||
|
||||
#include "ESPEasySerialPort.h"
|
||||
#include "../ESPEasySerialPort.h"
|
||||
|
||||
#include "../ESPEasySerial_common_defines.h"
|
||||
#include "../ESPEasySerialConfig.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
#include <Stream.h>
|
||||
|
||||
class ESPEasySerial_Port : public Stream {
|
||||
class ESPEasySerial_Port_base : public Stream {
|
||||
public:
|
||||
|
||||
ESPEasySerial_Port();
|
||||
virtual ~ESPEasySerial_Port() {}
|
||||
ESPEasySerial_Port_base();
|
||||
virtual ~ESPEasySerial_Port_base() {}
|
||||
|
||||
virtual void begin(unsigned long baud) = 0;
|
||||
|
||||
@@ -74,12 +75,23 @@ public:
|
||||
virtual size_t setRxBufferSize(size_t new_size) = 0;
|
||||
virtual size_t setTxBufferSize(size_t new_size) = 0;
|
||||
|
||||
|
||||
unsigned long getBaudRate() const {
|
||||
return _config.baud;
|
||||
}
|
||||
|
||||
bool useGPIOpins() const {
|
||||
return _config.port != ESPEasySerialPort::sc16is752;
|
||||
}
|
||||
|
||||
ESPEasySerialPort getSerialPortType() const {
|
||||
return _config.port;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ESPEasySerialPort _port = ESPEasySerialPort::not_set;
|
||||
|
||||
unsigned long _baud = 115200;
|
||||
ESPEasySerialConfig _config;
|
||||
};
|
||||
|
||||
|
||||
#endif // ifndef ESPEASY_SERIAL_PORT_H
|
||||
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_PORT_BASE_H
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
#include "ESPEasySerial_SW_Serial.h"
|
||||
|
||||
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#if USES_SW_SERIAL
|
||||
|
||||
|
||||
ESPEasySerial_SW_Serial::ESPEasySerial_SW_Serial(int receivePin, int transmitPin, bool inverse_logic)
|
||||
{
|
||||
_port = ESPEasySerialPort::software;
|
||||
_swserial = new ESPeasySoftwareSerial(receivePin, transmitPin, inverse_logic);
|
||||
_config.port = ESPEasySerialPort::software;
|
||||
_swserial = new ESPeasySoftwareSerial(receivePin, transmitPin, inverse_logic);
|
||||
}
|
||||
|
||||
ESPEasySerial_SW_Serial::~ESPEasySerial_SW_Serial()
|
||||
@@ -125,4 +125,4 @@ size_t ESPEasySerial_SW_Serial::setTxBufferSize(size_t new_size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#endif // if USES_SW_SERIAL
|
||||
+13
-19
@@ -1,24 +1,18 @@
|
||||
#ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
#define ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
|
||||
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ESP32)
|
||||
# ifndef DISABLE_SOFTWARE_SERIAL
|
||||
# define DISABLE_SOFTWARE_SERIAL
|
||||
# endif // ifndef DISABLE_SOFTWARE_SERIAL
|
||||
#endif // if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ESP32)
|
||||
|
||||
#if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
# include <ESPEasySoftwareSerial.h>
|
||||
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_SW_SERIAL_H
|
||||
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_SW_SERIAL_H
|
||||
|
||||
|
||||
# include "ESPEasySerial_Port.h"
|
||||
|
||||
# include <Arduino.h>
|
||||
# include <inttypes.h>
|
||||
# include <Stream.h>
|
||||
#include "../ESPEasySerial_common_defines.h"
|
||||
|
||||
|
||||
class ESPEasySerial_SW_Serial : public ESPEasySerial_Port {
|
||||
#if USES_SW_SERIAL
|
||||
|
||||
# include "../drivers/ESPEasySoftwareSerial.h"
|
||||
|
||||
# include "ESPEasySerial_Port_base.h"
|
||||
|
||||
|
||||
class ESPEasySerial_SW_Serial : public ESPEasySerial_Port_base {
|
||||
public:
|
||||
|
||||
ESPEasySerial_SW_Serial(int receivePin,
|
||||
@@ -56,7 +50,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266)
|
||||
#endif // if USES_SW_SERIAL
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYSERIAL_ESPEASYSERIAL_USBCDC_H
|
||||
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_SW_SERIAL_H
|
||||
+3
-2
@@ -1,9 +1,10 @@
|
||||
#include "ESPEasySerial_USBCDC.h"
|
||||
|
||||
#include "ESPEasySerial_USB.h"
|
||||
|
||||
#if USES_USBCDC
|
||||
|
||||
# include "../drivers/ESPEasySerial_USB.h"
|
||||
|
||||
volatile bool usbActive = false;
|
||||
|
||||
volatile int32_t eventidTriggered = ESP_EVENT_ANY_ID;
|
||||
@@ -93,7 +94,7 @@ ESPEasySerial_USBCDC_t::ESPEasySerial_USBCDC_t(ESPEasySerialPort port)
|
||||
}
|
||||
|
||||
if (uart_nr > 0) {
|
||||
_port = port;
|
||||
_config.port = port;
|
||||
|
||||
if ((uart_nr == 0) && (_usbcdc_serial != nullptr)) {
|
||||
_serial = _usbcdc_serial;
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USBCDC_H
|
||||
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USBCDC_H
|
||||
|
||||
#include "../ESPEasySerial_common_defines.h"
|
||||
|
||||
#if USES_USBCDC
|
||||
|
||||
// ESP32-S2 USB CDC interface
|
||||
# include <USB.h>
|
||||
# include <USBCDC.h>
|
||||
|
||||
# include "ESPEasySerial_Port_base.h"
|
||||
|
||||
class ESPEasySerial_USBCDC_t : public ESPEasySerial_Port_base {
|
||||
public:
|
||||
|
||||
ESPEasySerial_USBCDC_t(ESPEasySerialPort port);
|
||||
|
||||
virtual ~ESPEasySerial_USBCDC_t();
|
||||
|
||||
void begin(unsigned long baud);
|
||||
|
||||
void end();
|
||||
int available(void);
|
||||
int availableForWrite(void);
|
||||
int peek(void);
|
||||
int read(void);
|
||||
size_t read(uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
void flush(void);
|
||||
void flush(bool txOnly);
|
||||
size_t write(uint8_t);
|
||||
size_t write(const uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
operator bool() const;
|
||||
|
||||
void setDebugOutput(bool);
|
||||
|
||||
size_t setRxBufferSize(size_t new_size);
|
||||
size_t setTxBufferSize(size_t new_size);
|
||||
|
||||
private:
|
||||
|
||||
USBCDC *_serial = nullptr;
|
||||
bool _mustDelete = false;
|
||||
};
|
||||
|
||||
|
||||
#endif // if USES_USBCDC
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USBCDC_H
|
||||
+2
-3
@@ -1,9 +1,8 @@
|
||||
#include "ESPEasySerial_USB_HWCDC.h"
|
||||
|
||||
#include "ESPEasySerial_USB.h"
|
||||
|
||||
#if USES_HWCDC
|
||||
|
||||
# include "../drivers/ESPEasySerial_USB.h"
|
||||
|
||||
volatile bool usbActive = false;
|
||||
|
||||
@@ -49,7 +48,7 @@ static void hwcdcEventCallback(void *arg, esp_event_base_t event_base, int32_t e
|
||||
|
||||
ESPEasySerial_USB_WHCDC_t::ESPEasySerial_USB_WHCDC_t()
|
||||
{
|
||||
_port = ESPEasySerialPort::usb_hw_cdc;
|
||||
_config.port = ESPEasySerialPort::usb_hw_cdc;
|
||||
}
|
||||
|
||||
void ESPEasySerial_USB_WHCDC_t::begin(unsigned long baud)
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USB_HWCDC_H
|
||||
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USB_HWCDC_H
|
||||
|
||||
#include "../ESPEasySerial_common_defines.h"
|
||||
|
||||
#if USES_HWCDC
|
||||
|
||||
// ESP32C3/S3 embedded USB using JTAG interface
|
||||
# include <HWCDC.h>
|
||||
# include "ESPEasySerial_Port_base.h"
|
||||
|
||||
|
||||
class ESPEasySerial_USB_WHCDC_t : public ESPEasySerial_Port_base {
|
||||
public:
|
||||
|
||||
ESPEasySerial_USB_WHCDC_t();
|
||||
|
||||
virtual ~ESPEasySerial_USB_WHCDC_t() {}
|
||||
|
||||
void begin(unsigned long baud);
|
||||
|
||||
void end();
|
||||
int available(void);
|
||||
int availableForWrite(void);
|
||||
int peek(void);
|
||||
int read(void);
|
||||
size_t read(uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
void flush(void);
|
||||
void flush(bool txOnly);
|
||||
size_t write(uint8_t);
|
||||
size_t write(const uint8_t *buffer,
|
||||
size_t size);
|
||||
|
||||
operator bool() const;
|
||||
|
||||
void setDebugOutput(bool);
|
||||
|
||||
size_t setRxBufferSize(size_t new_size);
|
||||
size_t setTxBufferSize(size_t new_size);
|
||||
};
|
||||
|
||||
|
||||
#endif // if USES_HWCDC
|
||||
|
||||
|
||||
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USB_HWCDC_H
|
||||
Reference in New Issue
Block a user