mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu: sam3: use periph_common SPI functions
This commit is contained in:
parent
10a77b7775
commit
626289b5c7
@ -3,4 +3,7 @@ export CPU_ARCH = cortex-m3
|
||||
# use hwtimer compatibility module
|
||||
USEMODULE += hwtimer_compat
|
||||
|
||||
# include common SPI functions
|
||||
USEMODULE += periph_common
|
||||
|
||||
include $(RIOTCPU)/Makefile.include.cortexm_common
|
||||
|
@ -25,7 +25,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* nothing defined here so far... */
|
||||
/**
|
||||
* @brief declare needed generic SPI functions
|
||||
* @{
|
||||
*/
|
||||
#define PERIPH_SPI_NEEDS_TRANSFER_BYTES
|
||||
#define PERIPH_SPI_NEEDS_TRANSFER_REG
|
||||
#define PERIPH_SPI_NEEDS_TRANSFER_REGS
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -335,76 +335,6 @@ int spi_transfer_byte(spi_t dev, char out, char *in)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int spi_transfer_bytes(spi_t dev, char *out, char *in, unsigned int length)
|
||||
{
|
||||
int trans_ret, trans_bytes = 0;
|
||||
char in_temp;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
if (out) {
|
||||
trans_ret = spi_transfer_byte(dev, out[i], &in_temp);
|
||||
}
|
||||
else {
|
||||
trans_ret = spi_transfer_byte(dev, 0, &in_temp);
|
||||
}
|
||||
|
||||
if (trans_ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (in) {
|
||||
in[i] = in_temp;
|
||||
}
|
||||
|
||||
trans_bytes++;
|
||||
}
|
||||
|
||||
return trans_bytes++;
|
||||
}
|
||||
|
||||
|
||||
int spi_transfer_reg(spi_t dev, uint8_t reg, char out, char *in)
|
||||
{
|
||||
int trans_ret;
|
||||
|
||||
trans_ret = spi_transfer_byte(dev, reg, in);
|
||||
|
||||
if (trans_ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
trans_ret = spi_transfer_byte(dev, out, in);
|
||||
|
||||
if (trans_ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int spi_transfer_regs(spi_t dev, uint8_t reg, char *out, char *in, unsigned int length)
|
||||
{
|
||||
int trans_ret;
|
||||
|
||||
trans_ret = spi_transfer_byte(dev, reg, in);
|
||||
|
||||
if (trans_ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
trans_ret = spi_transfer_bytes(dev, out, in, length);
|
||||
|
||||
if (trans_ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return trans_ret;
|
||||
}
|
||||
|
||||
|
||||
void spi_transmission_begin(spi_t dev, char reset_val)
|
||||
{
|
||||
switch (dev) {
|
||||
|
Loading…
Reference in New Issue
Block a user