I am looking for some direction on how to directly access registers in my beloved RasberryPi. I have looked at the code at this url http://elinux.org/RPi_Low-level_peripherals. However, I am not looking for the kitchen sink of GPIO's. I just want to look at the Broadcom data sheet and cherry pick a register address and manipulate it through an mmap.
I am trying to use GPIO17 as a reference. Here is what the datasheet has provided me.
- Code: Select all
Broadcom datasheet excerpt
Peripherals (at physical address 0x20000000 on) are mapped into the kernel virtual address
space starting at address 0xF2000000. Thus a peripheral advertised
here at bus address 0x7Ennnnnn is available in the ARM kenel at virtual address 0xF2nnnnnn.
Select register GPIO17 are bits (23 -21)
GPFSEL1 = 0xF2200004
output bits are '001'
GPIO17 = 00000000 00100000 00000000 00000000
GPSET0 = 0xF220001C
Used to set the pin value if it is configured as an output
GPIO17 = 00000000 00000010 00000000 00000000
GPCLR0 = 0xF2200028
Used to clear the output of a pin
GPIO17 = 00000000 00000010 00000000 00000000]
GPLEV0 = 0xF2200034
Returns the level of the pins 0 - 31
Now I am under the impression that this will be as simple as mapping the address at offset 0xF2nnnnnn at a size of 4 bytes from there, but this is proving to be a challenge.
Can anyone provide some quick sample code in C that modifies one of the registers above in using mmap. Say bitwise &'ing GPFSEL1 to set GPIO17 as an output.