cpu/samd21: add helper functions spi_power_on/off
This commit is contained in:
parent
2a4655b6f8
commit
574b565e2a
@ -31,6 +31,16 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#if SPI_0_EN || SPI_1_EN
|
#if SPI_0_EN || SPI_1_EN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Internal helper function to do the actual work for spi_poweroff
|
||||||
|
*/
|
||||||
|
static void _spi_poweroff(SercomSpi* spi_dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Internal helper function to do the actual work for spi_poweron
|
||||||
|
*/
|
||||||
|
static void _spi_poweron(SercomSpi* spi_dev);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Array holding one pre-initialized mutex for each SPI device
|
* @brief Array holding one pre-initialized mutex for each SPI device
|
||||||
*/
|
*/
|
||||||
@ -177,8 +187,10 @@ int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
|
|||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
spi_dev->CTRLA.bit.ENABLE = 0; /* Disable spi to write confs */
|
|
||||||
while (spi_dev->SYNCBUSY.reg) {}
|
/* Disable spi to write confs */
|
||||||
|
_spi_poweroff(spi_dev);
|
||||||
|
|
||||||
spi_dev->CTRLA.reg |= SERCOM_SPI_CTRLA_MODE_SPI_MASTER;
|
spi_dev->CTRLA.reg |= SERCOM_SPI_CTRLA_MODE_SPI_MASTER;
|
||||||
while (spi_dev->SYNCBUSY.reg) {}
|
while (spi_dev->SYNCBUSY.reg) {}
|
||||||
|
|
||||||
@ -193,7 +205,9 @@ int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
|
|||||||
while (spi_dev->SYNCBUSY.reg) {}
|
while (spi_dev->SYNCBUSY.reg) {}
|
||||||
spi_dev->CTRLB.reg = (SERCOM_SPI_CTRLB_CHSIZE(0) | SERCOM_SPI_CTRLB_RXEN);
|
spi_dev->CTRLB.reg = (SERCOM_SPI_CTRLB_CHSIZE(0) | SERCOM_SPI_CTRLB_RXEN);
|
||||||
while(spi_dev->SYNCBUSY.reg) {}
|
while(spi_dev->SYNCBUSY.reg) {}
|
||||||
spi_poweron(dev);
|
|
||||||
|
/* enable */
|
||||||
|
_spi_poweron(spi_dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,37 +272,51 @@ int spi_transfer_byte(spi_t dev, char out, char *in)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _spi_poweron(SercomSpi* spi_dev)
|
||||||
|
{
|
||||||
|
if (spi_dev == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
spi_dev->CTRLA.reg |= SERCOM_SPI_CTRLA_ENABLE;
|
||||||
|
while (spi_dev->SYNCBUSY.bit.ENABLE) {}
|
||||||
|
}
|
||||||
|
|
||||||
void spi_poweron(spi_t dev)
|
void spi_poweron(spi_t dev)
|
||||||
{
|
{
|
||||||
switch(dev) {
|
switch(dev) {
|
||||||
#ifdef SPI_0_EN
|
#if SPI_0_EN
|
||||||
case SPI_0:
|
case SPI_0:
|
||||||
SPI_0_DEV.CTRLA.reg |= SERCOM_SPI_CTRLA_ENABLE;
|
_spi_poweron(&SPI_0_DEV);
|
||||||
while(SPI_0_DEV.SYNCBUSY.bit.ENABLE) {}
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef SPI_1_EN
|
#if SPI_1_EN
|
||||||
case SPI_1:
|
case SPI_1:
|
||||||
SPI_1_DEV.CTRLA.reg |= SERCOM_SPI_CTRLA_ENABLE;
|
_spi_poweron(&SPI_1_DEV);
|
||||||
while(SPI_1_DEV.SYNCBUSY.bit.ENABLE) {}
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _spi_poweroff(SercomSpi* spi_dev)
|
||||||
|
{
|
||||||
|
if (spi_dev == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
spi_dev->CTRLA.bit.ENABLE = 0; /* Disable spi */
|
||||||
|
while (spi_dev->SYNCBUSY.bit.ENABLE) {}
|
||||||
|
}
|
||||||
|
|
||||||
void spi_poweroff(spi_t dev)
|
void spi_poweroff(spi_t dev)
|
||||||
{
|
{
|
||||||
switch(dev) {
|
switch(dev) {
|
||||||
#ifdef SPI_0_EN
|
#if SPI_0_EN
|
||||||
case SPI_0:
|
case SPI_0:
|
||||||
SPI_0_DEV.CTRLA.bit.ENABLE = 0; /* Disable spi */
|
_spi_poweroff(&SPI_0_DEV);
|
||||||
while(SPI_0_DEV.SYNCBUSY.bit.ENABLE) {}
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef SPI_1_EN
|
#if SPI_1_EN
|
||||||
case SPI_1:
|
case SPI_1:
|
||||||
SPI_1_DEV.CTRLA.bit.ENABLE = 0; /* Disable spi */
|
_spi_poweroff(&SPI_1_DEV);
|
||||||
while(SPI_1_DEV.SYNCBUSY.bit.ENABLE) {}
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user