Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit e18797e

Browse files
author
Yannick
committed
Fix Raspberry Pi 2 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
1 parent 07c776f commit e18797e

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

source/RPIO/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ def socket_callback(socket, val):
159159
'd': ('B', '2.0', 512, 'Egoman'),
160160
'e': ('B', '2.0', 512, 'Sony'),
161161
'f': ('B', '2.0', 512, 'Qisda'),
162-
'10': ('B+', '1.0', 512, 'Sony')
162+
'10': ('B+', '1.0', 512, 'Sony'),
163+
'a01041': ('2B', '1.0', 1024, 'Sony'),
164+
'a21041': ('2B', '1.0', 1024, 'EMBEST')
163165
}
164166

165167
# List of valid bcm gpio ids for raspberry rev1, rev2 and rev3. Used for inspect-all.

source/c_gpio/c_gpio.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
#include <fcntl.h>
3232
#include <sys/mman.h>
3333
#include "c_gpio.h"
34+
#include "cpuinfo.h"
3435

3536
#define BCM2708_PERI_BASE 0x20000000
36-
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)
37+
#define BCM2709_PERI_BASE 0x3f000000
38+
#define GPIO_BASE (peri_base + 0x200000)
3739
#define OFFSET_FSEL 0 // 0x0000
3840
#define OFFSET_SET 7 // 0x001c / 4
3941
#define OFFSET_CLR 10 // 0x0028 / 4
@@ -52,6 +54,7 @@
5254
#define BLOCK_SIZE (4*1024)
5355

5456
static volatile uint32_t *gpio_map;
57+
static uint32_t peri_base;
5558

5659
// `short_wait` waits 150 cycles
5760
void
@@ -67,7 +70,8 @@ short_wait(void)
6770
int
6871
setup(void)
6972
{
70-
int mem_fd;
73+
int mem_fd, type;
74+
char revision_hex[1024];
7175
uint8_t *gpio_mem;
7276

7377
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0)
@@ -79,6 +83,12 @@ setup(void)
7983
if ((uint32_t)gpio_mem % PAGE_SIZE)
8084
gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);
8185

86+
type = get_cpuinfo_revision(revision_hex);
87+
if (type == 1)
88+
peri_base = BCM2708_PERI_BASE;
89+
else
90+
peri_base = BCM2709_PERI_BASE;
91+
8292
gpio_map = (uint32_t *)mmap( (caddr_t)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, GPIO_BASE);
8393

8494
if ((uint32_t)gpio_map < 0)

source/c_gpio/cpuinfo.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ get_cpuinfo_revision(char *revision_hex)
7575
(strcmp(revision_hex, "0003") == 0)) {
7676
return 1;
7777
} else if ((strcmp(revision_hex, "0010") == 0)) {
78-
// We'll call Model B+ (0010) rev3
78+
} else if (strcmp(revision_hex, "0010") == 0
79+
|| strcmp(revision_hex, "a21041") == 0
80+
|| strcmp(revision_hex, "a01041") == 0 ) {
81+
// We'll call Model B+ (0010) rev3 or Pi 2
7982
return 3;
8083
} else {
8184
// assume rev 2 (0004 0005 0006 ...)

source/c_pwm/mailbox.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
#include <stdint.h>
3535
#include <sys/mman.h>
3636
#include <sys/ioctl.h>
37+
#include <sys/stat.h>
3738

3839
#include "mailbox.h"
3940

@@ -249,9 +250,17 @@ int mbox_open() {
249250
// open a char device file used for communicating with kernel mbox driver
250251
file_desc = open(DEVICE_FILE_NAME, 0);
251252
if (file_desc < 0) {
252-
printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
253-
printf("Try creating a device file with: sudo mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUM);
254-
exit(-1);
253+
unlink(DEVICE_FILE_NAME);
254+
if (mknod(DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM, 0)) < 0) {
255+
printf("Failed to create mailbox device\n");
256+
exit(-1);
257+
}
258+
file_desc = open(DEVICE_FILE_NAME, 0);
259+
if (file_desc < 0) {
260+
printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
261+
printf("Try creating a device file with: sudo mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUM);
262+
exit(-1);
263+
}
255264
}
256265
return file_desc;
257266
}

source/c_pwm/mailbox.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
#define MAJOR_NUM 100
3131
#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
32-
#define DEVICE_FILE_NAME "/dev/vcio-mb"
32+
#define DEVICE_FILE_NAME "/dev/vcio"
3333

34-
int mbox_open();
34+
int mbox_open(void);
3535
void mbox_close(int file_desc);
3636

3737
unsigned get_version(int file_desc);

source/c_pwm/pwm.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
#include <sys/mman.h>
8787
#include "pwm.h"
8888
#include "mailbox.h"
89-
#define MBFILE DEVICE_FILE_NAME /* From mailbox.h */
9089
// 15 DMA channels are usable on the RPi (0..14)
9190
#define DMA_CHANNELS 15
9291

@@ -321,7 +320,6 @@ shutdown(void)
321320
}
322321
}
323322
_is_setup =0;
324-
unlink(MBFILE);
325323
}
326324

327325
// Terminate is triggered by signals
@@ -757,8 +755,6 @@ setup(int pw_incr_us, int hw)
757755
init_hardware();
758756
/* Use the mailbox interface to the VC to ask for physical memory */
759757

760-
if (mknod(MBFILE, S_IFCHR|0600, makedev(249, 0)) < 0)
761-
return fatal("Failed to create mailbox device\n");
762758
mbox.handle = mbox_open();
763759
if (mbox.handle < 0)
764760
return fatal("Failed to open mailbox\n");

source/scripts/rpio-curses

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if "no_rpio" not in CMD_OPTIONS:
7575
RPIO.setwarnings(False)
7676
RPIO_VERSION = RPIO.VERSION
7777
def get_gpiolist():
78-
if RPIO.sysinfo()[1] == 'B+':
78+
if RPIO.sysinfo()[1] == 'B+' or RPIO.sysinfo()[1] == '2B':
7979
pins = RPIO.GPIO_LIST_R3
8080
elif RPIO.RPI_REVISION == 1:
8181
pins = RPIO.GPIO_LIST_R1

0 commit comments

Comments
 (0)