mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
remove ESP8266
This commit is contained in:
72
.github/workflows/build_esp8266_dev_firmware.yml
vendored
72
.github/workflows/build_esp8266_dev_firmware.yml
vendored
@@ -1,72 +0,0 @@
|
|||||||
name: Build ESP8266 Dev Firmware
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- esp8266_dev
|
|
||||||
tags:
|
|
||||||
# - '*.*.*'
|
|
||||||
paths:
|
|
||||||
- 'CHANGELOG_LATEST.md'
|
|
||||||
workflow_dispatch:
|
|
||||||
branches: [ esp8266_dev ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Version
|
|
||||||
id: fetch_version
|
|
||||||
run: |
|
|
||||||
version=`grep -E '^#define EMSESP_APP_VERSION' ./src/version.h | awk '{print $3}' | sed 's/"//g'`
|
|
||||||
echo "::set-output name=s::$version"
|
|
||||||
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v1
|
|
||||||
|
|
||||||
- name: Install
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -U platformio
|
|
||||||
platformio upgrade
|
|
||||||
platformio update
|
|
||||||
|
|
||||||
- name: Build web
|
|
||||||
run: |
|
|
||||||
cd interface
|
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
- name: Build images
|
|
||||||
run: |
|
|
||||||
platformio run -e esp8266-ci
|
|
||||||
|
|
||||||
- name: Delete
|
|
||||||
uses: dev-drprasad/delete-tag-and-release@v0.1.2
|
|
||||||
# if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
with:
|
|
||||||
delete_release: true
|
|
||||||
tag_name: esp8266_dev
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Changelog
|
|
||||||
run: cat RELEASENOTES_DEV.md CHANGELOG_LATEST.md > BODY.txt
|
|
||||||
|
|
||||||
- name: Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
# if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
with:
|
|
||||||
body_path: BODY.txt
|
|
||||||
name: ESP8266 Development Build v${{steps.fetch_version.outputs.s}}
|
|
||||||
tag_name: esp8266_dev
|
|
||||||
prerelease: true
|
|
||||||
files: |
|
|
||||||
./build/firmware/*.*
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
55
.github/workflows/release_esp8266_stable.yml
vendored
55
.github/workflows/release_esp8266_stable.yml
vendored
@@ -1,55 +0,0 @@
|
|||||||
name: Release Stable ESP8266
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
branches: [ stable_esp8266 ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Version
|
|
||||||
id: fetch_version
|
|
||||||
run: |
|
|
||||||
version=`grep -E '^#define EMSESP_APP_VERSION' ./src/version.h | awk '{print $3}' | sed 's/"//g'`
|
|
||||||
echo "::set-output name=s::$version"
|
|
||||||
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v1
|
|
||||||
|
|
||||||
- name: Install
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -U platformio
|
|
||||||
platformio upgrade
|
|
||||||
platformio update
|
|
||||||
|
|
||||||
- name: Build web
|
|
||||||
run: |
|
|
||||||
cd interface
|
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
- name: Build images
|
|
||||||
run: |
|
|
||||||
platformio run -e esp8266-ci
|
|
||||||
|
|
||||||
- name: Changelog
|
|
||||||
run: cat RELEASENOTES.md CHANGELOG_LATEST.md > BODY.txt
|
|
||||||
|
|
||||||
- name: Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
with:
|
|
||||||
body_path: BODY.txt
|
|
||||||
name: EMS-ESP v${{steps.fetch_version.outputs.s}} (ESP8266)
|
|
||||||
tag_name: v${{steps.fetch_version.outputs.s}}
|
|
||||||
prerelease: false
|
|
||||||
files: |
|
|
||||||
./build/firmware/*.*
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
@@ -49,12 +49,7 @@
|
|||||||
#define EMSESP_DEFAULT_ANALOG_ENABLED false
|
#define EMSESP_DEFAULT_ANALOG_ENABLED false
|
||||||
|
|
||||||
// Default GPIO PIN definitions
|
// Default GPIO PIN definitions
|
||||||
#if defined(ESP8266)
|
#if defined(ESP32)
|
||||||
#define EMSESP_DEFAULT_RX_GPIO 13 // UART0, swapped
|
|
||||||
#define EMSESP_DEFAULT_TX_GPIO 15 // UART0, swapped
|
|
||||||
#define EMSESP_DEFAULT_DALLAS_GPIO 14 // D5
|
|
||||||
#define EMSESP_DEFAULT_LED_GPIO 2 // onboard LED
|
|
||||||
#elif defined(ESP32)
|
|
||||||
#define EMSESP_DEFAULT_RX_GPIO 23 // D7 on Wemos D1-32, OR 17 for UART2 on Lolin D32
|
#define EMSESP_DEFAULT_RX_GPIO 23 // D7 on Wemos D1-32, OR 17 for UART2 on Lolin D32
|
||||||
#define EMSESP_DEFAULT_TX_GPIO 5 // D8 on Wemos D1-32, OR 16 for UART2 on Lolin D32
|
#define EMSESP_DEFAULT_TX_GPIO 5 // D8 on Wemos D1-32, OR 16 for UART2 on Lolin D32
|
||||||
#define EMSESP_DEFAULT_DALLAS_GPIO 18 // 18 on Wemos D1-32, 14 on LOLIN D32
|
#define EMSESP_DEFAULT_DALLAS_GPIO 18 // 18 on Wemos D1-32, 14 on LOLIN D32
|
||||||
|
|||||||
@@ -76,11 +76,7 @@ void EMSESPShell::display_banner() {
|
|||||||
|
|
||||||
if (console_hostname_.empty()) {
|
if (console_hostname_.empty()) {
|
||||||
console_hostname_.resize(16, '\0');
|
console_hostname_.resize(16, '\0');
|
||||||
#if defined(ESP8266)
|
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("ems-esp"));
|
||||||
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("esp8266"));
|
|
||||||
#else
|
|
||||||
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("esp32"));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the list of commands
|
// load the list of commands
|
||||||
@@ -648,13 +644,7 @@ void Console::loop() {
|
|||||||
telnet_.loop();
|
telnet_.loop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
if (!EMSuart::sending()) {
|
|
||||||
Shell::loop_all();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
Shell::loop_all();
|
Shell::loop_all();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -97,11 +97,7 @@ void System::restart() {
|
|||||||
LOG_INFO(F("Restarting system..."));
|
LOG_INFO(F("Restarting system..."));
|
||||||
Shell::loop_all();
|
Shell::loop_all();
|
||||||
delay(1000); // wait a second
|
delay(1000); // wait a second
|
||||||
#if defined(ESP8266)
|
|
||||||
ESP.reset();
|
|
||||||
#elif defined(ESP32)
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// saves all settings
|
// saves all settings
|
||||||
@@ -122,11 +118,7 @@ void System::format(uuid::console::Shell & shell) {
|
|||||||
|
|
||||||
EMSuart::stop();
|
EMSuart::stop();
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
LittleFS.format();
|
|
||||||
#elif defined(ESP32)
|
|
||||||
LITTLEFS.format();
|
LITTLEFS.format();
|
||||||
#endif
|
|
||||||
|
|
||||||
System::restart();
|
System::restart();
|
||||||
}
|
}
|
||||||
@@ -257,9 +249,7 @@ void System::start(uint32_t heap_start) {
|
|||||||
|
|
||||||
void System::other_init() {
|
void System::other_init() {
|
||||||
// set the boolean format used for rendering booleans
|
// set the boolean format used for rendering booleans
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings & settings) { analog_enabled_ = settings.analog_enabled; });
|
||||||
analog_enabled_ = settings.analog_enabled;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init stuff. This is called when settings are changed in the web
|
// init stuff. This is called when settings are changed in the web
|
||||||
@@ -354,20 +344,10 @@ void System::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void System::show_mem(const char * note) {
|
void System::show_mem(const char * note) {
|
||||||
#if defined(ESP8266)
|
|
||||||
static uint32_t old_free_heap = 0;
|
|
||||||
static uint8_t old_heap_frag = 0;
|
|
||||||
uint32_t free_heap = ESP.getFreeHeap();
|
|
||||||
uint8_t heap_frag = ESP.getHeapFragmentation();
|
|
||||||
LOG_INFO(F("(%s) Free heap: %lu (~%lu), frag:%d%% (~%d)"), note, free_heap, (uint32_t)Helpers::abs(free_heap - old_free_heap), heap_frag, (uint8_t)Helpers::abs(heap_frag - old_heap_frag));
|
|
||||||
old_free_heap = free_heap;
|
|
||||||
old_heap_frag = heap_frag;
|
|
||||||
#elif defined(ESP32)
|
|
||||||
static uint32_t old_free_heap = 0;
|
static uint32_t old_free_heap = 0;
|
||||||
uint32_t free_heap = ESP.getFreeHeap();
|
uint32_t free_heap = ESP.getFreeHeap();
|
||||||
LOG_INFO(F("(%s) Free heap: %lu (~%lu)"), note, free_heap, (uint32_t)Helpers::abs(free_heap - old_free_heap));
|
LOG_INFO(F("(%s) Free heap: %lu (~%lu)"), note, free_heap, (uint32_t)Helpers::abs(free_heap - old_free_heap));
|
||||||
old_free_heap = free_heap;
|
old_free_heap = free_heap;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send periodic MQTT message with system information
|
// send periodic MQTT message with system information
|
||||||
@@ -382,10 +362,6 @@ void System::send_heartbeat() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
uint8_t frag_memory = ESP.getHeapFragmentation();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc;
|
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc;
|
||||||
|
|
||||||
uint8_t ems_status = EMSESP::bus_status();
|
uint8_t ems_status = EMSESP::bus_status();
|
||||||
@@ -410,9 +386,7 @@ void System::send_heartbeat() {
|
|||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
doc["freemem"] = ESP.getFreeHeap();
|
doc["freemem"] = ESP.getFreeHeap();
|
||||||
#endif
|
#endif
|
||||||
#if defined(ESP8266)
|
|
||||||
doc["fragmem"] = frag_memory;
|
|
||||||
#endif
|
|
||||||
if (analog_enabled_) {
|
if (analog_enabled_) {
|
||||||
doc["adc"] = analog_;
|
doc["adc"] = analog_;
|
||||||
}
|
}
|
||||||
@@ -426,9 +400,7 @@ void System::measure_analog() {
|
|||||||
|
|
||||||
if (!measure_last_ || (uint32_t)(uuid::get_uptime() - measure_last_) >= SYSTEM_MEASURE_ANALOG_INTERVAL) {
|
if (!measure_last_ || (uint32_t)(uuid::get_uptime() - measure_last_) >= SYSTEM_MEASURE_ANALOG_INTERVAL) {
|
||||||
measure_last_ = uuid::get_uptime();
|
measure_last_ = uuid::get_uptime();
|
||||||
#if defined(ESP8266)
|
#if defined(ESP32)
|
||||||
uint16_t a = analogRead(A0);
|
|
||||||
#elif defined(ESP32)
|
|
||||||
uint16_t a = analogRead(36);
|
uint16_t a = analogRead(36);
|
||||||
#else
|
#else
|
||||||
uint16_t a = 0; // standalone
|
uint16_t a = 0; // standalone
|
||||||
@@ -480,6 +452,7 @@ void System::system_check() {
|
|||||||
// if it was unhealthy but now we're better, make sure the LED is solid again cos we've been healed
|
// if it was unhealthy but now we're better, make sure the LED is solid again cos we've been healed
|
||||||
if (!system_healthy_) {
|
if (!system_healthy_) {
|
||||||
system_healthy_ = true;
|
system_healthy_ = true;
|
||||||
|
send_heartbeat();
|
||||||
if (led_gpio_) {
|
if (led_gpio_) {
|
||||||
digitalWrite(led_gpio_, hide_led_ ? !LED_ON : LED_ON); // LED on, for ever
|
digitalWrite(led_gpio_, hide_led_ ? !LED_ON : LED_ON); // LED on, for ever
|
||||||
}
|
}
|
||||||
@@ -708,7 +681,7 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
|||||||
networkSettings.ssid = arguments.front().c_str();
|
networkSettings.ssid = arguments.front().c_str();
|
||||||
return StateUpdateResult::CHANGED;
|
return StateUpdateResult::CHANGED;
|
||||||
});
|
});
|
||||||
shell.println("Use `wifi reconnect` to save the new settings");
|
shell.println("Use `wifi reconnect` to save and apply the new settings");
|
||||||
});
|
});
|
||||||
|
|
||||||
EMSESPShell::commands->add_command(ShellContext::SYSTEM, CommandFlags::ADMIN, flash_string_vector{F_(set), F_(wifi), F_(password)}, [](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) {
|
EMSESPShell::commands->add_command(ShellContext::SYSTEM, CommandFlags::ADMIN, flash_string_vector{F_(set), F_(wifi), F_(password)}, [](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) {
|
||||||
@@ -721,7 +694,7 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
|||||||
networkSettings.password = password2.c_str();
|
networkSettings.password = password2.c_str();
|
||||||
return StateUpdateResult::CHANGED;
|
return StateUpdateResult::CHANGED;
|
||||||
});
|
});
|
||||||
shell.println("Use `wifi reconnect` to save the new settings");
|
shell.println("Use `wifi reconnect` to save and apply the new settings");
|
||||||
} else {
|
} else {
|
||||||
shell.println(F("Passwords do not match"));
|
shell.println(F("Passwords do not match"));
|
||||||
}
|
}
|
||||||
@@ -753,7 +726,7 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
|||||||
Console::enter_custom_context(shell, context);
|
Console::enter_custom_context(shell, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// upgrade from previous versions of EMS-ESP (ESP8266)
|
// upgrade from previous versions of EMS-ESP
|
||||||
// returns true if an upgrade was done
|
// returns true if an upgrade was done
|
||||||
bool System::check_upgrade() {
|
bool System::check_upgrade() {
|
||||||
return false;
|
return false;
|
||||||
@@ -764,8 +737,8 @@ bool System::check_upgrade() {
|
|||||||
// value and id are ignored
|
// value and id are ignored
|
||||||
bool System::command_settings(const char * value, const int8_t id, JsonObject & json) {
|
bool System::command_settings(const char * value, const int8_t id, JsonObject & json) {
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & settings) {
|
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & settings) {
|
||||||
JsonObject node = json.createNestedObject("WIFI");
|
JsonObject node = json.createNestedObject("WIFI");
|
||||||
node["ssid"] = settings.ssid;
|
node["ssid"] = settings.ssid;
|
||||||
node["hostname"] = settings.hostname;
|
node["hostname"] = settings.hostname;
|
||||||
node["static_ip_config"] = settings.staticIPConfig;
|
node["static_ip_config"] = settings.staticIPConfig;
|
||||||
JsonUtils::writeIP(node, "local_ip", settings.localIP);
|
JsonUtils::writeIP(node, "local_ip", settings.localIP);
|
||||||
@@ -780,9 +753,9 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
|
|||||||
JsonObject node = json.createNestedObject("AP");
|
JsonObject node = json.createNestedObject("AP");
|
||||||
node["provision_mode"] = settings.provisionMode;
|
node["provision_mode"] = settings.provisionMode;
|
||||||
node["ssid"] = settings.ssid;
|
node["ssid"] = settings.ssid;
|
||||||
node["local_ip"] = settings.localIP.toString();
|
node["local_ip"] = settings.localIP.toString();
|
||||||
node["gateway_ip"] = settings.gatewayIP.toString();
|
node["gateway_ip"] = settings.gatewayIP.toString();
|
||||||
node["subnet_mask"] = settings.subnetMask.toString();
|
node["subnet_mask"] = settings.subnetMask.toString();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -860,10 +833,6 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & json
|
|||||||
|
|
||||||
node["version"] = EMSESP_APP_VERSION;
|
node["version"] = EMSESP_APP_VERSION;
|
||||||
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
||||||
#if defined(ESP8266)
|
|
||||||
node["freemem"] = ESP.getFreeHeap();
|
|
||||||
node["fragmem"] = ESP.getHeapFragmentation();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
node = json.createNestedObject("Status");
|
node = json.createNestedObject("Status");
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
// UART drivers
|
// UART drivers
|
||||||
#if defined(ESP8266)
|
#if defined(ESP32)
|
||||||
#include "uart/emsuart_esp8266.h"
|
|
||||||
#elif defined(ESP32)
|
|
||||||
#include "uart/emsuart_esp32.h"
|
#include "uart/emsuart_esp32.h"
|
||||||
#elif defined(EMSESP_STANDALONE)
|
#elif defined(EMSESP_STANDALONE)
|
||||||
#include <emsuart_standalone.h>
|
#include <emsuart_standalone.h>
|
||||||
|
|||||||
@@ -1,339 +0,0 @@
|
|||||||
/*
|
|
||||||
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
|
||||||
* Copyright 2020 Paul Derbyshire
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
|
|
||||||
#include "uart/emsuart_esp8266.h"
|
|
||||||
|
|
||||||
#include "emsesp.h"
|
|
||||||
|
|
||||||
namespace emsesp {
|
|
||||||
|
|
||||||
os_event_t recvTaskQueue[EMSUART_recvTaskQueueLen]; // our Rx queue
|
|
||||||
EMSuart::EMSRxBuf_t * pEMSRxBuf;
|
|
||||||
EMSuart::EMSRxBuf_t * paEMSRxBuf[EMS_MAXBUFFERS];
|
|
||||||
uint8_t emsRxBufIdx = 0;
|
|
||||||
uint8_t tx_mode_ = 0xFF;
|
|
||||||
bool drop_next_rx = true;
|
|
||||||
uint8_t emsTxBuf[EMS_MAXBUFFERSIZE];
|
|
||||||
uint8_t emsTxBufIdx;
|
|
||||||
uint8_t emsTxBufLen;
|
|
||||||
uint32_t emsTxWait;
|
|
||||||
bool EMSuart::sending_ = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main interrupt handler
|
|
||||||
// Important: must not use ICACHE_FLASH_ATTR
|
|
||||||
//
|
|
||||||
void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
|
||||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block
|
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset tx-brk
|
|
||||||
if (sending_) { // irq tx_mode is interrupted by <brk>, should never happen
|
|
||||||
drop_next_rx = true; // we have trash in buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
|
||||||
uint8_t length = 0;
|
|
||||||
uint8_t uart_buffer[EMS_MAXBUFFERSIZE + 2];
|
|
||||||
|
|
||||||
while ((USS(EMSUART_UART) >> USRXC) & 0x0FF) { // read fifo into buffer
|
|
||||||
uint8_t rx = USF(EMSUART_UART);
|
|
||||||
if (length < EMS_MAXBUFFERSIZE) {
|
|
||||||
if (length || rx) { // skip a leading zero
|
|
||||||
uart_buffer[length++] = rx;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
drop_next_rx = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drop_next_rx) {
|
|
||||||
if (uart_buffer[length - 1]) { // check if last byte is break
|
|
||||||
length++;
|
|
||||||
}
|
|
||||||
|
|
||||||
pEMSRxBuf->length = length;
|
|
||||||
os_memcpy((void *)pEMSRxBuf->buffer, (void *)&uart_buffer, pEMSRxBuf->length); // copy data into transfer buffer, including the BRK 0x00 at the end
|
|
||||||
system_os_post(EMSUART_recvTaskPrio, 0, 0); // call emsuart_recvTask() at next opportunity
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_next_rx = false;
|
|
||||||
sending_ = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* system task triggered on BRK interrupt
|
|
||||||
* incoming received messages are always asynchronous
|
|
||||||
* The full buffer is sent to EMSESP::incoming_telegram()
|
|
||||||
*/
|
|
||||||
void ICACHE_FLASH_ATTR EMSuart::emsuart_recvTask(os_event_t * events) {
|
|
||||||
EMSRxBuf_t * pCurrent = pEMSRxBuf;
|
|
||||||
pEMSRxBuf = paEMSRxBuf[++emsRxBufIdx % EMS_MAXBUFFERS]; // next free EMS Receive buffer
|
|
||||||
uint8_t length = pCurrent->length; // number of bytes including the BRK at the end
|
|
||||||
pCurrent->length = 0;
|
|
||||||
|
|
||||||
// Ignore telegrams with no data value, then transmit EMS buffer, excluding the BRK
|
|
||||||
if (length > 4 || length == 2) {
|
|
||||||
EMSESP::incoming_telegram((uint8_t *)pCurrent->buffer, length - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISR to Fire when Timer is triggered
|
|
||||||
void ICACHE_RAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
|
|
||||||
if (!sending_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emsTxBufIdx++;
|
|
||||||
if (emsTxBufIdx < emsTxBufLen) {
|
|
||||||
USF(EMSUART_UART) = emsTxBuf[emsTxBufIdx];
|
|
||||||
timer1_write(emsTxWait);
|
|
||||||
} else if (emsTxBufIdx == emsTxBufLen) {
|
|
||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
|
|
||||||
timer1_write(EMSUART_TX_BRK_TIMER);
|
|
||||||
} else {
|
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset <BRK>
|
|
||||||
sending_ = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* flush everything left over in buffer, this clears both rx and tx FIFOs
|
|
||||||
*/
|
|
||||||
void ICACHE_FLASH_ATTR EMSuart::emsuart_flush_fifos() {
|
|
||||||
USC0(EMSUART_UART) |= ((1 << UCRXRST) | (1 << UCTXRST)); // set bits
|
|
||||||
USC0(EMSUART_UART) &= ~((1 << UCRXRST) | (1 << UCTXRST)); // clear bits
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* init UART0 driver
|
|
||||||
*/
|
|
||||||
void ICACHE_FLASH_ATTR EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio) {
|
|
||||||
if (tx_mode_ != 0xFF) { // it's a restart no need to configure uart
|
|
||||||
tx_mode_ = tx_mode;
|
|
||||||
restart();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tx_mode_ = tx_mode;
|
|
||||||
// allocate and preset EMS Receive buffers
|
|
||||||
for (int i = 0; i < EMS_MAXBUFFERS; i++) {
|
|
||||||
EMSRxBuf_t * p = (EMSRxBuf_t *)malloc(sizeof(EMSRxBuf_t));
|
|
||||||
p->length = 0;
|
|
||||||
paEMSRxBuf[i] = p;
|
|
||||||
}
|
|
||||||
pEMSRxBuf = paEMSRxBuf[0]; // reset EMS Rx Buffer
|
|
||||||
|
|
||||||
ETS_UART_INTR_ATTACH(nullptr, nullptr);
|
|
||||||
|
|
||||||
// pin settings
|
|
||||||
PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
|
|
||||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
|
|
||||||
PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0RXD_U);
|
|
||||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD);
|
|
||||||
|
|
||||||
// set 9600, 8 bits, no parity check, 1 stop bit
|
|
||||||
USD(EMSUART_UART) = (UART_CLK_FREQ / EMSUART_BAUD);
|
|
||||||
USC0(EMSUART_UART) = EMSUART_CONFIG; // 8N1
|
|
||||||
emsuart_flush_fifos();
|
|
||||||
|
|
||||||
// conf1 params
|
|
||||||
// UCTOE = RX TimeOut enable (default is 1)
|
|
||||||
// UCTOT = RX TimeOut Threshold (7 bit) = want this when no more data after 1 characters (default is 2)
|
|
||||||
// UCFFT = RX FIFO Full Threshold (7 bit) = want this to be 31 for 32 bytes of buffer (default was 127)
|
|
||||||
// see https://www.espressif.com/sites/default/files/documentation/esp8266-technical_reference_en.pdf
|
|
||||||
//
|
|
||||||
// change: don't care, we do not use these interrupts
|
|
||||||
USC1(EMSUART_UART) = 0; // reset config
|
|
||||||
// USC1(EMSUART_UART) = (0x7F << UCFFT) | (0x01 << UCTOT) | (1 << UCTOE); // enable interupts
|
|
||||||
|
|
||||||
// set interrupts for triggers
|
|
||||||
USIC(EMSUART_UART) = 0xFFFF; // clear all interupts
|
|
||||||
USIE(EMSUART_UART) = 0; // disable all interrupts
|
|
||||||
|
|
||||||
// set up interrupt callbacks for Rx
|
|
||||||
system_os_task(emsuart_recvTask, EMSUART_recvTaskPrio, recvTaskQueue, EMSUART_recvTaskQueueLen);
|
|
||||||
|
|
||||||
// disable esp debug which will go to Tx and mess up the line - see https://github.com/espruino/Espruino/issues/655
|
|
||||||
system_set_os_print(0);
|
|
||||||
|
|
||||||
if (tx_gpio == 1 && rx_gpio == 3) {
|
|
||||||
system_uart_de_swap();
|
|
||||||
} else if (tx_gpio == 15 && rx_gpio == 13) {
|
|
||||||
system_uart_swap(); // swap Rx and Tx pins to use GPIO13 (D7) and GPIO15 (D8) respectively
|
|
||||||
}
|
|
||||||
|
|
||||||
ETS_UART_INTR_ATTACH(emsuart_rx_intr_handler, nullptr);
|
|
||||||
drop_next_rx = true;
|
|
||||||
|
|
||||||
// for sending with large delay in EMS+ mode we use a timer interrupt
|
|
||||||
timer1_attachInterrupt(emsuart_tx_timer_intr_handler);
|
|
||||||
|
|
||||||
restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* stop UART0 driver
|
|
||||||
* This is called prior to an OTA upload and also before a save to the filesystem to prevent conflicts
|
|
||||||
*/
|
|
||||||
void ICACHE_FLASH_ATTR EMSuart::stop() {
|
|
||||||
USIE(EMSUART_UART) = 0;
|
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear BRK bit
|
|
||||||
timer1_disable();
|
|
||||||
sending_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* re-start UART0 driver
|
|
||||||
*/
|
|
||||||
void ICACHE_FLASH_ATTR EMSuart::restart() {
|
|
||||||
if (USIR(EMSUART_UART) & ((1 << UIBD))) {
|
|
||||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the <brk> detect interrupt
|
|
||||||
drop_next_rx = true;
|
|
||||||
}
|
|
||||||
if (tx_mode_ > 100) {
|
|
||||||
emsTxWait = 5 * EMSUART_TX_BIT_TIME * (tx_mode_ - 90);
|
|
||||||
} else {
|
|
||||||
emsTxWait = 5 * EMSUART_TX_BIT_TIME * (tx_mode_ + 10); // bittimes wait to next bytes
|
|
||||||
}
|
|
||||||
emsTxBufIdx = 0;
|
|
||||||
emsTxBufLen = 0;
|
|
||||||
timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);
|
|
||||||
USIE(EMSUART_UART) = (1 << UIBD); // enable <brk> interrupt
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Sends a 1-byte poll, ending with a <BRK>
|
|
||||||
*/
|
|
||||||
void ICACHE_FLASH_ATTR EMSuart::send_poll(uint8_t data) {
|
|
||||||
transmit(&data, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send data to Tx line, ending with a <BRK>
|
|
||||||
* buf contains the CRC and len is #bytes including the CRC
|
|
||||||
* returns code, 0=success, 1=brk error, 2=watchdog timeout
|
|
||||||
*/
|
|
||||||
uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
|
||||||
if (len == 0 || len >= EMS_MAXBUFFERSIZE) {
|
|
||||||
return EMS_TX_STATUS_ERR; // nothing or to much to send
|
|
||||||
}
|
|
||||||
if (tx_mode_ == 0) {
|
|
||||||
return EMS_TX_STATUS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// timer controlled modes with extra delay
|
|
||||||
if (tx_mode_ >= 5) {
|
|
||||||
sending_ = true;
|
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
|
||||||
emsTxBuf[i] = buf[i];
|
|
||||||
}
|
|
||||||
USF(EMSUART_UART) = buf[0]; // send first byte
|
|
||||||
emsTxBufIdx = 0;
|
|
||||||
emsTxBufLen = len;
|
|
||||||
if (tx_mode_ > 100 && len > 1) {
|
|
||||||
timer1_write(EMSUART_TX_WAIT_REPLY); // large delay after first byte
|
|
||||||
} else {
|
|
||||||
timer1_write(emsTxWait);
|
|
||||||
}
|
|
||||||
return EMS_TX_STATUS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// new code from Michael. See https://github.com/proddy/EMS-ESP/issues/380
|
|
||||||
if (tx_mode_ == EMS_TXMODE_NEW) { // tx_mode 4
|
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
|
||||||
USF(EMSUART_UART) = buf[i];
|
|
||||||
}
|
|
||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // send <BRK> at the end, clear by interrupt
|
|
||||||
return EMS_TX_STATUS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// EMS+ https://github.com/proddy/EMS-ESP/issues/23#
|
|
||||||
if (tx_mode_ == EMS_TXMODE_EMSPLUS) { // tx_mode 2, With extra tx delay for EMS+
|
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
|
||||||
USF(EMSUART_UART) = buf[i];
|
|
||||||
delayMicroseconds(EMSUART_TX_WAIT_PLUS); // 2070
|
|
||||||
}
|
|
||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set break
|
|
||||||
delayMicroseconds(EMSUART_TX_BRK_PLUS);
|
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK);
|
|
||||||
return EMS_TX_STATUS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Junkers logic by @philrich, tx_mode 3
|
|
||||||
if (tx_mode_ == EMS_TXMODE_HT3) {
|
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
|
||||||
USF(EMSUART_UART) = buf[i];
|
|
||||||
// just to be safe wait for tx fifo empty (still needed?)
|
|
||||||
while (((USS(EMSUART_UART) >> USTXC) & 0xff)) {
|
|
||||||
}
|
|
||||||
// wait until bits are sent on wire
|
|
||||||
delayMicroseconds(EMSUART_TX_WAIT_HT3);
|
|
||||||
}
|
|
||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set break bit
|
|
||||||
delayMicroseconds(EMSUART_TX_BRK_HT3);
|
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK);
|
|
||||||
return EMS_TX_STATUS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Logic for tx_mode of 1
|
|
||||||
* based on code from https://github.com/proddy/EMS-ESP/issues/103 by @susisstrolch
|
|
||||||
*
|
|
||||||
* Logic:
|
|
||||||
* we emit the whole telegram, with Rx interrupt disabled, collecting busmaster response in FIFO.
|
|
||||||
* after sending the last char we poll the Rx status until either
|
|
||||||
* - size(Rx FIFO) == size(Tx-Telegram)
|
|
||||||
* - <BRK> is detected
|
|
||||||
* At end of receive we re-enable Rx-INT and send a Tx-BRK in loopback mode.
|
|
||||||
*
|
|
||||||
* EMS-Bus error handling
|
|
||||||
* 1. Busmaster stops echoing on Tx w/o permission
|
|
||||||
* 2. Busmaster cancel telegram by sending a BRK
|
|
||||||
*
|
|
||||||
* Case 1. is handled by a watchdog counter which is reset on each
|
|
||||||
* Tx attempt. The timeout should be 20x EMSUART_TX_BIT_TIME plus
|
|
||||||
* some smart guess for processing time on targeted EMS device.
|
|
||||||
* We set Status to EMS_TX_WTD_TIMEOUT and return
|
|
||||||
*
|
|
||||||
* Case 2. is handled via a BRK chk during transmission.
|
|
||||||
* We set Status to EMS_TX_BRK_DETECT and return
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// clear Rx status register, resetting the Rx FIFO and flush it
|
|
||||||
emsuart_flush_fifos();
|
|
||||||
|
|
||||||
// send the bytes along the serial line
|
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
|
||||||
volatile uint8_t _usrxc = (USS(EMSUART_UART) >> USRXC) & 0xFF;
|
|
||||||
uint16_t timeoutcnt = EMSUART_TX_TIMEOUT;
|
|
||||||
USF(EMSUART_UART) = buf[i]; // send each Tx byte
|
|
||||||
// wait for echo
|
|
||||||
while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) == _usrxc) && (--timeoutcnt > 0)) {
|
|
||||||
delayMicroseconds(EMSUART_TX_BUSY_WAIT); // burn CPU cycles...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
USC0(EMSUART_UART) |= (1 << UCBRK); // snd break
|
|
||||||
delayMicroseconds(EMSUART_TX_BRK_EMS);
|
|
||||||
USC0(EMSUART_UART) &= ~(1 << UCBRK);
|
|
||||||
return EMS_TX_STATUS_OK; // send the Tx ok status back
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace emsesp
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
|
||||||
* Copyright 2020 Paul Derbyshire
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#if defined(ESP8266)
|
|
||||||
|
|
||||||
#ifndef EMSESP_EMSUART_H
|
|
||||||
#define EMSESP_EMSUART_H
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include <user_interface.h>
|
|
||||||
|
|
||||||
#define EMSUART_UART 0 // UART 0
|
|
||||||
#define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no parity, 1 stop bit)
|
|
||||||
#define EMSUART_BAUD 9600 // uart baud rate for the EMS circuit
|
|
||||||
|
|
||||||
#define EMS_MAXBUFFERS 3 // buffers for circular filling to avoid collisions
|
|
||||||
#define EMS_MAXBUFFERSIZE 33 // max size of the buffer. EMS packets are max 32 bytes, plus extra 2 for BRKs
|
|
||||||
|
|
||||||
#define EMSUART_recvTaskPrio 2 // 0, 1 or 2. 0 being the lowest
|
|
||||||
#define EMSUART_recvTaskQueueLen 10 // number of queued Rx triggers
|
|
||||||
|
|
||||||
#define EMS_TXMODE_DEFAULT 1
|
|
||||||
#define EMS_TXMODE_EMSPLUS 2
|
|
||||||
#define EMS_TXMODE_HT3 3
|
|
||||||
#define EMS_TXMODE_NEW 4 // for michael's testing
|
|
||||||
|
|
||||||
// LEGACY
|
|
||||||
#define EMSUART_TX_BIT_TIME 104 // bit time @9600 baud
|
|
||||||
|
|
||||||
// TIMER modes
|
|
||||||
#define EMSUART_TX_BRK_TIMER (EMSUART_TX_BIT_TIME * 52) // > 10 bittimes for timer modes
|
|
||||||
#define EMSUART_TX_WAIT_REPLY 500000 // delay 100ms after first byte
|
|
||||||
|
|
||||||
// EMS 1.0
|
|
||||||
#define EMSUART_TX_BUSY_WAIT (EMSUART_TX_BIT_TIME / 8) // 13
|
|
||||||
// #define EMSUART_TX_TIMEOUT (32 * 8) // 256 for tx_mode 1 - see https://github.com/proddy/EMS-ESP/issues/398#issuecomment-645886277
|
|
||||||
#define EMSUART_TX_TIMEOUT (220 * 8) // 1760 as in v1.9 (180 ms)
|
|
||||||
#define EMSUART_TX_BRK_EMS (EMSUART_TX_BIT_TIME * 10)
|
|
||||||
|
|
||||||
// HT3/Junkers - Time to send one Byte (8 Bits, 1 Start Bit, 1 Stop Bit) plus 7 bit delay. The -8 is for lag compensation.
|
|
||||||
// since we use a faster processor the lag is negligible
|
|
||||||
#define EMSUART_TX_WAIT_HT3 (EMSUART_TX_BIT_TIME * 17) // 1768
|
|
||||||
#define EMSUART_TX_BRK_HT3 (EMSUART_TX_BIT_TIME * 11)
|
|
||||||
|
|
||||||
// EMS+ - Time to send one Byte (8 Bits, 1 Start Bit, 1 Stop Bit) and delay of another Bytetime.
|
|
||||||
#define EMSUART_TX_WAIT_PLUS (EMSUART_TX_BIT_TIME * 20) // 2080
|
|
||||||
#define EMSUART_TX_BRK_PLUS (EMSUART_TX_BIT_TIME * 11)
|
|
||||||
|
|
||||||
namespace emsesp {
|
|
||||||
|
|
||||||
#define EMS_TX_STATUS_ERR 0
|
|
||||||
#define EMS_TX_STATUS_OK 1
|
|
||||||
|
|
||||||
class EMSuart {
|
|
||||||
public:
|
|
||||||
EMSuart() = default;
|
|
||||||
~EMSuart() = default;
|
|
||||||
|
|
||||||
static void ICACHE_FLASH_ATTR start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio);
|
|
||||||
static void ICACHE_FLASH_ATTR stop();
|
|
||||||
static void ICACHE_FLASH_ATTR restart();
|
|
||||||
static void ICACHE_FLASH_ATTR send_poll(uint8_t data);
|
|
||||||
static uint16_t ICACHE_FLASH_ATTR transmit(uint8_t * buf, uint8_t len);
|
|
||||||
static bool sending() {
|
|
||||||
return sending_;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t length;
|
|
||||||
uint8_t buffer[EMS_MAXBUFFERSIZE];
|
|
||||||
} EMSRxBuf_t;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void ICACHE_RAM_ATTR emsuart_rx_intr_handler(void * para);
|
|
||||||
static void ICACHE_FLASH_ATTR emsuart_recvTask(os_event_t * events);
|
|
||||||
static void ICACHE_FLASH_ATTR emsuart_flush_fifos();
|
|
||||||
static void ICACHE_RAM_ATTR emsuart_tx_timer_intr_handler();
|
|
||||||
static bool sending_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace emsesp
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user