pinmap: GPIO pin map added.
* maa_gpio_init can take the IO number read physically off the board. * maa_check_gpio will also set up mutiplexers if needed * Intel Galileo Rev D board data added Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
23
api/maa.h
23
api/maa.h
@@ -45,23 +45,23 @@ typedef enum {
|
||||
MAA_ERROR_INVALID_RESOURCE = 7,
|
||||
MAA_ERROR_INVALID_QUEUE_TYPE = 8,
|
||||
MAA_ERROR_NO_DATA_AVAILABLE = 9,
|
||||
MAA_ERROR_INVALID_PLATFORM = 10,
|
||||
MAA_ERROR_PLATFORM_NOT_INITIALISED = 11,
|
||||
|
||||
MAA_ERROR_UNSPECIFIED = 99
|
||||
} maa_result_t;
|
||||
|
||||
typedef unsigned int maa_boolean_t;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
typedef struct {
|
||||
maa_boolean_t valid:1;
|
||||
maa_boolean_t gpio:1;
|
||||
maa_boolean_t pwm:1;
|
||||
maa_boolean_t fast_gpio:1;
|
||||
maa_boolean_t spi:1;
|
||||
maa_boolean_t i2c:1;
|
||||
};
|
||||
int raw;
|
||||
} maa_pincapabilities_t;
|
||||
}
|
||||
maa_pincapabilities_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int pin;
|
||||
@@ -75,11 +75,18 @@ typedef struct {
|
||||
maa_pincapabilities_t capabilites;
|
||||
maa_mux_t mux[4];
|
||||
unsigned int mux_total;
|
||||
} maa_pininfo;
|
||||
} maa_pininfo_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int gpio_count;
|
||||
unsigned int aio_count;
|
||||
unsigned int pwm_count;
|
||||
maa_pininfo_t* pins;
|
||||
} maa_board_t;
|
||||
|
||||
unsigned int maa_check_gpio(int pin);
|
||||
unsigned int maa_check_aio(int pin);
|
||||
unsigned int maa_check_pwm(int pin);
|
||||
//unsigned int maa_check_aio(int pin);
|
||||
//unsigned int maa_check_pwm(int pin);
|
||||
|
||||
/** Get the version string of maa autogenerated from git tag
|
||||
*
|
||||
|
||||
32
include/intel_galileo_rev_d.h
Normal file
32
include/intel_galileo_rev_d.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* 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
|
||||
|
||||
#include "maa.h"
|
||||
|
||||
#define MAA_INTEL_GALILEO_REV_D_PINCOUNT 25
|
||||
|
||||
maa_board_t*
|
||||
maa_intel_galileo_rev_d();
|
||||
@@ -10,6 +10,7 @@ set (maa_LIB_HEADERS
|
||||
${PROJECT_SOURCE_DIR}/api/pwm.h
|
||||
${PROJECT_SOURCE_DIR}/include/smbus.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/smbus.h
|
||||
${PROJECT_SOURCE_DIR}/include/intel_galileo_rev_d.h
|
||||
)
|
||||
|
||||
set (maa_LIB_KERNEL
|
||||
@@ -25,6 +26,7 @@ set (maa_LIB_SRCS
|
||||
${PROJECT_SOURCE_DIR}/src/i2c/i2c.c
|
||||
${PROJECT_SOURCE_DIR}/src/i2c/smbus.c
|
||||
${PROJECT_SOURCE_DIR}/src/pwm/pwm.c
|
||||
${PROJECT_SOURCE_DIR}/src/intel_galileo_rev_d.c
|
||||
# autogenerated version file
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.c
|
||||
)
|
||||
|
||||
@@ -44,13 +44,17 @@ maa_gpio_get_valfp(maa_gpio_context *dev)
|
||||
maa_gpio_context*
|
||||
maa_gpio_init(int pin)
|
||||
{
|
||||
//TODO
|
||||
return maa_gpio_init_raw(pin);
|
||||
int pinm = maa_check_gpio(pin);
|
||||
if (pinm < 0)
|
||||
return NULL;
|
||||
return maa_gpio_init_raw(pinm);
|
||||
}
|
||||
|
||||
maa_gpio_context*
|
||||
maa_gpio_init_raw(int pin)
|
||||
{
|
||||
if(pin < 0)
|
||||
return NULL;
|
||||
FILE *export_f;
|
||||
maa_gpio_context* dev = (maa_gpio_context*) malloc(sizeof(maa_gpio_context));
|
||||
|
||||
@@ -105,6 +109,8 @@ maa_gpio_mode(maa_gpio_context *dev, gpio_mode_t mode)
|
||||
maa_result_t
|
||||
maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir)
|
||||
{
|
||||
if (dev == NULL)
|
||||
return MAA_ERROR_INVALID_HANDLE;
|
||||
if (dev->value_fp != NULL) {
|
||||
dev->value_fp = NULL;
|
||||
}
|
||||
|
||||
144
src/intel_galileo_rev_d.c
Normal file
144
src/intel_galileo_rev_d.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "maa.h"
|
||||
|
||||
maa_board_t*
|
||||
maa_intel_galileo_rev_d()
|
||||
{
|
||||
maa_board_t* b = (maa_board_t*) malloc(sizeof(maa_board_t));
|
||||
if(b == NULL)
|
||||
return NULL;
|
||||
|
||||
b->gpio_count = 14;
|
||||
b->aio_count = 6;
|
||||
b->pwm_count = 5;
|
||||
b->pins = (maa_pininfo_t*) malloc(sizeof(maa_pininfo_t)*25);
|
||||
|
||||
//GPIO
|
||||
strncpy(b->pins[0].name, "IO0", 8);
|
||||
b->pins[0].pin = 50;
|
||||
b->pins[0].parent_id = 0;
|
||||
b->pins[0].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[0].mux_total = 1;
|
||||
b->pins[0].mux[0].pin = 40;
|
||||
b->pins[0].mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[1].name, "IO1", 8);
|
||||
b->pins[1].pin = 51;
|
||||
b->pins[1].parent_id = 0;
|
||||
b->pins[1].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[1].mux_total = 1;
|
||||
b->pins[1].mux[0].pin = 41;
|
||||
b->pins[1].mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[2].name, "IO2", 8);
|
||||
b->pins[2].pin = 32;
|
||||
b->pins[2].parent_id = 0;
|
||||
b->pins[2].capabilites = (maa_pincapabilities_t) {1,1,0,1,0,0};
|
||||
b->pins[2].mux_total = 1;
|
||||
b->pins[2].mux[0].pin = 31;
|
||||
b->pins[2].mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[3].name, "IO3", 8);
|
||||
b->pins[3].pin = 18;
|
||||
b->pins[3].parent_id = 0;
|
||||
b->pins[3].capabilites = (maa_pincapabilities_t) {1,1,1,1,0,0};
|
||||
b->pins[3].mux_total = 1;
|
||||
b->pins[3].mux[0].pin = 30;
|
||||
b->pins[3].mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[4].name, "IO4", 8);
|
||||
b->pins[4].pin = 28;
|
||||
b->pins[4].parent_id = 0;
|
||||
b->pins[4].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[4].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[5].name, "IO5", 8);
|
||||
b->pins[5].pin = 17;
|
||||
b->pins[5].parent_id = 0;
|
||||
b->pins[5].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0};
|
||||
b->pins[5].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[6].name, "IO6", 8);
|
||||
b->pins[6].pin = 24;
|
||||
b->pins[6].parent_id = 0;
|
||||
b->pins[6].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0};
|
||||
b->pins[6].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[7].name, "IO7", 8);
|
||||
b->pins[7].pin = 27;
|
||||
b->pins[7].parent_id = 0;
|
||||
b->pins[7].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[7].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[8].name, "IO8", 8);
|
||||
b->pins[8].pin = 26;
|
||||
b->pins[8].parent_id = 0;
|
||||
b->pins[8].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[8].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[9].name, "IO9", 8);
|
||||
b->pins[9].pin = 19;
|
||||
b->pins[9].parent_id = 0;
|
||||
b->pins[9].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0};
|
||||
b->pins[9].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[10].name, "IO10", 8);
|
||||
b->pins[10].pin = 16;
|
||||
b->pins[10].parent_id = 0;
|
||||
b->pins[10].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[10].mux_total = 1;
|
||||
b->pins[10].mux[0].pin = 42;
|
||||
b->pins[10].mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[11].name, "IO11", 8);
|
||||
b->pins[11].pin = 25;
|
||||
b->pins[11].parent_id = 0;
|
||||
b->pins[11].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[11].mux_total = 1;
|
||||
b->pins[11].mux[0].pin = 43;
|
||||
b->pins[11].mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[12].name, "IO12", 8);
|
||||
b->pins[12].pin = 38;
|
||||
b->pins[12].parent_id = 0;
|
||||
b->pins[12].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[12].mux_total = 1;
|
||||
b->pins[12].mux[0].pin = 54;
|
||||
b->pins[12].mux[0].value = 1;
|
||||
|
||||
strncpy(b->pins[13].name, "IO13", 8);
|
||||
b->pins[13].pin = 39;
|
||||
b->pins[13].parent_id = 0;
|
||||
b->pins[13].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[13].mux_total = 1;
|
||||
b->pins[13].mux[0].pin = 55;
|
||||
b->pins[13].mux[0].value = 1;
|
||||
|
||||
return b;
|
||||
}
|
||||
37
src/maa.c
37
src/maa.c
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@@ -25,10 +26,12 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "maa.h"
|
||||
#include "intel_galileo_rev_d.h"
|
||||
#include "gpio.h"
|
||||
#include "version.h"
|
||||
|
||||
static maa_pininfo* pindata;
|
||||
static maa_pininfo_t* pindata;
|
||||
static maa_board_t* plat;
|
||||
|
||||
const char *
|
||||
maa_get_version()
|
||||
@@ -39,32 +42,38 @@ maa_get_version()
|
||||
maa_result_t
|
||||
maa_init()
|
||||
{
|
||||
return MAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
plat = maa_intel_galileo_rev_d();
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
static maa_result_t
|
||||
maa_setup_mux_mapped(maa_pininfo meta)
|
||||
maa_setup_mux_mapped(maa_pininfo_t meta)
|
||||
{
|
||||
int mi;
|
||||
for(mi = 0; mi < meta.mux_total; mi++) {
|
||||
maa_gpio_context* mux_i;
|
||||
mux_i = maa_gpio_init_raw(meta.mux[mi].pin);
|
||||
maa_gpio_dir(mux_i, MAA_GPIO_OUT);
|
||||
maa_gpio_write(mux_i, meta.mux[mi].value);
|
||||
if(mux_i == NULL)
|
||||
return MAA_ERROR_INVALID_HANDLE;
|
||||
if(maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
if(maa_gpio_write(mux_i, meta.mux[mi].value) != MAA_SUCCESS)
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
maa_check_gpio(int pin){
|
||||
|
||||
if(pindata == NULL) {
|
||||
maa_check_gpio(int pin)
|
||||
{
|
||||
if(plat == NULL)
|
||||
return -1;
|
||||
}
|
||||
//Check in gpio bounds?
|
||||
if(pindata[pin].mux_total > 0)
|
||||
if(maa_setup_mux_mapped(pindata[pin]) != MAA_SUCCESS)
|
||||
return -1;
|
||||
|
||||
return pindata[pin].pin;
|
||||
if(pin < 0 || pin > plat->gpio_count)
|
||||
return -1;
|
||||
if(plat->pins[pin].mux_total > 0)
|
||||
if(maa_setup_mux_mapped(plat->pins[pin]) != MAA_SUCCESS)
|
||||
return -1;
|
||||
return plat->pins[pin].pin;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user