Private
Public Access
2
0

Merge branch 'pinmap'

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>

Conflicts:
	api/maa.h
	src/CMakeLists.txt
This commit is contained in:
Thomas Ingleby
2014-05-01 17:37:56 +01:00
14 changed files with 283 additions and 6 deletions

View File

@@ -48,10 +48,49 @@ typedef enum {
MAA_ERROR_INVALID_RESOURCE = 7, /**< Resource invalid */ MAA_ERROR_INVALID_RESOURCE = 7, /**< Resource invalid */
MAA_ERROR_INVALID_QUEUE_TYPE = 8, /**< Queue type incorrect */ MAA_ERROR_INVALID_QUEUE_TYPE = 8, /**< Queue type incorrect */
MAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */ MAA_ERROR_NO_DATA_AVAILABLE = 9, /**< No data available */
MAA_ERROR_INVALID_PLATFORM = 10, /**< Platform not recognised */
MAA_ERROR_PLATFORM_NOT_INITIALISED = 11, /**< Board information not initialised */
MAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */ MAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} maa_result_t; } maa_result_t;
typedef unsigned int maa_boolean_t;
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;
}
maa_pincapabilities_t;
typedef struct {
unsigned int pin;
unsigned int value;
} maa_mux_t;
typedef struct {
char name[8];// do we need this
unsigned int pin;
int parent_id;
maa_pincapabilities_t capabilites;
maa_mux_t mux[4];
unsigned int mux_total;
} 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);
/** Get the version string of maa autogenerated from git tag /** Get the version string of maa autogenerated from git tag
* *
* The version returned may not be what is expected however it is a reliable * The version returned may not be what is expected however it is a reliable

View File

@@ -29,10 +29,11 @@
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
maa_init();
fprintf(stdout, "MAA Version: %d\nStarting Blinking on IO8\n", fprintf(stdout, "MAA Version: %d\nStarting Blinking on IO8\n",
maa_get_version()); maa_get_version());
maa_gpio_context* gpio; maa_gpio_context* gpio;
gpio = maa_gpio_init(26); gpio = maa_gpio_init(8);
maa_gpio_dir(gpio, MAA_GPIO_OUT); maa_gpio_dir(gpio, MAA_GPIO_OUT);
while (1) { while (1) {

View File

@@ -29,6 +29,7 @@
int int
main () main ()
{ {
maa_init();
maa_pwm_context* pwm; maa_pwm_context* pwm;
pwm = maa_pwm_init(3); pwm = maa_pwm_init(3);
if (pwm == NULL) { if (pwm == NULL) {

View File

@@ -78,6 +78,7 @@
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
maa_init();
float direction = 0; float direction = 0;
int16_t x = 0, y = 0, z = 0; int16_t x = 0, y = 0, z = 0;
char rx_tx_buf[MAX_BUFFER_LENGTH]; char rx_tx_buf[MAX_BUFFER_LENGTH];

View File

@@ -23,7 +23,7 @@
*/ */
var m = require("maajs") var m = require("maajs")
m.init();
console.log("maa version: " + m.get_version()); console.log("maa version: " + m.get_version());
var r = new m.I2C(20, 21); var r = new m.I2C(20, 21);

View File

@@ -25,8 +25,9 @@
import pymaa as maa import pymaa as maa
import time import time
maa.maa_init()
x = maa.gpio_t() x = maa.gpio_t()
maa.gpio_init(x, 26) maa.gpio_init(x, 8)
maa.gpio_dir(x, "out") maa.gpio_dir(x, "out")
while True: while True:

View File

@@ -25,6 +25,7 @@
import pymaa as maa import pymaa as maa
import time import time
maa.maa_init()
x = maa.PWM(0,3) x = maa.PWM(0,3)
x.enable(1); x.enable(1);
x.period_us(20) x.period_us(20)

View File

@@ -24,7 +24,8 @@
import pymaa import pymaa
pumaa.maa_init()
x = pymaa.gpio_t() x = pymaa.gpio_t()
print(x.pin) print(x.pin)
pymaa.gpio_init(x, 20) pymaa.gpio_init(x, 8)
print(x.pin) print(x.pin)

View File

@@ -24,6 +24,7 @@
import pymaa import pymaa
pumaa.maa_init()
x = pymaa.I2CSlave(27,28) x = pymaa.I2CSlave(27,28)
x.address(0x62) x.address(0x62)
y= " " y= " "

View 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();

View File

@@ -12,6 +12,7 @@ set (maa_LIB_HEADERS
${PROJECT_SOURCE_DIR}/api/aio.h ${PROJECT_SOURCE_DIR}/api/aio.h
${PROJECT_SOURCE_DIR}/include/smbus.h ${PROJECT_SOURCE_DIR}/include/smbus.h
${PROJECT_SOURCE_DIR}/include/version.h ${PROJECT_SOURCE_DIR}/include/version.h
${PROJECT_SOURCE_DIR}/include/intel_galileo_rev_d.h
) )
set (maa_LIB_KERNEL set (maa_LIB_KERNEL
@@ -29,6 +30,7 @@ set (maa_LIB_SRCS
${PROJECT_SOURCE_DIR}/src/pwm/pwm.c ${PROJECT_SOURCE_DIR}/src/pwm/pwm.c
${PROJECT_SOURCE_DIR}/src/spi/spi.c ${PROJECT_SOURCE_DIR}/src/spi/spi.c
${PROJECT_SOURCE_DIR}/src/aio/aio.c ${PROJECT_SOURCE_DIR}/src/aio/aio.c
${PROJECT_SOURCE_DIR}/src/intel_galileo_rev_d.c
# autogenerated version file # autogenerated version file
${CMAKE_CURRENT_BINARY_DIR}/version.c ${CMAKE_CURRENT_BINARY_DIR}/version.c
) )

View File

@@ -44,13 +44,17 @@ maa_gpio_get_valfp(maa_gpio_context *dev)
maa_gpio_context* maa_gpio_context*
maa_gpio_init(int pin) maa_gpio_init(int pin)
{ {
//TODO int pinm = maa_check_gpio(pin);
return maa_gpio_init_raw(pin); if (pinm < 0)
return NULL;
return maa_gpio_init_raw(pinm);
} }
maa_gpio_context* maa_gpio_context*
maa_gpio_init_raw(int pin) maa_gpio_init_raw(int pin)
{ {
if(pin < 0)
return NULL;
FILE *export_f; FILE *export_f;
maa_gpio_context* dev = (maa_gpio_context*) malloc(sizeof(maa_gpio_context)); 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_result_t
maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir) maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir)
{ {
if (dev == NULL)
return MAA_ERROR_INVALID_HANDLE;
if (dev->value_fp != NULL) { if (dev->value_fp != NULL) {
dev->value_fp = NULL; dev->value_fp = NULL;
} }

144
src/intel_galileo_rev_d.c Normal file
View 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;
}

View File

@@ -1,5 +1,6 @@
/* /*
* Author: Brendan Le Foll <brendan.le.foll@intel.com> * Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Copyright (c) 2014 Intel Corporation. * Copyright (c) 2014 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
@@ -22,11 +23,57 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <stddef.h>
#include "maa.h" #include "maa.h"
#include "intel_galileo_rev_d.h"
#include "gpio.h"
#include "version.h" #include "version.h"
static maa_pininfo_t* pindata;
static maa_board_t* plat;
const char * const char *
maa_get_version() maa_get_version()
{ {
return gVERSION; return gVERSION;
} }
maa_result_t
maa_init()
{
plat = maa_intel_galileo_rev_d();
return MAA_SUCCESS;
}
static maa_result_t
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);
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(plat == NULL)
return -1;
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;
}