#ifndef ARENA_PINMUX_PERIPHERY_HELPER_CPP
#define ARENA_PINMUX_PERIPHERY_HELPER_CPP
//----------------------------------------------------------------------------
///
/// \file   peripheryHelper.h
///
/// \brief  See implementation for further details
///
/// \date   20220202
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Documentation------------------------------------------------------------


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

#include <peripheryHelper.h>

//---General--------------------------


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


const QString getWiring(const CReference &reference)
{
   QString _wiring;
   QString pin;
   QString peripheryName;

   // We want to reconstruct the sub-pins of complex periphery like SPI.
   // So when an periphery like an display consumes an SPI-Bus the pinning is
   // shown completely.
   if(!reference.getPeripheryLink())
   {
      return( QString("No periphery for reference '%1', id %2").arg(reference.getName()).arg(reference.getId()) );
   }

   peripheryName=reference.getPeripheryLink()->getPeripheryName();
   _wiring+=peripheryName;
   pin=reference.getPeripheryLink()->getAttribute("pin");
   if( (!pin.isEmpty()) && (pin!=peripheryName) )
   {
      _wiring+="@"+pin;
   }

   if(!reference.getPeripheryLink()->getConsumesList().empty())
   {
      //_wiring+=reference.getPeripheryType();
      _wiring+="[";
      bool first=true;
      for ( const auto &consumes : reference.getPeripheryLink()->getConsumesListConst() )
      {
         if(!first)
            _wiring+=", ";
         first=false;
         //_wiring+=consumes.getWiring();
         _wiring+=consumes.getName();
         _wiring+="/";
         _wiring+=consumes.getPeripheryLink()->getPeripheryName();
         _wiring+="@";
         QString pin=consumes.getPeripheryLink()->getAttribute( "pin" );
         _wiring+=pin;
      }
      _wiring+="]";
   }
   pin=reference.getAttribute( "pin" );
   //_wiring+=pin;
   _wiring+=" -> ";
   _wiring+=reference.getName();
   if(!pin.isEmpty())
   {
      _wiring+="@";
      _wiring+=pin;
   }
   if(!reference.getAttribute( "comment" ).isEmpty())
   {
      _wiring+="   \"";
      _wiring+=reference.getAttribute( "comment" );
      _wiring+="\"";
   }
   return(_wiring);
}

//---fin----------------------------------------------------------------------
#endif // ? ! ARENA_PINMUX_PERIPHERY_HELPER_CPP
