cmake: enable settign of MRAAPLATFORMFORCE to reduce libmraa.so size
[contrib/mraa.git] / src / x86 / x86.c
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "mraa_internal.h"
29
30 #include "x86/intel_galileo_rev_d.h"
31 #include "x86/intel_galileo_rev_g.h"
32 #include "x86/intel_edison_fab_c.h"
33 #include "x86/intel_de3815.h"
34 #include "x86/intel_nuc5.h"
35 #include "x86/intel_minnow_byt_compatible.h"
36
37 mraa_platform_t
38 mraa_x86_platform()
39 {
40 #ifndef MRAA_PLATFORM_FORCE
41     mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
42
43     char* line = NULL;
44     // let getline allocate memory for *line
45     size_t len = 0;
46     FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
47     if (fh != NULL) {
48         if (getline(&line, &len, fh) != -1) {
49             if (strncmp(line, "GalileoGen2", 11) == 0) {
50                 platform_type = MRAA_INTEL_GALILEO_GEN2;
51                 plat = mraa_intel_galileo_gen2();
52             } else if (strncmp(line, "BODEGA BAY", 10) == 0) {
53                 platform_type = MRAA_INTEL_EDISON_FAB_C;
54                 plat = mraa_intel_edison_fab_c();
55             } else if (strncmp(line, "SALT BAY", 8) == 0) {
56                 platform_type = MRAA_INTEL_EDISON_FAB_C;
57                 plat = mraa_intel_edison_fab_c();
58             } else if (strncmp(line, "DE3815", 6) == 0) {
59                 platform_type = MRAA_INTEL_DE3815;
60                 plat = mraa_intel_de3815();
61             } else if (strncmp(line, "NUC5i5MYBE", 10) == 0 || strncmp(line, "NUC5i3MYBE", 10) == 0) {
62                 platform_type = MRAA_INTEL_NUC5;
63                 plat = mraa_intel_nuc5();
64             } else if (strncmp(line, "NOTEBOOK", 8) == 0) {
65                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
66                 plat = mraa_intel_minnowboard_byt_compatible();
67             } else if (strncasecmp(line, "MinnowBoard MAX", 15) == 0) {
68                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
69                 plat = mraa_intel_minnowboard_byt_compatible();
70             } else if (strncasecmp(line, "Galileo", 7) == 0) {
71                 platform_type = MRAA_INTEL_GALILEO_GEN1;
72                 plat = mraa_intel_galileo_rev_d();
73             } else if (strncasecmp(line, "MinnowBoard Compatible", 22) == 0) {
74                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
75                 plat = mraa_intel_minnowboard_byt_compatible();
76             } else {
77                 syslog(LOG_ERR, "Platform not supported, not initialising");
78                 platform_type = MRAA_UNKNOWN_PLATFORM;
79             }
80             free(line);
81         }
82         fclose(fh);
83     }
84
85     return platform_type;
86 #else
87     #if defined(xMRAA_INTEL_GALILEO_GEN2)
88     plat = mraa_intel_galileo_gen2();
89     #elif defined(xMRAA_INTEL_EDISON_FAB_C)
90     plat = mraa_intel_edison_fab_c();
91     #elif defined(xMRAA_INTEL_DE3815)
92     plat = mraa_intel_de3815();
93     #elif defined(xMRAA_INTEL_MINNOWBOARD_MAX)
94     plat = mraa_intel_minnowboard_byt_compatible();
95     #elif defined(xMRAA_INTEL_GALILEO_GEN1)
96     plat = mraa_intel_galileo_rev_d();
97     #elif defined(xMRAA_INTEL_NUC5)
98     plat = mraa_intel_nuc5();
99     #else
100         #error "Not using a valid platform value from mraa_platform_t - cannot compile"
101     #endif
102     return MRAA_PLATFORM_FORCE;
103 #endif
104 }