Skip to content

Commit 5bc04ed

Browse files
authored
Various fixes with GPIO (#2548)
***NO_CI***
1 parent ccf53ec commit 5bc04ed

File tree

1 file changed

+13
-37
lines changed
  • targets/TI_SimpleLink/_nanoCLR/System.Device.Gpio

1 file changed

+13
-37
lines changed

targets/TI_SimpleLink/_nanoCLR/System.Device.Gpio/cpu_gpio.cpp

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,12 @@ void UnlinkInputState(gpio_input_state *pState)
133133

134134
// Remove interrupt associated with pin
135135
// it's OK to do always this, no matter if interrupts are enabled or not
136-
GPIO_disableInt(pState->pinConfigIndex);
137-
138-
// disable pin
139-
GPIO_setConfig(pState->pinConfigIndex, GPIO_CFG_NO_DIR);
140136

141137
// clear pin config array
142138
gpioPinConfigs[pState->pinConfigIndex] = GPIO_CFG_NO_DIR;
143139

144-
// remove callback
145-
gpioCallbackFunctions[pState->pinConfigIndex] = NULL;
140+
// reset pin
141+
GPIO_resetConfig(pState->pinConfigIndex);
146142

147143
// unlink from list
148144
pState->Unlink();
@@ -270,11 +266,11 @@ bool CPU_GPIO_Uninitialize()
270266
continue;
271267
}
272268

273-
// set config
274-
GPIO_setConfig(index, GPIO_CFG_NO_DIR);
275-
276269
// store config
277270
gpioPinConfigs[index] = GPIO_CFG_NO_DIR;
271+
272+
// reset pin
273+
GPIO_resetConfig(index);
278274
}
279275

280276
return true;
@@ -342,20 +338,15 @@ bool CPU_GPIO_EnableInputPin(
342338
return false;
343339
}
344340

345-
// check if pin is already in use
346-
if (CPU_GPIO_PinIsBusy(pinNumber))
347-
{
348-
return false;
349-
}
350-
351341
pState = AllocateGpioInputState(pinNumber);
352342

353343
// store index of this GPIO
354344
pState->pinConfigIndex = pinNumber;
355345

356346
// set default input config for GPIO pin
357-
gpioPinConfigs[pState->pinConfigIndex] |=
358-
GPIO_CFG_INPUT_INTERNAL | GPIO_CFG_IN_INT_NONE | GPIO_CFG_PULL_NONE_INTERNAL;
347+
gpioPinConfigs[pState->pinConfigIndex] = GPIO_CFG_INPUT | GPIO_CFG_IN_INT_NONE;
348+
349+
GPIO_setConfig(pState->pinConfigIndex, gpioPinConfigs[pState->pinConfigIndex]);
359350

360351
if (!CPU_GPIO_SetDriveMode(pState->pinConfigIndex, driveMode))
361352
{
@@ -366,16 +357,11 @@ bool CPU_GPIO_EnableInputPin(
366357
// CPU_GPIO_EnableInputPin could be called a 2nd time with changed parameters
367358
if (pinISR != NULL && (pState->isrPtr == NULL))
368359
{
369-
// get current config
370-
GPIO_PinConfig currentPinConfig;
371-
GPIO_getConfig(pState->pinConfigIndex, &currentPinConfig);
372-
373-
// set interrupt on both edges
374-
GPIO_setConfig(pState->pinConfigIndex, currentPinConfig | GPIO_CFG_IN_INT_BOTH_EDGES);
375360
// set callback
376361
GPIO_setCallback(pState->pinConfigIndex, GpioEventCallback);
377-
// enable INT
378-
GPIO_enableInt(pState->pinConfigIndex);
362+
363+
// set interrupt on both edges and enable interrupt
364+
GPIO_setInterruptConfig(pState->pinConfigIndex, GPIO_CFG_IN_INT_BOTH_EDGES | GPIO_CFG_INT_ENABLE);
379365

380366
// store parameters & configs
381367
pState->isrPtr = pinISR;
@@ -430,16 +416,10 @@ bool CPU_GPIO_EnableInputPin(
430416
// there is no managed handler setup anymore
431417
// remove INT handler
432418

433-
// get current config
434-
GPIO_PinConfig currentPinConfig;
435-
GPIO_getConfig(pState->pinConfigIndex, &currentPinConfig);
436-
437419
// disable interrupt
438420
GPIO_disableInt(pState->pinConfigIndex);
439421
// remove callback
440422
GPIO_setCallback(pState->pinConfigIndex, NULL);
441-
// remove interrupt config
442-
GPIO_setConfig(pState->pinConfigIndex, currentPinConfig | GPIO_CFG_IN_INT_NONE);
443423

444424
// clear parameters & configs
445425
pState->isrPtr = NULL;
@@ -477,6 +457,8 @@ bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, Pin
477457
// set the GPIO pin as output
478458
gpioPinConfigs[pinNumber] = GPIO_CFG_OUT_STD;
479459

460+
GPIO_setConfig(pinNumber, gpioPinConfigs[pinNumber]);
461+
480462
if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false)
481463
{
482464
return false;
@@ -491,12 +473,6 @@ void CPU_GPIO_DisablePin(GPIO_PIN pinNumber, PinMode driveMode, uint32_t alterna
491473
{
492474
GLOBAL_LOCK();
493475

494-
// check if pin is already in use
495-
if (CPU_GPIO_PinIsBusy(pinNumber))
496-
{
497-
return;
498-
}
499-
500476
DeleteGpioInputState(pinNumber);
501477

502478
CPU_GPIO_SetDriveMode(pinNumber, driveMode);

0 commit comments

Comments
 (0)