[ESPEasySerial] Refactor file names to clarify their use

This commit is contained in:
TD-er
2023-05-23 10:49:18 +02:00
parent 1898f00196
commit df92588b1b
34 changed files with 658 additions and 603 deletions
+1 -1
View File
@@ -10411,7 +10411,7 @@ Gijs Noorlander (7):
[MQTT] LWT "Connected" message doesn't have the retained flag (#925)
[v2.0] Added Vcc-binaries to deploy process #933 (#935)
[v2.0 merge] 2kwebserver_merge_to_mega #929 (#934)
[v2.0] Use ESPeasySoftwareSerial (#936)
[v2.0] Use Driver_ESPEasySoftwareSerial_t (#936)
[Mega] rename SoftwareSerial lib #930 (#937)
[timeouts] Improve response when hosts are not reachable (#939)
[2k Webserver] Proper initialisation of StreamingBuffer members. (#941)
@@ -1,4 +1,4 @@
#include <ESPEasySC16IS752_Serial.h>
#include <Driver_ESPEasySC16IS752_Serial.h>
#ifndef DISABLE_SC16IS752_Serial
@@ -1,5 +1,5 @@
#ifndef ESPeasySC16IS752_Serial_h
#define ESPeasySC16IS752_Serial_h
#ifndef ESPEASYSERIAL_DRIVER_ESPEASYSC16IS752_SERIAL_H
#define ESPEASYSERIAL_DRIVER_ESPEASYSC16IS752_SERIAL_H
#ifndef DISABLE_SC16IS752_Serial
#include <inttypes.h>
@@ -44,4 +44,4 @@ private:
#endif
#endif // ESPeasySC16IS752_Serial_h
#endif // ESPEASYSERIAL_DRIVER_ESPEASYSC16IS752_SERIAL_H
@@ -1,4 +1,4 @@
#include "ESPEasySerial_USB.h"
#include "Driver_ESPEasySerial_USB.h"
#ifdef ESP32
@@ -21,12 +21,14 @@ HWCDC *_hwcdc_serial = &Serial;
HWCDC *_hwcdc_serial = &USBSerial;
# endif // if ARDUINO_USB_CDC_ON_BOOT
# else // No ARDUINO_USB_MODE
/*
# if ARDUINO_USB_CDC_ON_BOOT// Serial used for USB CDC
USBCDC *_usbcdc_serial = &Serial;
# else // if ARDUINO_USB_CDC_ON_BOOT
USBCDC _usbcdc_serial_stack_allocated;
USBCDC *_usbcdc_serial = &_usbcdc_serial_stack_allocated;
# endif // if ARDUINO_USB_CDC_ON_BOOT
*/
# endif // ARDUINO_USB_MODE
# endif // ifdef USE_USB_CDC_CONSOLE
# endif // if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
@@ -11,11 +11,11 @@
#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
@@ -1,6 +1,6 @@
/*
ESPeasySoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266.
Driver_ESPEasySoftwareSerial_t.cpp - Implementation of the Arduino software serial for ESP8266.
Copyright (c) 2015-2016 Peter Lerup. All rights reserved.
This library is free software; you can redistribute it and/or
@@ -32,7 +32,7 @@ extern "C" {
#define IRAM_ATTR ICACHE_RAM_ATTR
#endif
#include <ESPEasySoftwareSerial.h>
#include <Driver_ESPEasySoftwareSerial.h>
#define MAX_PIN 16
#define USABLE_PINS 10
@@ -40,7 +40,7 @@ extern "C" {
// As the Arduino attachInterrupt has no parameter, lists of objects
// and callbacks corresponding to each possible GPIO pins have to be defined
static ESPeasySoftwareSerial *ObjList[NR_CONCURRENT_SOFT_SERIALS];
static Driver_ESPEasySoftwareSerial_t *ObjList[NR_CONCURRENT_SOFT_SERIALS];
static uint8_t PinControllerMap[NR_CONCURRENT_SOFT_SERIALS]={}; // Zero all elements
void IRAM_ATTR espeasy_sws_isr_0() { ObjList[0]->rxRead(); };
@@ -71,7 +71,7 @@ static void (*ISRList[NR_CONCURRENT_SOFT_SERIALS])() = {
*/
};
ESPeasySoftwareSerial::ESPeasySoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic, uint16_t buffSize) {
Driver_ESPEasySoftwareSerial_t::Driver_ESPEasySoftwareSerial_t(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic, uint16_t buffSize) {
m_rxValid = m_txValid = m_txEnableValid = false;
m_buffer = NULL;
m_invert = inverse_logic;
@@ -107,7 +107,7 @@ ESPeasySoftwareSerial::ESPeasySoftwareSerial(uint8_t receivePin, uint8_t transmi
begin(9600);
}
ESPeasySoftwareSerial::~ESPeasySoftwareSerial() {
Driver_ESPEasySoftwareSerial_t::~Driver_ESPEasySoftwareSerial_t() {
enableRx(false);
if (m_rxValid) {
@@ -124,7 +124,7 @@ ESPeasySoftwareSerial::~ESPeasySoftwareSerial() {
}
}
bool ESPeasySoftwareSerial::isValidGPIOpin(uint8_t pin) {
bool Driver_ESPEasySoftwareSerial_t::isValidGPIOpin(uint8_t pin) {
if ((pin >= 0) && (pin <= 5)) {
return true;
}
@@ -135,7 +135,7 @@ bool ESPeasySoftwareSerial::isValidGPIOpin(uint8_t pin) {
return false;
}
uint8_t ESPeasySoftwareSerial::pinToIndex(uint8_t pin) {
uint8_t Driver_ESPEasySoftwareSerial_t::pinToIndex(uint8_t pin) {
// Pin will be stored in the map, only "1" will be added,
// to allow simple initialize to 0 and still use GPIO-0.
const uint8_t stored_pin = pin + 1;
@@ -156,7 +156,7 @@ uint8_t ESPeasySoftwareSerial::pinToIndex(uint8_t pin) {
return NR_CONCURRENT_SOFT_SERIALS;
}
void ESPeasySoftwareSerial::begin(long speed) {
void Driver_ESPEasySoftwareSerial_t::begin(long speed) {
// Use getCycleCount() loop to get as exact timing as possible
m_bitTime = ESP.getCpuFreqMHz() * 1000000 / speed;
@@ -165,7 +165,7 @@ void ESPeasySoftwareSerial::begin(long speed) {
}
}
void ESPeasySoftwareSerial::setTransmitEnablePin(uint8_t transmitEnablePin) {
void Driver_ESPEasySoftwareSerial_t::setTransmitEnablePin(uint8_t transmitEnablePin) {
if (isValidGPIOpin(transmitEnablePin)) {
m_txEnableValid = true;
m_txEnablePin = transmitEnablePin;
@@ -176,7 +176,7 @@ void ESPeasySoftwareSerial::setTransmitEnablePin(uint8_t transmitEnablePin) {
}
}
void ESPeasySoftwareSerial::enableRx(bool on) {
void Driver_ESPEasySoftwareSerial_t::enableRx(bool on) {
if (m_rxValid) {
if (on) {
attachInterrupt(m_rxPin, ISRList[pinToIndex(m_rxPin)], m_invert ? RISING : FALLING);
@@ -187,14 +187,14 @@ void ESPeasySoftwareSerial::enableRx(bool on) {
}
}
int ESPeasySoftwareSerial::read() {
int Driver_ESPEasySoftwareSerial_t::read() {
if (!m_rxValid || (m_inPos == m_outPos)) { return -1; }
uint8_t ch = m_buffer[m_outPos];
m_outPos = (m_outPos + 1) % m_buffSize;
return ch;
}
int ESPeasySoftwareSerial::available() {
int Driver_ESPEasySoftwareSerial_t::available() {
if (!m_rxValid) { return 0; }
int avail = m_inPos - m_outPos;
@@ -204,7 +204,7 @@ int ESPeasySoftwareSerial::available() {
#define WAIT { while (ESP.getCycleCount() - start < wait); wait += m_bitTime; }
size_t ESPeasySoftwareSerial::write(uint8_t b) {
size_t Driver_ESPEasySoftwareSerial_t::write(uint8_t b) {
if (!m_txValid) { return 0; }
if (m_invert) { b = ~b; }
@@ -236,16 +236,16 @@ size_t ESPeasySoftwareSerial::write(uint8_t b) {
return 1;
}
void ESPeasySoftwareSerial::flush() {
void Driver_ESPEasySoftwareSerial_t::flush() {
m_inPos = m_outPos = 0;
}
int ESPeasySoftwareSerial::peek() {
int Driver_ESPEasySoftwareSerial_t::peek() {
if (!m_rxValid || (m_inPos == m_outPos)) { return -1; }
return m_buffer[m_outPos];
}
void IRAM_ATTR ESPeasySoftwareSerial::rxRead() {
void IRAM_ATTR Driver_ESPEasySoftwareSerial_t::rxRead() {
// Advance the starting point for the samples but compensate for the
// initial delay which occurs before the interrupt is delivered
unsigned long wait = m_bitTime + m_bitTime / 3 - 500;
@@ -1,7 +1,7 @@
/*
ESPeasySoftwareSerial.h
Driver_ESPEasySoftwareSerial_t.h
ESPeasySoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266.
Driver_ESPEasySoftwareSerial_t.cpp - Implementation of the Arduino software serial for ESP8266.
Copyright (c) 2015-2016 Peter Lerup. All rights reserved.
This library is free software; you can redistribute it and/or
@@ -20,8 +20,8 @@
*/
#ifdef ESP8266 // Needed for precompile issues.
#ifndef ESPeasySoftwareSerial_h
# define ESPeasySoftwareSerial_h
#ifndef ESPEASYSERIAL_DRIVER_ESPEASYSOFTWARESERIAL_H
# define ESPEASYSERIAL_DRIVER_ESPEASYSOFTWARESERIAL_H
# include <inttypes.h>
# include <Stream.h>
@@ -32,14 +32,14 @@
// Speed up to 115200 can be used.
class ESPeasySoftwareSerial : public Stream {
class Driver_ESPEasySoftwareSerial_t : public Stream {
public:
ESPeasySoftwareSerial(uint8_t receivePin,
Driver_ESPEasySoftwareSerial_t(uint8_t receivePin,
uint8_t transmitPin,
bool inverse_logic = false,
uint16_t buffSize = 64);
virtual ~ESPeasySoftwareSerial();
virtual ~Driver_ESPEasySoftwareSerial_t();
void begin(long speed);
void setTransmitEnablePin(uint8_t transmitEnablePin);
@@ -98,5 +98,5 @@ private:
# define SW_SERIAL_UNUSED_PIN -1
#endif // ifndef ESPeasySoftwareSerial_h
#endif // ifndef ESPEASYSERIAL_DRIVER_ESPEASYSOFTWARESERIAL_H
#endif // ifdef ESP8266
+56 -50
View File
@@ -1,44 +1,54 @@
#include <ESPeasySerial.h>
#include "ESPEasySerial_HardwareSerial.h"
#include "ESPEasySerial_I2C_SC16IS752.h"
#include "ESPEasySerial_SW_Serial.h"
#include "ESPEasySerial_USB_HWCDC.h"
#include "ESPEasySerial_USBCDC.h"
#include "Port_ESPEasySerial_HardwareSerial.h"
#if USES_I2C_SC16IS752
# include "Port_ESPEasySerial_I2C_SC16IS752.h"
#endif // if USES_I2C_SC16IS752
#if USES_SW_SERIAL
# include "Port_ESPEasySerial_SW_Serial.h"
#endif // if USES_SW_SERIAL
#if USES_HWCDC
# include "Port_ESPEasySerial_USB_HWCDC.h"
#endif // if USES_HWCDC
#if USES_USBCDC
# include "Port_ESPEasySerial_USBCDC.h"
#endif // if USES_USBCDC
ESPEasySerial_Port_base* ESPeasySerial::ESPEasySerial_Port_factory(const ESPEasySerialConfig &config)
Port_ESPEasySerial_base * ESPeasySerial::ESPEasySerial_Port_factory(const ESPEasySerialConfig& config)
{
switch (config.port) {
#if USES_SW_SERIAL
case ESPEasySerialPort::software:
{
return new (std::nothrow) ESPEasySerial_SW_Serial(config);
return new (std::nothrow) Port_ESPEasySerial_SW_Serial_t(config);
}
#endif
#endif // if USES_SW_SERIAL
#if USES_I2C_SC16IS752
case ESPEasySerialPort::sc16is752:
{
return new (std::nothrow) ESPEasySerial_I2C_SC16IS752(config);
return new (std::nothrow) Port_ESPEasySerial_I2C_SC16IS752_t(config);
}
#endif
#endif // if USES_I2C_SC16IS752
#if USES_HWCDC
case ESPEasySerialPort::usb_hw_cdc:
{
return new (std::nothrow) ESPEasySerial_USB_WHCDC_t(config);
return new (std::nothrow) Port_ESPEasySerial_USB_HWCDC_t(config);
}
#endif
#endif // if USES_HWCDC
#if USES_USBCDC
case ESPEasySerialPort::usb_cdc_0:
case ESPEasySerialPort::usb_cdc_1:
{
return new (std::nothrow) ESPEasySerial_USBCDC_t(config);
return new (std::nothrow) Port_ESPEasySerial_USBCDC_t(config);
}
#endif
#endif // if USES_USBCDC
default:
if (isHWserial(config.port)) {
ESPEasySerial_HardwareSerial_t* hw = new (std::nothrow) ESPEasySerial_HardwareSerial_t();
Port_ESPEasySerial_HardwareSerial_t *hw = new (std::nothrow) Port_ESPEasySerial_HardwareSerial_t();
if (hw != nullptr) {
hw->resetConfig(config);
return hw;
@@ -48,26 +58,23 @@ ESPEasySerial_Port_base* ESPeasySerial::ESPEasySerial_Port_factory(const ESPEasy
}
return nullptr;
}
ESPeasySerial::ESPeasySerial(ESPEasySerialPort port,
int receivePin,
int transmitPin,
bool inverse_logic,
unsigned int buffSize,
bool forceSWserial)
: Stream()
: Stream()
{
ESPEasySerialConfig config;
config.port = port;
config.receivePin = receivePin;
config.transmitPin = transmitPin;
config.port = port;
config.receivePin = receivePin;
config.transmitPin = transmitPin;
config.inverse_logic = inverse_logic;
config.buffSize = buffSize;
config.buffSize = buffSize;
config.forceSWserial = forceSWserial;
config.validate();
@@ -77,12 +84,10 @@ ESPeasySerial::ESPeasySerial(ESPEasySerialPort port,
// FIXME TD-er: Should it call begin() ???
if (_serialPort != nullptr) {
// _serialPort->begin(_baud);
// _serialPort->begin(_baud);
}
}
ESPeasySerial::~ESPeasySerial() {
flush();
end();
@@ -100,16 +105,17 @@ void ESPeasySerial::begin(unsigned long baud)
}
#ifdef ESP8266
void ESPeasySerial::begin(unsigned long baud,
SerialConfig config,
SerialMode mode)
void ESPeasySerial::begin(unsigned long baud,
SerialConfig config,
SerialMode mode)
{
if (isValid()) {
_serialPort->setPortConfig(baud, config, mode);
_serialPort->begin(baud);
}
}
#endif
#endif // ifdef ESP8266
#ifdef ESP32
void ESPeasySerial::begin(unsigned long baud, uint32_t config)
@@ -119,7 +125,8 @@ void ESPeasySerial::begin(unsigned long baud, uint32_t config)
_serialPort->begin(baud);
}
}
#endif
#endif // ifdef ESP32
void ESPeasySerial::end() {
@@ -129,7 +136,7 @@ void ESPeasySerial::end() {
}
}
int ESPeasySerial::peek(void)
int ESPeasySerial::peek(void)
{
if (!isValid()) {
return -1;
@@ -137,7 +144,7 @@ int ESPeasySerial::peek(void)
return _serialPort->peek();
}
size_t ESPeasySerial::write(uint8_t val)
size_t ESPeasySerial::write(uint8_t val)
{
if (!isValid()) {
return 0;
@@ -145,7 +152,7 @@ size_t ESPeasySerial::write(uint8_t val)
return _serialPort->write(val);
}
size_t ESPeasySerial::write(const uint8_t *buffer, size_t size)
size_t ESPeasySerial::write(const uint8_t *buffer, size_t size)
{
if (!isValid() || !buffer) {
return 0;
@@ -153,13 +160,13 @@ size_t ESPeasySerial::write(const uint8_t *buffer, size_t size)
return _serialPort->write(buffer, size);
}
size_t ESPeasySerial::write(const char *buffer)
size_t ESPeasySerial::write(const char *buffer)
{
if (!buffer) { return 0; }
return write(buffer, strlen_P(buffer));
}
int ESPeasySerial::read(void)
int ESPeasySerial::read(void)
{
if (!isValid()) {
return -1;
@@ -167,7 +174,7 @@ int ESPeasySerial::read(void)
return _serialPort->read();
}
int ESPeasySerial::available(void)
int ESPeasySerial::available(void)
{
if (!isValid()) {
return 0;
@@ -175,7 +182,7 @@ int ESPeasySerial::available(void)
return _serialPort->available();
}
int ESPeasySerial::availableForWrite(void)
int ESPeasySerial::availableForWrite(void)
{
if (!isValid()) {
return 0;
@@ -183,7 +190,7 @@ int ESPeasySerial::availableForWrite(void)
return _serialPort->availableForWrite();
}
void ESPeasySerial::flush(void)
void ESPeasySerial::flush(void)
{
if (isValid()) {
_serialPort->flush();
@@ -195,36 +202,38 @@ int ESPeasySerial::getBaudRate() const
if (!isValid()) {
return 0;
}
return getSerialConfig().baud;
return _serialPort->getBaudRate();
}
ESPeasySerial::operator bool() const
{
if (isValid())
if (isValid()) {
return _serialPort->operator bool();
}
return false;
}
bool ESPeasySerial::connected() const
{
if (isValid())
if (isValid()) {
return _serialPort->operator bool();
}
return false;
}
void ESPeasySerial::setDebugOutput(bool enable)
void ESPeasySerial::setDebugOutput(bool enable)
{
if (isValid()) {
_serialPort->setDebugOutput(enable);
}
}
bool ESPeasySerial::isTxEnabled(void)
bool ESPeasySerial::isTxEnabled(void)
{
return getTxPin() != -1;
}
bool ESPeasySerial::isRxEnabled(void)
bool ESPeasySerial::isRxEnabled(void)
{
return getRxPin() != -1;
}
@@ -235,14 +244,11 @@ bool ESPeasySerial::listen() {
return true;
}
String ESPeasySerial::getLogString() const {
return getSerialConfig().getLogString();
}
bool ESPeasySerial::isValid() const {
// FIXME TD-er: Must call isValid() on the individual _serialPort types
return _serialPort != nullptr;
}
}
+2 -2
View File
@@ -35,8 +35,8 @@ void ESPEasySerialConfig::setPortConfig(
#ifdef ESP32
void ESPEasySerialConfig::setPortConfig(
unsigned long baudrate,
uint32_t portconfig)
unsigned long baudrate,
uint32_t portconfig)
{
// FIXME TD-er: Must also set baudrate?
+18 -9
View File
@@ -6,26 +6,36 @@
#include "ESPEasySerialPort.h"
#if USES_I2C_SC16IS752
# include "ESPEasySC16IS752_Serial.h"
# include "Driver_ESPEasySC16IS752_Serial.h"
#endif // if USES_I2C_SC16IS752
#include <HardwareSerial.h>
struct ESPEasySerialConfig {
#ifdef ESP32
# include <soc/soc_caps.h>
#endif // ifdef ESP32
#ifdef ESP8266
# ifndef SOC_UART_FIFO_LEN
# define SOC_UART_FIFO_LEN 128
# endif // ifndef SOC_UART_FIFO_LEN
#endif // ifdef ESP8266
struct ESPEasySerialConfig {
ESPEasySerialConfig() = default;
void validate();
#ifdef ESP8266
void setPortConfig(unsigned long baud,
SerialConfig config,
SerialMode mode);
#endif
SerialConfig config,
SerialMode mode);
#endif // ifdef ESP8266
#ifdef ESP32
void setPortConfig(unsigned long baud, uint32_t config);
#endif
void setPortConfig(unsigned long baud,
uint32_t config);
#endif // ifdef ESP32
String getLogString() const;
@@ -56,9 +66,8 @@ struct ESPEasySerialConfig {
#ifdef ESP8266
SerialConfig config = SERIAL_8N1;
SerialMode mode = SERIAL_FULL;
SerialMode mode = SERIAL_FULL;
#endif // ifdef ESP8266
};
+5 -5
View File
@@ -11,9 +11,9 @@ const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort port)
case ESPEasySerialPort::serial0_swap: return F("HW Serial0 swap");
#endif // ifdef ESP8266
case ESPEasySerialPort::serial0: return F("HW Serial0");
# if SOC_UART_NUM > 1
#if SOC_UART_NUM > 1
case ESPEasySerialPort::serial1: return F("HW Serial1");
#endif
#endif // if SOC_UART_NUM > 1
#if SOC_UART_NUM > 2
case ESPEasySerialPort::serial2: return F("HW Serial2");
#endif // if SOC_UART_NUM > 2
@@ -44,7 +44,7 @@ bool isHWserial(ESPEasySerialPort port)
case ESPEasySerialPort::serial0:
#if SOC_UART_NUM > 1
case ESPEasySerialPort::serial1:
#endif
#endif // if SOC_UART_NUM > 1
#if SOC_UART_NUM > 2
case ESPEasySerialPort::serial2:
#endif // if SOC_UART_NUM > 2
@@ -64,7 +64,7 @@ bool useGPIOpins(ESPEasySerialPort port)
#endif // ifdef ESP8266
#if SOC_UART_NUM > 1
case ESPEasySerialPort::serial1:
#endif
#endif // if SOC_UART_NUM > 1
#if SOC_UART_NUM > 2
case ESPEasySerialPort::serial2:
#endif // if SOC_UART_NUM > 2
@@ -91,7 +91,7 @@ bool validSerialPort(ESPEasySerialPort port)
#endif // ifdef ESP8266
#if SOC_UART_NUM > 1
case ESPEasySerialPort::serial1:
#endif
#endif // if SOC_UART_NUM > 1
#if SOC_UART_NUM > 2
case ESPEasySerialPort::serial2:
#endif // if SOC_UART_NUM > 2
+1 -1
View File
@@ -16,7 +16,7 @@ enum class ESPEasySerialPort : uint8_t {
#endif // ifdef ESP8266
#if SOC_UART_NUM > 1
serial1 = 4,
#endif
#endif // if SOC_UART_NUM > 1
#if SOC_UART_NUM > 2
serial2 = 5,
#endif // if SOC_UART_NUM > 2
+8 -8
View File
@@ -5,9 +5,9 @@
#ifdef ESP32
#ifndef SOC_UART_FIFO_LEN
#define SOC_UART_FIFO_LEN (128)
#endif
# ifndef SOC_UART_FIFO_LEN
# define SOC_UART_FIFO_LEN (128)
# endif // ifndef SOC_UART_FIFO_LEN
// Default pins taken from here:
@@ -61,7 +61,7 @@
# endif // if CONFIG_IDF_TARGET_ESP32
# endif // ifndef SOC_TX1
# endif // if SOC_UART_NUM > 1
# endif // if SOC_UART_NUM > 1
# if SOC_UART_NUM > 2
@@ -70,7 +70,7 @@
# define SOC_RX2 16
# elif CONFIG_IDF_TARGET_ESP32S3
# define SOC_RX2 19
# else
# else // if CONFIG_IDF_TARGET_ESP32
# define SOC_RX2 -1
# endif // if CONFIG_IDF_TARGET_ESP32
# endif // ifndef SOC_RX2
@@ -80,14 +80,14 @@
# define SOC_TX2 17
# elif CONFIG_IDF_TARGET_ESP32S3
# define SOC_TX2 20
# else
# else // if CONFIG_IDF_TARGET_ESP32
# define SOC_TX2 -1
# endif // if CONFIG_IDF_TARGET_ESP32
# endif // ifndef SOC_TX2
# endif // if SOC_UART_NUM > 2
# endif // if SOC_UART_NUM > 2
#endif
#endif // ifdef ESP32
struct ESPeasySerialType {
static bool getSerialTypePins(ESPEasySerialPort serType,
@@ -18,7 +18,7 @@ bool ESPeasySerialType::getSerialTypePins(ESPEasySerialPort serType, int& rxPin,
# endif // if SOC_UART_NUM > 2
# if USES_I2C_SC16IS752
case ESPEasySerialPort::sc16is752: return true;
# endif
# endif // if USES_I2C_SC16IS752
default:
break;
+10 -10
View File
@@ -14,12 +14,12 @@ bool ESPeasySerialType::getSerialTypePins(ESPEasySerialPort serType, int& rxPin,
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
# if USES_SW_SERIAL
case ESPEasySerialPort::software: rxPin = 14; txPin = 12; return true;
#endif
#if USES_I2C_SC16IS752
# endif // if USES_SW_SERIAL
# if USES_I2C_SC16IS752
case ESPEasySerialPort::sc16is752: return true;
#endif // ifndef DISABLE_SC16IS752_Serial
# endif // ifndef DISABLE_SC16IS752_Serial
default:
break;
@@ -27,7 +27,6 @@ bool ESPeasySerialType::getSerialTypePins(ESPEasySerialPort serType, int& rxPin,
return false;
}
ESPEasySerialPort ESPeasySerialType::getSerialType(ESPEasySerialPort typeHint, int receivePin, int transmitPin) {
if (typeHint != ESPEasySerialPort::not_set) {
return typeHint;
@@ -48,21 +47,22 @@ ESPEasySerialPort ESPeasySerialType::getSerialType(ESPEasySerialPort typeHint, i
// it's RX pin is occupied for flash chip connection.
return ESPEasySerialPort::serial1;
}
#if USES_I2C_SC16IS752
# if USES_I2C_SC16IS752
if ((receivePin >= 0x48) && (receivePin <= 0x57)) {
return ESPEasySerialPort::sc16is752; // I2C address range of SC16IS752
}
#endif
# endif // if USES_I2C_SC16IS752
if ((receivePin == -1) && (transmitPin == -1)) {
// No pins set, so no serial type
return ESPEasySerialPort::MAX_SERIAL_TYPE;
}
#if USES_SW_SERIAL
# if USES_SW_SERIAL
return ESPEasySerialPort::software;
#else
# else // if USES_SW_SERIAL
return ESPEasySerialPort::MAX_SERIAL_TYPE;
#endif
# endif // if USES_SW_SERIAL
}
#endif // ESP8266
@@ -1,134 +0,0 @@
#include "ESPEasySerial_I2C_SC16IS752.h"
#if USES_I2C_SC16IS752
ESPEasySerial_I2C_SC16IS752::ESPEasySerial_I2C_SC16IS752(const ESPEasySerialConfig & config)
{
if (config.port == ESPEasySerialPort::sc16is752) {
ESPEasySC16IS752_Serial::I2C_address addr;
ESPEasySC16IS752_Serial::SC16IS752_channel ch;
if (config.getI2C_SC16IS752_Parameters(addr, ch)) {
_config = config;
_i2cserial = new ESPEasySC16IS752_Serial(addr, ch);
}
}
}
ESPEasySerial_I2C_SC16IS752::~ESPEasySerial_I2C_SC16IS752()
{
if (_i2cserial != nullptr) {
delete _i2cserial;
_i2cserial = nullptr;
}
}
void ESPEasySerial_I2C_SC16IS752::begin(unsigned long baud)
{
if (_i2cserial != nullptr) {
_i2cserial->begin(baud);
}
}
void ESPEasySerial_I2C_SC16IS752::end() {
if (_i2cserial != nullptr) {
_i2cserial->end();
}
}
int ESPEasySerial_I2C_SC16IS752::available(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->available();
}
return 0;
}
int ESPEasySerial_I2C_SC16IS752::availableForWrite(void)
{
if (_i2cserial != nullptr) {
// FIXME TD-er: Implement availableForWrite
return 4; // _i2cserial->availableForWrite();
}
return 0;
}
int ESPEasySerial_I2C_SC16IS752::peek(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->peek();
}
return 0;
}
int ESPEasySerial_I2C_SC16IS752::read(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->read();
}
return 0;
}
size_t ESPEasySerial_I2C_SC16IS752::read(uint8_t *buffer,
size_t size)
{
if (_i2cserial != nullptr) {
return _i2cserial->readBytes((char *)buffer, size);
}
return 0;
}
void ESPEasySerial_I2C_SC16IS752::flush(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->flush();
}
}
void ESPEasySerial_I2C_SC16IS752::flush(bool txOnly)
{
flush();
}
size_t ESPEasySerial_I2C_SC16IS752::write(uint8_t value)
{
if (_i2cserial != nullptr) {
return _i2cserial->write(value);
}
return 0;
}
size_t ESPEasySerial_I2C_SC16IS752::write(const uint8_t *buffer,
size_t size)
{
if (_i2cserial != nullptr) {
return _i2cserial->write(buffer, size);
}
return 0;
}
ESPEasySerial_I2C_SC16IS752::operator bool() const
{
return _i2cserial != nullptr;
}
void ESPEasySerial_I2C_SC16IS752::setDebugOutput(bool) {}
size_t ESPEasySerial_I2C_SC16IS752::setRxBufferSize(size_t new_size)
{
if (_i2cserial != nullptr) {
return 64;
}
return 0;
}
size_t ESPEasySerial_I2C_SC16IS752::setTxBufferSize(size_t new_size)
{
if (_i2cserial != nullptr) {
return 64;
}
return 0;
}
#endif // ifndef DISABLE_SC16IS752_Serial
@@ -1,5 +0,0 @@
#include "ESPEasySerial_Port_base.h"
ESPEasySerial_Port_base::ESPEasySerial_Port_base() {}
ESPEasySerial_Port_base::~ESPEasySerial_Port_base() {}
@@ -1,133 +0,0 @@
#include "ESPEasySerial_SW_Serial.h"
#if USES_SW_SERIAL
ESPEasySerial_SW_Serial::ESPEasySerial_SW_Serial(const ESPEasySerialConfig & config)
{
if (config.port == ESPEasySerialPort::software) {
_config = config;
_swserial = new ESPeasySoftwareSerial(
config.receivePin,
config.transmitPin,
config.inverse_logic);
}
}
ESPEasySerial_SW_Serial::~ESPEasySerial_SW_Serial()
{
if (_swserial != nullptr) {
delete _swserial;
_swserial = nullptr;
}
}
void ESPEasySerial_SW_Serial::begin(unsigned long baud)
{
if (_swserial != nullptr) {
_swserial->begin(baud);
}
}
void ESPEasySerial_SW_Serial::end() {
if (_swserial != nullptr) {
_swserial->end();
}
}
int ESPEasySerial_SW_Serial::available(void)
{
if (_swserial != nullptr) {
return _swserial->available();
}
return 0;
}
int ESPEasySerial_SW_Serial::availableForWrite(void)
{
if (_swserial != nullptr) {
// FIXME TD-er: Implement availableForWrite
return 1; // return _swserial->availableForWrite();
}
return 0;
}
int ESPEasySerial_SW_Serial::peek(void)
{
if (_swserial != nullptr) {
return _swserial->peek();
}
return 0;
}
int ESPEasySerial_SW_Serial::read(void)
{
if (_swserial != nullptr) {
return _swserial->read();
}
return 0;
}
size_t ESPEasySerial_SW_Serial::read(uint8_t *buffer,
size_t size)
{
if (_swserial != nullptr) {
return _swserial->readBytes((char *)buffer, size);
}
return 0;
}
void ESPEasySerial_SW_Serial::flush(void)
{
if (_swserial != nullptr) {
return _swserial->flush();
}
}
void ESPEasySerial_SW_Serial::flush(bool txOnly)
{
flush();
}
size_t ESPEasySerial_SW_Serial::write(uint8_t value)
{
if (_swserial != nullptr) {
return _swserial->write(value);
}
return 0;
}
size_t ESPEasySerial_SW_Serial::write(const uint8_t *buffer,
size_t size)
{
if (_swserial != nullptr) {
return _swserial->write(buffer, size);
}
return 0;
}
ESPEasySerial_SW_Serial::operator bool() const
{
return _swserial != nullptr;
}
void ESPEasySerial_SW_Serial::setDebugOutput(bool) {}
size_t ESPEasySerial_SW_Serial::setRxBufferSize(size_t new_size)
{
if (_swserial != nullptr) {
return 64;
}
return 0;
}
size_t ESPEasySerial_SW_Serial::setTxBufferSize(size_t new_size)
{
if (_swserial != nullptr) {
return 64;
}
return 0;
}
#endif // if USES_SW_SERIAL
@@ -13,7 +13,7 @@
# else // ifdef ESP8266
static_assert(false, "Implement processor architecture");
# endif // ifdef ESP8266
#endif
#endif // ifndef SOC_UART_NUM
#ifdef ESP32
@@ -33,45 +33,42 @@ static_assert(false, "Implement processor architecture");
# 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 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
#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_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(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(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 // ifndef 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 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
@@ -83,19 +80,19 @@ static_assert(false, "Implement processor architecture");
#ifndef USES_SW_SERIAL
#ifndef DISABLE_SOFTWARE_SERIAL
#define USES_SW_SERIAL 1
#else
#define USES_SW_SERIAL 0
#endif
#endif
# ifndef DISABLE_SOFTWARE_SERIAL
# define USES_SW_SERIAL 1
# else // ifndef DISABLE_SOFTWARE_SERIAL
# define USES_SW_SERIAL 0
# endif // ifndef DISABLE_SOFTWARE_SERIAL
#endif // ifndef USES_SW_SERIAL
#ifndef USES_I2C_SC16IS752
#ifndef DISABLE_SC16IS752_Serial
#define USES_I2C_SC16IS752 1
#else
#define USES_I2C_SC16IS752 0
#endif
#endif
# ifndef DISABLE_SC16IS752_Serial
# define USES_I2C_SC16IS752 1
# else // ifndef DISABLE_SC16IS752_Serial
# define USES_I2C_SC16IS752 0
# endif // ifndef DISABLE_SC16IS752_Serial
#endif // ifndef USES_I2C_SC16IS752
#endif
#endif // ifndef ESPEASYSERIAL_ESPEASYSERIAL_COMMON_DEFINES_H
+23 -21
View File
@@ -29,14 +29,14 @@
#include "ESPEasySerialPort.h"
#include "ESPEasySerialType.h"
#include "ESPEasySerial_Port_base.h"
#include "Port_ESPEasySerial_base.h"
#include <Stream.h>
class ESPeasySerial : public Stream {
public:
static ESPEasySerial_Port_base* ESPEasySerial_Port_factory(const ESPEasySerialConfig &config);
static Port_ESPEasySerial_base* ESPEasySerial_Port_factory(const ESPEasySerialConfig& config);
// ESP82xx has 2 HW serial ports and option for several software serial ports.
// Serial0: RX: 3 TX: 1
@@ -52,23 +52,24 @@ public:
virtual ~ESPeasySerial();
// Same parameters as the constructor, to allow to reconfigure the ESPEasySerial object to be another type of port.
void resetConfig(ESPEasySerialPort port,
int receivePin,
int transmitPin,
bool inverse_logic = false,
unsigned int buffSize = SOC_UART_FIFO_LEN,
bool forceSWserial = false);
void resetConfig(ESPEasySerialPort port,
int receivePin,
int transmitPin,
bool inverse_logic = false,
unsigned int buffSize = SOC_UART_FIFO_LEN,
bool forceSWserial = false);
// If baud rate is set to 0, it will perform an auto-detect on the baudrate
void begin(unsigned long baud);
#ifdef ESP8266
void begin(unsigned long baud,
SerialConfig config,
SerialMode mode = SERIAL_FULL);
#endif
SerialMode mode = SERIAL_FULL);
#endif // ifdef ESP8266
#ifdef ESP32
void begin(unsigned long baud, uint32_t config);
#endif
void begin(unsigned long baud,
uint32_t config);
#endif // ifdef ESP32
void end();
int peek(void);
@@ -97,17 +98,17 @@ void begin(unsigned long baud, uint32_t config);
size_t write(const uint8_t *buffer,
size_t size);
size_t write(const char *buffer);
int getBaudRate() const;
int getBaudRate() const;
operator bool() const;
bool connected() const;
bool connected() const;
void setDebugOutput(bool);
void setDebugOutput(bool);
bool isTxEnabled(void);
bool isRxEnabled(void);
bool isTxEnabled(void);
bool isRxEnabled(void);
bool listen();
@@ -133,18 +134,19 @@ void begin(unsigned long baud, uint32_t config);
}
ESPEasySerialConfig getSerialConfig() const {
if (_serialPort != nullptr)
if (_serialPort != nullptr) {
return _serialPort->getSerialConfig();
}
ESPEasySerialConfig res;
return res;
}
private:
bool isValid() const;
ESPEasySerial_Port_base* _serialPort = nullptr;
bool isValid() const;
Port_ESPEasySerial_base *_serialPort = nullptr;
};
#endif // ifndef ESPeasySerial_h
@@ -1,4 +1,4 @@
#include "ESPEasySerial_HardwareSerial.h"
#include "Port_ESPEasySerial_HardwareSerial.h"
#include "ESPEasySerialType.h"
@@ -32,7 +32,7 @@ bool pinsChanged(ESPEasySerialPort port,
case ESPEasySerialPort::serial0: return receivePin != receivePin0 || transmitPin != transmitPin0;
# if SOC_UART_NUM > 1
case ESPEasySerialPort::serial1: return receivePin != receivePin1 || transmitPin != transmitPin1;
# endif
# endif // if SOC_UART_NUM > 1
# if SOC_UART_NUM > 2
case ESPEasySerialPort::serial2: return receivePin != receivePin2 || transmitPin != transmitPin2;
# endif // if SOC_UART_NUM > 2
@@ -57,7 +57,7 @@ void setPinsCache(ESPEasySerialPort port,
receivePin1 = receivePin;
transmitPin1 = transmitPin;
break;
#endif
# endif // if SOC_UART_NUM > 1
# if SOC_UART_NUM > 2
case ESPEasySerialPort::serial2:
@@ -74,23 +74,25 @@ void setPinsCache(ESPEasySerialPort port,
#endif // ifdef ESP32
ESPEasySerial_HardwareSerial_t::ESPEasySerial_HardwareSerial_t() {}
ESPEasySerial_HardwareSerial_t::~ESPEasySerial_HardwareSerial_t() {}
Port_ESPEasySerial_HardwareSerial_t::Port_ESPEasySerial_HardwareSerial_t() {}
void ESPEasySerial_HardwareSerial_t::resetConfig(const ESPEasySerialConfig & config)
Port_ESPEasySerial_HardwareSerial_t::~Port_ESPEasySerial_HardwareSerial_t() {}
void Port_ESPEasySerial_HardwareSerial_t::resetConfig(const ESPEasySerialConfig& config)
{
if (!isHWserial(config.port)) return;
if (!isHWserial(config.port)) { return; }
/*
if (_config == config) return;
if (_config == config) return;
// First call end()
// Then create new instance.
// First call end()
// Then create new instance.
_config.receivePin = receivePin;
_config.transmitPin = transmitPin;
_config.inverse_logic = inverse_logic;
_config.buffSize = buffSize;
*/
_config.receivePin = receivePin;
_config.transmitPin = transmitPin;
_config.inverse_logic = inverse_logic;
_config.buffSize = buffSize;
*/
_config = config;
@@ -99,7 +101,7 @@ void ESPEasySerial_HardwareSerial_t::resetConfig(const ESPEasySerialConfig & con
case ESPEasySerialPort::serial0:
#if SOC_UART_NUM > 1
case ESPEasySerialPort::serial1:
#endif
#endif // if SOC_UART_NUM > 1
#if SOC_UART_NUM > 2
case ESPEasySerialPort::serial2:
#endif // if SOC_UART_NUM > 2
@@ -122,7 +124,7 @@ void ESPEasySerial_HardwareSerial_t::resetConfig(const ESPEasySerialConfig & con
#if SOC_UART_NUM > 1
} else if (_config.port == ESPEasySerialPort::serial1) {
_serial = &Serial1;
#endif
#endif // if SOC_UART_NUM > 1
#if SOC_UART_NUM > 2
} else if (_config.port == ESPEasySerialPort::serial2) {
_serial = &Serial2;
@@ -132,9 +134,8 @@ void ESPEasySerial_HardwareSerial_t::resetConfig(const ESPEasySerialConfig & con
}
}
#ifdef ESP8266
void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
void Port_ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
{
if (_serial == nullptr) {
_config.baud = 0;
@@ -168,7 +169,7 @@ void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
#endif // ifdef ESP8266
#ifdef ESP32
void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
void Port_ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
{
if (_serial == nullptr) {
_config.baud = 0;
@@ -188,6 +189,10 @@ void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
_serial->end();
delay(10);
if (_config.buffSize > 256) {
_config.buffSize = _serial->setRxBufferSize(_config.buffSize);
}
_serial->begin(baud, _config.config, _config.receivePin, _config.transmitPin, _config.inverse_logic);
_serial->flush();
}
@@ -195,7 +200,7 @@ void ESPEasySerial_HardwareSerial_t::begin(unsigned long baud)
#endif // ifdef ESP32
void ESPEasySerial_HardwareSerial_t::end() {
void Port_ESPEasySerial_HardwareSerial_t::end() {
if (_serial != nullptr) {
_serial->end();
@@ -203,7 +208,7 @@ void ESPEasySerial_HardwareSerial_t::end() {
}
}
int ESPEasySerial_HardwareSerial_t::available(void)
int Port_ESPEasySerial_HardwareSerial_t::available(void)
{
if (_serial != nullptr) {
return _serial->available();
@@ -211,7 +216,7 @@ int ESPEasySerial_HardwareSerial_t::available(void)
return 0;
}
int ESPEasySerial_HardwareSerial_t::availableForWrite(void)
int Port_ESPEasySerial_HardwareSerial_t::availableForWrite(void)
{
if (_serial != nullptr) {
return _serial->availableForWrite();
@@ -219,7 +224,7 @@ int ESPEasySerial_HardwareSerial_t::availableForWrite(void)
return 0;
}
int ESPEasySerial_HardwareSerial_t::peek(void)
int Port_ESPEasySerial_HardwareSerial_t::peek(void)
{
if (_serial != nullptr) {
return _serial->peek();
@@ -227,7 +232,7 @@ int ESPEasySerial_HardwareSerial_t::peek(void)
return 0;
}
int ESPEasySerial_HardwareSerial_t::read(void)
int Port_ESPEasySerial_HardwareSerial_t::read(void)
{
if (_serial != nullptr) {
return _serial->read();
@@ -235,8 +240,8 @@ int ESPEasySerial_HardwareSerial_t::read(void)
return 0;
}
size_t ESPEasySerial_HardwareSerial_t::read(uint8_t *buffer,
size_t size)
size_t Port_ESPEasySerial_HardwareSerial_t::read(uint8_t *buffer,
size_t size)
{
if (_serial != nullptr) {
#ifdef ESP32
@@ -249,14 +254,14 @@ size_t ESPEasySerial_HardwareSerial_t::read(uint8_t *buffer,
return 0;
}
void ESPEasySerial_HardwareSerial_t::flush(void)
void Port_ESPEasySerial_HardwareSerial_t::flush(void)
{
if (_serial != nullptr) {
_serial->flush();
}
}
void ESPEasySerial_HardwareSerial_t::flush(bool txOnly)
void Port_ESPEasySerial_HardwareSerial_t::flush(bool txOnly)
{
if (_serial != nullptr) {
#ifdef ESP32
@@ -268,7 +273,7 @@ void ESPEasySerial_HardwareSerial_t::flush(bool txOnly)
}
}
size_t ESPEasySerial_HardwareSerial_t::write(uint8_t value)
size_t Port_ESPEasySerial_HardwareSerial_t::write(uint8_t value)
{
if (_serial != nullptr) {
return _serial->write(value);
@@ -276,8 +281,8 @@ size_t ESPEasySerial_HardwareSerial_t::write(uint8_t value)
return 0;
}
size_t ESPEasySerial_HardwareSerial_t::write(const uint8_t *buffer,
size_t size)
size_t Port_ESPEasySerial_HardwareSerial_t::write(const uint8_t *buffer,
size_t size)
{
if (_serial != nullptr) {
return _serial->write(buffer, size);
@@ -285,20 +290,29 @@ size_t ESPEasySerial_HardwareSerial_t::write(const uint8_t *buffer,
return 0;
}
ESPEasySerial_HardwareSerial_t::operator bool() const
int Port_ESPEasySerial_HardwareSerial_t::getBaudRate() const
{
if (_serial != nullptr)
if (_serial != nullptr) {
return _serial->baudRate();
}
return 0;
}
Port_ESPEasySerial_HardwareSerial_t::operator bool() const
{
if (_serial != nullptr) {
return _serial->operator bool();
}
return false;
}
void ESPEasySerial_HardwareSerial_t::setDebugOutput(bool enabled) {
void Port_ESPEasySerial_HardwareSerial_t::setDebugOutput(bool enabled) {
if (_serial != nullptr) {
return _serial->setDebugOutput(enabled);
}
}
size_t ESPEasySerial_HardwareSerial_t::setRxBufferSize(size_t new_size)
size_t Port_ESPEasySerial_HardwareSerial_t::setRxBufferSize(size_t new_size)
{
if (_serial != nullptr) {
return _serial->setRxBufferSize(new_size);
@@ -306,7 +320,7 @@ size_t ESPEasySerial_HardwareSerial_t::setRxBufferSize(size_t new_size)
return 0;
}
size_t ESPEasySerial_HardwareSerial_t::setTxBufferSize(size_t new_size)
size_t Port_ESPEasySerial_HardwareSerial_t::setTxBufferSize(size_t new_size)
{
if (_serial != nullptr) {
#ifdef ESP32
@@ -3,7 +3,7 @@
#include "ESPEasySerial_common_defines.h"
#include "ESPEasySerial_Port_base.h"
#include "Port_ESPEasySerial_base.h"
#include <HardwareSerial.h>
@@ -11,17 +11,17 @@
# include <esp32-hal-uart.h>
#endif // ifdef ESP32
class ESPEasySerial_HardwareSerial_t : public ESPEasySerial_Port_base {
class Port_ESPEasySerial_HardwareSerial_t : public Port_ESPEasySerial_base {
public:
ESPEasySerial_HardwareSerial_t();
Port_ESPEasySerial_HardwareSerial_t();
~ESPEasySerial_HardwareSerial_t();
~Port_ESPEasySerial_HardwareSerial_t();
// Allow for resetConfig, instead of end() and begin().
// This can otherwise cause issues with some sensors when starting/stopping an ESPEasy task
void resetConfig(const ESPEasySerialConfig & config);
void resetConfig(const ESPEasySerialConfig& config);
void begin(unsigned long baud);
@@ -39,6 +39,7 @@ public:
size_t write(const uint8_t *buffer,
size_t size);
int getBaudRate() const override;
operator bool() const;
void setDebugOutput(bool);
@@ -0,0 +1,136 @@
#include "Port_ESPEasySerial_I2C_SC16IS752.h"
#if USES_I2C_SC16IS752
Port_ESPEasySerial_I2C_SC16IS752_t::Port_ESPEasySerial_I2C_SC16IS752_t(const ESPEasySerialConfig& config)
{
if (config.port == ESPEasySerialPort::sc16is752) {
ESPEasySC16IS752_Serial::I2C_address addr;
ESPEasySC16IS752_Serial::SC16IS752_channel ch;
if (config.getI2C_SC16IS752_Parameters(addr, ch)) {
_config = config;
_config.buffSize = 64; // Fixed size
_i2cserial = new (std::nothrow) ESPEasySC16IS752_Serial(addr, ch);
}
}
}
Port_ESPEasySerial_I2C_SC16IS752_t::~Port_ESPEasySerial_I2C_SC16IS752_t()
{
if (_i2cserial != nullptr) {
delete _i2cserial;
_i2cserial = nullptr;
}
}
void Port_ESPEasySerial_I2C_SC16IS752_t::begin(unsigned long baud)
{
if (_i2cserial != nullptr) {
_i2cserial->begin(baud);
}
}
void Port_ESPEasySerial_I2C_SC16IS752_t::end() {
if (_i2cserial != nullptr) {
_i2cserial->end();
}
}
int Port_ESPEasySerial_I2C_SC16IS752_t::available(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->available();
}
return 0;
}
int Port_ESPEasySerial_I2C_SC16IS752_t::availableForWrite(void)
{
if (_i2cserial != nullptr) {
// FIXME TD-er: Implement availableForWrite
return 4; // _i2cserial->availableForWrite();
}
return 0;
}
int Port_ESPEasySerial_I2C_SC16IS752_t::peek(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->peek();
}
return 0;
}
int Port_ESPEasySerial_I2C_SC16IS752_t::read(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->read();
}
return 0;
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::read(uint8_t *buffer,
size_t size)
{
if (_i2cserial != nullptr) {
return _i2cserial->readBytes((char *)buffer, size);
}
return 0;
}
void Port_ESPEasySerial_I2C_SC16IS752_t::flush(void)
{
if (_i2cserial != nullptr) {
return _i2cserial->flush();
}
}
void Port_ESPEasySerial_I2C_SC16IS752_t::flush(bool txOnly)
{
flush();
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::write(uint8_t value)
{
if (_i2cserial != nullptr) {
return _i2cserial->write(value);
}
return 0;
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::write(const uint8_t *buffer,
size_t size)
{
if (_i2cserial != nullptr) {
return _i2cserial->write(buffer, size);
}
return 0;
}
Port_ESPEasySerial_I2C_SC16IS752_t::operator bool() const
{
return _i2cserial != nullptr;
}
void Port_ESPEasySerial_I2C_SC16IS752_t::setDebugOutput(bool) {}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::setRxBufferSize(size_t new_size)
{
if (_i2cserial != nullptr) {
return 64;
}
return 0;
}
size_t Port_ESPEasySerial_I2C_SC16IS752_t::setTxBufferSize(size_t new_size)
{
if (_i2cserial != nullptr) {
return 64;
}
return 0;
}
#endif // ifndef DISABLE_SC16IS752_Serial
@@ -1,26 +1,26 @@
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_I2C_SC16IS752_H
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_I2C_SC16IS752_H
#ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_I2C_SC16IS752_H
#define ESPEASYSERIAL_PORT_ESPEASYSERIAL_I2C_SC16IS752_H
#include "ESPEasySerial_common_defines.h"
#if USES_I2C_SC16IS752
# include "ESPEasySC16IS752_Serial.h"
# include "Driver_ESPEasySC16IS752_Serial.h"
# include "ESPEasySerial_Port_base.h"
# include "Port_ESPEasySerial_base.h"
class ESPEasySerial_I2C_SC16IS752 : public ESPEasySerial_Port_base {
class Port_ESPEasySerial_I2C_SC16IS752_t : public Port_ESPEasySerial_base {
public:
// ESPEasySC16IS752_Serial::I2C_address addr = static_cast<ESPEasySC16IS752_Serial::I2C_address>(receivePin);
// ESPEasySC16IS752_Serial::SC16IS752_channel ch = static_cast<ESPEasySC16IS752_Serial::SC16IS752_channel>(transmitPin);
ESPEasySerial_I2C_SC16IS752(const ESPEasySerialConfig & config);
Port_ESPEasySerial_I2C_SC16IS752_t(const ESPEasySerialConfig& config);
virtual ~ESPEasySerial_I2C_SC16IS752();
virtual ~Port_ESPEasySerial_I2C_SC16IS752_t();
void begin(unsigned long baud);
@@ -54,4 +54,4 @@ private:
#endif // if USES_I2C_SC16IS752
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_I2C_SC16IS752_H
#endif // ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_I2C_SC16IS752_H
@@ -0,0 +1,135 @@
#include "Port_ESPEasySerial_SW_Serial.h"
#if USES_SW_SERIAL
Port_ESPEasySerial_SW_Serial_t::Port_ESPEasySerial_SW_Serial_t(const ESPEasySerialConfig& config)
{
if (config.port == ESPEasySerialPort::software) {
_config = config;
_swserial = new (std::nothrow) Driver_ESPEasySoftwareSerial_t(
config.receivePin,
config.transmitPin,
config.inverse_logic,
config.buffSize);
}
}
Port_ESPEasySerial_SW_Serial_t::~Port_ESPEasySerial_SW_Serial_t()
{
if (_swserial != nullptr) {
delete _swserial;
_swserial = nullptr;
}
}
void Port_ESPEasySerial_SW_Serial_t::begin(unsigned long baud)
{
if (_swserial != nullptr) {
_swserial->begin(baud);
}
}
void Port_ESPEasySerial_SW_Serial_t::end() {
if (_swserial != nullptr) {
_swserial->end();
}
}
int Port_ESPEasySerial_SW_Serial_t::available(void)
{
if (_swserial != nullptr) {
return _swserial->available();
}
return 0;
}
int Port_ESPEasySerial_SW_Serial_t::availableForWrite(void)
{
if (_swserial != nullptr) {
// FIXME TD-er: Implement availableForWrite
return 1; // return _swserial->availableForWrite();
}
return 0;
}
int Port_ESPEasySerial_SW_Serial_t::peek(void)
{
if (_swserial != nullptr) {
return _swserial->peek();
}
return 0;
}
int Port_ESPEasySerial_SW_Serial_t::read(void)
{
if (_swserial != nullptr) {
return _swserial->read();
}
return 0;
}
size_t Port_ESPEasySerial_SW_Serial_t::read(uint8_t *buffer,
size_t size)
{
if (_swserial != nullptr) {
return _swserial->readBytes((char *)buffer, size);
}
return 0;
}
void Port_ESPEasySerial_SW_Serial_t::flush(void)
{
if (_swserial != nullptr) {
return _swserial->flush();
}
}
void Port_ESPEasySerial_SW_Serial_t::flush(bool txOnly)
{
flush();
}
size_t Port_ESPEasySerial_SW_Serial_t::write(uint8_t value)
{
if (_swserial != nullptr) {
return _swserial->write(value);
}
return 0;
}
size_t Port_ESPEasySerial_SW_Serial_t::write(const uint8_t *buffer,
size_t size)
{
if (_swserial != nullptr) {
return _swserial->write(buffer, size);
}
return 0;
}
Port_ESPEasySerial_SW_Serial_t::operator bool() const
{
return _swserial != nullptr;
}
void Port_ESPEasySerial_SW_Serial_t::setDebugOutput(bool) {}
size_t Port_ESPEasySerial_SW_Serial_t::setRxBufferSize(size_t new_size)
{
if (_swserial != nullptr) {
_config.buffSize = new_size;
return new_size;
}
return 0;
}
size_t Port_ESPEasySerial_SW_Serial_t::setTxBufferSize(size_t new_size)
{
if (_swserial != nullptr) {
return 64;
}
return 0;
}
#endif // if USES_SW_SERIAL
@@ -1,5 +1,5 @@
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_SW_SERIAL_H
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_SW_SERIAL_H
#ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_SW_SERIAL_H
#define ESPEASYSERIAL_PORT_ESPEASYSERIAL_SW_SERIAL_H
#include "ESPEasySerial_common_defines.h"
@@ -7,17 +7,17 @@
#if USES_SW_SERIAL
# include "ESPEasySoftwareSerial.h"
# include "Driver_ESPEasySoftwareSerial.h"
# include "ESPEasySerial_Port_base.h"
# include "Port_ESPEasySerial_base.h"
class ESPEasySerial_SW_Serial : public ESPEasySerial_Port_base {
class Port_ESPEasySerial_SW_Serial_t : public Port_ESPEasySerial_base {
public:
ESPEasySerial_SW_Serial(const ESPEasySerialConfig & config);
Port_ESPEasySerial_SW_Serial_t(const ESPEasySerialConfig& config);
virtual ~ESPEasySerial_SW_Serial();
virtual ~Port_ESPEasySerial_SW_Serial_t();
void begin(unsigned long baud);
@@ -44,11 +44,11 @@ public:
private:
ESPeasySoftwareSerial *_swserial = nullptr;
Driver_ESPEasySoftwareSerial_t *_swserial = nullptr;
};
#endif // if USES_SW_SERIAL
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_SW_SERIAL_H
#endif // ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_SW_SERIAL_H
@@ -1,9 +1,9 @@
#include "ESPEasySerial_USBCDC.h"
#include "Port_ESPEasySerial_USBCDC.h"
#if USES_USBCDC
# include "ESPEasySerial_USB.h"
# include "Driver_ESPEasySerial_USB.h"
volatile bool usbActive = false;
@@ -80,9 +80,9 @@ static void usbcdcEventCallback(void *arg, esp_event_base_t event_base, int32_t
}
}
ESPEasySerial_USBCDC_t::ESPEasySerial_USBCDC_t(const ESPEasySerialConfig & config)
Port_ESPEasySerial_USBCDC_t::Port_ESPEasySerial_USBCDC_t(const ESPEasySerialConfig& config)
{
_serial = nullptr;
_serial = nullptr;
_mustDelete = false;
int uart_nr = -1;
@@ -95,18 +95,20 @@ ESPEasySerial_USBCDC_t::ESPEasySerial_USBCDC_t(const ESPEasySerialConfig & confi
if (uart_nr > 0) {
_config.port = config.port;
# if ARDUINO_USB_CDC_ON_BOOT
if ((uart_nr == 0) && (_usbcdc_serial != nullptr)) {
_serial = _usbcdc_serial;
} else {
_serial = new USBCDC(uart_nr);
if (uart_nr == 0) {
_serial = &Serial;
} else
# endif // if ARDUINO_USB_CDC_ON_BOOT
{
_serial = new (std::nothrow) USBCDC(uart_nr);
_mustDelete = true;
}
}
}
ESPEasySerial_USBCDC_t::~ESPEasySerial_USBCDC_t()
Port_ESPEasySerial_USBCDC_t::~Port_ESPEasySerial_USBCDC_t()
{
if (_serial != nullptr) {
_serial->end();
@@ -118,25 +120,26 @@ ESPEasySerial_USBCDC_t::~ESPEasySerial_USBCDC_t()
}
}
void ESPEasySerial_USBCDC_t::begin(unsigned long baud)
void Port_ESPEasySerial_USBCDC_t::begin(unsigned long baud)
{
if (_serial != nullptr) {
USB.onEvent(usbcdcEventCallback);
_serial->onEvent(usbcdcEventCallback);
delay(10);
_config.buffSize = _serial->setRxBufferSize(_config.buffSize);
_serial->begin();
USB.begin();
delay(1);
}
}
void ESPEasySerial_USBCDC_t::end() {
void Port_ESPEasySerial_USBCDC_t::end() {
if (_serial != nullptr) {
_serial->end();
}
}
int ESPEasySerial_USBCDC_t::available(void)
int Port_ESPEasySerial_USBCDC_t::available(void)
{
if (_serial != nullptr) {
return _serial->available();
@@ -144,7 +147,7 @@ int ESPEasySerial_USBCDC_t::available(void)
return 0;
}
int ESPEasySerial_USBCDC_t::availableForWrite(void)
int Port_ESPEasySerial_USBCDC_t::availableForWrite(void)
{
if (_serial != nullptr) {
return _serial->availableForWrite();
@@ -152,7 +155,7 @@ int ESPEasySerial_USBCDC_t::availableForWrite(void)
return 0;
}
int ESPEasySerial_USBCDC_t::peek(void)
int Port_ESPEasySerial_USBCDC_t::peek(void)
{
if (_serial != nullptr) {
return _serial->peek();
@@ -160,7 +163,7 @@ int ESPEasySerial_USBCDC_t::peek(void)
return 0;
}
int ESPEasySerial_USBCDC_t::read(void)
int Port_ESPEasySerial_USBCDC_t::read(void)
{
if (_serial != nullptr) {
return _serial->read();
@@ -168,8 +171,8 @@ int ESPEasySerial_USBCDC_t::read(void)
return 0;
}
size_t ESPEasySerial_USBCDC_t::read(uint8_t *buffer,
size_t size)
size_t Port_ESPEasySerial_USBCDC_t::read(uint8_t *buffer,
size_t size)
{
if (_serial != nullptr) {
return _serial->read(buffer, size);
@@ -177,19 +180,19 @@ size_t ESPEasySerial_USBCDC_t::read(uint8_t *buffer,
return 0;
}
void ESPEasySerial_USBCDC_t::flush(void)
void Port_ESPEasySerial_USBCDC_t::flush(void)
{
if (_serial != nullptr) {
return _serial->flush();
}
}
void ESPEasySerial_USBCDC_t::flush(bool txOnly)
void Port_ESPEasySerial_USBCDC_t::flush(bool txOnly)
{
flush();
}
size_t ESPEasySerial_USBCDC_t::write(uint8_t value)
size_t Port_ESPEasySerial_USBCDC_t::write(uint8_t value)
{
if (_serial != nullptr) {
return _serial->write(value);
@@ -197,8 +200,8 @@ size_t ESPEasySerial_USBCDC_t::write(uint8_t value)
return 0;
}
size_t ESPEasySerial_USBCDC_t::write(const uint8_t *buffer,
size_t size)
size_t Port_ESPEasySerial_USBCDC_t::write(const uint8_t *buffer,
size_t size)
{
if (_serial != nullptr) {
return _serial->write(buffer, size);
@@ -206,28 +209,30 @@ size_t ESPEasySerial_USBCDC_t::write(const uint8_t *buffer,
return 0;
}
ESPEasySerial_USBCDC_t::operator bool() const
Port_ESPEasySerial_USBCDC_t::operator bool() const
{
if (_serial != nullptr)
if (_serial != nullptr) {
return _serial->operator bool();
}
return false;
}
void ESPEasySerial_USBCDC_t::setDebugOutput(bool enabled) {
void Port_ESPEasySerial_USBCDC_t::setDebugOutput(bool enabled) {
if (_serial != nullptr) {
return _serial->setDebugOutput(enabled);
}
}
size_t ESPEasySerial_USBCDC_t::setRxBufferSize(size_t new_size)
size_t Port_ESPEasySerial_USBCDC_t::setRxBufferSize(size_t new_size)
{
if (_serial != nullptr) {
return _serial->setRxBufferSize(new_size);
_config.buffSize = _serial->setRxBufferSize(new_size);
return _config.buffSize;
}
return 0;
}
size_t ESPEasySerial_USBCDC_t::setTxBufferSize(size_t new_size)
size_t Port_ESPEasySerial_USBCDC_t::setTxBufferSize(size_t new_size)
{
if (_serial != nullptr) {
return new_size;
@@ -1,5 +1,5 @@
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USBCDC_H
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USBCDC_H
#ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_USBCDC_H
#define ESPEASYSERIAL_PORT_ESPEASYSERIAL_USBCDC_H
#include "ESPEasySerial_common_defines.h"
@@ -9,14 +9,14 @@
# include <USB.h>
# include <USBCDC.h>
# include "ESPEasySerial_Port_base.h"
# include "Port_ESPEasySerial_base.h"
class ESPEasySerial_USBCDC_t : public ESPEasySerial_Port_base {
class Port_ESPEasySerial_USBCDC_t : public Port_ESPEasySerial_base {
public:
ESPEasySerial_USBCDC_t(const ESPEasySerialConfig & config);
Port_ESPEasySerial_USBCDC_t(const ESPEasySerialConfig& config);
virtual ~ESPEasySerial_USBCDC_t();
virtual ~Port_ESPEasySerial_USBCDC_t();
void begin(unsigned long baud);
@@ -51,4 +51,4 @@ private:
#endif // if USES_USBCDC
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USBCDC_H
#endif // ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_USBCDC_H
@@ -1,8 +1,8 @@
#include "ESPEasySerial_USB_HWCDC.h"
#include "Port_ESPEasySerial_USB_HWCDC.h"
#if USES_HWCDC
# include "ESPEasySerial_USB.h"
# include "Driver_ESPEasySerial_USB.h"
volatile bool usbActive = false;
@@ -46,16 +46,17 @@ static void hwcdcEventCallback(void *arg, esp_event_base_t event_base, int32_t e
}
}
ESPEasySerial_USB_WHCDC_t::ESPEasySerial_USB_WHCDC_t(const ESPEasySerialConfig & config)
Port_ESPEasySerial_USB_HWCDC_t::Port_ESPEasySerial_USB_HWCDC_t(const ESPEasySerialConfig& config)
{
_config.port = ESPEasySerialPort::usb_hw_cdc;
}
ESPEasySerial_USB_WHCDC_t::~ESPEasySerial_USB_WHCDC_t() {}
Port_ESPEasySerial_USB_HWCDC_t::~Port_ESPEasySerial_USB_HWCDC_t() {}
void ESPEasySerial_USB_WHCDC_t::begin(unsigned long baud)
void Port_ESPEasySerial_USB_HWCDC_t::begin(unsigned long baud)
{
if (_hwcdc_serial != nullptr) {
_config.buffSize = _hwcdc_serial->setRxBufferSize(_config.buffSize);
_hwcdc_serial->begin();
delay(10);
_hwcdc_serial->onEvent(hwcdcEventCallback);
@@ -63,7 +64,7 @@ void ESPEasySerial_USB_WHCDC_t::begin(unsigned long baud)
}
}
void ESPEasySerial_USB_WHCDC_t::end() {
void Port_ESPEasySerial_USB_HWCDC_t::end() {
// Disabled for now
// See: https://github.com/espressif/arduino-esp32/issues/8224
if (_hwcdc_serial != nullptr) {
@@ -71,7 +72,7 @@ void ESPEasySerial_USB_WHCDC_t::end() {
}
}
int ESPEasySerial_USB_WHCDC_t::available(void)
int Port_ESPEasySerial_USB_HWCDC_t::available(void)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->available();
@@ -79,7 +80,7 @@ int ESPEasySerial_USB_WHCDC_t::available(void)
return 0;
}
int ESPEasySerial_USB_WHCDC_t::availableForWrite(void)
int Port_ESPEasySerial_USB_HWCDC_t::availableForWrite(void)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->availableForWrite();
@@ -87,7 +88,7 @@ int ESPEasySerial_USB_WHCDC_t::availableForWrite(void)
return 0;
}
int ESPEasySerial_USB_WHCDC_t::peek(void)
int Port_ESPEasySerial_USB_HWCDC_t::peek(void)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->peek();
@@ -95,7 +96,7 @@ int ESPEasySerial_USB_WHCDC_t::peek(void)
return 0;
}
int ESPEasySerial_USB_WHCDC_t::read(void)
int Port_ESPEasySerial_USB_HWCDC_t::read(void)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->read();
@@ -103,8 +104,8 @@ int ESPEasySerial_USB_WHCDC_t::read(void)
return 0;
}
size_t ESPEasySerial_USB_WHCDC_t::read(uint8_t *buffer,
size_t size)
size_t Port_ESPEasySerial_USB_HWCDC_t::read(uint8_t *buffer,
size_t size)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->read(buffer, size);
@@ -112,19 +113,19 @@ size_t ESPEasySerial_USB_WHCDC_t::read(uint8_t *buffer,
return 0;
}
void ESPEasySerial_USB_WHCDC_t::flush(void)
void Port_ESPEasySerial_USB_HWCDC_t::flush(void)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->flush();
}
}
void ESPEasySerial_USB_WHCDC_t::flush(bool txOnly)
void Port_ESPEasySerial_USB_HWCDC_t::flush(bool txOnly)
{
flush();
}
size_t ESPEasySerial_USB_WHCDC_t::write(uint8_t value)
size_t Port_ESPEasySerial_USB_HWCDC_t::write(uint8_t value)
{
if (operator bool()) {
return _hwcdc_serial->write(value);
@@ -132,8 +133,8 @@ size_t ESPEasySerial_USB_WHCDC_t::write(uint8_t value)
return 0;
}
size_t ESPEasySerial_USB_WHCDC_t::write(const uint8_t *buffer,
size_t size)
size_t Port_ESPEasySerial_USB_HWCDC_t::write(const uint8_t *buffer,
size_t size)
{
if (operator bool()) {
return _hwcdc_serial->write(buffer, size);
@@ -141,28 +142,30 @@ size_t ESPEasySerial_USB_WHCDC_t::write(const uint8_t *buffer,
return 0;
}
ESPEasySerial_USB_WHCDC_t::operator bool() const
Port_ESPEasySerial_USB_HWCDC_t::operator bool() const
{
if (_hwcdc_serial != nullptr)
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->operator bool();
}
return false;
}
void ESPEasySerial_USB_WHCDC_t::setDebugOutput(bool enabled) {
void Port_ESPEasySerial_USB_HWCDC_t::setDebugOutput(bool enabled) {
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->setDebugOutput(enabled);
}
}
size_t ESPEasySerial_USB_WHCDC_t::setRxBufferSize(size_t new_size)
size_t Port_ESPEasySerial_USB_HWCDC_t::setRxBufferSize(size_t new_size)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->setRxBufferSize(new_size);
_config.buffSize = _hwcdc_serial->setRxBufferSize(new_size);
return _config.buffSize;
}
return 0;
}
size_t ESPEasySerial_USB_WHCDC_t::setTxBufferSize(size_t new_size)
size_t Port_ESPEasySerial_USB_HWCDC_t::setTxBufferSize(size_t new_size)
{
if (_hwcdc_serial != nullptr) {
return _hwcdc_serial->setTxBufferSize(new_size);
@@ -1,5 +1,5 @@
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USB_HWCDC_H
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USB_HWCDC_H
#ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_USB_HWCDC_H
#define ESPEASYSERIAL_PORT_ESPEASYSERIAL_USB_HWCDC_H
#include "ESPEasySerial_common_defines.h"
@@ -7,15 +7,15 @@
// ESP32C3/S3 embedded USB using JTAG interface
# include <HWCDC.h>
# include "ESPEasySerial_Port_base.h"
# include "Port_ESPEasySerial_base.h"
class ESPEasySerial_USB_WHCDC_t : public ESPEasySerial_Port_base {
class Port_ESPEasySerial_USB_HWCDC_t : public Port_ESPEasySerial_base {
public:
ESPEasySerial_USB_WHCDC_t(const ESPEasySerialConfig & config);
Port_ESPEasySerial_USB_HWCDC_t(const ESPEasySerialConfig& config);
virtual ~ESPEasySerial_USB_WHCDC_t();
virtual ~Port_ESPEasySerial_USB_HWCDC_t();
void begin(unsigned long baud);
@@ -45,4 +45,4 @@ public:
#endif // if USES_HWCDC
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_USB_HWCDC_H
#endif // ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_USB_HWCDC_H
@@ -0,0 +1,10 @@
#include "Port_ESPEasySerial_base.h"
Port_ESPEasySerial_base::Port_ESPEasySerial_base() {}
Port_ESPEasySerial_base::~Port_ESPEasySerial_base() {}
int Port_ESPEasySerial_base::getBaudRate() const
{
return _config.baud;
}
@@ -1,5 +1,5 @@
#ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_PORT_BASE_H
#define ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_PORT_BASE_H
#ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_BASE_H
#define ESPEASYSERIAL_PORT_ESPEASYSERIAL_BASE_H
#include "ESPEasySerialPort.h"
@@ -8,11 +8,11 @@
#include <Stream.h>
class ESPEasySerial_Port_base {
class Port_ESPEasySerial_base {
public:
ESPEasySerial_Port_base();
virtual ~ESPEasySerial_Port_base();
Port_ESPEasySerial_base();
virtual ~Port_ESPEasySerial_base();
virtual void begin(unsigned long baud) = 0;
@@ -68,12 +68,14 @@ public:
return write((uint8_t)n);
}
virtual int getBaudRate() const;
virtual operator bool() const = 0;
virtual void setDebugOutput(bool) = 0;
virtual void setDebugOutput(bool) = 0;
virtual size_t setRxBufferSize(size_t new_size) = 0;
virtual size_t setTxBufferSize(size_t new_size) = 0;
virtual size_t setRxBufferSize(size_t new_size) = 0;
virtual size_t setTxBufferSize(size_t new_size) = 0;
const ESPEasySerialConfig& getSerialConfig() const {
return _config;
@@ -81,12 +83,13 @@ public:
#ifdef ESP8266
void setPortConfig(unsigned long baud,
SerialConfig config,
SerialMode mode)
SerialConfig config,
SerialMode mode)
{
_config.setPortConfig(baud, config, mode);
}
#endif
#endif // ifdef ESP8266
#ifdef ESP32
void setPortConfig(unsigned long baud, uint32_t config)
@@ -94,8 +97,7 @@ public:
_config.setPortConfig(baud, config);
}
#endif
#endif // ifdef ESP32
protected:
@@ -103,4 +105,4 @@ protected:
};
#endif // ifndef ESPEASYSERIAL_WRAPPERS_ESPEASYSERIAL_PORT_BASE_H
#endif // ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_BASE_H
+13 -8
View File
@@ -12,6 +12,8 @@
#include "../Helpers/Memory.h"
#include <ESPEasySerialPort.h>
/*
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
# include "../Helpers/_Plugin_Helper_serial.h"
@@ -108,7 +110,7 @@ void EspEasy_Console_t::begin(uint32_t baudrate)
_baudrate = baudrate;
if (_serial != nullptr && _serial->connected()) {
if (_serial != nullptr && _serial->operator bool()) {
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
_serial->begin(baudrate);
addLog(LOG_LEVEL_INFO, F("ESPEasy console using ESPEasySerial"));
@@ -163,13 +165,16 @@ void EspEasy_Console_t::loop()
return;
}
if (port->connected() && port->available())
if (port->operator bool() && port->available())
{
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
if (static_cast<ESPEasySerialPort>(_console_serial_port) == ESPEasySerialPort::serial0
#ifdef ESP8266
|| static_cast<ESPEasySerialPort>(_console_serial_port) == ESPEasySerialPort::serial0_swap
#endif
) {
)
#endif
{
String dummy;
if (PluginCall(PLUGIN_SERIAL_IN, 0, dummy)) {
@@ -305,7 +310,7 @@ bool EspEasy_Console_t::process_serialWriteBuffer() {
const int snip = availableForWrite();
if (snip > 0) {
size_t bytes_to_write = bufferSize;
int bytes_to_write = bufferSize;
if (snip < bytes_to_write) { bytes_to_write = snip; }
@@ -325,7 +330,7 @@ bool EspEasy_Console_t::process_serialWriteBuffer() {
void EspEasy_Console_t::setDebugOutput(bool enable)
{
if (_serial != nullptr && _serial->connected()) {
if (_serial != nullptr && _serial->operator bool()) {
_serial->setDebugOutput(enable);
}
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
@@ -351,7 +356,7 @@ void EspEasy_Console_t::setDebugOutput(bool enable)
#else
HardwareSerial * EspEasy_Console_t::getPort()
{
if (_serial != nullptr && _serial->connected())
if (_serial != nullptr && _serial->operator bool())
return _serial;
return nullptr;
}
@@ -361,7 +366,7 @@ void EspEasy_Console_t::setDebugOutput(bool enable)
void EspEasy_Console_t::endPort()
{
if (_serial != nullptr) {
if (_serial->connected()) {
if (_serial->operator bool()) {
_serial->end();
}
}
@@ -377,7 +382,7 @@ void EspEasy_Console_t::endPort()
int EspEasy_Console_t::availableForWrite()
{
auto serial = getPort();
if (serial != nullptr && serial->connected()) {
if (serial != nullptr && serial->operator bool()) {
return serial->availableForWrite();
}
return 0;
+1 -1
View File
@@ -110,7 +110,7 @@ bool P082_data_struct::init(ESPEasySerialPort port, const int16_t serial_rx, con
}
gps = new (std::nothrow) TinyGPSPlus();
easySerial = new (std::nothrow) ESPeasySerial(port, serial_rx, serial_tx);
easySerial = new (std::nothrow) ESPeasySerial(port, serial_rx, serial_tx, false, 512);
if (easySerial != nullptr) {
easySerial->begin(9600);