I am trying to figure out GPIO reads and writes using RTOS, and the documentation and examples are unclear. Reading a pin is never shown in any of the documentation or examples, for instance. However, here are some specific questions:
The doxygen documentation for the GPIO read is this:
Bits32 GPIO_read | ( | UInt | index | ) |
Reads the value of a GPIO pin.
The value returned will either be a zero or non-zero bit packed value of the pin(s) read.
- Parameters:
-
index GPIO index
- Returns:
- Bit packed value of the GPIO pin(s)
My questions are:
1) how is the bit-packed return value organized? I see no further specification. Is the bit location corresponding to the index of the pin that I request? If so, that leads to the second question.
2) How is the index organized? The way I think it is organized makes no sense. The write function example uses an Enum for the index. Looking at this enum, I don't understand how multiple pin reads and writes are handled. The enum is declared as follows:
typedef enum TMDXDOCKH52C1_GPIOName {
TMDXDOCKH52C1_LD2 = 0,
TMDXDOCKH52C1_LD3,
TMDXDOCKH52C1_BUTTON,
TMDXDOCKH52C1_GPIOCOUNT
} TMDXDOCKH52C1_GPIOName;
This enum declaration will essentially use values 0, 1, 2, 3... I don't get how this even works, especially with multiple read/writes in one function call. First, defining it this way instead of as bit fields (0x1, 0x2, 0x4,..) means that the third option is indistinguishable from (0x1 & 0x2). How am I supposed to read from both the first and second index? Secondly, a zero based index doesn't even make sense. How am I supposed to read LD2 and LD3 in this case? What is the value of (TMDXDOCKH52C1_LD2 & TMDXDOCKH52C1_LD3), which is (0x0 & 0x1)? It doesn't make any sense.
Perhaps you can only read one pin at a time. Then at least the indexes make sense, if only one can be used at a time. However, then the bit-packed field return value makes no sense, and this contradicts the documentation.
I am baffled. Does anyone know what is going on?