From 0b56f11f49da559cd88273cf2f3150b3f1036a9d Mon Sep 17 00:00:00 2001 From: Yannick Vignon Date: Wed, 17 Aug 2016 23:40:02 +0200 Subject: [PATCH 01/12] Fix Raspberry Pi2, Pi3 support . Fix Raspberry Pi model detection . Add model detection in GPIO module . Try to fix mailbox char device detection on various kernels . Fix compiler warnings --- documentation/source/rpio_py.rst | 2 +- source/RPIO/__init__.py | 5 ++++- source/c_gpio/c_gpio.c | 14 ++++++++++++-- source/c_gpio/cpuinfo.c | 6 +++++- source/c_pwm/mailbox.c | 15 ++++++++++++--- source/c_pwm/mailbox.h | 4 ++-- source/c_pwm/pwm.c | 4 ---- source/scripts/rpio | 4 ++-- source/scripts/rpio-curses | 2 +- source/tests_gpio.py | 2 +- 10 files changed, 40 insertions(+), 18 deletions(-) mode change 100644 => 100755 documentation/source/rpio_py.rst mode change 100644 => 100755 source/RPIO/__init__.py mode change 100644 => 100755 source/c_gpio/cpuinfo.c mode change 100644 => 100755 source/scripts/rpio mode change 100644 => 100755 source/scripts/rpio-curses mode change 100644 => 100755 source/tests_gpio.py diff --git a/documentation/source/rpio_py.rst b/documentation/source/rpio_py.rst old mode 100644 new mode 100755 index bdcbc45..f74e81a --- a/documentation/source/rpio_py.rst +++ b/documentation/source/rpio_py.rst @@ -219,7 +219,7 @@ Additions to RPi.GPIO Additional Constants * ``RPIO.RPI_REVISION`` - the current board's revision (either ``1`` or ``2``) -* ``RPIO.RPI_REVISION_HEX`` - the cpu hex revision code (``0002`` .. ``000f``) +* ``RPIO.RPI_REVISION_HEX`` - the cpu hex revision code (``0002`` .. ``000f``) for Pi 2 (``a01041``..``a21041``) for Pi 3 (``a02082``) Additional Methods diff --git a/source/RPIO/__init__.py b/source/RPIO/__init__.py old mode 100644 new mode 100755 index fae1705..6598cd3 --- a/source/RPIO/__init__.py +++ b/source/RPIO/__init__.py @@ -159,7 +159,10 @@ def socket_callback(socket, val): 'd': ('B', '2.0', 512, 'Egoman'), 'e': ('B', '2.0', 512, 'Sony'), 'f': ('B', '2.0', 512, 'Qisda'), - '10': ('B+', '1.0', 512, 'Sony') + '10': ('B+', '1.0', 512, 'Sony'), + 'a01041': ('2B', '1.0', 1024, 'Sony'), + 'a21041': ('2B', '1.0', 1024, 'EMBEST'), + 'a02082': ('3B', '1.0', 1024, '?') } # List of valid bcm gpio ids for raspberry rev1, rev2 and rev3. Used for inspect-all. diff --git a/source/c_gpio/c_gpio.c b/source/c_gpio/c_gpio.c index 25a04ca..570c3db 100644 --- a/source/c_gpio/c_gpio.c +++ b/source/c_gpio/c_gpio.c @@ -31,9 +31,11 @@ #include #include #include "c_gpio.h" +#include "cpuinfo.h" #define BCM2708_PERI_BASE 0x20000000 -#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) +#define BCM2709_PERI_BASE 0x3f000000 +#define GPIO_BASE (peri_base + 0x200000) #define OFFSET_FSEL 0 // 0x0000 #define OFFSET_SET 7 // 0x001c / 4 #define OFFSET_CLR 10 // 0x0028 / 4 @@ -52,6 +54,7 @@ #define BLOCK_SIZE (4*1024) static volatile uint32_t *gpio_map; +static uint32_t peri_base; // `short_wait` waits 150 cycles void @@ -67,7 +70,8 @@ short_wait(void) int setup(void) { - int mem_fd; + int mem_fd, type; + char revision_hex[1024]; uint8_t *gpio_mem; if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) @@ -79,6 +83,12 @@ setup(void) if ((uint32_t)gpio_mem % PAGE_SIZE) gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE); + type = get_cpuinfo_revision(revision_hex); + if (type == 1) + peri_base = BCM2708_PERI_BASE; + else + peri_base = BCM2709_PERI_BASE; + gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, GPIO_BASE); if ((uint32_t)gpio_map < 0) diff --git a/source/c_gpio/cpuinfo.c b/source/c_gpio/cpuinfo.c old mode 100644 new mode 100755 index 922fc5f..fd782be --- a/source/c_gpio/cpuinfo.c +++ b/source/c_gpio/cpuinfo.c @@ -75,7 +75,11 @@ get_cpuinfo_revision(char *revision_hex) (strcmp(revision_hex, "0003") == 0)) { return 1; } else if ((strcmp(revision_hex, "0010") == 0)) { - // We'll call Model B+ (0010) rev3 + } else if (strcmp(revision_hex, "0010") == 0 + || strcmp(revision_hex, "a21041") == 0 + || strcmp(revision_hex, "a01041") == 0 + || strcmp(revision_hex, "a02082") == 0 ) { + // We'll call Model B+ (0010) rev3 or Pi 2 return 3; } else { // assume rev 2 (0004 0005 0006 ...) diff --git a/source/c_pwm/mailbox.c b/source/c_pwm/mailbox.c index 139482a..3202a4b 100755 --- a/source/c_pwm/mailbox.c +++ b/source/c_pwm/mailbox.c @@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "mailbox.h" @@ -249,9 +250,17 @@ int mbox_open() { // open a char device file used for communicating with kernel mbox driver file_desc = open(DEVICE_FILE_NAME, 0); if (file_desc < 0) { - printf("Can't open device file: %s\n", DEVICE_FILE_NAME); - printf("Try creating a device file with: sudo mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUM); - exit(-1); + unlink(DEVICE_FILE_NAME); + if (mknod(DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM, 0)) < 0) { + printf("Failed to create mailbox device\n"); + exit(-1); + } + file_desc = open(DEVICE_FILE_NAME, 0); + if (file_desc < 0) { + printf("Can't open device file: %s\n", DEVICE_FILE_NAME); + printf("Try creating a device file with: sudo mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUM); + exit(-1); + } } return file_desc; } diff --git a/source/c_pwm/mailbox.h b/source/c_pwm/mailbox.h index ffd5b77..07ca361 100755 --- a/source/c_pwm/mailbox.h +++ b/source/c_pwm/mailbox.h @@ -29,9 +29,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define MAJOR_NUM 100 #define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *) -#define DEVICE_FILE_NAME "/dev/vcio-mb" +#define DEVICE_FILE_NAME "/dev/vcio" -int mbox_open(); +int mbox_open(void); void mbox_close(int file_desc); unsigned get_version(int file_desc); diff --git a/source/c_pwm/pwm.c b/source/c_pwm/pwm.c index 08fa381..c1c9d70 100644 --- a/source/c_pwm/pwm.c +++ b/source/c_pwm/pwm.c @@ -86,7 +86,6 @@ #include #include "pwm.h" #include "mailbox.h" -#define MBFILE DEVICE_FILE_NAME /* From mailbox.h */ // 15 DMA channels are usable on the RPi (0..14) #define DMA_CHANNELS 15 @@ -321,7 +320,6 @@ shutdown(void) } } _is_setup =0; - unlink(MBFILE); } // Terminate is triggered by signals @@ -757,8 +755,6 @@ setup(int pw_incr_us, int hw) init_hardware(); /* Use the mailbox interface to the VC to ask for physical memory */ - if (mknod(MBFILE, S_IFCHR|0600, makedev(249, 0)) < 0) - return fatal("Failed to create mailbox device\n"); mbox.handle = mbox_open(); if (mbox.handle < 0) return fatal("Failed to open mailbox\n"); diff --git a/source/scripts/rpio b/source/scripts/rpio old mode 100644 new mode 100755 index 7637136..639f8ba --- a/source/scripts/rpio +++ b/source/scripts/rpio @@ -148,7 +148,7 @@ def main(): RPIO.setwarnings(False) def is_valid_gpio_id(gpio_id): - if RPIO.sysinfo()[1] == 'B+': + if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': return gpio_id in RPIO.GPIO_LIST_R3 elif RPIO.RPI_REVISION == 1: return gpio_id in RPIO.GPIO_LIST_R1 @@ -205,7 +205,7 @@ def main(): show_help = False ids = options.show if options.inspect_all: - if RPIO.sysinfo()[1] == 'B+': + if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': pins = RPIO.GPIO_LIST_R3 elif RPIO.RPI_REVISION == 1: pins = RPIO.GPIO_LIST_R1 diff --git a/source/scripts/rpio-curses b/source/scripts/rpio-curses old mode 100644 new mode 100755 index fc549ec..63fc0ca --- a/source/scripts/rpio-curses +++ b/source/scripts/rpio-curses @@ -75,7 +75,7 @@ if "no_rpio" not in CMD_OPTIONS: RPIO.setwarnings(False) RPIO_VERSION = RPIO.VERSION def get_gpiolist(): - if RPIO.sysinfo()[1] == 'B+': + if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': pins = RPIO.GPIO_LIST_R3 elif RPIO.RPI_REVISION == 1: pins = RPIO.GPIO_LIST_R1 diff --git a/source/tests_gpio.py b/source/tests_gpio.py old mode 100644 new mode 100755 index 395c811..22136b4 --- a/source/tests_gpio.py +++ b/source/tests_gpio.py @@ -118,7 +118,7 @@ def test5_board_pin_numbers(self): logging.info("=== BCM AND BOARD NUMBERING TESTS ===") RPIO.setmode(RPIO.BCM) - if RPIO.sysinfo()[1] == 'B+': + if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': pins = RPIO.GPIO_LIST_R3 elif RPIO.RPI_REVISION == 1: pins = RPIO.GPIO_LIST_R1 From a25093f1c99b2da912af82fa98b6ef9717232772 Mon Sep 17 00:00:00 2001 From: Yannick Vignon Date: Fri, 9 Sep 2016 23:57:54 +0200 Subject: [PATCH 02/12] get_cpuinfo_revision fixes . Distinguish board revision from CPU model. . Consider the board revision to be 3 (latest) by default. . Use the CPU model (and not the board revision) to determine the GPIO base address. . Use the board revision to determine which pin/gpio mappings to use. . Fix the pin to gpio mapping definition for revision 3 boards. . Add all known models (according to http://elinux.org/RPi_HardwareHistory) to the MODEL_DATA (sysinfo) definition. . Only use the Pi revision (and no longer the sysinfo string) to determine which GPIO list to use in the Python scripts. --- documentation/source/rpio_py.rst | 4 ++-- source/RPIO/__init__.py | 11 +++++++++- source/c_gpio/c_gpio.c | 2 +- source/c_gpio/cpuinfo.c | 37 ++++++++++++++++++-------------- source/c_gpio/py_gpio.c | 4 ++-- source/scripts/rpio | 16 +++++++------- source/scripts/rpio-curses | 8 +++---- source/tests_gpio.py | 8 +++---- 8 files changed, 52 insertions(+), 38 deletions(-) mode change 100644 => 100755 source/c_gpio/c_gpio.c mode change 100644 => 100755 source/c_gpio/py_gpio.c diff --git a/documentation/source/rpio_py.rst b/documentation/source/rpio_py.rst index f74e81a..6baa772 100755 --- a/documentation/source/rpio_py.rst +++ b/documentation/source/rpio_py.rst @@ -218,8 +218,8 @@ Additions to RPi.GPIO Additional Constants -* ``RPIO.RPI_REVISION`` - the current board's revision (either ``1`` or ``2``) -* ``RPIO.RPI_REVISION_HEX`` - the cpu hex revision code (``0002`` .. ``000f``) for Pi 2 (``a01041``..``a21041``) for Pi 3 (``a02082``) +* ``RPIO.RPI_REVISION`` - the current board's revision and CPU model (either ``1``, ``2``, ``3`` or ``0x103``, with 0x103 identifying BCM2709 chips on revision 3 boards) +* ``RPIO.RPI_REVISION_HEX`` - the cpu hex revision code (``0002`` .. ``000f``) for Pi 2 (``a01041``..``a21041``) for Pi 3 (``a02082``..``a22082``) Additional Methods diff --git a/source/RPIO/__init__.py b/source/RPIO/__init__.py index 6598cd3..ee7ed59 100755 --- a/source/RPIO/__init__.py +++ b/source/RPIO/__init__.py @@ -160,9 +160,18 @@ def socket_callback(socket, val): 'e': ('B', '2.0', 512, 'Sony'), 'f': ('B', '2.0', 512, 'Qisda'), '10': ('B+', '1.0', 512, 'Sony'), + '11': ('CM', '1.0', 512, 'Sony'), + '12': ('A+', '1.1', 256, 'Sony'), + '13': ('B+', '1.2', 512, '?'), + '14': ('CM', '1.0', 512, 'EMBEST'), + '15': ('A+', '1.1', 256, 'EMBEST'), + 'a01040': ('2B', '1.0', 1024, '?'), 'a01041': ('2B', '1.0', 1024, 'Sony'), 'a21041': ('2B', '1.0', 1024, 'EMBEST'), - 'a02082': ('3B', '1.0', 1024, '?') + '900092': ('Zero', '1.2', 512, 'Sony'), + '900093': ('Zero', '1.3', 512, 'Sony'), + 'a02082': ('3B', '1.0', 1024, 'Sony'), + 'a22082': ('3B', '1.0', 1024, '?') } # List of valid bcm gpio ids for raspberry rev1, rev2 and rev3. Used for inspect-all. diff --git a/source/c_gpio/c_gpio.c b/source/c_gpio/c_gpio.c old mode 100644 new mode 100755 index 570c3db..3ed5355 --- a/source/c_gpio/c_gpio.c +++ b/source/c_gpio/c_gpio.c @@ -84,7 +84,7 @@ setup(void) gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE); type = get_cpuinfo_revision(revision_hex); - if (type == 1) + if ((type & 0x100) == 0) peri_base = BCM2708_PERI_BASE; else peri_base = BCM2709_PERI_BASE; diff --git a/source/c_gpio/cpuinfo.c b/source/c_gpio/cpuinfo.c index fd782be..289df54 100755 --- a/source/c_gpio/cpuinfo.c +++ b/source/c_gpio/cpuinfo.c @@ -42,6 +42,8 @@ get_cpuinfo_revision(char *revision_hex) char buffer[1024]; char hardware[1024]; int rpi_found = 0; + int bcm2709 = 0; + int board_rev = 3; if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) return -1; @@ -52,9 +54,11 @@ get_cpuinfo_revision(char *revision_hex) if (strcmp(hardware, "BCM2708") == 0|| strcmp(hardware, "BCM2709") == 0|| strcmp(hardware, "BCM2835") == 0|| - strcmp(hardware, "BCM2836") == 0 - ) + strcmp(hardware, "BCM2836") == 0) rpi_found = 1; + + if (strcmp(hardware, "BCM2709") == 0) + bcm2709 = 1; sscanf(buffer, "Revision : %s", revision_hex); } fclose(fp); @@ -72,19 +76,20 @@ get_cpuinfo_revision(char *revision_hex) // Returns revision if ((strcmp(revision_hex, "0002") == 0) || - (strcmp(revision_hex, "0003") == 0)) { - return 1; - } else if ((strcmp(revision_hex, "0010") == 0)) { - } else if (strcmp(revision_hex, "0010") == 0 - || strcmp(revision_hex, "a21041") == 0 - || strcmp(revision_hex, "a01041") == 0 - || strcmp(revision_hex, "a02082") == 0 ) { - // We'll call Model B+ (0010) rev3 or Pi 2 - return 3; - } else { - // assume rev 2 (0004 0005 0006 ...) - return 2; - } + (strcmp(revision_hex, "0003") == 0)) + board_rev = 1; + else if ((strcmp(revision_hex, "0004") == 0) + || (strcmp(revision_hex, "0005") == 0) + || (strcmp(revision_hex, "0006") == 0) + || (strcmp(revision_hex, "0007") == 0) + || (strcmp(revision_hex, "0008") == 0) + || (strcmp(revision_hex, "0009") == 0) + || (strcmp(revision_hex, "000d") == 0) + || (strcmp(revision_hex, "000e") == 0) + || (strcmp(revision_hex, "000f") == 0)) + board_rev = 2; + else // We'll call Model A+, B+, Pi2, Pi3 and Zero rev3 + board_rev = 3; - return -1; + return (bcm2709 << 8) | board_rev; } diff --git a/source/c_gpio/py_gpio.c b/source/c_gpio/py_gpio.c old mode 100644 new mode 100755 index 2e8ab7b..5a34dc6 --- a/source/c_gpio/py_gpio.c +++ b/source/c_gpio/py_gpio.c @@ -54,7 +54,7 @@ static PyObject *version; // eg. gpio_id = *(*pin_to_gpio_rev2 + board_pin_id); static const int pin_to_gpio_rev1[41] = {-1, -1, -1, 0, -1, 1, -1, 4, 14, -1, 15, 17, 18, 21, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; static const int pin_to_gpio_rev2[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; -static const int pin_to_gpio_rev3[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 24, 11, 7, -1, 7, -1, -1, 5, -1, 6, 12, 13, -1, 19, 16, 26, 20, -1, 21}; +static const int pin_to_gpio_rev3[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, 5, -1, 6, 12, 13, -1, 19, 16, 26, 20, -1, 21}; static const int (*pin_to_gpio)[41]; // Board header info is shifted left 8 bits (leaves space for up to 255 channel ids per header) @@ -519,7 +519,7 @@ PyMODINIT_FUNC init_GPIO(void) // detect board revision and set up accordingly cache_rpi_revision(); - switch (revision_int) { + switch (revision_int & 0xff) { case 1: pin_to_gpio = &pin_to_gpio_rev1; gpio_to_pin = &gpio_to_pin_rev1; diff --git a/source/scripts/rpio b/source/scripts/rpio index 639f8ba..bcf7fcb 100755 --- a/source/scripts/rpio +++ b/source/scripts/rpio @@ -148,12 +148,12 @@ def main(): RPIO.setwarnings(False) def is_valid_gpio_id(gpio_id): - if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': - return gpio_id in RPIO.GPIO_LIST_R3 - elif RPIO.RPI_REVISION == 1: + if RPIO.RPI_REVISION == 1: return gpio_id in RPIO.GPIO_LIST_R1 - else: + elif RPIO.RPI_REVISION == 2: return gpio_id in RPIO.GPIO_LIST_R2 + else: + return gpio_id in RPIO.GPIO_LIST_R3 def validate_gpio_id_or_die(gpio_id): if not is_valid_gpio_id(gpio_id): @@ -205,12 +205,12 @@ def main(): show_help = False ids = options.show if options.inspect_all: - if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': - pins = RPIO.GPIO_LIST_R3 - elif RPIO.RPI_REVISION == 1: + if RPIO.RPI_REVISION == 1: pins = RPIO.GPIO_LIST_R1 - else: + elif RPIO.RPI_REVISION == 2: pins = RPIO.GPIO_LIST_R2 + else: + pins = RPIO.GPIO_LIST_R3 id_list = list(pins) id_list.sort() ids = ",".join([str(gpio) for gpio in id_list if gpio >= 0]) diff --git a/source/scripts/rpio-curses b/source/scripts/rpio-curses index 63fc0ca..6512eb8 100755 --- a/source/scripts/rpio-curses +++ b/source/scripts/rpio-curses @@ -75,12 +75,12 @@ if "no_rpio" not in CMD_OPTIONS: RPIO.setwarnings(False) RPIO_VERSION = RPIO.VERSION def get_gpiolist(): - if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': - pins = RPIO.GPIO_LIST_R3 - elif RPIO.RPI_REVISION == 1: + if RPIO.RPI_REVISION == 1: pins = RPIO.GPIO_LIST_R1 - else: + elif RPIO.RPI_REVISION == 2: pins = RPIO.GPIO_LIST_R2 + else: + pins = RPIO.GPIO_LIST_R3 id_list = list(pins) id_list.sort() diff --git a/source/tests_gpio.py b/source/tests_gpio.py index 22136b4..e865a18 100755 --- a/source/tests_gpio.py +++ b/source/tests_gpio.py @@ -118,12 +118,12 @@ def test5_board_pin_numbers(self): logging.info("=== BCM AND BOARD NUMBERING TESTS ===") RPIO.setmode(RPIO.BCM) - if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B' or RPIO.sysinfo()[1] == '3B': - pins = RPIO.GPIO_LIST_R3 - elif RPIO.RPI_REVISION == 1: + if RPIO.RPI_REVISION == 1: pins = RPIO.GPIO_LIST_R1 - else: + elif RPIO.RPI_REVISION == 2: pins = RPIO.GPIO_LIST_R2 + else: + pins = RPIO.GPIO_LIST_R3 logging.info("testing bcm gpio numbering: %s", pins) for pin in pins: gpio_id = RPIO.channel_to_gpio(pin) From 7f890943b00cb1f2b6bed44070f368fcf04dc23c Mon Sep 17 00:00:00 2001 From: James Date: Mon, 24 Jul 2017 13:46:32 +0100 Subject: [PATCH 03/12] pi zero w support --- source/RPIO/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/source/RPIO/__init__.py b/source/RPIO/__init__.py index ee7ed59..8497a7d 100755 --- a/source/RPIO/__init__.py +++ b/source/RPIO/__init__.py @@ -170,6 +170,7 @@ def socket_callback(socket, val): 'a21041': ('2B', '1.0', 1024, 'EMBEST'), '900092': ('Zero', '1.2', 512, 'Sony'), '900093': ('Zero', '1.3', 512, 'Sony'), + '9000c1': ('Zero W', '1.1', 512, 'Elpida'), 'a02082': ('3B', '1.0', 1024, 'Sony'), 'a22082': ('3B', '1.0', 1024, '?') } From 4bf21a962798c7a0549eac8e8654bb66a3936c32 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 24 Jul 2017 13:51:13 +0100 Subject: [PATCH 04/12] corrected RAM manufacturer --- source/RPIO/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/RPIO/__init__.py b/source/RPIO/__init__.py index 8497a7d..c054a10 100755 --- a/source/RPIO/__init__.py +++ b/source/RPIO/__init__.py @@ -170,7 +170,7 @@ def socket_callback(socket, val): 'a21041': ('2B', '1.0', 1024, 'EMBEST'), '900092': ('Zero', '1.2', 512, 'Sony'), '900093': ('Zero', '1.3', 512, 'Sony'), - '9000c1': ('Zero W', '1.1', 512, 'Elpida'), + '9000c1': ('Zero W', '1.1', 512, 'Sony'), 'a02082': ('3B', '1.0', 1024, 'Sony'), 'a22082': ('3B', '1.0', 1024, '?') } From fab635a49a97bd2413bf032f01fe0f1f089f736d Mon Sep 17 00:00:00 2001 From: James Date: Mon, 24 Jul 2017 14:03:11 +0100 Subject: [PATCH 05/12] update all current pi models details taken from http://elinux.org/RPi_HardwareHistory --- source/RPIO/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/source/RPIO/__init__.py b/source/RPIO/__init__.py index c054a10..31cf4df 100755 --- a/source/RPIO/__init__.py +++ b/source/RPIO/__init__.py @@ -160,19 +160,25 @@ def socket_callback(socket, val): 'e': ('B', '2.0', 512, 'Sony'), 'f': ('B', '2.0', 512, 'Qisda'), '10': ('B+', '1.0', 512, 'Sony'), - '11': ('CM', '1.0', 512, 'Sony'), + '11': ('CM1', '1.0', 512, 'Sony'), '12': ('A+', '1.1', 256, 'Sony'), '13': ('B+', '1.2', 512, '?'), - '14': ('CM', '1.0', 512, 'EMBEST'), + '14': ('CM1', '1.0', 512, 'EMBEST'), '15': ('A+', '1.1', 256, 'EMBEST'), 'a01040': ('2B', '1.0', 1024, '?'), - 'a01041': ('2B', '1.0', 1024, 'Sony'), - 'a21041': ('2B', '1.0', 1024, 'EMBEST'), + 'a01041': ('2B', '1.1', 1024, 'Sony'), + 'a21041': ('2B', '1.1', 1024, 'EMBEST'), + 'a22042': ('2B', '1.2', 1024, 'EMBEST'), + '900021': ('A+', '1.1', 512, 'Sony'), + '900032': ('B+', '1.2', 512, 'Sony'), '900092': ('Zero', '1.2', 512, 'Sony'), '900093': ('Zero', '1.3', 512, 'Sony'), + '920093': ('Zero', '1.3', 512, 'Embest'), '9000c1': ('Zero W', '1.1', 512, 'Sony'), - 'a02082': ('3B', '1.0', 1024, 'Sony'), - 'a22082': ('3B', '1.0', 1024, '?') + 'a02082': ('3B', '1.2', 1024, 'Sony'), + 'a020a0': ('CM3', '1.0', 1024, 'Sony'), + 'a22082': ('3B', '1.0', 1024, 'EMBEST'), + 'a32082': ('3B', '1.0', 1024, 'Sony Japan'), } # List of valid bcm gpio ids for raspberry rev1, rev2 and rev3. Used for inspect-all. From 6420580fe78c9aa55dbe926aa99085c409247ea5 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 25 Jul 2017 12:16:48 +0100 Subject: [PATCH 06/12] add build recipes for newer python versions added build recipes for python version 3.3, 3.4, 3.5 and 3.6, include directories may need to be changed if incorrect --- source/c_gpio/Makefile | 30 +++++++++++++++++++++++++++++- source/c_pwm/Makefile | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/source/c_gpio/Makefile b/source/c_gpio/Makefile index 4d6a72a..9fcaee3 100644 --- a/source/c_gpio/Makefile +++ b/source/c_gpio/Makefile @@ -1,4 +1,4 @@ -all: gpio2.6 gpio2.7 gpio3.2 +all: gpio2.6 gpio2.7 gpio3.2 gpio3.3 gpio3.4 gpio2.6: mkdir -p build @@ -21,5 +21,33 @@ gpio3.2: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c cpuinfo.c -o build/cpuinfo.o gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so +gpio3.3: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c py_gpio.c -o build/py_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c c_gpio.c -o build/c_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so + +gpio3.4: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c py_gpio.c -o build/py_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c c_gpio.c -o build/c_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so + +gpio3.5: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c py_gpio.c -o build/py_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c c_gpio.c -o build/c_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so + +gpio3.6: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c py_gpio.c -o build/py_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c c_gpio.c -o build/c_gpio.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/py_gpio.o build/c_gpio.o build/cpuinfo.o -o build/_GPIO.so + clean: rm -rf build diff --git a/source/c_pwm/Makefile b/source/c_pwm/Makefile index 66dd765..8ac7811 100644 --- a/source/c_pwm/Makefile +++ b/source/c_pwm/Makefile @@ -26,3 +26,35 @@ py3.2: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c pwm_py.c -o build/pwm_py.o gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build + +py3.3: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c mailbox.c -o build/mailbox.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c pwm.c -o build/pwm.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c pwm_py.c -o build/pwm_py.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + rm -rf build + +py3.4: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c mailbox.c -o build/mailbox.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c pwm.c -o build/pwm.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c pwm_py.c -o build/pwm_py.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + rm -rf build + +py3.5: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c mailbox.c -o build/mailbox.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c pwm.c -o build/pwm.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c pwm_py.c -o build/pwm_py.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + rm -rf build + +py3.6: + mkdir -p build + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c mailbox.c -o build/mailbox.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c pwm.c -o build/pwm.o + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c pwm_py.c -o build/pwm_py.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + rm -rf build \ No newline at end of file From f861be99cc8b161837740bd4e044566cccd596f3 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 29 Jul 2017 08:06:53 +0100 Subject: [PATCH 07/12] fix getting per_base for new pis in pwm extension the pwm extension was using the default 2708 base address no matter what pi was in use, leading to corrupted memory and freezing the pi. Moved the cpuinfo files into a c_common directory so they can be used by both the RPIO extension and the PWM extension. --- setup.py | 4 +- source/c_common/cpuinfo.c | 95 +++++++++++ source/c_common/cpuinfo.h | 25 +++ source/c_gpio/c_gpio.c | 2 +- source/c_gpio/py_gpio.c | 2 +- source/c_pwm/Makefile | 23 ++- source/c_pwm/pwm.c | 58 ++++--- source/scripts/man/Makefile | 154 +++++++++++++++++- source/scripts/man/source/conf.py | 243 +++++++++++++++++++++++++++- source/scripts/man/source/index.rst | 102 +++++++++++- 10 files changed, 672 insertions(+), 36 deletions(-) create mode 100644 source/c_common/cpuinfo.c create mode 100644 source/c_common/cpuinfo.h diff --git a/setup.py b/setup.py index bf30dad..3fd7751 100644 --- a/setup.py +++ b/setup.py @@ -13,10 +13,10 @@ def read(fname): packages=['RPIO', 'RPIO.PWM'], ext_modules=[ Extension('RPIO._GPIO', ['source/c_gpio/py_gpio.c', - 'source/c_gpio/c_gpio.c', 'source/c_gpio/cpuinfo.c'], + 'source/c_gpio/c_gpio.c', 'source/c_common/cpuinfo.c'], extra_compile_args=["-Wno-error=declaration-after-statement"]), Extension('RPIO.PWM._PWM', ['source/c_pwm/pwm.c', 'source/c_pwm/mailbox.c', - 'source/c_pwm/pwm_py.c'], + 'source/c_pwm/pwm_py.c', 'source/c_common/cpuinfo.c'], extra_compile_args=["-Wno-error=declaration-after-statement"])], scripts=["source/scripts/rpio", "source/scripts/rpio-curses"], diff --git a/source/c_common/cpuinfo.c b/source/c_common/cpuinfo.c new file mode 100644 index 0000000..289df54 --- /dev/null +++ b/source/c_common/cpuinfo.c @@ -0,0 +1,95 @@ +/* + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + */ +#include +#include +#include "cpuinfo.h" + +// Writes the hex revision str into the argument and returns: +// 2 (raspberry with revision 2 pin setup) +// 1 (raspberry with revision 1 pin setup) +// 0 (not a raspberry pi) +// -1 (could not open /proc/cpuinfo) +// +// revision_hex will be four characters revision id (eg. '0004'), +// the over-voltage header, if present, is removed (since it is +// not consistently present on all overclocked boards). +int +get_cpuinfo_revision(char *revision_hex) +{ + FILE *fp; + char buffer[1024]; + char hardware[1024]; + int rpi_found = 0; + int bcm2709 = 0; + int board_rev = 3; + + if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) + return -1; + + while(!feof(fp)) { + fgets(buffer, sizeof(buffer) , fp); + sscanf(buffer, "Hardware : %s", hardware); + if (strcmp(hardware, "BCM2708") == 0|| + strcmp(hardware, "BCM2709") == 0|| + strcmp(hardware, "BCM2835") == 0|| + strcmp(hardware, "BCM2836") == 0) + rpi_found = 1; + + if (strcmp(hardware, "BCM2709") == 0) + bcm2709 = 1; + sscanf(buffer, "Revision : %s", revision_hex); + } + fclose(fp); + + if (!rpi_found) { + revision_hex = NULL; + return 0; + } + + // If over-voltage is present, remove it + char* pos = strstr(revision_hex, "1000"); + if (pos && pos - revision_hex == 0 && strlen(revision_hex) > 5) { + strcpy(revision_hex, revision_hex+(strlen(revision_hex) - 4)); + } + + // Returns revision + if ((strcmp(revision_hex, "0002") == 0) || + (strcmp(revision_hex, "0003") == 0)) + board_rev = 1; + else if ((strcmp(revision_hex, "0004") == 0) + || (strcmp(revision_hex, "0005") == 0) + || (strcmp(revision_hex, "0006") == 0) + || (strcmp(revision_hex, "0007") == 0) + || (strcmp(revision_hex, "0008") == 0) + || (strcmp(revision_hex, "0009") == 0) + || (strcmp(revision_hex, "000d") == 0) + || (strcmp(revision_hex, "000e") == 0) + || (strcmp(revision_hex, "000f") == 0)) + board_rev = 2; + else // We'll call Model A+, B+, Pi2, Pi3 and Zero rev3 + board_rev = 3; + + return (bcm2709 << 8) | board_rev; +} diff --git a/source/c_common/cpuinfo.h b/source/c_common/cpuinfo.h new file mode 100644 index 0000000..3b54068 --- /dev/null +++ b/source/c_common/cpuinfo.h @@ -0,0 +1,25 @@ +/* + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + */ +int get_cpuinfo_revision(char *revision_hex); \ No newline at end of file diff --git a/source/c_gpio/c_gpio.c b/source/c_gpio/c_gpio.c index 3ed5355..e233749 100755 --- a/source/c_gpio/c_gpio.c +++ b/source/c_gpio/c_gpio.c @@ -31,7 +31,7 @@ #include #include #include "c_gpio.h" -#include "cpuinfo.h" +#include "../c_common/cpuinfo.h" #define BCM2708_PERI_BASE 0x20000000 #define BCM2709_PERI_BASE 0x3f000000 diff --git a/source/c_gpio/py_gpio.c b/source/c_gpio/py_gpio.c index 5a34dc6..63e4bbe 100755 --- a/source/c_gpio/py_gpio.c +++ b/source/c_gpio/py_gpio.c @@ -27,7 +27,7 @@ */ #include "Python.h" #include "c_gpio.h" -#include "cpuinfo.h" +#include "../c_common/cpuinfo.h" // All these will get exposed via the Python module static PyObject *WrongDirectionException; diff --git a/source/c_pwm/Makefile b/source/c_pwm/Makefile index 8ac7811..be925b2 100644 --- a/source/c_pwm/Makefile +++ b/source/c_pwm/Makefile @@ -1,4 +1,4 @@ -all: pwm py +all: pwm py2.6 py2.7 py3.2 py3.3 py3.4 py3.5 py3.6 pwm: gcc -Wall -g -O2 -o pwm pwm.c @@ -8,7 +8,8 @@ py2.6: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c mailbox.c -o build/mailbox.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c pwm.c -o build/pwm.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c pwm_py.c -o build/pwm_py.o - gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build py2.7: @@ -16,7 +17,8 @@ py2.7: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c mailbox.c -o build/mailbox.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c pwm.c -o build/pwm.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c pwm_py.c -o build/pwm_py.o - gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build py3.2: @@ -24,7 +26,8 @@ py3.2: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c mailbox.c -o build/mailbox.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c pwm.c -o build/pwm.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c pwm_py.c -o build/pwm_py.o - gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.2mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build py3.3: @@ -32,7 +35,8 @@ py3.3: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c mailbox.c -o build/mailbox.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c pwm.c -o build/pwm.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c pwm_py.c -o build/pwm_py.o - gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.3mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build py3.4: @@ -40,7 +44,8 @@ py3.4: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c mailbox.c -o build/mailbox.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c pwm.c -o build/pwm.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c pwm_py.c -o build/pwm_py.o - gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.4mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build py3.5: @@ -48,7 +53,8 @@ py3.5: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c mailbox.c -o build/mailbox.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c pwm.c -o build/pwm.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c pwm_py.c -o build/pwm_py.o - gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.5mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build py3.6: @@ -56,5 +62,6 @@ py3.6: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c mailbox.c -o build/mailbox.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c pwm.c -o build/pwm.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c pwm_py.c -o build/pwm_py.o - gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/pwm.o build/pwm_py.o -o _PWM.so + gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python3.6mu -c cpuinfo.c -o build/cpuinfo.o + gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/mailbox.o build/cpuinfo.o build/pwm.o build/pwm_py.o -o _PWM.so rm -rf build \ No newline at end of file diff --git a/source/c_pwm/pwm.c b/source/c_pwm/pwm.c index c1c9d70..96a00b5 100644 --- a/source/c_pwm/pwm.c +++ b/source/c_pwm/pwm.c @@ -86,6 +86,7 @@ #include #include "pwm.h" #include "mailbox.h" +#include "../c_common/cpuinfo.h" // 15 DMA channels are usable on the RPi (0..14) #define DMA_CHANNELS 15 @@ -103,10 +104,13 @@ static uint32_t mem_flag = 0x0c; // Memory Addresses -static volatile unsigned int BCM2708_PERI_BASE = 0x20000000 ; //for PI1 +#define BCM2708_PERI_BASE 0x20000000 +#define BCM2709_PERI_BASE 0x3f000000 +static volatile unsigned int peri_base; static volatile unsigned int periph_phys_base = 0x7e000000; -static volatile unsigned int periph_virt_base = 0x20000000; +//static volatile unsigned int periph_virt_base = 0x20000000; +//static volatile unsigned int periph_virt_base = 0x3f000000; #define DMA_BASE_OFFSET 0x00007000 #define PWM_BASE_OFFSET 0x0020C000 @@ -114,11 +118,11 @@ static volatile unsigned int periph_virt_base = 0x20000000; #define GPIO_BASE_OFFSET 0x00200000 #define PCM_BASE_OFFSET 0x00203000 -#define DMA_VIRT_BASE (periph_virt_base + DMA_BASE_OFFSET) -#define PWM_VIRT_BASE (periph_virt_base + PWM_BASE_OFFSET) -#define CLK_VIRT_BASE (periph_virt_base + CLK_BASE_OFFSET) -#define GPIO_VIRT_BASE (periph_virt_base + GPIO_BASE_OFFSET) -#define PCM_VIRT_BASE (periph_virt_base + PCM_BASE_OFFSET) +#define DMA_VIRT_BASE (peri_base + DMA_BASE_OFFSET) +#define PWM_VIRT_BASE (peri_base + PWM_BASE_OFFSET) +#define CLK_VIRT_BASE (peri_base + CLK_BASE_OFFSET) +#define GPIO_VIRT_BASE (peri_base + GPIO_BASE_OFFSET) +#define PCM_VIRT_BASE (peri_base + PCM_BASE_OFFSET) #define PWM_PHYS_BASE (periph_phys_base + PWM_BASE_OFFSET) #define PCM_PHYS_BASE (periph_phys_base + PCM_BASE_OFFSET) @@ -715,22 +719,34 @@ get_error_message(void) int setup(int pw_incr_us, int hw) { - unsigned char buf[4]; - FILE *fp; + int type; + char revision_hex[1024]; + + type = get_cpuinfo_revision(revision_hex); + if ((type & 0x100) == 0) + peri_base = BCM2708_PERI_BASE; + else + peri_base = BCM2709_PERI_BASE; + + mem_flag = 0x04; +// unsigned char buf[4]; +// FILE *fp; // get peri base from device tree - if ((fp = fopen("/proc/device-tree/soc/ranges", "rb")) != NULL) { - fseek(fp, 4, SEEK_SET); - if (fread(buf, 1, sizeof buf, fp) == sizeof buf) { - BCM2708_PERI_BASE = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0; - } - fclose(fp); - } - if(BCM2708_PERI_BASE != periph_virt_base) - { - periph_virt_base = BCM2708_PERI_BASE; - mem_flag = 0x04; - } +// if ((fp = fopen("/proc/device-tree/soc/ranges", "rb")) != NULL) { +// fseek(fp, 4, SEEK_SET); +// if (fread(buf, 1, sizeof buf, fp) == sizeof buf) { +// PERI_BASE = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0; +// } +// fclose(fp); +// } + + +// if(peri_base != periph_virt_base) +// { +// periph_virt_base = PERI_BASE; +// mem_flag = 0x04; +// } delay_hw = hw; pulse_width_incr_us = pw_incr_us; diff --git a/source/scripts/man/Makefile b/source/scripts/man/Makefile index 8783090..aa76f96 120000 --- a/source/scripts/man/Makefile +++ b/source/scripts/man/Makefile @@ -1 +1,153 @@ -../../../documentation/Makefile \ No newline at end of file +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/RPIO.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/RPIO.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/RPIO" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/RPIO" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/source/scripts/man/source/conf.py b/source/scripts/man/source/conf.py index f4cc04d..7f8e307 120000 --- a/source/scripts/man/source/conf.py +++ b/source/scripts/man/source/conf.py @@ -1 +1,242 @@ -../../../../documentation/source/conf.py \ No newline at end of file +# -*- coding: utf-8 -*- +# +# RPIO documentation build configuration file, created by +# sphinx-quickstart on Thu Feb 21 13:13:51 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('../../source/')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ["sphinx.ext.autodoc"] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'RPIO' +copyright = u'2013, Chris Hager ' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '2.0.0-beta1' +# The full version, including alpha/beta/rc tags. +release = version + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'RPIOdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'RPIO.tex', u'RPIO Documentation', + u'Chris Hager ', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'rpio', u'RPIO Documentation', + [u'Chris Hager '], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'RPIO', u'RPIO Documentation', + u'Chris Hager ', 'RPIO', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' diff --git a/source/scripts/man/source/index.rst b/source/scripts/man/source/index.rst index f4ef903..ce52162 120000 --- a/source/scripts/man/source/index.rst +++ b/source/scripts/man/source/index.rst @@ -1 +1,101 @@ -../../../../documentation/source/rpio_cmd.rst \ No newline at end of file +.. _ref-rpio-cmd: + +``rpio``, the command line tools +================================ + +``rpio`` includes two command-line tools which allow you to inspect and manipulate GPIO's system wide +(including those used by other processes). The BCM GPIO numbering scheme is used by default. + +* ``rpio``, a command-line tool to inspect and manipulate GPIOs +* ``rpio-curses``, ``rpio`` with a graphical user interface for the terminal + + +``rpio-curses`` +--------------- +``rpio-curses`` is a graphical user interface for the terminal to inspect and manipulate GPIOs. Its part of RPIO since +version 0.8.4. With ``rpio-curses`` you can see all GPIOs on the board with function and state, and change every +possible parameter. The list is updated every second, and instantly if you change something. You can start ``rpio-curses`` in the command line by typing:: + + $ rpio-curses + +Here are a few screenshots of ``rpio-curses`` in action: + +.. image:: images/rpio-curses_1.png +.. image:: images/rpio-curses_2.png + + +``rpio`` +-------- +``rpio --inspect-all`` (or ``-I``) is perhaps the most popular command, which shows you all gpios +on the board, with function and state. Here is an overview of all the functions of ``rpio``: + +:: + + Show the help page: + + $ rpio -h + + Inspect the function and state of gpios (with -i/--inspect): + + $ rpio -i 7 + $ rpio -i 7,8,9 + $ rpio -i 1-9 + + # Example output for `rpio -i 1-9` (non-existing are ommitted): + GPIO 2: ALT0 (1) + GPIO 3: ALT0 (1) + GPIO 4: INPUT (0) + GPIO 7: OUTPUT (0) + GPIO 8: INPUT (1) + GPIO 9: INPUT (0) + + Inspect all GPIO's on this board (with -I/--inspect-all): + + $ rpio -I + + Set GPIO 7 output to `1` (or `0`) (with -s/--set): + + $ rpio -s 7:1 + + You can only write to pins that have been set up as OUTPUT. You can + set this yourself with `--setoutput `. + + Wait for interrupt events on GPIOs (with -w/--wait_for_interrupts). You + can specify an edge (eg. `:rising`; default='both') as well as `:pullup`, + `:pulldown` or `pulloff`. + + $ rpio -w 7 + $ rpio -w 7:rising + $ rpio -w 7:falling:pullup + + $ rpio -w 7:rising:pullup,17,18 + $ rpio -w 1-9 + + Setup a pin as INPUT (optionally with software resistor): + + $ rpio --setinput 7 + $ rpio --setinput 7:pullup + $ rpio --setinput 7:pulldown + + Setup a pin as OUTPUT (optionally with an initial value (0 or 1)): + + $ rpio --setoutput 8 + $ rpio --setoutput 8:1 + + Show Raspberry Pi system info: + + $ rpio --sysinfo + + # Example output: + 000e: Model B, Revision 2.0, RAM: 256 MB, Maker: Sony + + +You can update the ``RPIO`` package to the latest version (equivalent to ``easy_install -U RPIO``):: + + $ rpio --update-rpio + + +Install (and update) the ``rpio`` manpage:: + + $ rpio --update-man + $ man rpio From b0780ec819b041ec93fcc4650469a01622ec0252 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 29 Jul 2017 08:07:34 +0100 Subject: [PATCH 08/12] moved to c_common --- source/c_gpio/cpuinfo.c | 95 ----------------------------------------- 1 file changed, 95 deletions(-) delete mode 100755 source/c_gpio/cpuinfo.c diff --git a/source/c_gpio/cpuinfo.c b/source/c_gpio/cpuinfo.c deleted file mode 100755 index 289df54..0000000 --- a/source/c_gpio/cpuinfo.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This file is part of RPIO. - * - * Copyright - * - * Copyright (C) 2013 Chris Hager - * - * License - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at - * - * - * Documentation - * - * http://pythonhosted.org/RPIO - */ -#include -#include -#include "cpuinfo.h" - -// Writes the hex revision str into the argument and returns: -// 2 (raspberry with revision 2 pin setup) -// 1 (raspberry with revision 1 pin setup) -// 0 (not a raspberry pi) -// -1 (could not open /proc/cpuinfo) -// -// revision_hex will be four characters revision id (eg. '0004'), -// the over-voltage header, if present, is removed (since it is -// not consistently present on all overclocked boards). -int -get_cpuinfo_revision(char *revision_hex) -{ - FILE *fp; - char buffer[1024]; - char hardware[1024]; - int rpi_found = 0; - int bcm2709 = 0; - int board_rev = 3; - - if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) - return -1; - - while(!feof(fp)) { - fgets(buffer, sizeof(buffer) , fp); - sscanf(buffer, "Hardware : %s", hardware); - if (strcmp(hardware, "BCM2708") == 0|| - strcmp(hardware, "BCM2709") == 0|| - strcmp(hardware, "BCM2835") == 0|| - strcmp(hardware, "BCM2836") == 0) - rpi_found = 1; - - if (strcmp(hardware, "BCM2709") == 0) - bcm2709 = 1; - sscanf(buffer, "Revision : %s", revision_hex); - } - fclose(fp); - - if (!rpi_found) { - revision_hex = NULL; - return 0; - } - - // If over-voltage is present, remove it - char* pos = strstr(revision_hex, "1000"); - if (pos && pos - revision_hex == 0 && strlen(revision_hex) > 5) { - strcpy(revision_hex, revision_hex+(strlen(revision_hex) - 4)); - } - - // Returns revision - if ((strcmp(revision_hex, "0002") == 0) || - (strcmp(revision_hex, "0003") == 0)) - board_rev = 1; - else if ((strcmp(revision_hex, "0004") == 0) - || (strcmp(revision_hex, "0005") == 0) - || (strcmp(revision_hex, "0006") == 0) - || (strcmp(revision_hex, "0007") == 0) - || (strcmp(revision_hex, "0008") == 0) - || (strcmp(revision_hex, "0009") == 0) - || (strcmp(revision_hex, "000d") == 0) - || (strcmp(revision_hex, "000e") == 0) - || (strcmp(revision_hex, "000f") == 0)) - board_rev = 2; - else // We'll call Model A+, B+, Pi2, Pi3 and Zero rev3 - board_rev = 3; - - return (bcm2709 << 8) | board_rev; -} From ee17c8d56ccc7725184bfe4a2abec0624461304d Mon Sep 17 00:00:00 2001 From: James Date: Sat, 29 Jul 2017 08:07:47 +0100 Subject: [PATCH 09/12] moved to c_common --- source/c_gpio/cpuinfo.h | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 source/c_gpio/cpuinfo.h diff --git a/source/c_gpio/cpuinfo.h b/source/c_gpio/cpuinfo.h deleted file mode 100644 index 3b54068..0000000 --- a/source/c_gpio/cpuinfo.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of RPIO. - * - * Copyright - * - * Copyright (C) 2013 Chris Hager - * - * License - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at - * - * - * Documentation - * - * http://pythonhosted.org/RPIO - */ -int get_cpuinfo_revision(char *revision_hex); \ No newline at end of file From 18d5e0edd5e31296fa8248f325e55e0e2ce83be3 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 31 Jul 2017 12:41:15 +0100 Subject: [PATCH 10/12] change base detection mechanism --- source/c_common/cpuinfo.c | 34 ++++++++++++++++++++++++++++++++++ source/c_common/cpuinfo.h | 4 +++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/source/c_common/cpuinfo.c b/source/c_common/cpuinfo.c index 289df54..985a832 100644 --- a/source/c_common/cpuinfo.c +++ b/source/c_common/cpuinfo.c @@ -93,3 +93,37 @@ get_cpuinfo_revision(char *revision_hex) return (bcm2709 << 8) | board_rev; } + +uint32_t get_peri_base(void){ + uint32_t base = 0x20000000; + FILE * filp; + char buf[512]; + + filp = fopen ("/proc/cpuinfo", "r"); + + if (filp != NULL) + { + while (fgets(buf, sizeof(buf), filp) != NULL) + { + if (!strncasecmp("model name", buf, 10)) + { + if (strstr (buf, "ARMv6") != NULL) + { + base = 0x20000000; + break; + } + else if ((strstr (buf, "ARMv7") != NULL) | // + (strstr (buf, "ARMv8") != NULL) | + (strstr (buf, "CPU architecture: 7") != NULL) | // aarch64 kernel may report this way + (strstr (buf, "CPU architecture: 8") != NULL)) // aarch64 kernel may report this way + { + base = 0x3F000000; + break; + } + } + } + + fclose(filp); + } + return base; +} \ No newline at end of file diff --git a/source/c_common/cpuinfo.h b/source/c_common/cpuinfo.h index 3b54068..d0d1bbc 100644 --- a/source/c_common/cpuinfo.h +++ b/source/c_common/cpuinfo.h @@ -22,4 +22,6 @@ * * http://pythonhosted.org/RPIO */ -int get_cpuinfo_revision(char *revision_hex); \ No newline at end of file +int get_cpuinfo_revision(char *revision_hex); + +uint32_t get_peri_base(void); \ No newline at end of file From acabfdee1fbb32f81ea24eef85d64a5dd6221566 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 31 Jul 2017 12:42:04 +0100 Subject: [PATCH 11/12] change detection mechanism --- source/c_gpio/c_gpio.c | 15 ++++++++------- source/c_pwm/pwm.c | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/source/c_gpio/c_gpio.c b/source/c_gpio/c_gpio.c index e233749..4969b1f 100755 --- a/source/c_gpio/c_gpio.c +++ b/source/c_gpio/c_gpio.c @@ -33,8 +33,8 @@ #include "c_gpio.h" #include "../c_common/cpuinfo.h" -#define BCM2708_PERI_BASE 0x20000000 -#define BCM2709_PERI_BASE 0x3f000000 +//#define BCM2708_PERI_BASE 0x20000000 +//#define BCM2709_PERI_BASE 0x3f000000 #define GPIO_BASE (peri_base + 0x200000) #define OFFSET_FSEL 0 // 0x0000 #define OFFSET_SET 7 // 0x001c / 4 @@ -83,11 +83,12 @@ setup(void) if ((uint32_t)gpio_mem % PAGE_SIZE) gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE); - type = get_cpuinfo_revision(revision_hex); - if ((type & 0x100) == 0) - peri_base = BCM2708_PERI_BASE; - else - peri_base = BCM2709_PERI_BASE; +// type = get_cpuinfo_revision(revision_hex); + peri_base = get_peri_base(); +// if ((type & 0x100) == 0) +// peri_base = BCM2708_PERI_BASE; +// else +// peri_base = BCM2709_PERI_BASE; gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, GPIO_BASE); diff --git a/source/c_pwm/pwm.c b/source/c_pwm/pwm.c index 96a00b5..50f9808 100644 --- a/source/c_pwm/pwm.c +++ b/source/c_pwm/pwm.c @@ -722,12 +722,12 @@ setup(int pw_incr_us, int hw) int type; char revision_hex[1024]; - type = get_cpuinfo_revision(revision_hex); - if ((type & 0x100) == 0) - peri_base = BCM2708_PERI_BASE; - else - peri_base = BCM2709_PERI_BASE; - +// type = get_cpuinfo_revision(revision_hex); +// if ((type & 0x100) == 0) +// peri_base = BCM2708_PERI_BASE; +// else +// peri_base = BCM2709_PERI_BASE; + peri_base = get_peri_base(); mem_flag = 0x04; // unsigned char buf[4]; // FILE *fp; From b1112f52ef485d0c0a66c070526fd98b863b05b2 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 30 Nov 2017 10:50:56 +0000 Subject: [PATCH 12/12] include missing header --- source/c_common/cpuinfo.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/c_common/cpuinfo.h b/source/c_common/cpuinfo.h index d0d1bbc..e21b938 100644 --- a/source/c_common/cpuinfo.h +++ b/source/c_common/cpuinfo.h @@ -22,6 +22,9 @@ * * http://pythonhosted.org/RPIO */ + +#include + int get_cpuinfo_revision(char *revision_hex); -uint32_t get_peri_base(void); \ No newline at end of file +uint32_t get_peri_base(void);