2 * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3 * Author: Michael Ring <mail@michael-ring.org>
4 * Copyright (c) 2014 Intel Corporation.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "mraa_internal.h"
30 #include "arm/raspberry_pi.h"
31 #include "arm/beaglebone.h"
32 #include "arm/banana.h"
37 mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
39 char* line = malloc(len);
40 FILE* fh = fopen("/proc/cpuinfo", "r");
42 while (getline(&line, &len, fh) != -1) {
43 if (strncmp(line, "Hardware", 8) == 0) {
44 if (strstr(line, "BCM2708")) {
45 platform_type = MRAA_RASPBERRY_PI;
47 if (strstr(line, "BCM2709")) {
48 platform_type = MRAA_RASPBERRY_PI;
50 if (strstr(line, "Generic AM33XX")) {
51 platform_type = MRAA_BEAGLEBONE;
53 if (strstr(line, "sun7i")) {
54 if (mraa_file_contains("/sys/firmware/devicetree/base/model", "Banana Pro")) {
55 platform_type = MRAA_BANANA;
57 if (mraa_file_contains("/sys/firmware/devicetree/base/model", "Banana Pi")) {
58 platform_type = MRAA_BANANA;
61 if (mraa_file_exist("/sys/class/leds/green:ph24:led1")) {
62 platform_type = MRAA_BANANA;
71 switch (platform_type) {
72 case MRAA_RASPBERRY_PI:
73 plat = mraa_raspberry_pi();
76 plat = mraa_beaglebone();
83 syslog(LOG_ERR, "Unknown Platform, currently not supported by MRAA");