Skip to content

Commit

Permalink
Fix for GPIO pulsating on repeated Activate calls
Browse files Browse the repository at this point in the history
The problem is when "out" is written to the direction file in the sysfs,
the Linux kernel will overwrite the current value of the GPIO
and set it low. Legato will then continue to set the GPIO high.
The net result is that there is a very brief low pulse on the GPIO if
it is already set as an output, and is set high.
The fix is to skip writing the direction to the file, if the direction
is already correct.

Resolves: LE-13244
Change-Id: If408e5af608bcc255c76a07d2bcc232a383f42a2
(cherry picked from commit 5e715d7)
  • Loading branch information
stan-podin authored and nushcone committed Oct 22, 2019
1 parent e52376c commit a9b8edb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions components/sysfsGpio/gpioSysfsUtils.c
Expand Up @@ -394,13 +394,21 @@ static le_result_t SetDirection
{
char path[64];
const char *attr;
gpioSysfs_PinMode_t currentMode;

if ((!gpioRef) || (gpioRef->pinNum == 0))
{
LE_ERROR("gpioRef is NULL or object not initialized");
return LE_BAD_PARAMETER;
}

currentMode = (gpioSysfs_IsInput(gpioRef)) ? SYSFS_PIN_MODE_INPUT : SYSFS_PIN_MODE_OUTPUT;
if (currentMode == mode)
{
// Direction is already correct, don't do anything.
return LE_OK;
}

snprintf(path, sizeof(path), "%s/%s%s/%s", SYSFS_GPIO_PATH, GpioAliasesPath,
gpioRef->gpioName, "direction");
attr = (mode == SYSFS_PIN_MODE_OUTPUT) ? "out": "in";
Expand Down

0 comments on commit a9b8edb

Please sign in to comment.