#include "types.h"
typedef struct {
- mraa_boolean_t gpio_init_pre:1;
- mraa_boolean_t gpio_init_post:1;
- mraa_boolean_t gpio_mode_replace:1;
- mraa_boolean_t gpio_mode_pre:1;
- mraa_boolean_t gpio_mode_post:1;
- mraa_boolean_t gpio_dir_replace:1;
- mraa_boolean_t gpio_dir_pre:1;
- mraa_boolean_t gpio_dir_post:1;
- mraa_boolean_t gpio_write_pre:1;
- mraa_boolean_t gpio_write_post:1;
- mraa_boolean_t gpio_mmaped_write_replace:1;
- mraa_boolean_t gpio_mmaped_write_pre:1;
- mraa_boolean_t gpio_mmaped_write_post:1;
-} mraa_adv_def_t;
-
-typedef struct {
- mraa_adv_def_t defined;
- int (*gpio_init_pre) (int pin);
- void (*gpio_init_post) (mraa_gpio_context dev);
+ mraa_result_t (*gpio_init_pre) (int pin);
+ mraa_result_t (*gpio_init_post) (mraa_gpio_context dev);
mraa_result_t (*gpio_mode_replace) (mraa_gpio_context dev, gpio_mode_t mode);
mraa_result_t (*gpio_mode_pre) (mraa_gpio_context dev, gpio_mode_t mode);
#define MAX_SIZE 64
#define POLL_TIMEOUT
-static mraa_adv_func* advance;
-
static mraa_result_t
mraa_gpio_get_valfp(mraa_gpio_context dev)
{
mraa_gpio_context
mraa_gpio_init_raw(int pin)
{
- advance = mraa_get_advance();
- if (advance->defined.gpio_init_pre) {
- if((advance->gpio_init_pre(pin)) != 0) {
- printf("MRAA: Error in pre hook\n");
+ if (advance_func.gpio_init_pre != NULL) {
+ printf("Actually entering\n");
+ if (advance_func.gpio_init_pre(pin) != MRAA_SUCCESS)
return NULL;
- }
}
if (pin < 0)
return NULL;
close(export);
}
- if (advance->defined.gpio_init_post)
- advance->gpio_init_post(dev);
+ if (advance_func.gpio_init_post != NULL) {
+ free(dev);
+ return NULL;
+ }
return dev;
}
static mraa_result_t
mraa_gpio_write_register(mraa_gpio_context dev,int value)
{
- if (advance->defined.gpio_mmaped_write_replace)
- return advance->gpio_mmaped_write_replace(dev,value);
- if (advance->defined.gpio_mmaped_write_pre) {
- mraa_result_t pre_ret = (advance->gpio_mmaped_write_pre(dev,value));
+ if (advance_func.gpio_mmaped_write_replace != NULL)
+ return advance_func.gpio_mmaped_write_replace(dev,value);
+ if (advance_func.gpio_mmaped_write_pre != NULL) {
+ mraa_result_t pre_ret = (advance_func.gpio_mmaped_write_pre(dev,value));
if(pre_ret != MRAA_SUCCESS)
return pre_ret;
}
}
*((unsigned *)dev->reg) &= ~(1<<dev->reg_bit_pos);
- if (advance->defined.gpio_mmaped_write_post)
- return advance->gpio_mmaped_write_post(dev,value);
+ if (advance_func.gpio_mmaped_write_post != NULL)
+ return advance_func.gpio_mmaped_write_post(dev,value);
return MRAA_SUCCESS;
}
// assume our thread will exit either way we just lost it's handle
dev->thread_id = 0;
dev->isr_value_fp = -1;
-
return ret;
}
mraa_result_t
mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
{
- if (advance->defined.gpio_mode_replace)
- return advance->gpio_mode_replace(dev,mode);
+ if (advance_func.gpio_mode_replace != NULL)
+ return advance_func.gpio_mode_replace(dev,mode);
- if (advance->defined.gpio_mode_pre) {
- mraa_result_t pre_ret = (advance->gpio_mode_pre(dev,mode));
+ if (advance_func.gpio_mode_pre != NULL) {
+ mraa_result_t pre_ret = (advance_func.gpio_mode_pre(dev,mode));
if(pre_ret != MRAA_SUCCESS)
return pre_ret;
}
}
close(drive);
- if (advance->defined.gpio_mode_post)
- return advance->gpio_mode_post(dev,mode);
+ if (advance_func.gpio_mode_post != NULL)
+ return advance_func.gpio_mode_post(dev,mode);
return MRAA_SUCCESS;
}
mraa_result_t
mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir)
{
- if (advance->defined.gpio_dir_replace)
- return advance->gpio_dir_replace(dev,dir);
- if (advance->defined.gpio_dir_pre) {
- mraa_result_t pre_ret = (advance->gpio_dir_pre(dev,dir));
+ if (advance_func.gpio_dir_replace != NULL)
+ return advance_func.gpio_dir_replace(dev,dir);
+ if (advance_func.gpio_dir_pre != NULL) {
+ mraa_result_t pre_ret = (advance_func.gpio_dir_pre(dev,dir));
if(pre_ret != MRAA_SUCCESS)
return pre_ret;
}
}
close(direction);
- if (advance->defined.gpio_dir_post)
- return advance->gpio_dir_post(dev,dir);
+ if (advance_func.gpio_dir_post != NULL)
+ return advance_func.gpio_dir_post(dev,dir);
return MRAA_SUCCESS;
}
int ret = strtol(bu, NULL, 10);
return ret;
+ return 0;
}
mraa_result_t
if (dev->mmap == 1)
return mraa_gpio_write_register(dev,value);
- if (advance->defined.gpio_write_pre) {
- mraa_result_t pre_ret = (advance->gpio_write_pre(dev,value));
+ if (advance_func.gpio_write_pre != NULL) {
+ mraa_result_t pre_ret = (advance_func.gpio_write_pre(dev,value));
if(pre_ret != MRAA_SUCCESS)
return pre_ret;
}
return MRAA_ERROR_INVALID_HANDLE;
}
- if (advance->defined.gpio_write_post)
- return advance->gpio_write_post(dev,value);
+ if (advance_func.gpio_write_post != NULL)
+ return advance_func.gpio_write_post(dev,value);
return MRAA_SUCCESS;
}
//static mraa_pininfo_t* pindata;
static mraa_board_t* plat = NULL;
static mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
-static mraa_adv_func* advance = NULL;
+mraa_adv_func advance_func;
const char *
mraa_get_version()
return gVERSION;
}
-#ifdef SWIG
-mraa_result_t
-mraa_init()
-#else
mraa_result_t __attribute__((constructor))
mraa_init()
-#endif
{
/** Once more board definitions have been added,
* A method for detecting them will need to be devised.
free(line);
fclose(fh);
- advance = (mraa_adv_func*) malloc(sizeof(mraa_adv_func));
+ memset(&advance_func, 0, sizeof(mraa_adv_func));
switch(platform_type) {
case MRAA_INTEL_GALILEO_GEN2:
- plat = mraa_intel_galileo_gen2(advance);
+ plat = mraa_intel_galileo_gen2(&advance_func);
break;
case MRAA_INTEL_GALILEO_GEN1:
- plat = mraa_intel_galileo_rev_d(advance);
+ plat = mraa_intel_galileo_rev_d(&advance_func);
break;
default:
- plat = mraa_intel_galileo_rev_d(advance);
+ plat = mraa_intel_galileo_rev_d(&advance_func);
fprintf(stderr, "Platform not found, initialising MRAA_INTEL_GALILEO_GEN1\n");
}
return plat->adc_supported;
}
-
-mraa_adv_func*
-mraa_get_advance() {
- return advance;
-}