From ea38d8c3973abb777622381c9ade5df902b599b4 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Fri, 21 Nov 2014 01:47:16 +0000 Subject: [PATCH] raspberry pi: add model b definition Signed-off-by: Thomas Ingleby --- api/mraa/types.h | 1 + include/arm/raspberry_pi_b.h | 40 ++++++++++ src/arm/CMakeLists.txt | 1 + src/arm/raspberry_pi_b.c | 183 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 225 insertions(+) create mode 100644 include/arm/raspberry_pi_b.h create mode 100644 src/arm/raspberry_pi_b.c diff --git a/api/mraa/types.h b/api/mraa/types.h index ec4b05b..54cdc20 100644 --- a/api/mraa/types.h +++ b/api/mraa/types.h @@ -42,6 +42,7 @@ typedef enum { MRAA_INTEL_EDISON_FAB_C = 2, /**< The Intel Edison (FAB C) */ MRAA_INTEL_DE3815 = 3, /**< The Intel DE3815 Baytrail NUC */ MRAA_INTEL_MINNOWBOARD_MAX = 4, /**< The Intel Minnow Board Max */ + MRAA_RASPBERRY_PI_B = 5, /**< The Raspberry PI Model B */ MRAA_UNKNOWN_PLATFORM = 99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */ } mraa_platform_t; diff --git a/include/arm/raspberry_pi_b.h b/include/arm/raspberry_pi_b.h new file mode 100644 index 0000000..e82b365 --- /dev/null +++ b/include/arm/raspberry_pi_b.h @@ -0,0 +1,40 @@ +/* + * Author: Thomas Ingleby + * Copyright (c) 2014 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mraa_internal.h" + +#define MRAA_RASPBERRY_PI_B 27 + +mraa_board_t* +mraa_raspberry_pi_b(); + +#ifdef __cplusplus +} +#endif diff --git a/src/arm/CMakeLists.txt b/src/arm/CMakeLists.txt index 7f06106..7032943 100644 --- a/src/arm/CMakeLists.txt +++ b/src/arm/CMakeLists.txt @@ -1,5 +1,6 @@ message (INFO " - Adding ARM platforms") set (mraa_LIB_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO} ${PROJECT_SOURCE_DIR}/src/arm/arm.c + ${PROJECT_SOURCE_DIR}/src/arm/raspberry_pi_b.c PARENT_SCOPE ) diff --git a/src/arm/raspberry_pi_b.c b/src/arm/raspberry_pi_b.c new file mode 100644 index 0000000..ddb126d --- /dev/null +++ b/src/arm/raspberry_pi_b.c @@ -0,0 +1,183 @@ +/* + * Author: Thomas Ingleby + * Copyright (c) 2014 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#include "common.h" +#include "arm/raspberry_pi_b.h" + +mraa_board_t* +mraa_raspberry_pi_b() +{ + mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t)); + if (b == NULL) + return NULL; + + b->phy_pin_count = MRAA_RASPBERRY_PI_B; + b->aio_count = 0; + b->adc_raw = 0; + b->adc_supported = 0; + b->pwm_default_period = 500; + b->pwm_max_period = 2147483; + b->pwm_min_period = 1; + + b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_RASPBERRY_PI_B); + + strncpy(b->pins[0].name, "void", 8); + b->pins[0].capabilites = (mraa_pincapabilities_t) {0,0,0,0,0,0,0,0}; + strncpy(b->pins[1].name, "3V3", 8); + b->pins[1].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + strncpy(b->pins[2].name, "5V", 8); + b->pins[2].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + strncpy(b->pins[3].name, "I2C-SDA", 8); + b->pins[3].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0}; + b->pins[3].i2c.pinmap = 0; + b->pins[3].i2c.mux_total = 0; + strncpy(b->pins[4].name, "5V", 8); + b->pins[4].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + strncpy(b->pins[5].name, "I2C-SCL", 8); + b->pins[5].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0}; + b->pins[5].i2c.pinmap = 0; + b->pins[5].i2c.mux_total = 0; + strncpy(b->pins[6].name, "GND", 8); + b->pins[6].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + + strncpy(b->pins[7].name, "GPIO4", 8); + b->pins[7].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; + b->pins[7].gpio.pinmap = 4; + b->pins[7].gpio.mux_total = 0; + + strncpy(b->pins[8].name, "UARTtx", 8); + b->pins[8].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,1}; + b->pins[8].uart.parent_id = 0; + b->pins[8].uart.mux_total = 0; + strncpy(b->pins[9].name, "GND", 8); + b->pins[9].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + strncpy(b->pins[10].name, "UARTrx", 8); + b->pins[10].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,1}; + b->pins[10].uart.parent_id = 0; + b->pins[10].uart.mux_total = 0; + + strncpy(b->pins[11].name, "GPIO17", 8); + b->pins[11].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; + b->pins[11].gpio.pinmap = 17; + b->pins[11].gpio.mux_total = 0; + + strncpy(b->pins[12].name, "GPIO18", 8); + b->pins[12].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; + b->pins[12].gpio.pinmap = 18; + b->pins[12].gpio.mux_total = 0; + + strncpy(b->pins[13].name, "GPIO21", 8); + b->pins[13].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; + b->pins[13].gpio.pinmap = 21; + b->pins[13].gpio.mux_total = 0; + + strncpy(b->pins[14].name, "GND", 8); + b->pins[14].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + + strncpy(b->pins[15].name, "GPIO22", 8); + b->pins[15].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; + b->pins[15].gpio.pinmap = 22; + b->pins[15].gpio.mux_total = 0; + + strncpy(b->pins[16].name, "GPIO23", 8); + b->pins[16].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + b->pins[16].gpio.pinmap = 23; + b->pins[16].gpio.mux_total = 0; + + strncpy(b->pins[17].name, "3V3", 8); + b->pins[17].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + + strncpy(b->pins[18].name, "GPIO24", 8); + b->pins[18].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; + b->pins[18].gpio.pinmap = 24; + b->pins[18].gpio.mux_total = 0; + + strncpy(b->pins[19].name, "SPI-MOSI", 8); + b->pins[19].capabilites = (mraa_pincapabilities_t) {1,0,0,0,1,0,0,0}; + b->pins[19].spi.pinmap = 0; + b->pins[19].spi.mux_total = 0; + + strncpy(b->pins[20].name, "GND", 8); + b->pins[20].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + + strncpy(b->pins[21].name, "SPI-MISO", 8); + b->pins[21].capabilites = (mraa_pincapabilities_t) {1,0,0,0,1,0,0,0}; + b->pins[21].spi.pinmap = 0; + b->pins[21].spi.mux_total = 0; + + strncpy(b->pins[22].name, "GPIO25", 8); + b->pins[22].capabilites = (mraa_pincapabilities_t) {1,1,0,0,0,0,0,0}; + b->pins[22].gpio.pinmap = 25; + b->pins[22].gpio.mux_total = 0; + + strncpy(b->pins[23].name, "SPI-CLK", 8); + b->pins[23].capabilites = (mraa_pincapabilities_t) {1,0,0,0,1,0,0,0}; + b->pins[23].spi.pinmap = 0; + b->pins[23].spi.mux_total = 0; + + strncpy(b->pins[24].name, "SPI-CS0", 8); + b->pins[24].capabilites = (mraa_pincapabilities_t) {1,0,0,0,1,0,0,0}; + b->pins[24].spi.pinmap = 0; + b->pins[24].spi.mux_total = 0; + + strncpy(b->pins[25].name, "GND", 8); + b->pins[25].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0}; + strncpy(b->pins[26].name, "SPI-CS1", 8); + b->pins[26].capabilites = (mraa_pincapabilities_t) {1,0,0,0,1,0,0,0}; + b->pins[26].spi.pinmap = 0; + b->pins[26].spi.mux_total = 0; + + //BUS DEFINITIONS + b->i2c_bus_count = 1; + b->def_i2c_bus = 0; + b->i2c_bus[0].bus_id = 0; + b->i2c_bus[0].sda = 2; + b->i2c_bus[0].scl = 4; + + b->spi_bus_count = 2; + b->def_spi_bus = 0; + b->spi_bus[0].bus_id = 0; + b->spi_bus[0].slave_s = 0; + b->spi_bus[0].cs = 23; + b->spi_bus[0].mosi = 18; + b->spi_bus[0].miso = 20; + b->spi_bus[0].sclk = 22; + + b->spi_bus[1].bus_id = 0; + b->spi_bus[1].slave_s = 1; + b->spi_bus[1].cs = 25; + b->spi_bus[1].mosi = 18; + b->spi_bus[1].miso = 20; + b->spi_bus[1].sclk = 22; + + b->uart_dev_count = 1; + b->def_uart_dev = 0; + b->uart_dev[0].rx = 9; + b->uart_dev[0].tx = 7; + + return b; +} -- 2.7.4