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

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler@mbp committed Mar 26, 2016
1 parent 35ec1f5 commit c15b142
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 600 deletions.
38 changes: 19 additions & 19 deletions source/c_gpio/c_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@
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;
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
Expand Down Expand Up @@ -103,12 +103,12 @@ setup(void)
int type = get_CPU_info();
if (type == -1) {
return SETUP_MMAP_FAIL;
}
}
else if (type == 1 ){
gpio_map = (uint32_t *)mmap( (void *)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, BCM2708_PERI_BASE + 0x200000);
}
}
else{
gpio_map = (uint32_t *)mmap( (void *)gpio_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, mem_fd, BCM2709_PERI_BASE + 0x200000);
gpio_map = (uint32_t *)mmap( (void *)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
8 changes: 4 additions & 4 deletions source/c_gpio/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// 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
int
get_cpuinfo_revision(char *revision_hex)
{
FILE *fp;
Expand Down Expand Up @@ -71,9 +71,9 @@ get_cpuinfo_revision(char *revision_hex)
if ((strcmp(revision_hex, "0002") == 0) ||
(strcmp(revision_hex, "0003") == 0)) {
return 1;
} else if (strcmp(revision_hex, "0010") == 0
|| strcmp(revision_hex, "a21041") == 0
|| strcmp(revision_hex, "a01041") == 0 ) {
} else if (strcmp(revision_hex, "0010") == 0 ||
strcmp(revision_hex, "a21041") == 0 ||
strcmp(revision_hex, "a01041") == 0 ) {
// We'll call Model B+ (0010) rev3 or Pi 2
return 3;
} else {
Expand Down
Loading

0 comments on commit c15b142

Please sign in to comment.