https://github.com/yuvadm/tiva-c/blob/master/driverlib/gpio.c
//The pin(s) are specified using a bit-packed byte, where each bit that is
//! set identifies the pin to be accessed, and where bit 0 of the byte
//! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.
The first parameter points to which port you will be writing. The second one ui8Pins
is like a mask, such that the function only affects the specified pins (bits of ui8Pins
that are 1), for those 1 bits ui8Pins
the bits in the same position of ui8Val
(0 or 1) will be written to the the port.
This masking of ui8Pins
is actually part of the architecture of the Tiva, the function you are using will write to an address like this
(*((volatile ulong *)(ui32Port + (GPIO_O_DATA + (ui8Pins << 2))))) = ui8Val;
and the (ui8Pins << 2)
will not really address a "memory" but bitmask ui8Val
so that not all of its bits change the values in ui32Port + GPIO_O_DATA
which would be the GPIO data (each pin being high or low).
GPIO DataThis register is virtually mapped to 256 locations in the address space.
To facilitate the reading and writing of data to these registers byindependent
drivers, the data read from and written to the registers aremasked by the
eight address lines [9:2]. Reads from this register return its current state.
Writes to this register only affect bits that are not masked by ADDR[9:2] and are
configured as outputs. See “Data RegisterOperation” on page 654 for examples
of reads and writes.
In most other microcontroller the process a masking and writing can be done as such
(*((volatile ulong *)(ui32Port + (GPIO_O_DATA)))) = (~ui8Pins & *(ui32Port + (GPIO_O_DATA))) +(ui8Pins & ui8Val);
\\for all the bits that are zero in ui8Pins, the values in the memory to which you are writing should remain the same
(~ui8Pins & *(ui32Port + (GPIO_O_DATA)));
\\for the bits that are one in ui8Pins use the same bits in ui8Val
(GPIO_O_DATA))) +(ui8Pins & ui8Val);