树霉pi gpio内存映射
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>#define BCM2835_PERI_BASE 0x20000000
#define GPIO_BASE (BCM2835_PERI_BASE + 0x200000)
#define PAGE_SIZE 4096
int main() {char* fname = "/dev/gpiomem";int fd = open(fname,O_RDWR);printf("fd = %d\n", fd);unsigned int * adr = mmap(0,PAGE_SIZE,PROT_READ | PROT_WRITE,MAP_SHARED,fd,GPIO_BASE);printf("mem addr %p\n",adr);// manipulate munmap(adr,PAGE_SIZE);close(fd);
}