// © 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 <OutputPin.h>

#include <Timers.h>

#include <ADC.h>

#include <Spindle.h>


// derived classes

#include <PwmOutputPin.h>


#include "inc/hw_adc.h"

#include "driverlib/adc.h"

#include <inc/hw_gpio.h>



OutputPin::OutputPin(

     char*          data,

     String*          msgPtr )


     :     GpioPin(

          data,

          msgPtr ) {


     if ( valid() ) {

          ROM_GPIOPinTypeGPIOOutput(

               gpioBase,

               mask );

  

          uint32_t type          = GPIO_PIN_TYPE_STD;

          uint32_t strength     = GPIO_STRENGTH_2MA;


          switch ( driveCurrent ) {

               case '0' :

               type          = GPIO_PIN_TYPE_OD;

               break;


               case '1' :     // 2ma

               break;


               case '2' :

               strength     = GPIO_STRENGTH_4MA;

               break;


               case '3' :

               strength     = GPIO_STRENGTH_8MA; };


          ROM_GPIOPadConfigSet(

               gpioBase,

               mask,

               strength,

               type ); }; };



OutputPin::~OutputPin( void ) {

#ifdef DebugDelete

     Serial.println( " delete OutputPin" );

#endif

};


void

     OutputPin::setPin( bool state ) { // Can be called at interrupt level


     if ( valid() ) {


          uint8_t level     = state ?

               0xFF :

               0;


          if ( activeLow )

               level     = ~level;

          HWREG( pinSelectMask ) = level; }; };


void

     OutputPin::fmtPin( String* msgPtr ) {


     char data[8];

     snprintf( data, 8,

          " P%c%d%c%c",

          portC,

          pin,

          activeMode,

          driveCurrent );


     *msgPtr += String( data ); };


void

     OutputPin::togglePin() {


     if ( valid() )

          // TivaWare doesn't have a toggle command

          HWREG( pinSelectMask ) = ~HWREG( pinSelectMask ); };