Added all required GPIOs

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@242 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-06 12:08:24 +00:00
parent f9b2cda7f8
commit e54e15da18
10 changed files with 426 additions and 256 deletions

View File

@@ -62,11 +62,20 @@ static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length
ErrorStatus GPIO_construct(struct Gpio* self, GpioDirection direction, T_PL_GPIO io)
{
ErrorStatus returnValue = SUCCESS;
returnValue = IODevice_construct(&self->device, read, write);
self->direction = direction;
self->gpio = io;
if (!self->initialized)
{
returnValue = IODevice_construct(&self->device, read, write);
if (returnValue == SUCCESS)
{
self->direction = direction;
self->gpio = io;
self->initialized = true;
}
}
else
{
returnValue = ERROR;
}
return returnValue;
@@ -76,29 +85,34 @@ ErrorStatus GPIO_construct(struct Gpio* self, GpioDirection direction, T_PL_GPIO
ErrorStatus GPIO_setValue(struct Gpio* self, bool value)
{
ErrorStatus returnValue = SUCCESS;
if (self->direction == OUTPUT)
if (self->initialized)
{
// Writing to output is valid
if (value)
if (self->direction == OUTPUT)
{
// Writing to output is valid
if (value)
{
GPIO_SetBits(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin);
self->status = true;
}
else
{
GPIO_SetBits(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin);
self->status = true;
{
GPIO_ResetBits(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin);
self->status = false;
}
}
}
else
{
{
GPIO_ResetBits(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin);
self->status = false;
}
// Writing to input is invalid
returnValue = ERROR;
}
}
else
{
// Writing to input is invalid
returnValue = ERROR;
}
return returnValue;
}
@@ -106,35 +120,41 @@ ErrorStatus GPIO_setValue(struct Gpio* self, bool value)
ErrorStatus GPIO_getValue(struct Gpio* self, bool* value)
{
ErrorStatus returnValue = SUCCESS;
if (self->direction == OUTPUT)
if (self->initialized)
{
// Reading an output is impossible - but returning its current status is valid
if(GPIO_ReadOutputDataBit(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin) != 0)
if (self->direction == OUTPUT)
{
*value = true;
self->status = true;
// Reading an output is impossible - but returning its current status is valid
if(GPIO_ReadOutputDataBit(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin) != 0)
{
*value = true;
self->status = true;
}
else
{
*value = false;
self->status = false;
}
}
else
{
*value = false;
self->status = false;
// Read value on input
if(GPIO_ReadInputDataBit(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin) != 0)
{
*value = true;
self->status = true;
}
else
{
*value = false;
self->status = false;
}
}
}
else
{
// Read value on input
if(GPIO_ReadInputDataBit(self->gpio.GPIO_Typedef, self->gpio.GPIO_InitStruct.GPIO_Pin) != 0)
{
*value = true;
self->status = true;
}
else
{
*value = false;
self->status = false;
}
returnValue = ERROR;
}
return returnValue;