1 /*
2 * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3 * Author: Michael Ring <mail@michael-ring.org>
4 * Copyright (c) 2014 Intel Corporation.
5 *
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:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
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.
24 */
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/mman.h>
29 #include <mraa/common.h>
30
31 #include "common.h"
32 #include "arm/raspberry_pi.h"
33
34 #define PLATFORM_NAME_RASPBERRY_PI_B_REV_1 "Raspberry Pi Model B Rev 1"
35 #define PLATFORM_NAME_RASPBERRY_PI_A_REV_2 "Raspberry Pi Model A Rev 2"
36 #define PLATFORM_NAME_RASPBERRY_PI_B_REV_2 "Raspberry Pi Model B Rev 2"
37 #define PLATFORM_NAME_RASPBERRY_PI_B_PLUS_REV_1 "Raspberry Pi Model B+ Rev 1"
38 #define PLATFORM_NAME_RASPBERRY_PI_COMPUTE_MODULE_REV_1 "Raspberry Pi Compute Module Rev 1"
39 #define PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1 "Raspberry Pi Model A+ Rev 1"
40 #define PLATFORM_NAME_RASPBERRY_PI2_B_REV_1 "Raspberry Pi 2 Model B Rev 1"
41 #define PLATFORM_RASPBERRY_PI_B_REV_1 1
42 #define PLATFORM_RASPBERRY_PI_A_REV_2 2
43 #define PLATFORM_RASPBERRY_PI_B_REV_2 3
44 #define PLATFORM_RASPBERRY_PI_B_PLUS_REV_1 4
45 #define PLATFORM_RASPBERRY_PI_COMPUTE_MODULE_REV_1 5
46 #define PLATFORM_RASPBERRY_PI_A_PLUS_REV_1 6
47 #define PLATFORM_RASPBERRY_PI2_B_REV_1 7
48 #define MMAP_PATH "/dev/mem"
49 #define BCM2835_PERI_BASE 0x20000000
50 #define BCM2835_GPIO_BASE (BCM2835_PERI_BASE + 0x200000)
51 #define BCM2836_PERI_BASE 0x3f000000
52 #define BCM2836_GPIO_BASE (BCM2836_PERI_BASE + 0x200000)
53 #define BCM2835_BLOCK_SIZE (4 * 1024)
54 #define BCM2836_BLOCK_SIZE (4 * 1024)
55 #define BCM283X_GPSET0 0x001c
56 #define BCM283X_GPCLR0 0x0028
57 #define BCM2835_GPLEV0 0x0034
58 #define MAX_SIZE 64
59
60 // MMAP
61 static uint8_t* mmap_reg = NULL;
62 static int mmap_fd = 0;
63 static int mmap_size;
64 static unsigned int mmap_count = 0;
65 static int platform_detected = 0;
66
67 mraa_result_t
mraa_raspberry_pi_spi_init_pre(int index)68 mraa_raspberry_pi_spi_init_pre(int index)
69 {
70 char devpath[MAX_SIZE];
71 sprintf(devpath, "/dev/spidev%u.0", plat->spi_bus[index].bus_id);
72 if (!mraa_file_exist(devpath)) {
73 syslog(LOG_ERR, "spi: Device not initialized");
74 syslog(LOG_ERR, "spi: If you run a kernel >=3.18 then you will have to add dtparam=spi=on "
75 "to /boot/config.txt and reboot");
76 syslog(LOG_INFO, "spi: trying modprobe for spi-bcm2708");
77 system("modprobe spi-bcm2708 >/dev/null 2>&1");
78 system("modprobe spi_bcm2708 >/dev/null 2>&1");
79 if (!mraa_file_exist(devpath)) {
80 return MRAA_ERROR_NO_RESOURCES;
81 }
82 }
83 return MRAA_SUCCESS;
84 }
85
86 mraa_result_t
mraa_raspberry_pi_i2c_init_pre(unsigned int bus)87 mraa_raspberry_pi_i2c_init_pre(unsigned int bus)
88 {
89 char devpath[MAX_SIZE];
90 sprintf(devpath, "/dev/i2c-%u", bus);
91 if (!mraa_file_exist(devpath)) {
92 syslog(LOG_INFO, "spi: trying modprobe for i2c-bcm2708 & i2c-dev");
93 system("modprobe i2c-bcm2708 >/dev/null 2>&1");
94 system("modprobe i2c-dev >/dev/null 2>&1");
95 system("modprobe i2c_bcm2708 >/dev/null 2>&1");
96 system("modprobe i2c_dev >/dev/null 2>&1");
97 }
98 if (!mraa_file_exist(devpath)) {
99 syslog(LOG_ERR, "i2c: Device not initialized");
100 if (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_1) {
101 syslog(LOG_ERR, "i2c: If you run a kernel >=3.18 then you will have to add "
102 "dtparam=i2c0=on to /boot/config.txt and reboot");
103 } else {
104 syslog(LOG_ERR, "i2c: If you run a kernel >=3.18 then you will have to add "
105 "dtparam=i2c1=on to /boot/config.txt and reboot");
106 }
107 return MRAA_ERROR_NO_RESOURCES;
108 }
109 return MRAA_SUCCESS;
110 }
111
112 mraa_result_t
mraa_raspberry_pi_mmap_write(mraa_gpio_context dev,int value)113 mraa_raspberry_pi_mmap_write(mraa_gpio_context dev, int value)
114 {
115 volatile uint32_t* addr;
116 if (value) {
117 *(volatile uint32_t*) (mmap_reg + BCM283X_GPSET0 + (dev->pin / 32) * 4) =
118 (uint32_t)(1 << (dev->pin % 32));
119 } else {
120 *(volatile uint32_t*) (mmap_reg + BCM283X_GPCLR0 + (dev->pin / 32) * 4) =
121 (uint32_t)(1 << (dev->pin % 32));
122 }
123 return MRAA_SUCCESS;
124 }
125
126 static mraa_result_t
mraa_raspberry_pi_mmap_unsetup()127 mraa_raspberry_pi_mmap_unsetup()
128 {
129 if (mmap_reg == NULL) {
130 syslog(LOG_ERR, "raspberry mmap: null register cant unsetup");
131 return MRAA_ERROR_INVALID_RESOURCE;
132 }
133 munmap(mmap_reg, mmap_size);
134 mmap_reg = NULL;
135 if (close(mmap_fd) != 0) {
136 return MRAA_ERROR_INVALID_RESOURCE;
137 }
138 return MRAA_SUCCESS;
139 }
140
141 int
mraa_raspberry_pi_mmap_read(mraa_gpio_context dev)142 mraa_raspberry_pi_mmap_read(mraa_gpio_context dev)
143 {
144 uint32_t value = *(volatile uint32_t*) (mmap_reg + BCM2835_GPLEV0 + (dev->pin / 32) * 4);
145 if (value & (uint32_t)(1 << (dev->pin % 32))) {
146 return 1;
147 }
148 return 0;
149 }
150
151 mraa_result_t
mraa_raspberry_pi_mmap_setup(mraa_gpio_context dev,mraa_boolean_t en)152 mraa_raspberry_pi_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
153 {
154 if (dev == NULL) {
155 syslog(LOG_ERR, "raspberry mmap: context not valid");
156 return MRAA_ERROR_INVALID_HANDLE;
157 }
158
159 if (en == 0) {
160 if (dev->mmap_write == NULL && dev->mmap_read == NULL) {
161 syslog(LOG_ERR, "raspberry mmap: can't disable disabled mmap gpio");
162 return MRAA_ERROR_INVALID_PARAMETER;
163 }
164 dev->mmap_write = NULL;
165 dev->mmap_read = NULL;
166 mmap_count--;
167 if (mmap_count == 0) {
168 return mraa_raspberry_pi_mmap_unsetup();
169 }
170 return MRAA_SUCCESS;
171 }
172
173 if (dev->mmap_write != NULL && dev->mmap_read != NULL) {
174 syslog(LOG_ERR, "raspberry mmap: can't enable enabled mmap gpio");
175 return MRAA_ERROR_INVALID_PARAMETER;
176 }
177
178 // Might need to make some elements of this thread safe.
179 // For example only allow one thread to enter the following block
180 // to prevent mmap'ing twice.
181 if (mmap_reg == NULL) {
182 if ((mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) {
183 syslog(LOG_ERR, "raspberry map: unable to open resource0 file");
184 return MRAA_ERROR_INVALID_HANDLE;
185 }
186
187 if (platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1) {
188 mmap_reg = (uint8_t*) mmap(NULL, BCM2836_BLOCK_SIZE, PROT_READ | PROT_WRITE,
189 MAP_FILE | MAP_SHARED, mmap_fd, BCM2836_GPIO_BASE);
190 } else {
191 mmap_reg = (uint8_t*) mmap(NULL, BCM2835_BLOCK_SIZE, PROT_READ | PROT_WRITE,
192 MAP_FILE | MAP_SHARED, mmap_fd, BCM2835_GPIO_BASE);
193 }
194 if (mmap_reg == MAP_FAILED) {
195 syslog(LOG_ERR, "raspberry mmap: failed to mmap");
196 mmap_reg = NULL;
197 close(mmap_fd);
198 return MRAA_ERROR_NO_RESOURCES;
199 }
200 }
201 dev->mmap_write = &mraa_raspberry_pi_mmap_write;
202 dev->mmap_read = &mraa_raspberry_pi_mmap_read;
203 mmap_count++;
204
205 return MRAA_SUCCESS;
206 }
207
208 mraa_board_t*
mraa_raspberry_pi()209 mraa_raspberry_pi()
210 {
211 mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
212 if (b == NULL) {
213 return NULL;
214 }
215 b->phy_pin_count = 0;
216
217 size_t len = 100;
218 char* line = calloc(len, sizeof(char));
219
220 FILE* fh = fopen("/proc/cpuinfo", "r");
221 if (fh != NULL) {
222 while (getline(&line, &len, fh) != -1) {
223 if (strncmp(line, "Revision", 8) == 0) {
224 if (strstr(line, "0002") || strstr(line, "0003")) {
225 b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1;
226 platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1;
227 b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT;
228 } else if (strstr(line, "0004") || strstr(line, "0005") || strstr(line, "0006") ||
229 strstr(line, "000d") || strstr(line, "000e") || strstr(line, "000f")) {
230 b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_2;
231 platform_detected = PLATFORM_RASPBERRY_PI_B_REV_2;
232 b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
233 } else if (strstr(line, "0007") || strstr(line, "0008") || strstr(line, "0009")) {
234 b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_REV_2;
235 platform_detected = PLATFORM_RASPBERRY_PI_A_REV_2;
236 b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
237 } else if (strstr(line, "0010")) {
238 b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_PLUS_REV_1;
239 platform_detected = PLATFORM_RASPBERRY_PI_B_PLUS_REV_1;
240 b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT;
241 } else if (strstr(line, "0011")) {
242 b->platform_name = PLATFORM_NAME_RASPBERRY_PI_COMPUTE_MODULE_REV_1;
243 platform_detected = PLATFORM_RASPBERRY_PI_COMPUTE_MODULE_REV_1;
244 b->phy_pin_count = MRAA_RASPBERRY_PI_COMPUTE_MODULE_PINCOUNT;
245 } else if (strstr(line, "0012")) {
246 b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1;
247 platform_detected = PLATFORM_RASPBERRY_PI_A_PLUS_REV_1;
248 b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT;
249 } else if (strstr(line, "a01041") || strstr(line, "a21041")) {
250 b->platform_name = PLATFORM_NAME_RASPBERRY_PI2_B_REV_1;
251 platform_detected = PLATFORM_RASPBERRY_PI2_B_REV_1;
252 b->phy_pin_count = MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT;
253 } else {
254 b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1;
255 platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1;
256 b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT;
257 }
258 }
259 }
260 fclose(fh);
261 }
262 free(line);
263
264 b->aio_count = 0;
265 b->adc_raw = 0;
266 b->adc_supported = 0;
267 b->pwm_default_period = 500;
268 b->pwm_max_period = 2147483;
269 b->pwm_min_period = 1;
270
271 if (b->phy_pin_count == 0) {
272 free(b);
273 syslog(LOG_ERR, "raspberrypi: Failed to detect platform revision");
274 return NULL;
275 }
276
277 b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
278 if (b->adv_func == NULL) {
279 free(b);
280 return NULL;
281 }
282
283 b->pins = (mraa_pininfo_t*) calloc(b->phy_pin_count, sizeof(mraa_pininfo_t));
284 if (b->pins == NULL) {
285 free(b->adv_func);
286 free(b);
287 return NULL;
288 }
289
290 b->adv_func->spi_init_pre = &mraa_raspberry_pi_spi_init_pre;
291 b->adv_func->i2c_init_pre = &mraa_raspberry_pi_i2c_init_pre;
292 b->adv_func->gpio_mmap_setup = &mraa_raspberry_pi_mmap_setup;
293
294 strncpy(b->pins[0].name, "INVALID", MRAA_PIN_NAME_SIZE);
295 b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
296
297 strncpy(b->pins[1].name, "3V3", MRAA_PIN_NAME_SIZE);
298 b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
299
300 strncpy(b->pins[2].name, "5V", MRAA_PIN_NAME_SIZE);
301 b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
302
303 strncpy(b->pins[3].name, "SDA0", MRAA_PIN_NAME_SIZE);
304 b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
305 b->pins[3].gpio.pinmap = 2;
306 b->pins[3].gpio.mux_total = 0;
307 b->pins[3].i2c.pinmap = 0;
308 b->pins[3].i2c.mux_total = 0;
309
310 strncpy(b->pins[4].name, "5V", MRAA_PIN_NAME_SIZE);
311 b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
312
313 strncpy(b->pins[5].name, "SCL0", MRAA_PIN_NAME_SIZE);
314 b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
315 b->pins[5].gpio.pinmap = 3;
316 b->pins[5].gpio.mux_total = 0;
317 b->pins[5].i2c.pinmap = 0;
318 b->pins[5].i2c.mux_total = 0;
319
320 strncpy(b->pins[6].name, "GND", MRAA_PIN_NAME_SIZE);
321 b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
322
323 strncpy(b->pins[7].name, "GPIO4", MRAA_PIN_NAME_SIZE);
324 b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
325 b->pins[7].gpio.pinmap = 4;
326 b->pins[7].gpio.mux_total = 0;
327
328 strncpy(b->pins[8].name, "UART_TX", MRAA_PIN_NAME_SIZE);
329 b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
330 b->pins[8].gpio.pinmap = 14;
331 b->pins[8].gpio.mux_total = 0;
332 b->pins[8].uart.parent_id = 0;
333 b->pins[8].uart.mux_total = 0;
334
335 strncpy(b->pins[9].name, "GND", MRAA_PIN_NAME_SIZE);
336 b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
337
338 strncpy(b->pins[10].name, "UART_RX", MRAA_PIN_NAME_SIZE);
339 b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
340 b->pins[10].gpio.pinmap = 15;
341 b->pins[10].gpio.mux_total = 0;
342 b->pins[10].uart.parent_id = 0;
343 b->pins[10].uart.mux_total = 0;
344
345 strncpy(b->pins[11].name, "GPIO17", MRAA_PIN_NAME_SIZE);
346 b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
347 b->pins[11].gpio.pinmap = 17;
348 b->pins[11].gpio.mux_total = 0;
349
350 strncpy(b->pins[12].name, "GPIO18", MRAA_PIN_NAME_SIZE);
351 b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
352 b->pins[12].gpio.pinmap = 18;
353 b->pins[12].gpio.mux_total = 0;
354
355 if (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_1) {
356 strncpy(b->pins[13].name, "GPIO21", MRAA_PIN_NAME_SIZE);
357 b->pins[13].gpio.pinmap = 21;
358 } else {
359 strncpy(b->pins[13].name, "GPIO27", MRAA_PIN_NAME_SIZE);
360 b->pins[13].gpio.pinmap = 27;
361 }
362 b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
363 b->pins[13].gpio.mux_total = 0;
364
365 strncpy(b->pins[14].name, "GND", MRAA_PIN_NAME_SIZE);
366 b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
367
368 strncpy(b->pins[15].name, "GPIO22", MRAA_PIN_NAME_SIZE);
369 b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
370 b->pins[15].gpio.pinmap = 22;
371 b->pins[15].gpio.mux_total = 0;
372
373 strncpy(b->pins[16].name, "GPIO23", MRAA_PIN_NAME_SIZE);
374 b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
375 b->pins[16].gpio.pinmap = 23;
376 b->pins[16].gpio.mux_total = 0;
377
378 strncpy(b->pins[17].name, "3V3", MRAA_PIN_NAME_SIZE);
379 b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
380
381 strncpy(b->pins[18].name, "GPIO24", MRAA_PIN_NAME_SIZE);
382 b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
383 b->pins[18].gpio.pinmap = 24;
384 b->pins[18].gpio.mux_total = 0;
385
386 strncpy(b->pins[19].name, "SPI_MOSI", MRAA_PIN_NAME_SIZE);
387 b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
388 b->pins[19].gpio.pinmap = 10;
389 b->pins[19].gpio.mux_total = 0;
390 b->pins[19].spi.pinmap = 0;
391 b->pins[19].spi.mux_total = 0;
392
393 strncpy(b->pins[20].name, "GND", MRAA_PIN_NAME_SIZE);
394 b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
395
396 strncpy(b->pins[21].name, "SPI_MISO", MRAA_PIN_NAME_SIZE);
397 b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
398 b->pins[21].gpio.pinmap = 9;
399 b->pins[21].gpio.mux_total = 0;
400 b->pins[21].spi.pinmap = 0;
401 b->pins[21].spi.mux_total = 0;
402
403 strncpy(b->pins[22].name, "GPIO25", MRAA_PIN_NAME_SIZE);
404 b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
405 b->pins[22].gpio.pinmap = 25;
406 b->pins[22].gpio.mux_total = 0;
407
408 strncpy(b->pins[23].name, "SPI_CLK", MRAA_PIN_NAME_SIZE);
409 b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
410 b->pins[23].gpio.pinmap = 11;
411 b->pins[23].gpio.mux_total = 0;
412 b->pins[23].spi.pinmap = 0;
413 b->pins[23].spi.mux_total = 0;
414
415 strncpy(b->pins[24].name, "SPI_CS0", MRAA_PIN_NAME_SIZE);
416 b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
417 b->pins[24].gpio.pinmap = 8;
418 b->pins[24].gpio.mux_total = 0;
419 b->pins[24].spi.pinmap = 0;
420 b->pins[24].spi.mux_total = 0;
421
422 strncpy(b->pins[25].name, "GND", MRAA_PIN_NAME_SIZE);
423 b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
424
425 strncpy(b->pins[26].name, "SPI_CS1", MRAA_PIN_NAME_SIZE);
426 b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
427 b->pins[26].gpio.pinmap = 7;
428 b->pins[26].gpio.mux_total = 0;
429 b->pins[26].spi.pinmap = 0;
430 b->pins[26].spi.mux_total = 0;
431
432 if ((platform_detected == PLATFORM_RASPBERRY_PI_A_REV_2) ||
433 (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_2)) {
434 strncpy(b->pins[27].name, "5V", MRAA_PIN_NAME_SIZE);
435 b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
436
437 strncpy(b->pins[28].name, "3V3", MRAA_PIN_NAME_SIZE);
438 b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
439
440 strncpy(b->pins[29].name, "GPIO8", MRAA_PIN_NAME_SIZE);
441 b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
442 b->pins[29].gpio.pinmap = 8;
443 b->pins[29].gpio.mux_total = 0;
444
445 strncpy(b->pins[30].name, "GPIO9", MRAA_PIN_NAME_SIZE);
446 b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
447 b->pins[30].gpio.pinmap = 9;
448 b->pins[30].gpio.mux_total = 0;
449
450 strncpy(b->pins[31].name, "GPIO10", MRAA_PIN_NAME_SIZE);
451 b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
452 b->pins[31].gpio.pinmap = 10;
453 b->pins[31].gpio.mux_total = 0;
454
455 strncpy(b->pins[32].name, "GPIO11", MRAA_PIN_NAME_SIZE);
456 b->pins[32].gpio.pinmap = 11;
457 b->pins[32].gpio.mux_total = 0;
458 b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
459
460 strncpy(b->pins[33].name, "GND", MRAA_PIN_NAME_SIZE);
461 b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
462
463 strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
464 b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
465 }
466
467 // BUS DEFINITIONS
468 b->i2c_bus_count = 1;
469 b->def_i2c_bus = 0;
470 if (platform_detected == PLATFORM_RASPBERRY_PI_B_REV_1)
471 b->i2c_bus[0].bus_id = 0;
472 else
473 b->i2c_bus[0].bus_id = 1;
474 b->i2c_bus[0].sda = 3;
475 b->i2c_bus[0].scl = 5;
476
477 b->spi_bus_count = 1;
478 b->def_spi_bus = 0;
479 b->spi_bus[0].bus_id = 0;
480 b->spi_bus[0].slave_s = 0;
481 b->spi_bus[0].cs = 24;
482 b->spi_bus[0].mosi = 19;
483 b->spi_bus[0].miso = 21;
484 b->spi_bus[0].sclk = 23;
485
486 b->uart_dev_count = 1;
487 b->def_uart_dev = 0;
488 b->uart_dev[0].rx = 10;
489 b->uart_dev[0].tx = 8;
490
491 if ((platform_detected == PLATFORM_RASPBERRY_PI_A_PLUS_REV_1) ||
492 (platform_detected == PLATFORM_RASPBERRY_PI_B_PLUS_REV_1) ||
493 (platform_detected == PLATFORM_RASPBERRY_PI2_B_REV_1)) {
494
495 strncpy(b->pins[27].name, "ID_SD", MRAA_PIN_NAME_SIZE);
496 b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
497
498 strncpy(b->pins[28].name, "ID_SC", MRAA_PIN_NAME_SIZE);
499 b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
500
501 strncpy(b->pins[29].name, "GPIO05", MRAA_PIN_NAME_SIZE);
502 b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
503 b->pins[29].gpio.pinmap = 5;
504 b->pins[29].gpio.mux_total = 0;
505
506 strncpy(b->pins[30].name, "GND", MRAA_PIN_NAME_SIZE);
507 b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
508
509 strncpy(b->pins[31].name, "GPIO06", MRAA_PIN_NAME_SIZE);
510 b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
511 b->pins[31].gpio.pinmap = 6;
512 b->pins[31].gpio.mux_total = 0;
513
514 strncpy(b->pins[32].name, "GPIO12", MRAA_PIN_NAME_SIZE);
515 b->pins[32].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
516 b->pins[32].gpio.pinmap = 12;
517 b->pins[32].gpio.mux_total = 0;
518
519 strncpy(b->pins[33].name, "GPIO13", MRAA_PIN_NAME_SIZE);
520 b->pins[33].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
521 b->pins[33].gpio.pinmap = 13;
522 b->pins[33].gpio.mux_total = 0;
523
524 strncpy(b->pins[34].name, "GND", MRAA_PIN_NAME_SIZE);
525 b->pins[34].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
526
527 strncpy(b->pins[35].name, "GPIO19", MRAA_PIN_NAME_SIZE);
528 b->pins[35].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
529 b->pins[35].gpio.pinmap = 19;
530 b->pins[35].gpio.mux_total = 0;
531
532 strncpy(b->pins[36].name, "GPIO16", MRAA_PIN_NAME_SIZE);
533 b->pins[36].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
534 b->pins[36].gpio.pinmap = 16;
535 b->pins[36].gpio.mux_total = 0;
536
537 strncpy(b->pins[37].name, "GPIO26", MRAA_PIN_NAME_SIZE);
538 b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
539 b->pins[37].gpio.pinmap = 26;
540 b->pins[37].gpio.mux_total = 0;
541
542 strncpy(b->pins[38].name, "GPIO20", MRAA_PIN_NAME_SIZE);
543 b->pins[38].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
544 b->pins[38].gpio.pinmap = 20;
545 b->pins[38].gpio.mux_total = 0;
546
547 strncpy(b->pins[39].name, "GND", MRAA_PIN_NAME_SIZE);
548 b->pins[39].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
549
550 strncpy(b->pins[40].name, "GPIO21", MRAA_PIN_NAME_SIZE);
551 b->pins[40].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
552 b->pins[40].gpio.pinmap = 21;
553 b->pins[40].gpio.mux_total = 0;
554 }
555
556 b->gpio_count = 0;
557 int i;
558 for (i = 0; i < b->phy_pin_count; i++) {
559 if (b->pins[i].capabilites.gpio) {
560 b->gpio_count++;
561 }
562 }
563
564 return b;
565 }
566