Topic: Port manipulation
(Read 1 time)
Oct 26, 2017, 12:31 am
Following is a code snippet for direct port manipulation.
(g_APinDescription[4*address+1].pPort -> PIO_PDSR & g_APinDescription[4*address+1].ulPin)) - (!!(g_APinDescription[4*address].pPort -> PIO_PDSR & g_APinDescription[4*address].ulPin)));
Could anyone tell me what is the purpose of using g_APindescription here? Also, what do pPort and ulPin do exactly in the given code?
Strongly opinionated, but not official!
Re: Port manipulation
Oct 26, 2017, 02:14 am
g_APindescription is the table (array) that translates from "Arduino pin numbers" to a bunch of other information 9in a struct) about the pin.
".pPort" is a pointer to the "port" registers of the chip (another structure.) .pPort->PIO_PDSR is the "Pin Data Status Register."
".ulPin" is the bit (bitmask form) associated with that Arduino Pin Number.
The Arduino code (definition g_APindescription) is using "Hungarian notation", were the first letter of a variable name gives at least a hint as to the type of the variable. "pXXX" is a pointer, "ulYYY" is an unsigned long.
Um. You've posted this question in the "Arduino Zero" section of the forums, but based on the use of "PIO_PDSR", the code is for a Due. For a zero, it would be using something like ".pPort->IN.reg"