|
|
|
@ -15,6 +15,7 @@
|
|
|
|
|
*
|
|
|
|
|
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
|
|
|
|
|
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
|
*
|
|
|
|
|
* @}
|
|
|
|
|
*/
|
|
|
|
@ -22,6 +23,7 @@
|
|
|
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
|
#include "cpu.h"
|
|
|
|
|
#include "mutex.h"
|
|
|
|
|
#include "periph/spi.h"
|
|
|
|
|
#include "periph_conf.h"
|
|
|
|
|
#include "thread.h"
|
|
|
|
@ -34,12 +36,18 @@
|
|
|
|
|
/* guard this file in case no SPI device is defined */
|
|
|
|
|
#if SPI_NUMOF
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Data-structure holding the state for a SPI device
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
char(*cb)(char data);
|
|
|
|
|
} spi_state_t;
|
|
|
|
|
|
|
|
|
|
static inline void irq_handler_transfer(SPI_TypeDef *spi, spi_t dev);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Reserve memory for saving the SPI device's state
|
|
|
|
|
*/
|
|
|
|
|
static spi_state_t spi_config[SPI_NUMOF];
|
|
|
|
|
|
|
|
|
|
/* static bus div mapping */
|
|
|
|
@ -55,6 +63,21 @@ static const uint8_t spi_bus_div_map[SPI_NUMOF] = {
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Array holding one pre-initialized mutex for each SPI device
|
|
|
|
|
*/
|
|
|
|
|
static mutex_t locks[] = {
|
|
|
|
|
#if SPI_0_EN
|
|
|
|
|
[SPI_0] = MUTEX_INIT,
|
|
|
|
|
#endif
|
|
|
|
|
#if SPI_1_EN
|
|
|
|
|
[SPI_1] = MUTEX_INIT,
|
|
|
|
|
#endif
|
|
|
|
|
#if SPI_2_EN
|
|
|
|
|
[SPI_2] = MUTEX_INIT
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
|
|
|
|
|
{
|
|
|
|
|
uint8_t speed_devider;
|
|
|
|
@ -270,6 +293,24 @@ int spi_conf_pins(spi_t dev)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int spi_acquire(spi_t dev)
|
|
|
|
|
{
|
|
|
|
|
if (dev >= SPI_NUMOF) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
mutex_lock(&locks[dev]);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int spi_release(spi_t dev)
|
|
|
|
|
{
|
|
|
|
|
if (dev >= SPI_NUMOF) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
mutex_unlock(&locks[dev]);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int spi_transfer_byte(spi_t dev, char out, char *in)
|
|
|
|
|
{
|
|
|
|
|
SPI_TypeDef *spi_port;
|
|
|
|
|