pic32/libraries/SoftPWMServo/SoftPWMServo.cpp
// Initialize all static variables to default state
// Insert SoftPWM ISR into Core Timer ISR
Initialize all static variables to default state
Insert SoftPWM ISR into Core Timer ISR
Initialize all static variables to default state Insert SoftPWM ISR into Core Timer ISR
int32_t SoftPWMServoInit(void)
{
    uint32_t i, j;
    for (j = 0; j < 2; j++)
    {
        for (i = 0; i < SOFTPWMSERVO_MAX_PINS; i++)
        {
            Chan[j][i].NextEdgeTime = 0;
            Chan[j][i].SetPort = NULL;
            Chan[j][i].ClearPort = NULL;
            Chan[j][i].Port = 0;
            Chan[j][i].Bit = 0;
            Chan[j][i].PWMValue = 0;
            Chan[j][i].IsServo = false;
            Chan[j][i].NextChanP = NULL;
        }
        FirstChanP[j] = NULL;
    }
    RisingEdge = true;
    CurrentTime = 0;
    InactiveBuffer = 1;
    ActiveBuffer = 0;
    ISRFirstChanP = NULL;
    InactiveBufferReady = false;
    FrameTime = SOFTPWMSERVO_DEFAULT_FRAME_TIME;        
    ServoFrames = SOFTPWMSERVO_DEFAULT_SERVO_FRAMES;    
    if (attachCoreTimerService(HandlePWMServo))
    {
        Initalized = true;
        return SOFTPWMSERVO_OK;
    }
    else
    {
        Initalized = false;
        return SOFTPWMSERVO_ERROR;
    }
}
int32_t SoftPWMServoInit ( void ) { uint32_t i , j ; for ( j = 0 ; j < 2 ; j ++ ) { for ( i = 0 ; i < SOFTPWMSERVO_MAX_PINS ; i ++ ) { Chan [ j ] [ i ] . NextEdgeTime = 0 ; Chan [ j ] [ i ] . SetPort = NULL ; Chan [ j ] [ i ] . ClearPort = NULL ; Chan [ j ] [ i ] . Port = 0 ; Chan [ j ] [ i ] . Bit = 0 ; Chan [ j ] [ i ] . PWMValue = 0 ; Chan [ j ] [ i ] . IsServo = false ; Chan [ j ] [ i ] . NextChanP = NULL ; } FirstChanP [ j ] = NULL ; } RisingEdge = true ; CurrentTime = 0 ; InactiveBuffer = 1 ; ActiveBuffer = 0 ; ISRFirstChanP = NULL ; InactiveBufferReady = false ; FrameTime = SOFTPWMSERVO_DEFAULT_FRAME_TIME ; ServoFrames = SOFTPWMSERVO_DEFAULT_SERVO_FRAMES ; if ( attachCoreTimerService ( HandlePWMServo ) ) { Initalized = true ; return SOFTPWMSERVO_OK ; } else { Initalized = false ; return SOFTPWMSERVO_ERROR ; } }
Initialize all static variables to default state
Insert SoftPWM ISR into Core Timer ISR
Initialize all static variables to default state Insert SoftPWM ISR into Core Timer ISR
// Initialize all of our static arrays // Start out with default 2ms frame time // Start out with default of 10 frames (20ms) // Insert our ISR handler, if it's not already there