Private
Public Access
2
0

Merge branch 'pinmap-i2cspi' of github.com:tingleby/maa into tingleby-pinmap-i2cspi

This commit is contained in:
Brendan Le Foll
2014-05-02 16:43:10 +01:00
7 changed files with 102 additions and 11 deletions

View File

@@ -49,11 +49,22 @@ typedef struct {
int hz; /**< frequency of communication */
int fh; /**< the file handle to the /dev/i2c-* device */
int addr; /**< the address of the i2c slave */
maa_gpio_context gpio;
/*@}*/
} maa_i2c_context;
maa_i2c_context* maa_i2c_init();
/** Initialise i2c context, using board defintions
*
* @param bus i2c bus to use
* @return maa_i2c_context i2c context ready for other calls.
*/
maa_i2c_context* maa_i2c_init(int bus);
/** Initialise i2c context, passing in spi bus to use.
*
* @param bus The i2c bus to use i.e. /dev/i2c-2 would be "2"
* @return maa_i2c_context i2c context ready for other calls.
*/
maa_i2c_context* maa_i2c_init_raw(unsigned int bus);
/** Sets the frequency of the i2c context
*

View File

@@ -107,6 +107,10 @@ typedef struct {
unsigned int gpio_count; /**< GPIO Count */
unsigned int aio_count; /**< Analog In Count */
unsigned int pwm_count; /**< PWM Count */
unsigned int i2c_bus_count; /**< Usable i2c Count */
unsigned int i2c_bus[8]; /**< Array of i2c */
unsigned int spi_bus_count; /**< Usable spi Count */
double spi_bus[8]; /**< Array of spi */
maa_pininfo_t* pins; /**< Pointer to pin array */
/*@}*/
} maa_board_t;
@@ -134,7 +138,11 @@ unsigned int maa_check_gpio(int pin);
*/
unsigned int maa_check_aio(int pin);
//unsigned int maa_check_pwm(int pin);
/** Check i2c interface, sets up multiplexer on device.
*
* @return unsigned int if using /dev/i2c-2 returned would be 2
*/
unsigned int maa_check_i2c();
/** Get the version string of maa autogenerated from git tag
*

View File

@@ -84,7 +84,7 @@ main(int argc, char **argv)
char rx_tx_buf[MAX_BUFFER_LENGTH];
maa_i2c_context *i2c;
i2c = maa_i2c_init();
i2c = maa_i2c_init(0);
maa_i2c_address(i2c, HMC5883L_I2C_ADDR);
rx_tx_buf[0] = HMC5883L_CONF_REG_B;

View File

@@ -26,16 +26,41 @@
#include "smbus.h"
maa_i2c_context*
maa_i2c_init()
maa_i2c_init(int bus)
{
unsigned int checked_pin = maa_check_i2c(bus);
if (checked_pin < 0) {
switch(checked_pin) {
case -1:
fprintf(stderr, "No i2c on board\n");
return NULL;
case -2:
fprintf(stderr, "Failed to set-up i2c multiplexer!\n");
return NULL;
case -3:
fprintf(stderr, "Platform Not Initialised");
return NULL;
default: return NULL;
}
}
return maa_i2c_init_raw(checked_pin);
}
maa_i2c_context*
maa_i2c_init_raw(unsigned int bus)
{
if (bus < 0) {
fprintf(stderr, "Bus -%u- bellow zero\n", bus);
return NULL;
}
maa_i2c_context* dev = (maa_i2c_context*) malloc(sizeof(maa_i2c_context));
if (dev == NULL)
return NULL;
// Galileo only has one I2C master which should be /dev/i2c-0
// reliability is a fickle friend!
if ((dev->fh = open("/dev/i2c-0", O_RDWR)) < 1) {
fprintf(stderr, "Failed to open requested i2c port");
char filepath[32];
snprintf(filepath, 32, "/dev/i2c-%u", bus);
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
fprintf(stderr, "Failed to open requested i2c port %s", filepath);
}
return dev;
}

View File

@@ -37,6 +37,13 @@ maa_intel_galileo_rev_d()
b->gpio_count = 14;
b->aio_count = 6;
b->pwm_count = 5;
b->i2c_bus_count = 1;
b->i2c_bus[0] = 0;
b->spi_bus_count = 1;
b->spi_bus[0] = 1.0;
b->pins = (maa_pininfo_t*) malloc(sizeof(maa_pininfo_t)*25);
//GPIO
@@ -193,5 +200,27 @@ maa_intel_galileo_rev_d()
b->pins[19].mux[1].pin = 20;
b->pins[19].mux[1].value = 0;
strncpy(b->pins[20].name, "I2C", 8);
b->pins[20].pin = 0;
b->pins[20].parent_id = 0;
b->pins[20].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,1,1};
b->pins[20].mux_total = 1;
b->pins[20].mux[0].pin = 29;
b->pins[20].mux[0].value = 0;
strncpy(b->pins[21].name, "SPI-1.0", 8);
b->pins[21].pin = 1;
b->pins[21].parent_id = 0;
b->pins[21].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,1,1};
b->pins[21].mux_total = 4;
b->pins[21].mux[0].pin = 42;
b->pins[21].mux[0].value = 0;
b->pins[21].mux[1].pin = 43;
b->pins[21].mux[1].value = 0;
b->pins[21].mux[2].pin = 54;
b->pins[21].mux[2].value = 0;
b->pins[21].mux[3].pin = 55;
b->pins[21].mux[3].value = 0;
return b;
}

View File

@@ -97,3 +97,22 @@ maa_check_aio(int aio)
return plat->pins[pin].pin;
}
unsigned int
maa_check_i2c(int bus)
{
if (plat == NULL)
return -3;
if (plat->i2c_bus_count >! 0) {
fprintf(stderr, "No i2c buses defined in platform");
return -1;
}
int pin = (plat->gpio_count + plat->aio_count) + bus;
if (plat->pins[pin].mux_total > 0)
if (maa_setup_mux_mapped(plat->pins[pin]) != MAA_SUCCESS)
return -2;
return plat->pins[pin].pin;
}

View File

@@ -106,7 +106,6 @@ typedef struct {
int hz; /**< frequency of communication */
int fh; /**< the file handle to the /dev/i2c-* device */
int addr; /**< the address of the i2c slave */
maa_gpio_context gpio;
/*@}*/
} maa_i2c_context;
@@ -114,7 +113,7 @@ typedef struct {
%extend maa_i2c_context {
maa_i2c_context()
{
return maa_i2c_init();
return maa_i2c_init(0);
}
~maa_i2c_context()
{