// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved


// This software makes use of tools and libraries obtained from open source projects or released for

// use by relevant hardware manufactures. However, this software is NOT a part of any open source project.

// It is released only on a "need to know" basis for beta testers of the "RiceCNC Interpolation Engine".

// Recipents of this source code must respect the confidential nature of this software and prevent any

// distribution that could result in counterfeit copies of the "RiceCNC Interpolation Engine".


// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved

#include <SSI8711.h>

#include <SsiDeviceQueue.h>

#include <Machine.h>

#include <AxisTimer.h>

#include <OutputPin.h>

#include <Timers.h>


#include <inc/hw_ssi.h>

#include <inc/hw_gpio.h>

#include <driverlib/ssi.h>



SSI8711::SSI8711(

     char*          data,

     String*          msgPtr )


     :     SSI(

               data,

               msgPtr ) {


     resetPin          = NULL;

     sleepPin          = NULL;

     directionPin     = NULL;

     stepPin               = NULL;


     if ( ! configured )

          return;


     char    sleepPinString          [8];

     char    resetPinString      [8];

     char    directionPinString     [8];

     char    stepPinString          [8];


     sscanf( data + parseLength + 1,

          " %s %s %s %s",

          sleepPinString,

          resetPinString,

          directionPinString,

          stepPinString );


     *msgPtr               += "\n Reset";

     resetPin          = new OutputPin(

          resetPinString,

          msgPtr );

     if ( ! resetPin->valid() )

          return;

     resetPin->fmtPin( msgPtr );

     resetPin->setPin( true );


     *msgPtr               += "\n Sleep";

     sleepPin          = new OutputPin(

          sleepPinString,

          msgPtr );

     if ( ! sleepPin->valid() )

          return;

     sleepPin->fmtPin( msgPtr );

     sleepPin->setPin( false );


     *msgPtr               += "\n Dir";

     directionPin     = new OutputPin(

          directionPinString,

          msgPtr );

     if ( ! directionPin->valid() )

          return;

     directionPin->fmtPin( msgPtr );

     directionPin->setPin( false );


     *msgPtr               += "\n Step";

     stepPin               = new OutputPin(

          stepPinString,

          msgPtr );

     if ( ! stepPin->valid() )

          return;

     stepPin->fmtPin( msgPtr );

     stepPin->setPin( false );


     configureSSI( TI_8711_Protocol );

  

     resetPin->setPin( false ); // release reset


     snprintf( data, 40,

          "\n SSI %lu configured for BOOST-DRV8711\n",

          number );

     *msgPtr     += String( data );


     configured     = true; };


SSI8711::~SSI8711() {

     if ( resetPin )

          delete resetPin;


     if ( sleepPin )

          delete sleepPin;


     if ( directionPin )

          delete directionPin;


     if ( stepPin )

          delete stepPin; };