spi: add mraa_spi_init_raw
This lets you access a spidev device directly without any checking in the style of mraa_i2c_init_raw Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -70,6 +70,15 @@ typedef struct _spi* mraa_spi_context;
|
|||||||
*/
|
*/
|
||||||
mraa_spi_context mraa_spi_init(int bus);
|
mraa_spi_context mraa_spi_init(int bus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise SPI_context without any board configuration, selects a bus and a mux.
|
||||||
|
*
|
||||||
|
* @param bus Bus to use as listed by spidev
|
||||||
|
* @param cs Chip select to use as listed in spidev
|
||||||
|
* @return Spi context or NULL
|
||||||
|
*/
|
||||||
|
mraa_spi_context mraa_spi_init_raw(unsigned int bus, unsigned int cs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the SPI device mode. see spidev 0-3.
|
* Set the SPI device mode. see spidev 0-3.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -103,7 +103,22 @@ mraa_spi_init(int bus)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mraa_spi_context dev = mraa_spi_init_raw(plat->spi_bus[bus].bus_id, plat->spi_bus[bus].slave_s);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa_spi_context
|
||||||
|
mraa_spi_init_raw(unsigned int bus, unsigned int cs)
|
||||||
|
{
|
||||||
mraa_spi_context dev = (mraa_spi_context) malloc(sizeof(struct _spi));
|
mraa_spi_context dev = (mraa_spi_context) malloc(sizeof(struct _spi));
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
syslog(LOG_CRIT, "spi: Failed to allocate memory for context");
|
syslog(LOG_CRIT, "spi: Failed to allocate memory for context");
|
||||||
@@ -112,8 +127,7 @@ mraa_spi_init(int bus)
|
|||||||
memset(dev, 0, sizeof(struct _spi));
|
memset(dev, 0, sizeof(struct _spi));
|
||||||
|
|
||||||
char path[MAX_SIZE];
|
char path[MAX_SIZE];
|
||||||
sprintf(path, "/dev/spidev%u.%u",
|
sprintf(path, "/dev/spidev%u.%u", bus, cs);
|
||||||
plat->spi_bus[bus].bus_id, plat->spi_bus[bus].slave_s);
|
|
||||||
|
|
||||||
dev->devfd = open(path, O_RDWR);
|
dev->devfd = open(path, O_RDWR);
|
||||||
if (dev->devfd < 0) {
|
if (dev->devfd < 0) {
|
||||||
@@ -126,14 +140,6 @@ mraa_spi_init(int bus)
|
|||||||
dev->lsb = 0;
|
dev->lsb = 0;
|
||||||
dev->mode = 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;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user