// (C) 2026 Philip Endecott.
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENCE.txt or copy at https://www.boost.org/LICENSE_1_0.txt

#ifndef lipstick_opentherm_hh
#define lipstick_opentherm_hh

#include "power.hh"

#include <cstdint>


namespace opentherm {

constexpr auto power_bits = PCTIM1;

void setup();

__attribute__((interrupt("IRQ")))
__attribute__((target("arm")))
void timer_irq_handler();

void start_sync_process();

//void handle_interrupt(uint8_t interrupt_bits);


uint16_t get_register(uint16_t address);

void set_register(uint16_t address, uint16_t value);

enum Register: uint16_t {
  // These registers are writable with set_register() above:
  ch_enable,             // 0 = off, 1 = on.
  ch_flow_target_temp,
  dhw_target_temp,

  // These are readable with get_register() above:
  ch_flow_temp,
  ch_return_temp,
  outside_temp,
  ch_pressure,

  // The temperatures and pressure are in fixed point decimal with 
  // one decimal place, e.g. 256 = 25.6 degrees, 17 = 1.7 bar.
};


}; // namespace opentherm

#endif

