#ifndef ADCCLASS_SCOPE_H
#define ADCCLASS_SCOPE_H
#include <stdint.h>
#include "samplering.h"
#include "gpio.h"

/** @file
 *  @brief A/D převodník.
 * */

/**
 * @class AdcClass
 * @brief A/D převodník. 
 * 
 * Výhradně pro projekt osciloskopu.
 * Původně to bylo pro STM32L452, ale v podstatě je to stejné pro CH32V203.
 * Tedy deklarace třídy, nikoli její definice.
 * */

class AdcClass {
  public:
    AdcClass(SampleRing & r) : ring(r), led(GPIOA, 1), ptrl (buffer), ptrh (buffer + DATA_HALF_LEN) {
    };
    /**
     * @brief Inicializace ADC.
     * 
     * Včetně vstupů.
     * 
     */
    void     Init    ();
    DATA_BLOCK * setPtrH    (const int n) {
      if (n) { ptrh = buffer + 1;
      } else { ptrh = buffer + DATA_HALF_LEN; }
      return buffer;
    }
  public: // UNUSABLE
    void drq ();                        //!< obsluha přerušení, interní metoda, ale musí mít public atribut
  private:
    SampleRing & ring;
    GpioClass    led;
    DATA_BLOCK * ptrl;
    DATA_BLOCK * ptrh;
    [[gnu::aligned(4)]]DATA_BLOCK   buffer [DATA_FULL_LEN];  //!< data
};

#endif // ADCCLASS_SCOPE_H