diff --git a/Makefile b/Makefile
index 9c47525..ae05912 100644
--- a/Makefile
+++ b/Makefile
@@ -25,16 +25,12 @@ DEVICES = $(BUILDDIR)/devices/dspic33e.o \
a10: CFLAGS += -DBOARD_A10
raspberrypi: CFLAGS += -DBOARD_RPI
-raspberrypi2: CFLAGS += -DBOARD_RPI2
-raspberrypi4: CFLAGS += -DBOARD_RPI4
am335x: CFLAGS += -DBOARD_AM335X
default:
@echo "Please specify a target with 'make raspberrypi', 'make a10' or 'make am335x'."
raspberrypi: prepare picberry
-raspberrypi2: prepare picberry
-raspberrypi4: prepare picberry
a10: prepare picberry
am335x: prepare picberry gpio_test
diff --git a/README.md b/README.md
index c099e5f..9b51c03 100644
--- a/README.md
+++ b/README.md
@@ -52,9 +52,7 @@ To build picberry launch `make TARGET`, where _TARGET_ can be one of the followi
| _TARGET_ | Processor/Board |
| ------------- | ------------------------------------------ |
-| raspberrypi | Raspberry Pi v1 or Zero |
-| raspberrypi2 | Raspberry Pi v2 or v3 |
-| raspberrypi4 | Raspberry Pi 4A or 4B or CM4
+| raspberrypi | Raspberry Pi all models |
| am335x | Boards based on TI AM335x (BeagleBone) |
| a10 | Boards based on Allwinner A10 (Cubieboard) |
@@ -62,7 +60,7 @@ Then launch `sudo make install` to install it to /usr/bin.
To change destination prefix use PREFIX=, e.g. `sudo make install PREFIX=/usr/local`.
-For cross-compilation, given that you have the required cross toolchain in you PATH, simply export the `CROSS_COMPILE` variable before launching `make`, e.g. `CROSS_COMPILE=arm-linux-gnueabihf- make raspberrypi2`.
+For cross-compilation, given that you have the required cross toolchain in you PATH, simply export the `CROSS_COMPILE` variable before launching `make`, e.g. `CROSS_COMPILE=arm-linux-gnueabihf- make raspberrypi`.
## Using picberry
diff --git a/src/common.h b/src/common.h
index 5cbfc05..4a4d29e 100644
--- a/src/common.h
+++ b/src/common.h
@@ -25,10 +25,6 @@
#include "hosts/a10.h"
#elif defined(BOARD_RPI)
#include "hosts/rpi.h"
-#elif defined(BOARD_RPI2)
-#include "hosts/rpi2.h"
-#elif defined(BOARD_RPI4)
-#include "hosts/rpi4.h"
#elif defined(BOARD_AM335X)
#include "hosts/am335x.h"
#endif
diff --git a/src/gpio_test.cpp b/src/gpio_test.cpp
index b70efa2..9067078 100644
--- a/src/gpio_test.cpp
+++ b/src/gpio_test.cpp
@@ -129,41 +129,61 @@ int main(int argc, char *argv[])
/* Set up a memory regions to access GPIO */
void setup_io(void)
{
- /* open /dev/mem */
- mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
- if (mem_fd == -1) {
- perror("Cannot open /dev/mem");
- exit(1);
- }
+#ifdef USE_DEV_GPIOMEM
+ /* open /dev/gpiomem */
+ mem_fd = open("/dev/gpiomem", O_RDWR|O_SYNC);
+ if (mem_fd == -1) {
+ perror("Cannot open /dev/gpiomem");
+ exit(1);
+ }
- /* mmap GPIO */
- gpio_map = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, GPIO_BASE);
- if (gpio_map == MAP_FAILED) {
- perror("mmap() failed");
- exit(1);
- }
+ /* mmap GPIO */
+ gpio_map = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0);
+ if (gpio_map == MAP_FAILED) {
+ perror("mmap() failed");
+ exit(1);
+ }
+#else
+ /* open /dev/mem */
+ mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
+ if (mem_fd == -1) {
+ perror("Cannot open /dev/mem");
+ exit(1);
+ }
- /* Always use volatile pointer! */
- gpio = (volatile uint32_t *) gpio_map;
+ /* mmap GPIO */
+ gpio_map = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, GPIO_BASE);
+ if (gpio_map == MAP_FAILED) {
+ perror("mmap() failed");
+ exit(1);
+ }
+#endif
+
+ /* Always use volatile pointer! */
+ gpio = (volatile uint32_t *) gpio_map;
}
/* Release GPIO memory region */
void close_io(void)
{
- int ret;
+ int ret;
- /* munmap GPIO */
- ret = munmap(gpio_map, BLOCK_SIZE);
- if (ret == -1) {
- perror("munmap() failed");
- exit(1);
- }
+ /* munmap GPIO */
+ ret = munmap(gpio_map, BLOCK_SIZE);
+ if (ret == -1) {
+ perror("munmap() failed");
+ exit(1);
+ }
- /* close /dev/mem */
- ret = close(mem_fd);
- if (ret == -1) {
- perror("Cannot close /dev/mem");
- exit(1);
- }
+ /* close /dev/gpiomem or /dev/mem */
+ ret = close(mem_fd);
+ if (ret == -1) {
+#ifdef USE_DEV_GPIOMEM
+ perror("Cannot close /dev/gpiomem");
+#else
+ perror("Cannot close /dev/mem");
+#endif
+ exit(1);
+ }
}
diff --git a/src/hosts/rpi.h b/src/hosts/rpi.h
index 71c2fe3..b753b35 100644
--- a/src/hosts/rpi.h
+++ b/src/hosts/rpi.h
@@ -18,10 +18,10 @@
* along with this program. If not, see .
*/
+/* Set flag to use /dev/gpiomem instead of /dev/mem */
+#define USE_DEV_GPIOMEM
/* GPIO registers address */
-#define BCM2708_PERI_BASE 0x20000000
-#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
#define BLOCK_SIZE (256)
#define PORTOFFSET 0
diff --git a/src/hosts/rpi2.h b/src/hosts/rpi2.h
deleted file mode 100644
index b994941..0000000
--- a/src/hosts/rpi2.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Raspberry Pi PIC Programmer using GPIO connector
- * https://github.com/WallaceIT/picberry
- * Copyright 2016 Francesco Valla
- *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-
-/* GPIO registers address */
-#define BCM2708_PERI_BASE 0x3F000000
-#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
-#define BLOCK_SIZE (256)
-#define PORTOFFSET 0
-
-/* GPIO setup macros. Always use GPIO_IN(x) before using GPIO_OUT(x) */
-#define GPIO_IN(g) *(gpio+((g&0xFF)/10)) &= ~(7<<(((g&0xFF)%10)*3))
-#define GPIO_OUT(g) *(gpio+((g&0xFF)/10)) |= (1<<(((g&0xFF)%10)*3))
-
-#define GPIO_SET(g) *(gpio+7) = 1<<(g&0xFF)
-#define GPIO_CLR(g) *(gpio+10) = 1<<(g&0xFF)
-#define GPIO_LEV(g) (*(gpio+13) >> (g&0xFF)) & 0x1 /* reads pin level */
-
-/* default GPIO <-> PIC connections */
-#define DEFAULT_PIC_CLK 23 /* PGC - Output */
-#define DEFAULT_PIC_DATA 24 /* PGD - I/O */
-#define DEFAULT_PIC_MCLR 18 /* MCLR - Output */
diff --git a/src/hosts/rpi4.h b/src/hosts/rpi4.h
deleted file mode 100644
index 2fab271..0000000
--- a/src/hosts/rpi4.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Raspberry Pi PIC Programmer using GPIO connector
- * https://github.com/WallaceIT/picberry
- * Copyright 2016 Francesco Valla
- *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-
-/* GPIO registers address */
-#define BCM2708_PERI_BASE 0xFE000000
-#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
-#define BLOCK_SIZE (256)
-#define PORTOFFSET 0
-
-/* GPIO setup macros. Always use GPIO_IN(x) before using GPIO_OUT(x) */
-#define GPIO_IN(g) *(gpio+((g&0xFF)/10)) &= ~(7<<(((g&0xFF)%10)*3))
-#define GPIO_OUT(g) *(gpio+((g&0xFF)/10)) |= (1<<(((g&0xFF)%10)*3))
-
-#define GPIO_SET(g) *(gpio+7) = 1<<(g&0xFF)
-#define GPIO_CLR(g) *(gpio+10) = 1<<(g&0xFF)
-#define GPIO_LEV(g) (*(gpio+13) >> (g&0xFF)) & 0x1 /* reads pin level */
-
-/* default GPIO <-> PIC connections */
-#define DEFAULT_PIC_CLK 23 /* PGC - Output */
-#define DEFAULT_PIC_DATA 24 /* PGD - I/O */
-#define DEFAULT_PIC_MCLR 18 /* MCLR - Output */
diff --git a/src/picberry.cpp b/src/picberry.cpp
index ba5001c..c0feb2d 100644
--- a/src/picberry.cpp
+++ b/src/picberry.cpp
@@ -374,6 +374,22 @@ int main(int argc, char *argv[])
/* Set up a memory regions to access GPIO */
void setup_io(void)
{
+#ifdef USE_DEV_GPIOMEM
+ /* open /dev/gpiomem */
+ mem_fd = open("/dev/gpiomem", O_RDWR|O_SYNC);
+ if (mem_fd == -1) {
+ perror("Cannot open /dev/gpiomem");
+ exit(1);
+ }
+
+ /* mmap GPIO */
+ gpio_map = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
+ MAP_SHARED, mem_fd, 0);
+ if (gpio_map == MAP_FAILED) {
+ perror("mmap() failed");
+ exit(1);
+ }
+#else
/* open /dev/mem */
mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
if (mem_fd == -1) {
@@ -388,6 +404,7 @@ void setup_io(void)
perror("mmap() failed");
exit(1);
}
+#endif
/* Always use volatile pointer! */
gpio = (volatile uint32_t *) gpio_map;
@@ -409,24 +426,28 @@ void setup_io(void)
/* Release GPIO memory region */
void close_io(void)
{
- int ret;
-
- /* MCLR as input, puts the output driver in Hi-Z */
- GPIO_IN(pic_mclr);
+ int ret;
+
+ /* MCLR as input, puts the output driver in Hi-Z */
+ GPIO_IN(pic_mclr);
- /* munmap GPIO */
- ret = munmap(gpio_map, BLOCK_SIZE);
- if (ret == -1) {
- perror("munmap() failed");
- exit(1);
- }
+ /* munmap GPIO */
+ ret = munmap(gpio_map, BLOCK_SIZE);
+ if (ret == -1) {
+ perror("munmap() failed");
+ exit(1);
+ }
- /* close /dev/mem */
- ret = close(mem_fd);
- if (ret == -1) {
- perror("Cannot close /dev/mem");
- exit(1);
- }
+ /* close /dev/gpiomem or /dev/mem */
+ ret = close(mem_fd);
+ if (ret == -1) {
+#ifdef USE_DEV_GPIOMEM
+ perror("Cannot close /dev/gpiomem");
+#else
+ perror("Cannot close /dev/mem");
+#endif
+ exit(1);
+ }
}
/* reset the device */