hook: add spi init hooks
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
dd9129d411
commit
fb1034b2b0
@@ -57,4 +57,7 @@ typedef struct {
|
||||
mraa_result_t (*pwm_init_pre) (int pin);
|
||||
mraa_result_t (*pwm_init_post) (mraa_pwm_context pwm);
|
||||
mraa_result_t (*pwm_period_replace) (mraa_pwm_context dev, int period);
|
||||
|
||||
mraa_result_t (*spi_init_pre) (int bus);
|
||||
mraa_result_t (*spi_init_post) (mraa_spi_context spi);
|
||||
} mraa_adv_func_t;
|
||||
|
||||
@@ -52,6 +52,11 @@ struct _spi {
|
||||
mraa_spi_context
|
||||
mraa_spi_init(int bus)
|
||||
{
|
||||
if (advance_func->spi_init_pre != NULL) {
|
||||
if (advance_func->spi_init_pre(bus) != MRAA_SUCCESS)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mraa_spi_bus_t *spi = mraa_setup_spi(bus);
|
||||
if(bus < 0) {
|
||||
fprintf(stderr, "Failed. SPI platform Error\n");
|
||||
@@ -74,6 +79,14 @@ mraa_spi_init(int bus)
|
||||
dev->lsb = 0;
|
||||
dev->mode = 0;
|
||||
|
||||
if (advance_func->spi_init_post != NULL) {
|
||||
mraa_result_t ret = advance_func->spi_init_post(dev);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
free(dev);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user