i2c: add init(pre-post) hooks
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user