diff --git a/lib/ESPEasySerial/ESPeasySerial.h b/lib/ESPEasySerial/ESPeasySerial.h index 9b0395571..3f47cba99 100644 --- a/lib/ESPEasySerial/ESPeasySerial.h +++ b/lib/ESPEasySerial/ESPeasySerial.h @@ -43,7 +43,7 @@ # define NR_ESPEASY_SERIAL_TYPES 3 // Serial 0, 1, 2 #endif // ifdef ESP32 #if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266) - # define NR_ESPEASY_SERIAL_TYPES 4 // Serial 0, 1, 0_swap, software + # define NR_ESPEASY_SERIAL_TYPES 5 // Serial 0, 1, 0_swap, software, sc16is752 #else // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266) # define NR_ESPEASY_SERIAL_TYPES 3 // Serial 0, 1, 0_swap #endif // if !defined(DISABLE_SOFTWARE_SERIAL) && defined(ESP8266) @@ -125,6 +125,8 @@ struct ESPeasySerialType { case ESPeasySerialType::serialtype::software: rxPin = 14; txPin = 12; return true; # endif // DISABLE_SOFTWARE_SERIAL #endif // ifdef ESP8266 + case ESPeasySerialType::serialtype::sc16is752: rxPin = -1; txPin = -1; return true; + default: break; } diff --git a/lib/SC16IS752/README.md b/lib/SC16IS752/README.md index 2bc27938d..6c4e6a9e9 100644 --- a/lib/SC16IS752/README.md +++ b/lib/SC16IS752/README.md @@ -9,7 +9,7 @@ __The maximum transfer speed of SC16IS752 is 115,200bps__ ![SC16IS752-2](images/CJMCU-752-top.jpg) -![SC16IS752-1](images/CJMCU-752-top.jpg) +![SC16IS752-1](images/CJMCU-752-bottom.jpg) --- diff --git a/lib/SC16IS752/SC16IS752.cpp b/lib/SC16IS752/SC16IS752.cpp index 91c4b5667..a1dd5fed8 100644 --- a/lib/SC16IS752/SC16IS752.cpp +++ b/lib/SC16IS752/SC16IS752.cpp @@ -167,7 +167,7 @@ void SC16IS752::WriteRegister(uint8_t channel, uint8_t reg_addr, uint8_t val) } } -void SC16IS752::Initialize() +void SC16IS752::Initialize() { if (protocol == SC16IS750_PROTOCOL_I2C) { WIRE.begin(); diff --git a/lib/SC16IS752/SC16IS752.h b/lib/SC16IS752/SC16IS752.h index 7f441c372..fccb0dba6 100644 --- a/lib/SC16IS752/SC16IS752.h +++ b/lib/SC16IS752/SC16IS752.h @@ -1,40 +1,40 @@ -/* -Description: -This is a example code for Sandbox Electronics' I2C/SPI to UART bridge module. -You can get one of those products on -http://sandboxelectronics.com +/* + Description: + This is a example code for Sandbox Electronics' I2C/SPI to UART bridge module. + You can get one of those products on + http://sandboxelectronics.com -Version: -V0.1 + Version: + V0.1 -Release Date: -2014-02-16 + Release Date: + 2014-02-16 -Author: -Tiequan Shao info@sandboxelectronics.com + Author: + Tiequan Shao info@sandboxelectronics.com -Lisence: -CC BY-NC-SA 3.0 + Lisence: + CC BY-NC-SA 3.0 -Please keep the above information when you use this code in your project. -*/ + Please keep the above information when you use this code in your project. + */ #ifndef _SC16IS752_H_ #define _SC16IS752_H_ #if ARDUINO >= 100 - #include "Arduino.h" -#else - #include "WProgram.h" -#endif + # include "Arduino.h" +#else // if ARDUINO >= 100 + # include "WProgram.h" +#endif // if ARDUINO >= 100 -//Device Address +// Device Address -//A:VDD -//B:GND -//C:SCL -//D:SDA +// A:VDD +// B:GND +// C:SCL +// D:SDA #define SC16IS750_ADDRESS_AA (0X90) #define SC16IS750_ADDRESS_AB (0X92) #define SC16IS750_ADDRESS_AC (0X94) @@ -53,7 +53,7 @@ Please keep the above information when you use this code in your project. #define SC16IS750_ADDRESS_DD (0XAE) -//General Registers +// General Registers #define SC16IS750_REG_RHR (0x00) #define SC16IS750_REG_THR (0X00) #define SC16IS750_REG_IER (0X01) @@ -74,11 +74,11 @@ Please keep the above information when you use this code in your project. #define SC16IS750_REG_IOCONTROL (0X0E) #define SC16IS750_REG_EFCR (0X0F) -//Special Registers +// Special Registers #define SC16IS750_REG_DLL (0x00) #define SC16IS750_REG_DLH (0X01) -//Enhanced Registers +// Enhanced Registers #define SC16IS750_REG_EFR (0X02) #define SC16IS750_REG_XON1 (0X04) #define SC16IS750_REG_XON2 (0X05) @@ -95,82 +95,104 @@ Please keep the above information when you use this code in your project. #define SC16IS750_INT_THR (0X02) #define SC16IS750_INT_RHR (0X01) -//Application Related +// Application Related -//#define SC16IS750_CRYSTCAL_FREQ (14745600UL) -#define SC16IS750_CRYSTCAL_FREQ (1843200UL) -//#define SC16IS750_CRYSTCAL_FREQ (16000000UL) +// #define SC16IS750_CRYSTCAL_FREQ (14745600UL) +#define SC16IS750_CRYSTCAL_FREQ (1843200UL) + +// #define SC16IS750_CRYSTCAL_FREQ (16000000UL) #define SC16IS750_DEBUG_PRINT (1) #define SC16IS750_PROTOCOL_I2C (0) #define SC16IS750_PROTOCOL_SPI (1) -#define SC16IS752_CHANNEL_A 0x00 -#define SC16IS752_CHANNEL_B 0x01 -#define SC16IS752_CHANNEL_BOTH 0x00 +#define SC16IS752_CHANNEL_A 0x00 +#define SC16IS752_CHANNEL_B 0x01 +#define SC16IS752_CHANNEL_BOTH 0x00 -#define SC16IS752_DEFAULT_SPEED 9600 +#define SC16IS752_DEFAULT_SPEED 9600 -//class SC16IS752 : public Stream -class SC16IS752 -{ - public: - SC16IS752(uint8_t prtcl = SC16IS750_PROTOCOL_I2C, uint8_t addr = SC16IS750_ADDRESS_AD); - void begin(uint32_t baud_A, uint32_t baud_B); - void beginA(uint32_t baud_A); - void beginB(uint32_t baud_B); - int read(uint8_t channel); - size_t write(uint8_t channel, uint8_t val); - int available(uint8_t channel); - void pinMode(uint8_t pin, uint8_t io); - void digitalWrite(uint8_t pin, uint8_t value); - uint8_t digitalRead(uint8_t pin); - uint8_t ping(); - // void setTimeout(uint32_t); - // size_t readBytes(char *buffer, size_t length); - int peek(uint8_t channel); - void flush(uint8_t channel); - uint8_t GPIOGetPortState(void); - uint8_t InterruptPendingTest(uint8_t channel); - void SetPinInterrupt(uint8_t io_int_ena); - void InterruptControl(uint8_t channel, uint8_t int_ena); - void ModemPin(uint8_t gpio); //gpio == 0, gpio[7:4] are modem pins, gpio == 1 gpio[7:4] are gpios - void GPIOLatch(uint8_t latch); - - - private: - int peek_buf = -1; - uint8_t peek_flag = 0; - uint8_t device_address_sspin; - uint8_t protocol; - bool initialized = false; +// class SC16IS752 : public Stream +class SC16IS752 { +public: - // uint32_t timeout; - void Initialize(); - int16_t SetBaudrate(uint8_t channel, uint32_t baudrate); - uint8_t ReadRegister(uint8_t channel, uint8_t reg_addr); - void WriteRegister(uint8_t channel, uint8_t reg_addr, uint8_t val); - void SetLine(uint8_t channel, uint8_t data_length, uint8_t parity_select, uint8_t stop_length ); - void GPIOSetPinMode(uint8_t pin_number, uint8_t i_o); - void GPIOSetPinState(uint8_t pin_number, uint8_t pin_state); - - uint8_t GPIOGetPinState(uint8_t pin_number); - void GPIOSetPortMode(uint8_t port_io); - void GPIOSetPortState(uint8_t port_state); - void ResetDevice(); - - - - void __isr(uint8_t channel); - void FIFOEnable(uint8_t channel, uint8_t fifo_enable); - void FIFOReset(uint8_t channel, uint8_t rx_fifo); - void FIFOSetTriggerLevel(uint8_t channel, uint8_t rx_fifo, uint8_t length); - uint8_t FIFOAvailableData(uint8_t channel); - uint8_t FIFOAvailableSpace(uint8_t channel); - void WriteByte(uint8_t channel, uint8_t val); - int ReadByte(uint8_t channel); - void EnableTransmit(uint8_t channel, uint8_t tx_enable); - // int16_t readwithtimeout(); - + SC16IS752(uint8_t prtcl = SC16IS750_PROTOCOL_I2C, + uint8_t addr = SC16IS750_ADDRESS_AD); + void begin(uint32_t baud_A, + uint32_t baud_B); + void beginA(uint32_t baud_A); + void beginB(uint32_t baud_B); + int read(uint8_t channel); + size_t write(uint8_t channel, + uint8_t val); + int available(uint8_t channel); + void pinMode(uint8_t pin, + uint8_t io); + void digitalWrite(uint8_t pin, + uint8_t value); + uint8_t digitalRead(uint8_t pin); + uint8_t ping(); + + // void setTimeout(uint32_t); + // size_t readBytes(char *buffer, size_t length); + int peek(uint8_t channel); + void flush(uint8_t channel); + uint8_t GPIOGetPortState(void); + uint8_t InterruptPendingTest(uint8_t channel); + void SetPinInterrupt(uint8_t io_int_ena); + void InterruptControl(uint8_t channel, + uint8_t int_ena); + void ModemPin(uint8_t gpio); // gpio == 0, gpio[7:4] are modem pins, gpio == 1 gpio[7:4] are gpios + void GPIOLatch(uint8_t latch); + +private: + + int peek_buf = -1; + uint8_t peek_flag = 0; + uint8_t device_address_sspin; + uint8_t protocol; + bool initialized = false; + + // uint32_t timeout; + void Initialize(); + int16_t SetBaudrate(uint8_t channel, + uint32_t baudrate); + uint8_t ReadRegister(uint8_t channel, + uint8_t reg_addr); + void WriteRegister(uint8_t channel, + uint8_t reg_addr, + uint8_t val); + void SetLine(uint8_t channel, + uint8_t data_length, + uint8_t parity_select, + uint8_t stop_length); + void GPIOSetPinMode(uint8_t pin_number, + uint8_t i_o); + void GPIOSetPinState(uint8_t pin_number, + uint8_t pin_state); + + uint8_t GPIOGetPinState(uint8_t pin_number); + void GPIOSetPortMode(uint8_t port_io); + void GPIOSetPortState(uint8_t port_state); + void ResetDevice(); + + + void __isr(uint8_t channel); + void FIFOEnable(uint8_t channel, + uint8_t fifo_enable); + void FIFOReset(uint8_t channel, + uint8_t rx_fifo); + void FIFOSetTriggerLevel(uint8_t channel, + uint8_t rx_fifo, + uint8_t length); + uint8_t FIFOAvailableData(uint8_t channel); + uint8_t FIFOAvailableSpace(uint8_t channel); + void WriteByte(uint8_t channel, + uint8_t val); + int ReadByte(uint8_t channel); + void EnableTransmit(uint8_t channel, + uint8_t tx_enable); + + // int16_t readwithtimeout(); }; -#endif +#endif // ifndef _SC16IS752_H_ diff --git a/lib/SerialDevices/SensorSerial.cpp b/lib/SerialDevices/SensorSerial.cpp index 6a1b500c6..b405f9392 100644 --- a/lib/SerialDevices/SensorSerial.cpp +++ b/lib/SerialDevices/SensorSerial.cpp @@ -46,9 +46,9 @@ int SensorSerial::peek() return ESPeasySerial::peek(); } -size_t SensorSerial::write(uint8_t byte) +size_t SensorSerial::write(uint8_t val) { - return ESPeasySerial::write(byte); + return ESPeasySerial::write(val); } int SensorSerial::read() diff --git a/src/ESPEasyWifi.ino b/src/ESPEasyWifi.ino index dc749ce1b..1e50904df 100644 --- a/src/ESPEasyWifi.ino +++ b/src/ESPEasyWifi.ino @@ -241,7 +241,7 @@ void resetWiFi() { processedScanDone = true; wifiConnectAttemptNeeded = true; WifiDisconnect(); - setWebserverRunning(false); +// setWebserverRunning(false); // setWifiMode(WIFI_OFF); diff --git a/src/ESPEasyWifi_ProcessEvent.ino b/src/ESPEasyWifi_ProcessEvent.ino index b40f205a3..1c5573c7f 100644 --- a/src/ESPEasyWifi_ProcessEvent.ino +++ b/src/ESPEasyWifi_ProcessEvent.ino @@ -128,7 +128,7 @@ void processDisconnect() { if (processedDisconnect) { return; } processedDisconnect = true; wifiStatus = ESPEASY_WIFI_DISCONNECTED; - setWebserverRunning(false); +// setWebserverRunning(false); delay(100); // FIXME TD-er: See https://github.com/letscontrolit/ESPEasy/issues/1987#issuecomment-451644424 if (Settings.UseRules) { diff --git a/src/_Plugin_Helper_serial.ino b/src/_Plugin_Helper_serial.ino index 251d3db87..ed87294b3 100644 --- a/src/_Plugin_Helper_serial.ino +++ b/src/_Plugin_Helper_serial.ino @@ -6,6 +6,7 @@ static String serialHelper_getSerialTypeLabel(ESPeasySerialType::serialtype serT int portnr = 0; switch (serType) { case ESPeasySerialType::serialtype::software: return F("SoftwareSerial"); + case ESPeasySerialType::serialtype::sc16is752: return F("I2C Serial"); case ESPeasySerialType::serialtype::serial0_swap: return F("HW Serial0 swap"); case ESPeasySerialType::serialtype::serial0: portnr = 0; break; case ESPeasySerialType::serialtype::serial1: portnr = 1; break; @@ -72,19 +73,30 @@ void serialHelper_webformLoad(int rxPinDef, int txPinDef, bool allowSoftwareSeri option.reserve(48); option = serialHelper_getSerialTypeLabel(serType); - if (serType != ESPeasySerialType::serialtype::software) { - option += ": "; - option += formatGpioLabel(rxPin, false); - option += ' '; - option += formatGpioDirection(gpio_input); - option += "TX / "; - option += formatGpioLabel(txPin, false); - option += ' '; - option += formatGpioDirection(gpio_output); - option += "RX"; - } else { - if (!allowSoftwareSerial) { - attr[i] = F("disabled"); + switch (serType) { + case ESPeasySerialType::serialtype::software: + { + if (!allowSoftwareSerial) { + attr[i] = F("disabled"); + } + break; + } + case ESPeasySerialType::serialtype::sc16is752: + { + break; + } + default: + { + option += ": "; + option += formatGpioLabel(rxPin, false); + option += ' '; + option += formatGpioDirection(gpio_input); + option += "TX / "; + option += formatGpioLabel(txPin, false); + option += ' '; + option += formatGpioDirection(gpio_output); + option += "RX"; + break; } } options[index] = option;