Private
Public Access
2
0

i2c: add init(pre-post) hooks

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
Thomas Ingleby
2014-07-14 18:19:07 +01:00
parent 00f188c235
commit 57d58b66ca
3 changed files with 18 additions and 0 deletions

View File

@@ -19,3 +19,6 @@ Any functionality perfomed here is done just before the normal function returns.
* dir (replace-pre-post)
* write (pre-post)
* use-mmaped (replace-pre-post)
### I2C
* init (pre-post) - On RAW

View File

@@ -46,4 +46,7 @@ typedef struct {
mraa_result_t (*gpio_mmaped_write_replace) (mraa_gpio_context dev, int value);
mraa_result_t (*gpio_mmaped_write_pre) (mraa_gpio_context dev, int value);
mraa_result_t (*gpio_mmaped_write_post) (mraa_gpio_context dev, int value);
mraa_result_t (*i2c_init_pre) (unsigned int bus);
mraa_result_t (*i2c_init_post) (mraa_i2c_context dev);
} mraa_adv_func_t;

View File

@@ -50,6 +50,10 @@ mraa_i2c_init(int bus)
mraa_i2c_context
mraa_i2c_init_raw(unsigned int bus)
{
if (advance_func->i2c_init_pre != NULL) {
if (advance_func->i2c_init_pre(bus) != MRAA_SUCCESS)
return NULL;
}
mraa_i2c_context dev = (mraa_i2c_context) malloc(sizeof(struct _i2c));
if (dev == NULL)
return NULL;
@@ -59,6 +63,14 @@ mraa_i2c_init_raw(unsigned int bus)
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
fprintf(stderr, "Failed to open requested i2c port %s\n", filepath);
}
if (advance_func->i2c_init_post != NULL) {
mraa_result_t ret = advance_func->i2c_init_post(dev);
if (ret != MRAA_SUCCESS) {
free(dev);
return NULL;
}
}
return dev;
}