Private
Public Access
2
0

Merge branch 'tingleby-master'

This commit is contained in:
Brendan Le Foll
2014-05-07 14:50:04 +01:00
4 changed files with 117 additions and 7 deletions

View File

@@ -50,7 +50,7 @@ typedef enum {
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_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised
MAA_ERROR_PLATFORM_ALREADY_INITIALISED = 12, /**< Board is already initialised */
MAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} maa_result_t;
@@ -185,6 +185,15 @@ unsigned int maa_check_aio(int pin);
*/
unsigned int maa_check_i2c();
/** Check PWM
*
* Will check input is valid for pwm and will also setup required multiplexers.
* IF the pin also does gpio (strong chance), DO NOTHING, REV D is strange.
* @param pin the pin as read from the board surface.
* @return the pwm pin_info_t of that IO pin
*/
maa_pin_t* maa_check_pwm(int pin);
/** Get the version string of maa autogenerated from git tag
*
* The version returned may not be what is expected however it is a reliable
@@ -193,6 +202,12 @@ unsigned int maa_check_i2c();
*/
const char* maa_get_version();
/** Print a textual representation of the maa_result_t
*
* @param result the result to print,
*/
void maa_result_print(maa_result_t result);
#ifdef __cplusplus
}
#endif

View File

@@ -73,6 +73,12 @@ maa_intel_galileo_rev_d()
b->pins[3].fast_gpio.mux_total = 1;
b->pins[3].fast_gpio.mux[0].pin = 30;
b->pins[3].fast_gpio.mux[0].value = 0;
b->pins[3].pwm.pinmap = 3;
b->pins[3].pwm.parent_id = 0;
b->pins[3].pwm.mux_total = 1;
b->pins[3].pwm.mux[0].pin = 30;
b->pins[3].pwm.mux[0].value = 1;
strncpy(b->pins[4].name, "IO4", 8);
b->pins[4].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,0};

View File

@@ -24,6 +24,7 @@
*/
#include <stddef.h>
#include <stdlib.h>
#include "maa.h"
#include "intel_galileo_rev_d.h"
@@ -98,14 +99,13 @@ maa_check_aio(int aio)
int pin = aio + plat->gpio_count;
if(plat->pins[pin].capabilites.aio != 1)
if (plat->pins[pin].capabilites.aio != 1)
return -1;
if (plat->pins[pin].aio.mux_total > 0)
if (maa_setup_mux_mapped(plat->pins[pin].aio) != MAA_SUCCESS)
return -1;
return plat->pins[pin].aio.pinmap;
}
unsigned int
@@ -132,3 +132,87 @@ maa_check_i2c(int bus_s)
return plat->i2c_bus[bus].bus_id;
}
maa_pin_t*
maa_check_pwm(int pin)
{
if (plat == NULL)
return NULL;
if (plat->pins[pin].capabilites.pwm != 1)
return NULL;
/** quirk in rev d, this messes with pwm on that pin
* if (plat->pins[pin].capabilites.gpio == 1) {
* maa_gpio_context* mux_i;
* mux_i = maa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
* if (mux_i == NULL)
* return NULL;
* if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
* return NULL;
* if (maa_gpio_write(mux_i, 0) != MAA_SUCCESS)
* return NULL;
* if (maa_gpio_close(mux_i) != MAA_SUCCESS)
* return NULL;
* }
*/
if (plat->pins[pin].pwm.mux_total > 0)
if (maa_setup_mux_mapped(plat->pins[pin].pwm) != MAA_SUCCESS)
return NULL;
maa_pin_t *ret;
ret = (maa_pin_t*) malloc(sizeof(maa_pin_t));
ret->pinmap = plat->pins[pin].pwm.pinmap;
ret->parent_id = plat->pins[pin].pwm.parent_id;
return ret;
}
void
maa_result_print(maa_result_t result)
{
switch (result) {
case MAA_SUCCESS: fprintf(stderr, "MAA: SUCCESS\n");
break;
case MAA_ERROR_FEATURE_NOT_IMPLEMENTED:
fprintf(stderr, "MAA: Feature not implemented.\n");
break;
case MAA_ERROR_FEATURE_NOT_SUPPORTED:
fprintf(stderr, "MAA: Feature not supported by Hardware.\n");
break;
case MAA_ERROR_INVALID_VERBOSITY_LEVEL:
fprintf(stderr, "MAA: Invalid verbosity level.\n");
break;
case MAA_ERROR_INVALID_PARAMETER:
fprintf(stderr, "MAA: Invalid parameter.\n");
break;
case MAA_ERROR_INVALID_HANDLE:
fprintf(stderr, "MAA: Invalid Handle.\n");
break;
case MAA_ERROR_NO_RESOURCES:
fprintf(stderr, "MAA: No resources.\n");
break;
case MAA_ERROR_INVALID_RESOURCE:
fprintf(stderr, "MAA: Invalid resource.\n");
break;
case MAA_ERROR_INVALID_QUEUE_TYPE:
fprintf(stderr, "MAA: Invalid Queue Type.\n");
break;
case MAA_ERROR_NO_DATA_AVAILABLE:
fprintf(stderr, "MAA: No Data available.\n");
break;
case MAA_ERROR_INVALID_PLATFORM:
fprintf(stderr, "MAA: Platform not recognised.\n");
break;
case MAA_ERROR_PLATFORM_NOT_INITIALISED:
fprintf(stderr, "MAA: Platform not initialised.\n");
break;
case MAA_ERROR_PLATFORM_ALREADY_INITIALISED:
fprintf(stderr, "MAA: Platform already initialised.\n");
break;
case MAA_ERROR_UNSPECIFIED:
fprintf(stderr, "MAA: Unspecified Error.\n");
break;
default: fprintf(stderr, "MAA: Unrecognised error.\n");
break;
}
}

View File

@@ -101,8 +101,13 @@ maa_pwm_get_duty(maa_pwm_context* dev)
maa_pwm_context*
maa_pwm_init(int pin) {
//TODO
return maa_pwm_init_raw(0, pin);
maa_pin_t* pinm = maa_check_pwm(pin);
if (pinm == NULL)
return NULL;
int chip = pinm->parent_id;
int pinn = pinm->pinmap;
free(pinm);
return maa_pwm_init_raw(chip,pinn);
}
maa_pwm_context*
@@ -121,8 +126,8 @@ maa_pwm_init_raw(int chipin, int pin)
if ((export_f = fopen(buffer, "w")) == NULL) {
fprintf(stderr, "Failed to open export for writing!\n");
free(dev);
return NULL;
free(dev);
return NULL;
} else {
fprintf(export_f, "%d", dev->pin);
fclose(export_f);