aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-04-29 00:44:29 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-04-29 00:44:29 -0400
commit2c51cc19ccb5c08eb4d89d197623da6cd92b35f7 (patch)
treea68f0d6349119b85766207374824d8468fc9e6ea /libmaple
parent3988feb5e6fd9f22a3201c419f0db6ea0c1a07f2 (diff)
parenta7031b147c9ee77d1ed04ec419a7a23edd08014a (diff)
downloadlibrambutan-2c51cc19ccb5c08eb4d89d197623da6cd92b35f7.tar.gz
librambutan-2c51cc19ccb5c08eb4d89d197623da6cd92b35f7.zip
Merge branch 'spi'
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/spi.c31
-rw-r--r--libmaple/spi.h3
2 files changed, 31 insertions, 3 deletions
diff --git a/libmaple/spi.c b/libmaple/spi.c
index ddc8346..aa75c5f 100644
--- a/libmaple/spi.c
+++ b/libmaple/spi.c
@@ -112,7 +112,7 @@ void spi_init(uint32 spi_num,
* @param spi_num which spi to send on
* @return data shifted back from the slave
*/
-void spi_tx(uint32 spi_num, uint8 data) {
+uint8 spi_tx_byte(uint32 spi_num, uint8 data) {
SPI *spi;
ASSERT(spi_num == 1 || spi_num == 2);
@@ -121,8 +121,35 @@ void spi_tx(uint32 spi_num, uint8 data) {
spi->DR = data;
- while (!(spi->SR & SR_TXE) || (spi->SR & SR_BSY))
+ while (!(spi->SR & SR_TXE) ||
+ (spi->SR & SR_BSY))
;
+
+ return spi->DR;
+}
+
+uint8 spi_tx(uint32 spi_num, uint8 *buf, uint32 len) {
+ SPI *spi;
+ uint32 i = 0;
+ uint8 rc;
+
+ ASSERT(spi_num == 1 || spi_num == 2);
+ spi = (spi_num == 1) ? (SPI*)SPI1_BASE : (SPI*)SPI2_BASE;
+
+ if (!len) {
+ return 0;
+ }
+
+ while (i < len) {
+ spi->DR = buf[i];
+ while (!(spi->SR & SR_TXE) ||
+ (spi->SR & SR_BSY) ||
+ !(spi->SR & SR_RXNE))
+ ;
+ rc = spi->DR;
+ i++;
+ }
+ return rc;
}
static void spi_gpio_cfg(const spi_dev *dev) {
diff --git a/libmaple/spi.h b/libmaple/spi.h
index cde3b42..25c2c6b 100644
--- a/libmaple/spi.h
+++ b/libmaple/spi.h
@@ -96,7 +96,8 @@ void spi_init(uint32 spi_num,
uint32 prescale,
uint32 endian,
uint32 mode);
-void spi_tx(uint32 spi_num, uint8 data);
+uint8 spi_tx_byte(uint32 spi_num, uint8 data);
+uint8 spi_tx(uint32 spi_num, uint8 *buf, uint32 len);
static inline uint8 spi_rx(uint32 spi_num) {
SPI *spi;