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

@@ -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;
}