I have several "modes" of operation. One mode requires PB5 to be T1CCP1 and output a 1 ms pulse with 1/10th pulse width. Another mode requires PB5 to be a GPIO input. There could be three or four different modes of operation, each using the pin in different ways. My code includes a finite state machine mechanism to do Setup, Operation, and Tear Down of each mode.
When entering the mode that uses PB5 as T1CCP1, the Setup code does this:
// Set GPIO mux to Timer
GPIOPinConfigure(GPIO_PB5_T1CCP1);
// Set pin type to CCP
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5);
// Configure timer as 16-bit periodic
TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);
// Set PWM period
TimerLoadSet(TIMER1_BASE, TIMER_B, 40000);
// Set pulse width
TimerMatchSet(TIMER1_BASE, TIMER_B, 4000);
// Enable Timer
TimerEnable(TIMER1_BASE, TIMER_B);
This works. Now I'm trying to do the Tear Down code to put the pin back into its original state before calling the Setup code of a different mode. So far, I have only this:
// Disable Timer
TimerDisable(TIMER1_BASE, TIMER_B);
// Set pin type to GPIO
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_5);
I need the equivalent of a TimerUnconfigure() to tear down the timer setup and GPIOPinConfigure(GPIO_PB5_GPIO) to un-mux the pin from the timer. But there is no function TimerUnconfigure() or equivalent, and there is no GPIO_PB5_GPIO or equivalent define that can be passed to GPIOPinConfigure() to reverse the action of GPIOPinConfigure(GPIO_PB5_T1CCP1).
How can I go about tearing down this setup so that each mode can be entered and exited numerous times, and leave the pin in a consistent state after tear down, without requiring a complete system reset?