Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import io
import os
from setuptools import setup, Extension


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
return io.open(os.path.join(os.path.dirname(__file__), fname), 'rt', encoding='utf-8').read()


setup(
Expand All @@ -19,7 +20,7 @@ def read(fname):
scripts=["source/scripts/rpio", "source/scripts/rpio-curses"],

description=(("Advanced GPIO for the Raspberry Pi. Extends RPi.GPIO with "
"PWM, GPIO interrups, TCP socket interrupts, command line tools "
"PWM, GPIO interrupts, TCP socket interrupts, command line tools "
"and more")),
long_description=read('README.rst'),
url="https://github.com/metachris/RPIO",
Expand Down
23 changes: 22 additions & 1 deletion source/RPIO/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,30 @@ def socket_callback(socket, val):
'9': ('A', '2.0', 256, 'Qisda'),
'd': ('B', '2.0', 512, 'Egoman'),
'e': ('B', '2.0', 512, 'Sony'),
'f': ('B', '2.0', 512, 'Qisda')
'f': ('B', '2.0', 512, 'Qisda'),
'a01041': ('Pi 2 B', '1.0', 1024, 'Sony'),
'a21041': ('Pi 2 B', '1.0', 1024, 'EMBEST')
}

# Consider a parser for the new scheme
#SRRR MMMM PPPP TTTT TTTT VVVV
#
#S scheme (0=old, 1=new)
#R RAM (0=256, 1=512, 2=1024)
#M manufacturer (0='SONY',1='EGOMAN',2='EMBEST',3='UNKNOWN',4='EMBEST')
#P processor (0=2835, 1=2836)
#T type (0='A', 1='B', 2='A+', 3='B+', 4='Pi 2 B', 5='Alpha', 6='Compute Module')
#V revision (0-15)
#
#1010 0010 0001 0000 0100 0001
#SRRR MMMM PPPP TTTT TTTT VVVV
#S=1 new scheme
#R=2 1024 MB
#M=2 EMBEST
#P=1 2836
#T=4 Pi 2 B
#V=1 1

# List of valid bcm gpio ids for raspberry rev1 and rev2. Used for inspect-all.
GPIO_LIST_R1 = (0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25)
GPIO_LIST_R2 = (2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 22, 23, 24, 25, \
Expand Down
36 changes: 33 additions & 3 deletions source/c_gpio/c_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
#include <fcntl.h>
#include <sys/mman.h>
#include "c_gpio.h"
#include <stdio.h>
#include <string.h>

#define BCM2708_PERI_BASE 0x20000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)
#define BCM2709_PERI_BASE 0x3f000000
//#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)
#define OFFSET_FSEL 0 // 0x0000
#define OFFSET_SET 7 // 0x001c / 4
#define OFFSET_CLR 10 // 0x0028 / 4
Expand All @@ -53,6 +56,25 @@

static volatile uint32_t *gpio_map;

int get_CPU_info(){
FILE *fp;
char buffer[1024];
char hardware[1024];
if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
return -1;
while(!feof(fp)) {
fgets(buffer, sizeof(buffer) , fp);
sscanf(buffer, "Hardware : %s", hardware);
// BCM2709 for Pi 2, change base for Pi 2
if (strcmp(hardware, "BCM2709") == 0){
return 2;
}
}
fclose(fp);
// Default for Pi 1
return 1;
}

// `short_wait` waits 150 cycles
void
short_wait(void)
Expand All @@ -79,8 +101,16 @@ setup(void)
if ((uint32_t)gpio_mem % PAGE_SIZE)
gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);

gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, GPIO_BASE);

int type = get_CPU_info();
if (type == -1) {
return SETUP_MMAP_FAIL;
}
else if (type == 1 ){
gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, BCM2708_PERI_BASE + 0x200000);
}
else{
gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, BCM2709_PERI_BASE + 0x200000);
}
if ((uint32_t)gpio_map < 0)
return SETUP_MMAP_FAIL;

Expand Down
1 change: 1 addition & 0 deletions source/c_gpio/c_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int input_gpio(int gpio);
void cleanup(void);
int gpio_function(int gpio);
void set_pullupdn(int gpio, int pud);
int get_CPU_info(void);

#define SETUP_OK 0
#define SETUP_DEVMEM_FAIL 1
Expand Down
3 changes: 2 additions & 1 deletion source/c_gpio/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ get_cpuinfo_revision(char *revision_hex)
while(!feof(fp)) {
fgets(buffer, sizeof(buffer) , fp);
sscanf(buffer, "Hardware : %s", hardware);
if (strcmp(hardware, "BCM2708") == 0)
// BCM2708 for Pi 1, BCM2709 for Pi 2
if (strcmp(hardware, "BCM2708") == 0 || strcmp(hardware, "BCM2709") == 0)
rpi_found = 1;
sscanf(buffer, "Revision : %s", revision_hex);
}
Expand Down
8 changes: 8 additions & 0 deletions source/c_pwm/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ setup_sighandlers(void)
{
int i;
for (i = 0; i < 64; i++) {
// A few signals are safe and can be ignored
switch (i) {
case SIGWINCH: // Window resizing
case SIGCHLD: // Child process exited
case SIGCONT: // Continue executing, if stopped
case SIGURG: // High bandwidth data is available at a socket
continue;
}
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = (void *) terminate;
Expand Down
8 changes: 8 additions & 0 deletions source/c_pwm/servod.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ setup_sighandlers(void)
{
int i;
for (i = 0; i < 64; i++) {
// A few signals are safe and can be ignored
switch (i) {
case SIGWINCH: // Window resizing
case SIGCHLD: // Child process exited
case SIGCONT: // Continue executing, if stopped
case SIGURG: // High bandwidth data is available at a socket
continue;
}
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = terminate;
Expand Down