pic32/libraries/SoftPWMServo/SoftPWMServo.cpp
// Enable SoftPWM functionality on a particular pin number
Enable SoftPWM functionality on a particular pin number
Enable SoftPWM functionality on a particular pin number
int32_t SoftPWMServoPinEnable(uint32_t Pin, bool PinType)
{
    if (Pin >= SOFTPWMSERVO_MAX_PINS)
    {
        return SOFTPWMSERVO_ERROR;
    }
    if (Chan[InactiveBuffer][Pin].SetPort == NULL)
    {
        pinMode(Pin, OUTPUT);                                      
        digitalWrite(Pin, LOW);                                    
        Chan[InactiveBuffer][Pin].NextEdgeTime = 0;                
        Chan[InactiveBuffer][Pin].Port = digitalPinToPort(Pin);    
        Chan[InactiveBuffer][Pin].Bit = digitalPinToBitMask(Pin);  
        Chan[InactiveBuffer][Pin].SetPort = portOutputRegister(Chan[InactiveBuffer][Pin].Port) + 2; 
        Chan[InactiveBuffer][Pin].ClearPort = portOutputRegister(Chan[InactiveBuffer][Pin].Port) + 1; 
        Chan[InactiveBuffer][Pin].PWMValue = 0;                    
        Chan[InactiveBuffer][Pin].IsServo = PinType;               
        Chan[InactiveBuffer][Pin].NextChanP = NULL;                
        Chan[ActiveBuffer][Pin].NextEdgeTime = 0;                  
        Chan[ActiveBuffer][Pin].Port = digitalPinToPort(Pin);    
        Chan[ActiveBuffer][Pin].Bit = digitalPinToBitMask(Pin);  
        Chan[ActiveBuffer][Pin].SetPort = portOutputRegister(Chan[InactiveBuffer][Pin].Port) + 2;
        Chan[ActiveBuffer][Pin].ClearPort = portOutputRegister(Chan[InactiveBuffer][Pin].Port) + 1;
        Chan[ActiveBuffer][Pin].PWMValue = 0;                    
        Chan[InactiveBuffer][Pin].IsServo = PinType;
        Chan[ActiveBuffer][Pin].NextChanP = NULL;                
    }
    return SOFTPWMSERVO_OK;
}
int32_t SoftPWMServoPinEnable ( uint32_t Pin , bool PinType ) { if ( Pin >= SOFTPWMSERVO_MAX_PINS ) { return SOFTPWMSERVO_ERROR ; } if ( Chan [ InactiveBuffer ] [ Pin ] . SetPort == NULL ) { pinMode ( Pin , OUTPUT ) ; digitalWrite ( Pin , LOW ) ; Chan [ InactiveBuffer ] [ Pin ] . NextEdgeTime = 0 ; Chan [ InactiveBuffer ] [ Pin ] . Port = digitalPinToPort ( Pin ) ; Chan [ InactiveBuffer ] [ Pin ] . Bit = digitalPinToBitMask ( Pin ) ; Chan [ InactiveBuffer ] [ Pin ] . SetPort = portOutputRegister ( Chan [ InactiveBuffer ] [ Pin ] . Port ) + 2 ; Chan [ InactiveBuffer ] [ Pin ] . ClearPort = portOutputRegister ( Chan [ InactiveBuffer ] [ Pin ] . Port ) + 1 ; Chan [ InactiveBuffer ] [ Pin ] . PWMValue = 0 ; Chan [ InactiveBuffer ] [ Pin ] . IsServo = PinType ; Chan [ InactiveBuffer ] [ Pin ] . NextChanP = NULL ; Chan [ ActiveBuffer ] [ Pin ] . NextEdgeTime = 0 ; Chan [ ActiveBuffer ] [ Pin ] . Port = digitalPinToPort ( Pin ) ; Chan [ ActiveBuffer ] [ Pin ] . Bit = digitalPinToBitMask ( Pin ) ; Chan [ ActiveBuffer ] [ Pin ] . SetPort = portOutputRegister ( Chan [ InactiveBuffer ] [ Pin ] . Port ) + 2 ; Chan [ ActiveBuffer ] [ Pin ] . ClearPort = portOutputRegister ( Chan [ InactiveBuffer ] [ Pin ] . Port ) + 1 ; Chan [ ActiveBuffer ] [ Pin ] . PWMValue = 0 ; Chan [ InactiveBuffer ] [ Pin ] . IsServo = PinType ; Chan [ ActiveBuffer ] [ Pin ] . NextChanP = NULL ; } return SOFTPWMSERVO_OK ; }
Enable SoftPWM functionality on a particular pin number
Enable SoftPWM functionality on a particular pin number
// If user has not already enabled this pin for SoftPWM, then initialize it // Set up this pin's  // set servo pin to output // Always start out low // Computed on the fly in the ISR // Set up our bit and port so we don't have to //  do it inside the ISR. // +2 is PORTxSET // +1 is PORTxCLR // Start out with zero PWM time (always off) // Set the type for this pin (servo vs PWM) // Add() will set this // Now also do the same thing in the other buffer