engine_control/source/firmware/kernel/driver/spi.c

52 lines
1.4 KiB
C
Raw Normal View History

2016-07-23 05:59:54 +00:00
//! \file spi.c
//! \author tkl
//! \date Feb 11, 2012
//! \brief Source file of the architecture independent spi driver.
#include <stddef.h>
#include "spi.h"
//-----------------------------------------------------------------------------
int spi_open(const struct spi *device) {
if(device == NULL) {
return -1;
}
spi_fp_open_t open = device->fp->open;
return open(device->arch_dep_device);
}
//-----------------------------------------------------------------------------
int spi_close(const struct spi *device) {
if(device == NULL) {
return -1;
}
spi_fp_close_t close = device->fp->close;
return close(device->arch_dep_device);
}
//-----------------------------------------------------------------------------
void spi_assert_cs(const struct spi * device) {
if(device == NULL) {
return;
}
spi_fp_assert_cs_t assert_cs = device->fp->assert_cs;
assert_cs(device->arch_dep_device);
}
//-----------------------------------------------------------------------------
void spi_deassert_cs(const struct spi * device) {
if(device == NULL) {
return;
}
spi_fp_deassert_cs_t deassert_cs = device->fp->deassert_cs;
deassert_cs(device->arch_dep_device);
}
//-----------------------------------------------------------------------------
char spi_rxtx_byte(const struct spi * device, char byte) {
if(device == NULL) {
return 0;
}
spi_fp_rxtx_byte_t rxtx_byte = device->fp->rxtx_byte;
return rxtx_byte(device->arch_dep_device, byte);
}