//-----------------------------------------------------------------------------
///
/// \brief  Shift register; Piso or Sipo
///
///         Parallel input / Serial output
///         Serial input / Parallel output
///
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//-----------------------------------------------------------------------------


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


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

#include <biwak/biwak.h>
#include <biwak/shift.h>
#include <biwak/timer.hpp>

#define SHIFT_REGISTER_CLOCK_DELAY     0


//---Implementation------------------------------------------------------------

CShift::CShift( EGpioPeripheral peripheralClk, EGpioPin pinClk,
        EGpioPeripheral peripheralData, EGpioPin pinData,
        EGpioPeripheral peripheralStore, EGpioPin pinStore,
        int _bitCount /* = 32 */
        )
         :gpioClk(peripheralClk, pinClk) // , gpioModeOutput
         ,gpioData(peripheralData, pinData, gpioModeOutput)
         ,gpioStore(peripheralStore, pinStore) // , gpioModeOutput
         ,bitCount(_bitCount)
{

}


void CShift::setOutput(int data)
{
   for(int i1=1; i1 <= bitCount; i1++)
   {
      gpioData.setValue( ( data >> ( bitCount - i1 ) ) & 1 );
      gpioClk.switchOn();
      //delay( SHIFT_REGISTER_CLOCK_DELAY );
      gpioClk.switchOff();
      //delay( SHIFT_REGISTER_CLOCK_DELAY );
   }

   gpioStore.switchOn();
   //delay( SHIFT_REGISTER_CLOCK_DELAY );
   gpioStore.switchOff();
   //delay( SHIFT_REGISTER_CLOCK_DELAY );

   return;
}

//---fin-----------------------------------------------------------------------
