/* Fail if cannot open timer */
if (hTimer == NULL)
{
Log_error2("PWM_open(%x): Timer unit (%d) already in use.", (UArg) handle, hwAttrs->gpTimerUnit);
object->isOpen = false;
return NULL;
}
/* Open pin resource */
PIN_Config pinConfig;
/* Initial open of pin handle with no pins in it. Should never fail. */
if (hPins == NULL)
{
pinConfig = PIN_TERMINATE;
hPins = PIN_open(&pinState, &pinConfig);
}
/* Invert PWM idle level since pin output is inverted */
uint32_t idleLevel = PIN_GPIO_HIGH;
if (params->idleLevel == PWM_IDLE_HIGH)
{
idleLevel = PIN_GPIO_LOW;
}
/* Generate pin config for PWM pin.
* Output is inverted to make PWM duty calculations independent of period
*/
pinConfig = hwAttrs->pwmPin | PIN_INPUT_DIS | PIN_GPIO_OUTPUT_EN | idleLevel |
PIN_INV_INOUT | PIN_PUSHPULL | PIN_DRVSTR_MAX;
/* Fail if cannot add pin */
if (PIN_add(hPins, pinConfig) != PIN_SUCCESS)
{
Log_error2("PWM_open(%x): PIN (%d) already in use.", (UArg) handle, hwAttrs->pwmPin);
GPTimerCC26XX_close(hTimer);
object->isOpen = false;
return NULL;
}
/* Corner case: If using duty unit PWM_DUTY_FRACTION or PWM_DUTY_US with
value 0, then duty is already set by setPeriod. Skip if so. */
PWM_Duty_Units unit = object->dutyUnit;
uint32_t value = object->dutyValue;