#ifndef _DAC_H_
#define _DAC_H_
//----------------------------------------------------------------------------
///
/// \brief  DAC
///
///         See implementation files for further information.
//
/// \date   20150117
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#if defined MCU_PLATFORM_STM32
   #include <HALWrapper/stm32_dma.h>       // dac wants that
   #include <HALWrapper/stm32_dac.h>
#endif


// Some STM32F0s just dont have DAC
#if ! defined DAC_CHANNEL_1
   #define DAC_HandleTypeDef    void
   #define DAC_TypeDef    void
#endif

#include <biwak/biwak.h>
#include <biwak/gpio.hpp>
#include <biwak/timer.hpp>
#include <lepto/signal.h>


//---Defines------------------------------------------------------------------



//---Declaration--------------------------------------------------------------


enum EDacChannel
{
   eDacChannel1,
   eDacChannel2,
   eDacChannelMax,
};

class CDac;
    
struct SDacConfig;

class CDmaChannel;

extern const CDac* interruptDac1;
extern const CDac* interruptDac2;


class CDac
      //:public CGpio
{
   friend class CDacChannel;
   friend class CDacLineDma;

   private:
      DAC_HandleTypeDef *m_pHandle;

   public:
      
      CSignal <void> signalConvCompleted;

      CDac( const SDacConfig &dacConfig
            /*, EGpioPeripheral _eGpioPeripheral1, EGpioPin _eGpioPin1
                  , CDmaChannel *dmaChannel1, ETimer _eTimer1
                  , EGpioPeripheral _eGpioPeripheral2, EGpioPin _eGpioPin2
                  , CDmaChannel *dmaChannel2, ETimer _eTimer2 */
            );
      void init();
      ~CDac();

      DAC_HandleTypeDef *getHandle() const
      {
         return(m_pHandle);
      }
      void restart();
      void start(EDacChannel eDacChannel, void *buffer, int bufferSize);
      void stop();
};

class CDacChannel
{
   friend class CDacLineDma;
   
   private:
      CDac &m_pDac;
      EDacChannel m_eDacChannel;
      CGpio m_gpio;
      int m_state=0;

   public:
      CDacChannel(CDac &pDac, EDacChannel eDacChannel
               , EGpioPeripheral _eGpioPeripheral1, EGpioPin _eGpioPin1);
      void init(int trigger);
      void setValue(int value);
      const EDacChannel getChannel()
      {
         return(m_eDacChannel);
      }
      CDac &dac()
      {
         return(m_pDac);
      }
};

// #endif // ? SUPPORT_DAC

//---fin----------------------------------------------------------------------
#endif // ? ! _DAC_H_
