diff --git a/documentation/source/rpio_py.rst b/documentation/source/rpio_py.rst old mode 100644 new mode 100755 index bdcbc45..6baa772 --- 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``) +* ``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/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/RPIO/__init__.py b/source/RPIO/__init__.py old mode 100644 new mode 100755 index fae1705..31cf4df --- a/source/RPIO/__init__.py +++ b/source/RPIO/__init__.py @@ -159,7 +159,26 @@ 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'), + '11': ('CM1', '1.0', 512, 'Sony'), + '12': ('A+', '1.1', 256, 'Sony'), + '13': ('B+', '1.2', 512, '?'), + '14': ('CM1', '1.0', 512, 'EMBEST'), + '15': ('A+', '1.1', 256, 'EMBEST'), + 'a01040': ('2B', '1.0', 1024, '?'), + '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.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. diff --git a/source/c_gpio/cpuinfo.c b/source/c_common/cpuinfo.c similarity index 59% rename from source/c_gpio/cpuinfo.c rename to source/c_common/cpuinfo.c index 922fc5f..985a832 100644 --- a/source/c_gpio/cpuinfo.c +++ b/source/c_common/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,15 +76,54 @@ 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)) { - // We'll call Model B+ (0010) rev3 - 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; } + +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_gpio/cpuinfo.h b/source/c_common/cpuinfo.h similarity index 89% rename from source/c_gpio/cpuinfo.h rename to source/c_common/cpuinfo.h index 3b54068..e21b938 100644 --- a/source/c_gpio/cpuinfo.h +++ b/source/c_common/cpuinfo.h @@ -22,4 +22,9 @@ * * http://pythonhosted.org/RPIO */ -int get_cpuinfo_revision(char *revision_hex); \ No newline at end of file + +#include + +int get_cpuinfo_revision(char *revision_hex); + +uint32_t get_peri_base(void); 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_gpio/c_gpio.c b/source/c_gpio/c_gpio.c old mode 100644 new mode 100755 index 25a04ca..4969b1f --- 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 "../c_common/cpuinfo.h" -#define BCM2708_PERI_BASE 0x20000000 -#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) +//#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 #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,13 @@ 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); + 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); if ((uint32_t)gpio_map < 0) diff --git a/source/c_gpio/py_gpio.c b/source/c_gpio/py_gpio.c old mode 100644 new mode 100755 index 2e8ab7b..63e4bbe --- 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; @@ -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/c_pwm/Makefile b/source/c_pwm/Makefile index 66dd765..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,5 +26,42 @@ 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: + 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 -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: + 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 -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: + 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 -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: + 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 -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/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..50f9808 100644 --- a/source/c_pwm/pwm.c +++ b/source/c_pwm/pwm.c @@ -86,7 +86,7 @@ #include #include "pwm.h" #include "mailbox.h" -#define MBFILE DEVICE_FILE_NAME /* From mailbox.h */ +#include "../c_common/cpuinfo.h" // 15 DMA channels are usable on the RPi (0..14) #define DMA_CHANNELS 15 @@ -104,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 @@ -115,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) @@ -321,7 +324,6 @@ shutdown(void) } } _is_setup =0; - unlink(MBFILE); } // Terminate is triggered by signals @@ -717,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; + peri_base = get_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; @@ -757,8 +771,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/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 diff --git a/source/scripts/rpio b/source/scripts/rpio old mode 100644 new mode 100755 index 7637136..bcf7fcb --- 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+': - 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+': - 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 old mode 100644 new mode 100755 index fc549ec..6512eb8 --- 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+': - 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 old mode 100644 new mode 100755 index 395c811..e865a18 --- 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+': - 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)