Skip to content

Commit

Permalink
First cut of Pi2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Walther committed Mar 1, 2015
1 parent 8494a68 commit a92a859
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 9 additions & 1 deletion source/c_gpio/c_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
#include <fcntl.h>
#include <sys/mman.h>
#include "c_gpio.h"
#include "cpuinfo.h"

#define BCM2708_PERI_BASE 0x20000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)
#define BCM2709_PERI_BASE 0x3f000000
int rpi_revision = 0;
#define GPIO_BASE (rpi_revision < 4 ? \
(BCM2708_PERI_BASE + 0x200000) : \
(BCM2709_PERI_BASE + 0x200000))
#define OFFSET_FSEL 0 // 0x0000
#define OFFSET_SET 7 // 0x001c / 4
#define OFFSET_CLR 10 // 0x0028 / 4
Expand Down Expand Up @@ -69,6 +74,9 @@ setup(void)
{
int mem_fd;
uint8_t *gpio_mem;
char dummy[1024];

rpi_revision = get_cpuinfo_revision(dummy);

if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0)
return SETUP_DEVMEM_FAIL;
Expand Down
15 changes: 12 additions & 3 deletions source/c_gpio/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "cpuinfo.h"

// Writes the hex revision str into the argument and returns:
// 4 MARCO: raspberry2
// 3 Pi+
// 2 (raspberry with revision 2 pin setup)
// 1 (raspberry with revision 1 pin setup)
// 0 (not a raspberry pi)
Expand All @@ -49,8 +51,12 @@ get_cpuinfo_revision(char *revision_hex)
while(!feof(fp)) {
fgets(buffer, sizeof(buffer) , fp);
sscanf(buffer, "Hardware : %s", hardware);
if (strcmp(hardware, "BCM2708") == 0)
rpi_found = 1;
if (strcmp(hardware, "BCM2708") == 0) {
rpi_found = 1;
} else if (strcmp(hardware, "BCM2709") == 0) {
rpi_found = 4;
}

sscanf(buffer, "Revision : %s", revision_hex);
}
fclose(fp);
Expand All @@ -67,7 +73,10 @@ get_cpuinfo_revision(char *revision_hex)
}

// Returns revision
if ((strcmp(revision_hex, "0002") == 0) ||
if (rpi_found == 4) {
// MARCO Pi2
return rpi_found;
} else if ((strcmp(revision_hex, "0002") == 0) ||
(strcmp(revision_hex, "0003") == 0)) {
return 1;
} else if ((strcmp(revision_hex, "0010") == 0)) {
Expand Down
1 change: 1 addition & 0 deletions source/c_gpio/py_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ PyMODINIT_FUNC init_GPIO(void)
gpio_to_pin = &gpio_to_pin_rev2;
break;
case 3:
case 4: // MARCO Pi2
pin_to_gpio = &pin_to_gpio_rev3;
gpio_to_pin = &gpio_to_pin_rev3;
break;
Expand Down

0 comments on commit a92a859

Please sign in to comment.