Choco OS  V.0.16.9.0
Join to the chocolate world
(GPIO-LLD) General Purpose Input-Output Low Level Driver

Input/Output basic operations managing. More...

The driver is for managing and configuring all operations that handles basic operations that are based on the ports/pins of the machine. It supports configuration, handle pins usage (it stores informations about each pin that was used in the system), provide an interface to get printable pin and more.
All operations are based on basic definitions of the port: #oC_Port_t and #oC_Pins_t. The first type stores information about the port from which the pin come. The second type is for storing pin or more pins from the same port. To get port from the pins variable use #oC_GPIO_LLD_GetPortOfPins function. Note, that you can assign more pins from one port in one variable by using 'OR' operations, such in the example below:
oC_Pins_t pins = oC_Pins_PA2 | oC_Pins_PA3;
It provide also an interface for verification if the channel, port or pin is correct. You can use the following functions for it:
The driver also provides an interface for reading names of port or pins. There are two functions for it: #oC_GPIO_LLD_GetPortName, #oC_GPIO_LLD_GetPinName. This feature can be useful for example in case, when the configuration of GPIO should be printed to the STDOUT.
There are also functions, that helps to configure the driver to work, such as #oC_GPIO_LLD_SetDriverInterruptHandler. The function helps to configure an interrupt handler, that is common for all driver events. Each time, when there will be some interrupt on some port, this function will be called with source of the interrupt passed in function arguments.
Main purpose of this module is configuration of pins. There are few functions that helps to achieve it, but there must be used properly. Most of operations that changes port configurations require additional operations before any changes, such as turning on power, disable pin works, etc. Because of that, there are additional functions: #oC_GPIO_LLD_BeginConfiguration and #oC_GPIO_LLD_FinishConfiguration that should be called before and after any changes. It is required to call it only once before and after configuration. After it is possible to configure more parameters without second call of #oC_GPIO_LLD_BeginConfiguration function for the same port until the #oC_GPIO_LLD_FinishConfiguration is called.
Note
Not all functions require calls of #oC_GPIO_LLD_BeginConfiguration and #oC_GPIO_LLD_FinishConfiguration. To get to know if some function need it, check its documentation.
Generally most of functions that sets some configuration parameter require to preparation and finishing and read functions does not.
The driver provide an interface for marking pins as used or not. In the LLD layer this is only an additional feature, and it is protection against reconfiguration, because none of the driver functions checks it. The driver, that use this module should also use an interface for marking the pin as used for protection. To get more information look at function: #oC_GPIO_LLD_SetPinUsed, #oC_GPIO_LLD_SetPinUnused and #oC_GPIO_LLD_CheckIsPinUsed.
If you want to set a state on pin(s), you have few functions that makes it more comfortable. The #oC_GPIO_LLD_WriteData function is for situation, when you are using more pins in a port, and you need to set different states for each one. For example:
oC_Pins_t pins = oC_Pins_AllInPORTA;
oC_GPIO_LLD_WriteData( pins , 0xAA ); // now pins on this port are set to 0xAA value
oC_GPIO_LLD_WriteData( pins , 0x0C ); // now pins on this port are set to 0x0C value
oC_GPIO_LLD_SetPinsState( pins , oC_GPIO_LLD_PinsState_AllHigh ); // pins on this port are set to 0xFF
oC_GPIO_LLD_SetPinsState( pins , oC_GPIO_LLD_PinsState_AllLow ); // pins on this port are set to 0x00
oC_GPIO_LLD_SetPinsState( oC_Pins_PA2 , oC_GPIO_LLD_PinsState_AllHigh ); // only PA2 from the PORTA is set to high
oC_GPIO_LLD_TogglePinsState( pins ); // only PA2 from the PORTA is set to low, the other pins in this port are set to high
In the same way there is a possible to read value from pins in the given port by using #oC_GPIO_LLD_ReadData function. Note, that these functions reads and writes only value for pins that are set in the Pins argument, and that it also checks if arguments that are given to the function are correct. It is safe way to manage pins data, but it is recommended for time critical operations to use #oC_GPIO_LLD_SetPinsState, #oC_GPIO_LLD_GetLowStatePins and #oC_GPIO_LLD_GetHighStatePins functions, which should be little faster, and can be more comfortable in few cases. For example, when you expect, that all pins that are defined in the variable are set to high state, you can use #oC_GPIO_LLD_IsPinsState function, such in an example below:
if ( oC_GPIO_LLD_IsPinsState( oC_Pins_PA2 , oC_GPIO_LLD_PinsState_AllHigh ) )
{
// PA2 is set to high state
}
else
{
// PA2 is set to low state
}
Warning
The function #oC_GPIO_LLD_IsPinsState is fast, but it not checks if the given argument is correct. It should be used only when it is certain that pins are correct.