Create platform-independent SPI select and deselect

This commit is contained in:
George Oikonomou 2018-09-26 21:42:06 +01:00
parent a7fbdfa274
commit e71ef49c04
4 changed files with 10 additions and 66 deletions

View File

@ -281,27 +281,6 @@ spi_arch_close_and_unlock(const spi_device_t *dev)
return SPI_DEV_STATUS_OK; return SPI_DEV_STATUS_OK;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
spi_status_t
spi_arch_select(const spi_device_t *dev)
{
if(!spi_arch_has_lock(dev)) {
return SPI_DEV_STATUS_BUS_NOT_OWNED;
}
SPIX_CS_CLR(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs));
return SPI_DEV_STATUS_OK;
}
/*---------------------------------------------------------------------------*/
spi_status_t
spi_arch_deselect(const spi_device_t *dev)
{
SPIX_CS_SET(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs));
return SPI_DEV_STATUS_OK;
}
/*---------------------------------------------------------------------------*/
/* Assumes that checking dev and bus is not NULL before calling this */ /* Assumes that checking dev and bus is not NULL before calling this */
spi_status_t spi_status_t
spi_arch_transfer(const spi_device_t *dev, spi_arch_transfer(const spi_device_t *dev,

View File

@ -230,22 +230,3 @@ spi_arch_transfer(const spi_device_t *dev,
return SPI_DEV_STATUS_OK; return SPI_DEV_STATUS_OK;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
spi_status_t
spi_arch_select(const spi_device_t *dev)
{
if(!spi_arch_has_lock(dev)) {
return SPI_DEV_STATUS_BUS_NOT_OWNED;
}
ti_lib_gpio_clear_dio(dev->pin_spi_cs);
return SPI_DEV_STATUS_OK;
}
spi_status_t
spi_arch_deselect(const spi_device_t *dev)
{
ti_lib_gpio_set_dio(dev->pin_spi_cs);
return SPI_DEV_STATUS_OK;
}

View File

@ -235,30 +235,6 @@ spi_arch_transfer(const spi_device_t *dev,
return SPI_DEV_STATUS_OK; return SPI_DEV_STATUS_OK;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
spi_status_t
spi_arch_select(const spi_device_t *dev)
{
if(!spi_arch_has_lock(dev)) {
return SPI_DEV_STATUS_BUS_NOT_OWNED;
}
PINCC26XX_setOutputValue(dev->pin_spi_cs, 0);
return SPI_DEV_STATUS_OK;
}
/*---------------------------------------------------------------------------*/
spi_status_t
spi_arch_deselect(const spi_device_t *dev)
{
if(!spi_arch_has_lock(dev)) {
return SPI_DEV_STATUS_BUS_NOT_OWNED;
}
PINCC26XX_setOutputValue(dev->pin_spi_cs, 1);
return SPI_DEV_STATUS_OK;
}
/*---------------------------------------------------------------------------*/
/** /**
* @} * @}
* @} * @}

View File

@ -67,13 +67,21 @@ spi_release(const spi_device_t *dev)
spi_status_t spi_status_t
spi_select(const spi_device_t *dev) spi_select(const spi_device_t *dev)
{ {
return spi_arch_select(dev); if(!spi_arch_has_lock(dev)) {
return SPI_DEV_STATUS_BUS_NOT_OWNED;
}
gpio_hal_arch_clear_pin(dev->pin_spi_cs);
return SPI_DEV_STATUS_OK;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
spi_status_t spi_status_t
spi_deselect(const spi_device_t *dev) spi_deselect(const spi_device_t *dev)
{ {
return spi_arch_deselect(dev); gpio_hal_arch_set_pin(dev->pin_spi_cs);
return SPI_DEV_STATUS_OK;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
bool bool