-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This module contains shared functions for periph implementations.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser General | ||
* Public License v2.1. See the file LICENSE in the top level directory for more | ||
* details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers | ||
* @{ | ||
* | ||
* @file | ||
* @brief common SPI function fallback implementations | ||
* | ||
* @author Kaspar Schleiser <kaspar@schleiser.de> | ||
* | ||
* @} | ||
*/ | ||
#include <stddef.h> | ||
|
||
#include "board.h" | ||
#include "cpu.h" | ||
#include "periph/spi.h" | ||
#include "periph_cpu.h" | ||
|
||
#if SPI_NUMOF | ||
|
||
#ifdef PERIPH_SPI_NEEDS_TRANSFER_BYTES | ||
int spi_transfer_bytes(spi_t dev, char *out, char *in, unsigned int length) | ||
{ | ||
int i, trans_ret, trans_bytes = 0; | ||
char in_temp; | ||
|
||
for (i = 0; i < length; i++) { | ||
if (out != NULL) { | ||
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 != NULL) { | ||
in[i] = in_temp; | ||
} | ||
trans_bytes++; | ||
} | ||
|
||
return trans_bytes++; | ||
} | ||
#endif | ||
|
||
#ifdef PERIPH_SPI_NEEDS_TRANSFER_REG | ||
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; | ||
} | ||
#endif | ||
|
||
#ifdef PERIPH_SPI_NEEDS_TRANSFER_REGS | ||
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; | ||
} | ||
#endif | ||
|
||
#endif /* SPI_NUMOF */ |