bit shift - Raspberry Pi bitmask for GPIO (OUT_GPIO and INP_GPIO) -
i trying change state (output/input) more 1 pin @ same time (with bitmask).
the code 1 pin is:
#define inp_gpio(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) #define out_gpio(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) i don't understand code does.
let's say, gpio := 0x20200000 pin 1 should
10 0000 0010 0000 0000 0000 0000 0000 + 0 = (10 0000 0010 0000 0000 0000 0000 0000 + 0) & ~11 1000 = 0 i think can't correct. doing wrong?
so broadcom arm peripherals manual should referencing before asking read you...0x20200000 function select register gpio pins 0 9 each set of 10 pins there register 3 bits per gpio select 1 of 8 functions 2 bits unused. modulo 10 figure out function select register, times 3 three bits per gpio pin.
the bit pattern 0b000 defines pin input , bit pattern 0b001 output, code referenced either zeros 3 bits or ors 3 bits 1 of course buggy since other 2 bits not guaranteed zero. use code should either fix or set gpio input output clears 3 bits sets 1 bit.
Comments
Post a Comment