Customize it to fit the hardware.

This commit is contained in:
Attila Body 2025-06-05 12:57:11 +02:00
parent 381c994449
commit afd998adb6
Signed by: abody
GPG key ID: BD0C6214E68FB5CF
5 changed files with 24 additions and 14 deletions

View file

@ -7,6 +7,7 @@
#include "opentherm.h"
#include "esp_log.h"
#include "hal/gpio_types.h"
#include "rom/ets_sys.h"
#include <stdio.h>
@ -58,7 +59,7 @@ esp_err_t esp_ot_init(
io_conf.pin_bit_mask = (1ULL << pin_in);
io_conf.intr_type = GPIO_INTR_ANYEDGE;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
gpio_config(&io_conf);
io_conf.mode = GPIO_MODE_OUTPUT;
@ -385,11 +386,15 @@ float esp_ot_get_slave_ot_version()
*
* @return void
*/
#define OT_INPUT_ACTIVE 0
#define OT_INPUT_INACTIVE 1
void IRAM_ATTR esp_ot_handle_interrupt()
{
// ESP_DRAM_LOGI("esp_ot_handle_interrupt", "%ld", status);
if (esp_ot_is_ready()) {
if (esp_ot_is_slave && esp_ot_read_state() == 1) {
if (esp_ot_is_slave && esp_ot_read_state() == OT_INPUT_ACTIVE) {
esp_ot_status = OT_RESPONSE_WAITING;
} else {
return;
@ -398,7 +403,7 @@ void IRAM_ATTR esp_ot_handle_interrupt()
unsigned long newTs = esp_timer_get_time();
if (esp_ot_status == OT_RESPONSE_WAITING) {
if (esp_ot_read_state() == 1) {
if (esp_ot_read_state() == OT_INPUT_ACTIVE) {
// ESP_DRAM_LOGI("BIT", "Set start bit");
esp_ot_status = OT_RESPONSE_START_BIT;
esp_ot_response_timestamp = newTs;
@ -408,7 +413,7 @@ void IRAM_ATTR esp_ot_handle_interrupt()
esp_ot_response_timestamp = newTs;
}
} else if (esp_ot_status == OT_RESPONSE_START_BIT) {
if ((newTs - esp_ot_response_timestamp < 750) && esp_ot_read_state() == 0) {
if ((newTs - esp_ot_response_timestamp < 750) && esp_ot_read_state() == OT_INPUT_INACTIVE) {
esp_ot_status = OT_RESPONSE_RECEIVING;
esp_ot_response_timestamp = newTs;
esp_ot_response_bit_index = 0;
@ -419,7 +424,7 @@ void IRAM_ATTR esp_ot_handle_interrupt()
} else if (esp_ot_status == OT_RESPONSE_RECEIVING) {
if ((newTs - esp_ot_response_timestamp) > 750) {
if (esp_ot_response_bit_index < 32) {
response = (response << 1) | !esp_ot_read_state();
response = (response << 1) | (esp_ot_read_state() == OT_INPUT_INACTIVE);
esp_ot_response_timestamp = newTs;
esp_ot_response_bit_index++;
} else { // stop bit